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.

DS development > Problem with scanKeys()

#165729 - sverx - Mon Jan 05, 2009 5:37 pm

Hi!
is it normal that if you call scanKeys() function "too soon" then you get strange values? I mean, If I write:

Code:
int main(void) {
   // line1
   scanKeys();
   consoleDemoInit();  //setup the sub screen for printing
   iprintf("Keys=0x%x\n",keysDown());
.
.
.

I get
Quote:
Keys=0x1c00
, but what is really strange is that if I do something that takes some time (don't know how long) before the scanKeys() call, where I wrote // line1, then it's 0x0000.

It happens with no$gba, going to check this on hardware too, but it's annoying.

Normal? Bug? Nightmares?
_________________
libXM7|NDS programming tutorial (Italiano)|Waimanu DS / GBA|A DS Homebrewer's Diary


Last edited by sverx on Mon Jan 05, 2009 5:42 pm; edited 1 time in total

#165730 - Maxxie - Mon Jan 05, 2009 5:40 pm

scan keys can only "see" what happens at the time it's called.

If the status of the key changes, but returns to the previous state before scanKeys is called another time. It will not find any change.
_________________
Trying to bring more detail into understanding the wireless hardware

#165731 - sverx - Mon Jan 05, 2009 5:42 pm

mmm... I meant I wasn't pressing any key... :|
_________________
libXM7|NDS programming tutorial (Italiano)|Waimanu DS / GBA|A DS Homebrewer's Diary

#165734 - Maxxie - Mon Jan 05, 2009 6:21 pm

oh ok, then i have misread it.
_________________
Trying to bring more detail into understanding the wireless hardware

#165736 - hacker013 - Mon Jan 05, 2009 6:26 pm

i think 0x1c00 is the value of that key before it is pressed and because it isn't pressed before you that function calls you get this value.
_________________
Website / Blog

Let the nds be with you.

#165738 - Cearn - Mon Jan 05, 2009 6:42 pm

0x1C00 are the bits coming from the Arm7-only input register, accessed in scanKeys() via the transferRegion. It's possible this data hasn't been transferred yet, meaning the transferRegion's members are still 0. The bit-inversion to move from active-low to active-high logic would then result in 0x1C00.

#165751 - dovoto - Mon Jan 05, 2009 8:41 pm

keysDown gives the keys pressed during scanKeys that were not pressed durring the prior call to scanKeys(). In other words, scankeys must be called at least twice for keysDown to have any meaning.
_________________
www.drunkencoders.com

#165809 - sverx - Wed Jan 07, 2009 10:43 am

It happens on hardware too.

I understand that keysDown() will have meaning after two scanKeys(), but I believe that keysDown() should return 0 until then... at least because it does that if you spend 'enough' time before the scanKeys() call. If you consider that a generic program can look like:

Code:
int main(void) {
   prepare();
   while (1) {
     scanKeys();
     if (keysDown() & KEY_X)  doSomethingX();
     if (keysDown() & KEY_A)  doSomethingA();
   }


I think it's a problem if the behaviour of the program changes if prepare() takes enough or if it takes too little time...
_________________
libXM7|NDS programming tutorial (Italiano)|Waimanu DS / GBA|A DS Homebrewer's Diary