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
clr_arr_st:
cpy.w scr_ptr
bcs clr_arr_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 clr_arr_st
clr_arr_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
print_str2:
lda.q end
ldb
jsr set_ptr
tba
pntstr_lp:
ldb
stb b
lda.q ptr
cmp.q end
bne print_str2
and
phy
txy
lda (ptr), y
ply
beq pntstr_end
inx
jsr print_char
jmp pntstr_lp
pntstr_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 getchar_pnt
jsr cmd_cpy
getchar_pnt:
ply
pla
ldb e
bne reset_row
getchar_pt1:
jsr print_char
lda a
cmp
beq getchar_ln
jmp getchar_chr
reset_row:
ldb e
cpb
beq reset_row2
bcs reset_row1
jmp reset_row2
reset_row1:
ldb
reset_row2:
stb scr_row
jmp getchar_pt1
getchar_ln:
lda
jmp getchar_end
getchar_chr:
lda
getchar_end:
rts
cmd_cpy:
lda scr_row
sta scr_trow
jsr findend
ldb scr_str
beq cmd_cpy3
cmd_cpy2:
sec
sbc scr_str
clc
cmd_cpy3:
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
cmd_cpy_lp:
ldb
lda.q (ptr), y
cmd_cpy_lp1:
phy
txy
sta (ptr2), y
inx
ply
cpx.w
bcs cmd_cpy_nd0
iny
inb
lsr
stb g
tab
and
beq cmd_cpy_nd
tba
ldb g
cpb
beq cmd_cpy_lp
jmp cmd_cpy_lp1
cmd_cpy_nd0:
ldb
phy
txy
stb (ptr2), y
ply
cmd_cpy_nd:
tab
rts
findst:
lda
findst_lp:
pha
jsr getbit
pla
bcc findst_done
inc
dec scr_row
bpo findst_lp
dec
inc scr_row
findst_done:
cmp
rts
fndend:
phb
ldb
lda.d
jsr set_ptr
tba
plb
phy
fndend_lp:
lda (ptr), y
beq fndend_done
iny
jmp fndend_lp
fndend_done:
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 printc_save
lda b
bne printc_save
sty.w scr_ptr
jsr fndend
jmp prntc_movln
prntc_updt:
lda scr_col
sta scr_tcol
prntc_updt2:
jsr findend
sta e
sta scr_row
jsr findst
lda scr_row
prntc_updt3:
sta f
jsr rdrw_ln
lda scr_trow
sta scr_row
lda scr_tcol
sta scr_col
jsr update_pos
dec d
jmp printc_sav1
prntc_movln:
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 prntc_updt
printc_save:
ldb d
bne prntc_updt
printc_sav1:
lda a
sta (ptr3), y
printc_inc:
inc scr_col
iny
printc_2:
ldb
stb f
ldb scr_col
cpb
bcs printc_4
printc_3:
sta scr
ldb f
beq printc_wrap
jmp printc_end
printc_4:
ldb scr_row
cpb
bcs printc_scrl
printc_5:
ldb
stb f
jmp printc_3
printc_scrl:
sta scr
clc
lda
sta wrapped
jsr scrl_down
jmp printc_wrap
printc_wrap:
ldb
stb scr_col
ldb scr_row
cpb
bcs printc_wrp2
printc_wrap1:
inc scr_row
printc_wrp2:
phx
clc
lda scr_row
adc scr_str
tax
jsr setbit
plx
jsr update_pos
printc_end:
rts
nl:
lda
ldb (ptr3), y
bne nl1
sta (ptr3), y
nl1:
sta scr_col
lda scr_row
cmp
bcc nl_inc
jsr scrl_down
jmp nl_end
nl_inc:
inc scr_row
jsr update_pos
nl_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
back0:
jsr findst
beq back1
bcs back_updt
lda scr_trow
sta scr_row
back1:
dey
lda
sta (ptr3), y
tyx
iny
ldb
stb d
jsr shftln
lda
sta scr
lda e
beq back3
back2:
jsr findend
sta e
lda scr_col
sta scr_tcol
jsr rdrw_ln
lda scr_tcol
sta scr_col
back3:
lda scr_trow
sta scr_row
dec scr_col
jsr update_pos
jmp printc_end
back_updt:
lda scr_row
sta f
inc e
jmp back1
bs:
lda scr_col
beq back_wrap
jmp back
back_wrap:
jsr getbit
bcs back_wrap1
jmp printc_end
back_wrap1:
lda scr_row
beq back_wrap2
jmp backwrp
back_wrap2:
lda scr_str
bne back_scrl
jmp printc_end
back_scrl:
clc
jsr scrl_up
inc scr_row
backwrp:
clc
lda scr_row
adc scr_str
tax
backwrp2:
dec scr_row
ldb
stb scr_col
jsr update_pos
jmp back
shftln:
ldb d
beq shftln_lp1
ldb
jmp shftln_lp0
shftln_neg:
ldy.w zero
stb (ptr3), y
jmp shftln_end
shftln_lp0:
sty.w scr_ptr2
ldy.w scr_ptr
cpy.w scr_ptr2
beq shftln_lp01
bcs shftln_end
shftln_lp01:
ldy.w scr_ptr2
lda (ptr3), y
phy
txy
sta (ptr3), y
ply
stb (ptr3), y
bng shftln_neg
dey
dex
jmp shftln_lp0
shftln_lp1:
stx.w scr_ptr2
lda (ptr3), y
beq shftln_end1
phy
txy
sta (ptr3), y
inx
ply
stb (ptr3), y
iny
jmp shftln_lp1
shftln_wrap:
tax
jsr setbit
jmp shftln_end2
shftln_wrp1:
tax
jsr clrbit
jmp shftln_end2
shftln_end:
lda (ptr3), y
bne shftln_nd0
lda
sta (ptr3), y
shftln_nd0:
jsr findend
sta d
lda (ptr3), y
cmp
bne shftln_nd1
lda
sta (ptr3), y
shftln_nd1:
lda d
cmp scr_row
beq shftln_end2
bcs shftln_wrap
jmp shftln_end2
shftln_end1:
jsr findend
cpb
beq shftln_nd2
jmp shftln_end2
shftln_nd2:
cmp scr_row
beq shftln_end2
bcs shftln_wrp1
shftln_end2:
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 isup_done
lda scr_row
beq isup_scrl
isup_2:
lda c
cmp
beq up
jmp isup_done
isup_scrl:
lda scr_str
beq isup_done
jsr scrl_up
lda
sta d
isup_done:
rts
isdown:
lda c
cmp
bne isdown_done
lda scr_row
cmp
beq isdown_scrl
lda c
cmp
beq down
jmp isdown_done
isdown_scrl:
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
isdown_done:
rts
isright:
lda c
cmp
bne isright_dne
lda scr_col
cmp
beq isright_wrp
jmp right
isright_wrp:
inc scr_row
jsr getbit
bcs wrap_inc
dec scr_row
jmp isright_dne
isright_scr:
lda scr_str
beq isright_end
lda
sta wrapped
jsr scrl_down
jmp isright_end
wrap_inc:
lda
sta scr_col
lda scr_row
cmp
beq isright_nd2
bcs isright_scr
jmp isright_nd2
isright_end:
dec scr_row
isright_nd2:
jsr update_pos
isright_dne:
lda
sta wrapped
rts
isleft:
lda c
cmp
beq isleft_done
lda scr_col
beq isleft_wrp
lda c
cmp
beq left
jmp isleft_done
isleft_wrp:
jsr getbit
bcs wrap_dec
jmp isleft_done
wrap_dec:
lda scr_row
beq wrap_dec1
lda
sta wrapped
dec scr_row
wrap_dec1:
lda
sta scr_col
lda
sta d
lda scr_row
beq isleft_scrl
jmp isleft_end
isleft_scrl:
lda wrapped
bne isleft_end
lda scr_str
beq isleft_done
jsr scrl_up
jmp isleft_done
isleft_end:
jsr update_pos
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
adc scr_col
tay
lda
sta scr
lda
sta scr
jsr getrow
jsr getcol
lda
sta scr
rts
getrow:
lda scr_row
div
adc
sta scr
tba
adc
sta scr
rts
getcol:
lda
sta scr
lda scr_col
div
clc
adc
sta scr
tba
clc
adc
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 scrldn_save
scrldn1:
jsr rdrw_row
lda wrapped
beq scrldn_load
jmp scrldn_end
scrldn_save:
lda scr_col
pha
jmp scrldn1
scrldn_load:
pla
sta scr_col
scrldn_end:
pla
sta scr_row
jsr update_pos
lda
sta wrapped
scrldn_done:
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
scrlup_done:
rts
rdrw_row:
lda
sta scr_col
jsr update_pos
rdrow_st:
lda (ptr3), y
beq rdrow_inc
sta scr
rdrow_inc:
inc scr_col
lda (ptr3), y
beq rdrow_skip
rdrow_inc1:
iny
rdrow_inc2:
lda scr_col
cmp
bcs rdrow_end
jmp rdrow_st
rdrow_skip:
lda
sta scr
jmp rdrow_inc1
rdrow_end:
lda
sta scr_col
jsr update_pos
rdrow_done:
rts
rdrw_ln:
lda scr_row
pha
lda f
sta scr_row
lda scr_col
pha
jsr update_pos
rdrwln_lp:
lda scr_row
cmp e
beq rdrwln_lp1
bcs rdrwln_done
rdrwln_lp1:
jsr rdrw_row
rdrwln_inc:
inc scr_row
jmp rdrwln_lp
rdrwln_done:
pla
sta scr_col
pla
sta scr_row
jsr update_pos
lda
sta e
sta f
rts
set_ptr:
cpb
beq set_ptr2
cpb
beq set_ptr3
set_ptr1:
stb.q ptr
sta.q ptr
jmp setptr_end
set_ptr2:
stb.q ptr2
sta.q ptr2
jmp setptr_end
set_ptr3:
stb.q ptr3
sta.q ptr3
setptr_end:
rts
parser:
.org $FFC0
.qword reset
a
d