From f4e78fd6b8888512a9f45fa7033fb5aaa749c182 Mon Sep 17 00:00:00 2001 From: AZero13 <83477269+SiliconA-Z@users.noreply.github.com> Date: Sun, 22 Mar 2026 20:04:36 -0400 Subject: [PATCH] Do the syscall in crt0 in UBFIX instead of Main Harmless in practice but do this before setting up the vector, not after, since it will mess it up. --- src/crt0.s | 6 +++++- src/main.c | 32 +++----------------------------- 2 files changed, 8 insertions(+), 30 deletions(-) diff --git a/src/crt0.s b/src/crt0.s index a0d8a4b55..ce84f2f96 100644 --- a/src/crt0.s +++ b/src/crt0.s @@ -14,6 +14,10 @@ start_vector: mov r0, #PSR_SYS_MODE msr cpsr_cf, r0 ldr sp, sp_usr + .if MODERN + mov r0, #255 @ RESET_ALL + svc #1 << 16 + .endif @ MODERN ldr r1, =INTR_VECTOR adr r0, intr_main str r0, [r1] @@ -98,7 +102,7 @@ jump_intr: orr r0, r0, #INTR_FLAG_GAMEPAK orr r1, r0, #INTR_FLAG_SERIAL | INTR_FLAG_TIMER3 | INTR_FLAG_VCOUNT | INTR_FLAG_HBLANK and r1, r1, r2 - strh r1, [r3, #0] + strh r1, [r3] mrs r3, cpsr bic r3, r3, #PSR_I_BIT | PSR_F_BIT | PSR_MODE_MASK orr r3, r3, #PSR_SYS_MODE diff --git a/src/main.c b/src/main.c index 542b0f5d1..f9444a83b 100644 --- a/src/main.c +++ b/src/main.c @@ -102,37 +102,11 @@ void AgbMain() #if REVISION >= 0xA svc_stubbed(); #endif -#if MODERN - // Modern compilers are liberal with the stack on entry to this function, +#if !MODERN + // Some compilers, especially modern ones, 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\tr2, #0xFC\n" - "\tlsl\tr2, r2, #0x7\n" - "\tadd\tr2, r1, r2\n" - "\tmov\tr0, #0\n" - "\tmov\tr3, r0\n" - "\tmov\tr4, r0\n" - "\tmov\tr5, r0\n" - ".LCU%=:\n" - "\tstmia\tr1!, {r0, r3, r4, r5}\n" - "\tstmia\tr1!, {r0, r3, r4, r5}\n" - "\tstmia\tr1!, {r0, r3, r4, r5}\n" - "\tstmia\tr1!, {r0, r3, r4, r5}\n" - "\tstmia\tr1!, {r0, r3, r4, r5}\n" - "\tstmia\tr1!, {r0, r3, r4, r5}\n" - "\tstmia\tr1!, {r0, r3, r4, r5}\n" - "\tstmia\tr1!, {r0, r3, r4, r5}\n" - "\tcmp\tr1, r2\n" - "\tbcc\t.LCU%=\n" - : - : - : "r0", "r1", "r2", "r3", "r4", "r5", "memory" - ); -#else RegisterRamReset(RESET_ALL); -#endif //MODERN +#endif // !MODERN #if REVISION >= 0xA *(vu16 *)BG_PLTT = RGB_BLACK;