;:sys36864
	;.opt oo
	*= $c000
prg	=247
roml	=249
romh	=57
prgz	=59
daprg	=158
end	=828
zahl	=71
bast	=$800
strout	=$ab1e
konf	=1
numout	=$bdcd
mem	=$a000
trem	=143
adi	=2
ko	=73
qu	=61
pos	=62
tgoto	=137
tgosub	=141
tthen	=167
bau	=256
ct	=74
zwi	=57
iv	=788
key	=198
buf	=631
kb1	=$dc00
kb2	=$dc01
dirm	=157
quot	=212
inst	=$d8
	jmp sleep
	lda #<jop
	ldy #>jop
	jsr strout
	jsr run
	lda #0
	sta key
	rts
run	lda bast+2
	bne drin
	lda #<nawo
	ldy #>nawo
	jmp strout
drin	lda #<len1
	ldy #>len1
	jsr lenout
	sei
	lda #48
	sta konf
	lda #<bast
	ldy #>bast
	sta prg
	sty prg+1
	lda #0
	ldy #>mem
	sta roml
	sty roml+1
	ldy #-1
	sty romh
	sty romh+1
	iny
	sty $fffd
	sty $fffe
	sty $ffff
	sty mem+1
l051	lda (prg),y
	beq linanf
	jsr sub1
	jmp l051
linanf	iny
	lda (prg),y
	bne neulin
	iny
	lda (prg),y
	beq prgend
neulin	lda prg
	sta daprg
	lda prg+1
	sta daprg+1
	jsr sub1
	jsr sub1
	jsr sub1
	jsr sub1
	jsr sub1
	ldy #0
l096	lda (prg),y
	beq l116
	cmp #trem
	beq remfund
	iny
	bne l096
remfund	tya
	bne morerem
	jmp killrem
morerem	dey
l116	tya
	tax
	ldy #0
	lda daprg
	sta (roml),y
	jsr sub2
	lda daprg+1
	sta (roml),y
	jsr sub2
	txa
	sta (roml),y
	jsr sub2
	clc
	adc prg
	sta prg
	bcc l051
	inc prg+1
	bne l051
prgend	jsr sub1
	jsr sub1
	jsr sub1
	lda 45
	cmp prg
	bne faut
	lda 46
	cmp prg+1
	beq endprg
faut	lda #55
	sta konf
	cli
	lda #<fautt
	ldy #>fautt
	jmp strout
endprg	lda roml
	sta end
	lda roml+1
	sta end+1
	lda mem+1
	bne wasdrin
	lda #55
	sta konf
	lda #<outprg
	ldy #>outprg
	jmp strout
wasdrin	lda #<bast
	ldy #>bast
	sta prg
	sty prg+1
	ldy #0
	lda #>mem
	sty roml
	sta roml+1
l192	lda (roml),y
	sta daprg
	jsr sub2
	lda (roml),y
	sta daprg+1
	jsr sub2
	lda (roml),y
	tax
	inx
	inx
	inx
	inx
	inx
	jsr sub2
	stx adi
copyrein	lda (daprg),y
	sta (prg),y
	iny
	cpy adi
	bne copyrein
	ldy #0
	jsr sub1
	lda prg
	sta daprg
	lda prg+1
	sta daprg+1
	txa
	clc
	adc daprg
	sta daprg
	bcc noik
	inc daprg+1
noik	lda daprg
	sta (prg),y
	lda daprg+1
	jsr sub1
	sta (prg),y
	dex
	dex
	txa
	clc
	adc prg
	sta prg
	bcc noik2
	inc prg+1
noik2	lda roml
	cmp end
	bne l192
	lda roml+1
	cmp end+1
	bne l192
	ldy #0
	tya
	sta (prg),y
	jsr sub1
	sta (prg),y
	jsr sub1
	sta (prg),y
	jsr sub1
	lda prg
	sta 45
	sta 47
	sta 49
	lda prg+1
	sta 46
	sta 48
	sta 50
	ldy #0
	sty prg
	sty end
	lda #>bast
	sta prg+1
	sta end+1
	sty qu
	sty ko
l520	ldy #0
	lda (prg),y
	tax
	bne l563
	lda prg
	sta end
	lda prg+1
	sta end+1
	jsr sub1
	jsr sub1
	lda (prg),y
	bne xl600
	lda #55
	sta konf
	cli
	lda #<len2
	ldy #>len2
	jmp lenout
xl600	sty qu
	sty ko
	jsr sub1
	jsr sub1
l557	jsr sub1
	jmp l520
l563	cpx #34
	bne noqu
	lda #1
	eor qu
	sta qu
noqu	lda qu
	bne l557
	cpx #tgoto
	beq goto
	cpx #tgosub
	beq goto
	cpx #tthen
	beq goto
	lda ko
	beq l557
	cpx #44
	bne l557
goto	jsr sub1
	lda (prg),y
	cmp #32
	beq goto
	cmp #"0"
	bcc l557
	cmp #"9"+1
	bcs l557
	jsr readdigit
	sty pos
	lda (prg),y
	cmp #44
	beq setdir
	lda #0
setdir	sta ko
	ldy #-1
	sty romh
	sty romh+1
	iny
l656	lda (romh),y
	bne l683
	jsr sub4
	lda (romh),y
	bne l680
	jsr sub4
	lda (romh),y
	bne l677
	jmp l520
l677	jsr sub6
l680	jsr sub6
l683	lda (romh),y
	cmp zahl+1
	bne l701
	jsr sub4
	lda (romh),y
	cmp zahl
	bne l704
	beq l716
l701	jsr sub4
l704	jsr sub4
	jsr sub4
	jsr sub4
	jmp l656
l716	jsr sub4
	jsr sub4
	lda (romh),y
	tax
	jsr sub6
	lda (romh),y
	ldy #55
	sty konf
	sta $62
	stx $63
	ldx #144
	sec
	jsr $bc49
	jsr $bddf
	sei
	ldy #48
	sty konf
	ldy #0
l749	lda bau,y
	beq l758
	iny
	bne l749
l758	tya
	sec
	sbc pos
	sta ct
	inc ct
l766	ldy #0
	dec ct
	beq l778
	jsr shift
	jmp l766
l778	ldy #0
l780	lda bau,y
	beq l791
	sta (prg),y
	iny
	bne l780
l791	jmp l520
sub1	inc prg
	bne rt
	inc prg+1
rt	rts
sub2	inc roml
	bne rt
	inc roml+1
	rts
sub3	lda prgz
	bne lab1
	dec prgz+1
lab1	dec prgz
	rts
sub4	lda romh
	bne lab2
	dec romh+1
lab2	dec romh
	rts
sub5	inc prgz
	bne rt
	inc prgz+1
	rts
sub6	inc romh
	bne rt
	inc romh+1
	rts
lenout	jsr strout
	lda 45
	sec
	sbc 43
	tax
	lda 46
	sbc 44
	jsr numout
	lda #<len3
	ldy #>len3
	jmp strout
killrem	lda prg
	sta prgz
	lda prg+1
	sta prgz+1
	jsr sub3
	lda (prgz),y
	sta (romh),y
	jsr sub3
	jsr sub4
	lda (prgz),y
	sta (romh),y
	jsr sub4
l368	jsr sub5
l371	jsr sub5
	lda (prgz),y
	bne l371
	jsr sub5
	jsr sub5
	lda (prgz),y
	bne l397
	jsr sub6
	jsr sub6
	jmp l430
l397	ldy #3
	lda (prgz),y
	ldy #0
	cmp #trem
	beq l457
	jsr sub5
	jsr sub5
	lda (prgz),y
	sta (romh),y
	jsr sub3
	jsr sub4
	lda (prgz),y
	sta (romh),y
	jsr sub4
l430	lda #0
	sta (romh),y
	jsr sub4
	lda #0
	sta (romh),y
	jsr sub4
	lda #0
	sta (romh),y
	jsr sub6
	jsr sub6
	jmp l051
l457	jsr sub5
	jmp l368
readdigit	ldy #0
	sty zahl
	sty zahl+1
l800	lda (prg),y
	sec
	sbc #"0"
	clc
	adc zahl
	sta zahl
	bcc l816
	inc zahl+1
l816	iny
	lda (prg),y
	sec
	sbc #"0"
	cmp #10
	bcc l827
	rts
l827	lda zahl
	sta zwi
	lda zahl+1
	sta zwi+1
	asl zwi
	rol zwi+1
	asl zwi
	rol zwi+1
	asl zwi
	rol zwi+1
	asl zahl
	rol zahl+1
	clc
	lda zwi
	adc zahl
	sta zahl
	lda zwi+1
	adc zahl+1
	sta zahl+1
	jmp l800
shift	lda prg
	sta prgz
	lda prg+1
	sta prgz+1
l879	ldy #0
	lda (45),y
	iny
	sta (45),y
	lda 45
	cmp prgz
	bne l901
	lda 46
	cmp prgz+1
	beq l907
l901	lda 45
	bne l007
	dec 46
l007	dec 45
	jmp l879
l907	lda end
	sta prgz
	lda end+1
	sta prgz+1
l917	ldy #0
l919	lda (prgz),y
	beq l929
	jsr sub5
	jmp l919
l929	ldy #2
	lda (prgz),y
	beq l975
	ldy #1
	lda (prgz),y
	tax
	inx
	txa
	sta (prgz),y
	bne l957
	iny
	lda (prgz),y
	tax
	inx
	txa
	sta (prgz),y
l957	jsr sub5
	jsr sub5
	jsr sub5
	jsr sub5
	jsr sub5
	jmp l917
l975	jsr sub5
	jsr sub5
	jsr sub5
	lda prgz
	sta 45
	sta 47
	sta 49
	lda prgz+1
	sta 46
	sta 48
	sta 50
	rts
nawo	.byte "kein basicprogramm im speicher !"
	.byt 13,0
len1	.byte "programmlaenge alt: "
	brk
len2	.byte "               neu: "
	brk
len3	.byte " bytes"
	.byt 13,0
outprg	.byte "programm bestand nur aus rem-zeilen."
	.byt 13
	.byte "bitte 'new' eingeben !"
	.byt 13,0
fautt	.byte "zeigerstand 45/46 falsch: vorher renew"
	.byt 13
	.byte "ausfuehren !"
	.byt 13,0
sleep	sei
	lda #>neuirq
	cmp iv+1
	beq sat1
	ldx iv
	ldy iv+1
	stx oldirq
	sty oldirq+1
	sta iv+1
	lda #<neuirq
	sta iv
sat1	cli
	lda #<on
	ldy #>on
	jmp strout
oldirq	.word 0
systxt	.byt 141
	.byte "sY49155"
	.byt 13
on	.byte "\xb0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xae"
	.byt 13
	.byte "\xddrem-killer++ installiert\xdd"
	.byt 13
	.byte "\xddstart mit <shift/shift> \xdd"
	.byt 13
	.byte "\xddvon nikolaus heusler '90\xdd"
	.byt 13
	.byte "\xad\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xbd"
	.byt 13,0
neuirq	lda #0
	cmp dirm
	beq nokey
	cmp quot
	bne nokey
	cmp inst
	bne nokey
	sta kb1
	lda kb2
	cmp #-1
	beq nokey
	lda #%11111101
	sta kb1
	lda kb2
	cmp #%01111111
	bne nokey
	lda #%10111111
	sta kb1
	lda kb2
	cmp #%11101111
	bne nokey
	ldx #9
	stx key
	dex
transkey	lda systxt,x
	sta buf,x
	dex
	bpl transkey
nokey	lda #$7f
	sta kb1
	jmp (oldirq)
jop	.byte "\x91\xb0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xae"
	.byt 13
	.byte "\xddrem-killer aktiv\xdd"
	.byt 13
	.byte "\xad\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xbd\x11"
	.byt 13,0
