status = $C000
scr = $C001
kbd = $C002
step = $C010
maxrow = 23
maxcol = 79
.org $A000
tok:
.byte "dab"
msg:
.byte "oof, you divided a, and b on me.\n"
string:
.byte "Please, type something.\n"
string2:
.byte "You typed, "
bits:
.byte $80
.byte $40
.byte $20
.byte $10
.byte $08
.byte $04
.byte $02
.byte $01
.org $1000
bitabl:
.qword 0
.qword 0
.org $2000
buffer:
.org $4000
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:
.word 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.w
jsl clr_arr
jmp start
clr_arr:
phb
ldb
jsl set_ptr
adc
inb
jsl 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
rtl
start:
lda TODO
sta status
tax
phy
tay
lda.w
sta.w scr_ptr
lda.w
jsl clr_arr
ply
lda.w
jsl print_str
lsr
sta end
jmp read
read:
lda
sta end
inc end
lda status
beq read
jsl getchar
beq parse
jmp read
print_str:
sta.w end
print_str2:
lda.w end
ldb
jsl set_ptr
tba
inb
stb b
pntstr_lp:
lda.w ptr
cmp.w end
bne print_str2
lsr
phy
txy
lda (ptr), y
ply
beq pntstr_end
inx
jsl print_char
jmp pntstr_lp
pntstr_end:
ldb
stb b
rtl
getbit:
clc
lda scr_str
bne getbt0
ldx scr_row
jmp getbt1
getbt0:
lda scr_row
adc scr_str
tax
getbt1:
pha
ldb
lda.w
jsl set_ptr
lsr
pla
jsl bitpos
phy
txy
ldb (ptr2), y
ply
aba
cmp
jmp bitout
clrbit:
pha
ldb
lda.w
jsl set_ptr
lsr
pla
jsl bitpos
xor
phy
txy
ldb (ptr2), y
aba
bitsav:
sta (ptr2), y
ply
bitout:
ldx bitmask
rtl
setbit:
pha
ldb
lda.w
jsl set_ptr
lsr
pla
jsl bitpos
phy
txy
ldb (ptr2), y
oab
jmp bitsav
bitpos:
pha
ldb
lda.w
jsl set_ptr
lsr
pla
stx bitmask
txa
and
phy
tay
tax
lda (ptr), y
ply
pha
lda bitmask
lsr
tax
pla
rtl
getchar:
lda kbd
ldb
stb e
stb b
pha
phy
cmp
bne getchar_pnt
jsl cmd_cpy
getchar_pnt:
ply
pla
ldb e
bne reset_row
getchar_pt1:
jsl 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:
rtl
cmd_cpy:
lda scr_row
sta scr_trow
jsl findend
ldb scr_str
beq cmd_cpy3
cmd_cpy2:
sec
sbc scr_str
clc
cmd_cpy3:
sta scr_row
sta e
jsl findst
clc
lda scr_row
adc scr_str
mul
tay
ldx.w
ldb
lda.w
jsl set_ptr
inb
lda.w
jsl set_ptr
deb
tba
cmd_cpy_lp:
ldb
lda.q (ptr), y
cmd_cpy_lp1:
phy
txy
sta (ptr2), y
inx
ply
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_nd:
tab
rtl
findst:
lda
findst_lp:
pha
jsl getbit
pla
bcc findst_done
inc
dec scr_row
bpo findst_lp
dec
inc scr_row
findst_done:
cmp
rtl
fndend:
phb
ldb
lda.w
jsl set_ptr
tba
plb
phy
fndend_lp:
lda (ptr), y
beq fndend_done
iny
jmp fndend_lp
fndend_done:
sty.w scr_ptr3
ply
rtl
findend:
jsl fndend
lda.w scr_ptr3
div
rtl
parse:
lda
tax
jsl dabbed
beq start
lda
tax
jmp result
print_char:
sta a
ldb
lda.w
jsl 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
jsl fndend
jmp prntc_movln
prntc_updt:
lda scr_col
sta scr_tcol
prntc_updt2:
jsl findend
sta e
sta scr_row
jsl findst
lda scr_row
prntc_updt3:
sta f
jsl rdrw_ln
lda scr_trow
sta scr_row
lda scr_tcol
sta scr_col
jsl update_pos
dec d
jmp printc_sav1
prntc_movln:
ldy.w scr_ptr3
inc scr_ptr3
tyx
dey
ldb
stb d
jsl 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
jsl 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
jsl setbit
plx
jsl update_pos
printc_end:
rtl
nl:
lda
ldb (ptr3), y
bne nl1
sta (ptr3), y
nl1:
sta scr_col
lda scr_row
cmp
bcc nl_inc
jsl scrl_down
lda
sta a
jmp printc_end
nl_inc:
inc scr_row
jsl update_pos
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.w
jsl clr_arr
tay
lda.w
sta.w scr_ptr
lda.w
jsl clr_arr
sta scr_col
sta scr_row
jsl 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
jsl findend
sta scr_row
back0:
jsl findst
beq back1
bcs back_updt
lda scr_trow
sta scr_row
back1:
dey
lda
sta (ptr3), y
tyx
iny
ldb
stb d
jsl shftln
lda
sta scr
lda e
beq back3
back2:
jsl findend
sta e
lda scr_col
sta scr_tcol
jsl rdrw_ln
lda scr_tcol
sta scr_col
back3:
lda scr_trow
sta scr_row
dec scr_col
jsl 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:
jsl 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
jsl scrl_up
inc scr_row
backwrp:
clc
lda scr_row
adc scr_str
tax
backwrp2:
dec scr_row
ldb
stb scr_col
jsl 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
jsl setbit
jmp shftln_end2
shftln_wrp1:
tax
jsl clrbit
jmp shftln_end2
shftln_end:
lda (ptr3), y
bne shftln_nd0
lda
sta (ptr3), y
shftln_nd0:
jsl 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:
jsl findend
cpb
beq shftln_nd2
jmp shftln_end2
shftln_nd2:
cmp scr_row
beq shftln_end2
bcs shftln_wrp1
shftln_end2:
rtl
esc:
lda status
lda kbd
cmp
beq shftesc
lda status
beq printc_end
lda kbd
sta c
lda
sta d
jsl isup
lda d
bne esc_end
jsl isdown
lda d
bne esc_end
lda
jsl isleft
lda d
bne esc_end
jsl 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
jsl isshftup
lda d
bne shftesc_end
jsl 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
jsl scrl_up
lda
sta d
isup_done:
rtl
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
jsl scrl_down
lda scr_trow
sta scr_row
lda scr_tcol
sta scr_col
lda
sta d
isdown_done:
rtl
isright:
lda c
cmp
bne isright_dne
lda scr_col
cmp
beq isright_wrp
jmp right
isright_wrp:
inc scr_row
jsl getbit
bcs wrap_inc
dec scr_row
jmp isright_dne
isright_scr:
lda scr_str
beq isright_end
lda
sta wrapped
jsl 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:
jsl update_pos
isright_dne:
lda
sta wrapped
rtl
isleft:
lda c
cmp
beq isleft_done
lda scr_col
beq isleft_wrp
lda c
cmp
beq left
jmp isleft_done
isleft_wrp:
jsl 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
jsl scrl_up
jmp isleft_done
isleft_end:
jsl update_pos
isleft_done:
lda
sta wrapped
rtl
up:
dec scr_row
jsl update_pos
lda
sta d
jmp isup_done
down:
inc scr_row
jsl update_pos
lda
sta d
jmp isdown_done
right:
inc scr_col
jsl update_pos
jmp isright_dne
left:
dec scr_col
jsl 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:
rtl
isshftdown:
lda c
cmp
bne shftdn_done
lda
sta d
lda scr_end
cmp
bcs shftdn_done
jmp shftdown
shftdn_done:
rtl
shftup:
jsl scrl_up
lda
sta d
jmp shftup_done
shftdown:
jsl 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
jsl getrow
jsl getcol
lda
sta scr
rtl
getrow:
lda scr_row
div
adc
sta scr
tba
adc
sta scr
rtl
getcol:
lda
sta scr
lda scr_col
div
clc
adc
sta scr
tba
clc
adc
sta scr
rtl
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:
jsl 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
jsl update_pos
lda
sta wrapped
scrldn_done:
rtl
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
jsl rdrw_row
pla
sta scr_col
pla
sta scr_row
jsl update_pos
scrlup_done:
rtl
rdrw_row:
lda
sta scr_col
jsl 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
jsl update_pos
rdrow_done:
rtl
result:
lda.w
ldx.w zero
jsl print_str
rset_x:
lda
tax
jmp print_buf
dabbed:
ldb
lda.w
jsl set_ptr
inb
lda.w
jsl set_ptr
deb
tba
dab_st:
phy
txy
lda (ptr), y
beq dab_pend
cmp (ptr2), y
beq chk_str
jmp dab_pend
chk_str:
ply
inx
cpx
bne dab_st
ldx
pnt_msg:
lda.w
ldx
jsl print_str
jmp dab_peqnd
dab_pend:
ply
lda
jmp dab_end
dab_peqnd:
lda
jmp dab_end
dab_end:
rtl
print_buf:
lda.w
jsl print_str
lsr
cmd_clr:
lda
jsl print_char
jmp start
rdrw_ln:
lda scr_row
pha
lda f
sta scr_row
lda scr_col
pha
jsl update_pos
rdrwln_lp:
lda scr_row
cmp e
beq rdrwln_lp1
bcs rdrwln_done
rdrwln_lp1:
jsl rdrw_row
rdrwln_inc:
inc scr_row
jmp rdrwln_lp
rdrwln_done:
pla
sta scr_col
pla
sta scr_row
jsl update_pos
lda
sta e
sta f
rtl
set_ptr:
cpb
beq set_ptr2
cpb
beq set_ptr3
set_ptr1:
sta.q ptr
jmp setptr_end
set_ptr2:
sta.q ptr2
jmp setptr_end
set_ptr3:
sta.q ptr3
setptr_end:
rtl
.org $FFC0
.qword reset
a
d