.org $8000
reset:
cps
lds.d
lea 0
ldy
tyx
jsr init_heap
mov sp, a
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
mov d, e
jsr findramend
rts
init_tables:
lea d, SCRSIZE
jsr malloc
sta.q buffer
lea d, CMDSIZE
jsr malloc
sta.q cmd_buf
lea d, LWSIZE
jsr malloc
sta.q bitabl
rts
clr_arr:
pha.q
and
sub s,
@loop:
mov.q (d+s), a
mov.q (d+s+8), a
sub s,
bcs @loop
@end:
pla.q
rts
pnt_strt:
lea d, ed_name
jsr print_str
lea d, ver_str
jsr print_str
lea d, ed_ver
jsr print_str
lea d, ed_sver
jsr print_str
lea d, '\n'
lda
jsr print_char
lea d, made
jsr print_str
lea d, author
jsr print_str
lea d, '\n'
lda
jsr print_char
rts
clr_cmd:
and
tay
lea s, CMDSIZE
lea d, (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:
pha.q
phb.q
phx.q
and
mov b, d
tax
@loop:
mov regb,
xor d, d
mov d, (b+x)
beq @end
jsr update_ptr
tay
mov a, d
inx
jsr print_char
bra @loop
@end:
stz regb
and
tab
plx.q
plb.q
pla.q
rts
getbit:
des
add d, s
lea s, (sp+1)
jsr bitpos
ins
mov a, (bitabl)+a
and a, (s)
rts
clrbit:
pha.q
des
lea s, (sp+1)
jsr bitpos
ins
not (s)
and (bitabl)+a, (s)
pla.q
rts
setbit:
pha.q
phb.q
mov b, s
des
lea s, (sp+1)
jsr bitpos
ins
cpb
bne @clear
@set:
or (bitabl)+a, (s)
bra @end
@clear:
not (s)
and (bitabl)+a, (s)
@end:
plb.q
pla.q
rts
bitpos:
mov a, d
and d,
lsr
mov (s), (d+bits)
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
lea d, (buffer)
mov s, y
jsr get_endrow
sub scr_str
@start:
sta scr_row
sta rege
jsr findst
lda scr_row
add 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
@@loop:
phy.w
txy
sta (ptr2), y
inx
ply.w
cpx.w
bcs @@end
iny
inb
lsr
stb regg
tab
and
beq @@end
tba
ldb regg
cpb
beq @loop
bra @@loop
@@end:
ldb
phy.w
txy
stb (ptr2), y
ply.w
@end:
tab
rts
findst:
mov d, scr_row
mov s, scr_str
@loop:
jsr getbit
beq @end
inc d
dec scr_row
bpo @loop
dec d
inc scr_row
@end:
cmp d,
rts
find_end:
phb.q
phx.q
phy.q
mov a, s
div
tay
mov b, d
mov x, s
mov d, a
@loop:
xor s, s
iny
mov d, y
jsr getbit
bne @loop
@loop2_init:
tya
dec
mul
cmp a, x
mcc a, x
mov d, b
mov s, x
@loop2:
inc
cmp (d+a-1),
bne @loop2
@end:
ply.q
plx.q
plb.q
rts
get_endrow:
jsr find_end
div
rts
print_char:
phb.q
phx.q
phe.q
xor s, s
sta rega
lea b, 2
lda.q buffer
jsr set_ptr
deb
tba
lea d, ctrl_codes
mov s, rega
lea f, 0
jsr get_index
lea ct_jtb
mov.w e, (e+2*a)
deb
tba
jsr (e)
ple.q
plx.q
plb.q
rts
printc:
lda
sta regd
lda (ptr3), y
beq @save
lda regb
bne @save
bra @shift
@update:
lda scr_col
sta scr_tcol
@update1:
lea d, (buffer)
mov s, y
jsr get_endrow
mov d, a
mov s, scr_trow
lda scr_trow
@update2:
jsr rdrw_ln
lda scr_trow
sta scr_row
lda scr_tcol
sta scr_col
jsr update_pos
dec regd
bra @save1
@shift:
lea d, (buffer)
mov.w s, scr_ptr
lea f, 1
lea c, 1
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
inc.w scr_ptr
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
lda
sta wrapped
jsr scrl_down
@wrap:
ldb
stb scr_col
ldb scr_row
cpb
bcs @wrap2
@wrap1:
inc scr_row
@wrap2:
mov d, scr_row
add d, scr_str
lea s, 1
jsr setbit
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
lea s, LWSIZE
lea d, (bitabl)
jsr clr_arr
lea s, SCRSIZE
lea d, (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:
mov d, scr_row
mov s, scr_str
jsr getbit
bne @wrap1
rts
@wrap1:
lda scr_row
beq @wrap2
bra @wrap3
@wrap2:
lda scr_str
bne @scroll
rts
@scroll:
jsr scrl_up
inc scr_row
@wrap3:
lda scr_row
add 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
lea d, (buffer)
mov s, y
jsr get_endrow
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
lea d, (buffer)
mov s, y
lea f, 1
lea c, 0
jsr shftln
lda
sta scr
lda rege
beq @load
@find_end:
lea d, (buffer)
mov s, y
jsr get_endrow
mov d, a
mov s, scr_trow
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
inc rege
bra @shift
shftln:
pha.q
phb.q
phx.q
phy.q
phe.q
psh.q bp
mov x, d
mov y, s
mov e, f
and c, c
bne @find_end
cmp s, f
bcc @end
@find_end:
jsr find_end
sub a, c
tab
mov a, f
neg a
and c, c
mne a, f
lea bp, (b+a)
@copy:
add a, y
lea s, (x+y)
lea d, (x+a)
mov f, b
sub f, y
jsr memcpy_dir
@clear:
tya
and c, c
meq a, bp
lea d, (x+a)
xor s, s
mov f, e
jsr memset
@get_rows:
mov x, b
mov a, bp
div
mov e, a
mov r11, f
xor f, f
and c, c
meq f, b
tya
div
mov bp, a
and c, c
meq a, e
tay
txa
div
cmp bp, a
mcs a, bp
cmp r11,
adc
and c, c
mne a, e
tab
and c, c
bne @inc
cmp y, b
bcc @inc
@loop:
xor s, s
cmp y, b
beq @rem
bcs @end
bra @getbit
@rem:
and f, f
bne @end
@getbit:
mov d, y
jsr getbit
cmp a, c
beq @inc
@setbit:
mov d, y
mov s, c
jsr setbit
@inc:
iny
bra @loop
@end:
pul.q bp
ple.q
ply.q
plx.q
plb.q
pla.q
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
mov d, scr_row
mov s, scr_str
jsr getbit
bne @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:
mov d, scr_row
mov s, scr_str
jsr getbit
bne @decr
bra @end1
@decr:
lda scr_row
beq @@decr
lda
sta wrapped
dec scr_row
@@decr:
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:
lda scr_row
add scr_str
mul
add scr_col
sta.w scr_ptr
@end:
rts
update_pos:
phb.q
and
tab
ldb
stb regf
jsr update_ptr
tay
tba
mov scr,
mov scr,
jsr getrow
mov scr,
jsr getcol
mov scr,
plb.q
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
mov scr,
mov scr,
mov scr,
lda scr_row
pha
lda wrapped
beq @save
@redraw:
lea d, (buffer)
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
mov scr,
mov scr,
mov scr,
lda scr_row
pha
lda scr_col
pha
lda
sta scr_row
lea d, (buffer)
jsr rdrw_row
pla
sta scr_col
pla
sta scr_row
jsr update_pos
@end:
rts
rdrw_row:
pha.q
phb.q
stz scr_col
jsr update_pos
xor b, b
tya
tab
add b,
@loop:
cmp (d+a),
mne scr, (d+a)
meq scr,
inc
cmp b
bcc @loop
@end:
stz scr_col
jsr update_pos
plb.q
pla.q
rts
rdrw_ln:
pha.q
psh scr_row
psh scr_col
mov scr_row, s
jsr update_pos
mov a, d
lea d, (buffer)
@loop:
cmp scr_row, a
beq @redraw
bcs @end
@redraw:
jsr rdrw_row
@incr:
inc scr_row
bra @loop
@end:
pul scr_col
pul scr_row
jsr update_pos
pla.q
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