hendersonn Posted February 24, 2015 Share Posted February 24, 2015 I hope I do not catch flack for this (I almost feel embarrassed), but for the life of me I cannot seem to grasp the ability to read both Joystick inputs at once. I did look around, and even looked at disassembled roms, but nothing really stuck out to me. What am I missing? My mind keeps trying to compare values stored in SWCHA, but there must obviously be a better way to go about it. Here's an example: Joy lda #%00000000 sta SWACNT lda SWCHA cmp #%11111111 ;Zero beq Burn cmp #%11101111 ;L Up beq Loop1 cmp #%11111110 ;R Up beq Loop2 Loop1 sta WSYNC lda Onedat,x sta GRP0 inx cpx #190 bne Loop1 Loop2 sta WSYNC lda Twodat,x sta GRP1 inx cpx #190 bne Loop2 Thanks in advance. Quote Link to comment Share on other sites More sharing options...
Rybags Posted February 24, 2015 Share Posted February 24, 2015 Upper 4 bits are Port 1, lower 4 bits are Port 2. Generally you want to AND or bitshift so that the controller in question occupies the lower 4 bits, ie read the SWCHA register then do an LSR A 4 times to get port 1, or AND #$0F to get port 2. That gives the dual advantage of filtering out what's happening on the other port as well as allowing you to use the same program code to handle both joysticks. 1 Quote Link to comment Share on other sites More sharing options...
+SpiceWare Posted February 24, 2015 Share Posted February 24, 2015 (edited) Go check Collect. Download the last build and look for ProcessJoystick. There's a lot of comments in there, way more than I'd normally include, that explain exactly what's going on. Basically I load SWCHA into A then use ASL to put each direction into the Carry flag. Carry flag is then tested to see if the position is held or not. The same block of code gets run twice, once for the left player then again for the right. If you have any questions on the code please post them in the blog in case others have the same questions. Edited February 24, 2015 by SpiceWare Quote Link to comment Share on other sites More sharing options...
hendersonn Posted February 24, 2015 Author Share Posted February 24, 2015 I knew I had to OR/AND something somewhere. Seems so obvious; I'll have to take a step back and look at it again. Also Spice, your Collect demo is helpful with all the comments (that's actually the one source I've been trying to examine the most). I'll try to get the compare script out of my head and try again. Thanks Quote Link to comment Share on other sites More sharing options...
+SpiceWare Posted February 24, 2015 Share Posted February 24, 2015 One thing about the ASL method is it does tie up A. If you need to use A just do this: asl ; shift A bits left, R is now in the carry bit bcs CheckLeft ; branch if joystick is not held right pha ; save joystick reading ... ; do your routine for joystick held right pla ; restore joystick reading CheckLeft: asl ; shift A bits left, L is now in the carry bit bcs CheckDown ; branch if joystick not held left pha ; save joystick reading ... ; do your routine for joystick held left pla ; restore joystick reading CheckDown: ... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.