Jump to content
IGNORED

Previous input check


flame

Recommended Posts

Hey everyone,

 

Is there a way to check if the direction input was the same as the last ? I have a value that needs to reset if it is not.

 

MoveRT:
	lda direction
	cmp #$20
	beq .Reset
	jmp .Done

MoveLT:
	lda direction
	cmp #0
	beq .Reset
	jmp .Done

.Reset
	lda #0
	sta value
.Done:	rts

I have a direction facing that switches thanks to advice from @SpiceWare

 

This is what I am trying to do, but I am missing something.

Link to comment
Share on other sites

MoveRT	subroutine

	lda direction
	cmp #0
	beq .repeat
	lda #0
	sta steps

.repeat
	inc steps
	lda #0
	sta direction
	rts

MoveLT	subroutine	
    lda direction
	cmp #$20
	beq .repeat
	lda #0
	sta steps

.repeat
	inc steps
	lda #$20
	sta direction
	rts

I friend chimed in with some advice, this seems to be working !

Link to comment
Share on other sites

MoveRT subroutine
        lda #0 
        beq .move ; always branch

MoveLT
        lda #$20 

.move
        cmp direction 
        sta direction 
        beq .repeat 
        lda #1 
        sta steps 
        rts 

.repeat
        inc steps 
        rts 

I haven’t tested it but believe this will do the same thing, in fewer bytes and worst-case cycles. (You could also change the #1 to #0 and remove the first rts, trading a few cycles for a byte.)

  • Like 1
Link to comment
Share on other sites

I don't recall what direction is holding, but if you save the value of SCHWA from one frame you can easily compare it using EOR.

 

    lda SWCHA
    eor SAVED_SWCHA
    beq no_change

; handle change here, any bit in the accumulator that's a 1 is a joystick direction that's not the same as the prior frame

no_change:
    lda SWCHA
    sta SAVED_SWCHA

 

  • Like 2
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...