summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index 77f668e6f..367b7943d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -90,7 +90,27 @@ void EnableVCountIntrAtLine150(void);
void AgbMain()
{
+#if MODERN
+ // Modern compilers are liberal with the stack on entry to this function,
+ // so RegisterRamReset may crash if it resets IWRAM.
+ RegisterRamReset(RESET_ALL & ~RESET_IWRAM);
+ asm("mov\tr1, #0xC0\n"
+ "\tlsl\tr1, r1, #0x12\n"
+ "\tmov r2, #0xFC\n"
+ "\tlsl r2, r2, #0x7\n"
+ "\tadd\tr2, r1, r2\n"
+ "\tmov\tr0, #0\n"
+ "\tmov\tr3, r0\n"
+ "\tmov\tr4, r0\n"
+ "\tmov\tr5, r0\n"
+ ".LCU0:\n"
+ "\tstmia r1!, {r0, r3, r4, r5}\n"
+ "\tcmp\tr1, r2\n"
+ "\tbcc\t.LCU0\n"
+ );
+#else
RegisterRamReset(RESET_ALL);
+#endif //MODERN
*(vu16 *)BG_PLTT = RGB_WHITE;
InitGpuRegManager();
REG_WAITCNT = WAITCNT_PREFETCH_ENABLE | WAITCNT_WS0_S_1 | WAITCNT_WS0_N_3;