Dwedit's Board

Enjoy the board

You are not logged in.

Announcement

User passwords may have been corrupted, if you can't log in, use the "Forgot Password" feature. If you still can't log in, contact me and I can try to manually reset your password.

#1 2008-10-07 11:25:23 pm

Kuwanger
Guest

Understanding interrupts with PocketNES code

So, I've been working on adding a menu to Pogoshell2GBA.  Since I'm lazy, and PocketNES already has a pretty good menuing system, I decided to just copy it.  The problem is, I don't understand interrupts on the GBA well enough (apparently), so I've become stuck quite quickly when it comes to mimicking the menuing system.  So far, I have the following:

AGB_IRQVECT = 0x3007FFC

REG_BASE = 0x04000000
REG_P1 = 0x130

REG_INTERRUPT = 0x200
REG_IE = 0x00
REG_IF = 0x02
REG_IME = 0x08

...

ldr r5,=REG_BASE
add r5,r5,#REG_INTERRUPT

mov r0,#0
str r0,[r5,#REG_IME]

mov r0,#-1
strh r0,[r5,#REG_IF]
ldr r0,=0x1001
strh r0,[r5,#REG_IE]

ldr r1,=AGB_IRQVECT
adr r2,irqhandler
str r2,[r1]

mov r0,#1
strh r0,[r5,#REG_IME]

mov r0,#0
mov r3,#0
bl waitframe
bl drawmenu

...

waitframe:
stmfd sp!,{r0-r1}
mov r0,#0
mov r1,#1
swi 0x040000
ldmfd sp!,{r0-r1}
bx lr

irqhandler:
mov r2,#REG_BASE
add r2,r2,#REG_INTERRUPT
mov r3,#REG_BASE
ldr r1,[r2,#REG_IE]!
#r1=IE&IF
and r1,r1,r1,lsr#16
ldrh r0,[r3,#-8]
orr r0,r0,r1
strh r0,[r3,#-8]
strh r1,[r2,#REG_IF]
bx lr

I've confirmed that execution gets to the waitframe routine and that the 0x04000200-0x04000208 area looks right.  But, when I set a breakpoint on the irqhandler, it doesn't seem to be called at all.  I assume I'm missing something pretty major.  Any pointers/suggestions?

#2 2008-10-08 2:06:20 am

Dwedit
Administrator
From: Chicago
Registered: 2004-12-12
Posts: 1,022
Website

Re: Understanding interrupts with PocketNES code

There are four places for interrupts to be enabled and disabled:
* REG_IE
* REG_IME
* DISPSTAT
* The processor's CPSR register

DISPSTAT has three interrupt enable flags, one for HBLANK interrupts, one for VBLANK interrupts, and one for VCOUNT interrupts.  Vblank IRQ enable is bit #3, hblank irq is bit #4, and vcount irq is bit #5.

CPSR has an interrupt disable bit which is bit #7.  When set to 1, interrupts are disabled.
The interrupt disable bit can changed in every mode except user mode.
mrs r0,cpsr
bic r0,r0,#0x80  @clear "interrupt disable" bit
msr cpsr,r0


The other alternative:
Use devkitarm + libgba's interrupt functions.  Really easy to use.


"We are merely sprites that dance at the beck and call of our button pressing overlord."

Offline

#3 2008-10-08 9:08:45 am

Kuwanger
Guest

Re: Understanding interrupts with PocketNES code

Thanks for the help.  I wasn't setting DISPSTAT appropriately.

Registered users online in this topic: 0, guests: 1
[Bot] CCBot

Board footer

Powered by FluxBB
Modified by Visman