status = $100
scr = $101
kbd = $102
step = $110
maxrow = 23
maxcol = 79
.include "subasm.s"
.org $A000
tok:
.byte "dab"
msg:
.byte "oof, you divided a, and b on me.\n"
ed_name:
.byte "SuBEditor"
ed_ver:
.byte "1"
ed_sver:
.byte ".0.0"
ver_str:
.byte ", version "
made:
.byte "Created by, "
author:
.byte "mr b0nk 500"
string2:
.byte "You typed, "
bits:
.byte $80, $40, $20, $10, $08, $04, $02, $01
incl:
.org $30000
bitabl:
.qword 0
.qword 0
.org bitabl+$1000
buffer:
.org buffer+$2000
cmd_buf:
.org 0
scr_row:
.byte 0
scr_col:
.byte 0
scr_trow:
.byte 0
scr_tcol:
.byte 0
scr_ptr:
.word 0
scr_ptr2:
.word 0
scr_ptr3:
.word 0
a:
.byte 0
b:
.byte 0
c:
.byte 0
d:
.byte 0
e:
.byte 0
f:
.byte 0
g:
.byte 0
zero:
.qword 0
end:
.qword 0
bitmask:
.byte 0
scr_str:
.byte 0
scr_end:
.byte 0
wrapped:
.byte 0
ptr:
.qword 0
ptr2:
.qword 0
ptr3:
.qword 0
.org $8000
reset:
cps
ldx.w
txs
ldy
sty end
tyx
lda
sta scr_end
tya
sta scr_str
sta.q bitabl
sta.q bitabl+8
inc end
lda.w
sta.w scr_ptr
lda.d
jsr clr_arr
jsr pnt_strt
jmp start
clr_arr:
phb
ldb
jsr set_ptr
adc
inb
jsr set_ptr
deb
tba
@loop:
cpy.w scr_ptr
bcs @end
sta.q (ptr), y
sta.q (ptr2), y
tya
adc
tay
tba
sta.q (ptr), y
sta.q (ptr2), y
tya
adc
tay
tba
jmp @loop
@end:
ldy.w zero
plb
rts
pnt_strt:
lda.w
jsr print_str
lda.w
jsr print_str
lda.w
jsr print_str
lda.w
jsr print_str
lda
jsr print_char
lda.w
jsr print_str
lda.w
jsr print_str
lda
jsr print_char
rts
start:
lda TODO
sta status
tax
phy
tay
lda.w
sta.w scr_ptr
lda.d
jsr clr_arr
ply
and
sta end
jmp read
read:
lda
sta end
inc end
lda status
beq read
jsr getchar
beq parse
jmp read
print_str:
ldx
sta.q end
@reset:
lda.q end
ldb
jsr set_ptr
tba
@loop:
ldb
stb b
lda.q ptr
cmp.q end
bne @reset
and
phy
txy
lda (ptr), y
ply
beq @end
inx
jsr print_char
jmp @loop
@end:
ldb
stb b
rts
getbit:
clc
lda scr_str
bne getbt0
ldx scr_row
jmp getbt1
getbt0:
lda scr_row
adc scr_str
tax
getbt1:
pha
ldb
lda.d
jsr set_ptr
lsr
pla
jsr bitpos
phy
txy
ldb (ptr2), y
ply
aba
cmp
jmp bitout
clrbit:
pha
ldb
lda.d
jsr set_ptr
and
pla
jsr bitpos
xor
phy
txy
ldb (ptr2), y
aba
bitsav:
sta (ptr2), y
ply
bitout:
ldx bitmask
rts
setbit:
pha
ldb
lda.d
jsr set_ptr
and
pla
jsr bitpos
phy
txy
ldb (ptr2), y
oab
jmp bitsav
bitpos:
pha
ldb
lda.w
jsr set_ptr
and
pla
stx bitmask
txa
and
phy
tay
tax
lda (ptr), y
ply
pha
lda bitmask
lsr
tax
pla
rts
getchar:
lda kbd
ldb
stb e
stb b
pha
phy
cmp
bne @print
jsr cmd_cpy
@print:
ply
pla
ldb e
bne @row
@print1:
jsr print_char
lda a
cmp
beq @true
jmp @false
@row:
ldb e
cpb
beq @row2
bcs @row1
jmp @row2
@row1:
ldb
@row2:
stb scr_row
jmp @print1
@true:
lda
jmp @end
@false:
lda
@end:
rts
cmd_cpy:
lda scr_row
sta scr_trow
jsr findend
ldb scr_str
beq @start
@offset:
sec
sbc scr_str
clc
@start:
sta scr_row
sta e
jsr findst
clc
lda scr_row
adc scr_str
mul
tay
ldx.w
ldb
lda.d
jsr set_ptr
inb
lda.d
jsr set_ptr
deb
tba
@loop:
ldb
lda.q (ptr), y
@loop1:
phy
txy
sta (ptr2), y
inx
ply
cpx.w
bcs @end
iny
inb
lsr
stb g
tab
and
beq @end1
tba
ldb g
cpb
beq @loop
jmp @loop1
@end:
ldb
phy
txy
stb (ptr2), y
ply
@end1:
tab
rts
findst:
lda
@loop:
pha
jsr getbit
pla
bcc @end
inc
dec scr_row
bpo @loop
dec
inc scr_row
@end:
cmp
rts
fndend:
phb
ldb
lda.d
jsr set_ptr
tba
plb
phy
@loop:
lda (ptr), y
beq @end
iny
jmp @loop
@end:
sty.w scr_ptr3
ply
rts
findend:
jsr fndend
lda.w scr_ptr3
div
rts
parse:
lda
tax
jsr subasm
jmp start
print_char:
sta a
ldb
lda.d
jsr set_ptr
ldb
tba
lda a
cmp
beq esc
cmp
beq nl
cmp
beq clr_scr
cmp
beq en_step
cmp
beq dis_step
cmp
beq bs
cmp
beq bs
printc:
lda
sta d
lda (ptr3), y
beq @save
lda b
bne @save
sty.w scr_ptr
jsr fndend
jmp @shift
@update:
lda scr_col
sta scr_tcol
@update1:
jsr findend
sta e
sta scr_row
jsr findst
lda scr_row
@update2:
sta f
jsr rdrw_ln
lda scr_trow
sta scr_row
lda scr_tcol
sta scr_col
jsr update_pos
dec d
jmp @save1
@shift:
ldy.w scr_ptr3
inc scr_ptr3
tyx
dey
ldb
stb d
jsr shftln
ldb
stb d
lda a
sta (ptr3), y
lda scr_row
sta scr_trow
jmp @update
@save:
ldb d
bne @update
@save1:
lda a
sta (ptr3), y
@incr:
inc scr_col
iny
@wrapped:
ldb
stb f
ldb scr_col
cpb
bcs @scrolled
@print:
sta scr
ldb f
beq @wrap
jmp printc_end
@scrolled:
ldb scr_row
cpb
bcs @scroll
@wrapped2:
ldb
stb f
jmp @print
@scroll:
sta scr
clc
lda
sta wrapped
jsr scrl_down
@wrap:
ldb
stb scr_col
ldb scr_row
cpb
bcs @wrap2
@wrap1:
inc scr_row
@wrap2:
phx
clc
lda scr_row
adc scr_str
tax
jsr setbit
plx
jsr update_pos
printc_end:
rts
nl:
lda
ldb (ptr3), y
bne @scroll
sta (ptr3), y
@scroll:
sta scr_col
lda scr_row
cmp
bcc @incr
jsr scrl_down
jmp @end
@incr:
inc scr_row
jsr update_pos
@end:
lda
sta a
jmp printc_end
clr_scr:
lda
sta scr_end
lda
sta scr_str
sta.q bitabl
sta.q bitabl+8
tay
lda.w
sta.w scr_ptr
lda.d
jsr clr_arr
tay
lda.w
sta.w scr_ptr
lda.d
jsr clr_arr
sta scr_col
sta scr_row
jsr update_pos
lda
sta scr
jmp printc_end
en_step:
lda step
beq step_en
jmp printc_end
step_en:
lda
sta step
jmp printc_end
dis_step:
lda step
bne step_dis
jmp printc_end
step_dis:
lda
sta step
jmp printc_end
back:
ldb
stb e
stb f
lda scr_row
sta scr_trow
jsr findend
sta scr_row
@find_st:
jsr findst
beq @shift
bcs @update
lda scr_trow
sta scr_row
@shift:
dey
lda
sta (ptr3), y
tyx
iny
ldb
stb d
jsr shftln
lda
sta scr
lda e
beq @load
@find_end:
jsr findend
sta e
lda scr_col
sta scr_tcol
jsr rdrw_ln
lda scr_tcol
sta scr_col
@load:
lda scr_trow
sta scr_row
dec scr_col
jsr update_pos
jmp printc_end
@update:
lda scr_row
sta f
inc e
jmp @shift
bs:
lda scr_col
beq @wrap
jmp back
@wrap:
jsr getbit
bcs @wrap1
jmp printc_end
@wrap1:
lda scr_row
beq @wrap2
jmp @wrap3
@wrap2:
lda scr_str
bne @scroll
jmp printc_end
@scroll:
clc
jsr scrl_up
inc scr_row
@wrap3:
clc
lda scr_row
adc scr_str
tax
@wrap4:
dec scr_row
ldb
stb scr_col
jsr update_pos
jmp back
shftln:
ldb d
beq @dec_loop
ldb
jmp @inc_loop
@neg:
ldy.w zero
stb (ptr3), y
jmp @end
@inc_loop:
sty.w scr_ptr2
ldy.w scr_ptr
cpy.w scr_ptr2
beq @inc_loop1
bcs @end
@inc_loop1:
ldy.w scr_ptr2
lda (ptr3), y
phy
txy
sta (ptr3), y
ply
stb (ptr3), y
bng @neg
dey
dex
jmp @inc_loop
@dec_loop:
stx.w scr_ptr2
lda (ptr3), y
beq @end3
phy
txy
sta (ptr3), y
inx
ply
stb (ptr3), y
iny
jmp @dec_loop
@wrap:
tax
jsr setbit
jmp @end5
@wrap1:
tax
jsr clrbit
jmp @end5
@end:
lda (ptr3), y
bne @end1
lda
sta (ptr3), y
@end1:
jsr findend
sta d
lda (ptr3), y
cmp
bne @end5
lda
sta (ptr3), y
@end2:
lda d
cmp scr_row
beq @end5
bcs @wrap
jmp @end5
@end3:
jsr findend
cpb
beq @end4
jmp @end5
@end4:
cmp scr_row
beq @end5
bcs @wrap1
@end5:
rts
esc:
lda status
lda kbd
cmp
beq shftesc
lda status
beq printc_end
lda kbd
sta c
lda
sta d
jsr isup
lda d
bne esc_end
jsr isdown
lda d
bne esc_end
lda
jsr isleft
lda d
bne esc_end
jsr isright
esc_end:
lda
sta d
jmp printc_end
shftesc:
lda status
lda kbd
lda status
beq printc_end
lda kbd
sta c
lda
sta d
jsr isshftup
lda d
bne shftesc_end
jsr isshftdown
shftesc_end:
lda
sta d
jmp printc_end
isup:
lda c
cmp
bne @end
lda scr_row
beq @scroll
@check2:
lda c
cmp
beq up
jmp @end
@scroll:
lda scr_str
beq @end
jsr scrl_up
lda
sta d
@end:
isup_done:
rts
isdown:
lda c
cmp
bne @end
lda scr_row
cmp
beq @scroll
lda c
cmp
beq down
jmp @end
@scroll:
lda scr_row
sta scr_trow
lda scr_col
sta scr_tcol
jsr scrl_down
lda scr_trow
sta scr_row
lda scr_tcol
sta scr_col
lda
sta d
@end:
isdown_done:
rts
isright:
lda c
cmp
bne @end2
lda scr_col
cmp
beq @wrap
jmp right
@wrap:
inc scr_row
jsr getbit
bcs @incr
dec scr_row
jmp @end2
@scroll:
lda scr_str
beq @end
lda
sta wrapped
jsr scrl_down
jmp @end
@incr:
lda
sta scr_col
lda scr_row
cmp
beq @end1
bcs @scroll
jmp @end1
@end:
dec scr_row
@end1:
jsr update_pos
@end2:
isright_dne:
lda
sta wrapped
rts
isleft:
lda c
cmp
beq @end1
lda scr_col
beq @wrap
lda c
cmp
beq left
jmp @end1
@wrap:
jsr getbit
bcs @decr
jmp @end1
@decr:
lda scr_row
beq @decr1
lda
sta wrapped
dec scr_row
@decr1:
lda
sta scr_col
lda
sta d
lda scr_row
beq @scroll
jmp @end
@scroll:
lda wrapped
bne @end
lda scr_str
beq @end1
jsr scrl_up
jmp @end1
@end:
jsr update_pos
@end1:
isleft_done:
lda
sta wrapped
rts
up:
dec scr_row
jsr update_pos
lda
sta d
jmp isup_done
down:
inc scr_row
jsr update_pos
lda
sta d
jmp isdown_done
right:
inc scr_col
jsr update_pos
jmp isright_dne
left:
dec scr_col
jsr update_pos
lda
sta d
jmp isleft_done
isshftup:
lda c
cmp
bne shftup_done
lda
sta d
lda scr_str
beq shftup_done
jmp shftup
shftup_done:
rts
isshftdown:
lda c
cmp
bne shftdn_done
lda
sta d
lda scr_end
cmp
bcs shftdn_done
jmp shftdown
shftdn_done:
rts
shftup:
jsr scrl_up
lda
sta d
jmp shftup_done
shftdown:
jsr scrl_down
lda
sta d
jmp shftdn_done
update_pos:
ldb
stb f
clc
lda scr_row
adc scr_str
tay
mul
clc
adc scr_col
tay
tba
lda
sta scr
lda
sta scr
jsr getrow
jsr getcol
lda
sta scr
rts
getrow:
lda scr_row
jmp bcd
getcol:
lda
sta scr
lda scr_col
bcd:
div
ora
sta scr
tba
ora
sta scr
rts
scrl_down:
inc scr_str
inc scr_end
lda
sta scr
lda
sta scr
lda
sta scr
lda scr_row
pha
lda wrapped
beq @save
@redraw:
jsr rdrw_row
lda wrapped
beq @load
jmp @end
@save:
lda scr_col
pha
jmp @redraw
@load:
pla
sta scr_col
@end:
pla
sta scr_row
jsr update_pos
lda
sta wrapped
@end1:
rts
scrl_up:
dec scr_str
dec scr_end
lda
sta scr
lda
sta scr
lda
sta scr
lda scr_row
pha
lda scr_col
pha
lda
sta scr_row
jsr rdrw_row
pla
sta scr_col
pla
sta scr_row
jsr update_pos
@end:
rts
rdrw_row:
lda
sta scr_col
jsr update_pos
@loop:
lda (ptr3), y
beq @incr
sta scr
@incr:
inc scr_col
lda (ptr3), y
beq @skip
@incr1:
iny
@incr2:
lda scr_col
cmp
bcs @end
jmp @loop
@skip:
lda
sta scr
jmp @incr1
@end:
lda
sta scr_col
jsr update_pos
@end1:
rts
rdrw_ln:
lda scr_row
pha
lda f
sta scr_row
lda scr_col
pha
jsr update_pos
@loop:
lda scr_row
cmp e
beq @loop1
bcs @end
@loop1:
jsr rdrw_row
@incr:
inc scr_row
jmp @loop
@end:
pla
sta scr_col
pla
sta scr_row
jsr update_pos
lda
sta e
sta f
rts
set_ptr:
cpb
beq @ptr2
cpb
beq @ptr3
@ptr1:
stb.q ptr
sta.q ptr
jmp @end
@ptr2:
stb.q ptr2
sta.q ptr2
jmp @end
@ptr3:
stb.q ptr3
sta.q ptr3
@end:
rts
parser:
.org $FFC0
.qword reset
a
d