gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Interrupts....

#22364 - kanelo - Sat Jun 19, 2004 1:23 pm

Hi people from gbadev.

I'm using HAM, but without ham libraries. I set up interrupts like this:

INT_DISABLE;
// load the address of the interrupt handler
INT_DIR = (u32) IRQHandler;
// set wich interrupts could trigger interrupt handler
SET_INT(INT_VBLANK);
// enable vblank interrupt in REG_DISPSTAT
REG_DISPSTAT |= 0x8;
// enable interrupts
INT_ENABLE;

The Upper case are macros, or defines. So I set a funtion where to jump when an interrupt occurs, IRQHandler. Inside this function I check which one happened and do something.

void IRQHandler(void)
{
INT_DISABLE;
if( REG_IF == INT_VBLANK )
{
g_NewFrame = TRUE;
}
INT_ENABLE;
}


It wroks nice, but I wanted to know which is the best way to do this. I know this is not the best way. I also wanted some advice about interrupts, based on experience ^_^

Thank you for your time.

#22367 - kanelo - Sat Jun 19, 2004 2:57 pm

What do I have to do to support multiple interrupts ??

Thanks.

#22374 - dagamer34 - Sat Jun 19, 2004 5:25 pm

First, you are going to have to change your crt0.s to support multiple interrupts. Open up that file(%HAMDIR%/system) and comment lines 115 and 116 (Fast and Single interrupts) and uncomment line 117 (Multiple interrupts).

Now, stick this table somewhere in your code:
Code:

/* Macros that return virtual "types" */
typedef void (*fp)(void); 

/* Table of function pointers */
fp* IntrTable[]  =
{
   (fp*)VBLANK,
   (fp*)HBLANK,
   (fp*)VCOUNT,
   (fp*)TIMER0,
   (fp*)TIMER1,
   (fp*)TIMER2,
   (fp*)TIMER3,
   (fp*)SERIAL,
   (fp*)DMA0,
   (fp*)DMA1,
   (fp*)DMA2,
   (fp*)DMA3,
   (fp*)KEYBOARD,
   (fp*)CART
};


This is your interrupt "table". Every time an interrupt is triggered, it will look at this table for the function to call. This nicely allows you to change a function for an interrupt.

Here's an example, say, if I want to change the VBLANK interrupt to call function vbl():
Code:

IntrTable [0] = (fp*)vbl;


I suggest creating functions that easily set interrupt functions on the fly. Post again if you need more help.
_________________
Little kids and Playstation 2's don't mix. :(