So, in Legend of Zelda, I'm using Direct Input to check for keypresses. I have all of the keys I need checked for (code below), but I need to now check for dual arrow keypresses (UP+LEFT, UP+RIGHT, DOWN+LEFT, DOWN+RIGHT)


Code:
KeysCheck
    ld  a,%11111110
    out ($01),a         ; activate arrow keys
    in  a,($01)
    bit 0,a
    jr  z,movedown
    bit 1,a
    jr  z,moveleft
    bit 2,a
    jr  z,moveright
    bit 3,a
    jr  z,moveup
    ld  a,%11011111
    out ($01),a
    in  a,($01)
    bit 7,a
    jr  z,usespell
    bit 6,a
    jr  z,usesecondary
    ld  a,%10111111
    out ($01),a
    in  a,($01)
    bit 7,a
    jr  z,pausemenu
    bit 6,a
    jr  z,inventory
    bit 5,a
    jr  z,useprimary
    ld  a,$FF
    out ($01),a
    ret


What cp should I use for them? Never done multiple presses before. And, not sure if this matters, and you can likely infer from the code, but the only group active at this time is the arrows.
Did you write that code yourself, or take it from someone else? If you wrote it yourself, then you should already know how to detect multiple arrow keys pressed at the same time. Smile The byte returned from Port $01 for direct input has 1 bits for keys that are not pressed and 0 bits for keys that are pressed (counterintuitively). Therefore, if the bit for the [up] arrow key is 0, then that key is pressed, regardless of whatever other keys are pressed and bits are reset. If you want to do diagonal motion, the usual method is to call the movedown/moveleft/moveright/moveup functions, and have each one push and pop af. Therefore, if up and left are pressed, both moveup and moveleft will be called. If you want to call a separate routine moveupleft when up and left are pressed, then you need to cp a to a byte with 1s for everything other than the up and left keys, and 0s for the up and left keys.
Right, I assumed as much, I just wanted to be safe and confirm before I coded incorrectly. And I think I'll use the latter method, having a moveupleft sort of routine.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement