From e2a793a1c176960bd7a1055841ae7fa38d6ebaf9 Mon Sep 17 00:00:00 2001 From: HeartPiece Date: Fri, 10 Feb 2023 20:59:00 +1100 Subject: [PATCH] Link CARDBios, Block, Unlock (from Prime) ily primers Co-Authored-By: Phillip Stephens --- Makefile | 2 +- configure.py | 8 +- docs/recommended_todo.md | 26 +- include/Dolphin/card.h | 19 +- include/Dolphin/exi.h | 36 +- src/Dolphin/card/CARDBios.c | 2132 ++++++++------------------------- src/Dolphin/card/CARDBlock.c | 392 ++---- src/Dolphin/card/CARDUnlock.c | 1624 +++++-------------------- src/Dolphin/card/Makefile | 16 +- tools/progress.csv | 6 + 10 files changed, 1034 insertions(+), 3227 deletions(-) diff --git a/Makefile b/Makefile index 1998d0231..f44d633ae 100644 --- a/Makefile +++ b/Makefile @@ -75,7 +75,7 @@ include obj_files.mk O_FILES := $(JSYSTEM) $(DOLPHIN) $(PLUGPROJECT) $(SYS) $(UTILITY) ifeq ($(EPILOGUE_PROCESS),1) -E_FILES := $(AR_UNSCHEDULED) $(DSP_UNSCHEDULED) $(DVD_UNSCHEDULED) $(OS_UNSCHEDULED) $(PAD_UNSCHEDULED) $(SI_UNSCHEDULED) $(GBA_UNSCHEDULED) +E_FILES := $(AR_UNSCHEDULED) $(CARD_UNSCHEDULED) $(DSP_UNSCHEDULED) $(DVD_UNSCHEDULED) $(OS_UNSCHEDULED) $(PAD_UNSCHEDULED) $(SI_UNSCHEDULED) $(GBA_UNSCHEDULED) endif DEPENDS := $($(filter *.o,O_FILES):.o=.d) DEPENDS += $($(filter *.o,E_FILES):.o=.d) diff --git a/configure.py b/configure.py index 6b1608476..7ecc53acf 100755 --- a/configure.py +++ b/configure.py @@ -606,13 +606,13 @@ LIBS = [ { "lib": "card", "mw_version": "1.2.5e", - "cflags": "$cflags_base", + "cflags": "$cflags_base -str noreadonly", "host": False, "objects": [ - "Dolphin/card/CARDBios", - "Dolphin/card/CARDUnlock", + ["Dolphin/card/CARDBios", True], + ["Dolphin/card/CARDUnlock", True], "Dolphin/card/CARDRdwr", - "Dolphin/card/CARDBlock", + ["Dolphin/card/CARDBlock", True], "Dolphin/card/CARDDir", "Dolphin/card/CARDCheck", "Dolphin/card/CARDMount", diff --git a/docs/recommended_todo.md b/docs/recommended_todo.md index 1745b87cd..3b9cc61b9 100644 --- a/docs/recommended_todo.md +++ b/docs/recommended_todo.md @@ -22,23 +22,23 @@ | TRK_MINNOW_DOLPHIN/targsupp.c | 326 | gx/GXDisplayList.c | 647 | | Runtime/__init_cpp_exceptions.cpp | 659 | Runtime/global_destructor_chain.c | 965 | | card/CARDNet.c | 2505 | mtx/mtxvec.c | 3122 | -| card/CARDDir.c | 4548 | TRK_MINNOW_DOLPHIN/mslsupp.c | 4555 | -| TRK_MINNOW_DOLPHIN/CircleBuffer.c | 4715 | TRK_MINNOW_DOLPHIN/serpoll.c | 4793 | -| card/CARDRdwr.c | 4881 | dsp/dsp.c | 4915 | -| ar/arq.c | 4946 | TRK_MINNOW_DOLPHIN/mpc_7xx_603e.c | 5554 | -| MSL_C/mem_funcs.c | 5682 | mtx/mtx44.c | 5987 | -| MSL_C/direct_io.c | 6259 | os/OSMemory.c | 6385 | -| os/OSReboot.c | 6397 | card/CARDWrite.c | 6434 | -| card/CARDCreate.c | 6611 | os/OSResetSW.c | 6856 | -| os/OSError.c | 6937 | gx/GXGeometry.c | 6983 | -| card/CARDBlock.c | 7163 | thp/THPAudio.c | 7974 | +| card/CARDBlock.c | 3467 | card/CARDDir.c | 4548 | +| TRK_MINNOW_DOLPHIN/mslsupp.c | 4555 | TRK_MINNOW_DOLPHIN/CircleBuffer.c | 4715 | +| TRK_MINNOW_DOLPHIN/serpoll.c | 4793 | card/CARDRdwr.c | 4881 | +| dsp/dsp.c | 4915 | ar/arq.c | 4946 | +| TRK_MINNOW_DOLPHIN/mpc_7xx_603e.c | 5554 | MSL_C/mem_funcs.c | 5682 | +| mtx/mtx44.c | 5987 | MSL_C/direct_io.c | 6259 | +| os/OSMemory.c | 6385 | os/OSReboot.c | 6397 | +| card/CARDWrite.c | 6434 | card/CARDCreate.c | 6611 | +| os/OSResetSW.c | 6856 | os/OSError.c | 6937 | +| gx/GXGeometry.c | 6983 | thp/THPAudio.c | 7974 | | os/OSReset.c | 8122 | os/OSTime.c | 8247 | | card/CARDRead.c | 8271 | os/OSMutex.c | 8303 | | card/CARDOpen.c | 8692 | card/CARDStat.c | 8905 | | TRK_MINNOW_DOLPHIN/dolphin_trk_glue.c | 10320 | exi/EXIUart.c | 10329 | -| TRK_MINNOW_DOLPHIN/dolphin_trk.c | 11230 | ar/ar.c | 11920 | -| MSL_C/alloc.c | 12018 | TRK_MINNOW_DOLPHIN/support.c | 12046 | -| gx/GXTransform.c | 12379 | card/CARDFormat.c | 13901 | +| TRK_MINNOW_DOLPHIN/dolphin_trk.c | 11230 | card/CARDUnlock.c | 11441 | +| ar/ar.c | 11920 | MSL_C/alloc.c | 12018 | +| TRK_MINNOW_DOLPHIN/support.c | 12046 | gx/GXTransform.c | 12379 | ###
JSystem
| File | Size (bytes) | File | Size (bytes) | diff --git a/include/Dolphin/card.h b/include/Dolphin/card.h index ce6ac7659..6c8c8ea89 100644 --- a/include/Dolphin/card.h +++ b/include/Dolphin/card.h @@ -176,7 +176,7 @@ struct CARDDirectoryBlock { struct CARDFatBlock { u16 checkSum; // _00 u16 checkSumInv; // _02 - s16 checkCode; // _04 + u16 checkCode; // _04 u16 freeBlocks; // _06 u16 lastAllocBlock; // _08 u16 allocMap[0xFFB]; // _0A @@ -192,6 +192,14 @@ struct CARDMemoryCard { CARDFatBlock blockAllocMapBackup; // _8000 }; +// Struct for use in CARDUnlock. +typedef struct CARDDecodeParameters { + u8* inputAddr; // _00 + u32 inputLength; // _04 + u32 aramAddr; // _08 + u8* outputAddr; // _0C +} CARDDecodeParameters; + // Enum for 'permission' in CARDDir. typedef enum { FilePermPublic = 0x2, FilePermNoCopy = 0x4, FilePermNoMove = 0x8 } CARDFilePermissions; @@ -217,7 +225,7 @@ s32 CARDCheck(s32 channel); s32 CARDCheckExAsync(s32 channel, s32* xferBytes, CARDCallback callback); // CARD BIOS functions. -s32 CARDFreeBlocks(s32 channel, s32* byteNoteUsed, s32* filesNotUsed); +s32 CARDFreeBlocks(s32 channel, s32* byteNotUsed, s32* filesNotUsed); // CARD mounting functions. BOOL CARDProbe(s32 channel); @@ -269,17 +277,20 @@ void __CARDUnlockedHandler(s32 channel, OSContext* context); s32 __CARDEnableInterrupt(s32 channel, BOOL enable); s32 __CARDReadStatus(s32 channel, u8* status); s32 __CARDClearStatus(s32 channel); -s32 __CARDStart(s32 channel, CARDCallback c8callback, CARDCallback doneWriteCallback); +s32 __CARDStart(s32 channel, CARDCallback txCallback, CARDCallback exiCallback); s32 __CARDReadSegment(s32 channel, CARDCallback callback); s32 __CARDWritePage(s32 channel, CARDCallback callback); s32 __CARDEraseSector(s32 channel, u32 addr, CARDCallback callback); u16 __CARDGetFontEncode(); -void __CARDSetDiskID(u8* diskID); +void __CARDSetDiskID(const DVDDiskID* diskID); s32 __CARDGetControlBlock(s32 channel, CARDControl** card); s32 __CARDPutControlBlock(CARDControl* card, s32 result); s32 __CARDSync(s32 channel); void __CARDCheckSum(void* data, int length, u16* checksum, u16* checksumInv); +CARDDir* __CARDGetDirBlock(CARDControl* card); +CARDFatBlock* __CARDGetFatBlock(CARDControl* card); + //////////////////////////////////////////// //////////// OTHER CARD DEFINES //////////// diff --git a/include/Dolphin/exi.h b/include/Dolphin/exi.h index 793534b0b..28ed072ec 100644 --- a/include/Dolphin/exi.h +++ b/include/Dolphin/exi.h @@ -8,30 +8,24 @@ extern "C" { #endif // ifdef __cplusplus -typedef unknown EXICallback(int slotIndex); - -typedef enum { EXIResultMinusOne = -1, EXIResultZero = 0, EXIResultOne = 1 } EXIResult; - void EXIInit(); -EXIResult EXIImm(int slotIndex, u8* p2, int byteCount, int p4, unknown p5); -EXIResult EXIImmEx(int slotIndex, u8* p2, int byteCount, int p4); -EXIResult EXIDma(int slotIndex, unknown p2, unknown p3, unknown p4, unknown p5); -EXIResult EXISync(int slotIndex); -EXIResult EXIClearInterrupts(int slotIndex, unknown p2, unknown p3, unknown p4); -EXICallback* EXISetExiCallback(int slotIndex, EXICallback* callback); -EXIResult EXIProbe(int slotIndex); -EXIResult EXIProbeEx(int slotIndex); -EXIResult EXIAttach(int slotIndex, unknown p2); -EXIResult EXIDetach(int slotIndex); -EXIResult EXISelect(int slotIndex, unknown p2, unknown p3); -EXIResult EXIDeselect(int slotIndex); +BOOL EXIImm(s32 channel, void* buffer, s32 length, u32 type, EXICallback callback); +BOOL EXIImmEx(s32 channel, void* buffer, s32 length, u32 type); +BOOL EXIDma(s32 channel, void* buffer, s32 length, u32 type, EXICallback callback); +BOOL EXISync(s32 channel); +BOOL EXIClearInterrupts(s32 channel, BOOL clearExiBit, BOOL clearTcBit, BOOL clearExtBit); +EXICallback EXISetExiCallback(s32 channel, EXICallback callback); +BOOL EXIAttach(s32 channel, EXICallback callback); +BOOL EXIDetach(s32 channel); +BOOL EXISelect(s32 channel, u32 device, u32 frequency); +BOOL EXIDeselect(s32 channel); // sic -void EXIIntrruptHandler(unknown p1, OSContext* context); -EXIResult EXILock(int slotIndex, unknown p2, unknown p3); -EXIResult EXIUnlock(int slotIndex); -uint EXIGetState(int slotIndex); -EXIResult EXIGetID(int slotIndex, unknown p2, u8* p3); +void EXIIntrruptHandler(__OSInterrupt interrupt, OSContext* context); +BOOL EXILock(s32 channel, u32 device, EXICallback callback); +BOOL EXIUnlock(s32 channel); +u32 EXIGetState(s32 channel); +s32 EXIGetID(s32 channel, u32 device, u32* id); #ifdef __cplusplus }; diff --git a/src/Dolphin/card/CARDBios.c b/src/Dolphin/card/CARDBios.c index be1262086..86f2d40a0 100644 --- a/src/Dolphin/card/CARDBios.c +++ b/src/Dolphin/card/CARDBios.c @@ -2,277 +2,129 @@ #include "Dolphin/exi.h" #include "types.h" -CARDBlock __CARDBlock[2]; -u8 __CARDDiskNone[0x20]; // unknown struct +const char* __CARDVersion = "<< Dolphin SDK - CARD\trelease build: Apr 17 2003 12:34:19 (0x2301) >>"; -BOOL OnReset(unknown p1); -int Retry(int slotIndex); -void TimeoutHandler(OSAlarm* alarm); +CARDControl __CARDBlock[2]; +DVDDiskID __CARDDiskNone; + +static u16 __CARDEncode; + +s32 __CARDReadStatus(s32 chan, u8* status); +s32 __CARDClearStatus(s32 chan); +void __CARDSetDiskID(const DVDDiskID* id); +static s32 Retry(s32 chan); +BOOL OnReset(BOOL f); + +static OSResetFunctionInfo ResetFunctionInfo = { OnReset, 127 }; + +// bit manip stuff for __CARDReadSegment, __CARDWritePage, __CARDEraseSector +#define AD1(x) ((u8)(((x) >> 17) & 0x7f)) +#define AD1EX(x) ((u8)(AD1(x) | 0x80)); +#define AD2(x) ((u8)(((x) >> 9) & 0xff)) +#define AD3(x) ((u8)(((x) >> 7) & 0x03)) +#define BA(x) ((u8)((x)&0x7f)) /* * --INFO-- * Address: 800D466C * Size: 000004 */ -void __CARDDefaultApiCallback(void) { } +void __CARDDefaultApiCallback(s32 channel, s32 result) { } /* * --INFO-- * Address: 800D4670 * Size: 000034 */ -void __CARDSyncCallback(int slotIndex, int p2) -{ - OSWakeupThread(&__CARDBlock[slotIndex]._08C); - /* - .loc_0x0: - mflr r0 - mulli r4, r3, 0x110 - stw r0, 0x4(r1) - lis r3, 0x804F - stwu r1, -0x8(r1) - addi r0, r3, 0x5AF0 - add r3, r0, r4 - addi r3, r3, 0x8C - bl 0x1E348 - lwz r0, 0xC(r1) - addi r1, r1, 0x8 - mtlr r0 - blr - */ -} +void __CARDSyncCallback(s32 channel, s32 result) { OSWakeupThread(&__CARDBlock[channel].threadQueue); } /* * --INFO-- * Address: 800D46A4 * Size: 0000D8 */ -void __CARDExtHandler(int slotIndex) +void __CARDExtHandler(s32 channel, OSContext* context) { - CARDBlockDoneWriteCallback* doneWriteCallback; - CARDBlockC4Callback* c4Callback; - CARDBlock* block = &__CARDBlock[slotIndex]; - if (block->_000 != 0) { - block->_000 = 0; - EXISetExiCallback(slotIndex, nullptr); - OSCancelAlarm(&block->_0E0); - doneWriteCallback = block->doneWriteCallback; - if (doneWriteCallback) { - block->doneWriteCallback = nullptr; - doneWriteCallback(slotIndex, -3); + CARDControl* card; + CARDCallback callback; + + card = &__CARDBlock[channel]; + if (card->attached) { + card->attached = FALSE; + EXISetExiCallback(channel, nullptr); + OSCancelAlarm(&card->alarm); + callback = card->exiCallback; + + if (callback) { + card->exiCallback = nullptr; + callback(channel, CARD_RESULT_NOCARD); } - if (block->_004 != -1) { - block->_004 = -3; + + if (card->result != CARD_RESULT_BUSY) { + card->result = CARD_RESULT_NOCARD; } - c4Callback = block->_0C4; - if (c4Callback != nullptr && 6 < block->_024) { - block->_0C4 = nullptr; - c4Callback(slotIndex, -3); + + callback = card->extCallback; + if (callback && CARD_MAX_MOUNT_STEP <= card->mountStep) { + card->extCallback = nullptr; + callback(channel, CARD_RESULT_NOCARD); } } - /* - .loc_0x0: - mflr r0 - stw r0, 0x4(r1) - stwu r1, -0x20(r1) - stw r31, 0x1C(r1) - stw r30, 0x18(r1) - stw r29, 0x14(r1) - addi r29, r3, 0 - mulli r4, r29, 0x110 - lis r3, 0x804F - addi r0, r3, 0x5AF0 - add r30, r0, r4 - lwz r0, 0x0(r30) - cmpwi r0, 0 - beq- .loc_0xBC - li r31, 0 - stw r31, 0x0(r30) - addi r3, r29, 0 - li r4, 0 - bl 0xBBD8 - addi r3, r30, 0xE0 - bl 0x176E0 - lwz r0, 0xCC(r30) - cmplwi r0, 0 - mr r12, r0 - beq- .loc_0x78 - stw r31, 0xCC(r30) - mtlr r12 - addi r3, r29, 0 - li r4, -0x3 - blrl - - .loc_0x78: - lwz r0, 0x4(r30) - cmpwi r0, -0x1 - beq- .loc_0x8C - li r0, -0x3 - stw r0, 0x4(r30) - - .loc_0x8C: - lwz r12, 0xC4(r30) - cmplwi r12, 0 - beq- .loc_0xBC - lwz r0, 0x24(r30) - cmpwi r0, 0x7 - blt- .loc_0xBC - li r0, 0 - mtlr r12 - stw r0, 0xC4(r30) - addi r3, r29, 0 - li r4, -0x3 - blrl - - .loc_0xBC: - lwz r0, 0x24(r1) - lwz r31, 0x1C(r1) - lwz r30, 0x18(r1) - lwz r29, 0x14(r1) - addi r1, r1, 0x20 - mtlr r0 - blr - */ } -inline int __CARDUnknownInline(int slotIndex) -{ - u8 status[0xC]; - int v1; -} +// inline int __CARDUnknownInline(int slotIndex) +// { +// u8 status[0xC]; +// int v1; +// } /* * --INFO-- * Address: 800D477C * Size: 000118 */ -void __CARDExiHandler(int slotIndex) +void __CARDExiHandler(s32 channel, OSContext* context) { - int v1; - u8 status[0xC]; - CARDBlockDoneWriteCallback* cb; - CARDBlock* block = &__CARDBlock[slotIndex]; - OSCancelAlarm(&block->_0E0); - if (block->_000 == 0) { + + CARDControl* card; + CARDCallback callback; + u8 status; + s32 result; + + card = &__CARDBlock[channel]; + + OSCancelAlarm(&card->alarm); + + if (!card->attached) { return; } - if (EXILock(slotIndex, 0, 0) == EXIResultZero) { - v1 = -0x80; - } else { - v1 = __CARDReadStatus(slotIndex, status); - if (0 > v1) { - goto unlock; - } - v1 = __CARDClearStatus(slotIndex); - if (0 > v1) { - goto unlock; - } - if ((status[0] & 0x18) == 0) { - v1 = 0; - } else { - v1 = -5; - } - if (v1 == -5 && 0 < --block->_0A8) { - v1 = Retry(slotIndex); - if (0 > v1) { - goto doCallback; - } + + if (!EXILock(channel, 0, 0)) { + result = CARD_RESULT_FATAL_ERROR; + goto fatal; + } + + if ((result = __CARDReadStatus(channel, &status)) < 0 || (result = __CARDClearStatus(channel)) < 0) { + goto error; + } + + if ((result = (status & 0x18) ? CARD_RESULT_IOERROR : CARD_RESULT_READY) == CARD_RESULT_IOERROR && --card->retry > 0) { + result = Retry(channel); + if (result >= 0) { return; } - unlock: - EXIUnlock(slotIndex); + goto fatal; } -doCallback: - cb = block->doneWriteCallback; - if (cb) { - block->doneWriteCallback = nullptr; - cb(slotIndex, v1); + +error: + EXIUnlock(channel); + +fatal: + callback = card->exiCallback; + if (callback) { + card->exiCallback = nullptr; + callback(channel, result); } - /* - .loc_0x0: - mflr r0 - stw r0, 0x4(r1) - stwu r1, -0x28(r1) - stw r31, 0x24(r1) - addi r31, r3, 0 - mulli r4, r31, 0x110 - stw r30, 0x20(r1) - lis r3, 0x804F - stw r29, 0x1C(r1) - addi r0, r3, 0x5AF0 - add r30, r0, r4 - addi r3, r30, 0xE0 - bl 0x17628 - lwz r0, 0x0(r30) - cmpwi r0, 0 - beq- .loc_0xFC - addi r3, r31, 0 - li r4, 0 - li r5, 0 - bl 0xC7A8 - cmpwi r3, 0 - bne- .loc_0x60 - li r29, -0x80 - b .loc_0xD4 - - .loc_0x60: - addi r3, r31, 0 - addi r4, r1, 0x10 - bl 0x29C - mr. r29, r3 - blt- .loc_0xCC - mr r3, r31 - bl 0x37C - mr. r29, r3 - blt- .loc_0xCC - lbz r0, 0x10(r1) - rlwinm. r0,r0,0,27,28 - beq- .loc_0x98 - li r0, -0x5 - b .loc_0x9C - - .loc_0x98: - li r0, 0 - - .loc_0x9C: - mr r29, r0 - cmpwi r29, -0x5 - bne- .loc_0xCC - lwz r3, 0xA8(r30) - subic. r0, r3, 0x1 - stw r0, 0xA8(r30) - ble- .loc_0xCC - mr r3, r31 - bl 0x488 - mr. r29, r3 - blt- .loc_0xD4 - b .loc_0xFC - - .loc_0xCC: - mr r3, r31 - bl 0xC818 - - .loc_0xD4: - lwz r0, 0xCC(r30) - cmplwi r0, 0 - mr r12, r0 - beq- .loc_0xFC - li r0, 0 - mtlr r12 - stw r0, 0xCC(r30) - addi r3, r31, 0 - addi r4, r29, 0 - blrl - - .loc_0xFC: - lwz r0, 0x2C(r1) - lwz r31, 0x24(r1) - lwz r30, 0x20(r1) - lwz r29, 0x1C(r1) - addi r1, r1, 0x28 - mtlr r0 - blr - */ } /* @@ -280,61 +132,20 @@ doCallback: * Address: 800D4894 * Size: 0000A8 */ -void __CARDTxHandler(void) +void __CARDTxHandler(s32 channel, OSContext* context) { - /* - .loc_0x0: - mflr r0 - stw r0, 0x4(r1) - stwu r1, -0x28(r1) - stmw r27, 0x14(r1) - addi r27, r3, 0 - lis r3, 0x804F - addi r0, r3, 0x5AF0 - mulli r4, r27, 0x110 - addi r3, r27, 0 - add r29, r0, r4 - bl 0xC020 - cntlzw r0, r3 - addi r3, r27, 0 - rlwinm r31,r0,27,5,31 - bl 0xC798 - lwz r0, 0xC8(r29) - cmplwi r0, 0 - mr r28, r0 - beq- .loc_0x94 - li r30, 0 - cmpwi r31, 0 - stw r30, 0xC8(r29) - bne- .loc_0x70 - mr r3, r27 - bl 0xBBC0 - cmpwi r3, 0 - beq- .loc_0x70 - li r30, 0x1 + CARDControl* card; + CARDCallback callback; + BOOL err; - .loc_0x70: - cmpwi r30, 0 - beq- .loc_0x80 - li r4, 0 - b .loc_0x84 - - .loc_0x80: - li r4, -0x3 - - .loc_0x84: - addi r12, r28, 0 - mtlr r12 - addi r3, r27, 0 - blrl - - .loc_0x94: - lmw r27, 0x14(r1) - lwz r0, 0x2C(r1) - addi r1, r1, 0x28 - mtlr r0 - blr - */ + card = &__CARDBlock[channel]; + err = !EXIDeselect(channel); + EXIUnlock(channel); + callback = card->txCallback; + if (callback) { + card->txCallback = nullptr; + callback(channel, (!err && EXIProbe(channel)) ? CARD_RESULT_READY : CARD_RESULT_NOCARD); + } } /* @@ -342,50 +153,17 @@ void __CARDTxHandler(void) * Address: 800D493C * Size: 000084 */ -void __CARDUnlockedHandler(void) +void __CARDUnlockedHandler(s32 channel, OSContext* context) { - /* - .loc_0x0: - mflr r0 - stw r0, 0x4(r1) - stwu r1, -0x18(r1) - stw r31, 0x14(r1) - stw r30, 0x10(r1) - addi r30, r3, 0 - mulli r4, r30, 0x110 - lis r3, 0x804F - addi r0, r3, 0x5AF0 - add r3, r0, r4 - lwz r0, 0xDC(r3) - cmplwi r0, 0 - mr r31, r0 - beq- .loc_0x6C - li r0, 0 - stw r0, 0xDC(r3) - mr r3, r30 - bl 0xBB34 - cmpwi r3, 0 - beq- .loc_0x58 - li r4, 0x1 - b .loc_0x5C + CARDControl* card; + CARDCallback callback; - .loc_0x58: - li r4, -0x3 - - .loc_0x5C: - addi r12, r31, 0 - mtlr r12 - addi r3, r30, 0 - blrl - - .loc_0x6C: - lwz r0, 0x1C(r1) - lwz r31, 0x14(r1) - lwz r30, 0x10(r1) - addi r1, r1, 0x18 - mtlr r0 - blr - */ + card = &__CARDBlock[channel]; + callback = card->unlockCallback; + if (callback) { + card->unlockCallback = nullptr; + callback(channel, EXIProbe(channel) ? CARD_RESULT_UNLOCKED : CARD_RESULT_NOCARD); + } } /* @@ -393,69 +171,21 @@ void __CARDUnlockedHandler(void) * Address: 800D49C0 * Size: 0000C0 */ -void __CARDEnableInterrupt(void) +s32 __CARDEnableInterrupt(s32 channel, BOOL enable) { - /* - .loc_0x0: - mflr r0 - li r5, 0x4 - stw r0, 0x4(r1) - stwu r1, -0x20(r1) - stw r31, 0x1C(r1) - addi r31, r4, 0 - li r4, 0 - stw r30, 0x18(r1) - addi r30, r3, 0 - bl 0xBDCC - cmpwi r3, 0 - bne- .loc_0x38 - li r3, -0x3 - b .loc_0xA8 + BOOL err; + u32 cmd; - .loc_0x38: - cmpwi r31, 0 - beq- .loc_0x48 - lis r0, 0x8101 - b .loc_0x4C + if (!EXISelect(channel, 0, 4)) { + return CARD_RESULT_NOCARD; + } - .loc_0x48: - lis r0, 0x8100 - - .loc_0x4C: - stw r0, 0x10(r1) - addi r3, r30, 0 - addi r4, r1, 0x10 - li r5, 0x2 - li r6, 0x1 - li r7, 0 - bl 0xB224 - cntlzw r0, r3 - addi r3, r30, 0 - rlwinm r31,r0,27,5,31 - bl 0xB5FC - cntlzw r0, r3 - rlwinm r0,r0,27,5,31 - addi r3, r30, 0 - or r31, r31, r0 - bl 0xBE94 - cntlzw r0, r3 - rlwinm r0,r0,27,5,31 - or. r31, r31, r0 - beq- .loc_0xA4 - li r3, -0x3 - b .loc_0xA8 - - .loc_0xA4: - li r3, 0 - - .loc_0xA8: - lwz r0, 0x24(r1) - lwz r31, 0x1C(r1) - lwz r30, 0x18(r1) - addi r1, r1, 0x20 - mtlr r0 - blr - */ + cmd = enable ? 0x81010000 : 0x81000000; + err = FALSE; + err |= !EXIImm(channel, &cmd, 2, 1, nullptr); + err |= !EXISync(channel); + err |= !EXIDeselect(channel); + return err ? CARD_RESULT_NOCARD : CARD_RESULT_READY; } /* @@ -463,77 +193,23 @@ void __CARDEnableInterrupt(void) * Address: 800D4A80 * Size: 0000F0 */ -int __CARDReadStatus(int slotIndex, u8* buffer) +s32 __CARDReadStatus(s32 channel, u8* status) { - /* - .loc_0x0: - mflr r0 - li r5, 0x4 - stw r0, 0x4(r1) - stwu r1, -0x28(r1) - stw r31, 0x24(r1) - stw r30, 0x20(r1) - addi r30, r4, 0 - li r4, 0 - stw r29, 0x1C(r1) - addi r29, r3, 0 - bl 0xBD08 - cmpwi r3, 0 - bne- .loc_0x3C - li r3, -0x3 - b .loc_0xD4 + BOOL err; + u32 cmd; - .loc_0x3C: - lis r0, 0x8300 - stw r0, 0x10(r1) - addi r3, r29, 0 - addi r4, r1, 0x10 - li r5, 0x2 - li r6, 0x1 - li r7, 0 - bl 0xB170 - cntlzw r0, r3 - addi r3, r29, 0 - rlwinm r31,r0,27,5,31 - bl 0xB548 - cntlzw r0, r3 - rlwinm r0,r0,27,5,31 - addi r3, r29, 0 - addi r4, r30, 0 - or r31, r31, r0 - li r5, 0x1 - li r6, 0 - li r7, 0 - bl 0xB13C - cntlzw r0, r3 - rlwinm r0,r0,27,5,31 - addi r3, r29, 0 - or r31, r31, r0 - bl 0xB510 - cntlzw r0, r3 - rlwinm r0,r0,27,5,31 - addi r3, r29, 0 - or r31, r31, r0 - bl 0xBDA8 - cntlzw r0, r3 - rlwinm r0,r0,27,5,31 - or. r31, r31, r0 - beq- .loc_0xD0 - li r3, -0x3 - b .loc_0xD4 + if (!EXISelect(channel, 0, 4)) { + return CARD_RESULT_NOCARD; + } - .loc_0xD0: - li r3, 0 - - .loc_0xD4: - lwz r0, 0x2C(r1) - lwz r31, 0x24(r1) - lwz r30, 0x20(r1) - lwz r29, 0x1C(r1) - addi r1, r1, 0x28 - mtlr r0 - blr - */ + cmd = 0x83000000; + err = FALSE; + err |= !EXIImm(channel, &cmd, 2, 1, nullptr); + err |= !EXISync(channel); + err |= !EXIImm(channel, status, 1, 0, nullptr); + err |= !EXISync(channel); + err |= !EXIDeselect(channel); + return err ? CARD_RESULT_NOCARD : CARD_RESULT_READY; } /* @@ -541,137 +217,71 @@ int __CARDReadStatus(int slotIndex, u8* buffer) * Address: 800D4B70 * Size: 0000AC */ -int __CARDClearStatus(int slotIndex) +s32 __CARDClearStatus(s32 channel) { - /* - .loc_0x0: - mflr r0 - li r4, 0 - stw r0, 0x4(r1) - li r5, 0x4 - stwu r1, -0x18(r1) - stw r31, 0x14(r1) - stw r30, 0x10(r1) - addi r30, r3, 0 - bl 0xBC20 - cmpwi r3, 0 - bne- .loc_0x34 - li r3, -0x3 - b .loc_0x94 + BOOL err; + u32 cmd; - .loc_0x34: - lis r0, 0x8900 - stw r0, 0xC(r1) - addi r3, r30, 0 - addi r4, r1, 0xC - li r5, 0x1 - li r6, 0x1 - li r7, 0 - bl 0xB088 - cntlzw r0, r3 - addi r3, r30, 0 - rlwinm r31,r0,27,5,31 - bl 0xB460 - cntlzw r0, r3 - rlwinm r0,r0,27,5,31 - addi r3, r30, 0 - or r31, r31, r0 - bl 0xBCF8 - cntlzw r0, r3 - rlwinm r0,r0,27,5,31 - or. r31, r31, r0 - beq- .loc_0x90 - li r3, -0x3 - b .loc_0x94 + if (!EXISelect(channel, 0, 4)) { + return CARD_RESULT_NOCARD; + } - .loc_0x90: - li r3, 0 + cmd = 0x89000000; + err = FALSE; + err |= !EXIImm(channel, &cmd, 1, 1, nullptr); + err |= !EXISync(channel); + err |= !EXIDeselect(channel); - .loc_0x94: - lwz r0, 0x1C(r1) - lwz r31, 0x14(r1) - lwz r30, 0x10(r1) - addi r1, r1, 0x18 - mtlr r0 - blr - */ + return err ? CARD_RESULT_NOCARD : CARD_RESULT_READY; } -/* - * --INFO-- - * Address: ........ - * Size: 0000AC - */ -void __CARDSleep(void) -{ - // UNUSED FUNCTION -} +// /* +// * --INFO-- +// * Address: ........ +// * Size: 0000AC +// */ +// void __CARDSleep(void) +// { +// // UNUSED FUNCTION +// } -/* - * --INFO-- - * Address: ........ - * Size: 0000AC - */ -void __CARDWakeup(void) -{ - // UNUSED FUNCTION -} +// /* +// * --INFO-- +// * Address: ........ +// * Size: 0000AC +// */ +// void __CARDWakeup(void) +// { +// // UNUSED FUNCTION +// } /* * --INFO-- * Address: 800D4C1C * Size: 0000A4 */ -void TimeoutHandler(OSAlarm* alarm) +void TimeoutHandler(OSAlarm* alarm, OSContext* context) { - /* - .loc_0x0: - mflr r0 - lis r4, 0x804F - stw r0, 0x4(r1) - addi r4, r4, 0x5AF0 - addi r0, r4, 0xE0 - stwu r1, -0x18(r1) - cmplw r3, r0 - stw r31, 0x14(r1) - li r31, 0 - stw r30, 0x10(r1) - addi r30, r4, 0 - beq- .loc_0x4C - addi r0, r4, 0x1F0 - cmplw r3, r0 - addi r4, r4, 0x110 - addi r30, r4, 0 - li r31, 0x1 - beq- .loc_0x4C - li r31, 0x2 + s32 channel; + CARDControl* card; + CARDCallback callback; + for (channel = 0; channel < 2; channel++) { + card = &__CARDBlock[channel]; + if (alarm == &card->alarm) { + break; + } + } - .loc_0x4C: - lwz r0, 0x0(r30) - cmpwi r0, 0 - beq- .loc_0x8C - addi r3, r31, 0 - li r4, 0 - bl 0xB648 - lwz r0, 0xCC(r30) - cmplwi r0, 0 - mr r12, r0 - beq- .loc_0x8C - li r0, 0 - mtlr r12 - stw r0, 0xCC(r30) - addi r3, r31, 0 - li r4, -0x5 - blrl + if (!card->attached) { + return; + } - .loc_0x8C: - lwz r0, 0x1C(r1) - lwz r31, 0x14(r1) - lwz r30, 0x10(r1) - addi r1, r1, 0x18 - mtlr r0 - blr - */ + EXISetExiCallback(channel, NULL); + callback = card->exiCallback; + if (callback) { + card->exiCallback = nullptr; + callback(channel, CARD_RESULT_IOERROR); + } } /* @@ -679,9 +289,20 @@ void TimeoutHandler(OSAlarm* alarm) * Address: ........ * Size: 0000F8 */ -void SetupTimeoutAlarm(void) +void SetupTimeoutAlarm(CARDControl* card) { - // UNUSED FUNCTION + OSCancelAlarm(&card->alarm); + switch (card->cmd[0]) { + case 0xF2: + OSSetAlarm(&card->alarm, OSMillisecondsToTicks(100), TimeoutHandler); + break; + case 0xF3: + break; + case 0xF4: + case 0xF1: + OSSetAlarm(&card->alarm, OSSecondsToTicks((OSTime)2) * (card->sectorSize / 0x2000), TimeoutHandler); + break; + } } /* @@ -689,174 +310,43 @@ void SetupTimeoutAlarm(void) * Address: 800D4CC0 * Size: 00022C */ -int Retry(int slotIndex) +s32 Retry(s32 channel) { - /* - .loc_0x0: - mflr r0 - li r5, 0x4 - stw r0, 0x4(r1) - stwu r1, -0x18(r1) - stw r31, 0x14(r1) - stw r30, 0x10(r1) - addi r30, r3, 0 - mulli r4, r30, 0x110 - lis r3, 0x804F - addi r0, r3, 0x5AF0 - add r31, r0, r4 - addi r3, r30, 0 - li r4, 0 - bl 0xBABC - cmpwi r3, 0 - bne- .loc_0x50 - mr r3, r30 - bl 0xC360 - li r3, -0x3 - b .loc_0x214 + CARDControl* card; + card = &__CARDBlock[channel]; - .loc_0x50: - addi r3, r31, 0xE0 - bl 0x170C0 - lbz r0, 0x94(r31) - cmpwi r0, 0xF3 - beq- .loc_0x120 - bge- .loc_0x78 - cmpwi r0, 0xF1 - beq- .loc_0xBC - bge- .loc_0x84 - b .loc_0x120 + if (!EXISelect(channel, 0, 4)) { + EXIUnlock(channel); + return CARD_RESULT_NOCARD; + } - .loc_0x78: - cmpwi r0, 0xF5 - bge- .loc_0x120 - b .loc_0xBC + SetupTimeoutAlarm(card); - .loc_0x84: - lis r3, 0x8000 - lwz r0, 0xF8(r3) - lis r4, 0x1062 - lis r3, 0x800D - rlwinm r0,r0,30,2,31 - addi r4, r4, 0x4DD3 - mulhwu r0, r4, r0 - rlwinm r0,r0,26,6,31 - mulli r6, r0, 0x64 - addi r7, r3, 0x4C1C - addi r3, r31, 0xE0 - li r5, 0 - bl 0x16FF8 - b .loc_0x120 + if (!EXIImmEx(channel, card->cmd, card->cmdlen, 1)) { + EXIDeselect(channel); + EXIUnlock(channel); + return CARD_RESULT_NOCARD; + } - .loc_0xBC: - lis r3, 0x8000 - lwz r4, 0xC(r31) - lwz r0, 0xF8(r3) - lis r3, 0x800D - srawi r9, r4, 0xD - rlwinm r7,r0,30,2,31 - li r0, 0x2 - li r4, 0 - mullw r8, r4, r0 - mulhwu r6, r7, r0 - add r8, r8, r6 - mullw r5, r7, r0 - addze r9, r9 - mullw r6, r7, r4 - srawi r0, r9, 0x1F - mullw r4, r0, r5 - mulhwu r0, r9, r5 - addi r7, r3, 0x4C1C - add r3, r8, r6 - add r4, r4, r0 - mullw r0, r9, r3 - mullw r6, r9, r5 - addi r3, r31, 0xE0 - add r5, r4, r0 - bl 0x16F90 + if (card->cmd[0] == 0x52 && !EXIImmEx(channel, card->workArea->header.buffer, card->latency, 1)) { + EXIDeselect(channel); + EXIUnlock(channel); + return CARD_RESULT_NOCARD; + } - .loc_0x120: - lwz r5, 0xA0(r31) - addi r3, r30, 0 - addi r4, r31, 0x94 - li r6, 0x1 - bl 0xB0B4 - cmpwi r3, 0 - bne- .loc_0x154 - mr r3, r30 - bl 0xBADC - mr r3, r30 - bl 0xC25C - li r3, -0x3 - b .loc_0x214 + if (card->mode == 0xffffffff) { + EXIDeselect(channel); + EXIUnlock(channel); + return CARD_RESULT_READY; + } - .loc_0x154: - lbz r0, 0x94(r31) - cmplwi r0, 0x52 - bne- .loc_0x198 - lwz r4, 0x80(r31) - mr r3, r30 - lwz r5, 0x14(r31) - li r6, 0x1 - addi r4, r4, 0x200 - bl 0xB070 - cmpwi r3, 0 - bne- .loc_0x198 - mr r3, r30 - bl 0xBA98 - mr r3, r30 - bl 0xC218 - li r3, -0x3 - b .loc_0x214 + if (!EXIDma(channel, card->buffer, (s32)((card->cmd[0] == 0x52) ? 512 : 128), card->mode, __CARDTxHandler)) { + EXIDeselect(channel); + EXIUnlock(channel); + return CARD_RESULT_NOCARD; + } - .loc_0x198: - lwz r3, 0xA4(r31) - addis r0, r3, 0x1 - cmplwi r0, 0xFFFF - bne- .loc_0x1C0 - mr r3, r30 - bl 0xBA70 - mr r3, r30 - bl 0xC1F0 - li r3, 0 - b .loc_0x214 - - .loc_0x1C0: - lbz r0, 0x94(r31) - cmplwi r0, 0x52 - bne- .loc_0x1D4 - li r5, 0x200 - b .loc_0x1D8 - - .loc_0x1D4: - li r5, 0x80 - - .loc_0x1D8: - lis r3, 0x800D - lwz r4, 0xB4(r31) - addi r7, r3, 0x4894 - lwz r6, 0xA4(r31) - mr r3, r30 - bl 0xB098 - cmpwi r3, 0 - bne- .loc_0x210 - mr r3, r30 - bl 0xBA20 - mr r3, r30 - bl 0xC1A0 - li r3, -0x3 - b .loc_0x214 - - .loc_0x210: - li r3, 0 - - .loc_0x214: - lwz r0, 0x1C(r1) - lwz r31, 0x14(r1) - lwz r30, 0x10(r1) - addi r1, r1, 0x18 - mtlr r0 - blr - */ + return CARD_RESULT_READY; } /* @@ -864,91 +354,43 @@ int Retry(int slotIndex) * Address: 800D4EEC * Size: 000110 */ -void UnlockedCallback(void) +void UnlockedCallback(s32 channel, s32 result) { - /* - .loc_0x0: - mflr r0 - cmpwi r4, 0 - stw r0, 0x4(r1) - stwu r1, -0x18(r1) - stw r31, 0x14(r1) - addi r31, r3, 0 - mulli r5, r31, 0x110 - stw r30, 0x10(r1) - lis r3, 0x804F - addi r0, r3, 0x5AF0 - add r30, r0, r5 - blt- .loc_0x74 - lis r3, 0x800D - addi r0, r3, 0x4EEC - lis r3, 0x800D - stw r0, 0xDC(r30) - addi r5, r3, 0x493C - addi r3, r31, 0 - li r4, 0 - bl 0xC038 - cmpwi r3, 0 - bne- .loc_0x60 - li r4, 0 - b .loc_0x74 + CARDCallback callback; + CARDControl* card; - .loc_0x60: - li r0, 0 - stw r0, 0xDC(r30) - mr r3, r31 - bl -0x298 - mr r4, r3 + card = &__CARDBlock[channel]; + if (result >= 0) { + card->unlockCallback = UnlockedCallback; + if (!EXILock(channel, 0, __CARDUnlockedHandler)) { + result = CARD_RESULT_READY; + } else { + card->unlockCallback = nullptr; + result = Retry(channel); + } + } - .loc_0x74: - cmpwi r4, 0 - bge- .loc_0xF8 - lbz r0, 0x94(r30) - cmpwi r0, 0xF3 - beq- .loc_0xF8 - bge- .loc_0xA4 - cmpwi r0, 0x52 - beq- .loc_0xB0 - blt- .loc_0xF8 - cmpwi r0, 0xF1 - bge- .loc_0xD8 - b .loc_0xF8 + if (result < 0) { + switch (card->cmd[0]) { + case 0x52: + callback = card->txCallback; + if (callback) { + card->txCallback = nullptr; + callback(channel, result); + } - .loc_0xA4: - cmpwi r0, 0xF5 - bge- .loc_0xF8 - b .loc_0xD8 - - .loc_0xB0: - lwz r0, 0xC8(r30) - cmplwi r0, 0 - mr r12, r0 - beq- .loc_0xF8 - li r0, 0 - mtlr r12 - stw r0, 0xC8(r30) - mr r3, r31 - blrl - b .loc_0xF8 - - .loc_0xD8: - lwz r12, 0xCC(r30) - cmplwi r12, 0 - beq- .loc_0xF8 - li r0, 0 - mtlr r12 - stw r0, 0xCC(r30) - mr r3, r31 - blrl - - .loc_0xF8: - lwz r0, 0x1C(r1) - lwz r31, 0x14(r1) - lwz r30, 0x10(r1) - addi r1, r1, 0x18 - mtlr r0 - blr - */ + break; + case 0xF2: + case 0xF4: + case 0xF1: + callback = card->exiCallback; + if (callback) { + card->exiCallback = nullptr; + callback(channel, result); + } + break; + } + } } /* @@ -956,140 +398,43 @@ void UnlockedCallback(void) * Address: 800D4FFC * Size: 0001B4 */ -int __CARDStart(int slotIndex, CARDBlockC8Callback* c8Callback, CARDBlockDoneWriteCallback* doneWriteCallback) +s32 __CARDStart(s32 channel, CARDCallback txCallback, CARDCallback exiCallback) { - /* - .loc_0x0: - mflr r0 - stw r0, 0x4(r1) - stwu r1, -0x30(r1) - stmw r27, 0x1C(r1) - addi r27, r3, 0 - addi r28, r4, 0 - addi r29, r5, 0 - bl 0x19C20 - mulli r5, r27, 0x110 - lis r4, 0x804F - addi r0, r4, 0x5AF0 - add r31, r0, r5 - lwz r0, 0x0(r31) - addi r30, r3, 0 - cmpwi r0, 0 - bne- .loc_0x48 - li r31, -0x3 - b .loc_0x194 + BOOL enabled; + CARDControl* card; + s32 result; - .loc_0x48: - cmplwi r28, 0 - beq- .loc_0x54 - stw r28, 0xC8(r31) + enabled = OSDisableInterrupts(); - .loc_0x54: - cmplwi r29, 0 - beq- .loc_0x60 - stw r29, 0xCC(r31) + card = &__CARDBlock[channel]; + if (!card->attached) { + result = CARD_RESULT_NOCARD; + } else { - .loc_0x60: - lis r3, 0x800D - addi r0, r3, 0x4EEC - lis r3, 0x800D - stw r0, 0xDC(r31) - addi r5, r3, 0x493C - addi r3, r27, 0 - li r4, 0 - bl 0xBEF8 - cmpwi r3, 0 - bne- .loc_0x90 - li r31, -0x1 - b .loc_0x194 + if (txCallback) { + card->txCallback = txCallback; + } + if (exiCallback) { + card->exiCallback = exiCallback; + } + card->unlockCallback = UnlockedCallback; + if (!EXILock(channel, 0, __CARDUnlockedHandler)) { + result = CARD_RESULT_BUSY; + } else { + card->unlockCallback = nullptr; - .loc_0x90: - li r0, 0 - stw r0, 0xDC(r31) - addi r3, r27, 0 - li r4, 0 - li r5, 0x4 - bl 0xB710 - cmpwi r3, 0 - bne- .loc_0xC0 - mr r3, r27 - bl 0xBFB4 - li r31, -0x3 - b .loc_0x194 + if (!EXISelect(channel, 0, 4)) { + EXIUnlock(channel); + result = CARD_RESULT_NOCARD; + } else { + SetupTimeoutAlarm(card); + result = CARD_RESULT_READY; + } + } + } - .loc_0xC0: - addi r3, r31, 0xE0 - bl 0x16D14 - lbz r0, 0x94(r31) - cmpwi r0, 0xF3 - beq- .loc_0x190 - bge- .loc_0xE8 - cmpwi r0, 0xF1 - beq- .loc_0x12C - bge- .loc_0xF4 - b .loc_0x190 - - .loc_0xE8: - cmpwi r0, 0xF5 - bge- .loc_0x190 - b .loc_0x12C - - .loc_0xF4: - lis r3, 0x8000 - lwz r0, 0xF8(r3) - lis r4, 0x1062 - lis r3, 0x800D - rlwinm r0,r0,30,2,31 - addi r4, r4, 0x4DD3 - mulhwu r0, r4, r0 - rlwinm r0,r0,26,6,31 - mulli r6, r0, 0x64 - addi r7, r3, 0x4C1C - addi r3, r31, 0xE0 - li r5, 0 - bl 0x16C4C - b .loc_0x190 - - .loc_0x12C: - lis r3, 0x8000 - lwz r4, 0xC(r31) - lwz r0, 0xF8(r3) - lis r3, 0x800D - srawi r9, r4, 0xD - rlwinm r7,r0,30,2,31 - li r0, 0x2 - li r4, 0 - mullw r8, r4, r0 - mulhwu r6, r7, r0 - add r8, r8, r6 - mullw r5, r7, r0 - addze r9, r9 - mullw r6, r7, r4 - srawi r0, r9, 0x1F - mullw r4, r0, r5 - mulhwu r0, r9, r5 - addi r7, r3, 0x4C1C - add r3, r8, r6 - add r4, r4, r0 - mullw r0, r9, r3 - mullw r6, r9, r5 - addi r3, r31, 0xE0 - add r5, r4, r0 - bl 0x16BE4 - - .loc_0x190: - li r31, 0 - - .loc_0x194: - mr r3, r30 - bl 0x19ACC - mr r3, r31 - lmw r27, 0x1C(r1) - lwz r0, 0x34(r1) - addi r1, r1, 0x30 - mtlr r0 - blr - */ + OSRestoreInterrupts(enabled); + return result; } /* @@ -1097,96 +442,39 @@ int __CARDStart(int slotIndex, CARDBlockC8Callback* c8Callback, CARDBlockDoneWri * Address: 800D51B0 * Size: 000134 */ -int __CARDReadSegment(int slotIndex, CARDBlockC8Callback* c8Callback) +s32 __CARDReadSegment(s32 channel, CARDCallback callback) { - /* - .loc_0x0: - mflr r0 - li r6, 0x5 - stw r0, 0x4(r1) - stwu r1, -0x18(r1) - stw r31, 0x14(r1) - stw r30, 0x10(r1) - addi r30, r3, 0 - mulli r5, r30, 0x110 - lis r3, 0x804F - addi r0, r3, 0x5AF0 - add r31, r0, r5 - li r0, 0x52 - stb r0, 0x94(r31) - li r0, 0 - addi r3, r30, 0 - lwz r5, 0xB0(r31) - rlwinm r5,r5,15,25,31 - stb r5, 0x95(r31) - li r5, 0 - lwz r7, 0xB0(r31) - rlwinm r7,r7,23,24,31 - stb r7, 0x96(r31) - lwz r7, 0xB0(r31) - rlwinm r7,r7,25,30,31 - stb r7, 0x97(r31) - lwz r7, 0xB0(r31) - rlwinm r7,r7,0,25,31 - stb r7, 0x98(r31) - stw r6, 0xA0(r31) - stw r0, 0xA4(r31) - stw r0, 0xA8(r31) - bl -0x230 - cmpwi r3, -0x1 - bne- .loc_0x90 - li r3, 0 - b .loc_0x11C + CARDControl* card; + s32 result; - .loc_0x90: - cmpwi r3, 0 - blt- .loc_0x11C - lwz r5, 0xA0(r31) - addi r3, r30, 0 - addi r4, r31, 0x94 - li r6, 0x1 - bl 0xAC4C - cmpwi r3, 0 - beq- .loc_0xF8 - lwz r4, 0x80(r31) - mr r3, r30 - lwz r5, 0x14(r31) - li r6, 0x1 - addi r4, r4, 0x200 - bl 0xAC2C - cmpwi r3, 0 - beq- .loc_0xF8 - lis r3, 0x800D - lwz r4, 0xB4(r31) - addi r7, r3, 0x4894 - lwz r6, 0xA4(r31) - addi r3, r30, 0 - li r5, 0x200 - bl 0xACA8 - cmpwi r3, 0 - bne- .loc_0x118 + card = &__CARDBlock[channel]; + card->cmd[0] = 0x52; + card->cmd[1] = AD1(card->addr); + card->cmd[2] = AD2(card->addr); + card->cmd[3] = AD3(card->addr); + card->cmd[4] = BA(card->addr); + card->cmdlen = 5; + card->mode = 0; + card->retry = 0; - .loc_0xF8: - li r0, 0 - stw r0, 0xC8(r31) - mr r3, r30 - bl 0xB628 - mr r3, r30 - bl 0xBDA8 - li r3, -0x3 - b .loc_0x11C - - .loc_0x118: - li r3, 0 - - .loc_0x11C: - lwz r0, 0x1C(r1) - lwz r31, 0x14(r1) - lwz r30, 0x10(r1) - addi r1, r1, 0x18 - mtlr r0 - blr - */ + result = __CARDStart(channel, callback, 0); + if (result == CARD_RESULT_BUSY) { + result = CARD_RESULT_READY; + } else if (result >= 0) { + if (!EXIImmEx(channel, card->cmd, card->cmdlen, 1) + || !EXIImmEx(channel, card->workArea->header.buffer, card->latency, + 1) + || // XXX use DMA if possible + !EXIDma(channel, card->buffer, 512, card->mode, __CARDTxHandler)) { + card->txCallback = 0; + EXIDeselect(channel); + EXIUnlock(channel); + result = CARD_RESULT_NOCARD; + } else { + result = CARD_RESULT_READY; + } + } + return result; } /* @@ -1194,100 +482,36 @@ int __CARDReadSegment(int slotIndex, CARDBlockC8Callback* c8Callback) * Address: 800D52E4 * Size: 00011C */ -int __CARDWritePage(int slotIndex, CARDBlockDoneWriteCallback* doneWriteCallback) +s32 __CARDWritePage(s32 channel, CARDCallback callback) { - /* - .loc_0x0: - mflr r0 - li r7, 0x5 - stw r0, 0x4(r1) - li r6, 0x1 - stwu r1, -0x18(r1) - stw r31, 0x14(r1) - stw r30, 0x10(r1) - addi r30, r3, 0 - mulli r5, r30, 0x110 - lis r3, 0x804F - addi r0, r3, 0x5AF0 - add r31, r0, r5 - li r0, 0xF2 - stb r0, 0x94(r31) - addi r5, r4, 0 - li r0, 0x3 - lwz r3, 0xB0(r31) - li r4, 0 - rlwinm r3,r3,15,25,31 - stb r3, 0x95(r31) - addi r3, r30, 0 - lwz r8, 0xB0(r31) - rlwinm r8,r8,23,24,31 - stb r8, 0x96(r31) - lwz r8, 0xB0(r31) - rlwinm r8,r8,25,30,31 - stb r8, 0x97(r31) - lwz r8, 0xB0(r31) - rlwinm r8,r8,0,25,31 - stb r8, 0x98(r31) - stw r7, 0xA0(r31) - stw r6, 0xA4(r31) - stw r0, 0xA8(r31) - bl -0x36C - cmpwi r3, -0x1 - bne- .loc_0x98 - li r3, 0 - b .loc_0x104 + CARDControl* card; + s32 result; - .loc_0x98: - cmpwi r3, 0 - blt- .loc_0x104 - lwz r5, 0xA0(r31) - addi r3, r30, 0 - addi r4, r31, 0x94 - li r6, 0x1 - bl 0xAB10 - cmpwi r3, 0 - beq- .loc_0xE0 - lis r3, 0x800D - lwz r4, 0xB4(r31) - addi r7, r3, 0x4894 - lwz r6, 0xA4(r31) - addi r3, r30, 0 - li r5, 0x80 - bl 0xAB8C - cmpwi r3, 0 - bne- .loc_0x100 + card = &__CARDBlock[channel]; + card->cmd[0] = 0xF2; + card->cmd[1] = AD1(card->addr); + card->cmd[2] = AD2(card->addr); + card->cmd[3] = AD3(card->addr); + card->cmd[4] = BA(card->addr); + card->cmdlen = 5; + card->mode = 1; + card->retry = 3; - .loc_0xE0: - li r0, 0 - stw r0, 0xCC(r31) - mr r3, r30 - bl 0xB50C - mr r3, r30 - bl 0xBC8C - li r3, -0x3 - b .loc_0x104 + result = __CARDStart(channel, nullptr, callback); + if (result == CARD_RESULT_BUSY) { + result = CARD_RESULT_READY; + } else if (result >= 0) { + if (!EXIImmEx(channel, card->cmd, card->cmdlen, 1) || !EXIDma(channel, card->buffer, 128, card->mode, __CARDTxHandler)) { + card->exiCallback = nullptr; + EXIDeselect(channel); + EXIUnlock(channel); + result = CARD_RESULT_NOCARD; + } else { + result = CARD_RESULT_READY; + } + } - .loc_0x100: - li r3, 0 - - .loc_0x104: - lwz r0, 0x1C(r1) - lwz r31, 0x14(r1) - lwz r30, 0x10(r1) - addi r1, r1, 0x18 - mtlr r0 - blr - */ -} - -/* - * --INFO-- - * Address: ........ - * Size: 0000E4 - */ -void __CARDErase(void) -{ - // UNUSED FUNCTION + return result; } /* @@ -1295,75 +519,35 @@ void __CARDErase(void) * Address: 800D5400 * Size: 0000E0 */ -int __CARDEraseSector(int slotIndex, unknown p2, CARDBlockDoneWriteCallback* doneWriteCallback) +s32 __CARDEraseSector(s32 channel, u32 addr, CARDCallback callback) { - /* - .loc_0x0: - mflr r0 - stw r0, 0x4(r1) - stwu r1, -0x28(r1) - stw r31, 0x24(r1) - stw r30, 0x20(r1) - stw r29, 0x1C(r1) - addi r29, r3, 0 - mulli r6, r29, 0x110 - lis r3, 0x804F - addi r0, r3, 0x5AF0 - add r31, r0, r6 - li r0, 0xF1 - stb r0, 0x94(r31) - rlwinm r3,r4,15,25,31 - rlwinm r0,r4,23,24,31 - stb r3, 0x95(r31) - li r6, 0x3 - addi r3, r29, 0 - stb r0, 0x96(r31) - li r0, -0x1 - li r4, 0 - stw r6, 0xA0(r31) - stw r0, 0xA4(r31) - stw r6, 0xA8(r31) - bl -0x464 - addi r30, r3, 0 - cmpwi r30, -0x1 - bne- .loc_0x78 - li r30, 0 - b .loc_0xC0 + CARDControl* card; + s32 result; - .loc_0x78: - cmpwi r30, 0 - blt- .loc_0xC0 - lwz r5, 0xA0(r31) - addi r3, r29, 0 - addi r4, r31, 0x94 - li r6, 0x1 - bl 0xAA14 - cmpwi r3, 0 - bne- .loc_0xAC - li r0, 0 - stw r0, 0xCC(r31) - li r30, -0x3 - b .loc_0xB0 + card = &__CARDBlock[channel]; + card->cmd[0] = 0xF1; + card->cmd[1] = AD1(addr); + card->cmd[2] = AD2(addr); + card->cmdlen = 3; + card->mode = -1; + card->retry = 3; - .loc_0xAC: - li r30, 0 + result = __CARDStart(channel, nullptr, callback); - .loc_0xB0: - mr r3, r29 - bl 0xB428 - mr r3, r29 - bl 0xBBA8 + if (result == CARD_RESULT_BUSY) { + result = CARD_RESULT_READY; + } else if (result >= 0) { + if (!EXIImmEx(channel, card->cmd, card->cmdlen, 1)) { + card->exiCallback = nullptr; + result = CARD_RESULT_NOCARD; + } else { + result = CARD_RESULT_READY; + } - .loc_0xC0: - mr r3, r30 - lwz r0, 0x2C(r1) - lwz r31, 0x24(r1) - lwz r30, 0x20(r1) - lwz r29, 0x1C(r1) - addi r1, r1, 0x28 - mtlr r0 - blr - */ + EXIDeselect(channel); + EXIUnlock(channel); + } + return result; } /* @@ -1373,58 +557,30 @@ int __CARDEraseSector(int slotIndex, unknown p2, CARDBlockDoneWriteCallback* don */ void CARDInit() { - /* - .loc_0x0: - mflr r0 - lis r3, 0x804F - stw r0, 0x4(r1) - stwu r1, -0x18(r1) - stw r31, 0x14(r1) - stw r30, 0x10(r1) - addi r30, r3, 0x5AF0 - stw r29, 0xC(r1) - lwz r0, 0x10C(r30) - cmplwi r0, 0 - beq- .loc_0x38 - lwz r0, 0x21C(r30) - cmplwi r0, 0 - bne- .loc_0x90 + s32 channel; - .loc_0x38: - bl 0x18B90 - sth r3, -0x7260(r13) - lwz r3, -0x7D78(r13) - bl 0x16564 - bl 0x5814 - bl 0x16588 - li r29, 0 - li r31, -0x3 + if (__CARDBlock[0].diskID && __CARDBlock[1].diskID) { + return; + } - .loc_0x58: - stw r31, 0x4(r30) - addi r3, r30, 0x8C - bl 0x1C474 - addi r3, r30, 0xE0 - bl 0x165C4 - addi r29, r29, 0x1 - cmpwi r29, 0x2 - addi r30, r30, 0x110 - blt+ .loc_0x58 - lis r3, 0x8000 - bl 0x34 - lis r3, 0x804A - addi r3, r3, 0x7758 - bl 0x1AD38 + __CARDEncode = OSGetFontEncode(); - .loc_0x90: - lwz r0, 0x1C(r1) - lwz r31, 0x14(r1) - lwz r30, 0x10(r1) - lwz r29, 0xC(r1) - addi r1, r1, 0x18 - mtlr r0 - blr - */ + OSRegisterVersion(__CARDVersion); + + DSPInit(); + OSInitAlarm(); + + for (channel = 0; channel < 2; channel++) { + CARDControl* card = &__CARDBlock[channel]; + + card->result = CARD_RESULT_NOCARD; + OSInitThreadQueue(&card->threadQueue); + OSCreateAlarm(&card->alarm); + } + + __CARDSetDiskID((DVDDiskID*)OSPhysicalToCached(0x0)); + + OSRegisterResetFunction(&ResetFunctionInfo); } /* @@ -1432,147 +588,78 @@ void CARDInit() * Address: 800D558C * Size: 000008 */ -u16 __CARDGetFontEncode() -{ - /* - .loc_0x0: - lhz r3, -0x7260(r13) - blr - */ -} +u16 __CARDGetFontEncode() { return __CARDEncode; } -/* - * --INFO-- - * Address: ........ - * Size: 000028 - */ -void __CARDSetFontEncode(void) -{ - // UNUSED FUNCTION -} +// /* +// * --INFO-- +// * Address: ........ +// * Size: 000028 +// */ +// void __CARDSetFontEncode(void) +// { +// // UNUSED FUNCTION +// } /* * --INFO-- * Address: 800D5594 * Size: 000038 */ -void __CARDSetDiskID(u8* diskID) +void __CARDSetDiskID(const DVDDiskID* diskID) { - /* - .loc_0x0: - cmplwi r3, 0 - lis r4, 0x804F - addi r4, r4, 0x5AF0 - beq- .loc_0x18 - mr r0, r3 - b .loc_0x1C - - .loc_0x18: - addi r0, r4, 0x220 - - .loc_0x1C: - cmplwi r3, 0 - stw r0, 0x10C(r4) - beq- .loc_0x2C - b .loc_0x30 - - .loc_0x2C: - addi r3, r4, 0x220 - - .loc_0x30: - stw r3, 0x21C(r4) - blr - */ + __CARDBlock[0].diskID = diskID ? diskID : &__CARDDiskNone; + __CARDBlock[1].diskID = diskID ? diskID : &__CARDDiskNone; } -/* - * --INFO-- - * Address: ........ - * Size: 000018 - */ -void CARDGetDiskID(void) -{ - // UNUSED FUNCTION -} +// /* +// * --INFO-- +// * Address: ........ +// * Size: 000018 +// */ +// void CARDGetDiskID(void) +// { +// // UNUSED FUNCTION +// } -/* - * --INFO-- - * Address: ........ - * Size: 000078 - */ -void CARDSetDiskID(void) -{ - // UNUSED FUNCTION -} +// /* +// * --INFO-- +// * Address: ........ +// * Size: 000078 +// */ +// void CARDSetDiskID(void) +// { +// // UNUSED FUNCTION +// } /* * --INFO-- * Address: 800D55CC * Size: 0000B8 */ -int __CARDGetControlBlock(int slotIndex, CARDBlock** outBlock) +s32 __CARDGetControlBlock(s32 channel, CARDControl** card) { - /* - .loc_0x0: - mflr r0 - mulli r6, r3, 0x110 - stw r0, 0x4(r1) - stwu r1, -0x20(r1) - lis r5, 0x804F - cmpwi r3, 0 - stw r31, 0x1C(r1) - addi r0, r5, 0x5AF0 - stw r30, 0x18(r1) - add r30, r0, r6 - stw r29, 0x14(r1) - addi r29, r4, 0 - blt- .loc_0x48 - cmpwi r3, 0x2 - bge- .loc_0x48 - lwz r0, 0x10C(r30) - cmplwi r0, 0 - bne- .loc_0x50 + BOOL enabled; + s32 result; + CARDControl* reqCard; - .loc_0x48: - li r3, -0x80 - b .loc_0x9C + reqCard = &__CARDBlock[channel]; + if (channel < 0 || channel >= 2 || reqCard->diskID == NULL) { + return CARD_RESULT_FATAL_ERROR; + } - .loc_0x50: - bl 0x1961C - lwz r0, 0x0(r30) - cmpwi r0, 0 - bne- .loc_0x68 - li r31, -0x3 - b .loc_0x94 - - .loc_0x68: - lwz r0, 0x4(r30) - cmpwi r0, -0x1 - bne- .loc_0x7C - li r31, -0x1 - b .loc_0x94 - - .loc_0x7C: - li r0, -0x1 - stw r0, 0x4(r30) - li r0, 0 - li r31, 0 - stw r0, 0xD0(r30) - stw r30, 0x0(r29) - - .loc_0x94: - bl 0x19600 - mr r3, r31 - - .loc_0x9C: - lwz r0, 0x24(r1) - lwz r31, 0x1C(r1) - lwz r30, 0x18(r1) - lwz r29, 0x14(r1) - addi r1, r1, 0x20 - mtlr r0 - blr - */ + enabled = OSDisableInterrupts(); + if (!reqCard->attached) { + result = CARD_RESULT_NOCARD; + } else if (reqCard->result == CARD_RESULT_BUSY) { + result = CARD_RESULT_BUSY; + } else { + reqCard->result = CARD_RESULT_BUSY; + result = CARD_RESULT_READY; + reqCard->apiCallback = nullptr; + *card = reqCard; + } + OSRestoreInterrupts(enabled); + return result; } /* @@ -1580,40 +667,18 @@ int __CARDGetControlBlock(int slotIndex, CARDBlock** outBlock) * Address: 800D5684 * Size: 000064 */ -int __CARDPutControlBlock(CARDBlock* block, unknown p2) +s32 __CARDPutControlBlock(CARDControl* card, s32 result) { - /* - .loc_0x0: - mflr r0 - stw r0, 0x4(r1) - stwu r1, -0x18(r1) - stw r31, 0x14(r1) - addi r31, r4, 0 - stw r30, 0x10(r1) - addi r30, r3, 0 - bl 0x19598 - lwz r0, 0x0(r30) - cmpwi r0, 0 - beq- .loc_0x34 - stw r31, 0x4(r30) - b .loc_0x44 + BOOL enabled; - .loc_0x34: - lwz r0, 0x4(r30) - cmpwi r0, -0x1 - bne- .loc_0x44 - stw r31, 0x4(r30) - - .loc_0x44: - bl 0x19598 - mr r3, r31 - lwz r0, 0x1C(r1) - lwz r31, 0x14(r1) - lwz r30, 0x10(r1) - addi r1, r1, 0x18 - mtlr r0 - blr - */ + enabled = OSDisableInterrupts(); + if (card->attached) { + card->result = result; + } else if (card->result == CARD_RESULT_BUSY) { + card->result = result; + } + OSRestoreInterrupts(enabled); + return result; } /* @@ -1621,9 +686,16 @@ int __CARDPutControlBlock(CARDBlock* block, unknown p2) * Address: ........ * Size: 000030 */ -void CARDGetResultCode(void) +s32 CARDGetResultCode(s32 channel) { - // UNUSED FUNCTION + CARDControl* card; + + if (channel < 0 || channel >= 2) { + return CARD_RESULT_FATAL_ERROR; + } + + card = &__CARDBlock[channel]; + return card->result; } /* @@ -1631,211 +703,93 @@ void CARDGetResultCode(void) * Address: 800D56E8 * Size: 000150 */ -int CARDFreeBlocks(int slotIndex, unknown p2, unknown p3) +s32 CARDFreeBlocks(s32 channel, s32* byteNotUsed, s32* filesNotUsed) { - /* - .loc_0x0: - mflr r0 - stw r0, 0x4(r1) - stwu r1, -0x30(r1) - stw r31, 0x2C(r1) - addi r31, r5, 0 - stw r30, 0x28(r1) - stw r29, 0x24(r1) - addi r29, r4, 0 - addi r4, r1, 0x18 - bl -0x140 - cmpwi r3, 0 - bge- .loc_0x34 - b .loc_0x134 + CARDControl* card; + s32 result; + CARDFatBlock* fat; + CARDDir* dir; + CARDDir* ent; + u16 fileNo; - .loc_0x34: - lwz r3, 0x18(r1) - bl 0x16E0 - mr r30, r3 - lwz r3, 0x18(r1) - bl 0x1A3C - cmplwi r30, 0 - beq- .loc_0x58 - cmplwi r3, 0 - bne- .loc_0x98 + result = __CARDGetControlBlock(channel, &card); + if (result < 0) { + return result; + } - .loc_0x58: - lwz r30, 0x18(r1) - bl 0x194F4 - lwz r0, 0x0(r30) - cmpwi r0, 0 - beq- .loc_0x78 - li r0, -0x6 - stw r0, 0x4(r30) - b .loc_0x8C + fat = __CARDGetFatBlock(card); + dir = __CARDGetDirBlock(card); + if (fat == nullptr || dir == nullptr) { + return __CARDPutControlBlock(card, CARD_RESULT_BROKEN); + } - .loc_0x78: - lwz r0, 0x4(r30) - cmpwi r0, -0x1 - bne- .loc_0x8C - li r0, -0x6 - stw r0, 0x4(r30) + if (byteNotUsed) { + *byteNotUsed = (s32)(card->sectorSize * fat->freeBlocks); + } - .loc_0x8C: - bl 0x194EC - li r3, -0x6 - b .loc_0x134 + if (filesNotUsed) { + *filesNotUsed = 0; + for (fileNo = 0; fileNo < CARD_MAX_FILE; fileNo++) { + ent = &dir[fileNo]; + if (ent->fileName[0] == 0xff) { + ++*filesNotUsed; + } + } + } - .loc_0x98: - cmplwi r29, 0 - beq- .loc_0xB4 - lwz r4, 0x18(r1) - lhz r0, 0x6(r30) - lwz r4, 0xC(r4) - mullw r0, r4, r0 - stw r0, 0x0(r29) - - .loc_0xB4: - cmplwi r31, 0 - beq- .loc_0xF8 - li r0, 0 - stw r0, 0x0(r31) - li r5, 0 - b .loc_0xEC - - .loc_0xCC: - lbz r0, 0x8(r3) - cmplwi r0, 0xFF - bne- .loc_0xE4 - lwz r4, 0x0(r31) - addi r0, r4, 0x1 - stw r0, 0x0(r31) - - .loc_0xE4: - addi r3, r3, 0x40 - addi r5, r5, 0x1 - - .loc_0xEC: - rlwinm r0,r5,0,16,31 - cmplwi r0, 0x7F - blt+ .loc_0xCC - - .loc_0xF8: - lwz r30, 0x18(r1) - bl 0x19454 - lwz r0, 0x0(r30) - cmpwi r0, 0 - beq- .loc_0x118 - li r0, 0 - stw r0, 0x4(r30) - b .loc_0x12C - - .loc_0x118: - lwz r0, 0x4(r30) - cmpwi r0, -0x1 - bne- .loc_0x12C - li r0, 0 - stw r0, 0x4(r30) - - .loc_0x12C: - bl 0x1944C - li r3, 0 - - .loc_0x134: - lwz r0, 0x34(r1) - lwz r31, 0x2C(r1) - lwz r30, 0x28(r1) - lwz r29, 0x24(r1) - addi r1, r1, 0x30 - mtlr r0 - blr - */ + return __CARDPutControlBlock(card, CARD_RESULT_READY); } -/* - * --INFO-- - * Address: ........ - * Size: 000088 - */ -void CARDGetEncoding(void) -{ - // UNUSED FUNCTION -} +// /* +// * --INFO-- +// * Address: ........ +// * Size: 000088 +// */ +// void CARDGetEncoding(void) +// { +// // UNUSED FUNCTION +// } -/* - * --INFO-- - * Address: ........ - * Size: 000084 - */ -void CARDGetMemSize(void) -{ - // UNUSED FUNCTION -} +// /* +// * --INFO-- +// * Address: ........ +// * Size: 000084 +// */ +// void CARDGetMemSize(void) +// { +// // UNUSED FUNCTION +// } -/* - * --INFO-- - * Address: ........ - * Size: 000084 - */ -void CARDGetSectorSize(void) -{ - // UNUSED FUNCTION -} +// /* +// * --INFO-- +// * Address: ........ +// * Size: 000084 +// */ +// void CARDGetSectorSize(void) +// { +// // UNUSED FUNCTION +// } /* * --INFO-- * Address: 800D5838 * Size: 000098 */ -int __CARDSync(int slotIndex) +s32 __CARDSync(s32 channel) { - /* - .loc_0x0: - mflr r0 - stw r0, 0x4(r1) - stwu r1, -0x20(r1) - stw r31, 0x1C(r1) - stw r30, 0x18(r1) - stw r29, 0x14(r1) - stw r28, 0x10(r1) - addi r28, r3, 0 - mulli r4, r28, 0x110 - lis r3, 0x804F - addi r0, r3, 0x5AF0 - add r31, r0, r4 - bl 0x193D0 - mr r29, r3 - b .loc_0x44 + CARDControl* card; + s32 result; + BOOL enabled; - .loc_0x3C: - addi r3, r31, 0x8C - bl 0x1D074 + card = &__CARDBlock[channel]; + enabled = OSDisableInterrupts(); - .loc_0x44: - cmpwi r28, 0 - blt- .loc_0x54 - cmpwi r28, 0x2 - blt- .loc_0x5C + while ((result = CARDGetResultCode(channel)) == CARD_RESULT_BUSY) { + OSSleepThread(&card->threadQueue); + } - .loc_0x54: - li r0, -0x80 - b .loc_0x60 - - .loc_0x5C: - lwz r0, 0x4(r31) - - .loc_0x60: - mr r30, r0 - cmpwi r30, -0x1 - beq+ .loc_0x3C - mr r3, r29 - bl 0x193B8 - mr r3, r30 - lwz r0, 0x24(r1) - lwz r31, 0x1C(r1) - lwz r30, 0x18(r1) - lwz r29, 0x14(r1) - lwz r28, 0x10(r1) - addi r1, r1, 0x20 - mtlr r0 - blr - */ + OSRestoreInterrupts(enabled); + return result; } /* @@ -1843,35 +797,13 @@ int __CARDSync(int slotIndex) * Address: 800D58D0 * Size: 000050 */ -BOOL OnReset(unknown p1) +BOOL OnReset(BOOL f) { - /* - .loc_0x0: - mflr r0 - cmpwi r3, 0 - stw r0, 0x4(r1) - stwu r1, -0x8(r1) - bne- .loc_0x3C - li r3, 0 - bl 0x3498 - cmpwi r3, -0x1 - beq- .loc_0x34 - li r3, 0x1 - bl 0x3488 - cmpwi r3, -0x1 - bne- .loc_0x3C + if (!f) { + if (CARDUnmount(0) == CARD_RESULT_BUSY || CARDUnmount(1) == CARD_RESULT_BUSY) { + return FALSE; + } + } - .loc_0x34: - li r3, 0 - b .loc_0x40 - - .loc_0x3C: - li r3, 0x1 - - .loc_0x40: - lwz r0, 0xC(r1) - addi r1, r1, 0x8 - mtlr r0 - blr - */ + return TRUE; } diff --git a/src/Dolphin/card/CARDBlock.c b/src/Dolphin/card/CARDBlock.c index a2ac9dd25..c1a44941d 100644 --- a/src/Dolphin/card/CARDBlock.c +++ b/src/Dolphin/card/CARDBlock.c @@ -1,94 +1,52 @@ #include "Dolphin/card.h" -void WriteCallback(int slotIndex, int p2); -void EraseCallback(int slotIndex, int p2); +void WriteCallback(s32 channel, s32 result); +void EraseCallback(s32 channel, s32 result); +s32 __CARDUpdateFatBlock(s32 channel, CARDFatBlock* fat, CARDCallback callback); /* * --INFO-- * Address: 800D6E00 * Size: 000008 */ -CARDFatBlock* __CARDGetFatBlock(CARDBlock* block) -{ - return block->_088; - /* - .loc_0x0: - lwz r3, 0x88(r3) - blr - */ -} +CARDFatBlock* __CARDGetFatBlock(CARDControl* card) { return card->currentFat; } /* * --INFO-- * Address: 800D6E08 * Size: 0000D4 */ -void WriteCallback(int slotIndex, int p2) +void WriteCallback(s32 channel, s32 result) { - /* - .loc_0x0: - mflr r0 - stw r0, 0x4(r1) - stwu r1, -0x20(r1) - stw r31, 0x1C(r1) - stw r30, 0x18(r1) - mr. r30, r4 - stw r29, 0x14(r1) - addi r29, r3, 0 - mulli r5, r29, 0x110 - lis r3, 0x804F - addi r0, r3, 0x5AF0 - add r31, r0, r5 - blt- .loc_0x78 - lwz r3, 0x80(r31) - lwz r0, 0x88(r31) - addi r4, r3, 0x6000 - cmplw r0, r4 - addis r5, r3, 0x1 - subi r5, r5, 0x8000 - bne- .loc_0x64 - stw r5, 0x88(r31) - addi r3, r5, 0 - li r5, 0x2000 - bl -0xD1CC8 - b .loc_0x78 + CARDControl* card; + CARDCallback callback; + CARDFatBlock* fat; + CARDFatBlock* fatBack; - .loc_0x64: - stw r4, 0x88(r31) - addi r3, r4, 0 - addi r4, r5, 0 - li r5, 0x2000 - bl -0xD1CE0 + card = &__CARDBlock[channel]; - .loc_0x78: - lwz r0, 0xD0(r31) - cmplwi r0, 0 - bne- .loc_0x90 - addi r3, r31, 0 - addi r4, r30, 0 - bl -0x1810 + if (result >= 0) { + fat = &card->workArea->blockAllocMap; + fatBack = &card->workArea->blockAllocMapBackup; - .loc_0x90: - lwz r0, 0xD8(r31) - cmplwi r0, 0 - mr r12, r0 - beq- .loc_0xB8 - li r0, 0 - mtlr r12 - stw r0, 0xD8(r31) - addi r3, r29, 0 - addi r4, r30, 0 - blrl + if (card->currentFat == fat) { + card->currentFat = fatBack; + memcpy(fatBack, fat, 0x2000); + } else { + card->currentFat = fat; + memcpy(fat, fatBack, 0x2000); + } + } - .loc_0xB8: - lwz r0, 0x24(r1) - lwz r31, 0x1C(r1) - lwz r30, 0x18(r1) - lwz r29, 0x14(r1) - addi r1, r1, 0x20 - mtlr r0 - blr - */ + if (card->apiCallback == nullptr) { + __CARDPutControlBlock(card, result); + } + + callback = card->eraseCallback; + if (callback) { + card->eraseCallback = nullptr; + callback(channel, result); + } } /* @@ -96,67 +54,37 @@ void WriteCallback(int slotIndex, int p2) * Address: 800D6EDC * Size: 0000C8 */ -void EraseCallback(int slotIndex, int p2) +void EraseCallback(s32 channel, s32 result) { - /* - .loc_0x0: - mflr r0 - stw r0, 0x4(r1) - stwu r1, -0x28(r1) - stw r31, 0x24(r1) - addi r31, r3, 0 - lis r3, 0x804F - stw r30, 0x20(r1) - mulli r5, r31, 0x110 - stw r29, 0x1C(r1) - addi r0, r3, 0x5AF0 - mr. r29, r4 - add r30, r0, r5 - blt- .loc_0x6C - lwz r5, 0x88(r30) - lis r3, 0x800D - lwz r0, 0x80(r30) - addi r7, r3, 0x6E08 - lwz r3, 0xC(r30) - sub r0, r5, r0 - rlwinm r0,r0,19,13,31 - mullw r4, r3, r0 - addi r6, r5, 0 - addi r3, r31, 0 - li r5, 0x2000 - bl -0x1A0 - mr. r29, r3 - bge- .loc_0xAC + CARDControl* card; + CARDCallback callback; + u32 temp[2]; /* this compiler sucks */ + CARDFatBlock* fat; + u32 addr; - .loc_0x6C: - lwz r0, 0xD0(r30) - cmplwi r0, 0 - bne- .loc_0x84 - addi r3, r30, 0 - addi r4, r29, 0 - bl -0x18D8 + card = &__CARDBlock[channel]; + if (result < 0) { + goto error; + } - .loc_0x84: - lwz r0, 0xD8(r30) - cmplwi r0, 0 - mr r12, r0 - beq- .loc_0xAC - li r0, 0 - mtlr r12 - stw r0, 0xD8(r30) - addi r3, r31, 0 - addi r4, r29, 0 - blrl + fat = __CARDGetFatBlock(card); + addr = ((u32)fat - (u32)card->workArea) / CARD_SYSTEM_BLOCK_SIZE * card->sectorSize; + result = __CARDWrite(channel, addr, CARD_SYSTEM_BLOCK_SIZE, fat, WriteCallback); + if (result < 0) { + goto error; + } - .loc_0xAC: - lwz r0, 0x2C(r1) - lwz r31, 0x24(r1) - lwz r30, 0x20(r1) - lwz r29, 0x1C(r1) - addi r1, r1, 0x28 - mtlr r0 - blr - */ + return; + +error: + if (card->apiCallback == nullptr) { + __CARDPutControlBlock(card, result); + } + callback = card->eraseCallback; + if (callback) { + card->eraseCallback = nullptr; + callback(channel, result); + } } /* @@ -164,114 +92,54 @@ void EraseCallback(int slotIndex, int p2) * Address: 800D6FA4 * Size: 000118 */ -void __CARDAllocBlock(void) +s32 __CARDAllocBlock(s32 chan, u32 cBlock, CARDCallback callback) { - /* - .loc_0x0: - mflr r0 - mulli r7, r3, 0x110 - stw r0, 0x4(r1) - stwu r1, -0x20(r1) - lis r6, 0x804F - addi r0, r6, 0x5AF0 - stw r31, 0x1C(r1) - add r9, r0, r7 - stw r30, 0x18(r1) - lwz r0, 0x0(r9) - cmpwi r0, 0 - bne- .loc_0x38 - li r3, -0x3 - b .loc_0x100 + CARDControl* card; + CARDFatBlock* fat; + u16 iBlock; + u16 startBlock; + u16 prevBlock; + u16 count; - .loc_0x38: - lwz r8, 0x88(r9) - lhz r0, 0x6(r8) - cmplw r0, r4 - bge- .loc_0x50 - li r3, -0x9 - b .loc_0x100 + card = &__CARDBlock[chan]; + if (!card->attached) { + return CARD_RESULT_NOCARD; + } - .loc_0x50: - sub r0, r0, r4 - sth r0, 0x6(r8) - lis r6, 0x1 - subi r12, r6, 0x1 - lhz r11, 0x8(r8) - addi r0, r12, 0 - li r30, 0 - b .loc_0xE8 + fat = __CARDGetFatBlock(card); + if (fat->freeBlocks < cBlock) { + return CARD_RESULT_INSSPACE; + } - .loc_0x70: - lhz r10, 0x10(r9) - addi r30, r30, 0x1 - rlwinm r6,r30,0,16,31 - subi r7, r10, 0x5 - cmpw r7, r6 - bge- .loc_0x90 - li r3, -0x6 - b .loc_0x100 + fat->freeBlocks -= cBlock; + startBlock = 0xFFFF; + iBlock = fat->lastAllocBlock; + count = 0; + while (0 < cBlock) { + if (card->cBlock - 5 < ++count) { + return CARD_RESULT_BROKEN; + } - .loc_0x90: - addi r11, r11, 0x1 - rlwinm r6,r11,0,16,31 - cmplwi r6, 0x5 - blt- .loc_0xA8 - cmplw r6, r10 - blt- .loc_0xAC + iBlock++; + if (!CARDIsValidBlockNo(card, iBlock)) { + iBlock = 5; + } - .loc_0xA8: - li r11, 0x5 + if (((u16*)fat)[iBlock] == 0x0000u) { + if (startBlock == 0xFFFF) { + startBlock = iBlock; + } else { + ((u16*)fat)[prevBlock] = iBlock; + } + prevBlock = iBlock; + ((u16*)fat)[iBlock] = 0xFFFF; + --cBlock; + } + } + fat->lastAllocBlock = iBlock; + card->startBlock = startBlock; - .loc_0xAC: - rlwinm r6,r11,1,15,30 - add r7, r8, r6 - lhz r6, 0x0(r7) - cmplwi r6, 0 - bne- .loc_0xE8 - rlwinm r6,r12,0,16,31 - cmplwi r6, 0xFFFF - bne- .loc_0xD4 - mr r12, r11 - b .loc_0xDC - - .loc_0xD4: - rlwinm r6,r31,1,15,30 - sthx r11, r8, r6 - - .loc_0xDC: - sth r0, 0x0(r7) - addi r31, r11, 0 - subi r4, r4, 0x1 - - .loc_0xE8: - cmplwi r4, 0 - bne+ .loc_0x70 - sth r11, 0x8(r8) - mr r4, r8 - sth r12, 0xBE(r9) - bl .loc_0x118 - - .loc_0x100: - lwz r0, 0x24(r1) - lwz r31, 0x1C(r1) - lwz r30, 0x18(r1) - addi r1, r1, 0x20 - mtlr r0 - blr - - .loc_0x118: - */ -} - -/* - * --INFO-- - * Address: ........ - * Size: 00009C - */ -// void __CARDFreeBlock(int slotIndex, CARDFatBlock* fatBlock, CARDBlockD8Callback* d8Callback) -void __CARDFreeBlock(void) -{ - // UNUSED FUNCTION + return __CARDUpdateFatBlock(chan, fat, callback); } /* @@ -279,61 +147,15 @@ void __CARDFreeBlock(void) * Address: 800D70BC * Size: 0000AC */ -void __CARDUpdateFatBlock(int slotIndex, CARDFatBlock* fatBlock, CARDBlockD8Callback* d8Callback) +s32 __CARDUpdateFatBlock(s32 channel, CARDFatBlock* fat, CARDCallback callback) { - fatBlock->updateCounter++; - // __CARDFreeBlock(slotIndex, fatBlock, d8Callback); - // TODO: The rest of the func may go in __CARDFreeBlock?: - CARDBlock* block = &__CARDBlock[slotIndex]; - __CARDCheckSum(&fatBlock->updateCounter, 0x1FFC, &fatBlock->checksum1, &fatBlock->checksum2); - DCStoreRange(&fatBlock, 0x2000); - block->_0D8 = d8Callback; - __CARDEraseSector(slotIndex, ((int)fatBlock - (int)block->_080) >> 0xD, EraseCallback); + CARDControl* card; - /* - .loc_0x0: - mflr r0 - stw r0, 0x4(r1) - stwu r1, -0x28(r1) - stw r31, 0x24(r1) - stw r30, 0x20(r1) - addi r30, r5, 0 - stw r29, 0x1C(r1) - addi r29, r4, 0 - addi r5, r29, 0 - stw r28, 0x18(r1) - addi r28, r3, 0 - addi r6, r29, 0x2 - lhz r3, 0x4(r4) - mulli r4, r28, 0x110 - addi r0, r3, 0x1 - lis r3, 0x804F - sth r0, 0x4(r29) - addi r0, r3, 0x5AF0 - add r31, r0, r4 - addi r3, r29, 0x4 - li r4, 0x1FFC - bl 0x2BC - addi r3, r29, 0 - li r4, 0x2000 - bl 0x1562C - stw r30, 0xD8(r31) - lis r3, 0x800D - addi r5, r3, 0x6EDC - lwz r0, 0x80(r31) - mr r3, r28 - lwz r4, 0xC(r31) - sub r0, r29, r0 - rlwinm r0,r0,19,13,31 - mullw r4, r4, r0 - bl -0x1D44 - lwz r0, 0x2C(r1) - lwz r31, 0x24(r1) - lwz r30, 0x20(r1) - lwz r29, 0x1C(r1) - lwz r28, 0x18(r1) - addi r1, r1, 0x28 - mtlr r0 - blr - */ + card = &__CARDBlock[channel]; + ++fat->checkCode; + __CARDCheckSum(&fat->checkCode, 0x1FFC, &fat->checkSum, &fat->checkSumInv); + DCStoreRange(fat, 0x2000); + card->eraseCallback = callback; + + return __CARDEraseSector(channel, (((u32)fat - (u32)card->workArea) / CARD_SYSTEM_BLOCK_SIZE) * card->sectorSize, EraseCallback); } diff --git a/src/Dolphin/card/CARDUnlock.c b/src/Dolphin/card/CARDUnlock.c index 6593d1f0d..47077279b 100644 --- a/src/Dolphin/card/CARDUnlock.c +++ b/src/Dolphin/card/CARDUnlock.c @@ -1,24 +1,74 @@ #include "Dolphin/card.h" #include "Dolphin/dsp.h" +static void InitCallback(void* task); +static void DoneCallback(void* task); + +static u8 CardData[] ATTRIBUTE_ALIGN(32) = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x02, 0xFF, 0x00, 0x21, 0x13, 0x06, 0x12, 0x03, 0x12, 0x04, 0x13, 0x05, 0x00, 0x92, 0x00, 0xFF, + 0x00, 0x88, 0xFF, 0xFF, 0x00, 0x89, 0xFF, 0xFF, 0x00, 0x8A, 0xFF, 0xFF, 0x00, 0x8B, 0xFF, 0xFF, 0x8F, 0x00, 0x02, 0xBF, 0x00, 0x88, + 0x16, 0xFC, 0xDC, 0xD1, 0x16, 0xFD, 0x00, 0x00, 0x16, 0xFB, 0x00, 0x01, 0x02, 0xBF, 0x00, 0x8E, 0x25, 0xFF, 0x03, 0x80, 0xFF, 0x00, + 0x02, 0x94, 0x00, 0x27, 0x02, 0xBF, 0x00, 0x8E, 0x1F, 0xDF, 0x24, 0xFF, 0x02, 0x40, 0x0F, 0xFF, 0x00, 0x98, 0x04, 0x00, 0x00, 0x9A, + 0x00, 0x10, 0x00, 0x99, 0x00, 0x00, 0x8E, 0x00, 0x02, 0xBF, 0x00, 0x94, 0x02, 0xBF, 0x86, 0x44, 0x02, 0xBF, 0x00, 0x88, 0x16, 0xFC, + 0xDC, 0xD1, 0x16, 0xFD, 0x00, 0x03, 0x16, 0xFB, 0x00, 0x01, 0x8F, 0x00, 0x02, 0xBF, 0x00, 0x8E, 0x03, 0x80, 0xCD, 0xD1, 0x02, 0x94, + 0x00, 0x48, 0x27, 0xFF, 0x03, 0x80, 0x00, 0x01, 0x02, 0x95, 0x00, 0x5A, 0x03, 0x80, 0x00, 0x02, 0x02, 0x95, 0x80, 0x00, 0x02, 0x9F, + 0x00, 0x48, 0x00, 0x21, 0x8E, 0x00, 0x02, 0xBF, 0x00, 0x8E, 0x25, 0xFF, 0x02, 0xBF, 0x00, 0x8E, 0x25, 0xFF, 0x02, 0xBF, 0x00, 0x8E, + 0x25, 0xFF, 0x02, 0xBF, 0x00, 0x8E, 0x00, 0xC5, 0xFF, 0xFF, 0x03, 0x40, 0x0F, 0xFF, 0x1C, 0x9F, 0x02, 0xBF, 0x00, 0x8E, 0x00, 0xC7, + 0xFF, 0xFF, 0x02, 0xBF, 0x00, 0x8E, 0x00, 0xC6, 0xFF, 0xFF, 0x02, 0xBF, 0x00, 0x8E, 0x00, 0xC0, 0xFF, 0xFF, 0x02, 0xBF, 0x00, 0x8E, + 0x20, 0xFF, 0x03, 0x40, 0x0F, 0xFF, 0x1F, 0x5F, 0x02, 0xBF, 0x00, 0x8E, 0x21, 0xFF, 0x02, 0xBF, 0x00, 0x8E, 0x23, 0xFF, 0x12, 0x05, + 0x12, 0x06, 0x02, 0x9F, 0x80, 0xB5, 0x00, 0x21, 0x27, 0xFC, 0x03, 0xC0, 0x80, 0x00, 0x02, 0x9D, 0x00, 0x88, 0x02, 0xDF, 0x27, 0xFE, + 0x03, 0xC0, 0x80, 0x00, 0x02, 0x9C, 0x00, 0x8E, 0x02, 0xDF, 0x2E, 0xCE, 0x2C, 0xCF, 0x00, 0xF8, 0xFF, 0xCD, 0x00, 0xF9, 0xFF, 0xC9, + 0x00, 0xFA, 0xFF, 0xCB, 0x26, 0xC9, 0x02, 0xC0, 0x00, 0x04, 0x02, 0x9D, 0x00, 0x9C, 0x02, 0xDF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + +static u32 next = 1; + +// bit manip macros for use in ReadArrayUnlock +#define SEC_AD1(x) ((u8)(((x) >> 29) & 0x03)) +#define SEC_AD2(x) ((u8)(((x) >> 21) & 0xff)) +#define SEC_AD3(x) ((u8)(((x) >> 19) & 0x03)) +#define SEC_BA(x) ((u8)(((x) >> 12) & 0x7f)) + /* * --INFO-- * Address: ........ * Size: 000024 */ -void CARDRand(void) +int CARDRand() { - // UNUSED FUNCTION + next = next * 1103515245 + 12345; + return (int)((u32)(next / 65536) % 32768); } /* * --INFO-- * Address: ........ * Size: 000008 + * Fun fact: making the argument of this a u32 instead of uint + * makes the inlined versions of this not match (: + * LOVE this compiler. */ -void CARDSrand(void) +void CARDSrand(uint seed) { next = seed; } + +/* + * --INFO-- + * Address: ........ + * Size: 000174 + */ +u32 exnor_1st(u32 data, u32 rshift) { - // UNUSED FUNCTION + u32 wk; + u32 w; + u32 i; + + w = data; + for (i = 0; i < rshift; i++) { + wk = ~(w ^ (w >> 7) ^ (w >> 15) ^ (w >> 23)); + w = (w >> 1) | ((wk << 30) & 0x40000000); + } + return w; } /* @@ -26,19 +76,19 @@ void CARDSrand(void) * Address: ........ * Size: 000174 */ -void exnor_1st(void) +u32 exnor(u32 data, u32 lshift) { - // UNUSED FUNCTION -} + u32 wk; + u32 w; + u32 i; -/* - * --INFO-- - * Address: ........ - * Size: 000174 - */ -void exnor(void) -{ - // UNUSED FUNCTION + w = data; + for (i = 0; i < lshift; i++) { + // 1bit Left Shift + wk = ~(w ^ (w << 7) ^ (w << 15) ^ (w << 23)); + w = (w << 1) | ((wk >> 30) & 0x00000002); + } + return w; } /* @@ -46,128 +96,28 @@ void exnor(void) * Address: 800D5920 * Size: 00016C */ -uint bitrev(uint) +u32 bitrev(u32 data) { - /* - .loc_0x0: - li r0, 0x8 - mtctr r0 - rlwinm r6,r3,1,31,31 - li r9, 0 - li r10, 0x1 - li r7, 0 - li r8, 0 - li r5, 0x1 + u32 wk; + u32 i; + u32 k = 0; + u32 j = 1; - .loc_0x20: - cmplwi r8, 0xF - ble- .loc_0x50 - cmplwi r8, 0x1F - bne- .loc_0x38 - or r7, r7, r6 - b .loc_0x6C - - .loc_0x38: - slw r0, r5, r8 - and r0, r3, r0 - srw r0, r0, r10 - or r7, r7, r0 - addi r10, r10, 0x2 - b .loc_0x6C - - .loc_0x50: - slw r4, r5, r8 - subfic r0, r8, 0x1F - sub r0, r0, r9 - and r4, r3, r4 - slw r0, r4, r0 - or r7, r7, r0 - addi r9, r9, 0x1 - - .loc_0x6C: - addi r8, r8, 0x1 - cmplwi r8, 0xF - ble- .loc_0xA0 - cmplwi r8, 0x1F - bne- .loc_0x88 - or r7, r7, r6 - b .loc_0xBC - - .loc_0x88: - slw r0, r5, r8 - and r0, r3, r0 - srw r0, r0, r10 - or r7, r7, r0 - addi r10, r10, 0x2 - b .loc_0xBC - - .loc_0xA0: - slw r4, r5, r8 - subfic r0, r8, 0x1F - sub r0, r0, r9 - and r4, r3, r4 - slw r0, r4, r0 - or r7, r7, r0 - addi r9, r9, 0x1 - - .loc_0xBC: - addi r8, r8, 0x1 - cmplwi r8, 0xF - ble- .loc_0xF0 - cmplwi r8, 0x1F - bne- .loc_0xD8 - or r7, r7, r6 - b .loc_0x10C - - .loc_0xD8: - slw r0, r5, r8 - and r0, r3, r0 - srw r0, r0, r10 - or r7, r7, r0 - addi r10, r10, 0x2 - b .loc_0x10C - - .loc_0xF0: - slw r4, r5, r8 - subfic r0, r8, 0x1F - sub r0, r0, r9 - and r4, r3, r4 - slw r0, r4, r0 - or r7, r7, r0 - addi r9, r9, 0x1 - - .loc_0x10C: - addi r8, r8, 0x1 - cmplwi r8, 0xF - ble- .loc_0x140 - cmplwi r8, 0x1F - bne- .loc_0x128 - or r7, r7, r6 - b .loc_0x15C - - .loc_0x128: - slw r0, r5, r8 - and r0, r3, r0 - srw r0, r0, r10 - or r7, r7, r0 - addi r10, r10, 0x2 - b .loc_0x15C - - .loc_0x140: - slw r4, r5, r8 - subfic r0, r8, 0x1F - sub r0, r0, r9 - and r4, r3, r4 - slw r0, r4, r0 - or r7, r7, r0 - addi r9, r9, 0x1 - - .loc_0x15C: - addi r8, r8, 0x1 - bdnz+ .loc_0x20 - mr r3, r7 - blr - */ + wk = 0; + for (i = 0; i < 32; i++) { + if (i > 15) { + if (i == 31) { + wk |= (((data & (0x01 << 31)) >> 31) & 0x01); + } else { + wk |= ((data & (0x01 << i)) >> j); + j += 2; + } + } else { + wk |= ((data & (0x01 << i)) << (31 - i - k)); + k++; + } + } + return wk; } /* @@ -175,102 +125,37 @@ uint bitrev(uint) * Address: 800D5A8C * Size: 000144 */ -void ReadArrayUnlock(int slotIndex, u32 p2, u8* buffer, int byteCount, unknown p5) +s32 ReadArrayUnlock(s32 channel, u32 data, void* buffer, s32 rlen, s32 mode) { - /* - .loc_0x0: - mflr r0 - stw r0, 0x4(r1) - stwu r1, -0x40(r1) - stmw r26, 0x28(r1) - addi r29, r3, 0 - lis r3, 0x804F - addi r0, r3, 0x5AF0 - mulli r8, r29, 0x110 - addi r26, r4, 0 - addi r30, r5, 0 - addi r31, r6, 0 - addi r27, r7, 0 - addi r3, r29, 0 - add r28, r0, r8 - li r4, 0 - li r5, 0x4 - bl 0xACE4 - cmpwi r3, 0 - bne- .loc_0x54 - li r3, -0x3 - b .loc_0x130 + CARDControl* card; + BOOL err; + u8 cmd[5]; - .loc_0x54: - rlwinm r26,r26,0,0,19 - addi r3, r1, 0x1C - li r4, 0 - li r5, 0x5 - bl -0xD0A3C - li r0, 0x52 - cmpwi r27, 0 - stb r0, 0x1C(r1) - bne- .loc_0x9C - rlwinm r0,r26,3,30,31 - stb r0, 0x1D(r1) - rlwinm r0,r26,11,24,31 - rlwinm r3,r26,13,30,31 - stb r0, 0x1E(r1) - rlwinm r0,r26,20,25,31 - stb r3, 0x1F(r1) - stb r0, 0x20(r1) - b .loc_0xAC + card = &__CARDBlock[channel]; + if (!EXISelect(channel, 0, 4)) { + return CARD_RESULT_NOCARD; + } - .loc_0x9C: - rlwinm r0,r26,8,24,31 - stb r0, 0x1D(r1) - rlwinm r0,r26,16,24,31 - stb r0, 0x1E(r1) + data &= 0xfffff000; + memset(cmd, 0, 5); + cmd[0] = 0x52; + if (mode == 0) { + cmd[1] = SEC_AD1(data); + cmd[2] = SEC_AD2(data); + cmd[3] = SEC_AD3(data); + cmd[4] = SEC_BA(data); + } else { + cmd[1] = (u8)((data & 0xff000000) >> 24); + cmd[2] = (u8)((data & 0x00ff0000) >> 16); + } - .loc_0xAC: - addi r3, r29, 0 - addi r4, r1, 0x1C - li r5, 0x5 - li r6, 0x1 - bl 0xA35C - lwz r4, 0x80(r28) - cntlzw r0, r3 - lwz r5, 0x14(r28) - addi r3, r29, 0 - rlwinm r28,r0,27,5,31 - addi r4, r4, 0x200 - li r6, 0x1 - bl 0xA33C - cntlzw r0, r3 - rlwinm r0,r0,27,5,31 - addi r3, r29, 0 - addi r4, r30, 0 - addi r5, r31, 0 - or r28, r28, r0 - li r6, 0 - bl 0xA31C - cntlzw r0, r3 - rlwinm r0,r0,27,5,31 - addi r3, r29, 0 - or r28, r28, r0 - bl 0xAD40 - cntlzw r0, r3 - rlwinm r0,r0,27,5,31 - or. r28, r28, r0 - beq- .loc_0x12C - li r3, -0x3 - b .loc_0x130 + err = FALSE; + err |= !EXIImmEx(channel, cmd, 5, 1); + err |= !EXIImmEx(channel, card->workArea->header.buffer, card->latency, 1); + err |= !EXIImmEx(channel, buffer, rlen, 0); + err |= !EXIDeselect(channel); - .loc_0x12C: - li r3, 0 - - .loc_0x130: - lmw r26, 0x28(r1) - lwz r0, 0x44(r1) - addi r1, r1, 0x40 - mtlr r0 - blr - */ + return err ? CARD_RESULT_NOCARD : CARD_RESULT_READY; } /* @@ -278,9 +163,17 @@ void ReadArrayUnlock(int slotIndex, u32 p2, u8* buffer, int byteCount, unknown p * Address: ........ * Size: 000054 */ -void GetInitVal(void) +u32 GetInitVal() { - // UNUSED FUNCTION + u32 tmp; + u32 tick; + + tick = OSGetTick(); + CARDSrand(tick); + tmp = 0x7FEC8000; + tmp |= CARDRand(); + tmp &= 0xFFFFF000; + return tmp; } /* @@ -288,70 +181,39 @@ void GetInitVal(void) * Address: 800D5BD0 * Size: 0000C4 */ -int DummyLen(void) +s32 DummyLen() { - /* - .loc_0x0: - mflr r0 - stw r0, 0x4(r1) - stwu r1, -0x28(r1) - stw r31, 0x24(r1) - stw r30, 0x20(r1) - li r30, 0x1 - stw r29, 0x1C(r1) - li r29, 0 - bl 0x1CFB8 - stw r3, -0x7D70(r13) - lis r3, 0x41C6 - addi r31, r3, 0x4E6D - lwz r0, -0x7D70(r13) - mullw r3, r0, r31 - addi r0, r3, 0x3039 - stw r0, -0x7D70(r13) - lwz r0, -0x7D70(r13) - rlwinm r3,r0,16,27,31 - addi r3, r3, 0x1 - b .loc_0x8C + u32 tick; + u32 wk; + s32 tmp; + u32 max; - .loc_0x50: - bl 0x1CF88 - slw r0, r3, r30 - addi r30, r30, 0x1 - cmplwi r30, 0x10 - ble- .loc_0x68 - li r30, 0x1 + wk = 1; + max = 0; + tick = OSGetTick(); + CARDSrand(tick); - .loc_0x68: - stw r0, -0x7D70(r13) - addi r29, r29, 0x1 - lwz r0, -0x7D70(r13) - mullw r3, r0, r31 - addi r0, r3, 0x3039 - stw r0, -0x7D70(r13) - lwz r0, -0x7D70(r13) - rlwinm r3,r0,16,27,31 - addi r3, r3, 0x1 + tmp = CARDRand(); + tmp &= 0x0000001f; + tmp += 1; + while ((tmp < 4) && (max < 10)) { + tick = OSGetTick(); + tmp = (s32)(tick << wk); + wk++; + if (wk > 16) { + wk = 1; + } + CARDSrand((u32)tmp); + tmp = CARDRand(); + tmp &= 0x0000001f; + tmp += 1; + max++; + } + if (tmp < 4) { + tmp = 4; + } - .loc_0x8C: - cmpwi r3, 0x4 - bge- .loc_0x9C - cmplwi r29, 0xA - blt+ .loc_0x50 - - .loc_0x9C: - cmpwi r3, 0x4 - bge- .loc_0xA8 - li r3, 0x4 - - .loc_0xA8: - lwz r0, 0x2C(r1) - lwz r31, 0x24(r1) - lwz r30, 0x20(r1) - lwz r29, 0x1C(r1) - addi r1, r1, 0x28 - mtlr r0 - blr - */ + return tmp; } /* @@ -359,773 +221,124 @@ int DummyLen(void) * Address: 800D5C94 * Size: 000B58 */ -int __CARDUnlock(int slotIndex, void* p2) +s32 __CARDUnlock(s32 channel, u8 flashID[12]) { - /* - .loc_0x0: - mflr r0 - stw r0, 0x4(r1) - stwu r1, -0x120(r1) - stmw r22, 0xF8(r1) - addi r24, r3, 0 - lis r3, 0x804F - mulli r5, r24, 0x110 - addi r0, r3, 0x5AF0 - add r31, r0, r5 - addi r23, r4, 0 - addi r30, r31, 0x30 - lwz r3, 0x80(r31) - addi r0, r3, 0x2F - rlwinm r28,r0,0,0,26 - addi r29, r3, 0 - addi r22, r28, 0x20 - bl 0x1CED4 - stw r3, -0x7D70(r13) - lis r3, 0x41C6 - lis r5, 0x7FED - lwz r4, -0x7D70(r13) - addi r0, r3, 0x4E6D - subi r25, r5, 0x8000 - mullw r3, r4, r0 - addi r0, r3, 0x3039 - stw r0, -0x7D70(r13) - lwz r0, -0x7D70(r13) - rlwinm r0,r0,16,17,31 - or r25, r25, r0 - rlwinm r25,r25,0,0,19 - bl -0x13C - addi r26, r3, 0 - addi r6, r26, 0 - addi r3, r24, 0 - addi r4, r25, 0 - addi r5, r1, 0xA4 - li r7, 0 - bl -0x29C - cmpwi r3, 0 - bge- .loc_0xA8 - li r3, -0x3 - b .loc_0xB44 + u32 init_val; + u32 data; - .loc_0xA8: - rlwinm r3,r26,3,0,28 - addi r4, r3, 0x1 - cmplwi r4, 0 - li r3, 0 - ble- .loc_0x220 - cmplwi r4, 0x8 - subi r5, r4, 0x8 - ble- .loc_0x1E8 - addi r0, r5, 0x7 - rlwinm r0,r0,29,3,31 - cmplwi r5, 0 - mtctr r0 - ble- .loc_0x1E8 + s32 dummy; + s32 rlen; + u32 rshift; - .loc_0xDC: - rlwinm r0,r25,25,7,31 - rlwinm r5,r25,17,15,31 - xor r0, r25, r0 - xor r0, r5, r0 - rlwinm r6,r25,9,23,31 - eqv r0, r6, r0 - rlwinm r5,r25,31,1,31 - rlwinm r0,r0,30,1,1 - or r7, r5, r0 - rlwinm r0,r7,25,7,31 - rlwinm r5,r7,17,15,31 - xor r0, r7, r0 - rlwinm r6,r7,9,23,31 - xor r0, r5, r0 - eqv r0, r6, r0 - rlwinm r8,r0,30,1,1 - rlwimi r8,r7,31,2,31 - rlwinm r0,r8,25,7,31 - rlwinm r5,r8,17,15,31 - xor r0, r8, r0 - rlwinm r6,r8,9,23,31 - xor r0, r5, r0 - eqv r0, r6, r0 - rlwinm r7,r0,30,1,1 - rlwimi r7,r8,31,2,31 - rlwinm r0,r7,25,7,31 - rlwinm r5,r7,17,15,31 - xor r0, r7, r0 - rlwinm r6,r7,9,23,31 - xor r0, r5, r0 - eqv r0, r6, r0 - rlwinm r8,r0,30,1,1 - rlwimi r8,r7,31,2,31 - rlwinm r0,r8,25,7,31 - rlwinm r5,r8,17,15,31 - xor r0, r8, r0 - rlwinm r6,r8,9,23,31 - xor r0, r5, r0 - eqv r0, r6, r0 - rlwinm r7,r0,30,1,1 - rlwimi r7,r8,31,2,31 - rlwinm r0,r7,25,7,31 - rlwinm r5,r7,17,15,31 - xor r0, r7, r0 - rlwinm r6,r7,9,23,31 - xor r0, r5, r0 - eqv r0, r6, r0 - rlwinm r8,r0,30,1,1 - rlwimi r8,r7,31,2,31 - rlwinm r0,r8,25,7,31 - rlwinm r5,r8,17,15,31 - xor r0, r8, r0 - rlwinm r6,r8,9,23,31 - xor r0, r5, r0 - eqv r0, r6, r0 - rlwinm r7,r0,30,1,1 - rlwimi r7,r8,31,2,31 - rlwinm r0,r7,25,7,31 - rlwinm r5,r7,17,15,31 - xor r0, r7, r0 - rlwinm r6,r7,9,23,31 - xor r0, r5, r0 - eqv r0, r6, r0 - rlwinm r25,r0,30,1,1 - rlwimi r25,r7,31,2,31 - addi r3, r3, 0x8 - bdnz+ .loc_0xDC + u8 fsts; + u32 wk, wk1; + u32 Ans1 = 0; + u32 Ans2 = 0; + u32* dp; + u8 rbuf[64]; + u32 para1A = 0; + u32 para1B = 0; + u32 para2A = 0; + u32 para2B = 0; - .loc_0x1E8: - sub r0, r4, r3 - cmplw r3, r4 - mtctr r0 - bge- .loc_0x220 + CARDControl* card; + DSPTaskInfo* task; + CARDDecodeParameters* param; + u8* input; + u8* output; - .loc_0x1F8: - rlwinm r0,r25,25,7,31 - rlwinm r3,r25,17,15,31 - xor r0, r25, r0 - rlwinm r4,r25,9,23,31 - xor r0, r3, r0 - eqv r0, r4, r0 - rlwinm r3,r25,31,1,31 - rlwinm r0,r0,30,1,1 - or r25, r3, r0 - bdnz+ .loc_0x1F8 + card = &__CARDBlock[channel]; + task = &card->task; + param = (CARDDecodeParameters*)card->workArea; + input = (u8*)((u8*)param + sizeof(CARDDecodeParameters)); + input = (u8*)OSRoundUp32B(input); + output = input + 32; - .loc_0x220: - rlwinm r0,r25,25,7,31 - rlwinm r3,r25,17,15,31 - xor r0, r25, r0 - rlwinm r4,r25,9,23,31 - xor r0, r3, r0 - eqv r0, r4, r0 - rlwinm r0,r0,31,0,0 - or r0, r25, r0 - stw r0, 0x2C(r31) - lwz r3, 0x2C(r31) - bl -0x5BC - stw r3, 0x2C(r31) - bl -0x314 - addi r27, r3, 0 - addi r6, r27, 0x14 - addi r3, r24, 0 - addi r5, r1, 0xA4 - li r4, 0 - li r7, 0x1 - bl -0x474 - cmpwi r3, 0 - bge- .loc_0x280 - li r3, -0x3 - b .loc_0xB44 + fsts = 0; + init_val = GetInitVal(); - .loc_0x280: - li r3, 0x4 - lwz r7, 0x2C(r31) - lwz r25, 0xA4(r1) - mtctr r3 - lwz r26, 0xA8(r1) - lwz r24, 0xAC(r1) - xor r25, r25, r7 - lwz r0, 0xB0(r1) - lwz r5, 0xB4(r1) + dummy = DummyLen(); + rlen = dummy; + if (ReadArrayUnlock(channel, init_val, rbuf, rlen, 0) < 0) { + return CARD_RESULT_NOCARD; + } - .loc_0x2A4: - rlwinm r3,r7,7,0,24 - rlwinm r4,r7,15,0,16 - xor r3, r7, r3 - xor r3, r4, r3 - rlwinm r6,r7,23,0,8 - eqv r3, r6, r3 - rlwinm r4,r7,1,0,30 - rlwinm r3,r3,2,30,30 - or r7, r4, r3 - rlwinm r3,r7,7,0,24 - rlwinm r4,r7,15,0,16 - xor r3, r7, r3 - rlwinm r6,r7,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r9,r3,2,30,30 - rlwimi r9,r7,1,0,29 - rlwinm r3,r9,7,0,24 - rlwinm r4,r9,15,0,16 - xor r3, r9, r3 - rlwinm r6,r9,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r8,r3,2,30,30 - rlwimi r8,r9,1,0,29 - rlwinm r3,r8,7,0,24 - rlwinm r4,r8,15,0,16 - xor r3, r8, r3 - rlwinm r6,r8,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r7,r3,2,30,30 - rlwimi r7,r8,1,0,29 - rlwinm r3,r7,7,0,24 - rlwinm r4,r7,15,0,16 - xor r3, r7, r3 - rlwinm r6,r7,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r8,r3,2,30,30 - rlwimi r8,r7,1,0,29 - rlwinm r3,r8,7,0,24 - rlwinm r4,r8,15,0,16 - xor r3, r8, r3 - rlwinm r6,r8,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r7,r3,2,30,30 - rlwimi r7,r8,1,0,29 - rlwinm r3,r7,7,0,24 - rlwinm r4,r7,15,0,16 - xor r3, r7, r3 - rlwinm r6,r7,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r8,r3,2,30,30 - rlwimi r8,r7,1,0,29 - rlwinm r3,r8,7,0,24 - rlwinm r4,r8,15,0,16 - xor r3, r8, r3 - rlwinm r6,r8,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r7,r3,2,30,30 - rlwimi r7,r8,1,0,29 - bdnz+ .loc_0x2A4 - rlwinm r3,r7,7,0,24 - rlwinm r4,r7,15,0,16 - xor r3, r7, r3 - rlwinm r6,r7,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r3,r3,1,31,31 - or r3, r7, r3 - stw r3, 0x2C(r31) - li r3, 0x4 - mtctr r3 - lwz r7, 0x2C(r31) - xor r26, r26, r7 + rshift = (u32)(dummy * 8 + 1); + wk = exnor_1st(init_val, rshift); + wk1 = ~(wk ^ (wk >> 7) ^ (wk >> 15) ^ (wk >> 23)); + card->scramble = (wk | ((wk1 << 31) & 0x80000000)); + card->scramble = bitrev(card->scramble); + dummy = DummyLen(); + rlen = 20 + dummy; + data = 0; + if (ReadArrayUnlock(channel, data, rbuf, rlen, 1) < 0) { + return CARD_RESULT_NOCARD; + } + dp = (u32*)rbuf; + para1A = *dp++; + para1B = *dp++; + Ans1 = *dp++; + para2A = *dp++; + para2B = *dp++; + para1A = (para1A ^ card->scramble); + rshift = 32; + wk = exnor(card->scramble, rshift); + wk1 = ~(wk ^ (wk << 7) ^ (wk << 15) ^ (wk << 23)); + card->scramble = (wk | ((wk1 >> 31) & 0x00000001)); + para1B = (para1B ^ card->scramble); + rshift = 32; + wk = exnor(card->scramble, rshift); + wk1 = ~(wk ^ (wk << 7) ^ (wk << 15) ^ (wk << 23)); + card->scramble = (wk | ((wk1 >> 31) & 0x00000001)); + Ans1 ^= card->scramble; + rshift = 32; + wk = exnor(card->scramble, rshift); + wk1 = ~(wk ^ (wk << 7) ^ (wk << 15) ^ (wk << 23)); + card->scramble = (wk | ((wk1 >> 31) & 0x00000001)); + para2A = (para2A ^ card->scramble); + rshift = 32; + wk = exnor(card->scramble, rshift); + wk1 = ~(wk ^ (wk << 7) ^ (wk << 15) ^ (wk << 23)); + card->scramble = (wk | ((wk1 >> 31) & 0x00000001)); + para2B = (para2B ^ card->scramble); + rshift = (u32)(dummy * 8); + wk = exnor(card->scramble, rshift); + wk1 = ~(wk ^ (wk << 7) ^ (wk << 15) ^ (wk << 23)); + card->scramble = (wk | ((wk1 >> 31) & 0x00000001)); + rshift = 32 + 1; + wk = exnor(card->scramble, rshift); + wk1 = ~(wk ^ (wk << 7) ^ (wk << 15) ^ (wk << 23)); + card->scramble = (wk | ((wk1 >> 31) & 0x00000001)); - .loc_0x3E0: - rlwinm r3,r7,7,0,24 - rlwinm r4,r7,15,0,16 - xor r3, r7, r3 - xor r3, r4, r3 - rlwinm r6,r7,23,0,8 - eqv r3, r6, r3 - rlwinm r4,r7,1,0,30 - rlwinm r3,r3,2,30,30 - or r7, r4, r3 - rlwinm r3,r7,7,0,24 - rlwinm r4,r7,15,0,16 - xor r3, r7, r3 - rlwinm r6,r7,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r9,r3,2,30,30 - rlwimi r9,r7,1,0,29 - rlwinm r3,r9,7,0,24 - rlwinm r4,r9,15,0,16 - xor r3, r9, r3 - rlwinm r6,r9,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r8,r3,2,30,30 - rlwimi r8,r9,1,0,29 - rlwinm r3,r8,7,0,24 - rlwinm r4,r8,15,0,16 - xor r3, r8, r3 - rlwinm r6,r8,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r7,r3,2,30,30 - rlwimi r7,r8,1,0,29 - rlwinm r3,r7,7,0,24 - rlwinm r4,r7,15,0,16 - xor r3, r7, r3 - rlwinm r6,r7,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r8,r3,2,30,30 - rlwimi r8,r7,1,0,29 - rlwinm r3,r8,7,0,24 - rlwinm r4,r8,15,0,16 - xor r3, r8, r3 - rlwinm r6,r8,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r7,r3,2,30,30 - rlwimi r7,r8,1,0,29 - rlwinm r3,r7,7,0,24 - rlwinm r4,r7,15,0,16 - xor r3, r7, r3 - rlwinm r6,r7,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r8,r3,2,30,30 - rlwimi r8,r7,1,0,29 - rlwinm r3,r8,7,0,24 - rlwinm r4,r8,15,0,16 - xor r3, r8, r3 - rlwinm r6,r8,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r7,r3,2,30,30 - rlwimi r7,r8,1,0,29 - bdnz+ .loc_0x3E0 - rlwinm r3,r7,7,0,24 - rlwinm r4,r7,15,0,16 - xor r3, r7, r3 - rlwinm r6,r7,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r3,r3,1,31,31 - or r3, r7, r3 - stw r3, 0x2C(r31) - li r3, 0x4 - mtctr r3 - lwz r7, 0x2C(r31) - xor r24, r24, r7 + *(u32*)&input[0] = para2A; + *(u32*)&input[4] = para2B; - .loc_0x51C: - rlwinm r3,r7,7,0,24 - rlwinm r4,r7,15,0,16 - xor r3, r7, r3 - xor r3, r4, r3 - rlwinm r6,r7,23,0,8 - eqv r3, r6, r3 - rlwinm r4,r7,1,0,30 - rlwinm r3,r3,2,30,30 - or r7, r4, r3 - rlwinm r3,r7,7,0,24 - rlwinm r4,r7,15,0,16 - xor r3, r7, r3 - rlwinm r6,r7,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r9,r3,2,30,30 - rlwimi r9,r7,1,0,29 - rlwinm r3,r9,7,0,24 - rlwinm r4,r9,15,0,16 - xor r3, r9, r3 - rlwinm r6,r9,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r8,r3,2,30,30 - rlwimi r8,r9,1,0,29 - rlwinm r3,r8,7,0,24 - rlwinm r4,r8,15,0,16 - xor r3, r8, r3 - rlwinm r6,r8,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r7,r3,2,30,30 - rlwimi r7,r8,1,0,29 - rlwinm r3,r7,7,0,24 - rlwinm r4,r7,15,0,16 - xor r3, r7, r3 - rlwinm r6,r7,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r8,r3,2,30,30 - rlwimi r8,r7,1,0,29 - rlwinm r3,r8,7,0,24 - rlwinm r4,r8,15,0,16 - xor r3, r8, r3 - rlwinm r6,r8,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r7,r3,2,30,30 - rlwimi r7,r8,1,0,29 - rlwinm r3,r7,7,0,24 - rlwinm r4,r7,15,0,16 - xor r3, r7, r3 - rlwinm r6,r7,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r8,r3,2,30,30 - rlwimi r8,r7,1,0,29 - rlwinm r3,r8,7,0,24 - rlwinm r4,r8,15,0,16 - xor r3, r8, r3 - rlwinm r6,r8,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r7,r3,2,30,30 - rlwimi r7,r8,1,0,29 - bdnz+ .loc_0x51C - rlwinm r3,r7,7,0,24 - rlwinm r4,r7,15,0,16 - xor r3, r7, r3 - rlwinm r6,r7,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r3,r3,1,31,31 - or r3, r7, r3 - stw r3, 0x2C(r31) - li r3, 0x4 - mtctr r3 - lwz r7, 0x2C(r31) - xor r0, r0, r7 + param->inputAddr = input; + param->inputLength = 8; + param->outputAddr = output; + param->aramAddr = 0; - .loc_0x658: - rlwinm r3,r7,7,0,24 - rlwinm r4,r7,15,0,16 - xor r3, r7, r3 - xor r3, r4, r3 - rlwinm r6,r7,23,0,8 - eqv r3, r6, r3 - rlwinm r4,r7,1,0,30 - rlwinm r3,r3,2,30,30 - or r7, r4, r3 - rlwinm r3,r7,7,0,24 - rlwinm r4,r7,15,0,16 - xor r3, r7, r3 - rlwinm r6,r7,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r9,r3,2,30,30 - rlwimi r9,r7,1,0,29 - rlwinm r3,r9,7,0,24 - rlwinm r4,r9,15,0,16 - xor r3, r9, r3 - rlwinm r6,r9,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r8,r3,2,30,30 - rlwimi r8,r9,1,0,29 - rlwinm r3,r8,7,0,24 - rlwinm r4,r8,15,0,16 - xor r3, r8, r3 - rlwinm r6,r8,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r7,r3,2,30,30 - rlwimi r7,r8,1,0,29 - rlwinm r3,r7,7,0,24 - rlwinm r4,r7,15,0,16 - xor r3, r7, r3 - rlwinm r6,r7,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r8,r3,2,30,30 - rlwimi r8,r7,1,0,29 - rlwinm r3,r8,7,0,24 - rlwinm r4,r8,15,0,16 - xor r3, r8, r3 - rlwinm r6,r8,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r7,r3,2,30,30 - rlwimi r7,r8,1,0,29 - rlwinm r3,r7,7,0,24 - rlwinm r4,r7,15,0,16 - xor r3, r7, r3 - rlwinm r6,r7,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r8,r3,2,30,30 - rlwimi r8,r7,1,0,29 - rlwinm r3,r8,7,0,24 - rlwinm r4,r8,15,0,16 - xor r3, r8, r3 - rlwinm r6,r8,23,0,8 - xor r3, r4, r3 - eqv r3, r6, r3 - rlwinm r7,r3,2,30,30 - rlwimi r7,r8,1,0,29 - bdnz+ .loc_0x658 - rlwinm r3,r7,7,0,24 - rlwinm r4,r7,15,0,16 - xor r3, r7, r3 - xor r3, r4, r3 - rlwinm r6,r7,23,0,8 - eqv r3, r6, r3 - rlwinm r3,r3,1,31,31 - or r3, r7, r3 - stw r3, 0x2C(r31) - rlwinm r4,r27,3,0,28 - cmplwi r4, 0 - lwz r6, 0x2C(r31) - li r3, 0 - xor r5, r5, r6 - ble- .loc_0x900 - cmplwi r4, 0x8 - subi r8, r4, 0x8 - ble- .loc_0x8C8 - addi r7, r8, 0x7 - rlwinm r7,r7,29,3,31 - cmplwi r8, 0 - mtctr r7 - ble- .loc_0x8C8 + DCFlushRange(input, 8); + DCInvalidateRange(output, 4); + DCFlushRange(param, sizeof(CARDDecodeParameters)); - .loc_0x7BC: - rlwinm r7,r6,7,0,24 - rlwinm r8,r6,15,0,16 - xor r7, r6, r7 - xor r7, r8, r7 - rlwinm r9,r6,23,0,8 - eqv r7, r9, r7 - rlwinm r8,r6,1,0,30 - rlwinm r6,r7,2,30,30 - or r9, r8, r6 - rlwinm r6,r9,7,0,24 - rlwinm r7,r9,15,0,16 - xor r6, r9, r6 - rlwinm r8,r9,23,0,8 - xor r6, r7, r6 - eqv r6, r8, r6 - rlwinm r10,r6,2,30,30 - rlwimi r10,r9,1,0,29 - rlwinm r6,r10,7,0,24 - rlwinm r7,r10,15,0,16 - xor r6, r10, r6 - rlwinm r8,r10,23,0,8 - xor r6, r7, r6 - eqv r6, r8, r6 - rlwinm r9,r6,2,30,30 - rlwimi r9,r10,1,0,29 - rlwinm r6,r9,7,0,24 - rlwinm r7,r9,15,0,16 - xor r6, r9, r6 - rlwinm r8,r9,23,0,8 - xor r6, r7, r6 - eqv r6, r8, r6 - rlwinm r10,r6,2,30,30 - rlwimi r10,r9,1,0,29 - rlwinm r6,r10,7,0,24 - rlwinm r7,r10,15,0,16 - xor r6, r10, r6 - rlwinm r8,r10,23,0,8 - xor r6, r7, r6 - eqv r6, r8, r6 - rlwinm r9,r6,2,30,30 - rlwimi r9,r10,1,0,29 - rlwinm r6,r9,7,0,24 - rlwinm r7,r9,15,0,16 - xor r6, r9, r6 - rlwinm r8,r9,23,0,8 - xor r6, r7, r6 - eqv r6, r8, r6 - rlwinm r10,r6,2,30,30 - rlwimi r10,r9,1,0,29 - rlwinm r6,r10,7,0,24 - rlwinm r7,r10,15,0,16 - xor r6, r10, r6 - rlwinm r8,r10,23,0,8 - xor r6, r7, r6 - eqv r6, r8, r6 - rlwinm r9,r6,2,30,30 - rlwimi r9,r10,1,0,29 - rlwinm r6,r9,7,0,24 - rlwinm r7,r9,15,0,16 - xor r6, r9, r6 - rlwinm r8,r9,23,0,8 - xor r6, r7, r6 - eqv r6, r8, r6 - rlwinm r6,r6,2,30,30 - rlwimi r6,r9,1,0,29 - addi r3, r3, 0x8 - bdnz+ .loc_0x7BC + task->priority = 255; + task->iram_mmem_addr = (u16*)OSPhysicalToCached(CardData); + task->iram_length = 0x160; + task->iram_addr = 0; + task->dsp_init_vector = 0x10; + task->init_cb = InitCallback; + task->res_cb = nullptr; + task->done_cb = DoneCallback; + task->req_cb = nullptr; + DSPAddTask(task); - .loc_0x8C8: - sub r7, r4, r3 - cmplw r3, r4 - mtctr r7 - bge- .loc_0x900 + dp = (u32*)flashID; + *dp++ = para1A; + *dp++ = para1B; + *dp = Ans1; - .loc_0x8D8: - rlwinm r3,r6,7,0,24 - rlwinm r4,r6,15,0,16 - xor r3, r6, r3 - rlwinm r7,r6,23,0,8 - xor r3, r4, r3 - eqv r3, r7, r3 - rlwinm r4,r6,1,0,30 - rlwinm r3,r3,2,30,30 - or r6, r4, r3 - bdnz+ .loc_0x8D8 - - .loc_0x900: - rlwinm r3,r6,7,0,24 - rlwinm r4,r6,15,0,16 - xor r3, r6, r3 - rlwinm r7,r6,23,0,8 - xor r3, r4, r3 - eqv r3, r7, r3 - rlwinm r3,r3,1,31,31 - or r3, r6, r3 - stw r3, 0x2C(r31) - li r3, 0x4 - mtctr r3 - li r3, 0 - lwz r4, 0x2C(r31) - - .loc_0x934: - rlwinm r6,r4,7,0,24 - rlwinm r7,r4,15,0,16 - xor r6, r4, r6 - xor r6, r7, r6 - rlwinm r8,r4,23,0,8 - eqv r6, r8, r6 - rlwinm r7,r4,1,0,30 - rlwinm r4,r6,2,30,30 - or r8, r7, r4 - rlwinm r4,r8,7,0,24 - rlwinm r6,r8,15,0,16 - xor r4, r8, r4 - rlwinm r7,r8,23,0,8 - xor r4, r6, r4 - eqv r4, r7, r4 - rlwinm r9,r4,2,30,30 - rlwimi r9,r8,1,0,29 - rlwinm r4,r9,7,0,24 - rlwinm r6,r9,15,0,16 - xor r4, r9, r4 - rlwinm r7,r9,23,0,8 - xor r4, r6, r4 - eqv r4, r7, r4 - rlwinm r8,r4,2,30,30 - rlwimi r8,r9,1,0,29 - rlwinm r4,r8,7,0,24 - rlwinm r6,r8,15,0,16 - xor r4, r8, r4 - rlwinm r7,r8,23,0,8 - xor r4, r6, r4 - eqv r4, r7, r4 - rlwinm r9,r4,2,30,30 - rlwimi r9,r8,1,0,29 - rlwinm r4,r9,7,0,24 - rlwinm r6,r9,15,0,16 - xor r4, r9, r4 - rlwinm r7,r9,23,0,8 - xor r4, r6, r4 - eqv r4, r7, r4 - rlwinm r8,r4,2,30,30 - rlwimi r8,r9,1,0,29 - rlwinm r4,r8,7,0,24 - rlwinm r6,r8,15,0,16 - xor r4, r8, r4 - rlwinm r7,r8,23,0,8 - xor r4, r6, r4 - eqv r4, r7, r4 - rlwinm r9,r4,2,30,30 - rlwimi r9,r8,1,0,29 - rlwinm r4,r9,7,0,24 - rlwinm r6,r9,15,0,16 - xor r4, r9, r4 - rlwinm r7,r9,23,0,8 - xor r4, r6, r4 - eqv r4, r7, r4 - rlwinm r8,r4,2,30,30 - rlwimi r8,r9,1,0,29 - rlwinm r4,r8,7,0,24 - rlwinm r6,r8,15,0,16 - xor r4, r8, r4 - rlwinm r7,r8,23,0,8 - xor r4, r6, r4 - eqv r4, r7, r4 - rlwinm r4,r4,2,30,30 - rlwimi r4,r8,1,0,29 - addi r3, r3, 0x8 - bdnz+ .loc_0x934 - subfic r6, r3, 0x21 - cmplwi r3, 0x21 - mtctr r6 - bge- .loc_0xA78 - - .loc_0xA50: - rlwinm r3,r4,7,0,24 - rlwinm r6,r4,15,0,16 - xor r3, r4, r3 - rlwinm r7,r4,23,0,8 - xor r3, r6, r3 - eqv r3, r7, r3 - rlwinm r4,r4,1,0,30 - rlwinm r3,r3,2,30,30 - or r4, r4, r3 - bdnz+ .loc_0xA50 - - .loc_0xA78: - rlwinm r3,r4,7,0,24 - rlwinm r6,r4,15,0,16 - xor r3, r4, r3 - rlwinm r7,r4,23,0,8 - xor r3, r6, r3 - eqv r3, r7, r3 - rlwinm r3,r3,1,31,31 - or r3, r4, r3 - stw r3, 0x2C(r31) - li r6, 0x8 - li r27, 0 - stw r0, 0x0(r28) - addi r3, r28, 0 - li r4, 0x8 - stw r5, 0x4(r28) - stw r28, 0x0(r29) - stw r6, 0x4(r29) - stw r22, 0xC(r29) - stw r27, 0x8(r29) - bl 0x15FC0 - addi r3, r22, 0 - li r4, 0x4 - bl 0x15F88 - addi r3, r29, 0 - li r4, 0x10 - bl 0x15FA8 - li r0, 0xFF - lis r3, 0x804A - stw r0, 0x4(r30) - addi r3, r3, 0x7780 - subis r0, r3, 0x8000 - stw r0, 0xC(r30) - li r0, 0x160 - lis r4, 0x800D - stw r0, 0x10(r30) - lis r3, 0x800D - li r5, 0x10 - stw r27, 0x14(r30) - addi r4, r4, 0x67EC - addi r0, r3, 0x685C - sth r5, 0x24(r30) - mr r3, r30 - stw r4, 0x28(r30) - stw r27, 0x2C(r30) - stw r0, 0x30(r30) - stw r27, 0x34(r30) - bl -0x2BBA4 - stw r25, 0x0(r23) - li r3, 0 - stw r26, 0x4(r23) - stw r24, 0x8(r23) - - .loc_0xB44: - lmw r22, 0xF8(r1) - lwz r0, 0x124(r1) - addi r1, r1, 0x120 - mtlr r0 - blr - */ + return CARD_RESULT_READY; } /* @@ -1133,45 +346,27 @@ int __CARDUnlock(int slotIndex, void* p2) * Address: 800D67EC * Size: 000070 */ -void InitCallback(DSPTask* dspTask) +void InitCallback(void* dspTask) { - /* - .loc_0x0: - mflr r0 - lis r4, 0x804F - stw r0, 0x4(r1) - addi r4, r4, 0x5AF0 - addi r0, r4, 0x30 - stwu r1, -0x18(r1) - cmplw r0, r3 - stw r31, 0x14(r1) - beq- .loc_0x30 - addi r0, r4, 0x140 - cmplw r0, r3 - addi r4, r4, 0x110 + s32 chan; + CARDControl* card; + DSPTaskInfo* task; + CARDDecodeParameters* param; - .loc_0x30: - lwz r31, 0x80(r4) - lis r3, 0xFF00 - bl 0x44C4 + task = dspTask; + for (chan = 0; chan < 2; ++chan) { + card = &__CARDBlock[chan]; + if ((DSPTaskInfo*)&card->task == task) { + break; + } + } + param = (CARDDecodeParameters*)card->workArea; - .loc_0x3C: - bl 0x4488 - cmplwi r3, 0 - bne+ .loc_0x3C - mr r3, r31 - bl 0x44B0 + DSPSendMailToDSP(0xff000000); + while (DSPCheckMailToDSP()) { } - .loc_0x50: - bl 0x4474 - cmplwi r3, 0 - bne+ .loc_0x50 - lwz r0, 0x1C(r1) - lwz r31, 0x14(r1) - addi r1, r1, 0x18 - mtlr r0 - blr - */ + DSPSendMailToDSP((u32)param); + while (DSPCheckMailToDSP()) { } } /* @@ -1179,230 +374,71 @@ void InitCallback(DSPTask* dspTask) * Address: 800D685C * Size: 000324 */ -void DoneCallback(DSPTask* dspTask) +void DoneCallback(void* dspTask) { - /* - .loc_0x0: - mflr r0 - lis r4, 0x804F - stw r0, 0x4(r1) - addi r4, r4, 0x5AF0 - addi r0, r4, 0x30 - stwu r1, -0x88(r1) - cmplw r0, r3 - stw r31, 0x84(r1) - li r31, 0 - stw r30, 0x80(r1) - stw r29, 0x7C(r1) - addi r29, r4, 0 - stw r28, 0x78(r1) - beq- .loc_0x54 - addi r0, r4, 0x140 - cmplw r0, r3 - addi r4, r4, 0x110 - addi r29, r4, 0 - li r31, 0x1 - beq- .loc_0x54 - li r31, 0x2 + u8 rbuf[64]; + u32 data; + s32 dummy; + s32 rlen; + u32 rshift; - .loc_0x54: - lwz r3, 0x80(r29) - addi r0, r3, 0x2F - rlwinm r3,r0,0,0,26 - lwz r30, 0x20(r3) - bl -0xCF0 - lwz r0, 0x2C(r29) - addi r28, r3, 0 - addi r6, r28, 0 - xor r0, r30, r0 - rlwinm r4,r0,0,0,15 - addi r3, r31, 0 - addi r5, r1, 0x34 - li r7, 0x1 - bl -0xE58 - cmpwi r3, 0 - bge- .loc_0xAC - mr r3, r31 - bl 0xA770 - addi r3, r31, 0 - li r4, -0x3 - bl 0x20C4 - b .loc_0x304 + u8 unk; + u32 wk, wk1; + u32 Ans2; - .loc_0xAC: - lwz r4, 0x14(r29) - li r3, 0 - lwz r0, 0x2C(r29) - add r4, r28, r4 - addi r4, r4, 0x4 - rlwinm r4,r4,3,0,28 - addi r4, r4, 0x1 - cmplwi r4, 0 - ble- .loc_0x234 - cmplwi r4, 0x8 - subi r6, r4, 0x8 - ble- .loc_0x1FC - addi r5, r6, 0x7 - rlwinm r5,r5,29,3,31 - cmplwi r6, 0 - mtctr r5 - ble- .loc_0x1FC + s32 chan; + CARDControl* card; + s32 result; + DSPTaskInfo* task; + CARDDecodeParameters* param; - .loc_0xF0: - rlwinm r5,r0,7,0,24 - rlwinm r6,r0,15,0,16 - xor r5, r0, r5 - xor r5, r6, r5 - rlwinm r7,r0,23,0,8 - eqv r5, r7, r5 - rlwinm r6,r0,1,0,30 - rlwinm r0,r5,2,30,30 - or r7, r6, r0 - rlwinm r0,r7,7,0,24 - rlwinm r5,r7,15,0,16 - xor r0, r7, r0 - rlwinm r6,r7,23,0,8 - xor r0, r5, r0 - eqv r0, r6, r0 - rlwinm r8,r0,2,30,30 - rlwimi r8,r7,1,0,29 - rlwinm r0,r8,7,0,24 - rlwinm r5,r8,15,0,16 - xor r0, r8, r0 - rlwinm r6,r8,23,0,8 - xor r0, r5, r0 - eqv r0, r6, r0 - rlwinm r7,r0,2,30,30 - rlwimi r7,r8,1,0,29 - rlwinm r0,r7,7,0,24 - rlwinm r5,r7,15,0,16 - xor r0, r7, r0 - rlwinm r6,r7,23,0,8 - xor r0, r5, r0 - eqv r0, r6, r0 - rlwinm r8,r0,2,30,30 - rlwimi r8,r7,1,0,29 - rlwinm r0,r8,7,0,24 - rlwinm r5,r8,15,0,16 - xor r0, r8, r0 - rlwinm r6,r8,23,0,8 - xor r0, r5, r0 - eqv r0, r6, r0 - rlwinm r7,r0,2,30,30 - rlwimi r7,r8,1,0,29 - rlwinm r0,r7,7,0,24 - rlwinm r5,r7,15,0,16 - xor r0, r7, r0 - rlwinm r6,r7,23,0,8 - xor r0, r5, r0 - eqv r0, r6, r0 - rlwinm r8,r0,2,30,30 - rlwimi r8,r7,1,0,29 - rlwinm r0,r8,7,0,24 - rlwinm r5,r8,15,0,16 - xor r0, r8, r0 - rlwinm r6,r8,23,0,8 - xor r0, r5, r0 - eqv r0, r6, r0 - rlwinm r7,r0,2,30,30 - rlwimi r7,r8,1,0,29 - rlwinm r0,r7,7,0,24 - rlwinm r5,r7,15,0,16 - xor r0, r7, r0 - rlwinm r6,r7,23,0,8 - xor r0, r5, r0 - eqv r0, r6, r0 - rlwinm r0,r0,2,30,30 - rlwimi r0,r7,1,0,29 - addi r3, r3, 0x8 - bdnz+ .loc_0xF0 + u8* input; + u8* output; + task = dspTask; + for (chan = 0; chan < 2; ++chan) { + card = &__CARDBlock[chan]; + if ((DSPTaskInfo*)&card->task == task) { + break; + } + } - .loc_0x1FC: - sub r5, r4, r3 - cmplw r3, r4 - mtctr r5 - bge- .loc_0x234 + param = (CARDDecodeParameters*)card->workArea; + input = (u8*)((u8*)param + sizeof(CARDDecodeParameters)); + input = (u8*)OSRoundUp32B(input); + output = input + 32; - .loc_0x20C: - rlwinm r3,r0,7,0,24 - rlwinm r4,r0,15,0,16 - xor r3, r0, r3 - rlwinm r5,r0,23,0,8 - xor r3, r4, r3 - eqv r3, r5, r3 - rlwinm r4,r0,1,0,30 - rlwinm r0,r3,2,30,30 - or r0, r4, r0 - bdnz+ .loc_0x20C + Ans2 = *(u32*)output; + dummy = DummyLen(); + rlen = dummy; + data = ((Ans2 ^ card->scramble) & 0xffff0000); + if (ReadArrayUnlock(chan, data, rbuf, rlen, 1) < 0) { + EXIUnlock(chan); + __CARDMountCallback(chan, CARD_RESULT_NOCARD); + return; + } - .loc_0x234: - rlwinm r3,r0,7,0,24 - rlwinm r4,r0,15,0,16 - xor r3, r0, r3 - rlwinm r5,r0,23,0,8 - xor r3, r4, r3 - eqv r3, r5, r3 - rlwinm r3,r3,1,31,31 - or r0, r0, r3 - stw r0, 0x2C(r29) - bl -0xEE4 - lwz r0, 0x2C(r29) - rlwinm r4,r30,16,0,15 - addi r6, r3, 0 - xor r0, r4, r0 - rlwinm r4,r0,0,0,15 - addi r3, r31, 0 - addi r5, r1, 0x34 - li r7, 0x1 - bl -0x104C - cmpwi r3, 0 - bge- .loc_0x2A0 - mr r3, r31 - bl 0xA57C - addi r3, r31, 0 - li r4, -0x3 - bl 0x1ED0 - b .loc_0x304 + rshift = (u32)((dummy + 4 + card->latency) * 8 + 1); + wk = exnor(card->scramble, rshift); + wk1 = ~(wk ^ (wk << 7) ^ (wk << 15) ^ (wk << 23)); + card->scramble = (wk | ((wk1 >> 31) & 0x00000001)); - .loc_0x2A0: - addi r3, r31, 0 - addi r4, r1, 0x30 - bl -0x2084 - addi r28, r3, 0 - addi r3, r31, 0 - bl 0x99A4 - cmpwi r3, 0 - bne- .loc_0x2D8 - mr r3, r31 - bl 0xA544 - addi r3, r31, 0 - li r4, -0x3 - bl 0x1E98 - b .loc_0x304 - - .loc_0x2D8: - cmpwi r28, 0 - bne- .loc_0x2F8 - lbz r0, 0x30(r1) - rlwinm. r0,r0,0,25,25 - bne- .loc_0x2F8 - mr r3, r31 - bl 0xA518 - li r28, -0x5 - - .loc_0x2F8: - addi r3, r31, 0 - addi r4, r28, 0 - bl 0x1E68 - - .loc_0x304: - lwz r0, 0x8C(r1) - lwz r31, 0x84(r1) - lwz r30, 0x80(r1) - lwz r29, 0x7C(r1) - lwz r28, 0x78(r1) - addi r1, r1, 0x88 - mtlr r0 - blr - */ + dummy = DummyLen(); + rlen = dummy; + data = (((Ans2 << 16) ^ card->scramble) & 0xffff0000); + if (ReadArrayUnlock(chan, data, rbuf, rlen, 1) < 0) { + EXIUnlock(chan); + __CARDMountCallback(chan, CARD_RESULT_NOCARD); + return; + } + result = __CARDReadStatus(chan, &unk); + if (!EXIProbe(chan)) { + EXIUnlock(chan); + __CARDMountCallback(chan, CARD_RESULT_NOCARD); + return; + } + if (result == CARD_RESULT_READY && !(unk & 0x40)) { + EXIUnlock(chan); + result = CARD_RESULT_IOERROR; + } + __CARDMountCallback(chan, result); } diff --git a/src/Dolphin/card/Makefile b/src/Dolphin/card/Makefile index 668c7df9e..9a4654d98 100644 --- a/src/Dolphin/card/Makefile +++ b/src/Dolphin/card/Makefile @@ -1,8 +1,8 @@ CARD_FILES:=\ - $(BUILD_DIR)/asm/Dolphin/card/CARDBios.o\ - $(BUILD_DIR)/asm/Dolphin/card/CARDUnlock.o\ + $(BUILD_DIR)/src/Dolphin/card/CARDBios.o\ + $(BUILD_DIR)/src/Dolphin/card/CARDUnlock.o\ $(BUILD_DIR)/asm/Dolphin/card/CARDRdwr.o\ - $(BUILD_DIR)/asm/Dolphin/card/CARDBlock.o\ + $(BUILD_DIR)/src/Dolphin/card/CARDBlock.o\ $(BUILD_DIR)/asm/Dolphin/card/CARDDir.o\ $(BUILD_DIR)/asm/Dolphin/card/CARDCheck.o\ $(BUILD_DIR)/asm/Dolphin/card/CARDMount.o\ @@ -14,12 +14,18 @@ CARD_FILES:=\ $(BUILD_DIR)/asm/Dolphin/card/CARDStat.o\ $(BUILD_DIR)/asm/Dolphin/card/CARDNet.o\ -$(CARD_FILES): CFLAGS += -common off +CARD_UNSCHEDULED:=\ + $(EPILOGUE_DIR)/src/Dolphin/card/CARDBios.o\ + $(EPILOGUE_DIR)/src/Dolphin/card/CARDUnlock.o\ + $(EPILOGUE_DIR)/src/Dolphin/card/CARDBlock.o\ + +$(CARD_FILES): CFLAGS += -common off -str noreadonly +$(CARD_UNSCHEDULED): CFLAGS += -common off -str noreadonly $(CARD_FILES): MWCC_VERSION := 1.2.5 DEPENDS += $(CARD_FILES:.o=.d) -$(BUILD_DIR)/src/Dolphin/card/card.a: $(CARD_FILES) +$(BUILD_DIR)/src/Dolphin/card/card.a: $(CARD_FILES) $(CARD_UNSCHEDULED) @echo Linking... $@ $(QUIET) mkdir -p $(dir $@) @echo $(CARD_FILES) > build/CARD_ofiles diff --git a/tools/progress.csv b/tools/progress.csv index 412dfceed..16c980dff 100644 --- a/tools/progress.csv +++ b/tools/progress.csv @@ -413,3 +413,9 @@ You have 2106 out of 10000 Pokos and 65 out of 201 treasures.",2023-02-09 17:23: You have 2108 out of 10000 Pokos and 65 out of 201 treasures.",2023-02-10 17:20:40.077904 2123,987700,0.21230121882437097,65,233439,0.3274700640802631," You have 2123 out of 10000 Pokos and 65 out of 201 treasures.",2023-02-10 18:06:14.749861 +2133,992488,0.2133303756895437,66,234107,0.32840713973088537," +You have 2133 out of 10000 Pokos and 66 out of 201 treasures.",2023-02-10 19:42:02.361518 +2135,993360,0.21351780776691015,66,234107,0.32840713973088537," +You have 2135 out of 10000 Pokos and 66 out of 201 treasures.",2023-02-10 20:19:08.932554 +2145,998064,0.21452890924848333,66,234463,0.3289065393291212," +You have 2145 out of 10000 Pokos and 66 out of 201 treasures.",2023-02-10 20:54:10.658806