Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 23 additions & 62 deletions src/dolphin/card/CARDBios.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const char* __CARDVersion =
const char* __CARDVersion = "<< Dolphin SDK - CARD\tdebug build: Apr 5 2004 03:56:53 (0x2301) >>";
#endif

#if _DEBUG
#ifdef _DEBUG
u32 __CARDFreq = EXI_FREQ_16M;
#endif
#endif
Expand Down Expand Up @@ -45,15 +45,15 @@ void __CARDDefaultApiCallback(s32 chan, s32 result) {}
#if SDK_VERSION <= SDK_VERSION_DOLPHIN_2003_02
void __CARDSyncCallback(s32 chan) {
CARDControl* card = &__CARDBlock[chan];
#endif

#if SDK_VERSION >= SDK_VERSION_DOLPHIN_2003_04
OSWakeupThread(&card->threadQueue);
}
#else
void __CARDSyncCallback(s32 chan, s32 result) {
CARDControl* card;
card = &__CARDBlock[chan];
#endif
OSWakeupThread(&card->threadQueue);
}
#endif

#line 228
void __CARDExtHandler(s32 chan, OSContext* context) {
Expand All @@ -64,70 +64,40 @@ void __CARDExtHandler(s32 chan, OSContext* context) {
ASSERT(0 <= chan && chan < 2);
#endif
card = &__CARDBlock[chan];
#if SDK_VERSION <= SDK_VERSION_DOLPHIN_2003_02
if (card->attached) {
#if SDK_VERSION >= SDK_VERSION_DOLPHIN_2003_04
#line 260 // ASSERT below must report line 260 (debug builds); recompute on edit
ASSERT(card->txCallback == 0);
#endif
card->attached = FALSE;
EXISetExiCallback(chan, NULL);
OSCancelAlarm(&card->alarm);
callback = card->exiCallback;
#endif

#if SDK_VERSION <= SDK_VERSION_DOLPHIN_2003_02
if (callback) {
card->exiCallback = NULL;
callback(chan, CARD_RESULT_NOCARD);
}
#else
if (!card->attached) {
return;
}
#endif

#if SDK_VERSION <= SDK_VERSION_DOLPHIN_2003_02
if (card->result != CARD_RESULT_BUSY) {
card->result = CARD_RESULT_NOCARD;
}
#else
ASSERT(card->txCallback == 0);
#endif

#if SDK_VERSION <= SDK_VERSION_DOLPHIN_2003_02
callback = card->extCallback;
if (callback && CARD_MAX_MOUNT_STEP <= card->mountStep) {
card->extCallback = NULL;
callback(chan, CARD_RESULT_NOCARD);
}
#else
card->attached = FALSE;
EXISetExiCallback(chan, NULL);
OSCancelAlarm(&card->alarm);
callback = card->exiCallback;

if (callback) {
card->exiCallback = NULL;
callback(chan, CARD_RESULT_NOCARD);
}

if (card->result != CARD_RESULT_BUSY) {
card->result = CARD_RESULT_NOCARD;
}

callback = card->extCallback;
if (callback && CARD_MAX_MOUNT_STEP <= card->mountStep) {
card->extCallback = NULL;
callback(chan, CARD_RESULT_NOCARD);
#endif
}
}

#line 277
void __CARDExiHandler(s32 chan, OSContext* context) {
CARDControl* card;
CARDCallback callback;
u8 status;
s32 result;
#if SDK_VERSION >= SDK_VERSION_DOLPHIN_2003_04

#line 284 // ASSERT below must report line 284 (debug builds); recompute on edit
ASSERT(0 <= chan && chan < 2);
#endif

Expand Down Expand Up @@ -168,13 +138,12 @@ void __CARDExiHandler(s32 chan, OSContext* context) {
}
}

#line 359
void __CARDTxHandler(s32 chan, OSContext* context) {
CARDControl* card;
CARDCallback callback;
BOOL err;
#if SDK_VERSION >= SDK_VERSION_DOLPHIN_2003_04

#line 365 // ASSERT below must report line 365 (debug builds); recompute on edit
ASSERT(0 <= chan && chan < 2);
#endif

Expand Down Expand Up @@ -265,9 +234,8 @@ s32 __CARDReadVendorID(s32 chan, u16* id) {
err |= !EXIDeselect(chan);
return err ? CARD_RESULT_NOCARD : CARD_RESULT_READY;
}

#line 488
#endif

s32 __CARDClearStatus(s32 chan) {
BOOL err;
u32 cmd;
Expand All @@ -286,11 +254,11 @@ s32 __CARDClearStatus(s32 chan) {
}

#if SDK_VERSION >= SDK_VERSION_DOLPHIN_2003_04
//
s32 __CARDSleep(s32 chan) {
BOOL err;
u32 cmd;

#line 512 // ASSERT below must report line 512 (debug builds); recompute on edit
ASSERT(0 <= chan && chan < 2);
if (!EXISelect(chan, 0, CARDFreq)) {
return CARD_RESULT_NOCARD;
Expand Down Expand Up @@ -321,9 +289,8 @@ s32 __CARDWakeup(s32 chan) {
err |= !EXIDeselect(chan);
return err ? CARD_RESULT_NOCARD : CARD_RESULT_READY;
}

#line 564
#endif

static void TimeoutHandler(OSAlarm* alarm, OSContext* context) {
s32 chan;
CARDControl* card;
Expand All @@ -335,9 +302,7 @@ static void TimeoutHandler(OSAlarm* alarm, OSContext* context) {
}
}
#if SDK_VERSION >= SDK_VERSION_DOLPHIN_2003_04

//
//
#line 579 // ASSERT below must report line 579 (debug builds); recompute on edit
ASSERT(0 <= chan && chan < 2);
#endif

Expand Down Expand Up @@ -387,10 +352,8 @@ static void SetupTimeoutAlarm(CARDControl* card) {
static s32 Retry(s32 chan) {
CARDControl* card;
#if SDK_VERSION >= SDK_VERSION_DOLPHIN_2003_04

#line 654
#line 654 // ASSERT below must report line 654 (debug builds); recompute on edit
ASSERT(0 <= chan && chan < 2);

#endif
card = &__CARDBlock[chan];

Expand Down Expand Up @@ -652,14 +615,14 @@ s32 __CARDErase(s32 chan, CARDCallback callback) {
}
return result;
}

#line 1006
#endif

s32 __CARDEraseSector(s32 chan, u32 addr, CARDCallback callback) {
CARDControl* card;
s32 result;
#if SDK_VERSION >= SDK_VERSION_DOLPHIN_2003_04
// clang-format off
#line 1012 // ASSERT below must report line 1012 (debug builds); recompute on edit
ASSERT(0 <= chan && chan < 2);
card = &__CARDBlock[chan];
ASSERT(addr % card->sectorSize == 0);
Expand All @@ -676,8 +639,8 @@ s32 __CARDEraseSector(s32 chan, u32 addr, CARDCallback callback) {
}
return CARD_RESULT_READY;
}

#endif

card->cmd[0] = 0xF1;
card->cmd[1] = AD1(addr);
card->cmd[2] = AD2(addr);
Expand Down Expand Up @@ -749,14 +712,14 @@ u16 __CARDSetFontEncode(u16 encode) {
}
return prev;
}

#endif

void __CARDSetDiskID(const DVDDiskID* id) {
__CARDBlock[0].diskID = id ? id : &__CARDDiskNone;
__CARDBlock[1].diskID = id ? id : &__CARDDiskNone;
#if SDK_VERSION >= SDK_VERSION_DOLPHIN_2003_04
}

#if SDK_VERSION >= SDK_VERSION_DOLPHIN_2003_04
#line 1167
const DVDDiskID* CARDGetDiskID(s32 chan) {
ASSERT(0 <= chan && chan < 2);
Expand All @@ -776,8 +739,8 @@ s32 CARDSetDiskID(s32 chan, const DVDDiskID* diskID) {
card->diskID = diskID ? diskID : (DVDDiskID*)OSPhysicalToCached(0);
OSRestoreInterrupts(enabled);
return CARD_RESULT_READY;
#endif
}
#endif

s32 __CARDGetControlBlock(s32 chan, CARDControl** pcard) {
BOOL enabled;
Expand Down Expand Up @@ -821,11 +784,10 @@ s32 __CARDPutControlBlock(CARDControl* card, s32 result) {
return result;
}

#line 1289
s32 CARDGetResultCode(s32 chan) {
CARDControl* card;
#if SDK_VERSION >= SDK_VERSION_DOLPHIN_2003_04

#line 1293 // ASSERT below must report line 1293 (debug builds); recompute on edit
ASSERT(0 <= chan && chan < 2);
#endif
if (chan < 0 || chan >= 2) {
Expand Down Expand Up @@ -978,5 +940,4 @@ s32 CARDGetCurrentMode(s32 chan, u32* mode) {

return __CARDPutControlBlock(card, CARD_RESULT_READY);
}

#endif
32 changes: 14 additions & 18 deletions src/dolphin/card/CARDCheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

#include "string.h"

#define __CARDGetDirCheck(dir) ((CARDDirCheck*)&(dir)[CARD_MAX_FILE])

#line 78
void __CARDCheckSum(void* ptr, int length, u16* checksum, u16* checksumInv) {
u16* p;
Expand Down Expand Up @@ -89,12 +87,12 @@ static s32 VerifyDir(CARDControl* card, int* outCurrent) {
if (check[i]->checkSum != checkSum || check[i]->checkSumInv != checkSumInv) {
++errors;
current = i;
card->currentDir = 0;
card->currentDir = NULL;
}
}

if (0 == errors) {
if (card->currentDir == 0) {
if (card->currentDir == NULL) {
if ((check[0]->checkCode - check[1]->checkCode) < 0) {
current = 0;
} else {
Expand Down Expand Up @@ -132,7 +130,7 @@ static s32 VerifyFAT(CARDControl* card, int* outCurrent) {
if (fatp[CARD_FAT_CHECKSUM] != checkSum || fatp[CARD_FAT_CHECKSUMINV] != checkSumInv) {
++errors;
current = i;
card->currentFat = 0;
card->currentFat = NULL;
continue;
}

Expand All @@ -145,13 +143,13 @@ static s32 VerifyFAT(CARDControl* card, int* outCurrent) {
if (cFree != fatp[CARD_FAT_FREEBLOCKS]) {
++errors;
current = i;
card->currentFat = 0;
card->currentFat = NULL;
continue;
}
}

if (0 == errors) {
if (card->currentFat == 0) {
if (card->currentFat == NULL) {
if (((s16)fat[0][CARD_FAT_CHECKCODE] - (s16)fat[1][CARD_FAT_CHECKCODE]) < 0) {
current = 0;
} else {
Expand Down Expand Up @@ -215,7 +213,6 @@ s32 CARDCheckExAsync(s32 chan, s32* xferBytes, CARDCallback callback) {

#if SDK_VERSION >= SDK_VERSION_DOLPHIN_2003_04
ASSERT(0 <= chan && chan < 2);

#endif
if (xferBytes) {
*xferBytes = 0;
Expand All @@ -237,35 +234,35 @@ s32 CARDCheckExAsync(s32 chan, s32* xferBytes, CARDCallback callback) {
return __CARDPutControlBlock(card, CARD_RESULT_BROKEN);
}

dir[0] = (CARDDir*)((u8*)card->workArea + (1 + 0) * CARD_SYSTEM_BLOCK_SIZE);
dir[1] = (CARDDir*)((u8*)card->workArea + (1 + 1) * CARD_SYSTEM_BLOCK_SIZE);
fat[0] = (u16*)((u8*)card->workArea + (3 + 0) * CARD_SYSTEM_BLOCK_SIZE);
fat[1] = (u16*)((u8*)card->workArea + (3 + 1) * CARD_SYSTEM_BLOCK_SIZE);
dir[0] = (CARDDir*)((u8*)card->workArea + CARD_SYSTEM_BLOCK_SIZE);
dir[1] = (CARDDir*)((u8*)card->workArea + 2 * CARD_SYSTEM_BLOCK_SIZE);
fat[0] = (u16*)((u8*)card->workArea + 3 * CARD_SYSTEM_BLOCK_SIZE);
fat[1] = (u16*)((u8*)card->workArea + 4 * CARD_SYSTEM_BLOCK_SIZE);

#if SDK_VERSION >= SDK_VERSION_DOLPHIN_2003_04
#line 376 // ASSERT below must report line 376 (debug builds); recompute on edit
ASSERT(errors == 0 || errors == 1);

#endif
switch (errors) {
case 0:
#if SDK_VERSION >= SDK_VERSION_DOLPHIN_2003_04
#line 382 // ASSERT below must report line 382 (debug builds); recompute on edit
ASSERT(card->currentDir);
ASSERT(card->currentFat);

#endif
break;
case 1:
if (!card->currentDir) {
#if SDK_VERSION >= SDK_VERSION_DOLPHIN_2003_04
#line 390 // ASSERT below must report line 390 (debug builds); recompute on edit
ASSERT(card->currentFat);

#endif
card->currentDir = dir[currentDir];
memcpy(dir[currentDir], dir[currentDir ^ 1], CARD_SYSTEM_BLOCK_SIZE);
updateDir = TRUE;
} else {
#if SDK_VERSION >= SDK_VERSION_DOLPHIN_2003_04

#line 399 // ASSERT below must report line 399 (debug builds); recompute on edit
ASSERT(!card->currentFat);
#endif
card->currentFat = fat[currentFat];
Expand Down Expand Up @@ -357,7 +354,7 @@ s32 CARDCheckEx(s32 chan, s32* xferBytes) {
s32 result;

result = CARDCheckExAsync(chan, xferBytes, __CARDSyncCallback);
if (result < 0 || xferBytes == 0) {
if (result < 0 || xferBytes == NULL) {
return result;
}
return __CARDSync(chan);
Expand All @@ -368,5 +365,4 @@ s32 CARDCheck(s32 chan) {

return CARDCheckEx(chan, &xferBytes);
}

#endif
Loading