;---------------------------------------
;extended disassembly program for c+/4
;source code for plus-4 turbo-assembler
;written by ferenc turoczi (c)1993.
;all rights reserved (r)1993.
;---------------------------------------
;
         *= $1001
;
         .byte $0b,$10,$c9,$07,$9e
         .text "4109"
         .byte 0,0,0
;
ujstar   jmp start
;
kezdh    = $d1
kezdl    = $d0
;
vegh     = $d3
vegl     = $d2
;
pch      = $d5
pcl      = $d4
;
pch2     = $d7
pcl2     = $d6
;
excuth   = $d9
excutl   = $d8
;
relugh   = $db
relugl   = $da
;
illcod   = $dc
kepiro   = $dd
;
addmhi   = $de
addmlo   = $df
;
kezpuf   = $e0
vegpuf   = $e4
;
szmpuf   = $e8
;
opctb1
         .text "bocsnoaspoaanoas"
         .text "bocsnoasconsnoas"
         .text "jacrbarrparabarr"
         .text "bacrnarrsanrnarr"
         .text "recsnelspelljels"
         .text "becsnelscensnels"
         .text "racrnarrparrjarr"
         .text "bacrnarrsanrnarr"
         .text "nsnsssssdntxssss"
         .text "bscssssststsssss"
         .text "lllllllltltlllll"
         .text "blclllllcltlllll"
         .text "ccndccddicdsccdd"
         .text "bccdncddccndncdd"
         .text "csnicsiiisnscsii"
         .text "bscinsiissninsii"
;
opctb2
         .text "rrrl2rslhrsn3rsl"
         .text "prrl2rsllrol3rsl"
         .text "snrlinollnoninol"
         .text "mnrl2nolenol3nol"
         .text "torr2osrhossmosr"
         .text "vorr2osrloor3osr"
         .text "tdrr2dorldoomdor"
         .text "vdrr2doredor3dor"
         .text "2t2atttae2xattta"
         .text "ctratttaytxaataa"
         .text "dddadddaadaaddda"
         .text "cdradddaldssddda"
         .text "pm2cpmecnmebpmec"
         .text "nmrc2meclmoc3mec"
         .text "pb2spbnsnbocpbns"
         .text "ebrs2bnsebos3bns"
;
opctb3
         .text "kaaoaalopaleaalo"
         .text "labobalocaaobalo"
         .text "rdcntdlnpdlftdln"
         .text "iddncdlncdbncdln"
         .text "ireedrrearraprre"
         .text "crfeerreircedrre"
         .text "scgdfcrdacrspcrd"
         .text "schdgcrdicddecrd"
         .text "haixyaxxyjaayaxx"
         .text "caixyaxxaassdada"
         .text "yaxxyaxxyaxxyaxx"
         .text "sajxyaxxvaxpyaxx"
         .text "ypkpypcpypxxypcp"
         .text "epkplpcpdpepfpcp"
         .text "xcmcxcccxcpbxccc"
         .text "qclcncccdcfcgccc"
;
opctyp
         .text "  ***  *   **  *"
         .text "  ***  *  ***  *"
         .text "  **   *   *   *"
         .text "  ***  *  ***  *"
         .text "  ***  *   *   *"
         .text "  ***  *  ***  *"
         .text "  ***  *   *   *"
         .text "  ***  *  ***  *"
         .text "* **   * * *   *"
         .text "  **   *   ** **"
         .text "   *   *   *   *"
         .text "  **   *   *   *"
         .text "  **   *   *   *"
         .text "  ***  *  ***  *"
         .text "  **   *   *   *"
         .text "  ***  *  ***  *"
;
cimmod
         .byte $01,$09,$01,$09
         .byte $05,$05,$05,$05
         .byte $01,$04,$02,$04
         .byte $0a,$0a,$0a,$0a
         .byte $03,$08,$01,$08
         .byte $05,$07,$07,$07
         .byte $01,$0b,$01,$0b
         .byte $0a,$0c,$0c,$0c
         .byte $0a,$09,$01,$09
         .byte $05,$05,$05,$05
         .byte $01,$04,$02,$04
         .byte $0a,$0a,$0a,$0a
         .byte $03,$08,$01,$08
         .byte $05,$07,$07,$07
         .byte $01,$0b,$01,$0b
         .byte $0a,$0c,$0c,$0c
         .byte $01,$09,$01,$09
         .byte $05,$05,$05,$05
         .byte $01,$04,$02,$04
         .byte $0a,$0a,$0a,$0a
         .byte $03,$08,$01,$08
         .byte $05,$07,$07,$07
         .byte $01,$0b,$01,$0b
         .byte $0a,$0c,$0c,$0c
         .byte $01,$09,$01,$09
         .byte $05,$05,$05,$05
         .byte $01,$04,$02,$04
         .byte $0d,$0a,$0a,$0a
         .byte $03,$08,$01,$08
         .byte $05,$07,$07,$07
         .byte $01,$0b,$01,$0b
         .byte $0a,$0c,$0c,$0c
         .byte $05,$09,$05,$09
         .byte $05,$05,$05,$05
         .byte $01,$05,$01,$04
         .byte $0a,$0a,$0a,$0a
         .byte $03,$08,$01,$08
         .byte $07,$07,$06,$06
         .byte $01,$0b,$01,$0b
         .byte $0c,$0c,$0b,$0b
         .byte $04,$09,$04,$09
         .byte $05,$05,$05,$05
         .byte $01,$04,$01,$04
         .byte $0a,$0a,$0a,$0a
         .byte $03,$08,$01,$08
         .byte $07,$07,$06,$06
         .byte $01,$0b,$01,$0c
         .byte $0c,$0c,$0b,$0b
         .byte $04,$09,$05,$09
         .byte $05,$05,$05,$05
         .byte $01,$04,$01,$04
         .byte $0a,$0a,$0a,$0a
         .byte $03,$08,$01,$08
         .byte $05,$07,$07,$07
         .byte $01,$0b,$01,$0b
         .byte $0a,$0c,$0c,$0c
         .byte $04,$09,$05,$09
         .byte $05,$05,$05,$05
         .byte $01,$04,$01,$04
         .byte $0a,$0a,$0a,$0a
         .byte $03,$08,$01,$08
         .byte $05,$07,$07,$07
         .byte $01,$0b,$01,$0b
         .byte $0a,$0c,$0c,$0c
;
select   sei
         jsr stnwrt
         .text " (y/n) : "
         .byte 0
selrea   sei
         jsr $ff9f
         cmp #$59 ; "y"
         beq selkey
         cmp #$4e ; "n"
         beq selkey
         lda #$00
         sta $ef
         beq selrea
selkey   pha
         jsr scrwrt
         lda #$00
         sta $ef
         pla
         and #%00000001 ; y=1 n=0
         rts
;
keslel   php
         pha
         txa
         pha
         tya
         pha
         ldx #$80
kesle1   ldy #$00
kesle2   iny
         dey
         iny
         bne kesle2
         inx
         dex
         inx
         bne kesle1
         pla
         tay
         pla
         tax
         pla
         plp
         rts
;
hataro   lda #$3b
         jsr kiir
         ldx #$1a
hatar2   lda #$2a
         jsr kiir
         dex
         bpl hatar2
         rts
;
pntwrt   lda #$2e ; "."
         bne kiir
krdwrt   lda #$3f ; "?"
         bne kiir
crwrt    lda #$0d ; cr
         bne kiir
spcwrt   lda #$20 ; " "
         bne kiir
dolwrt   lda #$24 ; "$"
         bne kiir
heswrt   lda #$23 ; "#"
         bne kiir
kzjel    lda #$28 ; "("
         bne kiir
vzjel    lda #$29 ; ")"
         bne kiir
yregwr   lda #$2c ; ","
         jsr kiir
         lda #$59 ; "y"
         bne kiir
xregwr   lda #$2c ; ","
         jsr kiir
         lda #$58 ; "x"
kiir     pha
         sei
         jsr $ffd2
         lda $90
         and #%00000011
         bne filerr
         pla
         ldy kepiro
         cpy #$00
         beq nemiro
         sei
scrwrt
eofjel   cmp #$1a
         beq eofugr
         jmp $ff4c
nemiro   sta $ff19
eofugr   rts
;
kiir2    sty excuth
         stx excutl
         jsr kiir
         ldy excuth
         ldx excutl
         rts
;
stnnov   inc excutl
         bne stnno2
         inc excuth
stnno2   rts
;
stnwrt   pla
         sta excutl
         pla
         sta excuth
         jsr stnnov
         tya
         pha
         txa
         pha
stnwr2   ldy #$00
         php
         sei
         sta $ff3f
         lda (excutl),y
         sta $ff3e
         plp
         cmp #$00
         beq stnwr3
         jsr scrwrt
         jsr stnnov
         jmp stnwr2
stnwr3   jsr stnnov
         pla
         tax
         pla
         tay
         jmp (excutl)
;
filerr   sei
         cld
         ldx #$ff
         txs
         jmp errabr
;
exesel   tay
         tax
         lda opctyp,x
         cmp illcod
         beq illkod
         lda cimmod,x
exsel3   tax
         dex
         lda codtbh,x
         sta excuth
         lda codtbl,x
         sta excutl
         tya
         jmp (excutl)
;
illkod   jmp ill
;
codtbh
         .byte >imp
         .byte >acc
         .byte >rel
         .byte >bt
         .byte >zp
         .byte >zpy
         .byte >zpx
         .byte >zpindy
         .byte >zpindx
         .byte >abs
         .byte >absy
         .byte >absx
         .byte >absind
;
codtbl
         .byte <imp
         .byte <acc
         .byte <rel
         .byte <bt
         .byte <zp
         .byte <zpy
         .byte <zpx
         .byte <zpindy
         .byte <zpindx
         .byte <abs
         .byte <absy
         .byte <absx
         .byte <absind
;
filnam   .text "@:"
filkez   .text "????"
         .text "-"
filveg   .text "????"
filext   .text ".???mon"
         .text ",s,w"
;
fasthd   .byte $40,$00,$02,$1c,$06
         .text "w-m"
;
blkstp   .byte $0f,$08,$01,$00,$69
         .text "w-m"
;
dosini   .text ":0i"
;
start    sei
         cld
         ldx #$00
         stx addmhi
         stx addmlo
         sta $ff3e,x
         sta $fdd0,x
         stx $fb
         dex
         txs
         jsr $ff8a
         jsr $8117
         jsr $ff81
         jsr $ff84
         jsr $f39c
         lda #$ff
         sta $ff0c
         sta $ff0d
         sta $07f8
         sta $07f9
         sta $fd10
         sta $fd11
         sta $fd12
         sta $fd13
         lda #$00
         sta $053b
         lda #$40
         sta $0540
         jsr maimnu
         lda kepiro
         cmp #$00
         bne dosstr
         lda #$0b
         sta $ff06
         bne dosstr
;
doswww   lda #$00
         sta $90
         lda #$08
         jsr $ffb1
         lda $90
         bne dosww
         lda #$6f
         jsr $ff93
         lda $90
         bne dosww
         ldx #$07
         rts
;
dosww    jmp dvcnot
;
dosw     lda #$08
         jmp $ffae
;
dosstr   jsr doswww
fasth1   lda fasthd,x
         jsr $ffa8
         dex
         bpl fasth1
         jsr dosw
;
         jsr doswww
blkst1   lda blkstp,x
         jsr $ffa8
         dex
         bpl blkst1
         jsr dosw
;
         jsr doswww
         ldx #$02
dosin1   lda dosini,x
         jsr $ffa8
         dex
         bpl dosin1
         jsr dosw
         jsr starti
;
         jsr stnwrt
         .byte $0d,$0d
         .text "writing file "
         .byte 0
         ldx nevdb+1
         dex
         ldy #$00
nevkep   lda filnam,y
         jsr scrwrt
         iny
         dex
         bpl nevkep
         lda #$0d
         jsr scrwrt
;
         lda #$00
         sta $90
         lda #$02
         ldx #$08
         tay
         jsr $ffba
nevdb    lda #$16
         ldx #<filnam
         ldy #>filnam
         jsr $ffbd
         jsr $ffc0
         ldx #$02
         jsr $ffc9
         jsr crwrt
         jsr hataro
         jsr crwrt
         lda #$44 ; "d"
         jsr kiir
         jsr spcwrt
         ldy #$03
         ldx #$00
kezpww   lda kezpuf,x
         jsr kiir2
         inx
         dey
         bpl kezpww
         jsr spcwrt
         ldy #$03
         ldx #$00
vegpww   lda vegpuf,x
         jsr kiir2
         inx
         dey
         bpl vegpww
         jmp vanopc
;
starti   lda kezdh
         sta pch
         lda kezdl
         sta pcl
;
         lda kezdh
         clc
         adc addmhi
         jsr hexasc
         sta filkez
         stx filkez+1
;
         lda kezdl
         clc
         adc addmlo
         jsr hexasc
         sta filkez+2
         stx filkez+3
;
         lda vegh
         clc
         adc addmhi
         jsr hexasc
         sta filveg
         stx filveg+1
;
         lda vegl
         clc
         adc addmlo
         jsr hexasc
         sta filveg+2
         stx filveg+3
         rts
;
vanop1   ldy #$00
         lda pch
         sta pch2
         lda pcl
         sta pcl2
         jsr pcread
         jsr exesel
anykey   nop
anyke2   lda #$00
         jsr keymtx
         cmp #$ff
         beq anyke2
         rts
;
vanopc   jsr vanop1
         sec
         lda vegl
;******************************
;cmp pcl ;akkor a sec nem kell!
;******************************
         sbc pcl
         lda vegh
         sbc pch
         bcs vanopc ; ha kisebb
kelett   bit vanop1
         jsr crwrt
         jsr hataro
         jsr crwrt
         lda eofjel+1
         jsr kiir
         lda #$0d
         jsr kiir
errabr   jsr $ffcc
         lda #$02
         jsr $ffc3
         lda #$0d
         jsr scrwrt
         lda #$00
         sta $90
         lda #$08
         jsr $ffb4
         lda $90
         bne drstcl
         lda #$6f
         jsr $ff96
drstat   jsr $ffa5
         jsr scrwrt
         lda $90
         and #$40
         beq drstat
drstcl   lda #$08
         jsr $ffab
         jmp statdl
dvcnot   lda #$08
         pha
         jsr $ffab
         pla
         jsr $ffae
         jsr $ffe7
         jsr stnwrt
         .byte $0d
         .text "device not present"
         .text " error drive : 8"
         .byte 0
statdl   lda #$00
         sta $90
         lda #$0d
         jsr scrwrt
         lda #$09
         jsr kiir
         lda #$1b
         sta $ff06
         lda #$6e
         sta $ff19
         lda #$80
         sta $0540
         lda #$00
         sta $053b
         sta $ef
         sei
         cld
         ldx #$00
         sta $ff3e,x
         sta $fdd0,x
         stx $fb
         dex
         txs
         jsr $ff8a
         jsr $8117
         clv
         clc
         cli
         jmp $8703
;
hexasc   clc
         pha ; hexcod
         jsr hexas1
         tax ; x=low
         pla ; a=high
         lsr a
         lsr a
         lsr a
         lsr a
hexas1   and #$0f
         cmp #$0a
         bcc hexas2
         adc #$06
hexas2   adc #$30
         clc
         rts
;
hexwr2   ldy #$02
         jsr hexwww
hexwr1   ldy #$01
         jmp hexwww
hexwr0   ldy #$00
hexwww   jsr pcread
hexwrt   jsr hexasc
         jsr kiir
         txa
         jmp kiir
;
nodmp1
illwrt
impwrt
accwrt   nop
         pha
         jsr hexwr0
         ldx #$06
longw1   jsr spcwrt
         dex
         bpl longw1
         pla
         rts
;
nodmp2
rrrwrt
bbbwrt
zpgwrt   nop
         pha
         jsr hexwr0
         jsr spcwrt
         jsr hexwr1
         ldx #$03
longw2   jsr spcwrt
         dex
         bpl longw2
         pla
         rts
;
nodmp3
abswrt   nop
         pha
         jsr hexwr0
         jsr spcwrt
         jsr hexwr1
         jsr spcwrt
         ldy #$02
         jsr hexwww
         ldx #$00
longw3   jsr spcwrt
         dex
         bpl longw3
         pla
         rts
;
pcread   sei
         sta $ff3f
         lda (pcl),y
readvg   sta $ff3e
         sei
         rts
;
pcrea2   sei
         sta $ff3f
         lda (pcl2),y
         jmp readvg
;
relszm   lda pch
         sta pch2
         lda pcl
         sta pcl2
         ldy #$01
         jsr pcrea2
relcal   cmp #$80
         bcs adjunk ; ha nagyobb
         jmp reladd ; ha kisebb
adjunk   cmp #$ff
         bne reltov ; nem $ff
         jmp relad1 ; ha $ff
reltov   jmp relkiv ; $80 -> $fe
;
reladd   tax
         inx
         inx
relad2   sei
         stx szmpuf
         lda pcl2
         clc
relpu1   adc szmpuf
         sta relugl
         lda pch2
         adc #$00
relexv   sta relugh
         lda #$00
         sta szmpuf
         rts
;
relad1   ldx #$01
         jmp relad2
;
relkiv   eor #$ff
         tax
         dex
         sei
         stx szmpuf
         lda pcl2
         sec
relpu2   sbc szmpuf
         sta relugl
         lda pch2
         sbc #$00
         jmp relexv
;
pcnov3   jsr pcnov1
pcnov2   jsr pcnov1
pcnov1   php
         lda pcl
         clc
         adc #$01
         sta pcl
         lda pch
         adc #$00
         sta pch
         plp
pchnot   rts
;
cmopwr   pha
         jsr crwrt
         jsr sorelo
         lda pch
         clc
         adc addmhi
         jsr hexwrt
         lda pcl
         clc
         adc addmlo
         jsr hexwrt
         jsr spcwrt
         pla
         rts
;
cmopw2   tax
         lda opctb1,x
         jsr kiir
         lda opctb2,x
         jsr kiir
         lda opctb3,x
         jmp kiir
;
imp      jsr cmopwr ; implied
         jsr impwrt
         jsr cmopw2
         jmp pcnov1
;
acc      jsr cmopwr ; accumlator
         jsr accwrt
         jsr cmopw2
         jsr spcwrt
         lda #$41
         jsr kiir
         jmp pcnov1
;
rel      jsr cmopwr ; relative
         jsr rrrwrt
         jsr cmopw2
         jsr spcdol
         jsr relszm
         lda relugh
         clc
         adc addmhi
         jsr hexwrt
         lda relugl
         clc
         adc addmlo
         jsr hexwrt
         jmp pcnov2
;
bt       jsr cmopwr ; #byte
         jsr bbbwrt
         jsr cmopw2
         jsr spcwrt
         jsr heswrt
         jsr dolwrt
         jsr hexwr1
         jmp pcnov2
;
zp       jsr cmopwr ; zp
         jsr zpgwrt
         jsr cmopw2
         jsr spcdol
         jsr hexwr1
         jmp pcnov2
;
zpy      jsr cmopwr ; zp,y
         jsr zpgwrt
         jsr cmopw2
         jsr spcdol
         jsr hexwr1
         jsr yregwr
         jmp pcnov2
;
zpx      jsr cmopwr ; zp,x
         jsr zpgwrt
         jsr cmopw2
         jsr spcdol
         jsr hexwr1
         jsr xregwr
         jmp pcnov2
;
zpindy   jsr cmopwr ; (zp),y
         jsr zpgwrt
         jsr cmopw2
         jsr spckzj
         jsr dolwrt
         jsr hexwr1
         jsr vzjel
         jsr yregwr
         jmp pcnov2
;
zpindx   jsr cmopwr ; (zp,x)
         jsr zpgwrt
         jsr cmopw2
         jsr spckzj
         jsr dolwrt
         jsr hexwr1
         jsr xregwr
         jsr vzjel
         jmp pcnov2
;
abs      jsr cmopwr ; abs
         jsr abswrt
         jsr cmopw2
         jsr spcdol
         jsr hexwr2
         jmp pcnov3
;
absy     jsr cmopwr ; abs,y
         jsr abswrt
         jsr cmopw2
         jsr spcdol
         jsr hexwr2
         jsr yregwr
         jmp pcnov3
;
absx     jsr cmopwr ; abs,x
         jsr abswrt
         jsr cmopw2
         jsr spcdol
         jsr hexwr2
         jsr xregwr
         jmp pcnov3
;
absind   jsr cmopwr ; (abs)
         jsr abswrt
         jsr cmopw2
         jsr spckzj
         jsr dolwrt
         jsr hexwr2
         jsr vzjel
         jmp pcnov3
;
ill      jsr crwrt ; illegal
         jsr sorelo
         lda pch
         clc
         adc addmhi
         jsr hexwrt
         lda pcl
         clc
         adc addmlo
         jsr hexwrt
         jsr spcwrt
         jsr illwrt
         jsr krdwrt
         jsr krdwrt
         jsr krdwrt
         jmp pcnov1
;
sorelo   nop
         jsr pntwrt
         jmp dolwrt
;
spckzj   jsr spcwrt
         jmp kzjel
;
spcdol   jsr spcwrt
         jmp dolwrt
;
maimnu   sei
         jsr stnwrt
         .byte $13,$13,$93
         .byte $08,$8e,$0d
         .text "disassembly lister"
         .text " v7.92"
         .byte $0d
         .text "written by"
         .text " ferenc turoczi"
         .text " (c) 1993."
         .byte $0d,0
         jsr keslel
         jsr stnwrt
         .byte $0d
         .text "power off screen"
         .byte 0
         jsr select ; y=1 n=0
         beq bekap ; n=0
kikap    lda #$00 ; y=1
         beq kepbe
bekap    lda #$ff
kepbe    sta kepiro
         lda #$00
         sta relugh
         sta relugl
         sta pch
         sta pcl
         sta pch2
         sta pcl2
         sta excuth
         sta excutl
         ldx #$03
pufnul   sta kezpuf,x
         sta vegpuf,x
         dex
         bpl pufnul
         jsr keslel
         jsr stnwrt
         .byte $0d
         .text "illegal opcode"
         .text " listing"
         .byte 0
         jsr select ; y=1 n=0
         beq kiillk ; n=0
beillk   lda #$49 ; "i" y=1
         sta filext+1
         lda #$4c ; "l"
         sta filext+2
         sta filext+3
         lda #$00
         beq illkkd
kiillk   lda #$54 ; "t" ; n=0
         sta filext+1
         lda #$45 ; "e"
         sta filext+2
         lda #$44 ; "d"
         sta filext+3
         lda #$2a ; "*"
illkkd   sta illcod
         jsr keslel
         jsr stnwrt
         .byte $0d
         .text "list opcode and"
         .text " operand byte"
         .byte 0
         jsr select ; y=1 n=0
         beq nodump ; n=0
yedump   lda #$ea ; y=1
         bne dumpwr
nodump   lda #$60 ; n=0
dumpwr   sta nodmp1
         sta nodmp2
         sta nodmp3
         jsr keslel
         jsr stnwrt
         .byte $0d
         .text "list "
         .byte $27
         .text ".$"
         .byte $27
         .text " memory adress head"
         .byte 0
         jsr select ; y=1 n=0
         beq noptdl ; n=0
yeptdl   lda #$ea ; y=1
         bne ptdlwr
noptdl   lda #$60
ptdlwr   sta sorelo
         jsr keslel
         jsr stnwrt
         .byte $0d
         .text "wait for any key"
         .text " line end"
         .byte 0
         jsr select ; y=1 n=0
         beq nowait ; n=0
yewait   lda #$ea ; y=1
         bne waitwr
nowait   lda #$60
waitwr   sta anykey
         jmp cimbek
;
curson *=*
         lda $ca
         clc
         adc $c8
         sta $ff0d
         lda $c9
         adc #0
         sbc #11
         sta $ff0c
         rts
uitar    .word 0
uihosz   .byte 0
;
cursof   lda #$ff
         sta $ff0c
         sta $ff0d
         rts
;
uitkmi   .byte $11,$1d,$91,$9d
         .byte $22,$12,$92,$82
         .byte $84,$8d
         .byte $a0,$13,$93,$03
         .byte $90,$05,$1c,$9f
         .byte $81,$95,$96,$97
         .byte $9c,$1e,$1f,$9e
         .byte $98,$99,$9a,$9b
         .byte $1b
uitkma *=*
univin   sta uihosz
         inc uihosz
         jsr stnwrt
         .byte $1b,$4f,$22,$14,0
         txa
         sta $0200
         beq uist
         ldx #0
uiwri    lda $0201,x
         jsr scrwrt
         inx
         cpx $0200
         bne uiwri
uist     lda #0
         sta $ef
uicr     jsr curson
         txa
         pha
uibil    jsr $ffe4
         beq uibil
         ldy #uitkma-uitkmi-1
uicmp    cmp uitkmi,y
         beq uibil
         dey
         bpl uicmp
         tay
         pla
         tax
         tya
         cmp #$20 ; " "
         bne uiel4
uiel6    dex
         bpl uiel5
         inx
         beq uicr
uiel4    sta $0201,x
         inx
uiel5    jsr scrwrt
nesc     cmp #13
         beq uiel3
         cpx uihosz
         bne uicr
         lda #$20 ; " "
         bne uiel6
uiel3    dex
         stx $0200
         jmp cursof
;
pnlpnl   ldx #$05
pnl      lda #$00
         sta $0200,x
         dex
         bpl pnl
         rts
;
uniinp   lda #$04
         ldx #$00
         cli
         jsr univin
         sei
         rts
;
pnlchr   ldx #$03
pnlch1   lda $0201,x
         cmp #$30 ; "0"
         bcc chrerr
         cmp #$47 ; "g"
         bcs chrerr
         cmp #$3a ; ":"
         bcc chroke
         cmp #$41 ; "a"
         bcc chrerr
chroke   dex
         bpl pnlch1
chrerr   rts
;
inpelo   jsr stnwrt
         .text " :$"
         .byte $1b
escapq   .text "q"
         .byte 0
         rts
;
kcmhez   ldx #$08
         .byte $2c
vcmhez   ldx #$09
         .byte $2c
addhoz   ldx #$0a
         lda #$13
         jsr scrwrt
hexckl   lda #$0d
         jsr scrwrt
         dex
         bpl hexckl
         rts
;
cimbek
kezcim   jsr kcmhez
         jsr stnwrt
         .text "memory start"
         .byte 0
         lda #$51 ; "q"
         sta escapq
         jsr inpelo
         jsr pnlpnl
         jsr uniinp
         lda $0200
         cmp #$04
         bcc kezcim
         jsr pnlchr
         cpx #$ff
         bne kezcim
         ldx #$03
kezck1   lda $0201,x
         sta kezpuf,x
         dex
         bpl kezck1
;
vegcim   jsr vcmhez
         jsr stnwrt
         .text "memory end  "
         .byte 0
         lda #$51 ; "q"
         sta escapq
         jsr inpelo
         jsr pnlpnl
         jsr uniinp
         lda $0200
         cmp #$04
         bcc vegcim
         jsr pnlchr
         cpx #$ff
         bne vegcim
         ldx #$03
vegck1   lda $0201,x
         sta vegpuf,x
         dex
         bpl vegck1
         jsr hexava
;
hxcme1   lda kezdl
         cmp vegl
         bne hxcme2 ;nem egyenlo
         lda kezdh
         cmp vegh
         beq addinp ;ha egyenlo
;
hxcme2   sec
         lda kezdl
;*******************************
;cmp vegl ;akkor a sec nem kell!
;*******************************
         sbc vegl
         lda kezdh
         sbc vegh
         bcs hxcmer
         jmp addinp
;
hxcmer   jmp cimbek
;
addinp   jsr addhoz
         jsr stnwrt
         .text "add to start (curs,"
         .text "esc)"
         .byte 0
         lda #$4f ; "o"
         sta escapq
         jsr inpelo
         lda addmhi
         jsr $fb10
         lda addmlo
         jsr $fb10
         ldx #$80
crssp2   ldy #$60
crssp3   iny
         bne crssp3
         inx
         bne crssp2
keymx1   lda #$df
         jsr keymtx
         cmp #$ff
         beq keymx2
         cmp #$f7
         beq crsfel ; up key
         cmp #$fe
         beq crsle ; down key
         cmp #$7f
         beq kisjl ; < key
         cmp #$ef
         beq nagyjl ; > key
keymx2   lda #$bf
         jsr keymtx
         cmp #$ff
         beq keymx1
         cmp #$fe
         beq crsbal ; left key
         cmp #$f7
         beq crsjob ; right key
         cmp #$ef
         beq crsend ; escape key
         bne keymx1
;
kisjl    ldx #$0e
addh15   inc addmhi
         dex
         bpl addh15
crsfel   inc addmhi
         jmp addinp
;
nagyjl   ldx #$0e
dekh15   dec addmhi
         dex
         bpl dekh15
crsle    dec addmhi
         jmp addinp
;
crsbal   lda addmlo
         clc
         adc #$01
         sta addmlo
         lda addmhi
         adc #$00
         sta addmhi
         clc
         jmp addinp
;
crsjob   lda addmlo
         sec
         sbc #$01
         sta addmlo
         lda addmhi
         sbc #$00
         sta addmhi
         clc
         jmp addinp
;
crsend   jmp rakerd
;
szmell   clc
         cmp #$3a ; ":"
         php
         and #$0f
         plp
         bcc szmveg
         adc #$08
szmveg   rts
;
hexben   jsr szmell
         asl a
         asl a
         asl a
         asl a
         sta szmpuf
         txa
         jsr szmell
         ora szmpuf
         rts
;
hexava   lda kezpuf
         ldx kezpuf+1
         jsr hexben
         sta kezdh
;
         lda kezpuf+2
         ldx kezpuf+3
         jsr hexben
         sta kezdl
;
         lda vegpuf
         ldx vegpuf+1
         jsr hexben
         sta vegh
;
         lda vegpuf+2
         ldx vegpuf+3
         jsr hexben
         sta vegl
;
         lda #$00
         sta szmpuf
         clc
noind    rts
;
rakerd   jsr keslel
         sei
         jsr stnwrt
         .byte $0d
         .text "are you sure"
         .byte 0
         jsr select ; y=1 n=0
         bne noind ; y=1
         jmp statdl ; n=0
;
keymtx   sta $fd30
         sta $ff08
         lda $ff08
         rts
;
;---------------------------------------
;end of source code
;---------------------------------------
