Skip to content

Commit

Permalink
Fix Reset Game not working in the in-game menu after a crash
Browse files Browse the repository at this point in the history
  • Loading branch information
RocketRobz committed Jan 2, 2025
1 parent 891149a commit 74b5d63
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
10 changes: 5 additions & 5 deletions retail/cardengine/arm9/source/cardengine.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions retail/cardenginei/arm7/source/inGameMenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -130,7 +129,6 @@ void inGameMenu(void) {
exitMenu = true;
timeTillStatusRefresh = 7;
unloadInGameMenu();
sharedAddr[5] = flagBak;
#ifdef TWLSDK
i2cWriteRegister(0x4A, 0x12, 0x01);
#endif
Expand All @@ -153,7 +151,6 @@ void inGameMenu(void) {
case 0x444D4152: // RAMD
dumpRam();
unloadInGameMenu();
sharedAddr[5] = flagBak;
exitMenu = true;
break;
/* case 0x50455453: // STEP
Expand Down Expand Up @@ -227,7 +224,6 @@ void inGameMenu(void) {
timeTillStatusRefresh = 7;

unloadInGameMenu();
sharedAddr[5] = flagBak;

leaveCriticalSection(oldIME);
REG_MASTER_VOLUME = 127;
Expand Down
8 changes: 4 additions & 4 deletions retail/cardenginei/arm9/source/cardengine.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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...
Expand Down
15 changes: 11 additions & 4 deletions retail/cardenginei/arm9_igm/source/inGameMenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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;
}

0 comments on commit 74b5d63

Please sign in to comment.