diff --git a/configure.py b/configure.py index 007b0d2f..1854f7b2 100644 --- a/configure.py +++ b/configure.py @@ -339,22 +339,22 @@ def MatchingFor(*versions): Object(Matching, "jaudio/aictrl.c"), Object(Matching, "jaudio/sample.c"), Object(Matching, "jaudio/dummyrom.c"), - Object(not MatchingFor("GPIP01_00"), "jaudio/audiothread.c"), + Object(Matching, "jaudio/audiothread.c"), Object(Matching, "jaudio/streamctrl.c"), Object(Matching, "jaudio/dspbuf.c"), Object(Matching, "jaudio/cpubuf.c"), Object(Matching, "jaudio/playercall.c"), Object(Matching, "jaudio/dvdthread.c"), Object(Matching, "jaudio/rate.c"), - Object(not MatchingFor("G98P01_PIKIDEMO", "DPIJ01_PIKIDEMO"), "jaudio/audiomesg.c"), + Object(Matching, "jaudio/audiomesg.c"), Object(Matching, "jaudio/stackchecker.c"), Object(Matching, "jaudio/dspboot.c"), Object(Matching, "jaudio/dspproc.c"), Object(Matching, "jaudio/dsptask.c"), Object(Matching, "jaudio/osdsp.c"), - Object(not MatchingFor("GPIP01_00"), "jaudio/osdsp_task.c"), + Object(Equivalent, "jaudio/osdsp_task.c"), Object(Matching, "jaudio/ipldec.c"), - Object(not MatchingFor("G98E01_PIKIDEMO", "G98P01_PIKIDEMO"), "jaudio/dsp_cardunlock.c"), + Object(Matching, "jaudio/dsp_cardunlock.c"), Object(Matching, "jaudio/driverinterface.c"), Object(Matching, "jaudio/dspdriver.c"), Object(Matching, "jaudio/dspinterface.c"), @@ -367,11 +367,11 @@ def MatchingFor(*versions): Object(Matching, "jaudio/random.c"), Object(Matching, "jaudio/aramcall.c"), Object(Matching, "jaudio/ja_calc.c"), - Object(not MatchingFor("GPIJ01_01", "G98P01_PIKIDEMO", "DPIJ01_PIKIDEMO"), "jaudio/fat.c"), + Object(Matching, "jaudio/fat.c"), Object(Matching, "jaudio/cmdstack.c"), Object(Matching, "jaudio/virload.c"), Object(Matching, "jaudio/heapctrl.c"), - Object(not MatchingFor("GPIJ01_01", "G98P01_PIKIDEMO", "DPIJ01_PIKIDEMO"), "jaudio/jammain_2.c"), + Object(Matching, "jaudio/jammain_2.c"), Object(Matching, "jaudio/midplay.c"), Object(Matching, "jaudio/noteon.c"), Object(Matching, "jaudio/seqsetup.c"), @@ -385,7 +385,7 @@ def MatchingFor(*versions): Object(Matching, "jaudio/piki_player.c"), Object(Matching, "jaudio/piki_bgm.c"), Object(Matching, "jaudio/piki_scene.c"), - Object(not MatchingFor("GPIP01_00"), "jaudio/pikidemo.c"), + Object(Matching, "jaudio/pikidemo.c"), Object(Matching, "jaudio/file_seq.c"), Object(Matching, "jaudio/cmdqueue.c"), Object(Matching, "jaudio/filter3d.c"), @@ -393,7 +393,7 @@ def MatchingFor(*versions): Object(Matching, "jaudio/bankloader.c"), Object(Matching, "jaudio/interleave.c"), Object(Matching, "jaudio/pikiseq.c"), - Object(not MatchingFor("GPIP01_00"), "jaudio/hvqm_play.c"), + Object(Matching, "jaudio/hvqm_play.c"), ], }, { @@ -522,7 +522,7 @@ def MatchingFor(*versions): Object(Matching, "plugPikiKando/fastGrid.cpp"), Object(Matching, "plugPikiKando/ropeCreature.cpp"), Object(Matching, "plugPikiKando/objectTypes.cpp"), - Object(not MatchingFor("DPIJ01_PIKIDEMO"), "plugPikiKando/pelletMgr.cpp"), + Object(Matching, "plugPikiKando/pelletMgr.cpp"), Object(Matching, "plugPikiKando/animPellet.cpp"), Object(Matching, "plugPikiKando/genPellet.cpp"), Object(Matching, "plugPikiKando/pelletState.cpp"), @@ -870,7 +870,7 @@ def MatchingFor(*versions): Object(Matching, "os/OSInterrupt.c"), Object(Matching, "os/OSLink.c"), Object(Matching, "os/OSMessage.c"), - Object(not MatchingFor("DPIJ01_PIKIDEMO"), "os/OSMemory.c"), + Object(Matching, "os/OSMemory.c"), Object(Matching, "os/OSMutex.c"), Object(Matching, "os/OSReboot.c"), Object(Matching, "os/OSReset.c"), diff --git a/include/Dolphin/OS/OSSerial.h b/include/Dolphin/OS/OSSerial.h index 38510304..e353bd82 100644 --- a/include/Dolphin/OS/OSSerial.h +++ b/include/Dolphin/OS/OSSerial.h @@ -70,6 +70,7 @@ u32 SIGetStatus(void); // WHAT? u32 SIGetStatus(s32 chan); #endif void SISetCommand(s32 chan, u32 command); +u32 SIGetCommand(s32 chan); void SITransferCommands(void); u32 SISetXY(u32 x, u32 y); u32 SIEnablePolling(u32 poll); diff --git a/include/Dolphin/card.h b/include/Dolphin/card.h index 9fbc92dc..a47773fc 100644 --- a/include/Dolphin/card.h +++ b/include/Dolphin/card.h @@ -138,11 +138,10 @@ struct CARDControl { CARDCallback eraseCallback; // _D8 CARDCallback unlockCallback; // _DC OSAlarm alarm; // _E0, for timeout. -#if OS_BUILD_VERSION >= 20011112L +#if OS_BUILD_VERSION >= 20011112L && !defined(JAUDIO_BROKEN_CARDUNLOCK) u32 cid; // _108 const DVDDiskID* diskID; // _10C #endif - // while these members DO clearly exist in demo, dsp_cardunlock.c in jaudio seems to disagree }; // CARD identification struct (size 0x200). @@ -202,10 +201,18 @@ struct CARDDecodeParameters { }; // Enum for 'permission' in CARDDir. -typedef enum { FilePermPublic = 0x2, FilePermNoCopy = 0x4, FilePermNoMove = 0x8 } CARDFilePermissions; +typedef enum { + FilePermPublic = 0x2, + FilePermNoCopy = 0x4, + FilePermNoMove = 0x8, +} CARDFilePermissions; // Enum for banner format in CARDDir. -typedef enum { BannerColorCI8 = 0x1, BannerPresent = 0x2, IconAnimationPingPong = 0x4 } CARDBannerFlag; +typedef enum { + BannerColorCI8 = 0x1, + BannerPresent = 0x2, + IconAnimationPingPong = 0x4, +} CARDBannerFlag; // Managers for both memory card slots (A and B). extern CARDControl __CARDBlock[2]; diff --git a/include/jaudio/dsp_cardunlock.h b/include/jaudio/dsp_cardunlock.h deleted file mode 100644 index f65bcd47..00000000 --- a/include/jaudio/dsp_cardunlock.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _JAUDIO_DSP_CARDUNLOCK_H -#define _JAUDIO_DSP_CARDUNLOCK_H - -#include "types.h" - -BEGIN_SCOPE_EXTERN_C - -int __CARDUnlock(int chan, u8 flashID[12]); - -END_SCOPE_EXTERN_C - -#endif diff --git a/include/jaudio/jammain_2.h b/include/jaudio/jammain_2.h index 198e6910..43e51aa5 100644 --- a/include/jaudio/jammain_2.h +++ b/include/jaudio/jammain_2.h @@ -305,7 +305,7 @@ void Jam_CheckExportApp(void); void Jam_CheckImportApp(void); void Jam_WritePortIndirect(void); void Jam_ReadPortIndirect(void); -BOOL Jam_CheckPortIndirect(seqp_*, u8, int); +BOOL Jam_CheckPortIndirect(seqp_*, u32, u16); BOOL Jam_WritePortAppDirect(seqp_*, u32, u16); BOOL Jam_ReadPortAppDirect(seqp_*, u32, u16*); BOOL Jam_CheckPortAppDirect(seqp_*, u32, u16); diff --git a/include/jaudio/syncstream.h b/include/jaudio/syncstream.h index c25b0c68..74ba304b 100644 --- a/include/jaudio/syncstream.h +++ b/include/jaudio/syncstream.h @@ -16,7 +16,7 @@ typedef int (*StreamCallback)(u32, s32); void Init_StreamAudio(void); void Get_StreamAudio_Handle(int); -BOOL StreamAudio_Start(u32, int, immut char*, int, int, StreamHeader_*); +BOOL StreamAudio_Start(u32, int, immut char*, BOOL, BOOL, StreamHeader_*); void RegisterStreamCallback(StreamCallback); void Jac_Decode_ADPCM(u8*, s16*, s16*, u32, u8, s16*); BOOL StreamSyncCheckReady(u32); @@ -34,6 +34,7 @@ u8 StreamCheckAudioFormat(u32); void StreamCheckBufferEmpty(void); void StreamCheckBufferRemainSize(void); +// size 0x10 struct BufControl_ { u8 state; // _00 u8 maxBufCount; // _01 @@ -86,10 +87,10 @@ struct StreamCtrl_ { u32 samplesDecoded; // _21980 u32 playbackState; // _21984 StreamHeader_ header; // _21988 - s32 autoStart; // _219A8 - s32 stopRequested; // _219AC + BOOL autoStart; // _219A8 + BOOL stopRequested; // _219AC BOOL isPaused; // _219B0 - s32 isAtEnd; // _219B4 + BOOL isAtEnd; // _219B4 DVDFileInfo fileinfo; // _219B8 dspch_* dspch[2]; // _219F4 u32 totalSamples; // _219FC @@ -108,8 +109,8 @@ struct StreamCtrl_ { u32 updateFlags; // _21A38 u32 _21A3C; // _21A3C u32 samplesLoaded; // _21A40 - s32 isBufferingComplete; // _21A44 - s32 isLoadInProgress; // _21A48 + BOOL isBufferingComplete; // _21A44 + BOOL isLoadInProgress; // _21A48 s32 bufferMargin; // _21A4C }; diff --git a/include/system.h b/include/system.h index 04ec2f7b..95d64172 100644 --- a/include/system.h +++ b/include/system.h @@ -348,7 +348,7 @@ enum { /** * @brief FABRICATED - No other class we currently know of has a virtual table like this. */ -struct System_Class_250 { +struct SystemClass250 { virtual void method(Graphics& gfx) = 0; // _00 // _00 = VTBL @@ -420,7 +420,7 @@ struct System : public StdSystem { u32 mHeapStart; // _244 u32 mHeapEnd; // _248 Graphics* mDGXGfx; // _24C, cast to DGXGraphics in DOL - System_Class_250* _250; // _250, a vestigial pointer related to `System::halt` + SystemClass250* _250; // _250, a vestigial pointer related to `System::halt` Delegate1* mDvdErrorCallback; // _254 int mDvdErrorCode; // _258 u32 mDvdBufferSize; // _25C diff --git a/include/types.h b/include/types.h index be251a21..29c35bf5 100644 --- a/include/types.h +++ b/include/types.h @@ -179,6 +179,7 @@ typedef u32 HWND; #define IS_NOT_ALIGNED(X, N) (((X) & ((N) - 1)) != 0) // True if X is not aligned to N bytes, else false #define ATTRIBUTE_ALIGN(num) __attribute__((aligned(num))) // Align object to num bytes (num should be power of two) +// Makes the compiler averse to using that register for the entire function. #define BUMP_REGISTER(reg) TERNARY_BUILD_MATCHING(MACRO_ARG({ asm { mr reg, reg } }), (void)0) // clang-format off diff --git a/src/ai/ai.c b/src/ai/ai.c index d4c17281..349083e2 100644 --- a/src/ai/ai.c +++ b/src/ai/ai.c @@ -354,8 +354,8 @@ static void __AISHandler(s16 interrupt, OSContext* context) static void __AIDHandler(s16 interrupt, OSContext* context) { OSContext tempContext; - u32 temp = __DSPRegs[5]; - __DSPRegs[5] = (temp & ~0xA0) | 8; + u32 temp = __DSPRegs[DSP_CONTROL_STATUS]; + __DSPRegs[DSP_CONTROL_STATUS] = (temp & ~0xA0) | 8; OSClearContext(&tempContext); OSSetCurrentContext(&tempContext); if (__AID_Callback) { diff --git a/src/card/CARDMount.c b/src/card/CARDMount.c index f22e9ea3..7facefdc 100644 --- a/src/card/CARDMount.c +++ b/src/card/CARDMount.c @@ -235,7 +235,7 @@ static s32 DoMount(s32 channel) sram = __OSLockSramEx(); vendorID = *(u16*)sram->flashID[channel]; - __OSUnlockSramEx(0); + __OSUnlockSramEx(FALSE); if (__CARDVendorID == 0xFFFF || vendorID != __CARDVendorID) { result = CARD_RESULT_WRONGDEVICE; diff --git a/src/dsp/dsp.c b/src/dsp/dsp.c index 313c7091..12cadc88 100644 --- a/src/dsp/dsp.c +++ b/src/dsp/dsp.c @@ -143,15 +143,17 @@ void DSPInit(void) __OSSetInterruptHandler(7, __DSPHandler); __OSUnmaskInterrupts(OS_INTERRUPTMASK_DSP_DSP); - tmp = __DSPRegs[5]; - tmp = (tmp & ~0xA8) | 0x800; - __DSPRegs[5] = tmp; + tmp = __DSPRegs[DSP_CONTROL_STATUS]; + __DSPRegs[DSP_CONTROL_STATUS] = (tmp & ~0xA8) | 0x800; - tmp = __DSPRegs[5]; - __DSPRegs[5] = tmp = tmp & ~0xAC; + tmp = __DSPRegs[DSP_CONTROL_STATUS]; + __DSPRegs[DSP_CONTROL_STATUS] = tmp & ~0xAC; - __DSP_first_task = __DSP_last_task = __DSP_curr_task = __DSP_tmp_task = NULL; - __DSP_init_flag = 1; + __DSP_tmp_task = NULL; + __DSP_curr_task = NULL; + __DSP_last_task = NULL; + __DSP_first_task = NULL; + __DSP_init_flag = 1; OSRestoreInterrupts(old); } diff --git a/src/jaudio/audiomesg.c b/src/jaudio/audiomesg.c index 11f5e4f5..d5f1e424 100644 --- a/src/jaudio/audiomesg.c +++ b/src/jaudio/audiomesg.c @@ -17,10 +17,8 @@ void Jac_InitMessageQueue(Jac_MessageQueue* queue, OSMessage* msgArray, s32 coun */ BOOL Jac_SendMessageBlock(Jac_MessageQueue* queue, OSMessage mesg) { - if (Jac_SendMessage(queue, mesg) == TRUE) { - return TRUE; - } - // UNUSED FUNCTION + while (Jac_SendMessage(queue, mesg) != TRUE) { } + return TRUE; } /** diff --git a/src/jaudio/audiothread.c b/src/jaudio/audiothread.c index bd83c5b0..51fad022 100644 --- a/src/jaudio/audiothread.c +++ b/src/jaudio/audiothread.c @@ -82,9 +82,11 @@ static void DspSync() */ static void DspSync2(void*) { - volatile u32 check; + u32 check; u32 mesg; - u32 stack; + + u32* REF_check = ✓ + STACK_PAD_VAR(1); do { check = DSPCheckMailFromDSP(); @@ -92,11 +94,13 @@ static void DspSync2(void*) mesg = DSPReadMailFromDSP(); if (mesg >> 0x10 == 0xf355) { - stack = 0x10000; - if (u16(mesg & 0xff00) == stack - 0x100) { + switch (mesg & 0xff00) { + case 0xff00: DspSync(); - } else { + break; + default: DspFinishWork(mesg); + break; } } } diff --git a/src/jaudio/cmdqueue.c b/src/jaudio/cmdqueue.c index 3942c40d..9d7c293c 100644 --- a/src/jaudio/cmdqueue.c +++ b/src/jaudio/cmdqueue.c @@ -109,10 +109,11 @@ static s32 Jal_FrameWork(void* a) for (curr = queue_list; curr; curr = curr->next) { #if defined(VERSION_GPIJ01_01) || defined(VERSION_G98P01_PIKIDEMO) || defined(VERSION_DPIJ01_PIKIDEMO) - if (Jam_CheckPortIndirect(curr->track, curr->_64, 1) == 1) { + if (Jam_CheckPortIndirect(curr->track, curr->_64, 1) == 1) #else - if (Jam_CheckPortAppDirect(curr->track, curr->_64, 1) == 1) { + if (Jam_CheckPortAppDirect(curr->track, curr->_64, 1) == 1) #endif + { if (Jac_ReceiveMessage_Fast(&curr->msgQueue, &message) == 1) { Jam_WritePortAppDirect(curr->track, curr->_64, (u16)message); } diff --git a/src/jaudio/dsp_cardunlock.c b/src/jaudio/dsp_cardunlock.c index 557abe2f..c6932809 100644 --- a/src/jaudio/dsp_cardunlock.c +++ b/src/jaudio/dsp_cardunlock.c @@ -1,7 +1,13 @@ -#include "jaudio/dsp_cardunlock.h" - +// This file uses `OSAssert` even in release builds. #define DEBUG +// This modifies the struct `CARDControl` in "Dolphin/card.h" to be broken on purpose. Maybe a duplicate definition +// of `CARDControl` was in a JAudio library header and they forgot to update it after it was changed in the SDK? +// This probably implies JAudio didn't use the SDK header, but I'd rather not duplicate any more than we already have. +#if defined(VERSION_G98E01_PIKIDEMO) || defined(VERSION_G98P01_PIKIDEMO) +#define JAUDIO_BROKEN_CARDUNLOCK +#endif + #include "Dolphin/card.h" #include "Dolphin/exi.h" #include "Dolphin/os.h" diff --git a/src/jaudio/dspdriver.c b/src/jaudio/dspdriver.c index 108c9cb4..55da4c65 100644 --- a/src/jaudio/dspdriver.c +++ b/src/jaudio/dspdriver.c @@ -53,8 +53,8 @@ dspch_* AllocDSPchannel(u32 param_1, u32 param_2) s32 i; STACK_PAD_VAR(1); - u32* p2 = ¶m_2; - s32* ip = &i; + u32* REF_param_2 = ¶m_2; + s32* REF_i = &i; if (param_1 == 0) { for (i = 0; i < DSPCH_LENGTH; ++i) { diff --git a/src/jaudio/fat.c b/src/jaudio/fat.c index dac4e36c..ea6d80cb 100644 --- a/src/jaudio/fat.c +++ b/src/jaudio/fat.c @@ -23,9 +23,10 @@ static struct FAT_info2 { } FH_TO_FAT[FAT_SIZE]; static FATEntry FAT[FAT_SIZE]; - -// havent figured this out yet -static struct FATEntry fattmp[FAT_SIZE]; +#if defined(VERSION_GPIJ01_01) || defined(VERSION_DPIJ01_PIKIDEMO) || defined(VERSION_G98P01_PIKIDEMO) +#else +static FATEntry fattmp[FAT_SIZE]; +#endif /** * @TODO: Documentation @@ -126,6 +127,9 @@ int FAT_FreeMemory(u16 size) u16 size2; u32 count; u16 tail; +#if defined(VERSION_GPIJ01_01) || defined(VERSION_DPIJ01_PIKIDEMO) || defined(VERSION_G98P01_PIKIDEMO) + FATEntry fattmp[FAT_SIZE]; +#endif count = FH_TO_FAT[size].blockCount; start = FH_TO_FAT[size].startBlock; diff --git a/src/jaudio/hvqm_play.c b/src/jaudio/hvqm_play.c index d40207e9..329a3e24 100644 --- a/src/jaudio/hvqm_play.c +++ b/src/jaudio/hvqm_play.c @@ -2,6 +2,7 @@ #include "Dolphin/os.h" #include "hvqm4.h" #include "jaudio/dspbuf.h" +#include "jaudio/dummyprobe.h" #include "jaudio/dvdthread.h" #include "jaudio/interleave.h" #include "jaudio/sample.h" @@ -86,6 +87,9 @@ static u8 hvqmStack[0x1000] ATTRIBUTE_ALIGN(32); */ static void __ReLoad() { +#if defined(VERSION_GPIP01) + STACK_PAD_VAR(2); +#endif int size = dvdfile_size; if (dvdfile_size == 0) { dvd_loadfinish = 1; @@ -173,7 +177,7 @@ static int __VirtualLoad(u32 currentOffs, u32 bytesToRead, u8* data) static void InitAudio1(StreamHeader_* header, u8* data, u32 size) { Jac_InitStreamData(data, size); - StreamAudio_Start(0, 0, 0, 1, 0, header); + StreamAudio_Start(0, 0, NULL, TRUE, FALSE, header); } /** @@ -375,7 +379,11 @@ void Jac_HVQM_ThreadStart(void) */ BOOL Jac_HVQM_Update(void) { +#if defined(VERSION_GPIP01) + STACK_PAD_VAR(3); +#else STACK_PAD_VAR(2); +#endif u8* data = virtualfile_buf; if (gop_frame == file_header.mTotalFrames) { return TRUE; @@ -413,9 +421,15 @@ BOOL Jac_HVQM_Update(void) record_ok = 0; return FALSE; } +#if defined(VERSION_GPIP01) + u32 remainBefore = Jac_GetStreamRemain(); +#endif Jac_SendStreamData(data, rec_header.mDataSize); record_ok = 1; arcoffset += rec_header.mDataSize; +#if defined(VERSION_GPIP01) + u32 remainAfter = Jac_GetStreamRemain(); +#endif } break; } @@ -645,21 +659,39 @@ static int Decode1(u8* data, u32 frameId, u8 frameType) switch (frameType) { case 0x10: // IPIC chunk { +#if defined(VERSION_GPIP01) + Probe_Start(12, "HVQM-I-PIC"); +#endif HVQM4DecodeIpic(hvqm_obj, data, (u8*)ref); +#if defined(VERSION_GPIP01) + Probe_Finish(12); +#endif ref2 = ref1; ref1 = ref; break; } case 0x20: // PPIC chunk { +#if defined(VERSION_GPIP01) + Probe_Start(11, "HVQM-P-PIC"); +#endif HVQM4DecodePpic(hvqm_obj, data, (u8*)ref, (u8*)ref1); +#if defined(VERSION_GPIP01) + Probe_Finish(11); +#endif ref2 = ref1; ref1 = ref; break; } case 0x30: // BPIC chunk { +#if defined(VERSION_GPIP01) + Probe_Start(13, "HVQM-B-PIC"); +#endif HVQM4DecodeBpic(hvqm_obj, data, (u8*)ref, (u8*)ref2, (u8*)ref1); +#if defined(VERSION_GPIP01) + Probe_Finish(13); +#endif break; } } diff --git a/src/jaudio/jammain_2.c b/src/jaudio/jammain_2.c index d0877bb2..8de0638c 100644 --- a/src/jaudio/jammain_2.c +++ b/src/jaudio/jammain_2.c @@ -777,16 +777,16 @@ void Jam_WriteRegXY(seqp_* track, u32 param_2) u32 __ExchangeRegisterValue(seqp_* track, u8 reg) { u32 res; -#if defined(VERSION_GPIJ01_01) - u8* refReg = ® +#if defined(VERSION_GPIJ01_01) || defined(VERSION_DPIJ01_PIKIDEMO) || defined(VERSION_G98P01_PIKIDEMO) + u8* REF_reg = ® #endif if (reg < 64) { res = Jam_ReadReg32(track, reg); } else { res = track->trackPort[reg - 64].value; } -#if defined(VERSION_GPIJ01_01) - u32* refRes = &res; +#if defined(VERSION_GPIJ01_01) || defined(VERSION_DPIJ01_PIKIDEMO) || defined(VERSION_G98P01_PIKIDEMO) + u32* REF_res = &res; #endif return res; } @@ -849,9 +849,40 @@ void Jam_ReadPortIndirect(void) * @TODO: Documentation * @note UNUSED Size: 0000A4 */ -BOOL Jam_CheckPortIndirect(seqp_*, u8, int) +BOOL Jam_CheckPortIndirect(seqp_* track, u32 param_2, u16 param_3) { - // UNUSED FUNCTION + u8 port; + int depth; + size_t i; + + port = (param_2 >> 16) & 0xff; + depth = (param_2 >> 28) & 0x0f; + for (i = 0; i < depth; ++i) { + track = track->children[param_2 & 0x0f]; + if (!track) { + return FALSE; + } + param_2 >>= 4; + } + + // Again with the cast to u8... what is it? + switch ((u8)param_3) { + case FALSE: + { + if (track->trackPort[port].exportFlag == FALSE) { + return FALSE; + } + return TRUE; + } + case TRUE: + { + if (track->trackPort[port].importFlag == TRUE) { + return FALSE; + } + return TRUE; + } + } + return FALSE; } /** diff --git a/src/jaudio/osdsp_task.c b/src/jaudio/osdsp_task.c index d73b0243..07c8232d 100644 --- a/src/jaudio/osdsp_task.c +++ b/src/jaudio/osdsp_task.c @@ -20,9 +20,12 @@ BEGIN_SCOPE_EXTERN_C void __DSPHandler(__OSInterrupt interrupt, OSContext* context) { OSContext funcContext; + u32 mail; + u16 temp; STACK_PAD_VAR(3); - __DSPRegs[5] = ((u16)(__DSPRegs[5]) & ~0x28) | 0x80; + temp = __DSPRegs[DSP_CONTROL_STATUS]; + __DSPRegs[DSP_CONTROL_STATUS] = (temp & ~0x28) | 0x80; if (DSP_prior_yield == 1 || DSP_prior_yield == 0) { __DSP_curr_task = DSP_prior_task; @@ -30,7 +33,7 @@ void __DSPHandler(__OSInterrupt interrupt, OSContext* context) while (DSPCheckMailFromDSP() == 0) ; - u32 mail = DSPReadMailFromDSP(); + mail = DSPReadMailFromDSP(); if ((__DSP_curr_task->flags & 2) && mail == 0xDCD10002) { mail = 0xDCD10003; diff --git a/src/jaudio/piki_scene.c b/src/jaudio/piki_scene.c index c5726f5c..fcfc6bcb 100644 --- a/src/jaudio/piki_scene.c +++ b/src/jaudio/piki_scene.c @@ -467,7 +467,7 @@ void Jac_PrepareDemoSound(u32 id) } while (stop_ready == 0); } DVDT_ExtendPath(buffer, filelist[id]); - StreamAudio_Start(0, id, buffer, 1, 0, 0); + StreamAudio_Start(0, id, buffer, TRUE, FALSE, NULL); Jac_UpdateStreamLevel(); current_prepare = id; } diff --git a/src/jaudio/pikidemo.c b/src/jaudio/pikidemo.c index 1f92899e..3e324894 100644 --- a/src/jaudio/pikidemo.c +++ b/src/jaudio/pikidemo.c @@ -866,6 +866,18 @@ void Jac_FinishDemo(void) case DEMOID_DayEndForest: case DEMOID_DayEndCaveLast: case DEMOID_DayEndYakushima: +#if defined(VERSION_GPIP01) + case DEMOID_Unk90: + case DEMOID_Unk91: + case DEMOID_ExtDayEndPractice: + case DEMOID_ExtDayEndForest: + case DEMOID_ExtDayEndCaveLast: + case DEMOID_ExtDayEndYakushima: + case DEMOID_OliDownDayEndPractice: + case DEMOID_OliDownDayEndForest: + case DEMOID_OliDownDayEndCaveLast: + case DEMOID_OliDownDayEndYakushima: +#endif { demo_end_delay = 100; break; diff --git a/src/jaudio/syncstream.c b/src/jaudio/syncstream.c index f7a05011..78e606c7 100644 --- a/src/jaudio/syncstream.c +++ b/src/jaudio/syncstream.c @@ -143,7 +143,7 @@ static void __LoadFin(s32 size, DVDFileInfo* fileinfo) } } - ctrl->isLoadInProgress = 0; + ctrl->isLoadInProgress = FALSE; u32 idx = ctrl->buffCtrlMain.currentBufIdx; @@ -166,7 +166,7 @@ static void __LoadFin(s32 size, DVDFileInfo* fileinfo) ctrl->buffCtrlMain.currentBufIdx = (idx + 1) % ctrl->buffCtrlMain.maxBufCount; if (ctrl->remainingBytes == 0) { - ctrl->isBufferingComplete = 1; + ctrl->isBufferingComplete = TRUE; return; } @@ -253,7 +253,7 @@ static void LoadADPCM(StreamCtrl_* ctrl, int r28) DCStoreRange((void*)buff->mLength, size); - ctrl->isLoadInProgress = 1; + ctrl->isLoadInProgress = TRUE; if (DVDReadAsyncPrio2(&ctrl->fileinfo, (void*)buff->mLength, size, oldSize, __LoadFin, 1) == FALSE) { #if defined(VERSION_G98P01_PIKIDEMO) || defined(VERSION_DPIJ01_PIKIDEMO) @@ -304,7 +304,7 @@ static s32 StreamAudio_Callback(void*); /** * @TODO: Documentation */ -BOOL StreamAudio_Start(u32 ctrlID, int soundId, immut char* name, int r6, int r7, StreamHeader_* header) +BOOL StreamAudio_Start(u32 ctrlID, int soundId, immut char* name, BOOL r6, BOOL r7, StreamHeader_* header) { StreamCtrl_* ctrl = &SC[ctrlID]; int i; @@ -312,8 +312,8 @@ BOOL StreamAudio_Start(u32 ctrlID, int soundId, immut char* name, int r6, int r7 ctrl->controllerId = ctrlID; ctrl->streamId = soundId; - ctrl->stopRequested = 0; - ctrl->isAtEnd = 0; + ctrl->stopRequested = FALSE; + ctrl->isAtEnd = FALSE; ctrl->isPaused = FALSE; if (name) { @@ -340,7 +340,7 @@ BOOL StreamAudio_Start(u32 ctrlID, int soundId, immut char* name, int r6, int r7 ctrl->totalSamples = ctrl->header.sampleCount; ctrl->samplesDecoded = 0; ctrl->samplesLoaded = 0; - ctrl->isBufferingComplete = 0; + ctrl->isBufferingComplete = FALSE; ctrl->frameCounter = 0; ctrl->playbackState = 0; @@ -383,7 +383,7 @@ BOOL StreamAudio_Start(u32 ctrlID, int soundId, immut char* name, int r6, int r7 } ctrl->autoStart = r6; - ctrl->isLoadInProgress = 0; + ctrl->isLoadInProgress = FALSE; LoadADPCM(ctrl, 1); for (u32 i = 0; i < 2; i++) { @@ -424,15 +424,20 @@ static s32 StreamAudio_Callback(void* data) if (!ctrl->dspch[0]) { for (channelIdx = 0; channelIdx < 2; channelIdx++) { - ctrl->dspch[channelIdx] = AllocDSPchannel(0, (u32)&ctrl->dspch[channelIdx]); - ctrl->dspch[channelIdx]->prio = DSPCHAN_MAX_PRIO; + ctrl->dspch[channelIdx] = AllocDSPchannel(0, (u32)&ctrl->dspch[channelIdx]); +#if defined(VERSION_GPIP01) + if (ctrl->dspch[channelIdx]) +#endif + { + ctrl->dspch[channelIdx]->prio = DSPCHAN_MAX_PRIO; + } } } if (ctrl->frameCounter) { DSPchannel_* buff = GetDspHandle(ctrl->dspch[0]->buffer_idx); if (buff->done) { - ctrl->isAtEnd = 1; + ctrl->isAtEnd = TRUE; } if (ctrl->isAtEnd) { @@ -465,7 +470,7 @@ static s32 StreamAudio_Callback(void* data) int callbackResult = ctrl->syncCallback(ctrl->controllerId, r4); // TODO: Figure out what this -1 means if (callbackResult == -1) { - ctrl->stopRequested = 1; + ctrl->stopRequested = TRUE; } } @@ -526,7 +531,7 @@ static s32 StreamAudio_Callback(void* data) } } - if (ctrl->isBufferingComplete == 0 && ctrl->playbackState != 5 && ctrl->frameCounter != 0) { + if (ctrl->isBufferingComplete == FALSE && ctrl->playbackState != 5 && ctrl->frameCounter != 0) { DSPchannel_* buff = GetDspHandle(ctrl->dspch[0]->buffer_idx); u32 size = ctrl->totalSamples - Get_DirectPCM_Remain(buff); @@ -551,7 +556,7 @@ static s32 StreamAudio_Callback(void* data) DSPchannel_* buff = GetDspHandle(ctrl->dspch[0]->buffer_idx); u32 size = ctrl->totalSamples - Get_DirectPCM_Remain(buff); - if (ctrl->samplesLoaded - size > 0xc00 || ctrl->isBufferingComplete == 1) { + if (ctrl->samplesLoaded - size > 0xc00 || ctrl->isBufferingComplete == TRUE) { DSP_SetPauseFlag(ctrl->dspch[0]->buffer_idx, 0); DSP_SetPauseFlag(ctrl->dspch[1]->buffer_idx, 0); @@ -592,18 +597,18 @@ static s32 StreamAudio_Callback(void* data) ctrl->buffCtrlMain2.mLength -= ctrl->buffCtrlMain3.usedSize; } } else if (ctrl->frameCounter == 0) { - if (ctrl->autoStart == 1) { + if (ctrl->autoStart == TRUE) { if (ctrl->syncCallback != NULL) { int callbackResult = ctrl->syncCallback(ctrl->controllerId, 0); if (callbackResult == -1) { - ctrl->stopRequested = 1; + ctrl->stopRequested = TRUE; } if (callbackResult == 1) { - ctrl->autoStart = 0; + ctrl->autoStart = FALSE; } } ctrl->playbackState = 2; - if (ctrl->stopRequested == 0) { + if (!ctrl->stopRequested) { return 0; } } else { @@ -648,12 +653,12 @@ static s32 StreamAudio_Callback(void* data) return 0; } - if (ctrl->stopRequested != 0) { + if (ctrl->stopRequested) { if (ctrl->frameCounter == 0) { if (ctrl->buffCtrl[ctrl->buffCtrlMain.currentBufIdx].state == 1) { return 0; } - ctrl->stopRequested = 0; + ctrl->stopRequested = FALSE; if (ctrl->syncCallback != NULL) { ctrl->syncCallback(ctrl->controllerId, -1); } @@ -661,7 +666,7 @@ static s32 StreamAudio_Callback(void* data) ctrl->streamId = -1; return -1; } - ctrl->stopRequested = 0; + ctrl->stopRequested = FALSE; ctrl->playbackState = 3; for (channelIdx = 0; channelIdx < 2; channelIdx++) { ForceStopDSPchannel(ctrl->dspch[channelIdx]); @@ -680,6 +685,34 @@ void RegisterStreamCallback(StreamCallback callback) default_streamsync_call = callback; } +/** + * @TODO: Documentation + */ +static u32 __DecodePCM(StreamCtrl_* ctrl) +{ + u32 usedSize; + s16* psVar9; + s16* pasVar4; + u32 sampleCount; + s16* pasVar6; + size_t i; + + usedSize = ctrl->buffCtrl[ctrl->buffCtrlMain.activeBufIdx].usedSize; + sampleCount = ((ctrl->buffCtrl[ctrl->buffCtrlMain.activeBufIdx].pos - usedSize) / 4); + + pasVar6 = ctrl->leftChanBufs[ctrl->buffCtrlMain2.currentBufIdx]; + pasVar4 = ctrl->rightChanBufs[ctrl->buffCtrlMain2.currentBufIdx]; + psVar9 = (s16*)&ctrl->data[ctrl->buffCtrlMain.activeBufIdx].data[usedSize]; + for (i = 0; i < sampleCount; i++) { + // This FEELS like it's all optimized array subscripting, but I can't figure it out. + *pasVar6++ = psVar9[0]; + *pasVar4++ = psVar9[1]; + psVar9 += 2; + } + ctrl->samplesDecoded += sampleCount; + return sampleCount; +} + /** * @TODO: Documentation */ @@ -844,6 +877,13 @@ static u32 __Decode(StreamCtrl_* ctrl) { u32 size; switch (ctrl->header.audioFormat) { +#if defined(VERSION_GPIP01) + case AUDIOFRMT_16BIT_PCM: + { + size = __DecodePCM(ctrl); + break; + } +#endif case AUDIOFRMT_ADPCM: { size = __DecodeADPCM(ctrl); @@ -960,7 +1000,7 @@ int StreamSyncPlayAudio(f32 f1, u32 ctrlID, int volumeL, int volumeR) ctrl->pitchRatio = f1; ctrl->volume[0] = volumeL; ctrl->volume[1] = volumeR; - ctrl->autoStart = 0; + ctrl->autoStart = FALSE; return TRUE; } @@ -981,8 +1021,7 @@ BOOL StreamSyncStopAudio(u32 ctrlID) return FALSE; } - // isStopped? - ctrl->stopRequested = 1; + ctrl->stopRequested = TRUE; return TRUE; } @@ -1120,6 +1159,10 @@ BOOL StreamSetDVDPause(u32 ctrlID, BOOL isPaused) BOOL tmp = ctrl->isPaused; +#if defined(VERSION_GPIP01) + BOOL* REF_isPaused = &isPaused; +#endif + ctrl->isPaused = isPaused; return tmp; diff --git a/src/os/OSAudioSystem.c b/src/os/OSAudioSystem.c index c32c710c..06baa7eb 100644 --- a/src/os/OSAudioSystem.c +++ b/src/os/OSAudioSystem.c @@ -41,53 +41,53 @@ void __OSInitAudioSystem(void) DCFlushRange(__DSPWorkBuffer, 128); - __DSPRegs[9] = 0x43; - __DSPRegs[5] = 0x8AC; - __DSPRegs[5] |= 1; - while (__DSPRegs[5] & 1) + __DSPRegs[DSP_ARAM_SIZE] = 0x43; + __DSPRegs[DSP_CONTROL_STATUS] = 0x8AC; + __DSPRegs[DSP_CONTROL_STATUS] |= 1; + while (__DSPRegs[DSP_CONTROL_STATUS] & 1) ; - __DSPRegs[0] = 0; - while (((__DSPRegs[2] << 16) | __DSPRegs[3]) & 0x80000000) + __DSPRegs[DSP_MAILBOX_IN_HI] = 0; + while (((__DSPRegs[DSP_MAILBOX_OUT_HI] << 16) | __DSPRegs[DSP_MAILBOX_OUT_LO]) & 0x80000000) ; - *(u32*)&__DSPRegs[16] = 0x1000000; - *(u32*)&__DSPRegs[18] = 0; - *(u32*)&__DSPRegs[20] = 0x20; + *(u32*)&__DSPRegs[DSP_ARAM_DMA_MM_HI] = 0x1000000; + *(u32*)&__DSPRegs[DSP_ARAM_DMA_ARAM_HI] = 0; + *(u32*)&__DSPRegs[DSP_ARAM_DMA_SIZE_HI] = 0x20; - r3 = __DSPRegs[5]; + r3 = __DSPRegs[DSP_CONTROL_STATUS]; while (!(r3 & 0x20)) - r3 = __DSPRegs[5]; - __DSPRegs[5] = r3; + r3 = __DSPRegs[DSP_CONTROL_STATUS]; + __DSPRegs[DSP_CONTROL_STATUS] = r3; r28 = OSGetTick(); while ((s32)(OSGetTick() - r28) < 0x892) ; - *(u32*)&__DSPRegs[16] = 0x1000000; - *(u32*)&__DSPRegs[18] = 0; - *(u32*)&__DSPRegs[20] = 0x20; + *(u32*)&__DSPRegs[DSP_ARAM_DMA_MM_HI] = 0x1000000; + *(u32*)&__DSPRegs[DSP_ARAM_DMA_ARAM_HI] = 0; + *(u32*)&__DSPRegs[DSP_ARAM_DMA_SIZE_HI] = 0x20; - r3 = __DSPRegs[5]; + r3 = __DSPRegs[DSP_CONTROL_STATUS]; while (!(r3 & 0x20)) - r3 = __DSPRegs[5]; - __DSPRegs[5] = r3; + r3 = __DSPRegs[DSP_CONTROL_STATUS]; + __DSPRegs[DSP_CONTROL_STATUS] = r3; - __DSPRegs[5] &= ~0x800; - while ((__DSPRegs[5]) & 0x400) + __DSPRegs[DSP_CONTROL_STATUS] &= ~0x800; + while ((__DSPRegs[DSP_CONTROL_STATUS]) & 0x400) ; - __DSPRegs[5] &= ~4; + __DSPRegs[DSP_CONTROL_STATUS] &= ~4; - r3 = __DSPRegs[2]; + r3 = __DSPRegs[DSP_MAILBOX_OUT_HI]; // the nonmatching part while (!(r3 & 0x8000)) - r3 = __DSPRegs[2]; + r3 = __DSPRegs[DSP_MAILBOX_OUT_HI]; - (void)__DSPRegs[3]; + (void)__DSPRegs[DSP_MAILBOX_OUT_LO]; r3 != 42069; - __DSPRegs[5] |= 4; - __DSPRegs[5] = 0x8AC; - __DSPRegs[5] |= 1; - while (__DSPRegs[5] & 1) + __DSPRegs[DSP_CONTROL_STATUS] |= 4; + __DSPRegs[DSP_CONTROL_STATUS] = 0x8AC; + __DSPRegs[DSP_CONTROL_STATUS] |= 1; + while (__DSPRegs[DSP_CONTROL_STATUS] & 1) ; #if OS_BUILD_VERSION >= 20011002L memcpy(__DSPWorkBuffer, (void*)((u8*)OSGetArenaHi() - 128), 128); @@ -107,19 +107,19 @@ void __OSStopAudioSystem(void) r28 = (load); \ } - __DSPRegs[5] = 0x804; - r28 = __DSPRegs[27]; - __DSPRegs[27] = r28 & ~0x8000; - waitUntil(__DSPRegs[5], 0x400); - waitUntil(__DSPRegs[5], 0x200); - __DSPRegs[5] = 0x8ac; - __DSPRegs[0] = 0; + __DSPRegs[DSP_CONTROL_STATUS] = 0x804; + r28 = __DSPRegs[DSP_DMA_CONTROL_LEN]; + __DSPRegs[DSP_DMA_CONTROL_LEN] = r28 & ~0x8000; + waitUntil(__DSPRegs[DSP_CONTROL_STATUS], 0x400); + waitUntil(__DSPRegs[DSP_CONTROL_STATUS], 0x200); + __DSPRegs[DSP_CONTROL_STATUS] = 0x8ac; + __DSPRegs[DSP_MAILBOX_IN_HI] = 0; - while (((__DSPRegs[2] << 16) | __DSPRegs[3]) & 0x80000000) + while (((__DSPRegs[DSP_MAILBOX_OUT_HI] << 16) | __DSPRegs[DSP_MAILBOX_OUT_LO]) & 0x80000000) ; r28 = OSGetTick(); while ((s32)(OSGetTick() - r28) < 0x2c) ; - __DSPRegs[5] |= 1; - waitUntil(__DSPRegs[5], 0x001); + __DSPRegs[DSP_CONTROL_STATUS] |= 1; + waitUntil(__DSPRegs[DSP_CONTROL_STATUS], 0x001); } diff --git a/src/os/OSError.c b/src/os/OSError.c index 9fb1be89..c1828533 100644 --- a/src/os/OSError.c +++ b/src/os/OSError.c @@ -128,9 +128,9 @@ void __OSUnhandledException(__OSException exception, OSContext* context, u32 dsi case OS_ERROR_PROTECTION: { OSReport("\n"); - OSReport("AI DMA Address = 0x%04x%04x\n", __DSPRegs[0x00000018], __DSPRegs[0x00000018 + 1]); - OSReport("ARAM DMA Address = 0x%04x%04x\n", __DSPRegs[0x00000010], __DSPRegs[0x00000010 + 1]); - OSReport("DI DMA Address = 0x%08x\n", __DIRegs[0x00000005]); + OSReport("AI DMA Address = 0x%04x%04x\n", __DSPRegs[DSP_DMA_START_HI], __DSPRegs[DSP_DMA_START_LO]); + OSReport("ARAM DMA Address = 0x%04x%04x\n", __DSPRegs[DSP_ARAM_DMA_MM_HI], __DSPRegs[DSP_ARAM_DMA_MM_LO]); + OSReport("DI DMA Address = 0x%08x\n", __DIRegs[DI_DMA_MEM_ADDR]); break; } #endif diff --git a/src/os/OSMemory.c b/src/os/OSMemory.c index dc96e4bd..a056a2e6 100644 --- a/src/os/OSMemory.c +++ b/src/os/OSMemory.c @@ -26,7 +26,7 @@ u32 OSGetConsoleSimulatedMemSize() static BOOL OnReset(BOOL final) { if (final != FALSE) { - __MEMRegs[8] = 0xFF; + __MEMRegs[MEM_PROT_TYPE] = 0xFF; __OSMaskInterrupts(0xf0000000); } return TRUE; @@ -37,9 +37,9 @@ static void MEMIntrruptHandler(__OSInterrupt interrupt, OSContext* context) u32 addr; u32 cause; - cause = __MEMRegs[0xf]; - addr = (((u32)__MEMRegs[0x12] & 0x3ff) << 16) | __MEMRegs[0x11]; - __MEMRegs[0x10] = 0; + cause = __MEMRegs[MEM_INTRPT_SRC]; + addr = (((u32)__MEMRegs[MEM_INTRPT_ADDR_HI] & 0x3ff) << 16) | __MEMRegs[MEM_INTRPT_ADDR_LO]; + __MEMRegs[MEM_INTRPT_FLAG] = 0; #if OS_BUILD_VERSION >= 20011112L if (__OSErrorTable[OS_ERROR_PROTECTION]) { @@ -76,10 +76,10 @@ void OSProtectRange(u32 chan, void* addr, u32 nBytes, u32 control) __MEMRegs[0 + 2 * chan] = (u16)(start >> 10); __MEMRegs[1 + 2 * chan] = (u16)(end >> 10); - reg = __MEMRegs[8]; + reg = __MEMRegs[MEM_PROT_TYPE]; reg &= ~(OS_PROTECT_CONTROL_RDWR << 2 * chan); reg |= control << 2 * chan; - __MEMRegs[8] = reg; + __MEMRegs[MEM_PROT_TYPE] = reg; if (control != OS_PROTECT_CONTROL_RDWR) { __OSUnmaskInterrupts(OS_INTERRUPTMASK(__OS_INTERRUPT_MEM_0 + chan)); @@ -88,6 +88,10 @@ void OSProtectRange(u32 chan, void* addr, u32 nBytes, u32 control) OSRestoreInterrupts(enabled); } +// Compiling the following functions when they didn't exist yet (`OS_BUILD_VERSION == 20011002L`) breaks `__OSInitMemoryProtection`. + +#if OS_BUILD_VERSION >= 20011112L + static ASM void Config24MB() { #ifdef __MWERKS__ // clang-format off @@ -199,6 +203,8 @@ static ASM void RealMode(register u32 addr) #endif // clang-format on } +#endif + void __OSInitMemoryProtection() { #if OS_BUILD_VERSION >= 20011112L @@ -217,10 +223,10 @@ void __OSInitMemoryProtection() STACK_PAD_VAR(4); #endif - __MEMRegs[16] = 0; - __MEMRegs[8] = 0xFF; + __MEMRegs[MEM_INTRPT_FLAG] = 0; + __MEMRegs[MEM_PROT_TYPE] = 0xFF; - __OSMaskInterrupts(OS_INTERRUPTMASK_MEM_0 | OS_INTERRUPTMASK_MEM_1 | OS_INTERRUPTMASK_MEM_2 | OS_INTERRUPTMASK_MEM_3); + __OSMaskInterrupts(OS_INTERRUPTMASK_MEM_RESET); __OSSetInterruptHandler(__OS_INTERRUPT_MEM_0, MEMIntrruptHandler); __OSSetInterruptHandler(__OS_INTERRUPT_MEM_1, MEMIntrruptHandler); __OSSetInterruptHandler(__OS_INTERRUPT_MEM_2, MEMIntrruptHandler); @@ -229,7 +235,7 @@ void __OSInitMemoryProtection() OSRegisterResetFunction(&ResetFunctionInfo); if (OSGetConsoleSimulatedMemSize() < OSGetPhysicalMemSize() && OSGetConsoleSimulatedMemSize() == 0x1800000) { - __MEMRegs[20] = 2; + __MEMRegs[MEM_UNK_FLAG] = 2; } __OSUnmaskInterrupts(OS_INTERRUPTMASK_MEM_ADDRESS); diff --git a/src/os/OSSerial.c b/src/os/OSSerial.c index 350a5f56..8f62451b 100644 --- a/src/os/OSSerial.c +++ b/src/os/OSSerial.c @@ -432,7 +432,7 @@ u32 SIGetStatus(s32 chan) OSRestoreInterrupts(enabled); return sr; #else - // Something else + FORCE_DONT_INLINE; // TODO: Something else #endif #else return __SIRegs[SI_STAT]; @@ -449,11 +449,11 @@ void SISetCommand(s32 chan, u32 command) /** * @TODO: Documentation - * @note UNUSED Size: 000014 + * @note UNUSED Size: 000014 (Matching by size) */ -void SIGetCommand(void) +u32 SIGetCommand(s32 chan) { - // UNUSED FUNCTION + return __SIRegs[3 * chan]; } /** @@ -555,11 +555,15 @@ static BOOL SIGetResponseRaw(s32 chan) u32 sr; #if OS_BUILD_VERSION >= 20011002L && OS_BUILD_VERSION < 20011112L + int chanShift; sr = SIGetStatus(); + chanShift = 8 * (SI_MAX_CHAN - 1 - chan); + if (sr & (SI_ERROR_RDST << chanShift)) #else sr = SIGetStatus(chan); + if (sr & SI_ERROR_RDST) #endif - if (sr & SI_ERROR_RDST) { + { InputBuffer[chan][0] = __SIRegs[3 * chan + 1]; InputBuffer[chan][1] = __SIRegs[3 * chan + 2]; InputBufferValid[chan] = TRUE; diff --git a/src/plugPikiColin/gameflow.cpp b/src/plugPikiColin/gameflow.cpp index 65f445f2..c717e955 100644 --- a/src/plugPikiColin/gameflow.cpp +++ b/src/plugPikiColin/gameflow.cpp @@ -94,11 +94,12 @@ void GameFlow::drawLoadLogo(Graphics& gfx, bool force60FPSSpin, Texture* logoTex gfx.setOrthogonal(screenMtx.mMtx, AREA_FULL_SCREEN(gfx)); if (mIsNintendoLoadLogo) { -// red - this is just for the Nintendo logo on boot-up. -#if defined(VERSION_GPIJ01) +#if defined(VERSION_GPIJ01) || defined(VERSION_DPIJ01_PIKIDEMO) + // blue - this is just for the Nintendo logo on boot-up. gfx.setColour(Colour(0, 70, 255, fadeInFactor * 255.0f), true); gfx.setAuxColour(Colour(0, 70, 255, fadeInFactor * 255.0f)); #else + // red - this is just for the Nintendo logo on boot-up. gfx.setColour(Colour(220, 0, 0, fadeInFactor * 255.0f), true); gfx.setAuxColour(Colour(220, 0, 0, fadeInFactor * 255.0f)); #endif @@ -732,6 +733,11 @@ void GameFlow::softReset() PRINT("*--------------- %.2fk (%.2fk) free : %d files, %.1fk took %.1f secs : %.1f mb/sec\n", size / 1024.0f, size2 / 1024.0f, gsys->mDvdOpenFiles, gsys->mDvdBytesRead / 1024.0f, mLoadTimeSeconds, gsys->mDvdBytesRead / (1024.0f * 1024.0f) / mLoadTimeSeconds); +#elif defined(VERSION_PIKIDEMO) + u32 size = (u32)gsys->getHeap(SYSHEAP_App)->getFree(); + STACK_PAD_VAR(2); + _Print("*--------------- %.2fk free : %d files, %.1fk took %.1f secs : %.1f mb/sec\n", size / 1024.0f, gsys->mDvdOpenFiles, + gsys->mDvdBytesRead / 1024.0f, mLoadTimeSeconds, gsys->mDvdBytesRead / (1024.0f * 1024.0f) / mLoadTimeSeconds); #else u32 size = (u32)gsys->getHeap(SYSHEAP_App)->getFree(); PRINT("*--------------- %.2fk free : %d files, %.1fk took %.1f secs : %.1f mb/sec\n", size / 1024.0f, gsys->mDvdOpenFiles, diff --git a/src/plugPikiKando/aiBridge.cpp b/src/plugPikiKando/aiBridge.cpp index 60229817..836efcaf 100644 --- a/src/plugPikiKando/aiBridge.cpp +++ b/src/plugPikiKando/aiBridge.cpp @@ -544,14 +544,14 @@ int ActBridge::newExeWork() } if (absF(xDist) > 0.3f * mBridge->getStageWidth()) { - STACK_PAD_STRUCT(2); // Vector3f unused(xVec); // This would be more accurate, but it makes the stack worse. + Vector3f unused(xVec); // `STACK_PAD_STRUCT(2)` is a nicer fakematch, but this unused `Vector3f` is accurate to the DLL. if (xDist < 0.0f) { xVec.multiply(-1.0f); } zVec = zVec + xVec; zVec.normalise(); } - f32 unused = mBridge->getStageDepth(); // It looks like this unused result was stored in a variable in the DLL. + f32 unused = mBridge->getStageDepth(); // It looks like this unused result was stored in a variable in the DLL (affects stack). mPiki->setSpeed(0.5f, zVec); return ACTOUT_Continue; /* diff --git a/src/plugPikiKando/pelletMgr.cpp b/src/plugPikiKando/pelletMgr.cpp index a76e1ad8..ac3ec1ab 100644 --- a/src/plugPikiKando/pelletMgr.cpp +++ b/src/plugPikiKando/pelletMgr.cpp @@ -138,25 +138,6 @@ void PelletConfig::read(RandomAccessStream& input) mRepairAnimJointIndex = input.readInt(); } -#if defined(VERSION_GPIJ01) -#else -// see PelletBounceSoundID in Pellet.h -static u32 bounceSounds[] = { - SE_PELLET_BOUND, SE_UFOPARTS_BOUND, SE_UFOPARTS_SPRING, SE_UFOPARTS_MONEYBOX, SE_UFOPARTS_BOUND, SE_UFOPARTS_BOUND, - SE_UFOPARTS_BOUND, SE_UFOPARTS_BOUND, SE_UFOPARTS_BOUND, SE_UFOPARTS_BOUND, SE_UFOPARTS_BOUND, SE_UFOPARTS_BOUND, -}; - -NumberPel numberPellets[13] = { - { PELCOLOR_Blue, NUMPEL_OnePellet, 'pb01' }, { PELCOLOR_Blue, NUMPEL_FivePellet, 'pb05' }, - { PELCOLOR_Blue, NUMPEL_TenPellet, 'pb10' }, { PELCOLOR_Blue, NUMPEL_TwentyPellet, 'pb20' }, - { PELCOLOR_Red, NUMPEL_OnePellet, 'pr01' }, { PELCOLOR_Red, NUMPEL_FivePellet, 'pr05' }, - { PELCOLOR_Red, NUMPEL_TenPellet, 'pr10' }, { PELCOLOR_Red, NUMPEL_TwentyPellet, 'pr20' }, - { PELCOLOR_Yellow, NUMPEL_OnePellet, 'py01' }, { PELCOLOR_Yellow, NUMPEL_FivePellet, 'py05' }, - { PELCOLOR_Yellow, NUMPEL_TenPellet, 'py10' }, { PELCOLOR_Yellow, NUMPEL_TwentyPellet, 'py20' }, - { PELCOLOR_NULL, NUMPEL_NULL, 'ujaa' }, -}; -#endif - /** * @todo: Documentation */ @@ -1058,25 +1039,6 @@ void Pellet::startAI(int doSpawnScaleOff) mIsAIActive = true; } -#if defined(VERSION_GPIJ01) -// see PelletBounceSoundID in Pellet.h -static u32 bounceSounds[] = { - SE_PELLET_BOUND, SE_UFOPARTS_BOUND, SE_UFOPARTS_SPRING, SE_UFOPARTS_MONEYBOX, SE_UFOPARTS_BOUND, SE_UFOPARTS_BOUND, - SE_UFOPARTS_BOUND, SE_UFOPARTS_BOUND, SE_UFOPARTS_BOUND, SE_UFOPARTS_BOUND, SE_UFOPARTS_BOUND, SE_UFOPARTS_BOUND, -}; - -NumberPel numberPellets[13] = { - { PELCOLOR_Blue, NUMPEL_OnePellet, 'pb01' }, { PELCOLOR_Blue, NUMPEL_FivePellet, 'pb05' }, - { PELCOLOR_Blue, NUMPEL_TenPellet, 'pb10' }, { PELCOLOR_Blue, NUMPEL_TwentyPellet, 'pb20' }, - { PELCOLOR_Red, NUMPEL_OnePellet, 'pr01' }, { PELCOLOR_Red, NUMPEL_FivePellet, 'pr05' }, - { PELCOLOR_Red, NUMPEL_TenPellet, 'pr10' }, { PELCOLOR_Red, NUMPEL_TwentyPellet, 'pr20' }, - { PELCOLOR_Yellow, NUMPEL_OnePellet, 'py01' }, { PELCOLOR_Yellow, NUMPEL_FivePellet, 'py05' }, - { PELCOLOR_Yellow, NUMPEL_TenPellet, 'py10' }, { PELCOLOR_Yellow, NUMPEL_TwentyPellet, 'py20' }, - { PELCOLOR_NULL, NUMPEL_NULL, 'ujaa' }, -}; -#else -#endif - /** * @todo: Documentation * @note UNUSED Size: 00007C @@ -1144,6 +1106,12 @@ void Pellet::postUpdate(int unused, f32 deltaTime) } } +// see PelletBounceSoundID in Pellet.h +static u32 bounceSounds[] = { + SE_PELLET_BOUND, SE_UFOPARTS_BOUND, SE_UFOPARTS_SPRING, SE_UFOPARTS_MONEYBOX, SE_UFOPARTS_BOUND, SE_UFOPARTS_BOUND, + SE_UFOPARTS_BOUND, SE_UFOPARTS_BOUND, SE_UFOPARTS_BOUND, SE_UFOPARTS_BOUND, SE_UFOPARTS_BOUND, SE_UFOPARTS_BOUND, +}; + /** * @todo: Documentation */ @@ -1451,6 +1419,16 @@ bool InteractKill::actPellet(Pellet* pellet) immut return true; } +NumberPel numberPellets[13] = { + { PELCOLOR_Blue, NUMPEL_OnePellet, 'pb01' }, { PELCOLOR_Blue, NUMPEL_FivePellet, 'pb05' }, + { PELCOLOR_Blue, NUMPEL_TenPellet, 'pb10' }, { PELCOLOR_Blue, NUMPEL_TwentyPellet, 'pb20' }, + { PELCOLOR_Red, NUMPEL_OnePellet, 'pr01' }, { PELCOLOR_Red, NUMPEL_FivePellet, 'pr05' }, + { PELCOLOR_Red, NUMPEL_TenPellet, 'pr10' }, { PELCOLOR_Red, NUMPEL_TwentyPellet, 'pr20' }, + { PELCOLOR_Yellow, NUMPEL_OnePellet, 'py01' }, { PELCOLOR_Yellow, NUMPEL_FivePellet, 'py05' }, + { PELCOLOR_Yellow, NUMPEL_TenPellet, 'py10' }, { PELCOLOR_Yellow, NUMPEL_TwentyPellet, 'py20' }, + { PELCOLOR_NULL, NUMPEL_NULL, 'ujaa' }, +}; + /** * @todo: Documentation */ diff --git a/src/plugPikiKando/playerState.cpp b/src/plugPikiKando/playerState.cpp index a231b9af..b83d3e58 100644 --- a/src/plugPikiKando/playerState.cpp +++ b/src/plugPikiKando/playerState.cpp @@ -665,7 +665,7 @@ void PlayerState::update() mPerHourGraph.set(mLastUpdatedTime, Red, GameStat::allPikis[Red]); mPerHourGraph.set(mLastUpdatedTime, Yellow, GameStat::allPikis[Yellow]); PRINT("record (%d %d %d) = %d\n", GameStat::allPikis[Blue], GameStat::allPikis[Red], GameStat::allPikis[Yellow], - (int)GameStat::allPikis); + static_cast(GameStat::allPikis)); } } } diff --git a/src/si/SIBios.c b/src/si/SIBios.c index 00b42ded..2d97947a 100644 --- a/src/si/SIBios.c +++ b/src/si/SIBios.c @@ -46,10 +46,10 @@ static void SIClearTCInterrupt() { u32 reg; - reg = __SIRegs[13]; + reg = __SIRegs[SI_CC_STAT]; reg |= 0x80000000; reg &= ~0x00000001; - __SIRegs[13] = reg; + __SIRegs[SI_CC_STAT] = reg; } static u32 CompleteTransfer() @@ -59,7 +59,7 @@ static u32 CompleteTransfer() u32 rLen; u8* input; - sr = __SIRegs[14]; + sr = __SIRegs[SI_STAT]; SIClearTCInterrupt(); @@ -70,19 +70,19 @@ static u32 CompleteTransfer() rLen = Si.inputBytes / 4; for (i = 0; i < rLen; i++) { - *(u32*)input = __SIRegs[32 + i]; + *(u32*)input = __SIRegs[SI_IO_BUFFER + i]; input += 4; } rLen = Si.inputBytes & 3; if (rLen) { - u32 temp = __SIRegs[32 + i]; + u32 temp = __SIRegs[SI_IO_BUFFER + i]; for (i = 0; i < rLen; i++) { *input++ = (u8)((temp >> ((3 - i) * 8)) & 0xff); } } - if (__SIRegs[13] & 0x20000000) { + if (__SIRegs[SI_CC_STAT] & 0x20000000) { sr >>= 8 * (3 - Si.chan); sr &= 0xf; @@ -125,7 +125,7 @@ static void SIInterruptHandler(__OSInterrupt interrupt, OSContext* context) { u32 reg; - reg = __SIRegs[13]; + reg = __SIRegs[SI_CC_STAT]; if ((reg & 0xc0000000) == 0xc0000000) { s32 chan; @@ -143,9 +143,9 @@ static void SIInterruptHandler(__OSInterrupt interrupt, OSContext* context) callback(chan, sr, context); } - sr = __SIRegs[14]; + sr = __SIRegs[SI_STAT]; sr &= 0xf000000 >> (8 * chan); - __SIRegs[14] = sr; + __SIRegs[SI_STAT] = sr; if (Type[chan] == SI_ERROR_BUSY && !SIIsChanBusy(chan)) { static u32 cmdTypeAndStatus = 0 << 24; @@ -197,7 +197,7 @@ static BOOL SIEnablePollingInterrupt(BOOL enable) int i; enabled = OSDisableInterrupts(); - reg = __SIRegs[13]; + reg = __SIRegs[SI_CC_STAT]; rc = (reg & 0x08000000) ? TRUE : FALSE; if (enable) { reg |= 0x08000000; @@ -208,7 +208,7 @@ static BOOL SIEnablePollingInterrupt(BOOL enable) reg &= ~0x08000000; } reg &= ~0x80000001; - __SIRegs[13] = reg; + __SIRegs[SI_CC_STAT] = reg; OSRestoreInterrupts(enabled); return rc; } @@ -270,10 +270,10 @@ void SIInit(void) Si.poll = 0; SISetSamplingRate(0); - while (__SIRegs[13] & 1) + while (__SIRegs[SI_CC_STAT] & 1) ; - __SIRegs[13] = 0x80000000; + __SIRegs[SI_CC_STAT] = 0x80000000; __OSSetInterruptHandler(__OS_INTERRUPT_PI_SI, SIInterruptHandler); __OSUnmaskInterrupts(OS_INTERRUPTMASK_PI_SI); @@ -300,9 +300,9 @@ static BOOL __SITransfer(s32 chan, void* output, u32 outputBytes, void* input, u return FALSE; } - sr = __SIRegs[14]; + sr = __SIRegs[SI_STAT]; sr &= (0xf000000) >> (8 * chan); - __SIRegs[14] = sr; + __SIRegs[SI_STAT] = sr; Si.chan = chan; Si.callback = callback; @@ -311,17 +311,17 @@ static BOOL __SITransfer(s32 chan, void* output, u32 outputBytes, void* input, u rLen = ROUND(outputBytes, 4) / 4; for (i = 0; i < rLen; i++) { - __SIRegs[32 + i] = ((u32*)output)[i]; + __SIRegs[SI_IO_BUFFER + i] = ((u32*)output)[i]; } - comcsr.val = __SIRegs[13]; + comcsr.val = __SIRegs[SI_CC_STAT]; comcsr.flags.tcint = 1; comcsr.flags.tcintmsk = callback ? 1 : 0; comcsr.flags.outlngth = (outputBytes == SI_MAX_COMCSR_OUTLNGTH) ? 0 : outputBytes; comcsr.flags.inlngth = (inputBytes == SI_MAX_COMCSR_INLNGTH) ? 0 : inputBytes; comcsr.flags.channel = chan; comcsr.flags.tstart = 1; - __SIRegs[13] = comcsr.val; + __SIRegs[SI_CC_STAT] = comcsr.val; OSRestoreInterrupts(enabled); @@ -335,7 +335,7 @@ u32 SIGetStatus(s32 chan) int chanShift; enabled = OSDisableInterrupts(); - sr = __SIRegs[14]; + sr = __SIRegs[SI_STAT]; chanShift = 8 * (SI_MAX_CHAN - 1 - chan); sr >>= chanShift; if (sr & SI_ERROR_NO_RESPONSE) { @@ -354,7 +354,7 @@ void SISetCommand(s32 chan, u32 command) void SITransferCommands(void) { - __SIRegs[14] = 0x80000000; + __SIRegs[SI_STAT] = 0x80000000; } u32 SISetXY(u32 x, u32 y) @@ -369,7 +369,7 @@ u32 SISetXY(u32 x, u32 y) Si.poll &= ~(0x03ff0000 | 0x0000ff00); Si.poll |= poll; poll = Si.poll; - __SIRegs[12] = poll; + __SIRegs[SI_POLL] = poll; OSRestoreInterrupts(enabled); return poll; } @@ -400,7 +400,7 @@ u32 SIEnablePolling(u32 poll) SITransferCommands(); - __SIRegs[12] = poll; + __SIRegs[SI_POLL] = poll; OSRestoreInterrupts(enabled); @@ -422,7 +422,7 @@ u32 SIDisablePolling(u32 poll) poll = Si.poll & ~poll; - __SIRegs[12] = poll; + __SIRegs[SI_POLL] = poll; Si.poll = poll; OSRestoreInterrupts(enabled); diff --git a/src/sysCommon/ayuStack.cpp b/src/sysCommon/ayuStack.cpp index 397f26fd..13e8963a 100644 --- a/src/sysCommon/ayuStack.cpp +++ b/src/sysCommon/ayuStack.cpp @@ -194,8 +194,8 @@ AyuCache::AyuCache(u32 cacheSize) PRINT("Creating cache of size %.2f k\n", cacheSize / 1024.0f); s32 alignedSize = OSRoundUp32B(cacheSize); - u32 bufAddr = (u32) new char[(alignedSize / 4) * 4]; - init(bufAddr, bufAddr + alignedSize); + char* bufAddr = new char[(alignedSize / 4) * 4]; + init((u32)bufAddr, (u32)bufAddr + alignedSize); } /** diff --git a/src/sysCommon/shapeBase.cpp b/src/sysCommon/shapeBase.cpp index e6db4d91..2a33e403 100644 --- a/src/sysCommon/shapeBase.cpp +++ b/src/sysCommon/shapeBase.cpp @@ -1786,7 +1786,7 @@ BaseShape::BaseShape() mTexCoordList[7] = nullptr; mNormalList = nullptr; - mNBTList = 0; + mNBTList = nullptr; mFallbackTexAttrCount = 0; mAttrListMatCount = 0; mResolvedTextureList = nullptr; diff --git a/src/sysDolphin/dgxGraphics.cpp b/src/sysDolphin/dgxGraphics.cpp index ae7e1827..92aa7b1a 100644 --- a/src/sysDolphin/dgxGraphics.cpp +++ b/src/sysDolphin/dgxGraphics.cpp @@ -219,7 +219,7 @@ DGXGraphics::DGXGraphics(bool flag) mDisplayBuffer = new (0x20) u8[sFrameSize]; -#if defined(VERSION_GPIJ01) || defined(VERSION_G98P01_PIKIDEMO) +#if defined(VERSION_GPIJ01) || defined(VERSION_DPIJ01_PIKIDEMO) || defined(VERSION_G98P01_PIKIDEMO) #else u16* test = (u16*)mDisplayBuffer; for (int i = 0; i < sFrameSize / 2; i++) { @@ -238,7 +238,7 @@ DGXGraphics::DGXGraphics(bool flag) VIWaitForRetrace(); #endif -#if defined(VERSION_GPIJ01) || defined(VERSION_G98P01_PIKIDEMO) +#if defined(VERSION_GPIJ01) || defined(VERSION_DPIJ01_PIKIDEMO) || defined(VERSION_G98P01_PIKIDEMO) directErase(AREA_FULL_SCREEN(*this), true); #else #endif @@ -251,7 +251,7 @@ DGXGraphics::DGXGraphics(bool flag) mRetraceCallback = VISetPostRetraceCallback(retraceProc); OSInitMessageQueue(&mPostRetraceMsgQueue, &mPostRetraceMsgBuffer, 1); -#if defined(VERSION_GPIJ01) || defined(VERSION_G98P01_PIKIDEMO) +#if defined(VERSION_GPIJ01) || defined(VERSION_DPIJ01_PIKIDEMO) || defined(VERSION_G98P01_PIKIDEMO) VISetBlack(TRUE); VIFlush(); VIWaitForRetrace(); @@ -305,7 +305,7 @@ void DGXGraphics::videoReset() sFirstFrame = 2; -#if defined(VERSION_GPIE01_00) || defined(VERSION_GPIJ01) || defined(VERSION_G98P01_PIKIDEMO) +#if defined(VERSION_GPIE01_00) || defined(VERSION_GPIJ01) || defined(VERSION_DPIJ01_PIKIDEMO) || defined(VERSION_G98P01_PIKIDEMO) __VIInit(mRenderMode == 0 ? VI_TVMODE_NTSC_INT : VI_TVMODE_NTSC_PROG); #endif @@ -519,7 +519,7 @@ void DGXGraphics::initRender(int a1, int a2) mActiveTexture[5] = nullptr; mActiveTexture[6] = nullptr; mActiveTexture[7] = nullptr; - mCustomScale = 0; + mCustomScale = nullptr; gsys->resetLFlares(); } @@ -564,7 +564,7 @@ void DGXGraphics::waitRetrace() if (sFirstFrame) { sFirstFrame--; if (sFirstFrame == 0) { -#if defined(VERSION_GPIJ01) || defined(VERSION_G98P01_PIKIDEMO) +#if defined(VERSION_GPIJ01) || defined(VERSION_DPIJ01_PIKIDEMO) || defined(VERSION_G98P01_PIKIDEMO) VISetBlack(FALSE); #else #endif