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.

Coding > Both keys pressed (REG_P1CNT)

#35869 - bobb - Fri Feb 11, 2005 6:11 pm

Hello, I cant figure out how I can turn of that both keys kan be pressed, like up and right.

It is something in the REG_P1CNT register, someone know how to enable this flag?

Thanks

#35870 - tepples - Fri Feb 11, 2005 6:43 pm

What are you talking about? REG_P1CNT refers only to keypad interrupts. There is no way to make it impossible for the player to press diagonally on the controller.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#35877 - Fatnickc - Fri Feb 11, 2005 8:43 pm

Maybe you could do something like this :
Code:

....
if(keyDown(KeyUp)&&keyDown(KeyLeft)!=True)
{..}

etc.
I used a fairly similar setup in a recent tiny minigame made for a friend, but don't have the code on-hand right now.

#35879 - bobb - Fri Feb 11, 2005 9:28 pm

well I have if loops to check what key is pressed, but if both keys are pressed it will go through both loops, I read this can be prevented by setting 16 of the REG_P1CNT register (Interrupt Condition Specification Flag), if its 1 it will do a logical AND if its 0 it will do an OR, but how do I set it.

#35881 - sajiimori - Fri Feb 11, 2005 9:30 pm

Do you have a particular reason for using key interrupts? If not, polling will make things simpler. To check for 2 keys, you just check if 2 bits are on in the input register.

#35888 - bobb - Sat Feb 12, 2005 12:19 am

no but I thought it is faster (optimezed) if I just set bit 16 and dont have to do any other checks...

#35892 - sajiimori - Sat Feb 12, 2005 1:23 am

Are you having performance issues? If so, input is probably not your bottleneck. Find out what it really is.