From 74b5d631497f2d259716e30cebc8ac2a4eb8d1b9 Mon Sep 17 00:00:00 2001 From: RocketRobz Date: Wed, 1 Jan 2025 17:08:50 -0700 Subject: [PATCH] Fix `Reset Game` not working in the in-game menu after a crash --- retail/cardengine/arm9/source/cardengine.c | 10 +++++----- retail/cardenginei/arm7/source/inGameMenu.c | 4 ---- retail/cardenginei/arm9/source/cardengine.c | 8 ++++---- retail/cardenginei/arm9_igm/source/inGameMenu.c | 15 +++++++++++---- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/retail/cardengine/arm9/source/cardengine.c b/retail/cardengine/arm9/source/cardengine.c index 02d5225be..74e25508a 100644 --- a/retail/cardengine/arm9/source/cardengine.c +++ b/retail/cardengine/arm9/source/cardengine.c @@ -524,8 +524,8 @@ void inGameMenu(s32* exRegisters) { opened = true; *(u32*)(igmLocation + IGM_TEXT_SIZE_ALIGNED) = (u32)sharedAddr; - volatile void (*inGameMenu)(s32*, u32, s32*) = (volatile void*)igmLocation + IGM_TEXT_SIZE_ALIGNED + 0x10; - (*inGameMenu)(&ce9->mainScreen, 0, exRegisters); + volatile u32 (*inGameMenu)(s32*, u32, s32*) = (volatile void*)INGAME_MENU_LOCATION + IGM_TEXT_SIZE_ALIGNED + 0x10; + const u32 res = (*inGameMenu)(&ce9->mainScreen, 0, exRegisters); opened = false; @@ -536,13 +536,13 @@ void inGameMenu(s32* exRegisters) { writeIgm(0); // Store in-game menu readIgm(0xA000); // Restore part of game RAM from page file - if (sharedAddr[3] == 0x54495845) { + if (res == 0x54495845) { igmReset = true; reset(0xFFFFFFFF, 0); - } else if (sharedAddr[3] == 0x52534554) { + } else if (res == 0x52534554) { igmReset = true; reset(0, 0); - } else if (sharedAddr[3] == 0x444D4152) { // RAMD + } else if (res == 0x444D4152) { // RAMD #ifdef EXTMEM fileWrite((char*)0x02000000, &ramDumpFile, 0, 0x800000); // fileWrite((char*)((ce9->valueBits & isSdk5) ? 0x02FE0000 : 0x027E0000), &ramDumpFile, 0x7E0000, 0x20000); diff --git a/retail/cardenginei/arm7/source/inGameMenu.c b/retail/cardenginei/arm7/source/inGameMenu.c index 2bca9c162..9a21f6bd5 100644 --- a/retail/cardenginei/arm7/source/inGameMenu.c +++ b/retail/cardenginei/arm7/source/inGameMenu.c @@ -56,7 +56,6 @@ void inGameMenu(void) { // returnToMenu = false; sharedAddr[4] = 0x554E454D; // 'MENU' const u32 errorBak = sharedAddr[0]; - const u32 flagBak = sharedAddr[5]; IPC_SendSync(0x9); REG_MASTER_VOLUME = 0; int oldIME = enterCriticalSection(); @@ -130,7 +129,6 @@ void inGameMenu(void) { exitMenu = true; timeTillStatusRefresh = 7; unloadInGameMenu(); - sharedAddr[5] = flagBak; #ifdef TWLSDK i2cWriteRegister(0x4A, 0x12, 0x01); #endif @@ -153,7 +151,6 @@ void inGameMenu(void) { case 0x444D4152: // RAMD dumpRam(); unloadInGameMenu(); - sharedAddr[5] = flagBak; exitMenu = true; break; /* case 0x50455453: // STEP @@ -227,7 +224,6 @@ void inGameMenu(void) { timeTillStatusRefresh = 7; unloadInGameMenu(); - sharedAddr[5] = flagBak; leaveCriticalSection(oldIME); REG_MASTER_VOLUME = 127; diff --git a/retail/cardenginei/arm9/source/cardengine.c b/retail/cardenginei/arm9/source/cardengine.c index 5b7ed29aa..80c312705 100644 --- a/retail/cardenginei/arm9/source/cardengine.c +++ b/retail/cardenginei/arm9/source/cardengine.c @@ -1366,8 +1366,8 @@ void inGameMenu(s32* exRegisters) { #endif *(u32*)(INGAME_MENU_LOCATION + IGM_TEXT_SIZE_ALIGNED) = (u32)sharedAddr; - volatile void (*inGameMenu)(s32*, u32, s32*) = (volatile void*)INGAME_MENU_LOCATION + IGM_TEXT_SIZE_ALIGNED + 0x10; - (*inGameMenu)(&ce9->mainScreen, ce9->consoleModel, exRegisters); + volatile u32 (*inGameMenu)(s32*, u32, s32*) = (volatile void*)INGAME_MENU_LOCATION + IGM_TEXT_SIZE_ALIGNED + 0x10; + const u32 res = (*inGameMenu)(&ce9->mainScreen, ce9->consoleModel, exRegisters); while (sharedAddr[5] != 0x4C4D4749) { // 'IGML' while (REG_VCOUNT != 191) swiDelay(100); @@ -1379,7 +1379,7 @@ void inGameMenu(s32* exRegisters) { } #ifdef TWLSDK - if (sharedAddr[3] == 0x54495845) { + if (res == 0x54495845) { igmReset = true; if (*(u32*)0x02FFE234 == 0x00030004 || *(u32*)0x02FFE234 == 0x00030005) { reset(0, 0); @@ -1388,7 +1388,7 @@ void inGameMenu(s32* exRegisters) { } } else #endif - if (sharedAddr[3] == 0x52534554) { + if (res == 0x52534554) { igmReset = true; #ifdef TWLSDK if (*(u32*)0x02FFE234 == 0x00030004 || *(u32*)0x02FFE234 == 0x00030005) { // If DSiWare... diff --git a/retail/cardenginei/arm9_igm/source/inGameMenu.c b/retail/cardenginei/arm9_igm/source/inGameMenu.c index b5f76ef52..623b258cf 100644 --- a/retail/cardenginei/arm9_igm/source/inGameMenu.c +++ b/retail/cardenginei/arm9_igm/source/inGameMenu.c @@ -757,7 +757,7 @@ static void ramViewer(void) { (*revertMpu)(); } -void inGameMenu(s32 *mainScreen, u32 consoleModel, s32 *exceptionRegisters) { +u32 inGameMenu(s32 *mainScreen, u32 consoleModel, s32 *exceptionRegisters) { // If we were given exception registers, then we're handling an exception bool exception = (exceptionRegisters != 0); @@ -777,6 +777,8 @@ void inGameMenu(s32 *mainScreen, u32 consoleModel, s32 *exceptionRegisters) { #endif #endif + u32 res = 0; + u32 dispcnt = REG_DISPCNT_SUB; u16 bg0cnt = REG_BG0CNT_SUB; u16 bg1cnt = REG_BG1CNT_SUB; @@ -900,7 +902,8 @@ void inGameMenu(s32 *mainScreen, u32 consoleModel, s32 *exceptionRegisters) { case MENU_RESET: extern bool exceptionPrinted; exceptionPrinted = false; - sharedAddr[3] = 0x52534554; // TESR + res = 0x52534554; // TESR + sharedAddr[3] = res; sharedAddr[4] = 0x54455352; // RSET break; case MENU_SCREENSHOT: @@ -918,7 +921,8 @@ void inGameMenu(s32 *mainScreen, u32 consoleModel, s32 *exceptionRegisters) { } #else // sharedAddr[1] = 0; - sharedAddr[3] = 0x444D4152; // RAMD + res = 0x444D4152; // RAMD + sharedAddr[3] = res; sharedAddr[4] = 0x54495845; // EXIT while (sharedAddr[4] != 0) swiDelay(100); #endif @@ -930,7 +934,8 @@ void inGameMenu(s32 *mainScreen, u32 consoleModel, s32 *exceptionRegisters) { ramViewer(); break; case MENU_QUIT: - sharedAddr[3] = 0x54495845; // EXIT + res = 0x54495845; // EXIT + sharedAddr[3] = res; sharedAddr[4] = 0x54495551; // QUIT break; default: @@ -976,4 +981,6 @@ void inGameMenu(s32 *mainScreen, u32 consoleModel, s32 *exceptionRegisters) { REG_POWERCNT &= ~POWER_SWAP_LCDS; else if(*mainScreen == 2) REG_POWERCNT |= POWER_SWAP_LCDS; + + return res; } \ No newline at end of file