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.

Beginners > What is the register for 'when no buttons are pressed'?

#9445 - yaustar - Tue Aug 05, 2003 1:14 am

I am trying to put in an operation when no buttons are pressed by the user.
Please help....
_________________
[Blog] [Portfolio]

#9446 - Freke - Tue Aug 05, 2003 2:12 am

Code:
#include "keypad.h"

if ((*KEYS & KEY_UP) && (*KEYS & KEY_DOWN) && (*KEYS & KEY_LEFT) && (*KEYS & KEY_RIGHT) && (*KEYS & KEY_L) && (*KEYS & KEY_R) && (*KEYS & KEY_START) && (*KEYS & KEY_SELECT))
{
// Do stuff
}


Untested...

#9447 - yaustar - Tue Aug 05, 2003 2:27 am

I thought about that, is there a short hand way of doing it?
_________________
[Blog] [Portfolio]

#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.

#9480 - yaustar - Tue Aug 05, 2003 10:43 pm

thank you, that works perfectly. How did you know that?
_________________
[Blog] [Portfolio]

#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

#9512 - yaustar - Thu Aug 07, 2003 1:58 am

It works for what I want it to do, ie do something when NOTHING is pressed. but you seem to say that the code is for when ANY button is pressed.
??
_________________
[Blog] [Portfolio]

#9514 - funkeejeffou - Thu Aug 07, 2003 11:09 am

The code is for no button pressed, excuse my english, I'm french.

#9537 - yaustar - Thu Aug 07, 2003 10:06 pm

that's ok, just wanted to be sure :p
_________________
[Blog] [Portfolio]