Jump to content
IGNORED

Controlling both Joysticks independently?


hendersonn

Recommended Posts

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.

Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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 by SpiceWare
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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:
...
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...