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 > keysDown() on libgba, different behavior

#177830 - sverx - Mon Mar 25, 2013 4:30 pm

Is it just me or keysDown() of libgba works differently compared to the same function of libnds?

I mean... on a GBA project, if I call keysDown() twice, the second time I won't get the keys 'downed' since the last scanKeys() call... while on the NDS I will keep on reading the same value.

A bug? Just a little difference I wasn't aware of? Am I screwing something?
_________________
libXM7|NDS programming tutorial (Italiano)|Waimanu DS / GBA|A DS Homebrewer's Diary

#177831 - elhobbs - Mon Mar 25, 2013 5:00 pm

no, it behaves differently. whether this is intentional or not, I could not say.

libnds
Code:
uint32 keysDown(void) {
//------------------------------------------------------------------------------
return (keys &~ keysold);
}


libgba
Code:
u16 keysDown(void)
//---------------------------------------------------------------------------------
{
u16 tmp = Keys.Down;
Keys.Down = 0;
return tmp;
}

#177832 - sverx - Mon Mar 25, 2013 10:37 pm

Oh, well. Then it's better to do something like
Code:
while () {
  scanKeys()
  keysD=keysDown()
 ...
}

and then use only the local variable, both if you're coding for GBA or NDS...

Thanks :)
_________________
libXM7|NDS programming tutorial (Italiano)|Waimanu DS / GBA|A DS Homebrewer's Diary