From ed376ef2ef149cf91e7e343bbcaddaf644029b47 Mon Sep 17 00:00:00 2001 From: Cuyler36 Date: Sat, 21 Jun 2025 05:24:59 -0400 Subject: [PATCH] jaudio_NES: match & link dsp_cardunlock --- configure.py | 2 +- include/MSL_C/rand.h | 8 ++++ include/dolphin/exi.h | 8 ++++ src/static/dolphin/card/__card.h | 10 ++++- .../jaudio_NES/internal/dsp_cardunlock.c | 42 ++++++++++++------- 5 files changed, 53 insertions(+), 17 deletions(-) diff --git a/configure.py b/configure.py index 36c53bb8..33222ae5 100644 --- a/configure.py +++ b/configure.py @@ -768,7 +768,7 @@ config.libs = [ Object(NonMatching, "jaudio_NES/internal/connect.c"), Object(NonMatching, "jaudio_NES/internal/driver.c"), Object(NonMatching, "jaudio_NES/internal/driverinterface.c"), - Object(NonMatching, "jaudio_NES/internal/dsp_cardunlock.c"), + Object(Matching, "jaudio_NES/internal/dsp_cardunlock.c"), Object(NonMatching, "jaudio_NES/internal/dsp_GBAKey.c"), Object(NonMatching, "jaudio_NES/internal/dspdriver.c"), Object(NonMatching, "jaudio_NES/internal/dspinterface.c"), diff --git a/include/MSL_C/rand.h b/include/MSL_C/rand.h index daed9b2e..94432696 100644 --- a/include/MSL_C/rand.h +++ b/include/MSL_C/rand.h @@ -2,7 +2,15 @@ #define RAND_H #include "types.h" +#ifdef __cplusplus +extern "C" { +#endif + void srand(u32 seed); int rand(void); +#ifdef __cplusplus +} +#endif + #endif diff --git a/include/dolphin/exi.h b/include/dolphin/exi.h index e1e90489..3802b36f 100644 --- a/include/dolphin/exi.h +++ b/include/dolphin/exi.h @@ -3,6 +3,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + typedef enum { EXI_STATE_DMA_ACCESS = (1 << 0), EXI_STATE_IMM_ACCESS = (1 << 1), @@ -47,4 +51,8 @@ u32 EXIGetState(s32 channel); s32 EXIGetID(s32 channel, u32 device, u32* id); void EXIProbeReset(void); +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/static/dolphin/card/__card.h b/src/static/dolphin/card/__card.h index 03db3bea..221543af 100644 --- a/src/static/dolphin/card/__card.h +++ b/src/static/dolphin/card/__card.h @@ -4,6 +4,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + #define CARDIsValidBlockNo(card, iBlock) (CARD_NUM_SYSTEM_BLOCK <= (iBlock) && (iBlock) < (card)->cBlock) // CARDStatEx.c @@ -12,7 +16,7 @@ long __CARDSetStatusExAsync(long chan, long fileNo, struct CARDDir * dirent, voi long __CARDSetStatusEx(long chan, long fileNo, struct CARDDir * dirent); // CARDUnlock.c -s32 __CARDUnlock(s32 chan, u8 flashID[12]); +// s32 __CARDUnlock(s32 chan, u8 flashID[12]); // CARDRead.c s32 __CARDSeek(CARDFileInfo *fileInfo, s32 length, s32 offset, CARDControl **pcard); @@ -87,4 +91,8 @@ s32 __CARDGetControlBlock(s32 chan, CARDControl **pcard); s32 __CARDPutControlBlock(CARDControl *card, s32 result); s32 __CARDSync(s32 chan); +#ifdef __cplusplus +} +#endif + #endif // _DOLPHIN_CARD_INTERNAL_H_ diff --git a/src/static/jaudio_NES/internal/dsp_cardunlock.c b/src/static/jaudio_NES/internal/dsp_cardunlock.c index 9b0cb629..7f0dd3c7 100644 --- a/src/static/jaudio_NES/internal/dsp_cardunlock.c +++ b/src/static/jaudio_NES/internal/dsp_cardunlock.c @@ -1,10 +1,13 @@ +#undef DEBUG +#define DEBUG 1 + #include "jaudio_NES/dsp_cardunlock.h" -#include "dolphin/os.h" -#include "dolphin/card.h" #include "MSL_C/rand.h" #include "jaudio_NES/ipldec.h" #include "_mem.h" +#include "dolphin/os.h" +#include "dolphin/card.h" #include "card/__card.h" #define DATA_SCRAMBLE_R(data) (~(data ^ (data >> 7) ^ (data >> 15) ^ (data >> 23))) @@ -72,7 +75,7 @@ static u32 bitrev(u32 data) */ static s32 ReadArrayUnlock(s32 chan, u32 data, void* rbuf, s32 length, BOOL mode) { - ASSERTLINE(216, 0 <= chan && chan < 2); + ASSERTLINE(217, 0 <= chan && chan < 2); CARDControl* card = &__CARDBlock[chan]; if (!EXISelect(chan, 0, 4)) @@ -133,7 +136,12 @@ static u32 DummyLen() srand(result); result = (rand() & 0x1f) + 1; } - return result < 4 ? 4 : result; + + if (result < 4) { + result = 4; + } + + return result; } static void InitCallback(void* dspTask); @@ -155,19 +163,26 @@ int __CARDUnlock(int chan, u8 flashID[12]) { u32 Ans1, Ans2; u8 rbuf[64]; - - // The nonsense + u32 para1A; + u32 para1B; + u32 para2A; + u32 para2B; + + // The nonsense CARDControl* card = &__CARDBlock[chan]; DSPTaskInfo* task = &card->task; CARDDecodeParameters* param = (CARDDecodeParameters*)card->workArea; u8* input = (u8*)param + sizeof(CARDDecodeParameters); input = (u8*)OSRoundUp32B(input); u8* output = input + 32; - + u32 data; s32 dummy; s32 rlen; + u32 shift; + u32 wk; + data = GetInitVal(); dummy = DummyLen(); rlen = dummy; @@ -177,9 +192,6 @@ int __CARDUnlock(int chan, u8 flashID[12]) // TODO: Pikmin uses `card->formatStep`, but every other // decomp uses `card->scramble`. What's up with that? - u32 shift; - u32 wk; - shift = dummy * 8 + 1; wk = exnor_1st(data, shift); card->formatStep = wk | (DATA_SCRAMBLE_R(wk) << 31 & 0x80000000); @@ -191,11 +203,11 @@ int __CARDUnlock(int chan, u8 flashID[12]) if (ReadArrayUnlock(chan, data, rbuf, rlen, TRUE) < CARD_RESULT_READY) return CARD_RESULT_NOCARD; - u32 para1A = *(u32*)(rbuf + 0); - u32 para1B = *(u32*)(rbuf + 4); + para1A = *(u32*)(rbuf + 0); + para1B = *(u32*)(rbuf + 4); Ans1 = *(u32*)(rbuf + 8); - u32 para2A = *(u32*)(rbuf + 12); - u32 para2B = *(u32*)(rbuf + 16); + para2A = *(u32*)(rbuf + 12); + para2B = *(u32*)(rbuf + 16); para1A ^= card->formatStep; shift = 32; @@ -277,7 +289,7 @@ static void DoneCallback(void* dspTask) break; } } - ASSERTLINE(548, 0 <= chan && chan < 2); + ASSERTLINE(549, 0 <= chan && chan < 2); // The nonsense CARDDecodeParameters* param = (CARDDecodeParameters*)card->workArea;