Skip to content

Commit

Permalink
Fix *Luminous Arc 2* crashing on first boot after initializing save data
Browse files Browse the repository at this point in the history
  • Loading branch information
RocketRobz committed Jan 2, 2025
1 parent 74b5d63 commit b88f8b1
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
4 changes: 4 additions & 0 deletions retail/bootloader/source/arm7/hook_arm7.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "nocashMessage.h"

#define b_a9IrqHooked BIT(7)
#define b_delayWrites BIT(8)
#define b_sleepMode BIT(17)

extern u32 newArm7binarySize;
Expand Down Expand Up @@ -224,6 +225,9 @@ int hookNdsRetailArm7(
if (patchedCardIrqEnable) {
ce7->valueBits |= b_a9IrqHooked;
}
if (strncmp(romTid, "YL2", 3) == 0) { // Luminous Arc 2
ce7->valueBits |= b_delayWrites; // Delay save writes by 1 frame for the first 2 seconds to fix crash on first boot
}
if (sleepMode) {
ce7->valueBits |= b_sleepMode;
}
Expand Down
5 changes: 4 additions & 1 deletion retail/bootloaderi/source/arm7/hook_arm7.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#define b_dsiSD BIT(5)
#define b_preciseVolumeControl BIT(6)
#define b_powerCodeOnVBlank BIT(7)
#define b_runCardEngineCheck BIT(8)
#define b_delayWrites BIT(8)
#define b_igmAccessible BIT(9)
#define b_hiyaCfwFound BIT(10)
#define b_slowSoftReset BIT(11)
Expand Down Expand Up @@ -391,6 +391,9 @@ int hookNdsRetailArm7(
if (consoleModel < 2 && preciseVolumeControl) {
ce7->valueBits |= b_preciseVolumeControl;
}
if (strncmp(romTid, "YL2", 3) == 0) { // Luminous Arc 2
ce7->valueBits |= b_delayWrites; // Delay save writes by 1 frame for the first 2 seconds to fix crash on first boot
}
if (hiyaCfwFound) {
ce7->valueBits |= b_hiyaCfwFound;
}
Expand Down
19 changes: 19 additions & 0 deletions retail/cardengine/arm7/source/cardengine.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "tonccpy.h"

#define a9IrqHooked BIT(7)
#define delayWrites BIT(8)

#define RUMBLE_PAK (*(vuint16 *)0x08000000)
#define WARIOWARE_PAK (*(vuint16 *)0x080000C4)
Expand Down Expand Up @@ -128,6 +129,14 @@ static PERSONAL_DATA* personalData = NULL;
}
}*/

// Alternative to swiWaitForVBlank()
static inline void waitFrames(int count) {
for (int i = 0; i < count; i++) {
while (REG_VCOUNT != 191);
while (REG_VCOUNT == 191);
}
}

static void waitForArm9(void) {
IPC_SendSync(0x4);
while (sharedAddr[3] != (vu32)0);
Expand Down Expand Up @@ -584,6 +593,16 @@ bool eepromPageWrite(u32 dst, const void *src, u32 len) {
return false;
}

#ifndef MUSIC
if (valueBits & delayWrites) {
if (*(int*)((valueBits & isSdk5Set) ? 0x02FFFC3C : 0x027FFC3C) >= 60*2) {
valueBits &= ~delayWrites;
} else {
waitFrames(1);
}
}
#endif

// Send a command to the ARM9 to write the save
const u32 commandSaveWrite = 0x53415657;

Expand Down
9 changes: 8 additions & 1 deletion retail/cardenginei/arm7/source/cardengine.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
#define b_dsiSD BIT(5)
#define preciseVolumeControl BIT(6)
#define powerCodeOnVBlank BIT(7)
#define b_runCardEngineCheck BIT(8)
#define delayWrites BIT(8)
#define igmAccessible BIT(9)
#define hiyaCfwFound BIT(10)
#define slowSoftReset BIT(11)
Expand Down Expand Up @@ -2105,6 +2105,13 @@ bool eepromPageWrite(u32 dst, const void *src, u32 len) {
/*if (saveInRam) {
tonccpy((char*)0x02440000 + dst, src, len);
}*/
if (valueBits & delayWrites) {
if (*(int*)((valueBits & isSdk5) ? 0x02FFFC3C : 0x027FFC3C) >= 60*2) {
valueBits &= ~delayWrites;
} else {
waitFrames(1);
}
}
sdmmc_set_ndma_slot(4);
if ((dst % saveSize)+len > saveSize) {
u32 len2 = len;
Expand Down
3 changes: 2 additions & 1 deletion retail/common/include/cardengine_header_arm7.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ typedef struct cardengineArm7 {
5: dsiSD
6: preciseVolumeControl
7: powerCodeOnVBlank
8: runCardEngineCheck
8: delayWrites
9: igmAccessible
10: hiyaCfwFound
11: slowSoftReset
Expand Down Expand Up @@ -140,6 +140,7 @@ typedef struct cardengineArm7B4DS {
u32 valueBits;
/*
7: a9IrqHooked
8: delayWrites
17: sleepMode
*/
s32 mainScreen;
Expand Down

0 comments on commit b88f8b1

Please sign in to comment.