;:sys36864
	;.opt oo
zeichen	=247
map	=209
dreh	=215
spalte	=211
zeile	=214
freg	=213
zaehler	=$b6
buff	=$57
rvs	=199
bank	=$dd00
char	=53272
chrgot	=121
irqvec	=$314
buf	=$c6
get	=$e5b4
ctrl	=$28d
sat1	=55296
sat2	=53248
endirq	=$ea7b
speed	=20
ctr	=$cd
blink	=$cf
updwn	=2
cr	=13
mem	=206
konf	=1
getnx	=$b79b
getkx	=$b7f1
komma	=$aefd
fremevl	=$ad9e
frestr	=$b6a3
stradr	=34
len	=$60
flag	=3
tmp	=4
switch	=53265
page	=648
	*= 49152
	lda char
	pha
	lda switch
	pha
	jsr main
	pla
	sta switch
	pla
	sta char
	rts
main	lda switch
	and #32
	bne gron
	lda #59
	sta switch
	lda #29
	sta char
gron	jsr screen
	lda #0
	sta rvs
	sta freg
	sta dreh
	sta updwn
	sta flag
	clc
home	sta zeile
	sta spalte
	sta map
	php
	lda bank
	and #3
	lsr
	beq zgr1
	lda #$80
zgr1	ror
	eor #$c0
	sta map+1
	lda char
	and #8
	asl
	asl
	ora map+1
	sta map+1
	plp
	bcs setback
	bit flag
	bpl gt
	rts
gt	jsr chrgot
	cmp #","
	bne write
	jmp text
write	jsr umschalt
	lda irqvec
	pha
	lda irqvec+1
	pha
	lda #<irq
	ldy #>irq
	sta irqvec
	sty irqvec+1
setback	cli
	jsr setb
tastatur	lda buf
	beq tastatur
	jsr get
	ldx ctrl
	cpx #4
	bne decode
	jsr control
	jmp setback
control	cmp #"\x1a"
	bne umdreh
	lda updwn
	eor #128
	sta updwn
	rts
umdreh	cmp #"\x15"
	bne frg0
	eor dreh
	sta dreh
	rts
frg0	cmp #"\x1e"
	bne frg1
	lda #128
sx	sta freg
	rts
frg1	cmp #"\x05"
	bne frg2
	lda #64
	bne sx
frg2	cmp #"\x92"
	bne frg3
	lda #0
	beq sx
frg3	cmp #"\x12"
	bne driv
	lda rvs
	eor #128
	sta rvs
	rts
driv	cmp #"\x19"
	bne quit
	lda #64
	eor updwn
	sta updwn
quit	cmp #"\x18"
	bne ctrlend
	sei
	lda mem
	sta (map),y
	pla
	sta irqvec+1
	pla
	sta irqvec
	cli
	rts
ctrlend	rts
decode	ldy #7
	cmp #cr
	bne cr2
crlf	sei
	lda mem
	sta (map),y
	ldx spalte
godown	jsr right
	inx
	cpx #40
	bcc godown
	jmp setback
cr2	cmp #cr+128
	beq crlf
	cmp #"\x13"
	bne nothome
	lda mem
	sta (map),y
	lda #0
	sec
	jmp home
nothome	cmp #"\x93"
	bne notclr
	lda mem
	sta (map),y
	lda #255
	sta flag
	lda #0
	clc
	jsr home
	jmp clear
notclr	cmp #20
	bne notdel
	lda #32
	jsr revoff
	jmp del1
notdel	cmp #"\x9d"
	bne dcd1
del1	jsr left
	jmp setback
dcd1	cmp #"\x1d"
	bne crsrdown
	jsr right
	jmp setback
crsrdown	cmp #"\x11"
	bne crup
	jsr down
	jmp setback
crup	cmp #"\x91"
	bne notcrs
	jsr up
	jmp setback
notcrs	jsr drucken
	jsr richtung
	jmp setback
richtung	ldx dreh
	bne richt1
	jmp right
richt1	bit updwn
	bvs richt2
	jmp up
richt2	jmp down
right	lda zeile
	cmp #24
	bne rgt1
	lda spalte
	cmp #39
	beq rgtend
rgt1	ldy #7
	lda mem
	sta (map),y
	lda map
	clc
	adc #8
	bne rgt2
	inc map+1
rgt2	sta map
	ldy spalte
	iny
	cpy #40
	bne rgt3
	inc zeile
	ldy #0
	sty spalte
rgt3	sty spalte
crsrset	jsr umschalt
	lda #2
	sta ctr
rgtend	rts
left	lda zeile
	bne lft2
	lda spalte
	beq rgtend
lft2	ldy #7
	lda mem
	sta (map),y
	lda map
	sec
	sbc #8
	bcs lft1
	dec map+1
lft1	sta map
	dec spalte
	bpl crsrset
	dec zeile
	lda #39
	sta spalte
	bne crsrset
up	lda zeile
	beq up2
	ldx #40
up1	jsr left
	dex
	bne up1
up2	rts
down	lda zeile
	cmp #24
	beq dw2
	ldx #40
dw1	jsr right
	dex
	bne dw1
dw2	rts
setb	ldx #<sat1
	ldy #>sat1
	bit updwn
	bpl setb1
	ldx #<sat2
	ldy #>sat2
setb1	stx zeichen
	sty zeichen+1
	rts
irq	dec ctr
	bne irqend
	lda #speed
	sta ctr
	lsr blink
	ldy #7
	lda #0
	bcs irq1
	inc blink
	lda #$ff
irq1	sta (map),y
irqend	jmp endirq
umschalt	sei
	lda konf
	pha
	and #%11111100
	sta konf
	ldy #7
	lda (map),y
	sta mem
	pla
	sta konf
	rts
drucken	cmp #$7f
	bcc ausg0
	and #127
	ora #$40
	bne ausg2
ausg0	cmp #$60
	bcc ausg1
	and #$df
	bne ausg2
ausg1	and #$3f
ausg2	asl rvs
	bcc revoff
	ora #128
	ror rvs
revoff	ldy #0
	tax
	beq charen
mal8	lda zeichen
	clc
	adc #8
	sta zeichen
	lda zeichen+1
	adc #0
	sta zeichen+1
	dex
	bne mal8
charen	sei
	lda konf
	pha
	and #251
	sta konf
	ldx dreh
	bne drehen
	ldx zeile
	beq plot2
	bit freg
	bpl plot1
	jsr up
	ldy #0
high1	lda (zeichen),y
	iny
	iny
	iny
	iny
	sta (map),y
	dey
	dey
	dey
	cpy #4
	bne high1
	sta mem
	jsr down
	ldy #4
high2	lda (zeichen),y
	dey
	dey
	dey
	dey
	sta (map),y
	tya
	clc
	adc #5
	tay
	cpy #8
	bne high2
	beq charoff
plot1	bvc plot2
	jsr up
	ldy #0
doub1	tya
	pha
	lda (zeichen),y
	sta mem
	pha
	txa
	tay
	pla
	sta (map),y
	iny
	sta (map),y
	iny
	tya
	tax
	pla
	tay
	iny
	cpy #4
	bcc doub1
	beq doub2
	cpy #8
	bne doub1
	beq charoff
doub2	tya
	pha
	jsr down
	pla
	tay
	jmp doub1
plot2	ldy #0
trans	lda (zeichen),y
	sta (map),y
	iny
	cpy #8
	bne trans
	sta mem
charoff	pla
	sta konf
	rts
drehen	sty freg
dre0	lda (zeichen),y
	sta buff,y
	iny
	cpy #8
	bne dre0
dre1	ldx #7
dre3	pha
	bit updwn
	pla
	bvs ou
	asl buff,x
	ror
	bvc dre2
ou	lsr buff,x
	rol
dre2	dex
	bpl dre3
	dey
	sta (map),y
	bne dre1
	sta mem
	beq charoff
clear	ldx #32
	ldy #0
	sty tmp
	lda map+1
	sta tmp+1
	tya
clr	sta (tmp),y
	iny
	bne clr
	inc tmp+1
	dex
	bne clr
	jmp setback
text	jsr getnx
	dex
	stx zaehler
	beq txt1
lp1	jsr down
	dec zaehler
	bne lp1
txt1	jsr getkx
	dex
	stx zaehler
	beq txt2
lp2	jsr right
	dec zaehler
	bne lp2
txt2	jsr komma
	jsr fremevl
	jsr frestr
	sta len
loop3	jsr setb
	ldy zaehler
	lda (stradr),y
	cmp #" "
	bcs druck
	jsr control
	jmp next
druck	jsr decode
	jsr richtung
next	inc zaehler
	dec len
	bne loop3
	cli
	rts
screen	lda page
	sta tmp+1
	ldy #0
	sty tmp
	ldx #4
	lda #16
flp	sta (tmp),y
	iny
	bne flp
	inc tmp+1
	dex
	bne flp
	rts
