* Version 2.0
*
* proc for Rip with height 200
* uncompress, this is important
*
* height 200=200*40byte(widght)=8000
* 2x16kb banks for 1 picture
* all Rip = 16kb memory for 200 line

* Rip header
* d'RIP1.0  ',b(0),b(packed=1, unpack=0)
* a(header lenCht),a(widght),a(height+1),
* a(name lenght),d'T:',name,
* how many colors(default=9 in RIP1.0)
* d'CM:',d'123456789'
*
* ASM source: line 144,148 - 8000 for 200line
* or 9520 for 238line

 org $b000

ad1 equ $2010 ;screen 1
ad2 equ $4010 ;screen 2

pic  equ $80
rip  equ pic+2
x    equ rip+2
y    equ x+2
line equ y+2

*--

main ldx <$6000 ;rip adres
 ldy >$6000     ;file load to this ...

* ldx $600  ;parametr /adres/
 stx pic
* ldy $601
 sty pic+1

 lda $2c8   ;for dli
 sta col1+1
 sta col2+1

 lda #$22
 sta $22f
 lda <dl
 sta $230
 lda >dl
 sta $231
 lda #$80
 sta $26f

 jsr copy
 jsr _conv

 lda <dli
 sta $200
 lda >dli
 sta $201
 lda #$c0
 sta $d40e
t jmp t     ;loop or exit

dli pha
 txa
 pha
 ldx #100
_d0 lda #$40
 sta $d40a
 sta $d01b
 lda #0
 sta $d01a
 lda #$80
 sta $d40a
 sta $d01b
col1 lda #$0
 sta $d01a
 dex
 bpl _d0
 lda >ad2
 sta adr+1
 lda >ad2+$1000
 sta adr2+1
 lda <dli2
 sta $200
 lda >dli2
 sta $201
 pla
 tax
 pla
 rti

dli2 pha
 txa
 pha
 ldx #100
_d1 lda #$80
 sta $d40a
 sta $d01b
col2 lda #$0
 sta $d01a
 lda #$40
 sta $d40a
 sta $d01b
 lda #0
 sta $d01a
 dex
 bpl _d1
 lda >ad1
 sta adr+1
 lda >ad1+$1000
 sta adr2+1
 lda <dli
 sta $200
 lda >dli
 sta $201
 pla
 tax
 pla
 rti

*- Copy
*  Rip data /2 picture/
*  to adres ad1, ad2
*-

copy ldy #11 ;header lenght
 lda (pic),y
 sta mem+1

 lda pic   ;get absolute adres
 clc       ;of rip data /skip header/
mem adc #0
 sta rip
 lda pic+1
 adc #0
 sta rip+1

 lda rip
 sta c1+1
 clc
 adc <9520  ;238line x 40byte=9520
 sta c3+1
 lda rip+1
 sta c1+2
 adc >9520
 sta c3+2

 ldx <ad1
 ldy >ad1
 stx c2+1
 sty c2+2

 ldx <ad2
 ldy >ad2
 stx c4+1
 sty c4+2

 ldy #0
 ldx #32
c1 lda $ffff,y      ;picture 1
c2 sta ad1,y
c3 lda $8000,y      ;picture 2
c4 sta ad2,y
 iny
 bne c1

 inc c1+2
 inc c2+2
 inc c3+2
 inc c4+2

 dex
 bne c1
 rts

*--

_conv lda #99
 sta line
 lda <ad1
 sta x
 lda >ad1
 sta x+1
 lda <ad2
 sta y
 lda >ad2
 sta y+1
 ldy #39
exc lda (x),y
 tax
 lda (y),y
 sta (x),y
 txa
 sta (y),y
 dey
 bpl exc
 ldy #39
 clc
 lda x
 adc <80
 sta x
 bcc *+4
 inc x+1
 clc
 lda y
 adc <80
 sta y
 bcc *+4
 inc y+1
 dec line
 bpl exc
 rts


dl dta d'ppš',b($4f)
adr dta a(ad1)
 dta d'////////////////'
 dta d'////////////////'
 dta d'////////////////'
 dta d'////////////////'
 dta d'////////////////'
 dta d'////////////////'
 dta d'/////',b($4f)
adr2 dta b(0),h(ad1+$1000)
 dta d'////////////////'
 dta d'////////////////'
 dta d'////////////////'
 dta d'////////////////'
 dta d'////////////////'
 dta d'////////////////'
 dta d'/',b($41),a(dl)

 run main