;:sys36864
; screen tool by -nh-240386-
	;.opt oo
	*= $c000
	jmp init
	jmp show
	jmp scroll
jmput	jmp put
	jmp clear
	jmp write
	jmp outset
	jmp frame
	jmp invert
	jmp swap
	jmp save
	jmp load
	jmp replace
	jmp randfill
	jmp nreplace
farbram	=$d800
error	=$a445
stradr	=$22
page	=$288
naxl	=25
naxs	=40
crsr	=$286
chrgot	=121
getky	=65508
axout	=$bdcd
spalte	=211
zeile	=214
setcr	=58732
chkcom	=$aefd
frestr	=$b6a3
out	=$ffd2
frmevl	=$ad9e
toolong	=$a571
illquan	=$b248
konf	=1
getx	=$b7f1
tmp	=247
tmp2	=tmp+2
basic	=$7000
basend	=$a000
getpara	=$e1d4
save64	=$f5ea
load64	=$ffd5
savevon	=$c1
savebis	=$ae
sa	=$b9
latch	=704
fnlen	=$b7
fnadr	=$bb
memory	=$d000
ti	=162
maxl	=96
maxs	=128
screen	.word 0,0,0,0,0
	.word 0,0,0,0,0
	.word 0,0,0,0,0
	.word 0,0,0,0,0
	.word 0,0,0,0,0
lines	.word 0,0,0,0,0,0,0,0
	.word 0,0,0,0,0,0,0,0
	.word 0,0,0,0,0,0,0,0
	.word 0,0,0,0,0,0,0,0
	.word 0,0,0,0,0,0,0,0
	.word 0,0,0,0,0,0,0,0
	.word 0,0,0,0,0,0,0,0
	.word 0,0,0,0,0,0,0,0
	.word 0,0,0,0,0,0,0,0
	.word 0,0,0,0,0,0,0,0
	.word 0,0,0,0,0,0,0,0
	.word 0,0,0,0,0,0,0,0
initflag	.byt 0
ox	.byt 0
oy	.byt 0
mem1	.byt 0
mem2	.byt 0
mem3	.byt 0
konfmerk	.byt 0
writex	.byt 0
writey	.byt 0
setx	.byt 0
sety	.byt 0
outflag	.byt 0
rndm	.byt $ff,$55
rtemp	.byt 0,0
er0	.byte "not initializeD"
er1	.byte "illegal coordinateS"
errt	.word er0,er1
initlines	ldx #0
	ldy #>memory
	stx tmp
	sty tmp+1
z1004	cpx #maxl
	bcs z1014
	txa
	asl
	tay
	lda tmp
	sta lines,y
	clc
	adc #maxs
	sta tmp
	lda tmp+1
	sta lines+1,y
	adc #0
	sta tmp+1
	inx
	bne z1004
z1014	rts
faerbc	ldx crsr
fillx	ldy #<farbram
	lda #>farbram
	sty tmp
	sta tmp+1
	txa
	ldx #4
z1024	sta (tmp),y
	iny
	bne z1024
	inc tmp+1
	dex
	bne z1024
	rts
errx	txa
	asl
	tax
	lda errt,x
	sta stradr
	lda errt+1,x
	jmp error
testinit	ldx initflag
	beq errx
	rts
getkoor	jsr chrgot
	bne getpar
	ldx ox
	ldy oy
	rts
getpar	jsr getx
	txa
	pha
	jsr getx
	cpx #maxs
	bcc z1056
z1054	ldx #1
	bne errx
z1056	pla
	cmp #maxl
	bcs z1054
	tay
z1058	sty oy
	stx ox
	rts
adry	tya
	pha
	asl
	tay
	lda lines,y
	sta tmp
	lda lines+1,y
	sta tmp+1
	pla
	tay
	rts
initscreen	ldx #0
	ldy page
	stx tmp
	sty tmp+1
z1074	cpx #naxl
	bcs z1084
	txa
	asl
	tay
	lda tmp
	sta screen,y
	clc
	adc #naxs
	sta tmp
	lda tmp+1
	sta screen+1,y
	adc #0
	sta tmp+1
	inx
	bne z1074
z1084	rts
scry	tya
	pha
	asl
	tay
	lda screen,y
	sta tmp2
	lda screen+1,y
	sta tmp2+1
	pla
	tay
	rts
testko	cpx #maxs-naxs+1
	bcc z1104
z1102	jmp z1054
z1104	cpy #maxl-naxl+1
	bcs z1102
	rts
ram	lda konf
	sta konfmerk
	sei
	lda #48
	sta konf
	rts
rom	lda konfmerk
	sta konf
	cli
	rts
getkey	txa
	pha
	tya
	pha
	jsr getky
	sta mem1
	pla
	tay
	pla
	tax
	lda mem1
z1045	rts
koordout	lda outflag
	beq z1045
	stx mem1
	sty mem2
	lda #32
	sta $426
	sta $421
	lda #0
	sta zeile
	lda #32
	sta spalte
	jsr setcr
	ldx mem1
	lda #0
	jsr axout
	lda #37
	sta spalte
	jsr setcr
	ldx mem2
	lda #0
	jsr axout
	ldx mem1
	ldy mem2
	rts
showxy	jsr ram
	sty oy
	stx ox
	sty mem1
	ldy #0
z1204	jsr scry
	sty mem2
	ldy mem1
	jsr adry
	ldy #0
	ldx ox
z1210	cpy #naxs
	bcs z1218
	sty mem3
	txa
	tay
	lda (tmp),y
	pha
	ldy mem3
	pla
	sta (tmp2),y
	inx
	iny
	jmp z1210
z1218	inc mem1
	ldy mem2
	iny
	cpy #naxl
	bcc z1204
	jsr rom
	jsr faerbc
	ldy oy
	ldx ox
	jmp koordout
putxy	jsr ram
	sty mem1
	ldy #0
	stx ox
z1304	jsr scry
	sty mem2
	ldy mem1
	jsr adry
	ldy #0
	ldx ox
z1310	cpy #naxs
	bcs z1318
	lda (tmp2),y
	pha
	sty mem3
	txa
	tay
	pla
	sta (tmp),y
	ldy mem3
	inx
	iny
	jmp z1310
z1318	inc mem1
	ldy mem2
	iny
	cpy #naxl
	bcc z1304
	jmp rom
swap	jsr ram
	ldx #48
	ldy #0
	sty tmp
	sty tmp2
	lda #>memory
	sta tmp+1
	lda #>basic
	sta tmp2+1
z1408	lda (tmp),y
	pha
	lda (tmp2),y
	sta (tmp),y
	pla
	sta (tmp2),y
	iny
	bne z1408
	inc tmp2+1
	inc tmp+1
	dex
	bne z1408
	jmp rom
setnam	ldy #0
z1502	cpy fnlen
	bcs z1508
	lda (fnadr),y
	sta latch,y
	iny
	bne z1502
z1508	lda #<latch
	ldy #>latch
	sta fnadr
	sty fnadr+1
	rts
random	lda rndm
	sta rtemp
	eor rndm+1
	ror rtemp+1
	ror
	adc ti
	ror rtemp+1
	sta rndm
	lda rtemp
	sta rndm+1
	inc rndm+1
	dec rndm
	cmp #128
	bcc z1620
	ror
	eor rndm
	dec rndm
	rts
z1620	asl
	eor rndm+1
	sbc rtemp+1
	rts
init	jsr initlines
	jsr initscreen
	lda #55
	sta konf
	sta konfmerk
	lda #0
	sta ox
	sta oy
	sta outflag
	lda #-1
	sta initflag
	rts
show	jsr testinit
	jsr getkoor
	jsr testko
	jmp showxy
scroll	jsr testinit
	jsr getkoor
	jsr testko
z2024	jsr showxy
z2026	jsr getkey
	beq z2026
	cmp #13
	bne z2032
	rts
z2032	cmp #"\x11"
	bne z2038
	cpy #maxl-naxl
	bcs z2026
	iny
	bne z2024
z2038	cmp #"\x1d"
	bne z2044
	cpx #maxs-naxs
	bcs z2026
	inx
	bne z2024
z2044	cmp #"\x91"
	bne z2050
	cpy #0
	beq z2026
	dey
	jmp z2024
z2050	cmp #"\x9d"
	bne z2056
	cpx #0
	beq z2026
	dex
	jmp z2024
z2056	cmp #"\x13"
	bne z2058
	ldx #0
	ldy #0
	beq z2024
z2058	cmp #"\x93"
	bne z2026
	ldx #88
	ldy #71
	bne z2024
put	jsr testinit
	jsr getkoor
	jsr testko
	jmp putxy
clear	jsr testinit
	ldy #<memory
	lda #>memory
	sty tmp
	sta tmp+1
	ldx #32
	jsr chrgot
	beq z2078
	jsr getx
z2078	jsr ram
	txa
	ldx #48
z2080	sta (tmp),y
	iny
	bne z2080
	inc tmp+1
	dex
	bne z2080
	jmp rom
write	jsr testinit
	jsr chkcom
	jsr frmevl
	jsr frestr
	pha
	lda stradr
	pha
	lda stradr+1
	pha
	jsr getkoor
	lda #0
	sta writex
	sta writey
	lda #maxl-naxl
	sta sety
	lda #maxs-naxs
	sta setx
	cpy #maxl-naxl
	bcc z2116
	tya
	sec
	sbc #maxl-naxl
	sta writey
	jmp z2118
z2116	sty sety
z2118	cpx #maxs-naxs
	bcc z2124
	txa
	sec
	sbc #maxs-naxs
	sta writex
	jmp z2126
z2124	stx setx
z2126	ldx setx
	ldy sety
	jsr showxy
	lda writex
	sta spalte
	lda writey
	sta zeile
	jsr setcr
	pla
	sta stradr+1
	pla
	sta stradr
	pla
	sta mem1
	ldy #0
z2134	cpy mem1
	bcs z2142
	lda (stradr),y
	jsr out
	lda spalte
	iny
	cmp #40
	bcc z2134
	jmp toolong
z2142	lda setx
	sta ox
	lda sety
	sta oy
	jmp jmput
outset	jsr getx
	stx outflag
	rts
frame	jsr testinit
	ldx #1
	jsr chrgot
	beq z2206
	jsr getx
	cpx #maxl
	bcc z2206
	jmp illquan
z2206	stx mem1
	ldx #160
	jsr chrgot
	beq z2210
	jsr getx
z2210	stx mem2
	jsr ram
	ldy #0
z2212	sty mem3
	jsr adry
	ldy #maxs-1
	lda mem2
z2216	sta (tmp),y
	dey
	bpl z2216
	ldy mem3
	iny
	cpy mem1
	bcc z2212
	ldy #0
z2222	iny
	sty mem3
	jsr adry
	ldy #0
	lda mem2
z2226	sta (tmp),y
	iny
	cpy mem1
	bcc z2226
	lda #maxs
	sec
	sbc mem1
	tay
	lda mem2
z2234	sta (tmp),y
	iny
	cpy #maxs
	bcc z2234
	ldy mem3
	cpy #maxl-2
	bcc z2222
	lda #maxl
	sec
	sbc mem1
	tay
z2242	sty mem3
	jsr adry
	ldy #maxs-1
	lda mem2
z2246	sta (tmp),y
	dey
	bpl z2246
	ldy mem3
	iny
	cpy #maxl
	bcc z2242
	jmp rom
invert	jsr testinit
	ldy #<memory
	lda #>memory
	sty tmp
	sta tmp+1
	ldx #128
	jsr chrgot
	beq z2308
	jsr getx
z2308	jsr ram
	stx mem1
	ldx #48
z2310	lda (tmp),y
	eor mem1
	sta (tmp),y
	iny
	bne z2310
	inc tmp+1
	dex
	bne z2310
	jmp rom
save	jsr chkcom
	jsr getpara
	jsr setnam
	lda #<basic
	ldy #>basic
	sta savevon
	sty savevon+1
	ldy #>basend
	sty savebis+1
	sta savebis
	lda #1
	sta sa
	jsr swap
	jsr save64
	jmp swap
load	jsr chkcom
	jsr getpara
	jsr setnam
	jsr swap
	ldx #<basic
	ldy #>basic
	lda #0
	sta sa
	jsr load64
	jmp swap
replace	jsr testinit
	jsr getx
	stx mem1
	jsr getx
	stx mem2
	jsr ram
	ldy #<memory
	lda #>memory
	sty tmp
	sta tmp+1
	ldx #48
z2612	lda (tmp),y
	cmp mem1
	bne z2618
	lda mem2
	sta (tmp),y
z2618	iny
	bne z2612
	inc tmp+1
	dex
	bne z2612
	jmp rom
randfill	jsr testinit
	ldy #<memory
	lda #>memory
	sty tmp
	sta tmp+1
	txa
	ldx #48
z2708	jsr rom
	jsr random
	pha
	jsr ram
	pla
	sta (tmp),y
	iny
	bne z2708
	inc tmp+1
	dex
	bne z2708
	jmp rom
nreplace	jsr testinit
	jsr getx
	stx mem1
	jsr getx
	stx mem2
	jsr ram
	ldy #<memory
	lda #>memory
	sty tmp
	sta tmp+1
	ldx #48
z2812	lda (tmp),y
	cmp mem1
	beq z2818
	lda mem2
	sta (tmp),y
z2818	iny
	bne z2812
	inc tmp+1
	dex
	bne z2812
	jmp rom
