.org $1000
tok:
.byte "dab"
msg:
.byte "oof, you divided a, and b on me.\n"
string:
.byte "Please, type something.\n"
string2:
.byte "You typed, "
.org $1100
bits:
.byte $80
.byte $40
.byte $20
.byte $10
.byte $08
.byte $04
.byte $02
.byte $01
.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
a:
.byte $0
b:
.byte $0
c:
.byte $0
d:
.byte $0
e:
.byte $0
f:
.byte $0
zero:
.qword $0
end:
.byte $0
bitmask:
.byte $0
bitabl:
.qword $0
.qword $0
scr_str:
.byte $0
scr_end:
.byte $0
wrapped:
.byte $0
ptr:
.qword $0
ptr2:
.qword $0
ptr3:
.qword $0
ptr4:
.qword $0
ptr5:
.qword $0
ptr6:
.qword $0
.org $8000
reset:
cps
ldx.w
txs
ldy
tyx
lda
sta scr_end
lda.w
sta.q ptr5
lda.w
sta.q ptr6
tya
sta scr_str
sta.q bitabl
sta.q bitabl+8
jsl clr_buf
jmp start
clr_buf:
phb
ldb
clr_buf_st:
cpy.w
bcs clr_buf_end
sta.q (ptr5), y
tya
adc
tay
tba
sta.q (ptr5), y
tya
adc
tay
tba
sta.q (ptr5), y
tya
adc
tay
tba
sta.q (ptr5), y
tya
adc
tay
tba
jmp clr_buf_st
clr_buf_end:
ldy.w zero
plb
rtl
start:
lda
sta $C000
tax
phy
tay
jsl clr_cbuf
ply
lda.w
jsl print_str
lda.w zero
jmp rset_a
clr_cbuf:
phb
ldb
clr_cbuf_st:
cpy.w
bcs clr_cbuf_end
sta.q (ptr6), y
tya
adc
tay
tba
sta.q (ptr6), y
tya
adc
tay
tba
sta.q (ptr6), y
tya
adc
tay
tba
sta.q (ptr6), y
tya
adc
tay
tba
jmp clr_cbuf_st
clr_cbuf_end:
plb
rtl
pull_y:
ply
rset_a:
lda
sta $C000
inc
read:
lda $C000
beq rset_a
jsl getchar
beq parse
jmp rset_a
print_str:
sta.q ptr
ldb
tba
inb
stb b
pntstr_st:
phy
txy
lda (ptr), y
beq pntstr_end
ply
inx
jsl print_char
jmp pntstr_st
pntstr_end:
ply
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:
jsl bitpos
ldb bitabl, x
aba
cmp
jmp bitout
clrbit:
jsl bitpos
xor
ldb bitabl, x
aba
bitsav:
sta bitabl, x
bitout:
ldx bitmask
rtl
setbit:
jsl bitpos
ldb bitabl, x
oab
jmp bitsav
bitpos:
pha
lda.w
sta.q ptr3
lda.w zero
pla
stx bitmask
txa
and
phy
tay
tax
lda (ptr3), y
ply
pha
lda bitmask
lsr
tax
pla
rtl
getchar:
lda $C002
ldb
stb e
stb b
pha
phy
cmp
beq cmd_cpy
getchar_pnt:
ply
pla
ldb e
bne reset_row
getchar_pnt1:
jsl print_char
lda a
cmp
beq getchar_line
jmp getchar_char
reset_row:
ldb e
stb scr_row
jmp getchar_pnt1
cmd_cpy:
ldb scr_row
stb e
jsl findst
clc
lda scr_row
adc scr_str
mul
tay
ldx.w
cmd_cpy_strt:
lda (ptr5), y
beq getchar_pnt
phy
txy
sta (ptr6), y
inx
ply
iny
jmp cmd_cpy_strt
getchar_line:
lda
jmp getchar_end
getchar_char:
lda
getchar_end:
rtl
findst:
jsl getbit
bcc findst_done
dec scr_row
bpo findst
inc scr_row
findst_done:
rtl
parse:
lda
tax
jsl dabbed
beq start
lda
tax
jmp result
print_char:
sta 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
sta a
printc:
lda (ptr5), y
beq printc_save
lda b
bne printc_save
sty.w scr_ptr
prntc_fndnd:
lda (ptr5), y
beq prntc_movln
iny
jmp prntc_fndnd
printc_updt:
jmp prntc_updt2
prntc_updt1:
pla
clc
adc scr_row
sta scr_row
jsl update_pos
prntc_updt2:
lda scr_row
pha
lda scr_col
pha
jsl rdrw_row
pla
sta scr_col
pla
sta scr_row
jsl update_pos
prntc_updt3:
ldb scr_row
lda scr_trow
sec
sab
pha
tab
sec
sab
clc
sta scr_row
prntc_updt4:
jsl getbit
bcs prntc_updt1
pla
lda scr_trow
sta scr_row
jsl update_pos
dec d
jmp printc_sav1
prntc_movln:
tyx
dey
ldb
stb d
jsl shftln
ldb
stb d
lda scr_row
sta scr_trow
printc_save:
ldb d
bne printc_updt
printc_sav1:
lda a
sta (ptr5), y
printc_inc:
inc scr_col
iny
printc_2:
ldb
stb f
ldb scr_col
cpb
bcs printc_4
printc_3:
sta $C001
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 $C001
clc
lda
sta wrapped
jsl scrl_down
printc_wrap:
ldb
stb scr_col
ldb scr_row
cpb
bcs printc_wrap2
printc_wrap1:
inc scr_row
printc_wrap2:
phx
clc
lda scr_row
adc scr_str
tax
jsl setbit
plx
jsl update_pos
printc_end:
rtl
nl:
lda
ldb (ptr5), y
bne nl1
sta (ptr5), y
nl1:
sta scr_col
lda scr_row
cmp
bne 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
jsl clr_buf
tay
jsl clr_cbuf
sta scr_col
sta scr_row
jsl update_pos
lda
sta $C001
jmp printc_end
en_step:
lda $C010
beq step_en
jmp stp_end
step_en:
lda
sta $C010
jmp stp_end
dis_step:
lda $C010
bne step_dis
jmp stp_end
step_dis:
lda
sta $C010
stp_end:
jmp printc_end
back:
dey
lda
sta (ptr5), y
tyx
iny
ldb
stb d
jsl shftln
lda
sta $C001
dec scr_col
jsl update_pos
jmp printc_end
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
jsl clrbit
ldb
stb scr_col
jsl update_pos
jmp back
shftln:
ldb d
beq shftln_lp1
jmp shftln_lp0
shftln_neg:
ldy.w zero
lda
sta (ptr5), 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 (ptr5), y
phy
txy
sta (ptr5), y
ply
lda
sta (ptr5), y
dey
bng shftln_neg
dex
jmp shftln_lp0
shftln_lp1:
lda (ptr5), y
beq shftln_end
phy
txy
sta (ptr5), y
inx
ply
lda
sta (ptr5), y
iny
jmp shftln_lp1
shftln_end:
rtl
esc:
lda $C000
lda $C002
cmp
beq shftesc
lda $C000
beq printc_end
lda $C002
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 $C000
lda $C000
beq printc_end
lda $C002
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
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
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
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 isshftup_done
lda
sta d
lda scr_str
beq isshftup_done
jmp shftup
isshftup_done:
rtl
isshftdown:
lda c
cmp
bne isshftdown_done
lda
sta d
lda scr_end
cmp
bcs isshftdown_done
jmp shftdown
isshftdown_done:
rtl
shftup:
jsl scrl_up
lda
sta d
jmp isshftup_done
shftdown:
jsl scrl_down
lda
sta d
jmp isshftdown_done
update_pos:
ldb
stb f
clc
lda scr_row
adc scr_str
tay
clc
lsl
tab
tya
lsl
aab
clc
adc scr_col
tay
lda
sta $C001
lda
sta $C001
jsl getrow
jsl getcol
lda
sta $C001
rtl
getrow:
lda scr_row
div
adc
sta $C001
tba
adc
sta $C001
rtl
getcol:
lda
sta $C001
lda scr_col
div
clc
adc
sta $C001
tba
clc
adc
sta $C001
rtl
scrl_down:
inc scr_str
inc scr_end
lda
sta $C001
lda
sta $C001
lda
sta $C001
lda wrapped
beq scrldn_save
scrldn1:
jsl rdrw_row
lda wrapped
beq scrldn_load
jmp scrldn_end
scrldn_save:
lda scr_row
pha
lda scr_col
pha
jmp scrldn1
scrldn_load:
pla
sta scr_col
pla
sta scr_row
jsl update_pos
scrldn_end:
lda
sta wrapped
scrldn_done:
rtl
scrl_up:
dec scr_str
dec scr_end
lda
sta $C001
lda
sta $C001
lda
sta $C001
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 (ptr5), y
beq rdrow_inc
sta $C001
rdrow_inc:
inc scr_col
lda (ptr5), y
beq rdrow_skip
rdrow_inc1:
iny
rdrow_inc2:
lda scr_col
cmp
bcs rdrow_end
jmp rdrow_st
rdrow_skip:
lda
sta $C001
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
sta.q ptr2
tba
dab_st:
phy
txy
lda (ptr6), 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
stx.q ptr
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
lda.w zero
cmd_clr:
lda
jsl print_char
jmp start
.org $FFC0
.qword reset
r
done