#58539 - Nacho - Mon Oct 24, 2005 2:13 pm
Hi! I?m trying to set my game?s frequency to 20 FPS. Until now, I?ve been using the scanline counter register but I?ve been suggested to use interruptions instead so I looked into that. My plan of attack is the following one: keep a static variable inside the InterruptHandler and increment it everytime a VBlank interruption occurs. Whenever that variable reaches 3, set a global variable to 1 so that the main loop can flip pages. Here?s the code:
Unfortunately, the program crashes, although it works ok whenever I comment the
statement. I believe this has something to do with the fact that InterruptHandler() is located in IWRAM whereas main() is not but I don?t know how to solve it. Can you help with this? Thanks in advance!
--Nacho
Code: |
// Interruptions.c int g_iOK = 0; CODE_IN_IWRAM void InterruptHandler(void) { static int iNumPasses = 0; unsigned short usFlags; REG_IME = 0x00; usFlags = REG_IF; if((REG_IF & INT_VBLANK)==INT_VBLANK) { if(++iNumPasses==3) { iNumPasses = 0; g_iOK = 1; } /* End if */ else { g_iOK = 0; } /* End else */ } /* End if */ REG_IF = usFlags; REG_IME = 0x01; return; } /* End InterruptHandler() */ |
Code: |
// Main.c int main(void) { // Code while(iFlag) { GameMain(&RendCont); while(!g_iOK); FlipPages(); FillScreen(); } // More code. } |
Unfortunately, the program crashes, although it works ok whenever I comment the
Code: |
while(!g_iOK); |
--Nacho