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 > REG_KEYCNT for X, Y & touchscreen in ARM7 code?

#126193 - Phantaseur - Fri Apr 20, 2007 9:06 pm

Code:
   REG_IME=0;
   IRQ_HANDLER=KeyPressed;
   REG_IE = IRQ_KEYS;
   REG_IF=~0;
   REG_KEYCNT=0x7fff;
   REG_IME=IME_ENABLE;

What else need I set up in code for ARM7 to get an interrupt for X, Y and touchscreen?

#126195 - tepples - Fri Apr 20, 2007 9:47 pm

Why do you need an interrupt for keypresses? Can't you just poll these at every vblank?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#126241 - Phantaseur - Sat Apr 21, 2007 8:59 am

Vblank happens 60 times per second, if I once press any key I have ~100 detections. I need: one push - one detecion.

#126242 - qw3rty - Sat Apr 21, 2007 9:02 am

keysDown() will do exactly what you want - it will only trigger once.
(and will be true until you scanKeys() again)

#126254 - Phantaseur - Sat Apr 21, 2007 10:59 am

http://nocash.emubase.de/gbatek.htm
Quote:
Interrupts are reportedly not supported for X,Y buttons.

Aaaa... Is it true?

#126257 - LiraNuna - Sat Apr 21, 2007 11:18 am

key IRQ is only for the buttons that are accessible from ARM9.
_________________
Private property.
Violators will be shot, survivors will be shot again.

#126259 - Phantaseur - Sat Apr 21, 2007 11:25 am

So, the only way to process X, Y & touchscreen is to process it during vblank irq?

#126304 - HyperHacker - Sun Apr 22, 2007 2:26 am

All game consoles I know of read the button status during VBlank, and use some simple logic to split the input into "buttons pressed this frame" and "buttons held for multiple frames" bitflags.
_________________
I'm a PSP hacker now, but I still <3 DS.

#126333 - LiraNuna - Sun Apr 22, 2007 11:43 am

HyperHacker wrote:
All game consoles I know of read the button status during VBlank, and use some simple logic to split the input into "buttons pressed this frame" and "buttons held for multiple frames" bitflags.


Like libnds' key*() functions, which also gives you the same info for X and Y buttons (inc. touch and lid aswell). Implementing a software IRQ wouldn't be a problem at all.
_________________
Private property.
Violators will be shot, survivors will be shot again.

#126479 - Phantaseur - Mon Apr 23, 2007 5:21 pm

Code:
main7.cpp:11: error: 'scanKeys' was not declared in this scope
main7.cpp:12: error: 'keysDown' was not declared in this scope
These functions weren't realised for ARM7? Is it possible to process keys in code for ARM7?

#126489 - tepples - Mon Apr 23, 2007 7:46 pm

Did you forget to #include the header that declares these functions?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#126490 - Phantaseur - Mon Apr 23, 2007 7:50 pm

I didn't forget include nds.h, it was enough for ARM9; something else needed by ARM7?

#126536 - HyperHacker - Tue Apr 24, 2007 4:43 am

You need to include it for ARM7 too.
_________________
I'm a PSP hacker now, but I still <3 DS.

#126537 - Phantaseur - Tue Apr 24, 2007 5:01 am

Yes, I know and I did it after creation of file. This string
Code:
#include<nds.h>
is the first string of my file, but I get error trying compile it with next options:
Code:
arm-eabi-g++ -mcpu=arm7tdmi -Wall -DARM7 -I/e/devkitPro/libnds/include/ -c main7.cpp
I said I didn't forget include it, I thought maybe something else neded?

#126546 - strager - Tue Apr 24, 2007 11:00 am

Those two functions are not in -lnds7. You'd either have to not use them, or copy their source from the -lnds9 to your own module on the ARM7.

#126585 - Phantaseur - Tue Apr 24, 2007 9:04 pm

OK, I'll try copy source from libnds9 to my ARM7 code, but where can I find it? I just tried search 'libnds' on sourceforge and found there libnds for freePascal and palib.
Quote:
You'd either have to not use them...
Is there any alternative solution?

#126660 - Phantaseur - Wed Apr 25, 2007 7:04 pm

Yeah! I did it. It was simple, I needed correct just one string and write
Code:
#define KEYS_CUR (( ( ((~REG_KEYXY)&0x07) | (~REG_KEYINPUT)&0x3ff) | (((~IPC->buttons)&3)<<10) | (((~IPC->buttons)<<6) & (KEY_TOUCH|KEY_LID) ))^KEY_LID)
instead of
Code:
#define KEYS_CUR (( ((~REG_KEYINPUT)&0x3ff) | (((~IPC->buttons)&3)<<10) | (((~IPC->buttons)<<6) & (KEY_TOUCH|KEY_LID) ))^KEY_LID)
I think may be I can delete these (((~IPC->buttons...?
added later:
Yes, now it looks next
Code:
#define KEYS_CUR ( ((~REG_KEYXY)&0x43) | (~REG_KEYINPUT)&0x3ff)