mirror of
https://github.com/Ninjdai1/pokeemerald.git
synced 2024-11-16 19:47:35 +01:00
153 lines
3.1 KiB
ArmAsm
153 lines
3.1 KiB
ArmAsm
.include "constants/gba_constants.inc"
|
|
|
|
.syntax unified
|
|
|
|
.global Start
|
|
|
|
.text
|
|
|
|
.arm
|
|
|
|
Start: @ 8000000
|
|
b Init
|
|
|
|
.include "asm/rom_header.inc"
|
|
|
|
@ 80000C0
|
|
.word 0
|
|
|
|
.global GPIOPortData
|
|
GPIOPortData: @ 80000C4
|
|
.hword 0
|
|
|
|
.global GPIOPortDirection
|
|
GPIOPortDirection: @ 80000C6
|
|
.hword 0
|
|
|
|
.global GPIOPortReadEnable
|
|
GPIOPortReadEnable: @ 80000C8
|
|
.hword 0
|
|
|
|
.incbin "baserom.gba", 0xCA, 0x204 - 0xCA
|
|
|
|
.arm
|
|
.align 2, 0
|
|
.global Init
|
|
Init: @ 8000204
|
|
mov r0, PSR_IRQ_MODE
|
|
msr cpsr_cf, r0
|
|
ldr sp, sp_irq
|
|
mov r0, PSR_SYS_MODE
|
|
msr cpsr_cf, r0
|
|
ldr sp, sp_sys
|
|
ldr r1, =INTR_VECTOR
|
|
adr r0, InterruptMain
|
|
str r0, [r1]
|
|
ldr r1, =Main + 1
|
|
mov lr, pc
|
|
bx r1
|
|
b Init
|
|
|
|
.align 2, 0
|
|
sp_sys: .word IWRAM_END - 0x1c0
|
|
sp_irq: .word IWRAM_END - 0x60
|
|
|
|
.pool
|
|
|
|
.arm
|
|
.align 2, 0
|
|
.global InterruptMain
|
|
InterruptMain: @ 8000248
|
|
mov r3, REG_BASE
|
|
add r3, r3, 0x200
|
|
ldr r2, [r3, OFFSET_REG_IE - 0x200]
|
|
ldrh r1, [r3, OFFSET_REG_IME - 0x200]
|
|
mrs r0, spsr
|
|
stmdb sp!, {r0-r3,lr}
|
|
mov r0, 0
|
|
strh r0, [r3, OFFSET_REG_IME - 0x200]
|
|
and r1, r2, r2, lsr 16
|
|
mov r12, 0
|
|
ands r0, r1, INTR_FLAG_VCOUNT
|
|
bne InterruptMain_FoundIntr
|
|
add r12, r12, 0x4
|
|
mov r0, 0x1
|
|
strh r0, [r3, OFFSET_REG_IME - 0x200]
|
|
ands r0, r1, INTR_FLAG_SERIAL
|
|
bne InterruptMain_FoundIntr
|
|
add r12, r12, 0x4
|
|
ands r0, r1, INTR_FLAG_TIMER3
|
|
bne InterruptMain_FoundIntr
|
|
add r12, r12, 0x4
|
|
ands r0, r1, INTR_FLAG_HBLANK
|
|
bne InterruptMain_FoundIntr
|
|
add r12, r12, 0x4
|
|
ands r0, r1, INTR_FLAG_VBLANK
|
|
bne InterruptMain_FoundIntr
|
|
add r12, r12, 0x4
|
|
ands r0, r1, INTR_FLAG_TIMER0
|
|
bne InterruptMain_FoundIntr
|
|
add r12, r12, 0x4
|
|
ands r0, r1, INTR_FLAG_TIMER1
|
|
bne InterruptMain_FoundIntr
|
|
add r12, r12, 0x4
|
|
ands r0, r1, INTR_FLAG_TIMER2
|
|
bne InterruptMain_FoundIntr
|
|
add r12, r12, 0x4
|
|
ands r0, r1, INTR_FLAG_DMA0
|
|
bne InterruptMain_FoundIntr
|
|
add r12, r12, 0x4
|
|
ands r0, r1, INTR_FLAG_DMA1
|
|
bne InterruptMain_FoundIntr
|
|
add r12, r12, 0x4
|
|
ands r0, r1, INTR_FLAG_DMA2
|
|
bne InterruptMain_FoundIntr
|
|
add r12, r12, 0x4
|
|
ands r0, r1, INTR_FLAG_DMA3
|
|
bne InterruptMain_FoundIntr
|
|
add r12, r12, 0x4
|
|
ands r0, r1, INTR_FLAG_KEYPAD
|
|
bne InterruptMain_FoundIntr
|
|
add r12, r12, 0x4
|
|
ands r0, r1, INTR_FLAG_GAMEPAK
|
|
strbne r0, [r3, OFFSET_REG_SOUNDCNT_X - 0x200]
|
|
InterruptMain_Loop:
|
|
bne InterruptMain_Loop
|
|
InterruptMain_FoundIntr:
|
|
strh r0, [r3, OFFSET_REG_IF - 0x200]
|
|
bic r2, r2, r0
|
|
ldr r0, =gUnknown_03007868
|
|
ldr r0, [r0]
|
|
ldrb r0, [r0, 0xA]
|
|
mov r1, 0x8
|
|
mov r0, r1, lsl r0
|
|
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, OFFSET_REG_IE - 0x200]
|
|
mrs r3, cpsr
|
|
bic r3, r3, PSR_I_BIT | PSR_F_BIT | PSR_MODE_MASK
|
|
orr r3, r3, PSR_SYS_MODE
|
|
msr cpsr_cf, r3
|
|
ldr r1, =gUnknown_03002710
|
|
add r1, r1, r12
|
|
ldr r0, [r1]
|
|
stmdb sp!, {lr}
|
|
adr lr, InterruptMain_RetAddr
|
|
bx r0
|
|
InterruptMain_RetAddr:
|
|
ldmia sp!, {lr}
|
|
mrs r3, cpsr
|
|
bic r3, r3, PSR_I_BIT | PSR_F_BIT | PSR_MODE_MASK
|
|
orr r3, r3, PSR_I_BIT | PSR_IRQ_MODE
|
|
msr cpsr_cf, r3
|
|
ldmia sp!, {r0-r3,lr}
|
|
strh r2, [r3, OFFSET_REG_IE - 0x200]
|
|
strh r1, [r3, OFFSET_REG_IME - 0x200]
|
|
msr spsr_cf, r0
|
|
bx lr
|
|
|
|
.pool
|
|
|
|
.align 2, 0 @ Don't pad with nop.
|