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.

C/C++ > Interrupt handling: tutorial and docs all differ on basics.

#4378 - jaholmes - Sat Mar 29, 2003 8:41 am

Ok, so I'm working on my first GBA project, and I'm a bit confused. Docs talk about saving and restoring REG_IME in your interrupt handler, but is that really a concern? For example, many demos don't do this (e.g., those that use Jeff F's Crt0.S with __FastInterrupts or __SingleInterrupts turned on and implement InterruptProcess in their C/C++ sources).

I've written some code that enables interrupts for timers 0 and 1, one set for twice the overflow rate of the other, and I don't see any nested interrupts happening. I've put hideous delay loops inside of InterruptProcess, but a nested interrupt simply never happens. Am I missing something?

Seems to me that, if you're NOT aiming to allow nested interrupts and NOT using __MultipleInterrupts, your interrupt handler ought to be as simple as:

void InterruptProcess() {

//
// <-- do whatever you want based on REG_IF;
//

REG_IF=REG_IF; // acknowledge all interrupts
}

All of my experiments seem to indicate this is fine, but I'm more interested in hard facts :)

Regards,
Aaron

BTW: THANKS LUNA_S!!! ... for fixing my registration. This is my first post, so "hello" all around. I'm jazzed to be getting started here.

#4389 - tepples - Sat Mar 29, 2003 5:07 pm

Note that when you acknowledge interrupts, you also have to tell the BIOS that you acknowledged them. Whatever you write to REG_IF you should also write to 0x03fffff8 (an address in IWRAM).

#define REG_BIOSIF (*(unsigned short *)0x03fffff8)

and then it'd be
Code:
void InterruptProcess() {
  int interrupts = REG_IF;

  //
  // <-- do whatever you want based on |interrupts|;
  //

  REG_BIOSIF = interrupts; // acknowledge all interrupts to BIOS
  REG_IF = interrupts; // acknowledge all interrupts to HW
}

_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.