.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
pha.w
lda.d
pha.q
jsr clr_arr
pla.q
pla.w
and
jsr pnt_strt
lda
sta scr
bra start
clr_arr:
phb
ldb
clc
adc
pha.q
tba
@loop:
cpy.w sp+26
bcs @end
sta.q (sp+18), y
sta.q (sp+1), y
tya
adc
tay
tba
sta.q (sp+18), y
sta.q (sp+1), y
tya
adc
tay
tba
bra @loop
@end:
ldy.w zero
pla.q
tba
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.w
tay
lda.w
pha.w
lda.d
pha.q
jsr clr_arr
pla.q
pla.w
ply.w
and
sta end
bra read
read:
lda
sta end
inc end
lda status
beq read
jsr getchar
beq parse
bra read
parse:
lda
tax
jsr subasm
bra start
print_str:
ldx
pha.q
@loop:
ldb
stb b
and
phy.w
txy
lda (sp+3), y
ply.w
beq @end
inx
jsr print_char
bra @loop
@end:
pla.q
ldb
stb b
tba
rts
getbit:
clc
lda scr_str
bne getbt0
ldx scr_row
bra getbt1
getbt0:
lda scr_row
adc scr_str
tax
getbt1:
tab
lda.d
pha.q
tba
jsr bitpos
phy.w
txy
ldb (sp+3), y
ply.w
aba
cmp
bra bitout
clrbit:
tab
lda.d
pha.q
tba
jsr bitpos
xor
phy.w
txy
ldb (sp+3), y
aba
bitsav:
sta (sp+3), y
ply.w
bitout:
pla.q
and
ldx bitmask
rts
setbit:
tab
lda.d
pha.q
tba
jsr bitpos
phy.w
txy
ldb (sp+3), y
oab
bra bitsav
bitpos:
tab
lda.w
pha.q
tba
stx bitmask
txa
and
phy.w
tay
tax
lda (sp+3), y
ply.w
pha
lda bitmask
lsr
tax
pla
tab
pla.q
tba
rts
getchar:
lda kbd
ldb
stb e
stb b
pha
phy.w
cmp
bne @print
jsr cmd_cpy
@print:
ply.w
pla
ldb e
bne @row
@print1:
jsr print_char
lda a
cmp
beq @true
bra @false
@row:
ldb e
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 e
jsr findst
clc
lda scr_row
adc scr_str
mul
tay
ldx.w
ldb
lda.d
pha.q
lda.d
pha.q
tba
@loop:
ldb
lda.q (sp+9), y
@loop1:
phy.w
txy
sta (sp+3), y
inx
ply.w
cpx.w
bcs @end
iny
inb
lsr
stb g
tab
and
beq @end1
tba
ldb g
cpb
beq @loop
bra @loop1
@end:
ldb
phy.w
txy
stb (sp+3), y
ply.w
@end1:
pla.q
pla.q
tba
rts
findst:
lda
@loop:
pha
jsr getbit
pla
bcc @end
inc
dec scr_row
bpo @loop
dec
inc scr_row
@end:
cmp
rts
fndend:
lda.d
pha.q
phb
ldb
tba
plb
phy.w
@loop:
lda (sp+3), y
beq @end
iny
bra @loop
@end:
sty.w scr_ptr3
ply.w
pla.q
and
rts
findend:
jsr fndend
lda.w scr_ptr3
div
rts
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 @save
lda b
bne @save
sty.w scr_ptr
jsr fndend
bra @shift
@update:
lda scr_col
sta scr_tcol
@update1:
jsr findend
sta e
sta scr_row
jsr findst
lda scr_row
@update2:
sta f
jsr rdrw_ln
lda scr_trow
sta scr_row
lda scr_tcol
sta scr_col
jsr update_pos
dec d
bra @save1
@shift:
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
bra @update
@save:
ldb d
bne @update
@save1:
lda a
sta (ptr3), y
@incr:
inc scr_col
iny
@wrapped:
ldb
stb f
ldb scr_col
cpb
bcs @scrolled
@print:
sta scr
ldb f
beq @wrap
bra printc_end
@scrolled:
ldb scr_row
cpb
bcs @scroll
@wrapped2:
ldb
stb f
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 a
rts
clr_scr:
lda
sta scr_end
lda
sta scr_str
sta.q bitabl
sta.q bitabl+8
tay
lda.w
pha.w
lda.d
pha.q
jsr clr_arr
tay
pla.q
pla.w
lda.w
pha.w
lda.d
pha.q
jsr clr_arr
pla.q
pla.w
and
sta scr_col
sta 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 e
stb f
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 d
jsr shftln
lda
sta scr
lda e
beq @load
@find_end:
jsr findend
sta e
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 scr_row
sta f
inc e
bra @shift
shftln:
ldb d
beq @dec_loop
ldb
bra @inc_loop
@neg:
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 @neg
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 d
lda (ptr3), y
cmp
bne @end5
lda
sta (ptr3), y
@end2:
lda d
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 c
lda
sta d
jsr isup
lda d
bne @end
jsr isdown
lda d
bne @end
lda
jsr isleft
lda d
bne @end
jsr isright
@end:
lda
sta d
rts
shftesc:
lda status
lda kbd
lda status
beq @end
lda kbd
sta c
lda
sta d
jsr isshftup
lda d
bne @end
jsr isshftdown
@end:
lda
sta d
rts
isup:
lda c
cmp
bne @end
lda scr_row
beq @scroll
@check2:
lda c
cmp
beq @up
bra @end
@up:
dec scr_row
jsr update_pos
lda
sta d
rts
@scroll:
lda scr_str
beq @end
jsr scrl_up
lda
sta d
@end:
rts
isdown:
lda c
cmp
bne @end
lda scr_row
cmp
beq @scroll
lda c
cmp
beq @down
bra @end
@down:
inc scr_row
jsr update_pos
lda
sta d
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 d
@end:
rts
isright:
lda c
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 c
cmp
beq @end1
lda scr_col
beq @wrap
lda c
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 d
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 d
rts
@end:
jsr update_pos
@end1:
lda
sta wrapped
rts
isshftup:
lda c
cmp
bne @end
lda
sta d
lda scr_str
beq @end
@shftup:
jsr scrl_up
lda
sta d
@end:
rts
isshftdown:
lda c
cmp
bne @end
lda
sta d
lda scr_end
cmp
bcs @end
@shftdown:
jsr scrl_down
lda
sta d
@end:
rts
update_pos:
ldb
stb f
clc
lda scr_row
adc scr_str
tay
mul
clc
adc scr_col
tay
tba
lda
sta scr
lda
sta scr
jsr getrow
jsr getcol
lda
sta scr
rts
getrow:
lda scr_row
bra bcd
getcol:
lda
sta scr
lda scr_col
bcd:
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 f
sta scr_row
lda scr_col
pha
jsr update_pos
@loop:
lda scr_row
cmp e
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 e
sta f
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