;Based on 64'er 1992/4 p. 58-59

*=$0801
;** BASIC-Zeile: 2018 SYS 2062
 !word main-2, 10 
 !byte $9e
 !text " 2062"
 !byte $00,$00,$00
 
 main


  sei
        jsr sprites
        lda  #$f9
        sta $d012
        lda #$01
        sta $d01a
        lda #$7d
        sta $dc0d
        lda #<start
        sta $0314
        lda #>start
        sta $0315
        lda #0
        sta $3fff
        ldx #0
sprd    lda spribits,x
        sta $3fc0,x
        inx
        cpx #64
        bne sprd
        ;sta $d021
        lda #$ff
        sta $d015
        lda #0
        sta $3fff
        
        ldx #0
sprpc    txa
        clc
        adc #7
        sta $d027,x
        inx
        cpx #8
        bne sprpc
        cli
wait  jmp wait
        rts
        
start
  lda #%00010011
        sta $d011
        ;lda $d021
        nop
        nop
        ;sta $d021
        nop
        nop
        
        nop
        nop
        nop
        nop
        ldx #21
        ldy #$08
rzyaus  dey
  bne rzyaus
conti nop
  nop
        nop
        dec $d016
        inc $d016
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        bit $00
        dex
        bne conti

        lda #$00
        sta $d012
        lda #<ready
        sta $0314
        lda #>ready
        sta $0315
        
        lda $d019
        sta $d019
        jmp $ea31
        
ready lda #$1b
  sta $d011
        jsr movesprites
        
        lda #$f9
        sta $d012
        
        lda #<start
        sta $0314
        lda #>start
        sta $0315
        lda $d019
        sta $d019
        jmp $ea31
        
sprites ldx #$00
spr1  lda sprdates,x
  sta $d000,x
        lda #1
        sta $d027,x
        inx
        cpx #$11
        bne spr1
        
        ldx #0
sprp    lda #$ff
        sta $07f8,x
        inx
        cpx #8
        bne sprp
        rts

spribits
  !byte 0,127,0,1,255,192,3,255,224,3,231,224
  !byte 7,217,240,7,223,240,7,217,240,3,231,224
  !byte 3,255,224,3,255,224,2,255,160,1,127,64
  !byte 1,62,64,0,156,128,0,156,128,0,73,0,0,73,0
  !byte  0,62,0,0,62,0,0,62,0,0,28,0 
        
movesprites
        ldx #0
moveit  inc $d000,x
        beq doflip
        lda $d010
        and andbits,x
        beq noflip
        lda $d000,x
        cmp #120
        bne noflip
        lda #0
        sta $d000,x
doflip
        lda andbits,x
        eor $d010
        sta $d010
        
noflip  
        inx
        inx
        cpx #16
        bne moveit
rts

sprdates
        !byte $00,$fa,$20,$fa
        !byte $40,$fa,$60,$fa
        !byte $f0,$fa,$10,$fa
        !byte $30,$fa,$50,$fa
        !byte %11100000
        
        andbits
 !byte 1,1,2,2,4,4,8,8,16,16,32,32,64,64,128,128
 
  