#3838 - DaveMidknight - Mon Mar 10, 2003 10:23 am
Hi,
I have a problem with the following code. It works without problem with all emus, but not with the real GBA. As a workaround I am polling the keys from the VBL-Interrupt, but I would like to use the Key Interrupt. May be someone has an idea.
Thanks anyway!
Dave
//// CODE
// one include to rule them all
#include "mygba.h"
short key_code;
short key_event;
MULTIBOOT
// this function gets called by the Interrupt handler
void keyint()
{
key_code=0;
if(F_CTRLINPUT_A_PRESSED ) { key_event=1; key_code|=0x001; }
if(F_CTRLINPUT_B_PRESSED ) { key_event=1; key_code|=0x002; }
if(F_CTRLINPUT_R_PRESSED ) { key_event=1; key_code|=0x004; }
if(F_CTRLINPUT_L_PRESSED ) { key_event=1; key_code|=0x008; }
if(F_CTRLINPUT_START_PRESSED ) { key_event=1; key_code|=0x010; }
if(F_CTRLINPUT_SELECT_PRESSED) { key_event=1; key_code|=0x020; }
if(F_CTRLINPUT_UP_PRESSED ) { key_event=1; key_code|=0x040; }
if(F_CTRLINPUT_DOWN_PRESSED ) { key_event=1; key_code|=0x080; }
if(F_CTRLINPUT_LEFT_PRESSED ) { key_event=1; key_code|=0x100; }
if(F_CTRLINPUT_RIGHT_PRESSED ) { key_event=1; key_code|=0x200; }
}
int main(void)
{
// initialize HAMlib
ham_Init();
ham_InitText(0);
// Sets Key Interrupt to react on pressing of all buttons
*(volatile u16 *)(MEM_IO + 0x132)=0x43FF;
ham_StartIntHandler(INT_TYPE_KEY,&keyint);
while(1)
{
// Keyboard-Event !!
if(key_event)
{
// Just a quick test! Press each button ones! :-)
if (key_code&0x1) ham_DrawText(2,1,"A-Button");
if (key_code&0x2) ham_DrawText(2,2,"B-Button");
if (key_code&0x4) ham_DrawText(2,3,"R-Button");
if (key_code&0x8 ) ham_DrawText(2,4,"L-Button");
if (key_code&0x10) ham_DrawText(2,5,"Start-Button");
if (key_code&0x20) ham_DrawText(2,6,"Select-Button");
if (key_code&0x40) ham_DrawText(2,7,"Up-Button");
if (key_code&0x80) ham_DrawText(2,8,"Down-Button");
if (key_code&0x100) ham_DrawText(2,9,"Left-Button");
if (key_code&0x200) ham_DrawText(2,10,"Right-Button");
key_event = 0;
inventary = 0;
repaint = 1;
}
}
}
P.S. On the GBA it stops working after you have pressed 5 buttons.
I have a problem with the following code. It works without problem with all emus, but not with the real GBA. As a workaround I am polling the keys from the VBL-Interrupt, but I would like to use the Key Interrupt. May be someone has an idea.
Thanks anyway!
Dave
//// CODE
// one include to rule them all
#include "mygba.h"
short key_code;
short key_event;
MULTIBOOT
// this function gets called by the Interrupt handler
void keyint()
{
key_code=0;
if(F_CTRLINPUT_A_PRESSED ) { key_event=1; key_code|=0x001; }
if(F_CTRLINPUT_B_PRESSED ) { key_event=1; key_code|=0x002; }
if(F_CTRLINPUT_R_PRESSED ) { key_event=1; key_code|=0x004; }
if(F_CTRLINPUT_L_PRESSED ) { key_event=1; key_code|=0x008; }
if(F_CTRLINPUT_START_PRESSED ) { key_event=1; key_code|=0x010; }
if(F_CTRLINPUT_SELECT_PRESSED) { key_event=1; key_code|=0x020; }
if(F_CTRLINPUT_UP_PRESSED ) { key_event=1; key_code|=0x040; }
if(F_CTRLINPUT_DOWN_PRESSED ) { key_event=1; key_code|=0x080; }
if(F_CTRLINPUT_LEFT_PRESSED ) { key_event=1; key_code|=0x100; }
if(F_CTRLINPUT_RIGHT_PRESSED ) { key_event=1; key_code|=0x200; }
}
int main(void)
{
// initialize HAMlib
ham_Init();
ham_InitText(0);
// Sets Key Interrupt to react on pressing of all buttons
*(volatile u16 *)(MEM_IO + 0x132)=0x43FF;
ham_StartIntHandler(INT_TYPE_KEY,&keyint);
while(1)
{
// Keyboard-Event !!
if(key_event)
{
// Just a quick test! Press each button ones! :-)
if (key_code&0x1) ham_DrawText(2,1,"A-Button");
if (key_code&0x2) ham_DrawText(2,2,"B-Button");
if (key_code&0x4) ham_DrawText(2,3,"R-Button");
if (key_code&0x8 ) ham_DrawText(2,4,"L-Button");
if (key_code&0x10) ham_DrawText(2,5,"Start-Button");
if (key_code&0x20) ham_DrawText(2,6,"Select-Button");
if (key_code&0x40) ham_DrawText(2,7,"Up-Button");
if (key_code&0x80) ham_DrawText(2,8,"Down-Button");
if (key_code&0x100) ham_DrawText(2,9,"Left-Button");
if (key_code&0x200) ham_DrawText(2,10,"Right-Button");
key_event = 0;
inventary = 0;
repaint = 1;
}
}
}
P.S. On the GBA it stops working after you have pressed 5 buttons.