;:rem open1,8,2,"code,p,w
;:sys36864
	*= 49152	;2075
; nicht vergessen, anfmem = $1000
;                  endmem = $d000
	;.opt oo
bsout	=$ffd2
tmp	=2
return	=$aad7
vic	=$d000
cint	=65409
key	=198
crs1	=204
crs2	=205
crs3	=207
get	=65508
setnam	=$ffbd
setpar	=$ffba
open	=$ffc0
close	=$ffc3
fa	=$ba
sa	=$b9
talk	=$ffb4
sectalk	=$ff96
untalk	=$ffab
iecin	=$ffa5
anfmem	=$8000	;    ***
endmem	=$9000	;    ***
axout	=$bdcd
space	=$ab3f
spalte	=211
setcr	=58732
chkin	=$ffc6
clrchn	=$ffcc
clall	=$ffe7
status	=144
tmp2	=tmp+2
konf	=1
chkout	=$ffc9
relanf	=anfmem-95
	jmp run
title	.byte "\x1a\x9a\x93\x19(\xa4\x12\x0e\x08Konverter: TEXTOMAT+ -> VIZAWRITE 64  V3"
	.byte "programmiert von  N. Heusler,  26.2.1987"
	.byte "[c] NIG Software Service NSS 1987 arr   \x1a\x03"
diskt1	.byte "\x05\x1a\x1aQuel"
diskt	.byte "ldiskette einlegen !\x1a\x03"
diskt2	.byte "\x05\x1a\x1aZie\x03"
namtxt	.byte "\x1a\x99Textname ?\x19\x10} T\x19\x10}\x9d\x03"
delt	.byte "\x9d \x9d\x03"
atn	.byte "\x96\x1aDISK ERROR:\x1a\x03"
readt	.byte "\x1a\x9aLese u. vereinfache Zeile \x03"
transt	.byte "\x1a\x1a\x9aWandle Text in BS-Code\x03"
bis	.byte "\x9a\x1a\x1aText geht bis \x03"
headt	.byte "\x1a\x9aHeader wird geschrieben\x1a\x03"
okt	.byte "\x1a\x99OK. Fertig, keine Fehler.\x1a\x03"
tolong	.byte "\x1a\x1a\x96ACHTUNG: Text zu lang !\x1a\x03"
umlt	.byte "\x1a\x1a\x9aUmlaute werden gewandelt\x03"
nunte	.byte "\x1a\x9aText wird gespeichert\x1a\x03"
dub	.byte "\x1a\x99\x1aAbsatzende verdoppeln ? [j/n/_] \x12\x03"
filnam	.byte "                ,p,"
filtyp	brk
flag	brk
zeile	.word 0
ymerk	brk
mspalte	brk
textend	.word 0
dubflag	brk
tab	.byte "_\xa0\xb6\xb2\xbe\xbb\xb5"
	.byt $b0,$ae
tab2	.byte "\xdc []><#()"
longtab	.byte "\xbc\xad\xbd\xb1\xb8\xb4"
	.byt $de,$af,$ac,$a3
adrtab	.word ad1,ad2,ad3,ad4,ad5,ad6,ad7,ad8,ad9,ada
ad1	.byte "(c)\x03"
ad2	.byte "<<\x03"
ad3	.byte ">>\x03"
ad4	.byte "entspricht\x03"
ad5	.byte "ungleich\x03"
ad6	.byte "Herz\x03"
ad7	.byte "Pi\x03"
ad8	.byte "Tel.\x03"
ad9	.byte "Grad\x03"
ada	.byte "*****\x03"
fndtab	.byt $a5,$a1,$a6,$a9,$a8,$aa,$a7
erstab	.byt $65,$76,$78,$79,$7a,$7b,$7c
form1	.byt 87,86,-1,86
form2	.word 0,0,0,0
	.byt 3
form3	.byt $10,$f0,$e
	.byt $60,$60,$60,$60,$60,$60,$60,$60
	.byt $60,$60,$60,$60,$60,$60,$60,$60
	.byte "  \x19"
	.byt 0,6,0,1,0,14,0,1,14,0,2,25,14,32,0,22,96
form4	.byt $dc
	.byte "                                        "
	.byte "                                        "
	.byt $db,32,32,$e6,$f1,32,0
form5	.byt $ff,$f1,32,$f1,32,$f1,32,$dc
strout	tax
	lda tmp
	pha
	lda tmp+1
	pha
	stx tmp
	sty tmp+1
stlop	ldy #0
	lda (tmp),y
	beq fin
	cmp #"\x03"
	beq fin
	cmp #"\x1a"
	bne nocr
	lda #13
nocr	cmp #"\x19"
	beq repeat
	jsr bsout
weiter	inc tmp
	bne stlop
	inc tmp+1
	bne stlop
repeat	iny
	lda (tmp),y
	tax
	iny
	lda (tmp),y
rep	jsr bsout
	dex
	bne rep
	lda tmp
	clc
	adc #3
	sta tmp
	lda tmp+1
	adc #0
	sta tmp+1
	bne stlop
fin	pla
	sta tmp+1
	pla
	sta tmp
	rts
ram	lda #54
	.byt $2c
rom	lda #55
	sta konf
	rts
check	jsr qcheck
	bpl chok
	pla
	pla
	jmp cloall
chok	rts
out2	ldx #2
	jmp chkout
outxa	jsr bsout
	dex
	bne outxa
	rts
setanf	lda #<anfmem
	ldy #>anfmem
	sta tmp
	sty tmp+1
	rts
disk1	lda #<diskt1
	ldy #>diskt1
	jsr strout
	jmp waitkey
disk2	lda #<diskt2
	ldy #>diskt2
	jsr strout
	lda #<diskt
	ldy #>diskt
	jsr strout
waitkey	lda #0
	sta key
wk	lda key
	beq wk
	dec key
	rts
qcheck	lda #8
	sta fa
	jsr talk
	lda #$6f
	sta sa
	jsr sectalk
	jsr iecin
	cmp #"0"
	beq okay
	pha
	lda #<atn
	ldy #>atn
	jsr strout
	pla
	ldx #-1
	.byt $2c
okay	ldx #0
	stx flag
chklop	bit flag
	bpl goon
	jsr bsout
goon	cmp #13
	beq cer
	jsr iecin
	jmp chklop
cer	jsr untalk
	lda flag
	rts
init	jsr cint
	jsr rom
cloall	jsr clrchn
	lda #2
	jsr close
	jmp clall
zeilout	lda mspalte
	sta spalte
	jsr setcr
	ldx zeile
	lda zeile+1
	jsr axout
	jmp space
put2	ldy #0
	sta (tmp),y
	inc tmp
	bne nocy
	inc tmp+1
	lda tmp+1
	cmp #>endmem
	bcc nocy
	lda #<tolong
	ldy #>tolong
	jsr strout
	pla
	pla
	jmp cloall
nocy	rts
put	pha
	jsr put2
	pla
	cmp #"\xdc"
	bne no2
	bit dubflag
	bpl no2
	jsr put2
no2	rts
getby	lda status
	bne wegda
	jmp get
wegda	pla
	pla
	jmp daweiter
wandel	ldx #tab2-tab-1
wand	cmp tab,x
	beq found
	dex
	bpl wand
	ldx #adrtab-longtab-1
wand2	cmp longtab,x
	beq found2
	dex
	bpl wand2
	rts
found	lda tab2,x
	rts
found2	txa
	asl
	tax
	lda adrtab,x
	sta tmp2
	lda adrtab+1,x
	sta tmp2+1
	ldy #0
setlong	lda (tmp2),y
	cmp #"\x03"
	beq endl
	sty ymerk
	jsr put
	ldy ymerk
	iny
	bne setlong
endl	lda tmp
	sec
	sbc #1
	sta tmp
	lda tmp+1
	sbc #0
	sta tmp+1
	ldy #0
	lda (tmp),y
	rts
bsput	lda #<transt
	ldy #>transt
	jsr strout
	jsr setanf
	jsr ram
	ldy #0
codlop	lda tmp+1
	cmp textend+1
	bcc noend
	bne stopit
	lda tmp
	cmp textend
	bcc noend
stopit	jmp rom
noend	lda (tmp),y
	bmi gr127
	cmp #64
	bcs gr64
ink	inc tmp
	bne codlop
	inc tmp+1
	bne codlop
gr64	cmp #96
	bcs ink
	sbc #63
setit	sta (tmp),y
	jmp ink
gr127	cmp #-1
	bne nopi
	lda #$5e
	bne setit
nopi	cmp #192
	bcc ink
	cmp #219
	bcs ink
	sbc #127
	bne setit
umlaute	lda #<umlt
	ldy #>umlt
	jsr strout
	jsr setanf
	jsr ram
	ldy #0
umllop	lda tmp+1
	cmp textend+1
	bcc unoend
	bne stopit
	lda tmp
	cmp textend
	bcs stopit
unoend	lda (tmp),y
	ldx #erstab-fndtab-1
unosuch	cmp fndtab,x
	beq unofund
	dex
	bpl unosuch
nouno	inc tmp
	bne umllop
	inc tmp+1
	bne umllop
unofund	lda erstab,x
	sta (tmp),y
	bne nouno
getdub	lda #<dub
	ldy #>dub
	jsr strout
	lda #0
	sta key
get123	jsr get
	cmp #"_"
	beq esc
	cmp #"j"
	beq ja
	cmp #"n"
	bne get123
	ldx #0
	.byt $2c
ja	ldx #-1
	stx dubflag
	ora #$80
	jmp bsout
esc	jsr bsout
	jsr return
	pla
	pla
	jmp cloall
urput	cmp #$a2
	beq trenn
	jmp put
trenn	rts
run	jsr init
	lda #0
	sta vic+32
	sta vic+33
	lda #<title
	ldy #>title
	jsr strout
	lda #<namtxt
	ldy #>namtxt
	jsr strout
	ldx #0
	stx key
getnam	ldy #0
	sty crs1
	stx tmp
getn	jsr get
	beq getn
	ldy #2
	sty crs2
geta	ldy crs3
	bne geta
	inc crs1
	ldx tmp
	cmp #20
	bne nodel
	txa
	beq getnam
	dex
	stx tmp
	lda #<delt
	ldy #>delt
	jsr strout
	ldx tmp
	jmp getnam
nocrr	cmp #" "
	bcc getnam
	tay
	bpl ok
	cmp #149
	bcc getnam
	cmp #156
	bcc ok
	cmp #160
	bcc getnam
ok	cpx #15
	bcs getnam
	sta filnam,x
	inx
	jsr bsout
	bcc getnam
nodel	cmp #13
	beq cr
	cmp #"\x85"
	beq cr
	cmp #"\x88"
	bne nocrr
	jmp run
cr	cpx #15
	beq sezn
	lda #" "
	sta filnam,x
	inx
	bne cr
sezn	lda #"T"
	sta filnam+15
	lda #20
	ldx #<filnam
	ldy #>filnam
	jsr setnam
	lda #"r"
	sta filtyp
	ldx #8
	ldy #2
	tya
	jsr setpar
	jsr getdub
	jsr disk1
	jsr open
	jsr check
	jsr setanf
	ldx #2
	jsr chkin
	lda #<readt
	ldy #>readt
	jsr strout
	lda spalte
	sta mspalte
	ldx #0
	stx zeile
	stx zeile+1
zeilread	inc zeile
	bne nocy2
	inc zeile+1
nocy2	jsr zeilout
zeillop	jsr getby
	jsr wandel
	jsr urput
	cmp #"\xdc"
	bne zeillop
	beq zeilread
daweiter	jsr cloall
	jsr check
	lda #<bis
	ldy #>bis
	jsr strout
	ldx tmp
	lda tmp+1
	stx textend
	sta textend+1
	jsr axout
	jsr bsput
	jsr umlaute
	jsr disk2
	lda #"v"
	sta filnam+15
	ldx #14
findjok	lda filnam,x
	cmp #"*"
	bne jo1
jo3	lda #"."
	sta filnam,x
	bne jo2
jo1	cmp #"?"
	beq jo3
jo2	dex
	bpl findjok
	lda #"w"
	sta filtyp
	lda #2
	tay
	ldx #8
	jsr setpar
	jsr open
	jsr check
	lda #<headt
	ldy #>headt
	jsr strout
	jsr out2
	ldx #3
trans1	lda form1,x
	jsr bsout
	dex
	bpl trans1
	lda textend
	sec
	sbc #<relanf
	tax
	lda textend+1
	sbc #>relanf
	pha
	txa
	jsr bsout
	pla
	jsr bsout
	ldx #8
trans2	lda form2,x
	jsr bsout
	dex
	bpl trans2
	ldx #0
transn	lda filnam,x
	jsr bsout
	inx
	cpx #16
	bcc transn
	ldx #38
trans3	lda form3,x
	jsr bsout
	dex
	bpl trans3
	ldx #117
	lda #32
	jsr outxa
	lda #0
	jsr bsout
	lda #$aa
	ldx #11
	jsr outxa
	ldx #87
trans4	lda form4,x
	jsr bsout
	dex
	bpl trans4
	jsr clrchn
	lda #<nunte
	ldy #>nunte
	jsr strout
	jsr out2
	jsr setanf
	jsr ram
	ldy #0
cmpend	lda tmp+1
	cmp textend+1
	bcc nixend
	bne jaend
	lda tmp
	cmp textend
	bcs jaend
nixend	lda (tmp),y
	jsr bsout
	inc tmp
	bne cmpend
	inc tmp+1
	bne cmpend
jaend	jsr rom
	ldx #7
trans5	lda form5,x
	jsr bsout
	dex
	bpl trans5
	jsr cloall
	jsr check
	lda #<okt
	ldy #>okt
	jmp strout
