#9448 - funkeejeffou - Tue Aug 05, 2003 4:32 am
unsigned short int *INPUT_REG = (unsigned short int *)0x4000130h;
if (((*INPUT_REG) & (0x3FF)) == 0x3FF)
//do funky stuff, here any key is pressed
If you have put O3 optimization level, declare the INPUT REG as volatile.
Hope this helps.
#9492 - funkeejeffou - Wed Aug 06, 2003 10:02 am
I'm happy it works cause I wrote it on the fly.
0x4000130h is the adress of the register where the keypad state is stored.
It is 16 bit wide so we declare a unsigned short int pointing at this adress.
As there are 10 buttons on the GBA, only the lower 10 bits of this variable are used, so we mask what is contained by the keypad register to keep these 10 significants bits(maybe it is not vital to do this, but I do it for security as we don't know what value is stored in the 6 upper bits) :
*KEY_INPUT & 0x3FF
//0x3FF = 0000001111111111
Each bit represents the state of a button. If the button is pressed, the corresponding bit is equal to 0, otherwise it is set to 1.
So when any key is pressed, all the 10 last bits are set to 1 :
if ((*KEY_INPUT & 0x3FF) = 0x3FF)
//no key pressed
This is easy to figure out, just grap a doc like cowbite or GbaTek (Gbatek rocks!), and read each time the technica info about registers and other stuff. That way you could implement whatever you want (DMA, bios functiun...).
Cheers
#9514 - funkeejeffou - Thu Aug 07, 2003 11:09 am
The code is for no button pressed, excuse my english, I'm french.