Skip to content

Instantly share code, notes, and snippets.

@jeff-1amstudios
Last active December 2, 2021 14:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeff-1amstudios/7355d73284aab8e4e34aa7119e09c6a5 to your computer and use it in GitHub Desktop.
Save jeff-1amstudios/7355d73284aab8e4e34aa7119e09c6a5 to your computer and use it in GitHub Desktop.
C64 sprite animation routine
FRAME_COUNT = 10 ; constant for the nbr of sprite frames you have
.frame_counter !byte .FRAME_COUNT ; variable to keep track of how far through the animation we are
SPRITE_INITIAL_DATA_POINTER = 128 ; sprite data will be read by VIC-II at 128*64 ($2000)
on_screen_refresh
dec .frame_counter ; frame_counter variable -= 1
bne .increment_sprite_pointer ; if frame_counter > 0, goto .increment_sprite_pointer...
lda #SPRITE_INITIAL_DATA_POINTER ; ... otherwise, we should reset to the start of the animation
sta $07f8 ; reset the sprite pointer to start of sprite data
ldx #FRAME_COUNT
stx .frame_counter ; reset frame_counter to the nbr of sprite frames again
rts ; return
.increment_sprite_pointer
inc $07f8 ; sprite pointer += 1 (moves to the next frame)
rts ; return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment