;:poke56,128:clr
;:sys36864
	;.opt oo
	*= $8000
vic	=$d000
raster	=vic+18
irr	=vic+25
imr	=vic+26
irqvec	=$314
irqalt	=$ea31
cia1	=$dc00
irqrun	=cia1+$d
vicctrl	=vic+17
zeile1	=167
zeile2	=235
irqend	=$ea81
vicinit	=65409
tmp	=247
tmp2	=tmp+2
konf	=1
return	=$aad7
bsout	=$ffd2
setcr	=58732
spalte	=211
tab	=10
zeile	=214
axout	=$bdcd
space	=$ab3f
getin	=65508
ioinit	=$ff84
sel	=vic+21
spx	=vic
spy	=vic+1
sph	=vic+16
cr	=13
spmem	=704
spptr	=$7f8
tmp3	=tmp2+2
repeat	=650
tmp4	=2
page	=648
crs1	=204
crs2	=205
crs3	=207
normset	=$3800
rom1	=$f61b
rom2	=$f620
rom3	=$f4f1
iectmp	=4
message	=$f5d2
loadr	=$ffd5
saver	=$ffd8
setpar	=$ffba
buffer	=normset+$800
setnam	=$ffbd
mode	=157
floppy	=8
clrx	=59903
dirstr	=$50c
normend	=normset+$800
lastline	=$7c0
chkin	=$ffc6
clrchn	=$ffcc
ayfac	=$b391
facasc	=$bddf
zahl	=$100
close	=$ffc3
open	=$ffc0
stat	=$90
plot	=$fff0
rvs	=199
quote	=$d4
fa	=$ba
sa	=$b9
talk	=$ffb4
listen	=$ffb1
sectalk	=$ff96
seclist	=$ff93
unlist	=$ffae
untalk	=$ffab
key	=198
iecin	=$ffa5
iecout	=$ffa8
farbpos	=$da58
anfang	jmp init
hello	.byte "\x1a\x13\x05\x08\x19\x05 NSS Charactertransporter V 1."
	.byte "0\x9b\x1a\x1aCommands: (press uppercase)\x1a\x19\x08\xa3\x1a"
	.byte "Invert\x18Load\x18Save\x18Quit\x18mirror X\x18mirror"
	.byte " Y\x18inV. half\x18Test\x18lFt marg.\x18Rgt. mrg.\x18rOm set 0"
	.byte "\x18Clear\x18Prepare\x18Work area\x18rotAte\x18rEstart\x18cataloG"
	.byte "\x18Disk cmd\x18iNfo\x18sHow area"
	brk
st1	.byte "\x90\x13\x19\x0c\x11\x11left margin: "
	brk
st2	.byte " \x18  right margin: "
	brk
st3	.byte "\x90\x17\x13\x19\x18\x11\x18working with $"
	brk
invite	.byte "\x93nss chartransposer - test    (\x12f1\x92 = ende)"
	brk
name	.byte "\x90\x17\x13\x19\x18\x11\x18filename: "
	brk
cmd	.byte "\x90\x17\x13\x19\x18\x11>"
	brk
stm	.byte "\x17\x13\x19\x18\x11"
	brk
info	.byte "\x93NSS chartransposer - INFO"
	.byte "\x1a\x11With this program, you can adapt your"
	.byte "\x1afont files, e.g. made by 'ULTRAFONT'."
	.byte "\x1a\x11Programmed by Nikolaus Heusler 280986"
	.byte "\x1aCopyright by NIG Software Service NSS"
	.byte "\x1a\x11When  loading  or saving,  the screen"
	.byte "\x1amay flare.            (Press any key)"
	brk
hextext	.byte "0123456789abcdef"
grbit	.byt 1,2,4,8,$10,$20,$40,$80
dirsgn	.byt "$"
ca	.byt >normset
rastset	.byt 31,23
left	.byt 0
right	.byt 0
irqmode	.byt 0
romtype	.byt 0
max	.byt 0
irqinit	sei
	lda #zeile1
	sta raster
	lda vicctrl
	and #$7f
	sta vicctrl
	lda #$81
	sta imr
	lda #0
	sta irqmode
	lda #<testirq
	ldy #>testirq
setirq	sta irqvec
	sty irqvec+1
	cli
	rts
irqaus	sei
	lda #0
	sta imr
	lda rastset+1
	sta vic+24
	lda #<irqalt
	ldy #>irqalt
	bne setirq
testirq	lda irr
	sta irr
	and #1
	bne ok
	lda irqrun
	cli
	jmp irqcont
ok	lda raster
	cmp #zeile2
	bcs deux
	ldy #zeile2
	ldx #0
back	sty raster
	lda rastset,x
	sta vic+24
	jmp irqend
deux	ldy #zeile1
	ldx #1
	bne back
irqcont	lda irqmode
	bne toac
	sta sel
	jmp irqalt
toac	jsr action
	jmp irqalt
action	tax
	bmi toright
	lda left
	jmp leri
toright	lda right
leri	ldx #1
	stx sel
	pha
	lsr
	lsr
	lsr
	lsr
	lsr
	asl
	asl
	asl
	clc
	adc #169
	sta spy
	pla
	and #31
	asl
	asl
	asl
	clc
	adc #55
	sta spx
	bcc n0
	lda #1
	.byt $2c
n0	lda #0
	sta sph
	rts
farbset	pha
	ldx #4
	ldy #0
	sty tmp
	lda #$d8
	sta tmp+1
	pla
loop1	sta (tmp),y
	iny
	bne loop1
	inc tmp+1
	dex
	bne loop1
	rts
chart	jsr fillin
	jsr chartadr
	lda #88
	sta tmp
	ldx #7
	lda #0
	sta tmp2
loop2	ldy #4
loop3	lda tmp2
	sta (tmp),y
	inc tmp2
	iny
	cpy #36
	bcc loop3
	lda #32
	lda tmp
	clc
	adc #40
	sta tmp
	bcc loop4
	inc tmp+1
loop4	dex
	bpl loop2
	bmi sprite
chartadr	lda page
	clc
	adc #2
	sta tmp+1
	rts
fillin	jsr chartadr
	ldy #0
	sty tmp
	ldx #2
	lda #32
loop6	sta (tmp),y
	iny
	bne loop6
	inc tmp+1
	dex
	bne loop6
	rts
sprite	lda #11
	sta spptr
	ldy #63
	lda #0
slp2	sta spmem,y
	dey
	bne slp2
	lda #-1
	sta spmem
	lda #$80
	sta spmem+1
	ldx #8
	ldy #1
slp1	iny
	iny
	lda #$80
	sta spmem,y
	iny
	sta spmem,y
	dex
	bne slp1
	pha
	lda #255
	iny
	iny
	sta spmem,y
	iny
	pla
	sta spmem,y
	rts
test	jsr irqaus
	lda rastset
	sta vic+24
	lda #<invite
	ldy #>invite
	jsr strout
gk1	lda #0
	sta crs1
gk2	jsr getin
	beq gk2
	ldx #2
	stx crs2
gk3	ldx crs3
	bne gk3
	inc crs1
	cmp #"\x85"
	beq title
	jsr bsout
	bcc gk1
title	jsr cint
	jsr color
	jsr irqinit
	lda #0
	jsr farbset
	jsr chart
	jsr rommatch
	lda #<hello
	ldy #>hello
	jsr strout
	jsr status
	jmp status2
color	lda #11
	sta vic+33
	sta vic+32
	rts
clrlast	ldx #24
	jmp clrx
rom	lda konf
	pha
	sei
	lda #51
	sta konf
	jsr calcrom
	ldy #0
	sty tmp
	sty tmp2
	ldx #8
roro	lda #0
	sta tmp+1
	lda #>normset
	sta tmp2+1
loop5	lda (tmp),y
	sta (tmp2),y
	iny
	bne loop5
	inc tmp+1
	inc tmp2+1
	dex
	bne loop5
	pla
	sta konf
	cli
	rts
calcrom	lda romtype
	eor #8
	sta romtype
	clc
	adc #>vic
	sta roro+1
	jmp status3
status3	lda romtype
	lsr
	lsr
	lsr
	clc
	adc #"0"
	sta dirstr
	rts
strout	tax
	lda tmp
	pha
	lda tmp+1
	pha
	stx tmp
	sty tmp+1
loop7	ldy #0
	lda (tmp),y
	bne goon
	pla
	sta tmp+1
	pla
	sta tmp
	rts
goon	cmp #"\x19"
	bne norep
	iny
	lda (tmp),y
	tax
	iny
	lda (tmp),y
loop8	dex
	bmi loop9
	jsr bsout
	bcc loop8
loop9	lda tmp
	clc
	adc #2
	sta tmp
	bcc loopa
	inc tmp+1
loopa	inc tmp
	bne loop7
	inc tmp+1
	bne loop7
norep	cmp #"\x1a"
	bne nocrlf
	jsr return
	jmp loopa
nocrlf	cmp #"\x18"
	bne loope
	lda spalte
	sec
loopb	sbc #tab
	bcs loopb
	eor #-1
	adc #1
	clc
	adc spalte
loopc	cmp #40
	bcc loopd
	inc zeile
	sec
	sbc #40
	jmp loopc
loopd	sta spalte
	jsr setcr
	jmp loopa
loope	cmp #"\x17"
	bne einfach
	jsr clrlast
	jmp loopa
einfach	jsr bsout
	bcc loopa
parinit	ldx #0
	stx romtype
	stx left
	stx mode
	dex
	stx right
	stx repeat
	rts
xout	lda #0
	jmp axout
status	lda #<st1
	ldy #>st1
	jsr strout
	ldx left
	jsr xout
	lda #<st2
	ldy #>st2
	jsr strout
	ldx right
	jsr xout
	jmp space
status2	lda #<st3
	ldy #>st3
	jsr strout
	jsr hiadr2
	jsr hexout
	lda tmp
hexout	pha
	lsr
	lsr
	lsr
	lsr
	jsr hex1
	pla
hex1	and #15
	tax
	lda hextext,x
	jmp bsout
cint	jsr ioinit
	jmp vicinit
hiadr2	lda #0
	sta tmp
	lda ca
	sta tmp+1
	rts
adrx	txa
	pha
	jsr hiadr
	lda #0
	sta tmp2
	pla
	asl
	rol tmp2
	asl
	rol tmp2
	asl
	rol tmp2
	clc
	adc tmp
	sta tmp
	lda tmp+1
	adc tmp2
	sta tmp+1
	rts
hiadr	lda #0
	sta tmp
	lda #>normset
	sta tmp+1
	rts
rommatch	ldy #0
	sty tmp
	lda #224
	jsr copyrom
	lda #160
	jsr copyrom
	lda #iectmp
	sta rom1
	lda #iectmp+1
	sta rom2
	lda #<here
	ldy #>here
	sta rom3
	sty rom3+1
	lda #53
	sta konf
	rts
copyrom	sta tmp+1
	ldx #32
copirom	lda (tmp),y
	sta (tmp),y
	iny
	bne copirom
	inc tmp+1
	dex
	bpl copirom
	rts
here	jsr message
	pha
	lda $ae
	sta iectmp
	lda $af
	sta iectmp+1
	lda #>normset
	sta $af
	lda #<normset
	sta $ae
	pla
	rts
inform	sty max
	ldy #0
fi1	lda #0
	sta crs1
	sty tmp
fi2	jsr getin
	and #127
	beq fi2
	ldx #2
	stx crs2
fi3	ldx crs3
	bne fi3
	inc crs1
	ldy tmp
	cmp #20
	bne fi4
	tya
	beq fi1
	dey
	lda #20
	jsr bsout
	bcc fi1
fi4	cmp #13
	beq fi5
	cpy max
	bcs fi1
	cmp #32
	bcc fi1
	jsr bsout
	sta buffer,y
	iny
	bne fi1
fi5	rts
filename	lda #<name
	ldy #>name
	jsr strout
	ldy #16
	jsr inform
	tya
	beq fi6
	ldx #<buffer
	ldy #>buffer
	jsr setnam
	clc
	rts
fi6	sec
	rts
diskcmd	lda #<cmd
	ldy #>cmd
	jsr strout
	ldy #30
	jsr inform
	lda #0
	sta buffer,y
	lda #floppy
	sta fa
	jsr listen
	lda #$6f
	sta sa
	jsr seclist
	ldy #0
di1	lda buffer,y
	beq di2
	jsr iecout
	iny
	bne di1
di2	jsr unlist
	lda #0
	sta stat
	lda #<stm
	ldy #>stm
	jsr strout
	lda #floppy
	sta fa
	jsr talk
	lda #$6f
	sta sa
	jsr sectalk
di3	jsr iecin
	bit stat
	bvs di4
	jsr bsout
	bcc di3
di4	jsr untalk
waitkey	lda #0
	sta key
wk	lda key
	beq wk
	dec key
	rts
shift	jsr wait
	ldy #0
sh1	iny
	lda lastline,y
	pha
	lda lastline+$d400,y
	dey
	sta lastline+$d400,y
	pla
	sta lastline,y
	iny
	cpy #39
	bcc sh1
	lda #" "
	sta lastline,y
	rts
in1	ldx #1
	jmp chkin
st	ldx stat
	beq st0
	sec
	rts
st0	clc
	rts
cat	lda #1
	ldx #<dirsgn
	ldy #>dirsgn
	jsr setnam
	ldx #floppy
	ldy #0
	jsr setpar
	jsr open
	bcs derr
	jsr in1
	jsr st
	bcs derr
	jsr getin
	jsr st
	bcs derr
	jsr getin
dir5	jsr getin
	jsr getin
	beq derr
	jsr getin
	
	pha
	jsr getin
	tax
	pla
	tay
	txa
	jsr ayfac
	jsr facasc
	dey
dir1	lda zahl,y
	beq dir2
	sta buffer,y
	iny
	bne dir1
dir2	lda #" "
	sta buffer,y
	iny
dir3	sty tmp
	jsr getin
	ldy tmp
	tax
	beq dir4
	sta buffer,y
	iny
	bne dir3
dir4	lda #0
	sta buffer,y
	jsr ausgabe
	jsr taste
	bcs derr
	jmp dir5
derr	jsr clrchn
	lda #1
	jsr close
	jmp waitkey
ausgabe	ldx #10
	jsr scrollh
	ldy #0
ausg1	sty tmp
	jsr goto
	ldy tmp
	lda buffer,y
	beq ausg2
	jsr bsout
	jsr shift
	ldy tmp
	iny
	bne ausg1
ausg2	ldx #0
	stx rvs
	stx quote
	ldx #4
scrollh	jsr shift
	dex
	bne scrollh
	rts
goto	ldx #24
	ldy #38
	clc
	jmp plot
wait	stx tmp2
	ldy #-1
	ldx #30
wa	dey
	bne wa
	dex
	bne wa
	ldx tmp2
	rts
taste	jsr clrchn
	jsr getin
	cmp #" "
	beq spac
	cmp #"\x03"
	beq stop
weiter	jmp in1
stop	sec
	rts
spac	jsr getin
	cmp #"\x03"
	beq stop
	cmp #" "
	bne spac
	beq weiter
init	jsr parinit
	jsr title
gk	jsr getin
	beq gk
	and #127
	cmp #"q"
	bne no1
	jsr irqaus
	lda #55
	sta konf
	jmp cint
no1	cmp #"f"
	bne no2
	lda #1
	sta irqmode
lm1	jsr status
	jsr getin
	cmp #cr
	bne nno1
off	lda #0
	sta irqmode
	beq gk
nno1	cmp #"\x11"
	bne nno2
	lda left
	beq lm1
	dec left
	jmp lm1
nno2	cmp #"\x1d"
	bne lm1
	lda left
	cmp right
	bcs lm1
	inc left
	bne lm1
no2	cmp #"r"
	bne no3
	lda #-1
	sta irqmode
lm2	jsr status
	jsr getin
	cmp #cr
	beq off
	cmp #"\x1d"
	bne nno3
	lda right
	cmp #-1
	beq lm2
	inc right
	bne lm2
nno3	cmp #"\x11"
	bne lm2
	lda right
	cmp left
	beq lm2
	dec right
	jmp lm2
no3	cmp #"i"
	bne no4
	ldx left
	dex
ilp1	inx
	stx tmp3
	jsr adrx
	ldy #7
ilp2	lda (tmp),y
	eor #-1
	sta (tmp),y
	dey
	bpl ilp2
	ldx tmp3
	cpx right
	bcc ilp1
	jmp gk
no4	cmp #"o"
	bne no5
	jsr rom
	jmp gk
no5	cmp #"x"
	bne no6
	ldx left
	dex
ilp3	inx
	stx tmp3
	jsr adrx
	ldy #7
ilp4	sty tmp3+1
	lda (tmp),y
	sta tmp2
	ldx #0
	stx tmp2+1
	ldy #7
ilp5	lda tmp2
	and grbit,x
	beq ilp6
	lda tmp2+1
	ora grbit,y
	sta tmp2+1
ilp6	inx
	dey
	bpl ilp5
	lda tmp2+1
	ldy tmp3+1
	sta (tmp),y
	dey
	bpl ilp4
	ldx tmp3
	cpx right
	bcc ilp3
	jmp gk
no6	cmp #"c"
	bne no7
	ldx left
	dex
ilp7	inx
	stx tmp3
	jsr adrx
	ldy #7
	lda #0
ilp8	sta (tmp),y
	dey
	bpl ilp8
	ldx tmp3
	cpx right
	bcc ilp7
	jmp gk
no7	cmp #"y"
	bne no8
	ldx left
	dex
ilp9	inx
	stx tmp3
	jsr adrx
	ldy #3
	sty tmp4
	ldy #4
	sty tmp4+1
ilpa	jsr copty
	inc tmp4+1
	dec tmp4
	bpl ilpa
	ldx tmp3
	cpx right
	bne ilp9
	jmp gk
copty	ldy tmp4
	lda (tmp),y
	pha
	ldy tmp4+1
	lda (tmp),y
	ldy tmp4
	sta (tmp),y
	ldy tmp4+1
	pla
	sta (tmp),y
	rts
no8	cmp #"v"
	bne no9
	jsr hiadr
	lda tmp+1
	clc
	adc #4
	sta tmp2+1
	lda tmp
	sta tmp2
	ldy #0
	ldx #3
ivv	lda (tmp),y
	eor #-1
	sta (tmp2),y
	iny
	bne ivv
	inc tmp+1
	inc tmp2+1
	dex
	bpl ivv
	jmp gk
no9	cmp #"t"
	bne noa
	jsr test
	jmp gk
noa	cmp #"p"
	bne nob
	ldx left
	dex
pre1	inx
	stx tmp3
	jsr adrx
	ldy #7
pre2	lda (tmp),y
	sta tmp2
	lda #%11
	jsr multi
	lda #%1100
	jsr multi
	lda #%110000
	jsr multi
	lda #%11000000
	jsr multi
	lda tmp2
	sta (tmp),y
	dey
	bpl pre2
	ldx tmp3
	cpx right
	bne pre1
	jmp gk
multi	tax
	and tmp2
	beq pre3
	txa
	ora tmp2
	sta tmp2
pre3	rts
nob	cmp #"l"
	bne noc
	jsr filename
	bcc wahr
	jsr status2
	jmp gk
wahr	ldx #floppy
	ldy #1
	jsr setpar
	lda #0
	jsr loadr
	lda iectmp+1
	sta ca
	jsr status2
	jmp gk
noc	cmp #"w"
	bne nod
	lda ca
	clc
	adc #8
	sta ca
	jsr status2
	jmp gk
nod	cmp #"a"
	bne noe
	ldx left
	dex
rot1	inx
	stx tmp3
	jsr adrx
	jsr rotate
	ldx tmp3
	cpx right
	bne rot1
	jmp gk
rotate	ldy #7
rot2	lda (tmp),y
	sta buffer,y
	dey
	bpl rot2
	ldy #7
rot3	lda #0
	sta tmp2
	ldx #0
rot4	asl buffer,x
	rol tmp2
	inx
	cpx #8
	bcc rot4
	lda tmp2
	sta (tmp),y
	dey
	bpl rot3
	rts
noe	cmp #"s"
	bne nof
	jsr filename
	bcc doit
	jsr status2
	jmp gk
doit	ldx #floppy
	ldy #1
	jsr setpar
	ldx #0
	stx tmp
	stx iectmp
	lda ca
	sta iectmp+1
	ldy #>normend
	lda #>normset
	sta tmp+1
	lda #tmp
	jsr saver
	jsr status2
	jmp gk
nof	cmp #"e"
	bne noh
	jmp anfang
noh	cmp #"g"
	bne noi
	jsr irqaus
	jsr cat
	jsr irqinit
	jsr status2
	jmp gk
noi	cmp #"d"
	bne noj
	jsr diskcmd
	jsr status2
	jmp gk
noj	cmp #"n"
	bne nok
	jsr irqaus
	lda #<info
	ldy #>info
	jsr strout
	jsr waitkey
	jsr title
	jmp gk
nok	cmp #"h"
	bne nol
	lda #0
	jsr farbset
	ldx left
	dex
so1	inx
	stx tmp3
	jsr sadr
	ldy #0
	lda #12
	sta (tmp),y
	ldx tmp3
	cpx right
	bcc so1
nol	jmp gk
sadr	txa
	ldx #0
sa1	cmp #32
	bcc sa2
	sec
	sbc #32
	inx
	bne sa1
sa2	pha
	lda #<farbpos
	ldy #>farbpos
	sta tmp
	sty tmp+1
sa3	txa
	beq sa4
	lda tmp
	clc
	adc #40
	sta tmp
	lda tmp+1
	adc #0
	sta tmp+1
	dex
	bne sa3
sa4	pla
	clc
	adc tmp
	php
	clc
	adc #4
	sta tmp
	lda tmp+1
	adc #0
	plp
	adc #0
	sta tmp+1
	rts
	.end
poke56,56
	clr
