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 > No VBLANK interrupt in mode 5?!

#8304 - Lupin - Mon Jul 07, 2003 9:37 pm

I have problems getting the vblank interrupt work in mode5, but maybe it's just my odd interrupt handling wich already caused some other problems...

Here is the basic interrupt stuff I'm doing:
Code:

typedef void (*interrupt_handler_t)();
typedef interrupt_handler_t *interrupt_handler_ptr_t;

#define REG_IME (*(vu16*)0x4000208)
#define REG_IE (*(vu16*)0x4000200)
#define REG_IF (*(vu16*)0x4000202)
#define REG_INTERUPT (*((interrupt_handler_ptr_t)0x03007FFC))

void HandleInterrupt() {
  switch (REG_IF) {
   case INT_VBLANK:
    VBLANK();
    REG_IF = INT_VBLANK;
   case INT_KEYBOARD:
    KEYBOARD();
    REG_IF = INT_KEYBOARD;
  }
}

void EnableInterrupts(u16 interrupts) {
  REG_IME = 0;
   
  if(interrupts | INT_VBLANK)
   REG_DISP_STAT |= 0x8;

  if(interrupts | INT_HBLANK)
   REG_DISP_STAT |= 0x10;

  if(interrupts | INT_KEYBOARD)
   REG_P1CNT |= BIT14 | BIT0 | BIT1 | BIT2 | BIT3 | BIT4 | BIT5 | BIT6 |  BIT7 | BIT8 | BIT9;

  REG_IE |= interrupts;
  REG_IME = 1;
}


In my main() I'm just doing this:
Code:

  REG_INTERUPT = HandleInterrupt;
  EnableInterrupts(INT_VBLANK);


I'm not doing any interrupt stuff within my crt0.o files, so the problem has to be within the lines I posted above or mode 5 simply doesn't have an VBLANK interrupt (wich would be kinda odd...)

#8427 - Darkain - Thu Jul 10, 2003 5:59 am

VBLANK is there is mode5... possibly something else is causing errors?

one thing i noticed is that you have a switch (REG_IF)... wich is bad, as multiple interupts can fire at the same time. key input is polled alongside the vblank for its interupt from what ive seen. (some people have tried to argue this w/ me, but from what ive seen, if both are enabled, they will both always be called at the same time)
_________________
-=- Darkain Dragoon -=-
http://www.darkain.com
DarkStar for Nintendo DS

#8428 - marker - Thu Jul 10, 2003 7:26 am

Isn't there only 160x128 resolution in mode 5? Have you thought about that when you wrote the VBLANK function?

I'm a newbie, so i really don't know what I'm talking about, but this is certainly a mistake I would make.

-Marker

#8499 - Lupin - Sat Jul 12, 2003 9:53 am

I shouldn't have used an switch to check REG_IF, that was my problem :(