#23202 - simc - Wed Jul 07, 2004 10:50 am
Hi everyone,
I have run into a snag while trying to use key interupts. I am trying to set a global variable when the interupt is triggered. As you can see, my code is very textbook and I don't really have any idea what is causing the keyInterupt to not run. The Vblank interupt works perfectly. I am using Jeff's crt0.S and I have modifed it to enable interupts and I am using multiple interupts. From my testing using Insight I know my enable function is run. I am also pretty sure that the key interupt function never runs as the global variable is never changed and breakpoints inside the function are never reached.
Basically, i'm hoping someone will notice some tiny error that I couldn't find ;-).
I have run into a snag while trying to use key interupts. I am trying to set a global variable when the interupt is triggered. As you can see, my code is very textbook and I don't really have any idea what is causing the keyInterupt to not run. The Vblank interupt works perfectly. I am using Jeff's crt0.S and I have modifed it to enable interupts and I am using multiple interupts. From my testing using Insight I know my enable function is run. I am also pretty sure that the key interupt function never runs as the global variable is never changed and breakpoints inside the function are never reached.
Basically, i'm hoping someone will notice some tiny error that I couldn't find ;-).
Code: |
#include "gba.h" #include "interupts.h" // External Variables // Used in BLANK interut handler to know if it is supposed to flip the buffers u16 ReadyToFlipBuffers=0; u16 InputFromKeyInterrupt=0; void (*IntrTable[])() = { vBlankInterrupt, // v-blank 0, // h-blank 0, // vcount 0, // timer0 0, // timer1 0, // timer2 0, // timer3 0, // serial 0, // dma0 0,// dma1 0, // dma2 0, // dma3 keyInterrupt, // key 0 // cart }; void enableVblankInterrupt() { REG_IME = 0x00; // Disable interrupts REG_IE |= BIT0; // Enable V-Blank IRQ. REG_DISPSTAT |= BIT3; // Enable Display V-Blank IRQ also. REG_IME = BIT0; // Enable interrupts } void disableInterrupts() { REG_IME = 0x00;// Disable interrupts } void keyInterrupt() { //InputFromKeyInterrupt = 0; // if (keyDown(KEY_B)) InputFromKeyInterrupt = InputFromKeyInterrupt | KEY_B; InputFromKeyInterrupt = 1; REG_IF |= INT_KEYBOARD; } void vBlankInterrupt() { if (ReadyToFlipBuffers == 1) { // Change buffers // See Pern Project tutorials day2 if (REG_DISPCNT & BACKBUFFER) // Back buffer is current buffer { //Switch to front buffer REG_DISPCNT = REG_DISPCNT & ~BACKBUFFER; currentVideoBuffer = BackBuffer; // Back buffer is the one we draw to, Front buffer is the one on screen } else { // Switch to front buffer REG_DISPCNT = REG_DISPCNT | BACKBUFFER; currentVideoBuffer = FrontBuffer; // Drawing on frontbuffer, displaying backbuffer } ReadyToFlipBuffers = 2; // signifies we don't need to do it again next vblank } REG_IF |= INT_VBLANK; } void enableKeyInterrupt() { REG_IME = 0; //probably not necessary but not a good idea to change interrupt registers when an interrupt is occuring REG_IE |= INT_KEYBOARD; REG_IME = 1; } |