.bank
*=$2000
;-----------------------------chars--------------
chars
.BYTE 068, 017, 068, 017, 068, 017, 068, 017
;.BYTE 068, 017, 068, 017, 068, 017, 068, 017
;.BYTE 068, 017, 068, 017, 068, 017, 068, 017
;.BYTE 068, 017, 068, 017, 068, 017, 068, 017
;.BYTE 068, 017, 068, 017, 068, 017, 068, 017
;.BYTE 068, 017, 068, 017, 068, 017, 068, 017
;.BYTE 068, 017, 068, 017, 068, 017, 068, 017
;.BYTE 068, 017, 068, 017, 068, 017, 068, 017

.BYTE 085, 085, 085, 085, 085, 085, 085, 085
;.BYTE 085, 085, 085, 085, 085, 085, 085, 085
;.BYTE 085, 085, 085, 085, 085, 085, 085, 085
;.BYTE 085, 085, 085, 085, 085, 085, 085, 085
;.BYTE 085, 085, 085, 085, 085, 085, 085, 085
;.BYTE 085, 085, 085, 085, 085, 085, 085, 085
;.BYTE 085, 085, 085, 085, 085, 085, 085, 085
;.BYTE 085, 085, 085, 085, 085, 085, 085, 085

.BYTE 102, 153, 102, 153, 102, 153, 102, 153
;.BYTE 102, 153, 102, 153, 102, 153, 102, 153
;.BYTE 102, 153, 102, 153, 102, 153, 102, 153
;.BYTE 102, 153, 102, 153, 102, 153, 102, 153
;.BYTE 102, 153, 102, 153, 102, 153, 102, 153
;.BYTE 102, 153, 102, 153, 102, 153, 102, 153
;.BYTE 102, 153, 102, 153, 102, 153, 102, 153
;.BYTE 102, 153, 102, 153, 102, 153, 102, 153

.BYTE 034, 136, 034, 136, 034, 136, 034, 136
;.BYTE 034, 136, 034, 136, 034, 136, 034, 136
;.BYTE 034, 136, 034, 136, 034, 136, 034, 136
;.BYTE 034, 136, 034, 136, 034, 136, 034, 136
;.BYTE 034, 136, 034, 136, 034, 136, 034, 136
;.BYTE 034, 136, 034, 136, 034, 136, 034, 136
;.BYTE 034, 136, 034, 136, 034, 136, 034, 136
;.BYTE 034, 136, 034, 136, 034, 136, 034, 136

.BYTE 170, 170, 170, 170, 170, 170, 170, 170
;.BYTE 170, 170, 170, 170, 170, 170, 170, 170
;.BYTE 170, 170, 170, 170, 170, 170, 170, 170
;.BYTE 170, 170, 170, 170, 170, 170, 170, 170
;.BYTE 170, 170, 170, 170, 170, 170, 170, 170
;.BYTE 170, 170, 170, 170, 170, 170, 170, 170
;.BYTE 170, 170, 170, 170, 170, 170, 170, 170
;.BYTE 170, 170, 170, 170, 170, 170, 170, 170

.BYTE 204, 051, 204, 051, 204, 051, 204, 051
;.BYTE 204, 051, 204, 051, 204, 051, 204, 051
;.BYTE 204, 051, 204, 051, 204, 051, 204, 051
;.BYTE 204, 051, 204, 051, 204, 051, 204, 051
;.BYTE 204, 051, 204, 051, 204, 051, 204, 051
;.BYTE 204, 051, 204, 051, 204, 051, 204, 051
;.BYTE 204, 051, 204, 051, 204, 051, 204, 051
;.BYTE 204, 051, 204, 051, 204, 051, 204, 051
;.BYTE 204, 051, 204, 051, 204, 051, 204, 051

.BYTE 255, 255, 255, 255, 255, 255, 255, 255
;.BYTE 255, 255, 255, 255, 255, 255, 255, 255
;.BYTE 255, 255, 255, 255, 255, 255, 255, 255
;.BYTE 255, 255, 255, 255, 255, 255, 255, 255
;.BYTE 255, 255, 255, 255, 255, 255, 255, 255
;.BYTE 255, 255, 255, 255, 255, 255, 255, 255
;.BYTE 255, 255, 255, 255, 255, 255, 255, 255
;.BYTE 255, 255, 255, 255, 255, 255, 255, 255
;.BYTE 255, 255, 255, 255, 255, 255, 255, 255

.BYTE 238, 187, 238, 187, 238, 187, 238, 187
;.BYTE 238, 187, 238, 187, 238, 187, 238, 187
;.BYTE 238, 187, 238, 187, 238, 187, 238, 187
;.BYTE 238, 187, 238, 187, 238, 187, 238, 187
;.BYTE 238, 187, 238, 187, 238, 187, 238, 187
;.BYTE 238, 187, 238, 187, 238, 187, 238, 187
;.BYTE 238, 187, 238, 187, 238, 187, 238, 187
;.BYTE 238, 187, 238, 187, 238, 187, 238, 187
;.BYTE 238, 187, 238, 187, 238, 187, 238, 187

starti
 lda #12 ; open graphics 8 mode (320x200)
 jsr $ef9c ; openmode=$ef9c

;-copy to font
 lda #$10
 sta 756

 lda #$08
 sta $CB
 sta $CC



fo4
 ldy #$00


fo3
 ldx #$00
fo1
 lda chars,x
fo2
 sta $1000,y
 inx
 iny
 cpx #$08
 bne fo1

 dec $CB
 bne fo3

 lda fo1+1
 clc
 adc #$08
 bcc no_h1
 inc fo1+2
no_h1
 sta fo1+1


 lda fo2+1
 clc
 adc #$40
 bcc no_h2
 inc fo2+2
no_h2
 sta fo2+1

 dec $CC
 bne fo4
;--------------------------------------------------------
;setup intvec
SETVBV      = $E45C
 ldx #vbi/256
 ldy #vbi&255
 lda #$06
 jsr SETVBV

;go
ONEL

AUDF1       = $D200
AUDC1       = $D201
; jsr makesnd

RANDOM=$D20A
vmem = $BBA0;BC40 for GR.0, initial for GR.13
buff = $9300;-----------------------------------------??A000
var_e = $E0
adr_l = $E1
adr_h = $E2
var_c = $E3

 lda vars4
 sta var_e
 
 lda RANDOM

 clc
 adc #04
 bcc bra3

 lda RANDOM
 and #03
 tax
 lda vars,x
 sta var_e

bra3

 lda var_e
 sta vars4

 lda vars5
 and #$08
 bne bra4

 lda vars5
 and #$03
 bne bra5

bra4
lda RANDOM
 tay
 lda #0
 sta adr_l

 lda RANDOM
 and #1
 clc
 adc #buff/256
 sta adr_h
 
 lda (adr_l),y
 clc
 adc var_e
 eor (adr_l),y
 and #$38
 eor (adr_l),y
 sta (adr_l),y
;---------------------
bra5   lda RANDOM ; jsr LA53A
		AND #$FE

		php
		lda vars5
		plp
		bne LA5A4
		eor #$08
LA5A4
	clc
	adc #$01
	and #$0B
	sta vars5

 lda #buff/256
 sta adr1+2
 sta adr6+2

 lda #vmem/256
 sta adr2+2
 sta adr3+2
 sta adr4+2 ;?
 sta adr5+2


 lda #4
 sta var_c
check_lp2
 ldy #0

check_lp1
adr1 lda buff,y
 clc
 adc var_e
 and #$38

adr2 cmp vmem+1,y
 beq put

adr3 cmp vmem+40,y
 beq put
 
adr4 cmp vmem-40,y
 beq put

adr5 cmp vmem-1,y
 bne next

put
adr6 sta buff,y

next
 iny
 bne check_lp1

 inc adr1+2
 inc adr2+2
 inc adr3+2
 inc adr4+2
 inc adr5+2
 inc adr6+2

 dec var_c
 bne check_lp2

 ldy #0
copy
 lda buff,y

 sta vmem,y
 
 lda buff+256,y
 sta vmem+256,y

 lda buff+512,y
 sta vmem+512,y

 lda buff+768,y
 sta vmem+768,y
 iny
 bne copy

 jmp ONEL
vars .byte 8,$28,$18,$38

vars4   .byte 0+$16
vars5   .byte 0+1
vars6   .byte 0+8

vbi
 php
 pha
 txa
 pha
; tya
; pha

 jsr makesnd

; pla
; tay
 pla
 tax
 pla
 plp
SYSVBV   =   $E45F
 JMP SYSVBV;rti?


makesnd
            lda #$A2
            sta AUDC1
            ldx var1
slp       lda snddata,X
            bne bra1
            ldx #$00
            stx var1
            beq slp
bra1       adc var3
            sta var3
            sta AUDF1
            lda var2
            beq bra2
            dec var2
            rts
bra2       dec var2
            inc var1
            rts
var1       .byte $00
var2       .byte $00
var3       .byte $00
snddata       .byte $54,$AA,$BB,$CC,$EE,$34,$66,$99
            .byte $64,$CE,$EB,$DD,$44,$00,$02,$37


.bank
            *= $02E0
            .word starti;$2000

