Skip to content

Instantly share code, notes, and snippets.

@nurpax
Last active July 29, 2019 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nurpax/4996160f290fa1b9470520d7be0ca25e to your computer and use it in GitHub Desktop.
Save nurpax/4996160f290fa1b9470520d7be0ca25e to your computer and use it in GitHub Desktop.
c64jasm sprites example in a gist
!include "c64.asm"
; C64jasm example program
;
; see https://github.com/nurpax/c64jasm/tree/master/examples for more
!let SIN_LEN = 64
!let zptmp0 = $20
+c64::basic_start(entry)
;-----------------------------------------------
; Execution starts here
;-----------------------------------------------
entry:
frame_loop:
jsr wait_first_line
; sine animate the sprite
lda #0
tay
sta zptmp0
anim_sprites:
lda animcnt
clc
adc zptmp0
and #SIN_LEN-1
tax
lda sintab, x
clc
adc #100
sta sprite_ypos, y
lda zptmp0
clc
adc #5
sta zptmp0
iny
cpy #8
bne anim_sprites
inc animcnt
jsr set_sprites
jmp frame_loop
set_sprites: {
!let xtmp = zptmp0
lda #0
sta $d01d ; no double width
sta $d017 ; no double height
sta $d01c ; single color sprites
lda #sprite_data/64
!for i in range(8) {
sta $07f8+i ; sprite ptr
}
lda #30
sta xtmp
ldx #0
ldy #0
xloop:
lda xtmp ; x coord
sta $d000, x
clc
adc #28
sta xtmp
lda sprite_color, y
sta $d027, y
lda sprite_ypos, y
sta $d001, x
iny
inx
inx
cpx #16
bne xloop
; Enable all sprites
lda #%11111111
sta $d015
rts
}
wait_first_line: {
ldx $d012
lda $d011
and #$80
bne wait_first_line
cpx #0
bne wait_first_line
rts
}
animcnt: !byte 0
sprite_ypos: !fill 8, 0
sprite_color: !byte 1, 7, 8, 9, 10, 2, 13, 14
sintab:
!for i in range(SIN_LEN) {
!byte Math.sin(i/SIN_LEN * Math.PI * 2.0) * 30
}
!align 64
sprite_data:
!for y in range(21) {
!for x in range(3) {
!let bits = 0
!for xi in range(8) {
!let xx = x*8 + xi
!let ox = xx - 24/2
!let oy = y - 21/2
!let r = ox*ox + oy*oy
!let v = 0
!if (r < 10*10) {
v = 1
}
!if (r < 5*5) {
v = 0
}
bits = bits | (v << (7-xi))
}
!byte bits
}
}
!byte 0 ; pad to 64 bytes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment