I'm using the Nerdy Nights tutorials from Nintendo Age, in case you've heard of them, and am attempting to finish a pong game. The original, unfinished version by the tutorial author (Bunnyboy) can be downloaded here: http://www.nespowerpak.com/nesasm/pong1.zip
I'm trying to make it so the paddle stops moving whenever it collides with boundaries on the top and bottom of the screen. The first code I tried to write to move the paddle up was
But when I assembled it I couldn't move up whatsoever, so I changed
which works as expected. The problem also occurs with my code to move the paddle down, (BOTTOMWALL was defined as $E0 which caused the same problem) except I can't find a hex value like I did as a workaround for the code to move the paddle up.
Also, as a side note, could somebody please tell me the difference between the opcodes "AND" and "CMP"? I've looked at definitions of both of them but they seem to do the same thing and the definitons are just worded slightly differently between the two.
I'm trying to make it so the paddle stops moving whenever it collides with boundaries on the top and bottom of the screen. The first code I tried to write to move the paddle up was
Code:
MovePaddleUp:
LDA buttons1
; (is a variable where each bit from left to right is for A, B, Select, Start, Up, Down, Left, Right)
AND #%00001000
BEQ MovePaddleUpDone
;;if up button pressed
LDA $0204
AND #TOPWALL ; (defined as a constant equal to $20)
BEQ MovePaddleUpDone
;; if paddle top > top wall
LDA paddle1ytop
SEC
SBC #$05
STA paddle1ytop
LDA paddle1ybot
SEC
SBC #$05
STA paddle1ybot
;; move paddle top and bottom up
MovePaddleUpDone:
LDA buttons1
; (is a variable where each bit from left to right is for A, B, Select, Start, Up, Down, Left, Right)
AND #%00001000
BEQ MovePaddleUpDone
;;if up button pressed
LDA $0204
AND #TOPWALL ; (defined as a constant equal to $20)
BEQ MovePaddleUpDone
;; if paddle top > top wall
LDA paddle1ytop
SEC
SBC #$05
STA paddle1ytop
LDA paddle1ybot
SEC
SBC #$05
STA paddle1ybot
;; move paddle top and bottom up
MovePaddleUpDone:
But when I assembled it I couldn't move up whatsoever, so I changed
Code:
AND #TOPWALL
to Code:
AND #$D1
to get the boundary to the location where I wanted it and it worked fine. I had previously tried Code:
AND #$20 ; the value of the constant TOPWALL
but I couldn't move up whatsoever with that either. I don't think #$20 (the value of TOPWALL) is incorrect because it is used in part of the code to move the ball as inCode:
MoveBallUp:
LDA ballup
BEQ MoveBallUpDone ;;if ballup=0, skip this section
LDA bally
SEC
SBC ballspeedy ;;bally position = bally - ballspeedy
STA bally
LDA bally
CMP #TOPWALL
BCS MoveBallUpDone ;;if ball y > top wall, still on screen, skip next section
LDA #$01
STA balldown
LDA #$00
STA ballup ;;bounce, ball now moving down
MoveBallUpDone:
LDA ballup
BEQ MoveBallUpDone ;;if ballup=0, skip this section
LDA bally
SEC
SBC ballspeedy ;;bally position = bally - ballspeedy
STA bally
LDA bally
CMP #TOPWALL
BCS MoveBallUpDone ;;if ball y > top wall, still on screen, skip next section
LDA #$01
STA balldown
LDA #$00
STA ballup ;;bounce, ball now moving down
MoveBallUpDone:
which works as expected. The problem also occurs with my code to move the paddle down, (BOTTOMWALL was defined as $E0 which caused the same problem) except I can't find a hex value like I did as a workaround for the code to move the paddle up.
Also, as a side note, could somebody please tell me the difference between the opcodes "AND" and "CMP"? I've looked at definitions of both of them but they seem to do the same thing and the definitons are just worded slightly differently between the two.