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.

DS development > REG_IF quick question

#86569 - wickedtrickster - Wed Jun 07, 2006 10:11 pm

Hello,

I'm currently coding at interrupt handler to be call once per VBlank. So far, everything works, my code is as follow:

void on_irq (void) {
if (REG_IF & IRQ_VBLANK) {
do_stuff ();
VBLANK_INTR_WAIT_FLAGS |= IRQ_VBLANK;
REG_IF |= IRQ_VBLANK;
}

Well, what's bugging me is this line :

REG_IF |= IRQ_VBLANK;

which is the same as

REG_IF = REG_IF | IRQ_VBLANK;

which since we are inside a if (REG_IF & IRQ_VBLANK) is the same as

REG_IF = REG_IF;

Which doesn't make sense. I did some search on the forum and found that you need to write set bits to REG_IF in order to let the DS knows you handled the interrupts. With this explanation, a line like

REG_IF = REG_IF;

tell the DS you handled all interrupts, which works in my code since I only manage 1 interrupts but I do not think it was the idea when the code was written. Shouldn't the line

REG_IF |= IRQ_VBLANK;

be written

REG_IF = IRQ_VBLANK;

? Yet, allmost all the example code I find on the internet do the |= kind of code. I guess there is something I understood wrong, but I can't figured out what is it....

Thank you,
Ben.

#86572 - NEiM0D - Wed Jun 07, 2006 10:13 pm

It should be REG_IF = IRQ_VBLANK. Everyone doing it with |= is simply wrong.

#86575 - wickedtrickster - Wed Jun 07, 2006 10:29 pm

Ok, thankx a lot !