diff --git a/include/emulator/mcardGCN.h b/include/emulator/mcardGCN.h index 6c48a7fe..cb8f3734 100644 --- a/include/emulator/mcardGCN.h +++ b/include/emulator/mcardGCN.h @@ -3,7 +3,6 @@ #include "dolphin.h" -// __anon_0x1BD8E typedef enum MemCardCommand { MC_C_NONE = 0, MC_C_CONTINUE = 1, @@ -14,7 +13,6 @@ typedef enum MemCardCommand { MC_C_FORMAT_CARD = 6, } MemCardCommand; -// __anon_0x1B0CB typedef enum MemCardError { MC_E_NONE = 0, MC_E_BUSY = 1, @@ -97,50 +95,49 @@ typedef enum MemCardMessage { MC_M_GF06 = 49, } MemCardMessage; -// __anon_0x1AC1A -typedef struct __anon_0x1AC1A { +typedef struct MemCardGameInfo { /* 0x00 */ s32 configuration; /* 0x04 */ s32 size; /* 0x08 */ s32 offset; /* 0x0C */ char* buffer; - /* 0x10 */ s32* writtenBlocks; - /* 0x14 */ s32 writtenConfig; -} __anon_0x1AC1A; // size = 0x18 + /* 0x10 */ bool* writtenBlocks; + /* 0x14 */ bool writtenConfig; +} MemCardGameInfo; // size = 0x18 -typedef struct __anon_0x1AEB5 { +typedef struct MemCardFileInfo { /* 0x000 */ s32 currentGame; /* 0x004 */ s32 fileSize; /* 0x008 */ char name[33]; /* 0x02C */ s32 numberOfGames; - /* 0x030 */ __anon_0x1AC1A game; - /* 0x048 */ s32 changedDate; - /* 0x04C */ s32 changedChecksum; + /* 0x030 */ MemCardGameInfo game; + /* 0x048 */ bool changedDate; + /* 0x04C */ bool changedChecksum; /* 0x050 */ s32 gameSize[16]; /* 0x090 */ s32 gameOffset[16]; /* 0x0D0 */ s32 gameConfigIndex[16]; /* 0x110 */ char gameName[16][33]; /* 0x320 */ OSCalendarTime time; /* 0x348 */ CARDFileInfo fileInfo; -} __anon_0x1AEB5; // size = 0x35C +} MemCardFileInfo; // size = 0x35C // __anon_0x1B36F typedef struct _MCARD { - /* 0x000 */ __anon_0x1AEB5 file; + /* 0x000 */ MemCardFileInfo file; /* 0x35C */ MemCardError error; /* 0x360 */ s32 slot; /* 0x364 */ bool (*pPollFunction)(void); /* 0x368 */ s32 pollPrevBytes; /* 0x36C */ s32 pollSize; /* 0x370 */ char pollMessage[256]; - /* 0x470 */ s32 saveToggle; + /* 0x470 */ bool saveToggle; /* 0x474 */ char* writeBuffer; /* 0x478 */ char* readBuffer; - /* 0x47C */ s32 writeToggle; - /* 0x480 */ s32 soundToggle; + /* 0x47C */ bool writeToggle; + /* 0x480 */ bool soundToggle; /* 0x484 */ s32 writeStatus; /* 0x488 */ s32 writeIndex; /* 0x48C */ s32 accessType; - /* 0x490 */ s32 gameIsLoaded; + /* 0x490 */ bool gameIsLoaded; /* 0x494 */ char saveFileName[256]; /* 0x594 */ char saveComment[256]; /* 0x694 */ char* saveIcon; @@ -148,10 +145,10 @@ typedef struct _MCARD { /* 0x69C */ char saveGameName[256]; /* 0x79C */ s32 saveFileSize; /* 0x7A0 */ s32 saveGameSize; - /* 0x7A4 */ s32 bufferCreated; + /* 0x7A4 */ bool bufferCreated; /* 0x7A8 */ s32 cardSize; - /* 0x7AC */ s32 wait; - /* 0x7B0 */ s32 isBroken; + /* 0x7AC */ bool wait; + /* 0x7B0 */ bool isBroken; /* 0x7B4 */ s32 saveConfiguration; } MemCard; // size = 0x7B8 diff --git a/src/emulator/mcardGCN.c b/src/emulator/mcardGCN.c index b4c887e8..44a2bc8c 100644 --- a/src/emulator/mcardGCN.c +++ b/src/emulator/mcardGCN.c @@ -12,10 +12,10 @@ static char gMCardCardWorkArea[40960]; MemCard mCard; -s32 bNoWriteInCurrentFrame[10]; +bool bNoWriteInCurrentFrame[10]; OSCalendarTime gDate; s32 currentIdx = 0; -s32 bWrite2Card; +bool bWrite2Card; static inline bool mcardReadyFile(MemCard* pMCard); static inline bool mcardFinishCard(MemCard* pMCard); @@ -36,14 +36,14 @@ static bool mcardGCErrorHandler(MemCard* pMCard, s32 gcError) { return false; case CARD_RESULT_NOCARD: pMCard->error = MC_E_NOCARD; - pMCard->isBroken = 0; + pMCard->isBroken = false; return false; case CARD_RESULT_NOFILE: pMCard->error = MC_E_NOFILE; return false; case CARD_RESULT_IOERROR: pMCard->error = MC_E_IOERROR; - pMCard->isBroken = 1; + pMCard->isBroken = true; return false; case CARD_RESULT_BROKEN: pMCard->error = MC_E_BROKEN; @@ -216,7 +216,7 @@ static bool mcardCheckChecksumFileHeader(MemCard* pMCard, char* buffer) { s32 pad2; s32 checksum; char buffer2[0x2000]; - s32 toggle = 1; + bool toggle = true; s32 pad[2]; memcpy(buffer2, pMCard->writeBuffer, 0x2000); @@ -225,7 +225,7 @@ static bool mcardCheckChecksumFileHeader(MemCard* pMCard, char* buffer) { mcardCalculateChecksumFileBlock1(pMCard, &checksum); if (checksum != *(s32*)(pMCard->writeBuffer + 0x28)) { - toggle = 0; + toggle = false; if (mcardReplaceFileBlock(pMCard, 0) == false) { return false; } @@ -235,7 +235,7 @@ static bool mcardCheckChecksumFileHeader(MemCard* pMCard, char* buffer) { mcardCalculateChecksumFileBlock2(pMCard, &checksum); if (checksum != *(s32*)(pMCard->writeBuffer + 0x106C)) { - if (toggle == 1) { + if (toggle == true) { if (!mcardReplaceFileBlock(pMCard, 1)) { return false; } @@ -810,10 +810,10 @@ bool mcardReadGameData(MemCard* pMCard) { s32 checksum1; s32 checksum2; s32 i; - s32 toggle; + bool toggle; s32 pad; - toggle = 1; + toggle = true; if (pMCard->saveToggle == true) { strcpy(pMCard->pollMessage, "Reading Game Data"); @@ -826,8 +826,8 @@ bool mcardReadGameData(MemCard* pMCard) { memcpy(&checksum1, pMCard->writeBuffer, 4); mcardCalculateChecksum(pMCard, &checksum2); if (checksum1 != checksum2) { - if (toggle == 1) { - toggle = 0; + if (toggle == true) { + toggle = false; if (!mcardReplaceBlock(pMCard, i)) { pMCard->error = MC_E_CHECKSUM; return false; @@ -934,7 +934,7 @@ bool mcardReInit(MemCard* pMCard) { bool mcardInit(MemCard* pMCard) { CARDInit(); - if (pMCard->bufferCreated == 0) { + if (!pMCard->bufferCreated) { pMCard->file.game.buffer = NULL; } @@ -952,7 +952,7 @@ bool mcardFileSet(MemCard* pMCard, char* name) { if (pMCard->saveToggle == true) { mcardCopyName(pMCard->file.name, name); - pMCard->file.changedDate = 0; + pMCard->file.changedDate = false; pMCard->file.fileSize = 0x6000; if (mcardReadyFile(pMCard) == true) { if (!pMCard->gameIsLoaded) { @@ -1059,7 +1059,7 @@ bool mcardGameSet(MemCard* pMCard, char* name) { pMCard->file.game.size = pMCard->file.gameSize[pMCard->file.currentGame]; pMCard->file.game.offset = pMCard->file.gameOffset[pMCard->file.currentGame]; pMCard->file.game.configuration = pMCard->file.gameConfigIndex[pMCard->file.currentGame]; - pMCard->file.game.writtenConfig = 0; + pMCard->file.game.writtenConfig = false; if (!pMCard->bufferCreated) { if (pMCard->file.game.buffer != NULL) { @@ -1094,11 +1094,11 @@ bool mcardGameSet(MemCard* pMCard, char* name) { } if (!xlHeapTake((void**)&pMCard->file.game.writtenBlocks, - (((u32)(pMCard->file.game.size + 8187) / 8188) * 4) | 0x30000000)) { + (((u32)(pMCard->file.game.size + 8187) / 8188) * sizeof(bool)) | 0x30000000)) { return false; } - memset(pMCard->file.game.writtenBlocks, 0, ((u32)(pMCard->file.game.size + 8187) / 8188) * 4); + memset(pMCard->file.game.writtenBlocks, 0, ((u32)(pMCard->file.game.size + 8187) / 8188) * sizeof(bool)); pMCard->writeStatus = 0; pMCard->writeIndex = 0; @@ -1121,7 +1121,7 @@ bool mcardGameSet(MemCard* pMCard, char* name) { pMCard->file.game.buffer[0] &= 0xFC; } } - *pMCard->file.game.writtenBlocks = 1; + pMCard->file.game.writtenBlocks[0] = true; } } else { if (gpSystem->eTypeROM == SRT_ZELDA1) { @@ -1166,7 +1166,7 @@ bool mcardFileCreate(MemCard* pMCard, char* name, char* comment, char* icon, cha if (!mcardReadyCard(pMCard)) { return false; } - pMCard->file.changedDate = 0; + pMCard->file.changedDate = false; if (!mcardGCErrorHandler(pMCard, CARDFreeBlocks(pMCard->slot, &freeBytes, &freeFiles))) { return false; } @@ -1323,14 +1323,14 @@ bool mcardGameCreate(MemCard* pMCard, char* name, s32 defaultConfiguration, s32 } if (!xlHeapTake((void**)&pMCard->file.game.writtenBlocks, - (((u32)(pMCard->file.game.size + 8187) / 8188) * 4) | 0x30000000)) { + (((u32)(pMCard->file.game.size + 8187) / 8188) * sizeof(bool)) | 0x30000000)) { return false; } pMCard->file.gameSize[i] = pMCard->file.game.size; pMCard->file.gameOffset[i] = pMCard->file.game.offset; pMCard->file.gameConfigIndex[i] = defaultConfiguration; - pMCard->file.game.writtenConfig = 0; + pMCard->file.game.writtenConfig = false; mcardCopyName(pMCard->file.gameName[i], name); @@ -1404,7 +1404,7 @@ bool mcardCardErase(MemCard* pMCard) { slot = pMCard->slot; CARDInit(); - if (pMCard->bufferCreated == 0) { + if (!pMCard->bufferCreated) { pMCard->file.game.buffer = NULL; } @@ -1419,7 +1419,7 @@ bool mcardCardErase(MemCard* pMCard) { } bool mcardFileErase(MemCard* pMCard) { - if (pMCard->saveToggle == 1) { + if (pMCard->saveToggle == true) { if (!mcardReadyCard(pMCard)) { return false; } @@ -1451,7 +1451,7 @@ bool mcardFileErase(MemCard* pMCard) { } bool mcardGameErase(MemCard* pMCard, s32 index) { - if (pMCard->saveToggle == 1) { + if (pMCard->saveToggle == true) { pMCard->accessType = 2; simulatorPrepareMessage(S_M_CARD_SV09); pMCard->file.fileSize -= (((u32)(pMCard->file.gameSize[index] + 8187) / 8188) << 13) + 0x2000; @@ -1481,7 +1481,7 @@ bool mcardGameErase(MemCard* pMCard, s32 index) { static inline bool mcardFileRelease(MemCard* pMCard) { mcardGameRelease(pMCard); - pMCard->file.changedDate = 0; + pMCard->file.changedDate = false; memset(pMCard->file.name, 0, ARRAY_COUNT(pMCard->file.name)); pMCard->file.numberOfGames = 0; memset(pMCard->file.gameSize, 0, ARRAY_COUNT(pMCard->file.gameSize)); @@ -1490,7 +1490,7 @@ static inline bool mcardFileRelease(MemCard* pMCard) { } bool mcardGameRelease(MemCard* pMCard) { - if (pMCard->bufferCreated == 0) { + if (!pMCard->bufferCreated) { if (pMCard->file.game.buffer != NULL) { if (!xlHeapFree((void**)&pMCard->file.game.buffer)) { return false; @@ -1507,7 +1507,7 @@ bool mcardGameRelease(MemCard* pMCard) { } } - pMCard->file.game.writtenConfig = 0; + pMCard->file.game.writtenConfig = false; pMCard->file.currentGame = 16; return true; @@ -1629,7 +1629,7 @@ bool mcardMenu(MemCard* pMCard, MemCardMessage menuEntry, MemCardCommand* pComma nextMenuEntry = MC_M_LD07; prevMenuEntry = MC_M_NONE; if ((s32)yes == true) { - pMCard->isBroken = 0; + pMCard->isBroken = false; *pCommand = MC_C_GO_TO_GAME; } else { *pCommand = MC_C_CONTINUE; @@ -1780,7 +1780,7 @@ bool mcardMenu(MemCard* pMCard, MemCardMessage menuEntry, MemCardCommand* pComma } break; case MC_M_SV10: - pMCard->wait = 1; + pMCard->wait = true; prevMenuEntry = menuEntry; nextMenuEntry = menuEntry; if (simulatorDrawErrorMessageWait(S_M_CARD_SV10) == true) { @@ -1798,7 +1798,7 @@ bool mcardMenu(MemCard* pMCard, MemCardMessage menuEntry, MemCardCommand* pComma break; case MC_M_SV12: prevMenuEntry = menuEntry; - pMCard->wait = 1; + pMCard->wait = true; if (simulatorDrawErrorMessageWait(S_M_CARD_SV12) == true) { pMCard->wait = false; prevMenuEntry = MC_M_NONE; @@ -1836,7 +1836,7 @@ bool mcardMenu(MemCard* pMCard, MemCardMessage menuEntry, MemCardCommand* pComma } break; case MC_M_IN03: - pMCard->wait = 1; + pMCard->wait = true; if (simulatorDrawErrorMessageWait(S_M_CARD_IN03) == true) { pMCard->wait = false; prevMenuEntry = MC_M_NONE; @@ -1845,7 +1845,7 @@ bool mcardMenu(MemCard* pMCard, MemCardMessage menuEntry, MemCardCommand* pComma } break; case MC_M_IN04_L: - pMCard->wait = 1; + pMCard->wait = true; prevMenuEntry = menuEntry; nextMenuEntry = menuEntry; if (simulatorDrawErrorMessageWait(S_M_CARD_IN04) == true) { @@ -1854,7 +1854,7 @@ bool mcardMenu(MemCard* pMCard, MemCardMessage menuEntry, MemCardCommand* pComma } break; case MC_M_IN04_S: - pMCard->wait = 1; + pMCard->wait = true; prevMenuEntry = menuEntry; nextMenuEntry = menuEntry; if (simulatorDrawErrorMessageWait(S_M_CARD_IN04) == true) { @@ -1904,7 +1904,7 @@ bool mcardMenu(MemCard* pMCard, MemCardMessage menuEntry, MemCardCommand* pComma } break; case MC_M_GF03: - pMCard->wait = 1; + pMCard->wait = true; prevMenuEntry = menuEntry; nextMenuEntry = menuEntry; if (simulatorDrawErrorMessageWait(S_M_CARD_GF03) == true) { @@ -1914,7 +1914,7 @@ bool mcardMenu(MemCard* pMCard, MemCardMessage menuEntry, MemCardCommand* pComma } break; case MC_M_GF04_L: - pMCard->wait = 1; + pMCard->wait = true; prevMenuEntry = menuEntry; nextMenuEntry = menuEntry; if (simulatorDrawErrorMessageWait(S_M_CARD_GF04) == true) { @@ -1925,7 +1925,7 @@ bool mcardMenu(MemCard* pMCard, MemCardMessage menuEntry, MemCardCommand* pComma } break; case MC_M_GF04_S: - pMCard->wait = 1; + pMCard->wait = true; prevMenuEntry = menuEntry; nextMenuEntry = menuEntry; if (simulatorDrawErrorMessageWait(S_M_CARD_GF04) == true) { @@ -2037,8 +2037,8 @@ bool mcardOpenDuringGameError(MemCard* pMCard, MemCardCommand* pCommand) { } bool mcardWrite(MemCard* pMCard, s32 address, s32 size, char* data) { - static s32 toggle = 1; - static s32 toggle2; + static bool toggle = true; + static bool toggle2; s32 i; char testByte; @@ -2050,7 +2050,7 @@ bool mcardWrite(MemCard* pMCard, s32 address, s32 size, char* data) { if (gpSystem->eTypeROM == SRT_ZELDA1) { if (address == 0) { - if (toggle != 0 && pMCard->soundToggle == 1) { + if (toggle && pMCard->soundToggle == true) { if (OSGetSoundMode() == OS_SOUND_MODE_MONO) { pMCard->file.game.buffer[0] &= 0xFC; pMCard->file.game.buffer[0] |= 1; @@ -2060,7 +2060,7 @@ bool mcardWrite(MemCard* pMCard, s32 address, s32 size, char* data) { } } *data = pMCard->file.game.buffer[0]; - toggle = 0; + toggle = false; } else if (pMCard->file.game.buffer[0] != testByte) { if ((testByte & 3) == 1) { OSSetSoundMode(OS_SOUND_MODE_STEREO); @@ -2069,45 +2069,45 @@ bool mcardWrite(MemCard* pMCard, s32 address, s32 size, char* data) { } } } - if (pMCard->saveToggle == 1) { + if (pMCard->saveToggle == true) { //! TODO: fake match for (i = (u64)((u32)address / 8188); i < (u32)(address + size + 8187) / 8188; i++) { - pMCard->file.game.writtenBlocks[i] = 1; + pMCard->file.game.writtenBlocks[i] = true; } - if (size == 0x1450 && toggle2 == 1) { + if (size == 0x1450 && toggle2 == true) { toggle2 = 0; simulatorRumbleStop(0); if (!mcardUpdate()) { return false; } - } else if (size == 0x1450 && toggle2 == 0) { - toggle2 = 1; + } else if (size == 0x1450 && toggle2 == false) { + toggle2 = true; } - } else if (size == 0x1450 && toggle2 == 1) { - toggle2 = 0; - pMCard->saveToggle = 1; - pMCard->wait = 0; + } else if (size == 0x1450 && toggle2 == true) { + toggle2 = false; + pMCard->saveToggle = true; + pMCard->wait = false; mcardOpenDuringGame(pMCard); - if (pMCard->saveToggle == 1) { + if (pMCard->saveToggle == true) { if (!mcardUpdate()) { return false; } } - } else if (size == 0x1450 && toggle2 == 0) { - toggle2 = 1; + } else if (size == 0x1450 && toggle2 == false) { + toggle2 = true; } } else { - if (pMCard->saveToggle == 1) { + if (pMCard->saveToggle == true) { simulatorRumbleStop(0); if (!mcardUpdate()) { return false; } } else { - pMCard->saveToggle = 1; - pMCard->wait = 0; + pMCard->saveToggle = true; + pMCard->wait = false; mcardOpenDuringGame(pMCard); - if (pMCard->saveToggle == 1) { + if (pMCard->saveToggle == true) { if (!mcardUpdate()) { return false; } @@ -2459,7 +2459,7 @@ bool mcardOpen(MemCard* pMCard, char* fileName, char* comment, char* icon, char* bool mcardOpenDuringGame(MemCard* pMCard) { s32 i; MemCardCommand command; - s32 loadToggle; + bool loadToggle; gButtonDownToggle = 1; if (!pMCard->gameIsLoaded) { @@ -2739,7 +2739,7 @@ bool mcardOpenDuringGame(MemCard* pMCard) { pMCard->accessType = 2; simulatorPrepareMessage(S_M_CARD_SV09); if (!mcardGameCreate(pMCard, pMCard->saveGameName, pMCard->saveConfiguration, pMCard->saveGameSize)) { - pMCard->isBroken = 1; + pMCard->isBroken = true; continue; } if (!mcardGameSet(pMCard, pMCard->saveGameName)) { @@ -2892,7 +2892,7 @@ bool mcardStore(MemCard* pMCard) { return true; } } - return 1; + return true; } else if (pMCard->writeStatus == 3) { pMCard->writeStatus = 4; if (pMCard->writeIndex < ((u32)(pMCard->file.game.size + 8187) / 8188)) { @@ -2937,7 +2937,7 @@ bool mcardStore(MemCard* pMCard) { bool mcardUpdate(void) { s32 j; s32 i; - s32 toggle; + bool toggle; MemCardCommand command; s32 prevIndex; s32 index; @@ -2949,7 +2949,7 @@ bool mcardUpdate(void) { if (mCard.saveToggle == true) { for (i = 0; i < (u32)(mCard.file.game.size + 8187) / 8188; i++) { - mCard.file.game.writtenBlocks[i] = 1; + mCard.file.game.writtenBlocks[i] = true; } prevIndex = 100; @@ -2967,18 +2967,18 @@ bool mcardUpdate(void) { simulatorDrawMCardText(); } - toggle = 0; + toggle = false; j = (u32)(mCard.file.game.size + 8187) / 8188; for (i = 0; i < (u32)j; i++) { - if (mCard.file.game.writtenBlocks[i] == 1) { + if (mCard.file.game.writtenBlocks[i] == true) { index = i; toggle = true; break; } } - if (toggle != 1) { - if (mCard.file.game.writtenConfig == 1) { + if (toggle != true) { + if (mCard.file.game.writtenConfig == true) { index = j; toggle = true; } else if (mCard.file.changedDate == true) { diff --git a/src/emulator/simGCN.c b/src/emulator/simGCN.c index 18f230eb..131cf97f 100644 --- a/src/emulator/simGCN.c +++ b/src/emulator/simGCN.c @@ -1953,7 +1953,7 @@ bool simulatorReadEEPROM(u8 address, u8* data) { return false; } - mcardRead(&mCard, (address * 8) & 0x7F8, 8, (char*)data); + mcardRead(&mCard, address * 8, 8, (char*)data); return true; } @@ -1964,7 +1964,7 @@ bool simulatorWriteEEPROM(u8 address, u8* data) { return false; } - mcardWrite(&mCard, (address * 8) & 0x7F8, 8, (char*)data); + mcardWrite(&mCard, address * 8, 8, (char*)data); return true; } @@ -2483,9 +2483,9 @@ bool xlMain(void) { return false; } - mCard.bufferCreated = 0; + mCard.bufferCreated = false; #if VERSION != MQ_J - mCard.isBroken = 0; + mCard.isBroken = false; #endif mcardInit(&mCard); diff --git a/src/emulator/system.c b/src/emulator/system.c index 98dd008f..0e8d496d 100644 --- a/src/emulator/system.c +++ b/src/emulator/system.c @@ -1538,7 +1538,7 @@ static bool systemSetupGameALL(System* pSystem) { } } - if (mCard.saveToggle == 1) { + if (mCard.saveToggle == true) { systemSetControllerConfiguration(&gSystemRomConfigurationList[0], mCard.file.game.configuration, false); }