CEMETECH
Leading The Way To The Future
Login [Register]
Username:
Password:
Autologin:

Don't have an account? Register now to chat, post, use our tools, and much more.
Latest Headlines
Online Users
There are 90 users online: 2 members, 63 guests and 25 bots.
Members: gbl08ma.
Bots: Spinn3r (3), Magpie Crawler (3), Googlebot (19).
RSS & Social Media
SAX
You must log in to view the SAX chat widget
Author Message
ACagliano


Super-Expert


Joined: 08 Feb 2010
Posts: 922

Posted: 24 Apr 2012 09:49:27 am    Post subject: Detecting Multiple Arrow KeyPresses

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.
_________________
-ACagliano

Current Projects

Legend of Zelda. "Ganon's Rage"
51%
Back to top
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 55741
Location: Earth, Sol, Milky Way

Posted: 24 Apr 2012 11:29:43 am    Post subject:

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.
_________________


Back to top
ACagliano


Super-Expert


Joined: 08 Feb 2010
Posts: 922

Posted: 24 Apr 2012 11:38:52 am    Post subject:

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.
_________________
-ACagliano

Current Projects

Legend of Zelda. "Ganon's Rage"
51%
Back to top
Display posts from previous:   
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
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are GMT - 5 Hours

 
Jump to:  
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

© Copyright 2000-2013 Cemetech & Kerm Martian :: Page Execution Time: 0.023828 seconds.