
scren1 equ $c000
scren2 equ $e000
buf equ scren1
src equ $2000

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

 org src
 ins 'auto.ani'

 org $400
main
 lda >scren1
 eor >scren2
 sta e1+1
 sta e2+1
 lda src+4   ;liczba klatek
 sta m_frm+1
 lda src+10  ;opoznienie w ramkach
 sta delay+1

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

 lda 20
 cmp 20
 beq *-2

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

 ldx <nmi
 ldy >nmi
 stx $fffa
 sty $fffa+1

 ldx #16
 ldy #0
 tya
c1 sta scren1,y
c2 sta scren2,y
 dey
 bne c1
 inc c1+2
 inc c2+2
 dex
 bne c1

 lda #6
 sta clock

 lda #$40
 sta $d40e

go ldx <src+$c
 ldy >src+$c
 stx sr
 sty sr+1
m_frm lda #0
 sta frm

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

 jsr depack

 ldy #2
 dec frm
 bne anm
 jmp go

* Depacker

depack equ *
mad lda <buf
 sta bf+1
sad lda >buf
 sta bf+2
dep tya
 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 iny
 txa
 and #$3f
 tax
u1 lda (sr),y
 iny
 jsr bf
 dex
 bpl u1
 jmp dep

exit rts
unp2 txa
 iny
 ora (sr),y
 beq exit
 lda (sr),y
 clc
 adc bf+1
 sta bf+1
 txa
 adc bf+2
 sta bf+2
 iny
 jmp dep

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

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

 ldy #0
i lda $ffff,y
 jsr bf
 iny
 dex
 bpl i
 ldy #3
 jmp dep

nmi pha
 sta $d40f

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

skp pla
 rti

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

 org $f0
bf sta buf
 inc bf+1
 bne *+4
 inc bf+2
 rts

 run main