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 > IPC_PEN_DOWN question

#43356 - Mr Snowflake - Sun May 22, 2005 6:49 pm

Why is this working:
Code:
     
   if(!(IPC->buttons & IPC_PEN_DOWN))
         consolePrintf("Touched!    ");
      else
         consolePrintf("Not touched!");

I expected it to work like this:
Code:

   if(IPC->buttons & IPC_PEN_DOWN)
         consolePrintf("Touched!    ");
      else
         consolePrintf("Not touched!");

Which would be more natural!

#43357 - Mollusk - Sun May 22, 2005 7:27 pm

Maybe it should be PEN_UP then...

IF you look at the ndstech, for the keys, it says
Quote:
Each key normally reads as 1, becomming zero when depressed


(http://www.bottledlight.com/ds/index.php/Misc/KeyInput)

So that's just how the DS works...

#43364 - Darkain - Sun May 22, 2005 8:00 pm

this is how the GBA always worked for key presses.. it was a natural move to the DS. (as i always say, i should code demos for the GBA before DS, as the GBA is much more well documented)
_________________
-=- Darkain Dragoon -=-
http://www.darkain.com
DarkStar for Nintendo DS

#43368 - Maverick - Sun May 22, 2005 8:12 pm

The reason is, on the GBA the KEYS register was defined as:

#define KEYS *(u16*)0x04000130

The register was full of 1's and the bits turned to 0's when a key was pressed.

This can be therefor reversed by defining it as:

#define KEYS ~(*(u16*)0x04000130)

This is the same on the DS.

#43369 - Darkain - Sun May 22, 2005 8:19 pm

Maverick wrote:
The reason is, on the GBA the KEYS register was defined as:

#define KEYS *(u16*)0x04000130

The register was full of 1's and the bits turned to 0's when a key was pressed.

This can be therefor reversed by defining it as:

#define KEYS ~(*(u16*)0x04000130)

This is the same on the DS.



A) you want
#define KEYS (~(*(u16*)0x04000130))
not
#define KEYS ~(*(u16*)0x04000130)

B) doing this adds an additional step every time you read key presses... while this may not seem important now, some people ARE speed freaks and dont like having the extra 2 or 3 ASM instructiosn to test for key presses. ;) plus, its common to compare it against a previous key settting from last poll, so you would need to test one normal and one inverse anyways, so it makes no difference
if ( (lastState & KEY_SELECT) && (!(inputState & KEY_SELECT)) ) {
_________________
-=- Darkain Dragoon -=-
http://www.darkain.com
DarkStar for Nintendo DS

#43376 - Mr Snowflake - Sun May 22, 2005 9:23 pm

That explains :) I understand now :) Ty you all