#define USER_INTERRUPT_HANDLE (void*)0x03005B00
#define WRAM_USER_INTERRUPT *(u32*)(0x03007FFC)
#define GAME_PAK_WAITCNT *(u32)(0x04000204)
#define USERHANDLE_DISPATCHER (void*)(0x081D6000)
#define DISPSTAT *(u32*)(0x04000004)
#define KEYCNT *(u32*)(0x04000132)
int main() {
asm (
"r0, #0x12\n\t"
"msr cpsr_cf, r0\n\t" // IRQ Mode
"ldr sp, =IRQStack\n\t" // Inicializa a Stack do IRQMode, 0x03007F60
"r0, #0x13\n\t"
"msr cpsr_cf, r0\n\t" // SVC Mode
"ldr sp, =SVCStack\n\t" // Inicializa a Stack do SVCMode, 0x03007FE0
"r0, #0x1F\n\t"
"msr cpsr_cf, r0\n\t" // Sys Mode
"ldr sp, =SysStack" // Inicializa a Stack do SysMode, 0x03007E00
);
// Salva um ponteiro para o user Interrupt Handle ?
WRAM_USER_INTERRUPT = USER_INTERRUPT_HANDLE;
// Inicializa o GamePak WAITCNT com os bits
GAME_PAK_WAITCNT = 0x45B4;
// Limpa Fast WRAM
memset_zero(0x3000000, 0x7E00);
// Limpa Slow WRAM
memset_zero(0x2000000, 0x40000);
// Limpa VRAM
memset_zero(0x6000000, 0x18000);
// Limpa OAM
memset_zero(0x7000000, 0x400);
// Limpa Palette
memset_zero(0x5000000, 0x400);
// Copia o UserHandle_Dispatcher para a WRAM
SetupUserHandle(USERHANDLE_DISPATCHER, USER_INTERRUPT_HANDLE, 0x1ED4);
// ?
CallCpuSet_Copy();
// ?
psRandom_And_Copy_Data();
// ?
BiosInterrupt_funcptr();
// Inicializa algumas variaveis
// wram_var_unk e as outras duas tem algo relacionado com hblank
// wram_var_unk
*(u32*)(0x020081B0) = 0;
// hblank_r_2
*(u32*)(0x02009930) = 1;
// hblank_r_1
*(u32*)(0x0200A870) = 0;
// Inicializa DisplayStatus com VBLANK
DISPSTAT = 8;
// Inicializa Key Interrupt, todos os botões e logica AND ?
KEYCNT = 0x83FF;
// Mais inicilizações e main game loop
init_main_game_loop(); // 0x080002BC
}
void CpuFastSet_FillMode(void* dst, u32 flag_mode) {
u32 fill_mode = 0x1000000;
fill_mode = (flag_mode >> 0x2) | fill_mode;
SWI_CpuFastSet(0x0, dst, fill_mode);
}
void clearVRAM() {
CpuFastSet_FillMode(0x06000000, 0x40);
CpuFastSet_FillMode(0x6004000, 0x40);
CpuFastSet_FillMode(0x6008000, 0x40);
CpuFastSet_FillMode(0x600C000, 0x20);
}
void SetupIRQHandle(void *src, void *dst, size_t size) {
while (size) {
dst[size] = src[size];
size--;
}
}