;:ifpeek(777)<>167then:&x
;:sys36864
	;.opt oo
	*= 49152
; ram-disk simulator by nicki heusler
exec	= 776
strout	= $ab1e
chrget	= 115
chrgot	= chrget+6
temp	= 2
temp2	= 4
fehler	= 42053
stradr	= 34
sign	= "&"
exold	= $a7e7
inter	= $a7ae
setold	= $e453
line	= $3a
flag	= 167
max	= 12
chrout	= $ffd2
ret	= $aad7
fremevl	= $ad9e
frestr	= $b6a3
komma	= $aefd
len	= 168
getx	= 47006
num	= 169
errx	= $a437
axout	= $bdcd
space	= $ab3f
latch	= $cf00
ram	= 48
rom	= 55
konfig	= 1
full	= 181
spalte	= 211
setcr	= 58732
findvar	= $b08b
varadr	= $49
strres	= $b475
para	= $61
getnum	= $ad8a
integer	= $b7f7
int	= 20
	jmp start
l1	.byte "----------"
	.byt 0
	.word $d000,0,0
l2	.byte "----------"
	.byt 0
	.word $d400,0,0
l3	.byte "----------"
	.byt 0
	.word $d800,0,0
l4	.byte "----------"
	.byt 0
	.word $dc00,0,0
l5	.byte "----------"
	.byt 0
	.word $e000,0,0
l6	.byte "----------"
	.byt 0
	.word $e400,0,0
l7	.byte "----------"
	.byt 0
	.word $e800,0,0
l8	.byte "----------"
	.byt 0
	.word $ec00,0,0
l9	.byte "----------"
	.byt 0
	.word $f000,0,0
la	.byte "----------"
	.byt 0
	.word $f400,0,0
lb	.byte "----------"
	.byt 0
	.word $f800,0,0
lc	.byte "----------"
	.byt 0
	.word $fc00,0,0
adradr	.word l1,l2,l3,l4,l5,l6
	.word l7,l8,l9,la,lb,lc
stat	.byte "xdocawlrpsf"
adress	.word exit,dir,open,close,clall,write,loesch,read
	.word pointer,set,format
mess1	.byte "\x93nss ramdisk simulator ok." 
	 .byt 13,0
mess2	.byte "*** good bye ***" 
	 .byt 13,0
mess3	.byte "\x93directory of nss ram disk:" 
	 .byt 13,13,0
mess4	.byte "-- keine files --" 
	 .byt 13,0
mess5	.byte "nr." 
	 .byt 0
mess6	.byte "r:" 
	 .byt 0
err1	.byte "illegal statemenT"
err2	.byte "illegal filenumbeR"
err3	.byte "filename lenghT"
err4	.byte "missing commA"
err5	.byte "missing strinG"
err6	.byte "zerobyte in writestrinG"
err7	.byte "file overfloW"
err8	.byte "read lenght zerO"
start	jsr clall
	lda #< exnew
	ldy #> exnew
	sta exec
	sty exec+1
	lda #< mess1
	ldy #> mess1
	jmp strout
chklen	lda len
	cmp #10
	beq lenok
	lda #< err3
	sta stradr
	lda #> err3
	jmp fehler
lenok	rts
next	jsr chrget
	ldy #adress-stat-1
compare	cmp stat,y
	beq found
	dey
	cpy #255
	bne compare
	lda #< err1
	sta stradr
	lda #> err1
	jmp fehler
exnew	jsr chrget
	cmp #sign
	beq next
	jsr chrgot
	jmp exold
found	tya
	asl
	tax
	lda adress,x
	sta temp
	lda adress+1,x
	sta temp+1
	jsr chrget
	jsr exerc
	jmp inter
exerc	jmp (temp)
exit	jsr setold
	lda #< mess2
	ldy #> mess2
	jmp strout
chkdir	ldx line
	inx
	beq direkt
	pla
	pla
direkt	rts
dirtit	jsr chkdir
	lda #< mess3
	ldy #> mess3
	jmp strout
dir	jsr dirtit
	ldx #0
	stx flag
dirloop	txa
	asl
	tay
	lda adradr,y
	sta temp
	lda adradr+1,y
	sta temp+1
	ldy #10
	lda (temp),y
	beq noopen
	lda #255
	sta flag
	stx temp2
	ldy #> mess5
	lda #< mess5
	jsr strout
	lda #0
	ldx temp2
	jsr axout
	lda #6
	sta spalte
	jsr setcr
	ldy #0
dirloop2	lda (temp),y
	jsr chrout
	iny
	cpy #10
	bne dirloop2
	jsr data
	ldx temp2
noopen	inx
	cpx #max
	bne dirloop
	lda flag
	bne ausgeg
	lda #< mess4
	ldy #> mess4
	jsr strout
ausgeg	rts
return	pha
	txa 
	 pha
	tya 
	 pha
	jsr ret
	pla 
	 tay
	pla 
	 tax
	pla 
	 rts
getstr	jsr chkcom
	jsr fremevl
	jsr frestr
	sta len
	cmp #0
	bne gut
	lda #< err5
	sta stradr
	lda #>err5
	jmp fehler
gut	rts
getnr	jsr chkcom
	jsr getx
	cpx #max
	bcc gut
	lda #< err2
	sta stradr
	lda #> err2
	jmp fehler
open	jsr getnr
	stx num
	jsr getstr 
	 jsr chklen
	ldx num
	txa
	asl
	tay
	lda adradr,y
	sta temp
	lda adradr+1,y
	sta temp+1
	ldy #10
	lda (temp),y
	beq noop
	ldx #2
	jmp errx
noop	lda #1
	sta (temp),y
	ldy #9
copyname	lda (stradr),y
	sta (temp),y
	dey
	bpl copyname
copydata	ldy #11
	lda (temp),y
	ldy #13
	sta (temp),y
	ldy #15
	sta (temp),y
	ldy #12
	lda (temp),y
	ldy #14
	sta (temp),y
	ldy #16
	sta (temp),y
	rts
close	jsr getnr
closx	txa
	asl
	tay
	lda adradr,y
	sta temp
	lda adradr+1,y
	sta temp+1
	ldy #10
	lda #0
	sta (temp),y
	rts
clall	ldx #max-1
cla	jsr closx
	dex
	bpl cla
	rts
chkcom	jsr chrgot
	cmp #","
	beq check
	lda #< err4
	sta stradr
	lda #> err4
	jmp fehler
check	jmp komma
data	jsr space
	ldy #11
	lda (temp),y
	tax
	iny
	lda (temp),y
	jsr axout
	lda #"-"
	jsr chrout
	ldy #13
	lda (temp),y
	tax
	iny
	lda (temp),y
	jsr axout
	lda #29
	sta spalte
	jsr setcr
	lda #<mess6
	ldy #>mess6
	jsr strout
	ldy #15
	lda (temp),y
	tax
	iny
	lda (temp),y
	jsr axout
	jmp flagout
chkopen	txa
	asl
	tay
	lda adradr,y
	sta temp
	lda adradr+1,y
	sta temp+1
	ldy #10
	lda (temp),y
	bne op
	ldx #3
	jmp errx
op	rts
write	jsr getnr
	jsr chkopen
	jsr getstr
	ldy #13
	lda (temp),y
	sta temp2
	iny
	lda (temp),y
	sta temp2+1
	ldy #0
copy1	lda (stradr),y
	beq null
	sta latch,y
	iny
	cpy len
	bne copy1
	lda #0
	sta latch,y
	jmp weiter
null	lda #< err6
	sta stradr
	lda #> err6
	jmp fehler
weiter	ldx #0
	ldy #12
	lda (temp),y
	clc 
	 adc #4
	sta full
	ldy #0
	sei
	lda #ram
	sta konfig
copy2	jsr testover
	lda latch,x
	sta (temp2),y
	inc temp2
	bne noinc
	inc temp2+1
noinc	inx
	cmp #0
	bne copy2
	lda #rom
	sta konfig
	cli
	ldy #13
	lda temp2
	sta (temp),y
	iny
	lda temp2+1
	sta (temp),y
nofull	rts
testover	lda temp2+1
	cmp full
	bne nofull
	lda #rom
	sta konfig
	cli
	lda #< err7
	sta stradr
	lda #> err7
	jmp fehler
loesch	jsr getnr
	jsr chkopen
	ldy #10
	lda #128
	sta (temp),y
	jmp copydata
read	jsr getnr
	jsr chkopen
	jsr chkcom
	jsr getx
	cpx #0
	bne long
	lda #<err8
	sta stradr
	lda #>err8
	jmp fehler
long	txa
	pha
	jsr chkcom
	jsr findvar
	sta varadr
	sty varadr+1
	jsr frestr
	pla
	jsr strres
	ldy #2
store	lda para,y
	sta (varadr),y
	dey
	bpl store
	sei
	lda #ram
	sta konfig
	ldy #12
	lda (temp),y
	clc 
	 adc #4
	sta full
	ldy #15
	lda (temp),y
	sta temp2
	iny
	lda (temp),y
	sta temp2+1
	ldx #0
fetch	jsr testover
	ldy #0
	lda (temp2),y
	sta (para+1),y
	inx
	inc temp2
	bne nin1
	inc temp2+1
nin1	inc para+1
	bne nin2
	inc para+2
nin2	cpx para
	bne fetch
	lda #rom
	sta konfig
	cli
	ldy #15
	lda temp2
	sta (temp),y
	iny
	lda temp2+1
	sta (temp),y
	rts
pointer	jsr getnr
	jsr chkopen
	jsr chkcom
	jsr getnum
	jsr integer
	ldy #15
	lda int
	sta (temp),y
	iny
	lda int+1
	sta (temp),y
	jsr chkcom
	jsr getnum
	jsr integer
	ldy #13
	lda int
	sta (temp),y
	lda int+1
	iny
	sta (temp),y
	rts
set	ldx #max-1
setloop	txa
	asl 
	 tay
	lda adradr,y
	sta temp
	lda adradr+1,y
	sta temp+1
	ldy #10
	lda #255
	sta (temp),y
	dex
	bpl setloop
	rts
flagout	lda #37
	sta spalte
	jsr setcr
	ldy #10
	lda (temp),y
	ldx #"-"
	cmp #255
	bne tstin
	ldx #"*"
ausgeben	txa
	jsr chrout
	jmp nextflag
tstin	cmp #128
	bne ausgeben
	ldx #"i"
	bne ausgeben
nextflag	ldx #"b"
	ldy #12
	lda (temp),y
	clc 
	 adc #4
	sta full
	ldy #14
	lda (temp),y
	cmp full
	bne nofl
	ldx #"f"
	bne ausg
nofl	ldy #12
	cmp (temp),y
	bne ausg
	dey
	lda (temp),y
	ldy #13
	cmp (temp),y
	bne ausg
	ldx #"e"
ausg	txa
	jsr chrout
	jmp return
format	sei
	lda #ram
	sta konfig
	ldx #48
	ldy #0
	sty temp
	lda #208
	sta temp+1
	tya
formloop	sta (temp),y
	iny
	bne formloop
	inc temp+1
	dex
	bne formloop
	lda #rom
	sta konfig
	cli
	ldx #max-1
fl1	txa 
	 asl 
	 tay
	lda adradr,y
	sta temp
	lda adradr+1,y
	sta temp+1
	ldy #10
	lda #0
fl2	sta (temp),y
	dey
	bpl fl2
	ldy #16
fl3	sta (temp),y
	dey
	cpy #12
	bne fl3
	dex
	bpl fl1
	rts
