I am making a very very simple sprite movement program based on the Nerdy Night tutorial. and I am a bit stuck. I have 4 little bubble moving around the screen at different speeds when the user pressed up / down / left / right. I have 2 questions
1 - how do I make sprite movement continuous without the user constantly holding down a direction. I am guessing at BNE rather than BEQ while reading controllers but I cant work out how to implement it.
2 - How do I make the sprites start moving from the moment the rom is started rather than waiting for user input? I was assuming something like
Before reading controllers would do the trick but I couldn't work out where to put it!
Here is the code I have for movement so far. I attached the .nes as well is anyone wanted to have a look at it.
thanks everyone!
1 - how do I make sprite movement continuous without the user constantly holding down a direction. I am guessing at BNE rather than BEQ while reading controllers but I cant work out how to implement it.
2 - How do I make the sprites start moving from the moment the rom is started rather than waiting for user input? I was assuming something like
Code:
LDA $0200 ; load sprite X position
SEC ; make sure the carry flag is clear
SBC #$01 ; A = A - 1
STA $0200 ; save sprite X position
SEC ; make sure the carry flag is clear
SBC #$01 ; A = A - 1
STA $0200 ; save sprite X position
Before reading controllers would do the trick but I couldn't work out where to put it!
Here is the code I have for movement so far. I attached the .nes as well is anyone wanted to have a look at it.
thanks everyone!
Code:
LatchController:
LDA #$01
STA $4016
LDA #$00
STA $4016 ; tell both the controllers to latch buttons
ReadA:
LDA $4016 ; player 1 - A
AND #%00000001 ; only look at bit 0
BEQ ReadADone ; branch to ReadADone if button is NOT pressed (0)
ReadADone: ; handling this button is done
ReadB:
LDA $4016 ; player 1 - B
AND #%00000001 ; only look at bit 0
BEQ ReadBDone ; branch to ReadBDone if button is NOT pressed (0)
ReadBDone: ; handling this button is done
Readselect:
LDA $4016 ; player 1 - select
AND #%00000001 ; only look at bit 0
BEQ ReadselectDone ; branch to Readselect Done if button is NOT pressed (0)
ReadselectDone: ; handling this button is done
Readstart:
LDA $4016 ; player 1 - select
AND #%00000001 ; only look at bit 0
BEQ ReadstartDone ; branch to Readstart Done if button is NOT pressed (0)
ReadstartDone: ; handling this button is done
Readup:
LDA $4016 ; player 1 - up
AND #%00000001 ; only look at bit 0
BEQ ReadupDone ; branch to Readup Done if button is NOT pressed (0)
; add instructions here to do something when button IS pressed (1)
LDA $0200 ; load sprite X position
SEC ; make sure the carry flag is clear
SBC #$01 ; A = A - 1
STA $0200 ; save sprite X position
LDA $0204 ; load sprite X position
SEC ; make sure the carry flag is clear
SBC #$02 ; A = A - 1
STA $0204 ; save sprite X position
LDA $0208 ; load sprite X position
SEC ; make sure the carry flag is clear
SBC #$03 ; A = A - 1
STA $0208 ; save sprite X position
LDA $020C ; load sprite X position
SEC ; make sure the carry flag is clear
SBC #$04 ; A = A - 1
STA $020C ; save sprite X position
ReadupDone: ; handling this button is done
Readdown:
LDA $4016 ; player 1 + down
AND #%00000001 ; only look at bit 0
BEQ ReaddownDone ; branch to Readdown Done if button is NOT pressed (0)
; add instructions here to do something when button IS pressed (1)
LDA $0200 ; load sprite Y position
CLC ; make sure the carry flag is clear
ADC #$01 ; A = A + 1
STA $0200 ; save sprite Y position
LDA $0204 ; load sprite X position
SEC ; make sure the carry flag is clear
ADC #$02 ; A = A + 1
STA $0204 ; save sprite X position
LDA $0208 ; load sprite X position
SEC ; make sure the carry flag is clear
ADC #$03 ; A = A + 1
STA $0208 ; save sprite X position
LDA $020C ; load sprite X position
SEC ; make sure the carry flag is clear
ADC #$04 ; A = A + 1
STA $020C ; save sprite X position
ReaddownDone: ; handling this button is done
Readleft:
LDA $4016 ; player 1 - select
AND #%00000001 ; only look at bit 0
BEQ ReadleftDone ; branch to Readleft Done if button is NOT pressed (0)
; add instructions here to do something when button IS pressed (1)
LDA $0203 ; load sprite X position
SEC ; make sure the carry flag is clear
SBC #$01 ; A = A - 1
STA $0203 ; save sprite X position
LDA $0207 ; load sprite X position
SEC ; make sure the carry flag is clear
SBC #$02 ; A = A - 1
STA $0207 ; save sprite X position
LDA $020B ; load sprite X position
SEC ; make sure the carry flag is clear
SBC #$03 ; A = A - 1
STA $020B ; save sprite X position
LDA $020F ; load sprite X position
SEC ; make sure the carry flag is clear
SBC #$04 ; A = A - 1
STA $020F ; save sprite X position
ReadleftDone: ; handling this button is done
Readright:
LDA $4016 ; player 1 - select
AND #%00000001 ; only look at bit 0
BEQ ReadrightDone ; branch to Readright Done if button is NOT pressed (0)
; add instructions here to do something when button IS pressed (1)
LDA $0203 ; load sprite X position
CLC ; make sure the carry flag is clear
ADC #$01 ; A = A + 1
STA $0203 ; save sprite X position
LDA $0207 ; load sprite X position
CLC ; make sure the carry flag is clear
ADC #$02 ; A = A + 1
STA $0207 ; save sprite X position
LDA $020b ; load sprite X position
CLC ; make sure the carry flag is clear
ADC #$03 ; A = A + 1
STA $020b ; save sprite X position
LDA $020f ; load sprite X position
CLC ; make sure the carry flag is clear
ADC #$04 ; A = A + 1
STA $020f ; save sprite X position
ReadrightDone: ; handling this button is done
LDA #$01
STA $4016
LDA #$00
STA $4016 ; tell both the controllers to latch buttons
ReadA:
LDA $4016 ; player 1 - A
AND #%00000001 ; only look at bit 0
BEQ ReadADone ; branch to ReadADone if button is NOT pressed (0)
ReadADone: ; handling this button is done
ReadB:
LDA $4016 ; player 1 - B
AND #%00000001 ; only look at bit 0
BEQ ReadBDone ; branch to ReadBDone if button is NOT pressed (0)
ReadBDone: ; handling this button is done
Readselect:
LDA $4016 ; player 1 - select
AND #%00000001 ; only look at bit 0
BEQ ReadselectDone ; branch to Readselect Done if button is NOT pressed (0)
ReadselectDone: ; handling this button is done
Readstart:
LDA $4016 ; player 1 - select
AND #%00000001 ; only look at bit 0
BEQ ReadstartDone ; branch to Readstart Done if button is NOT pressed (0)
ReadstartDone: ; handling this button is done
Readup:
LDA $4016 ; player 1 - up
AND #%00000001 ; only look at bit 0
BEQ ReadupDone ; branch to Readup Done if button is NOT pressed (0)
; add instructions here to do something when button IS pressed (1)
LDA $0200 ; load sprite X position
SEC ; make sure the carry flag is clear
SBC #$01 ; A = A - 1
STA $0200 ; save sprite X position
LDA $0204 ; load sprite X position
SEC ; make sure the carry flag is clear
SBC #$02 ; A = A - 1
STA $0204 ; save sprite X position
LDA $0208 ; load sprite X position
SEC ; make sure the carry flag is clear
SBC #$03 ; A = A - 1
STA $0208 ; save sprite X position
LDA $020C ; load sprite X position
SEC ; make sure the carry flag is clear
SBC #$04 ; A = A - 1
STA $020C ; save sprite X position
ReadupDone: ; handling this button is done
Readdown:
LDA $4016 ; player 1 + down
AND #%00000001 ; only look at bit 0
BEQ ReaddownDone ; branch to Readdown Done if button is NOT pressed (0)
; add instructions here to do something when button IS pressed (1)
LDA $0200 ; load sprite Y position
CLC ; make sure the carry flag is clear
ADC #$01 ; A = A + 1
STA $0200 ; save sprite Y position
LDA $0204 ; load sprite X position
SEC ; make sure the carry flag is clear
ADC #$02 ; A = A + 1
STA $0204 ; save sprite X position
LDA $0208 ; load sprite X position
SEC ; make sure the carry flag is clear
ADC #$03 ; A = A + 1
STA $0208 ; save sprite X position
LDA $020C ; load sprite X position
SEC ; make sure the carry flag is clear
ADC #$04 ; A = A + 1
STA $020C ; save sprite X position
ReaddownDone: ; handling this button is done
Readleft:
LDA $4016 ; player 1 - select
AND #%00000001 ; only look at bit 0
BEQ ReadleftDone ; branch to Readleft Done if button is NOT pressed (0)
; add instructions here to do something when button IS pressed (1)
LDA $0203 ; load sprite X position
SEC ; make sure the carry flag is clear
SBC #$01 ; A = A - 1
STA $0203 ; save sprite X position
LDA $0207 ; load sprite X position
SEC ; make sure the carry flag is clear
SBC #$02 ; A = A - 1
STA $0207 ; save sprite X position
LDA $020B ; load sprite X position
SEC ; make sure the carry flag is clear
SBC #$03 ; A = A - 1
STA $020B ; save sprite X position
LDA $020F ; load sprite X position
SEC ; make sure the carry flag is clear
SBC #$04 ; A = A - 1
STA $020F ; save sprite X position
ReadleftDone: ; handling this button is done
Readright:
LDA $4016 ; player 1 - select
AND #%00000001 ; only look at bit 0
BEQ ReadrightDone ; branch to Readright Done if button is NOT pressed (0)
; add instructions here to do something when button IS pressed (1)
LDA $0203 ; load sprite X position
CLC ; make sure the carry flag is clear
ADC #$01 ; A = A + 1
STA $0203 ; save sprite X position
LDA $0207 ; load sprite X position
CLC ; make sure the carry flag is clear
ADC #$02 ; A = A + 1
STA $0207 ; save sprite X position
LDA $020b ; load sprite X position
CLC ; make sure the carry flag is clear
ADC #$03 ; A = A + 1
STA $020b ; save sprite X position
LDA $020f ; load sprite X position
CLC ; make sure the carry flag is clear
ADC #$04 ; A = A + 1
STA $020f ; save sprite X position
ReadrightDone: ; handling this button is done