pokeemerald/src/crt0.s

129 lines
2.7 KiB
ArmAsm
Raw Normal View History

2016-11-01 16:29:13 +01:00
.include "constants/gba_constants.inc"
2016-09-03 08:11:29 +02:00
.syntax unified
.arm
2021-11-01 06:42:02 +01:00
2016-09-03 08:11:29 +02:00
.align 2, 0
.global Init
Init:
2020-07-17 00:15:49 +02:00
mov r0, #PSR_IRQ_MODE
msr cpsr_cf, r0
ldr sp, sp_irq
2020-07-17 00:15:49 +02:00
mov r0, #PSR_SYS_MODE
msr cpsr_cf, r0
ldr sp, sp_sys
ldr r1, =INTR_VECTOR
2017-02-04 01:44:06 +01:00
adr r0, IntrMain
str r0, [r1]
.if MODERN
mov r0, #255 @ RESET_ALL
2020-11-06 18:34:57 +01:00
svc #1 << 16
.endif @ MODERN
2017-02-04 01:44:06 +01:00
ldr r1, =AgbMain + 1
mov lr, pc
bx r1
b Init
.align 2, 0
2016-09-03 08:11:29 +02:00
sp_sys: .word IWRAM_END - 0x1c0
sp_irq: .word IWRAM_END - 0x60
.pool
2016-09-03 08:11:29 +02:00
.arm
.align 2, 0
2017-02-04 01:44:06 +01:00
.global IntrMain
IntrMain:
2020-07-17 00:15:49 +02:00
mov r3, #REG_BASE
add r3, r3, #OFFSET_REG_IE
ldr r2, [r3]
ldrh r1, [r3, #OFFSET_REG_IME - 0x200]
mrs r0, spsr
2020-07-17 00:15:49 +02:00
stmfd 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
2017-02-04 01:44:06 +01:00
bne IntrMain_FoundIntr
add r12, r12, 0x4
mov r0, 0x1
2020-07-17 00:15:49 +02:00
strh r0, [r3, #OFFSET_REG_IME - 0x200]
ands r0, r1, #INTR_FLAG_SERIAL
2017-02-04 01:44:06 +01:00
bne IntrMain_FoundIntr
add r12, r12, 0x4
2020-07-17 00:15:49 +02:00
ands r0, r1, #INTR_FLAG_TIMER3
2017-02-04 01:44:06 +01:00
bne IntrMain_FoundIntr
add r12, r12, 0x4
2020-07-17 00:15:49 +02:00
ands r0, r1, #INTR_FLAG_HBLANK
2017-02-04 01:44:06 +01:00
bne IntrMain_FoundIntr
add r12, r12, 0x4
2020-07-17 00:15:49 +02:00
ands r0, r1, #INTR_FLAG_VBLANK
2017-02-04 01:44:06 +01:00
bne IntrMain_FoundIntr
add r12, r12, 0x4
2020-07-17 00:15:49 +02:00
ands r0, r1, #INTR_FLAG_TIMER0
2017-02-04 01:44:06 +01:00
bne IntrMain_FoundIntr
add r12, r12, 0x4
2020-07-17 00:15:49 +02:00
ands r0, r1, #INTR_FLAG_TIMER1
2017-02-04 01:44:06 +01:00
bne IntrMain_FoundIntr
add r12, r12, 0x4
2020-07-17 00:15:49 +02:00
ands r0, r1, #INTR_FLAG_TIMER2
2017-02-04 01:44:06 +01:00
bne IntrMain_FoundIntr
add r12, r12, 0x4
2020-07-17 00:15:49 +02:00
ands r0, r1, #INTR_FLAG_DMA0
2017-02-04 01:44:06 +01:00
bne IntrMain_FoundIntr
add r12, r12, 0x4
2020-07-17 00:15:49 +02:00
ands r0, r1, #INTR_FLAG_DMA1
2017-02-04 01:44:06 +01:00
bne IntrMain_FoundIntr
add r12, r12, 0x4
2020-07-17 00:15:49 +02:00
ands r0, r1, #INTR_FLAG_DMA2
2017-02-04 01:44:06 +01:00
bne IntrMain_FoundIntr
add r12, r12, 0x4
2020-07-17 00:15:49 +02:00
ands r0, r1, #INTR_FLAG_DMA3
2017-02-04 01:44:06 +01:00
bne IntrMain_FoundIntr
add r12, r12, 0x4
2020-07-17 00:15:49 +02:00
ands r0, r1, #INTR_FLAG_KEYPAD
2017-02-04 01:44:06 +01:00
bne IntrMain_FoundIntr
add r12, r12, 0x4
2020-07-17 00:15:49 +02:00
ands r0, r1, #INTR_FLAG_GAMEPAK
strbne r0, [r3, #REG_SOUNDCNT_X - REG_IE]
2017-02-04 01:44:06 +01:00
bne . @ spin
IntrMain_FoundIntr:
2020-07-17 00:15:49 +02:00
strh r0, [r3, #OFFSET_REG_IF - 0x200]
bic r2, r2, r0
2020-01-15 21:46:17 +01:00
ldr r0, =gSTWIStatus
ldr r0, [r0]
ldrb r0, [r0, 0xA]
mov r1, 0x8
2020-07-17 00:15:49 +02:00
lsl r0, r1, 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
2020-07-17 00:15:49 +02:00
strh r1, [r3, #OFFSET_REG_IE - 0x200]
mrs r3, cpsr
2020-07-17 00:15:49 +02:00
bic r3, r3, #PSR_I_BIT | PSR_F_BIT | PSR_MODE_MASK
orr r3, r3, #PSR_SYS_MODE
msr cpsr_cf, r3
ldr r1, =gIntrTable
add r1, r1, r12
ldr r0, [r1]
2020-07-17 00:15:49 +02:00
stmfd sp!, {lr}
2017-02-04 01:44:06 +01:00
adr lr, IntrMain_RetAddr
bx r0
2017-02-04 01:44:06 +01:00
IntrMain_RetAddr:
2020-07-17 00:15:49 +02:00
ldmfd sp!, {lr}
mrs r3, cpsr
2020-07-17 00:15:49 +02:00
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}
2020-07-17 00:15:49 +02:00
strh r2, [r3, #OFFSET_REG_IE - 0x200]
strh r1, [r3, #OFFSET_REG_IME - 0x200]
msr spsr_cf, r0
bx lr
.pool
2016-09-03 08:11:29 +02:00
.align 2, 0 @ Don't pad with nop.