prg equ $a000

scren1 equ $8000
scren2 equ $9000
buf equ scren1
src equ $2000

bf equ $80
sr equ bf+2
frm equ sr+2
clock equ frm+1

 org src
 ins 'beet.ani'

 org prg
mai lda >scren1
 eor >scren2
 sta e2+1
 sta e1+1

 ldx <ant
 ldy >ant
 stx 560
 sty 561
 lda #%00100001
 sta 559
 lda #$40
 sta 623

 lda 20
 cmp 20
 beq *-2

 sei
 lda #$fe
 sta $d301
 lda #0
 sta $d40e

 ldx <nmi
 ldy >nmi
 stx $fffa
 sty $fffa+1
 lda #$17   ;pierwsze opuznienie
 sta clock

 lda #$40
 sta $d40e

go lda src+4 ;liczba klatek
 sta frm
 asl @
 clc
 adc #10
 adc frm
 adc <src
 sta sr
 lda #0
 adc >src
 sta sr+1

 ldx #0
 ldy #0
anm lda #1
 beq anm
 lda #0
 sta anm+1

 jsr depack

 ldy #0
 ldx #1
 dec frm
 bne anm
 jmp go

* Depacker

depack equ *
mad lda <buf
 sta bf
sad lda >buf
 sta bf+1

dep tya
dep_ clc
 adc bf
 sta bf
 bcc *+4
 inc bf+1

 txa
 clc
 adc sr
 sta sr
 bcc *+4
 inc sr+1

 ldy #0
 lda (sr),y
 tax
 and #$c0
 beq unp2
 cmp #$40
 beq rle
 cmp #$c0
 beq imp

unp1 inc sr
 bne *+4
 inc sr+1
 txa
 and #$3f
 tax
u1 lda (sr),y
 sta (bf),y
 iny
 dex
 bpl u1
 tya
 tax
 jmp dep_

exit rts
unp2 txa
 beq exit
 tay
 ldx #1
 jmp dep

rle txa
 and #$3f
 tax
 iny
 lda (sr),y
 dey
r sta (bf),y
 iny
 dex
 bpl r
 ldx #2
 jmp dep

imp txa
 and #$3f
 tax
 iny
 lda bf
 sec
 sbc (sr),y
 sta i+1
 lda bf+1
 sbc #0
 sta i+2

 ldy #0
i lda $ffff,y
 sta (bf),y
 iny
 dex
 bpl i
 ldx #2
 jmp dep


nmi pha
 tya
 pha
 sta $d40f

 inc 20

 dec clock
 bne skp
 lda adr+1
e1 eor #2
 sta adr+1
 lda sad+1
e2 eor #0
 sta sad+1

delay ldy #0
 lda src+10,y  ;opoznienie w ramkach
 sta clock
 sta anm+1
 inc delay+1
 lda delay+1
 cmp src+4
 bne skp
 lda #0
 sta delay+1

skp pla
 tay
 pla
 rti

ant dta d'ppp'
 dta b($4f)
adr dta a(scren2)
 dta d' / / / / / / / / / /'
 dta d' / / / / / / / / / /'
 dta d' / / / / / / / / / /'
 dta d' / / / / / / / / / /'
 dta d' / / / / / / / / / /'
 dta d' / / / / / / / / / /'
 dta d' / / / / / / / / / /'
 dta d' / / / / / / / / / /'
 dta d' / / / / / / / / / /'
 dta d' / / / / /'
 dta b($41),a(ant)

 run mai