;---------------------------------------
;Fill & clear & draw & draw tabs
;routine generator
;(c) BRUSH/ELYSIUM'94
;---------------------------------------

src      = $fa
dst      = $fc
put      = $fe

         *= $0900

         jmp fil
         jmp cls
         jmp drw

aput     .word $3a20   ;adres kodu fila
aput2    .word $2200   ;adres kodu cls
aput3    .word $1200   ;adres kodu draw
aput4    .word $1000   ;adres tabeli d.
ilekol   .byte $10     ;ile kolumn
padf     .word $3000   ;pocz adr.do rys.
krys     .byte $80     ;ile kolumn draw

kom1     .byte $fb     ;komorka do draw
kom2     .byte $fc     ;--------"------

;---------------------------------------
;Fill generator
;---------------------------------------

fil      sei
         lda aput
         sta put
         lda aput+1
         sta put+1
         lda #$00
         sta kol
dal3     ldx kol
         cpx ilekol
         bne dal1
         ldy #$00
         lda #$60
         sta (put),y
         rts

dal1     jsr wlda
         lda kol
         tay
         asl a
         tax
         lda pocze,x
         sta src
         lda pocze+1,x
         sta src+1
         lda poczs,x
         sta dst
         lda poczs+1,x
         sta dst+1
         lda offs,y
         clc
         adc src
         sta src
         lda src+1
         adc #$00
         sta src+1
         lda offs,y
         clc
         adc dst
         sta dst
         lda dst+1
         adc #$00
         sta dst+1
         lda ile,y
         sta lin
dal2     jsr weor
         jsr wsta
         lda src
         clc
         adc #$01
         sta src
         lda src+1
         adc #$00
         sta src+1
         lda dst
         clc
         adc #$01
         sta dst
         lda dst+1
         adc #$00
         sta dst+1
         dec lin
         bne dal2
         inc kol
         jmp dal3

;---------------------------------------
;Cls generator
;---------------------------------------

cls      sei
         lda aput2
         sta put
         lda aput2+1
         sta put+1
         lda #$00
         sta kol
         jsr wlda
kdal3    ldx kol
         cpx ilekol
         bne kdal1
         ldy #$00
         lda #$60
         sta (put),y
         rts


kdal1    lda kol
         tay
         asl a
         tax
         lda pocze,x
         sta src
         lda pocze+1,x
         sta src+1
         lda offs,y
         clc
         adc src
         sta src
         lda src+1
         adc #$00
         sta src+1
         lda ile,y
         sta lin
kdal2    jsr wsta2
         lda src
         clc
         adc #$01
         sta src
         lda src+1
         adc #$00
         sta src+1
         lda dst
         clc
         adc #$01
         sta dst
         lda dst+1
         adc #$00
         sta dst+1
         dec lin
         bne kdal2
         inc kol
         jmp kdal3

;---------------------------------------
;Draw routine
;---------------------------------------

drw      sei
         lda aput3
         sta put
         lda aput3+1
         sta put+1
         lda #$00
         sta kol
dfg1     jsr wrou
         inc kol
         lda kol
         cmp #$80
         bne dfg1

         dec kol
dfg2     jsr wrou
         dec kol
         bpl dfg2





         lda aput4
         sta put
         lda aput4+1
         sta put+1
         lda put
         clc
         adc #$80
         sta dst
         lda put+1
         adc #$00
         sta dst+1
         lda aput3
         sta src
         lda aput3+1
         sta src+1

         ldx #$02
klj2     ldy #$00
klj1     lda src
         sta (put),y
         lda src+1
         sta (dst),y
         lda src
         clc
         adc #$10
         sta src
         lda src+1
         adc #$00
         sta src+1
         iny
         bpl klj1
         inc put+1
         inc dst+1
         dex
         bne klj2
         cli
         rts

;---------------------------------------

wrou     ldx kol
         txa
         and #%00000111
         tay
         lda eort,y
         sta teor
         txa
         lsr a
         lsr a
         lsr a
         tax
         lda padf
         clc
         adc dtabl,x
         sta tadd
         lda padf+1
         adc dtabh,x
         sta tadd+1

         ldy #$00
         lda #$b9
         sta (put),y
         iny
         lda tadd
         sta (put),y
         iny
         lda tadd+1
         sta (put),y
         iny
         lda #$49
         sta (put),y
         iny
         lda teor
         sta (put),y
         iny
         lda #$99
         sta (put),y
         iny
         lda tadd
         sta (put),y
         iny
         lda tadd+1
         sta (put),y
         iny
         lda #$8a
         sta (put),y
         iny
         lda #$65
         sta (put),y
         iny
         lda kom1
         sta (put),y
         iny
         lda #$aa
         sta (put),y
         iny
         lda #$98
         sta (put),y
         iny
         lda #$65
         sta (put),y
         iny
         lda kom2
         sta (put),y
         iny
         lda #$a8
         sta (put),y

         lda put
         clc
         adc #$10
         sta put
         lda put+1
         adc #$00
         sta put+1
         rts

;---------------------------------------
;Procedurki
;---------------------------------------

wlda     ldy #$00
         lda #$a9
         sta (put),y
         iny
         lda #$ff
         sta (put),y
         lda put
         clc
         adc #$02
         sta put
         lda put+1
         adc #$00
         sta put+1
         rts

weor     ldy #$00
         lda #$4d
         sta (put),y
         iny
         lda src
         sta (put),y
         iny
         lda src+1
         sta (put),y
         lda put
         clc
         adc #$03
         sta put
         lda put+1
         adc #$00
         sta put+1
         rts

wsta     ldy #$00
         lda #$8d
         sta (put),y
         iny
         lda dst
         sta (put),y
         iny
         lda dst+1
         sta (put),y
         lda put
         clc
         adc #$03
         sta put
         lda put+1
         adc #$00
         sta put+1
         rts

wsta2    ldy #$00
         lda #$8d
         sta (put),y
         iny
         lda src
         sta (put),y
         iny
         lda src+1
         sta (put),y
         lda put
         clc
         adc #$03
         sta put
         lda put+1
         adc #$00
         sta put+1
         rts

;---------------------------------------

pocze    .word $2000,$2080,$2100,$2180
         .word $2200,$2280,$2300,$2380
         .word $2400,$2480,$2500,$2580
         .word $2600,$2680,$2700,$2780

;---------------------------------------

poczs    .word $3000,$3080,$3100,$3180
         .word $3200,$3280,$3300,$3380
         .word $3400,$3480,$3500,$3580
         .word $3600,$3680,$3700,$3780

;---------------------------------------

offs     .byte $00,$00,$00,$00
         .byte $00,$00,$00,$00
         .byte $00,$00,$00,$00
         .byte $00,$00,$00,$00

;---------------------------------------

ile      .byte $80,$80,$80,$80
         .byte $80,$80,$80,$80
         .byte $80,$80,$80,$80
         .byte $80,$80,$80,$80

;---------------------------------------

kol      .byte 0
lin      .byte 0
tadd     .word 0
teor     .byte 0

;---------------------------------------

eort     .byte $80,$40,$20,$10
         .byte $08,$04,$02,$01

;---------------------------------------

dtabl    .byte $00,$80,$00,$80
         .byte $00,$80,$00,$80
         .byte $00,$80,$00,$80
         .byte $00,$80,$00,$80

dtabh    .byte $00,$00,$01,$01
         .byte $02,$02,$03,$03
         .byte $04,$04,$05,$05
         .byte $06,$06,$07,$07

;---------------------------------------

