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

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

 org src
 ins 'odlot2.ani'

 org $400
main
 lda >scren1
 eor >scren2
 sta e1+1
 sta e2+1

 ldx <ant
 ldy >ant
 stx 560
 sty 561
 lda #%00100011
 sta 559
 lda #15
 sta 708

 lda 20
 cmp 20
 beq *-2

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

 ldx #32
 ldy #0
 tya
cl1 sta scren1-$10,y
cl2 sta scren2-$10,y
 dey
 bne cl1
 inc cl1+2
 inc cl2+2
 dex
 bne cl1

 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
 lda <src
 adc src+6
 sta sr
 lda >src
 adc src+7
 sta sr+1

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

 jsr depack

 ldx #1
 ldy #0
 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
 cmp #$c0
 bcs imp
 cmp #$80
 bcs unp1
 cmp #$40
 bcs rle

unp2 tay
 beq exit
 ldx #1
 jmp dep
exit rts

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

rle and #$3f
 sta tmp
 iny
 lda (sr),y
 ldy tmp
r sta (bf),y
 dey
 bpl r
 sec
 lda tmp
 ldx #2
 jmp dep_+1

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

 ldy tmp
i lda $ffff,y
 sta (bf),y
 dey
 bpl i
 sec
 lda tmp
 ldx #2
 jmp dep_+1

nmi pha
 tya
 pha
 sta $d40f

 inc 20

 dec clock
 bne skp

 lda adr+1
e1 eor #0
 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 b($4b)
adr dta a(scren2)
 dta d'++++++++++++++++++++'
 dta d'++++++++++++++++++++'
 dta d'++++++++++++++++++++'
 dta d'++++++++++++++++++++'
 dta d'++++++++++++++++++++'
 dta d'++++++++++++++++++'
 dta b($41),a(ant)

 run main