;:ifpeek(789)<234thensys51203
;:poke650,128
;:sys36864
	;.opt oo
irqvec	=$314
oldirq	=$ea31
vic	=$d000
fa1	=vic+32
fa2	=fa1+1
cia	=$dc0d
imr	=vic+26
irr	=vic+25
ras	=vic+18
con	=ras-1
getx	=$b7f1
clrx	=59903
setcr	=58732
zeile	=214
endirq	=$ea81
puff	=820
pag	=648
tmp	=251
spalte	=211
getkey	=65508
illquan	=$b248
crs1	=204
crs2	=205
crs3	=207
setzeile	=setcr-2
bsout	=$ffd2
calc	=$e9f0
farbram	=$ea24
farb	=$f3
bild	=$d1
mem	=tmp+2
quote	=212
crsr	=646
len	=$d5
nuins	=$d8
komma	=$aefd
getpar	=$e1d4
save	=$ffd8
load	=$ffd5
sad	=$b9
getnam	=$e257
iecin	=$ffa5
status	=$90
sendnam	=$f3d5
fad	=$ba
clsfil	=$f642
talk	=$ffb4
stalk	=$ff96
return	=$aad7
strout	=$ab1e
space	=$ab3f
taste	=198
nct	=$293
ric	=$294
hep	=$295
von	=$296
zeil1	=$297
zeil2	=$298
tmp2	=$299
bis	=$29a
blpos	=$29b
lan	=$29c
seite	=$29d
	*= $c000
	jmp menue
toirqoff	jmp irqoff
	jmp editxy
	jmp savexy
	jmp loadxy
	jmp dir
hell	.byt 1,1,15,7,12,2,11,249
dirte	.byte "\x93\x11inhalt der disk "
puffn	.byte "                 "
ta	.byt 13
	.byte "\x11(taste)"
	.byt 0
se	.byte "seite "
	.byt 0
setras	sei
	lda #100
	sta ras
	lda #0
	sta ric
	lda #2
	sta hep
	lda con
	and #$7f
	sta con
	lda #$81
	sta imr
	lda #<testirq
	ldy #>testirq
seti	sta irqvec
	sty irqvec+1
	cli
	rts
irqoff	sei
	lda #0
	sta imr
	sta fa1
	sta fa2
	lda #<oldirq
	ldy #>oldirq
	bne seti
testirq	lda zeil1
	clc
	adc #8
	sta zeil2
	lda irr
	sta irr
	and #1
	bne ok
	lda cia
	cli
	jsr next
	jmp oldirq
ok	lda ras
	cmp zeil2
	bcs seco
	ldy zeil2
color	lda #0
setp	sta fa1
	sta fa2
	sty ras
	jmp endirq
seco	lda #0
	ldy zeil1
	jmp setp
wel	asl
	asl
	asl
	clc
	adc #49
	rts
such	lda pag
	sta tmp+1
	ldy #0
	sty tmp
	ldx #0
	stx tmp2
sulo	lda (tmp),y
	bne nix
fu	lda #" "
	sta (tmp),y
	txa
	jsr wel
	ldy tmp2
	inc tmp2
	sta puff,y
nix	cmp #42
	bne nix2
	stx erst+1
	lda tmp2
	sta erst2+1
	jmp fu
nix2	ldy #0
	clc
	lda #40
	adc tmp
	sta tmp
	lda tmp+1
	adc #0
	sta tmp+1
	inx
	cpx #25
	bne sulo
	ldx tmp2
	tya
	sta puff,x
	rts
menue	jsr such
	lda puff
	bne ok2
	lda #-1
	sta tmp
ret	jmp toirqoff
ok2	jsr setras
	lda #1
	sta nct
erst	lda #0
	jsr wel
	sta zeil1
erst2	lda #0
	sta tmp
menloop	jsr getkey
	cmp #13
	beq ret
	cmp #"\x11"
	beq down
	cmp #"\x91"
	beq up
	bne menloop
down	inc tmp
	ldx tmp
	lda puff,x
	bne nowel
	ldx #-1
	stx tmp
	bne down
nowel	sta zeil1
	jmp menloop
up	dec tmp
	bpl weirau
	ldx tmp2
	stx tmp
	jmp up
weirau	ldx tmp
	lda puff,x
	jmp nowel
next	dec nct
	bne gut
	lda #4
	sta nct
	ldx hep
	lda ric
	beq vorw
	lda hell,x
	sta color+1
	dec hep
	bpl gut
	inc hep
	inc hep
	jmp tausch
vorw	inc hep
	lda hell,x
	sta color+1
	bpl gut
	dec hep
	dec hep
tausch	lda ric
	eor #-1
	sta ric
gut	rts
homer	lda #0
	sta spalte
	ldy von
	jmp setzeile
downr	ldx zeile
	cpx bis
	bcs fert
	inc zeile
	rts
fert	rts
upr	ldx zeile
	cpx von
	beq fert
	bcc fert
	dec zeile
	rts
sa	lda blpos
	beq nu
	cmp lan
	bcc x
	sec
	sbc lan
	sta blpos
	jmp sa
x	rts
nu	inc blpos
	bne sa
testlen	ldy #38
tl	dey
	beq n
	lda (bild),y
	cmp #" "
	beq tl
	iny
	sty lan
	clc
	rts
n	sec
	rts
calc2	cpx #25
	bcc ocalc
	dex
	jsr calc
	inx
	lda bild
	clc
	adc #40
	sta bild
	lda bild+1
	adc #0
	sta bild+1
	rts
ocalc	jmp calc
editxy	jsr getx
	txa
	bne gt
ill	jmp illquan
gt	cpx #25
	bcs ill
	stx von
	jsr getx
	cpx von
	bcc ill
	cpx #25
	bcs ill
	stx bis
	jsr homer
haupt	lda #0
	sta nuins
	sta quote
	jsr setcr
	lda #0
	sta crs1
gk	jsr getkey
	beq gk
	pha
	lda #2
	sta crs2
waus	lda crs3
	bne waus
	sei
	lda #1
	sta crs1
	cli
	pla
	cmp #"\x85"
	bne nof1
	rts
nof1	cmp #"\x93"
	bne noclr
	ldx von
clrlo	jsr clrx
	inx
	cpx bis
	beq clrlo
	bcc clrlo
	bcs clend
noclr	cmp #"\x13"
	bne nohome
clend	jsr homer
	jmp haupt
nohome	cmp #"\x91"
	bne noup
upaus	jsr upr
	jmp haupt
noup	cmp #"\x11"
	bne nodown
downaus	jsr downr
	jmp haupt
nodown	cmp #13
	bne nocr
craus	lda #0
	sta spalte
	jsr downr
	jmp haupt
nocr	cmp #141
	beq craus
	cmp #"\x9d"
	bne noleft
	ldx spalte
	dex
	bpl nopro
	ldx #38
	stx spalte
	jsr upr
	jmp haupt
nopro	stx spalte
	jmp haupt
noleft	cmp #"\x09"
	bne noinsert
	ldx bis
insloop	cpx zeile
	beq fnsh
	jsr calc
	jsr farbram
	lda bild
	sta tmp
	lda bild+1
	sta tmp+1
	lda farb
	sta mem
	lda farb+1
	sta mem+1
	dex
	jsr calc
	jsr farbram
	ldy #38
inslp2	lda (bild),y
	sta (tmp),y
	lda (farb),y
	sta (mem),y
	dey
	bpl inslp2
	bmi insloop
fnsh	jsr clrx
	jmp haupt
noinsert	cmp #"\x15"
	bne nopfund
	lda bis
	sta zeile
	lda #38
	sta spalte
	jmp haupt
nopfund	cmp #"\x0a"
	bne noroll1
	ldx bis
	lda zeile
	pha
roll1lp	cpx von
	bcc tohaup
	jsr calc
	jsr farbram
	ldy #1
roll1l1	lda (bild),y
	pha
	lda (farb),y
	dey
	sta (farb),y
	pla
	sta (bild),y
	iny
	iny
	cpy #40
	bcc roll1l1
	dex
	jmp roll1lp
tohaup	pla
	sta zeile
	tax
	jsr calc
	jmp haupt
noroll1	cmp #"\x0b"
	bne noroll2
	ldx bis
	lda zeile
	pha
roll2lp	cpx von
	bcc tohaup
	jsr calc
	jsr farbram
	ldy #37
roll2l2	lda (bild),y
	pha
	lda (farb),y
	iny
	sta (farb),y
	pla
	sta (bild),y
	dey
	dey
	bpl roll2l2
	iny
	lda #32
	sta (bild),y
	dex
	jmp roll2lp
noroll2	cmp #"\x94"
	bne noinst
	ldy #38
	jsr farbram
instloop	dey
	lda (bild),y
	pha
	lda (farb),y
	iny
	sta (farb),y
	pla
	sta (bild),y
	dey
	cpy spalte
	bne instloop
	lda #" "
	sta (bild),y
	lda crsr
	sta (farb),y
noakt	jmp haupt
noinst	cmp #"\x04"
	bne nodel
	ldx zeile
delloop	cpx bis
	beq finish
	jsr calc
	jsr farbram
	lda bild
	sta tmp
	lda bild+1
	sta tmp+1
	lda farb
	sta mem
	lda farb+1
	sta mem+1
	inx
	jsr calc
	jsr farbram
	ldy #38
dellp2	lda (bild),y
	sta (tmp),y
	lda (farb),y
	sta (mem),y
	dey
	bpl dellp2
	bmi delloop
finish	jmp fnsh
nodel	cmp #"\x06"
	bne nofill
	jsr farbram
	ldy spalte
	lda (bild),y
	sta fillp2+1
	lda (farb),y
	sta fillf+1
	ldx von
	dex
	lda zeile
	pha
filllp	inx
	jsr calc
	jsr farbram
	ldy #38
fillp2	lda #0
	sta (bild),y
fillf	lda #0
	sta (farb),y
	dey
	bpl fillp2
	cpx bis
	bcc filllp
	jmp tohaup
nofill	cmp #"\x02"
	bne char
	ldx von
	lda zeile
	pha
	lda #20
	sta blpos
blocklp	jsr calc
	jsr farbram
testneu	ldy #38
	lda #" "
	cmp (bild),y
	bne voll
	ldy #0
	cmp (bild),y
	beq voll
	jsr testlen
	bcs voll
	jsr sa
	ldy blpos
suchsp	lda (bild),y
	cmp #" "
	beq found
	iny
	cpy lan
	bcc test2
	ldy #1
test2	cpy blpos
	bne suchsp
	beq voll
found	iny
	sty blpos
	ldy #38
ruk	dey
	lda (bild),y
	pha
	lda (farb),y
	iny
	sta (farb),y
	pla
	sta (bild),y
	dey
	cpy blpos
	bne ruk
	beq temp
voll	inx
	cpx bis
	beq blocklp
	bcc blocklp
	jmp tohaup
temp	lda #" "
	sta (bild),y
	inc blpos
	jmp testneu
char	jsr bsout
	ldx spalte
	cpx #39
	bcc nopanik
	jmp craus
nopanik	jmp haupt
savexy	jsr getx
	stx tmp2
	jsr getx
	txa
	bne gt2
ill2	jmp illquan
gt2	cpx #25
	bcs ill2
	stx von
	jsr getx
	cpx von
	bcc ill2
	cpx #25
	bcs ill2
	inx
	stx bis
	jsr komma
	jsr getpar
	ldx von
	jsr calc
	jsr evtl
	lda bild
	pha
	lda bild+1
	pha
	ldx bis
	jsr calc2
	jsr evtl
	ldx bild
	ldy bild+1
	pla
	sta tmp+1
	pla
	sta tmp
	lda #tmp
	sta sad
	jsr save
	jmp setcr
evtl	lda tmp2
	bne fa
	rts
fa	jsr farbram
	lda farb
	sta bild
	lda farb+1
	sta bild+1
	rts
loadxy	jsr komma
	jsr getpar
	lda #1
	sta sad
	lda #0
	jmp load
dir	jsr komma
	jsr getnam
	lda #0
	sta seite
	jsr getx
	stx tmp2
	lda #8
	sta fad
	lda #$60
	sta sad
	jsr sendnam
	lda fad
	jsr talk
	lda sa
	jsr stalk
	lda #0
	sta status
	jsr iecin
	jsr iecin
	jsr iecin
	jsr iecin
	jsr suchqu
	bcc l2
l3	jmp clsfil
l2	ldx #0
l4	jsr iecin
	cmp #34
	beq l5
	sta puffn,x
	inx
	bne l4
l5	lda #0
	sta puffn,x
	jsr such0
	bcs l3
l6	lda #<dirte
	ldy #>dirte
	jsr strout
	lda #<se
	ldy #>se
	jsr strout
	inc seite
	lda seite
	clc
	adc #"0"
	jsr bsout
	jsr return
l7	jsr skip4
	bcs l3
	jsr return
	jsr space
	jsr suchqu
	bcs l3
	jsr skip
	bcs l3
l8	jsr iecin
	ldy status
	bne l3
	cmp #34
	beq l9
	jsr bsout
	bcc l8
l9	jsr such0
	bcs l3
	lda zeile
	cmp #22
	bcc l7
	lda #<ta
	ldy #>ta
	jsr strout
	lda #0
	sta taste
wat	lda taste
	beq wat
	dec taste
	jmp l6
suchqu	jsr iecin
	ldy status
	bne l1
	cmp #34
	bne suchqu
	clc
	rts
l1	sec
	rts
such0	jsr iecin
	ldy status
	bne l1
	tax
	bne such0
	clc
	rts
skip4	ldx #4
sklp	jsr iecin
	ldy status
	bne l1
	dex
	bne sklp
	clc
	rts
skip	ldx tmp2
	bne sklp
	clc
	rts
