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 > interupts

#8502 - whodoo - Sat Jul 12, 2003 12:47 pm

as far as I know, an interupthandle for e.g. VBlank should look something like this:

...
if(REG_IF == INT_VBLANK)
{
// Do VBlank stuff
REG_IF = INT_VBLANK; // Clear
}

why do I have to set REG_IF = ... to clear it? I mean since I checked REG if in the first line, it?s allready set to 1?..so why do I have to set it to 1 when it?s allready is 1?

and if the program occurs more than one interupt at the same time I guess that
if(REG_IF == INT_VBLANK)
wouldnt work?

#8503 - whodoo - Sat Jul 12, 2003 1:46 pm

shouldnt it be like

if(REG_IF & VBLANK)
...
if(REG_IF & HBlank)..

to make sure the program will detect all interupts

#8514 - Darkain - Sat Jul 12, 2003 6:49 pm

you have to clear REG_IF flags so this way, once the interupt handler finishes, it isnt called again imediatly. i had an instance where it was calling the vblank irq more than 100 times a second cause it wasnt cleared.

for some strange reason, you have to set the bit to 1 to clear it, even though it is aleady set to 1.

and as for checking your interupts, you should be using & instead of ==, because more than 1 interupt could be triggered at the same time.
_________________
-=- Darkain Dragoon -=-
http://www.darkain.com
DarkStar for Nintendo DS

#8515 - whodoo - Sat Jul 12, 2003 7:27 pm

thx got a lil bit confused as I read the pern project tutorial..
works great