Marching in place isn't nearly as exciting as using the OAM for its
real power, which is moving sprites around the screen, so this is a little
tweak to demonstrate updating the OAM coordinates.
current_frame:
.byte 0
sprite_x:
- .byte 0
+ .byte $7F
sprite_y:
- .byte 0
+ .byte $7F
frame_count:
.byte 0
; and frame index (i.e. where in the animation we are)
; and then call load_sprite to do the hard work
- lda #$7F
- sta sprite_x
- sta sprite_y
lda #0
sta current_frame
lda #0
sta frame_count
; We counted 15 NMIs, so let's update the animation frame and
-; make the little character walk in place
+; make the little character walk
lda current_frame
clc ; NEVER forget to clear the carry flag before adding
adc #6 ; Each frame is an offset of a multiple of 6
lda #0
dont_cycle_anim:
sta current_frame
+
+
+ lda sprite_x
+ clc
+ adc #4
+ sta sprite_x
+dont_reset_x:
+ sta sprite_x
done:
jsr load_sprite
rti ; Return from the NMI (NTSC refresh interrupt)
ldx #0
ldy current_frame
lda #$7F
- sta sprite_x
- lda #$7F
sta sprite_y
load_loop:
; First of two cells
inx
lda sprite_x
sta SPRITE_PAGE, X
+ sec
sbc #7 ; return to the left cell
sta sprite_x
inx
cpx #24
bne load_loop
lda sprite_y
+ sec
sbc #14
sta sprite_y
rts