.org $8000
reset:
cps
lds.d
lea 0
ldy
tyx
jsr init_heap
tax
txs
sub.d
sta.q heapend
and
tax
clc
jsr init_tables
jsr clr_scr
jsr pnt_strt
bra start
init_heap:
lea HEAPORG
ste.q heapptr
jsr findramend
rts
init_tables:
and
lda.w
jsr malloc
sta.q buffer
and
lda.w
jsr malloc
sta.q cmd_buf
and
lda.w
jsr malloc
sta.q bitabl
and
rts
clr_arr:
stz.q (e)
ade
stz.q (e)
ade
sub
bcc @end
beq @end
bra clr_arr
@end:
rts
pnt_strt:
lea ed_name
jsr print_str
lea ver_str
jsr print_str
lea ed_ver
jsr print_str
lea ed_sver
jsr print_str
lda
jsr print_char
lea made
jsr print_str
lea author
jsr print_str
lda
jsr print_char
rts
clr_cmd:
and
tay
lda.w
lea (cmd_buf)
jsr clr_arr
rts
start:
lda TODO
sta status
tax
jsr clr_cmd
jsr update_ptr
tay
and
bra read
read:
jsr getchar
jsr handle_char
beq parse
bra read
parse:
and
tax
jsr subasm
bra start
getchar:
and
@loop:
lda status
beq @loop
lda kbd
@end:
rts
print_str:
and
tba
@loop:
ldb
stb regb
and
ldb (e)
beq @end
jsr update_ptr
tay
tba
ine
jsr print_char
bra @loop
@end:
stz regb
and
tab
rts
getbit:
clc
lda scr_str
bne getbt0
ldx scr_row
bra getbt1
getbt0:
lda scr_row
adc scr_str
tax
getbt1:
pha
ldb
lda.q bitabl
jsr set_ptr
lsr
pla
jsr bitpos
phy.w
txy
ldb (ptr2), y
ply.w
and b
cmp
bra bitout
clrbit:
pha
ldb
lda.q bitabl
jsr set_ptr
and
pla
jsr bitpos
xor
phy.w
txy
ldb (ptr2), y
and b
bitsav:
sta (ptr2), y
ply.w
bitout:
ldx bitmask
rts
setbit:
pha
ldb
lda.q bitabl
jsr set_ptr
and
pla
jsr bitpos
phy.w
txy
ldb (ptr2), y
ora b
bra bitsav
bitpos:
pha
ldb
lda.w
jsr set_ptr
and
pla
stx bitmask
txa
and
phy.w
tay
tax
lda (ptr), y
ply.w
pha
lda bitmask
lsr
tax
pla
rts
handle_char:
ldb
stb rege
stb regb
pha
phy.w
cmp
bne @print
jsr cmd_cpy
@print:
ply.w
pla
ldb rege
bne @row
@print1:
jsr print_char
lda rega
cmp
beq @true
bra @false
@row:
ldb rege
cpb
beq @row2
bcs @row1
bra @row2
@row1:
ldb
@row2:
stb scr_row
bra @print1
@true:
lda
bra @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 rege
jsr findst
clc
lda scr_row
adc scr_str
mul
tay
ldx.w
ldb
lda.q buffer
jsr set_ptr
inb
lda.q cmd_buf
jsr set_ptr
deb
tba
@loop:
ldb
lda.q (ptr), y
@loop1:
phy.w
txy
sta (ptr2), y
inx
ply.w
cpx.w
bcs @end
iny
inb
lsr
stb regg
tab
and
beq @end1
tba
ldb regg
cpb
beq @loop
bra @loop1
@end:
ldb
phy.w
txy
stb (ptr2), y
ply.w
@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.q buffer
jsr set_ptr
tba
plb
phy.w
@loop:
lda (ptr), y
beq @end
iny
bra @loop
@end:
sty.w scr_ptr3
ply.w
rts
findend:
jsr fndend
lda.w scr_ptr3
div
rts
print_char:
phe.q
sta rega
ldb
lda.q buffer
jsr set_ptr
deb
tba
lda rega
jsr get_ctrlidx
lsl
tax
lea.w (ct_jtb, x)
deb
tba
jsr (e)
ple.q
rts
printc:
lda
sta regd
lda (ptr3), y
beq @save
lda regb
bne @save
sty.w scr_ptr
jsr fndend
bra @shift
@update:
lda scr_col
sta scr_tcol
@update1:
jsr findend
sta rege
lda scr_trow
@update2:
sta regf
jsr rdrw_ln
lda scr_trow
sta scr_row
lda scr_tcol
sta scr_col
jsr update_pos
dec regd
bra @save1
@shift:
ldy.w scr_ptr3
inc scr_ptr3
tyx
dey
ldb
stb regd
jsr shftln
ldb
stb regd
lda rega
sta (ptr3), y
lda scr_row
sta scr_trow
bra @update
@save:
ldb regd
bne @update
@save1:
lda rega
sta (ptr3), y
@incr:
inc scr_col
iny
@wrapped:
ldb
stb regf
ldb scr_col
cpb
bcs @scrolled
@print:
sta scr
ldb regf
beq @wrap
bra printc_end
@scrolled:
ldb scr_row
cpb
bcs @scroll
@wrapped2:
ldb
stb regf
bra @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.w
clc
lda scr_row
adc scr_str
tax
jsr setbit
plx.w
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
bra @end
@incr:
inc scr_row
jsr update_pos
@end:
lda
sta rega
rts
clr_scr:
lda
sta scr_end
stz scr_str
tay
lda.w
lea (bitabl)
jsr clr_arr
lda.w
lea (buffer)
jsr clr_arr
stz scr_col
stz scr_row
jsr update_pos
lda
sta scr
rts
en_step:
lda step
beq step_en
rts
step_en:
lda
sta step
rts
dis_step:
lda step
bne step_dis
rts
step_dis:
lda
sta step
rts
bs:
lda scr_col
beq @wrap
bra back
@wrap:
jsr getbit
bcs @wrap1
rts
@wrap1:
lda scr_row
beq @wrap2
bra @wrap3
@wrap2:
lda scr_str
bne @scroll
rts
@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
back:
ldb
stb rege
stb regf
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 regd
jsr shftln
lda
sta scr
lda rege
beq @load
@find_end:
jsr findend
sta rege
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
rts
@update:
lda (ptr3), y
beq @shift
lda scr_trow
sta regf
inc rege
bra @shift
shftln:
ldb regd
beq @dec_loop
ldb
bra @inc_loop
@minus:
ldy.w zero
stb (ptr3), y
bra @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.w
txy
sta (ptr3), y
ply.w
stb (ptr3), y
bng @minus
dey
dex
bra @inc_loop
@dec_loop:
stx.w scr_ptr2
lda (ptr3), y
beq @end3
phy.w
txy
sta (ptr3), y
inx
ply.w
stb (ptr3), y
iny
bra @dec_loop
@wrap:
tax
jsr setbit
bra @end5
@wrap1:
tax
jsr clrbit
bra @end5
@end:
lda (ptr3), y
bne @end1
lda
sta (ptr3), y
@end1:
jsr findend
sta regd
lda (ptr3), y
cmp
bne @end5
lda
sta (ptr3), y
@end2:
lda regd
cmp scr_row
beq @end5
bcs @wrap
bra @end5
@end3:
jsr findend
cpb
beq @end4
bra @end5
@end4:
cmp scr_row
beq @end5
bcs @wrap1
@end5:
rts
esc:
lda status
lda kbd
cmp
beq shftesc
lda status
beq @end
lda kbd
sta regc
lda
sta regd
jsr isup
lda regd
bne @end
jsr isdown
lda regd
bne @end
lda
jsr isleft
lda regd
bne @end
jsr isright
@end:
lda
sta regd
rts
shftesc:
lda status
lda kbd
lda status
beq @end
lda kbd
sta regc
lda
sta regd
jsr isshftup
lda regd
bne @end
jsr isshftdown
@end:
lda
sta regd
rts
isup:
lda regc
cmp
bne @end
lda scr_row
beq @scroll
@check2:
lda regc
cmp
beq @up
bra @end
@up:
dec scr_row
jsr update_pos
lda
sta regd
rts
@scroll:
lda scr_str
beq @end
jsr scrl_up
lda
sta regd
@end:
rts
isdown:
lda regc
cmp
bne @end
lda scr_row
cmp
beq @scroll
lda regc
cmp
beq @down
bra @end
@down:
inc scr_row
jsr update_pos
lda
sta regd
rts
@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 regd
@end:
rts
isright:
lda regc
cmp
bne @end2
lda scr_col
cmp
beq @wrap
bra @right
@wrap:
inc scr_row
jsr getbit
bcs @incr
dec scr_row
bra @end2
@scroll:
lda scr_str
beq @end
lda
sta wrapped
jsr scrl_down
bra @end
@incr:
lda
sta scr_col
lda scr_row
cmp
beq @end1
bcs @scroll
bra @end1
@right:
inc scr_col
jsr update_pos
rts
@end:
dec scr_row
@end1:
jsr update_pos
@end2:
lda
sta wrapped
rts
isleft:
lda regc
cmp
beq @end1
lda scr_col
beq @wrap
lda regc
cmp
beq @left
bra @end1
@wrap:
jsr getbit
bcs @decr
bra @end1
@decr:
lda scr_row
beq @decr1
lda
sta wrapped
dec scr_row
@decr1:
lda
sta scr_col
lda
sta regd
lda scr_row
beq @scroll
bra @end
@scroll:
lda wrapped
bne @end
lda scr_str
beq @end1
jsr scrl_up
bra @end1
@left:
dec scr_col
jsr update_pos
lda
sta regd
rts
@end:
jsr update_pos
@end1:
lda
sta wrapped
rts
isshftup:
lda regc
cmp
bne @end
lda
sta regd
lda scr_str
beq @end
@shftup:
jsr scrl_up
lda
sta regd
@end:
rts
isshftdown:
lda regc
cmp
bne @end
lda
sta regd
lda scr_end
cmp
bcs @end
@shftdown:
jsr scrl_down
lda
sta regd
@end:
rts
update_ptr:
clc
lda scr_row
adc scr_str
mul
clc
adc scr_col
@end:
rts
update_pos:
ldb
stb regf
jsr update_ptr
tay
tba
lda
sta scr
lda
sta scr
jsr getrow
lda
sta scr
jsr getcol
lda
sta scr
rts
getrow:
lda scr_row
bra bcd
getcol:
lda scr_col
bcd:
inc
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
bra @end
@save:
lda scr_col
pha
bra @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
bra @loop
@skip:
lda
sta scr
bra @incr1
@end:
lda
sta scr_col
jsr update_pos
@end1:
rts
rdrw_ln:
lda scr_row
pha
lda regf
sta scr_row
lda scr_col
pha
jsr update_pos
@loop:
lda scr_row
cmp rege
beq @loop1
bcs @end
@loop1:
jsr rdrw_row
@incr:
inc scr_row
bra @loop
@end:
pla
sta scr_col
pla
sta scr_row
jsr update_pos
lda
sta rege
sta regf
rts
set_ptr:
cpb
beq @ptr2
cpb
beq @ptr3
@ptr1:
stb.q ptr
sta.q ptr
bra @end
@ptr2:
stb.q ptr2
sta.q ptr2
bra @end
@ptr3:
stb.q ptr3
sta.q ptr3
@end:
rts