generalized lisbox routines, fixed msg_read, can now switch mailboxes

This commit is contained in:
Iris Lightshard 2023-03-18 01:18:02 -06:00
parent ad0d627418
commit b9267e5130
Signed by: nilix
GPG key ID: 3B7FBC22144E6398
2 changed files with 262 additions and 119 deletions

View file

@ -33,6 +33,7 @@ module Taro
@stdin_w : IO::FileDescriptor @stdin_w : IO::FileDescriptor
@stdin_r : IO::FileDescriptor @stdin_r : IO::FileDescriptor
@decoding : Bool = false @decoding : Bool = false
@sizing : Bool = false
@szshort : UInt16 = 0 @szshort : UInt16 = 0
def initialize(w : WinType = WinType::LIST) def initialize(w : WinType = WinType::LIST)
@ -73,13 +74,19 @@ module Taro
def write_msg(msgtype : UInt8, data : Slice) def write_msg(msgtype : UInt8, data : Slice)
msgsz = UInt16.new(data.size > 16384 ? 16384 : data.size) msgsz = UInt16.new(data.size > 16384 ? 16384 : data.size)
msgtype.to_io(@stdin_w, IO::ByteFormat::BigEndian) msgtype.to_io(@stdin_w, IO::ByteFormat::BigEndian)
msgsz.to_io(@stdin_w, IO::ByteFormat::BigEndian) if msgsz != 0
msgsz.to_io(@stdin_w, IO::ByteFormat::BigEndian)
else
8_u16.to_io(@stdin_w, IO::ByteFormat::BigEndian)
end
if msgsz == 16384 if msgsz == 16384
@stdin_w.write(data[0..msgsz - 2]) @stdin_w.write(data[0..msgsz - 2])
10_u8.to_io(@stdin_w, IO::ByteFormat::BigEndian) 10_u8.to_io(@stdin_w, IO::ByteFormat::BigEndian)
else elsif msgsz != 0
@stdin_w.write(data[0..msgsz - 1]) @stdin_w.write(data[0..msgsz - 1])
else
@stdin_w.write("nothing\n".to_slice)
end end
end end
@ -88,22 +95,28 @@ module Taro
data : Slice(UInt8) = Slice(UInt8).new(0) data : Slice(UInt8) = Slice(UInt8).new(0)
loop do loop do
if @stdout_r.closed? if @stdout_r.closed?
@decoding = false
@sizing = false
@szshort = 0
break break
end end
if !@decoding if !@decoding
msgType = @stdout_r.read_byte || 0_u8 msgType = @stdout_r.read_byte || 0_u8
@decoding = true @decoding = true
elsif @szshort == 0 @sizing = true
elsif @sizing
szslice = Slice(UInt8).new(2) szslice = Slice(UInt8).new(2)
@stdout_r.read_fully(szslice) @stdout_r.read_fully(szslice)
szlow : UInt16 = UInt16.new(szslice[0])*256 szlow : UInt16 = UInt16.new(szslice[0])*256
szhigh : UInt16 = UInt16.new(szslice[1]) szhigh : UInt16 = UInt16.new(szslice[1])
@szshort = szlow + szhigh @szshort = szlow + szhigh
@sizing = false
else else
slc = Slice(UInt8).new(@szshort) slc = Slice(UInt8).new(@szshort)
@stdout_r.read_fully(slc) @stdout_r.read_fully(slc)
@decoding = false @decoding = false
data = slc data = slc
szshort = 0
break break
end end
end end
@ -118,25 +131,28 @@ module Taro
def initialize def initialize
@mailbox = "INBOX" @mailbox = "INBOX"
end end
private def run_cmd(cmdtxt : String) : String
puts cmdtxt
io = IO::Memory.new
Process.run(cmdtxt, shell: true, output: io)
return io.to_s
end
def list_mail(box : String = "INBOX") def list_mail
mailCmd = " mailCmd = "
mbox=${MBOX_ROOT}/#{box} mbox=${MBOX_ROOT}/#{@mailbox}
mdirs ${mbox} | xargs minc > /dev/null mdirs ${mbox} | xargs minc > /dev/null
mlist ${mbox} | msort -dr | mseq -S | mscan" mlist ${mbox} | msort -dr | mseq -S | mscan"
io = IO::Memory.new return run_cmd(mailCmd)
Process.run(mailCmd, shell: true, output: io)
return io.to_s
end end
def list_mboxes def list_mboxes
mailCmd ="for x in $(mdirs ${MBOX_ROOT}); do echo ${x#$MBOX_ROOT/}; done" mailCmd ="echo 'INBOX' ; for x in $(mdirs -a ${MBOX_ROOT} | sort | grep -v INBOX); do echo ${x#$MBOX_ROOT/}; done"
io = IO::Memory.new return run_cmd(mailCmd)
Process.run(mailCmd, shell: true, output: io)
return io.to_s
end end
def set_mbox(box : String) def set_mbox(box : String)
@ -158,7 +174,8 @@ module Taro
@mblaze = MblazeProxy.new @mblaze = MblazeProxy.new
list = @mblaze.list_mail list = @mblaze.list_mail
mboxes = @mblaze.list_mboxes
@lsWin.write_msg(0_u8, mboxes.to_slice)
@lsWin.write_msg(2_u8, list.to_slice) @lsWin.write_msg(2_u8, list.to_slice)
end end
@ -189,7 +206,9 @@ loop do
exit exit
when m = taro.mainWindow.msg.receive when m = taro.mainWindow.msg.receive
case m.type case m.type
when 1 then taro.mblaze.set_mbox(m.data.to_s) when 1 then
taro.mblaze.set_mbox(String.new(m.data))
taro.mainWindow.write_msg(2_u8, taro.mblaze.list_mail.to_slice)
end end
end end
end end

View file

@ -8,9 +8,21 @@
( UI constants ) ( UI constants )
%TOP_SECTION { #0020 } %TOP_SECTION { #0040 }
%MID_SEPARATOR { #0008 }
%BOTTOM_SECTION { #0040 } %BOTTOM_SECTION { #0040 }
%LB_DATA { #02 ADD }
%LB_LEN { #04 ADD }
%LB_OFFSET { #06 ADD }
%LB_ELEM_OFFSET { #08 ADD }
%LB_TOP { #09 ADD }
%LB_HEIGHT { #0b ADD }
%LB_SELECT_IDX { #0c ADD }
%SB_LEN { #0e ADD }
%SB_POS { #0f ADD }
%SB_STEP { #11 ADD }
|00 @System &vector $2 &wst $1 &rst $1 &eaddr $2 &ecode $1 &pad $1 &r $2 &g $2 &b $2 &debug $1 &halt $1 |00 @System &vector $2 &wst $1 &rst $1 &eaddr $2 &ecode $1 &pad $1 &r $2 &g $2 &b $2 &debug $1 &halt $1
|10 @Console &vector $2 &read $1 &pad $5 &write $1 &error $1 |10 @Console &vector $2 &read $1 &pad $5 &write $1 &error $1
|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 |20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
@ -31,9 +43,12 @@
@refresh [ &mboxes $1 &list $1 &fg $1 ] @refresh [ &mboxes $1 &list $1 &fg $1 ]
@resizing [ $1 &x $2 &y $2 &dx $2 &dy $2 ] @resizing [ $1 &x $2 &y $2 &dx $2 &dy $2 ]
@decoding [ $1 &msg_type $1 &counting $1 &count $2 &processed $2 ] @decoding [ $1 &msg_type $1 &counting $1 &count $2 &processed $2 ]
@mboxes [ &bytes $2 &len $1 &offset $2 &elem_offset $1 &top $2 &height $1 &select_index $2 &sb_len $1 &sb_pos $2 &sb_step $2 ] @mboxes [ &bytes $2 &data $2 &len $2 &offset $2 &elem_offset $1
@list [ &bytes $2 &len $1 &offset $2 &elem_offset $1 &top $2 &height $1 &select_index $2 &sb_len $1 &sb_pos $2 &sb_step $2 ] &top $2 &height $1 &select_index $2
@sb [ &len $1 &pos $2 &step $2 ] &sb_len $1 &sb_pos $2 &sb_step $2 ]
@list [ &bytes $2 &data $2 &len $2 &offset $2 &elem_offset $1
&top $2 &height $1 &select_index $2
&sb_len $1 &sb_pos $2 &sb_step $2 ]
( program ) ( program )
@ -44,10 +59,14 @@
#0a8d .System/g DEO2 #0a8d .System/g DEO2
#098d .System/b DEO2 #098d .System/b DEO2
#0180 .Screen/width DEO2 #0300 .Screen/width DEO2
#0200 .Screen/height DEO2 #0200 .Screen/height DEO2
.Screen/height DEI2 TOP_SECTION BOTTOM_SECTION ADD2 SUB2 #03 SFT2 NIP .list/height STZ ;list_data .list/data STZ2
;mbox_data .mboxes/data STZ2
.Screen/height DEI2 TOP_SECTION BOTTOM_SECTION ADD2 MID_SEPARATOR ADD2 SUB2 #03 SFT2 NIP .list/height STZ
TOP_SECTION #03 SFT2 NIP .mboxes/height STZ
#01 .refresh/fg STZ #01 .refresh/fg STZ
;on_screen .Screen/vector DEO2 ;on_screen .Screen/vector DEO2
@ -71,25 +90,31 @@ BRK
( decode data ) ( decode data )
.Console/read DEI .Console/read DEI
.decoding/msg_type LDZ .decoding/msg_type LDZ
DUP MBOX_LIST NEQ ,&no_mbox_list JCN
POP ;mbox_data .decoding/processed LDZ2 ADD2 STA
decode_inc_count .mboxes/bytes STZ2
,&count JMP
&no_mbox_list
DUP MAIL_LIST NEQ ,&no_mail_list JCN DUP MAIL_LIST NEQ ,&no_mail_list JCN
POP ;list_data .decoding/processed LDZ2 ADD2 STA
POP ;list_data .decoding/processed LDZ2 ADD2 STA
decode_inc_count .list/bytes STZ2 decode_inc_count .list/bytes STZ2
,&count JMP ,&count JMP
#01 .refresh/list STZ
&no_mail_list &no_mail_list
POP POP
&count &count
decode_is_done ,&done JCN decode_is_done ,&done JCN
BRK BRK
&done &done
#0000 DUP2 .decoding/count STZ2 .decoding/processed STZ2 #00 .decoding STZ #0000 DUP2 .decoding/count STZ2 .decoding/processed STZ2 #00 .decoding STZ
BRK BRK
&count_1 &count_1
.Console/read DEI .decoding/count STZ .Console/read DEI .decoding/count STZ
#02 .decoding/counting STZ #02 .decoding/counting STZ
BRK BRK
&count_2 &count_2
.Console/read DEI .decoding/count INC STZ .Console/read DEI .decoding/count INC STZ
#00 .decoding/counting STZ #00 .decoding/counting STZ
@ -101,13 +126,21 @@ BRK
JMP2r JMP2r
@decode_is_done ( -- bit ) @decode_is_done ( -- bit )
.decoding/processed LDZ2 .decoding/count LDZ2 EQU2 DUP ,&refresh_ui JCN
JMP2r
&refresh_ui
.list/bytes LDZ2 .decoding/count LDZ2 NEQ2 ,&no_list JCN
#01 .refresh/list STZ #01 .refresh/list STZ
.decoding/processed LDZ2 .decoding/count LDZ2 EQU2 &no_list
.mboxes/bytes LDZ2 .decoding/count LDZ2 NEQ2 ,&no_mbox JCN
#01 .refresh/mboxes STZ
&no_mbox
JMP2r JMP2r
@on_mouse ( -> ) @on_mouse ( -> )
#01 .refresh/fg STZ
get_select_idx_by_mouse ;mbox_select_handler .mboxes .refresh/mboxes #0000 mouse_event_list
;noop_list_click .list .refresh/list TOP_SECTION MID_SEPARATOR ADD2 mouse_event_list
.resizing LDZ #00 EQU ,&resz_check JCN .resizing LDZ #00 EQU ,&resz_check JCN
( resizing ) ( resizing )
@ -129,6 +162,7 @@ JMP2r
.Mouse/x DEI2 .resizing/x STZ2 .Mouse/x DEI2 .resizing/x STZ2
.Mouse/y DEI2 .resizing/y STZ2 .Mouse/y DEI2 .resizing/y STZ2
&done &done
#01 .refresh/fg STZ
BRK BRK
@handle_rsz ( -- mousestate ) @handle_rsz ( -- mousestate )
@ -159,19 +193,28 @@ BRK
&chk_release &chk_release
#01 .refresh/list STZ #01 .refresh/list STZ
.Screen/height DEI2 TOP_SECTION BOTTOM_SECTION ADD2 SUB2 #03 SFT2 NIP .list/height STZ #01 .refresh/mboxes STZ
.Screen/height DEI2 TOP_SECTION BOTTOM_SECTION ADD2 MID_SEPARATOR ADD2 SUB2 #03 SFT2 NIP .list/height STZ
.Mouse/state DEI .Mouse/state DEI
JMP2r JMP2r
@on_screen ( -> ) @on_screen ( -> )
.refresh/mboxes LDZ #00 EQU ,&no_mboxes JCN
#0000 .mboxes/height LDZ clear_listbox
.mboxes #0000 draw_listbox
.mboxes #0000 draw_scrollbar
#00 .refresh/mboxes STZ
&no_mboxes
.refresh/list LDZ #00 EQU ,&no_list JCN .refresh/list LDZ #00 EQU ,&no_list JCN
draw_mail_list [ TOP_SECTION MID_SEPARATOR ADD2 ] .list/height LDZ clear_listbox
draw_scrollbar .list [ TOP_SECTION MID_SEPARATOR ADD2 ] draw_listbox
.list [ TOP_SECTION MID_SEPARATOR ADD2 ] draw_scrollbar
#00 .refresh/list STZ #00 .refresh/list STZ
&no_list &no_list
.refresh/fg LDZ #00 EQU ,&no_fg JCN .refresh/fg LDZ #00 EQU ,&no_fg JCN
clear_fg clear_fg
draw_resize_handle draw_resize_handle
@ -183,20 +226,37 @@ BRK
@clear_fg ( -> ) @clear_fg ( -> )
;blank .Screen/addr DEO2
.Screen/width DEI2 #0000 &whilex EQU2k ,&endx JCN .Screen/width DEI2 #0000 &whilex EQU2k ,&endx JCN
DUP2 ,&x STR2 DUP2 ,&x STR2
.Screen/height DEI2 #0000 &whiley EQU2k ,&endy JCN .Screen/height DEI2 #0000 &whiley EQU2k ,&endy JCN
DUP2 ,&y STR2 DUP2 .Screen/y DEO2
,&x LDR2 .Screen/x DEO2 ,&x LDR2 .Screen/x DEO2
,&y LDR2 .Screen/y DEO2
;blank .Screen/addr DEO2
#41 .Screen/sprite DEO #41 .Screen/sprite DEO
#0008 ADD2 ,&whiley JMP &endy POP2 POP2 #0008 ADD2 ,&whiley JMP &endy POP2 POP2
#0008 ADD2 ,&whilex JMP &endx POP2 POP2 #0008 ADD2 ,&whilex JMP &endx POP2 POP2
JMP2r JMP2r
&x $2 &x $2
&y $2
@clear_listbox ( top* height -- )
#00 SWP #30 SFT2
,&height STR2
,&top STR2
;blank .Screen/addr DEO2
.Screen/width DEI2 #0008 SUB2 #0000 &whilex EQU2k ,&endx JCN
DUP2 ,&x STR2
,&top LDR2 ,&height LDR2 ADD2 ,&top LDR2 &whiley EQU2k ,&endy JCN
DUP2 .Screen/y DEO2
,&x LDR2 .Screen/x DEO2
#00 .Screen/sprite DEO
#0008 ADD2 ,&whiley JMP &endy POP2 POP2
#0008 ADD2 ,&whilex JMP &endx POP2 POP2
JMP2r
&x $2
&top $2
&height $2
@draw_resize_handle ( -> ) @draw_resize_handle ( -> )
@ -207,7 +267,7 @@ JMP2r
JMP2r JMP2r
@strlen ( addr -- len ) @strlen ( addr* -- len* )
DUP2 DUP2
&loop &loop
@ -216,40 +276,41 @@ JMP2r
JMP2r JMP2r
@store_char ( char -- char ) @store_char ( char list_e_offset -- char )
#00 .list/elem_offset LDZ ;word ADD2 STA SWP OVR LDZ #00 SWP ;word ADD2 STA
.list/elem_offset LDZ INC .list/elem_offset STZ LDZk INC SWP STZ
JMP2r JMP2r
@shouldnt_draw_word ( -- flag ) @shouldnt_draw_word ( list -- flag )
.list/offset LDZ2 .list/top LDZ2 LTH2 ,&no JCN DUP LB_OFFSET LDZ2 DUP2
.list/offset LDZ2 .list/top LDZ2 #00 .list/height LDZ ADD2 #0001 SUB2 GTH2 ,&no JCN STH2 ROT STHk LB_TOP LDZ2 LTH2 ,&clear_rtn JCN
STHr DUP LB_TOP LDZ2 ROT LB_HEIGHT LDZ #00 SWP ADD2 #0001 SUB2 STH2r SWP2 GTH2 ,&no_draw JCN
#00 JMP2r #00 JMP2r
&no &clear_rtn
POP2r POPr
&no_draw
#01 #01
JMP2r JMP2r
@draw_list_elem ( -> ) @draw_list_elem ( list -- )
STHk
( ;get_entry_color JSR2 #0c NEQ ,&no_store_cart JCN get_entry_color STH
;store_cart JSR2 )
&no_store_cart
[ ;word [ ;word
.Screen/x DEI2 .Screen/x DEI2
.Screen/y DEI2 .Screen/y DEI2
get_entry_color ] draw_str STHr ] draw_str
finish_line STHr finish_line
JMP2r JMP2r
@get_entry_color ( -- colorByte ) @get_entry_color ( list -- colorByte )
.list/offset LDZ2 DUP LB_OFFSET LDZ2
.list/select_index LDZ2 ROT LB_SELECT_IDX LDZ2
NEQ2 ,&normal JCN NEQ2 ,&normal JCN
@ -259,55 +320,50 @@ JMP2r
#03 #03
JMP2r JMP2r
@finish_line ( -> ) @finish_line ( list -- )
STH
;blank .Screen/addr DEO2 ;blank .Screen/addr DEO2
&while &while
.Screen/x DEI2 .Screen/x DEI2
.Screen/width DEI2 #0010 SUB2 .Screen/width DEI2 #0010 SUB2
GTH2 ,&end JCN GTH2 ,&end JCN
get_entry_color .Screen/sprite DEO STHkr get_entry_color .Screen/sprite DEO
.Screen/x DEI2 #0008 ADD2 .Screen/x DEO2 .Screen/x DEI2 #0008 ADD2 .Screen/x DEO2
,&while JMP &end ,&while JMP &end
POPr
JMP2r JMP2r
@draw_mail_list ( -> ) @draw_listbox ( .list ypos* -- )
#0000 .Screen/x DEO2 #0000 .Screen/x DEO2
TOP_SECTION .Screen/y DEO2 ( ypos ) .Screen/y DEO2
.decoding LDZ #01 NEQ ,&proceed JCN ( .list ) STH
;loading .Screen/x DEI2 .Screen/y DEI2 #03 draw_str &begin
JMP2r #0000 STHkr LB_OFFSET STZ2
&proceed STHkr LDZ2 #0000 &while EQU2k ,&end JCN
DUP2 STHkr LB_DATA LDZ2 ADD2 LDA
#0000 .list/offset STZ2
.list/bytes LDZ2 #0000 &while EQU2k ,&end JCN
DUP2 ;list_data ADD2 LDA
DUP #00 EQU ,&end JCN DUP #00 EQU ,&end JCN
( if not newline, store the character and increment the offsets ) ( if not newline, store the character and increment the offsets )
DUP #0a EQU ,&inc_line JCN DUP #0a EQU ,&inc_line JCN
;store_char JSR2 STHkr LB_ELEM_OFFSET store_char
,&continue JMP ( continue looping ) ,&continue JMP ( continue looping )
&inc_line &inc_line
POP #0000 .list/elem_offset LDZ ;word ADD2 STA POP #0000 STHkr LB_ELEM_OFFSET LDZ ;word ADD2 STA
shouldnt_draw_word ,&no_draw JCN STHkr shouldnt_draw_word ,&no_draw JCN
draw_list_elem STHkr draw_list_elem
#0000 .Screen/x DEO2 #0000 .Screen/x DEO2
.Screen/y DEI2 #0008 ADD2 .Screen/y DEO2 .Screen/y DEI2 #0008 ADD2 .Screen/y DEO2
&no_draw &no_draw
.list/offset LDZ2 INC2 .list/offset STZ2 STHkr LB_OFFSET LDZ2 INC2 STHkr LB_OFFSET STZ2
#ff #00 &word_clr EQUk ,&end_clr JCN #00 STHkr LB_ELEM_OFFSET STZ
#00 OVR SWP DUP ROT ;word ADD2 STA
INC ,&word_clr JMP &end_clr POP2
#00 .list/elem_offset STZ
&continue INC2 ,&while JMP &continue INC2 ,&while JMP
&end &end
.list/offset LDZ2 #0001 SUB2 .list/len STZ2 POP2 POP2 STHkr LB_OFFSET LDZ2 #0001 SUB2 STHr LB_LEN STZ2 POP2 POP2
JMP2r JMP2r
@ -324,107 +380,172 @@ JMP2r
SWP ,&byte JSR SWP ,&byte JSR
&byte ( byte -- ) DUP #04 SFT ,&char JSR &byte ( byte -- ) DUP #04 SFT ,&char JSR
&char ( char -- ) #0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO &char ( char -- ) #0f AND DUP #09 GTH #27 MUL ADD #30 ADD .Console/error DEO
JMP2r JMP2r
@print_str ( str* -- ) @print_str ( str* -- )
&while &while
LDAk #18 DEO LDAk .Console/write DEO
INC2 LDAk ,&while JCN INC2 LDAk ,&while JCN
POP2 POP2
JMP2r JMP2r
@get_select_idx_by_mouse ( -> ) @debug ( str* -- )
&while
LDAk .Console/error DEO
INC2 LDAk ,&while JCN
POP2
JMP2r
@mouse_event_list ( clickhandler* list refresh ypos* -- )
,&y STR2
,&r STR
STH
( check bounds )
.Mouse/x DEI2 .Screen/width DEI2 #0008 SUB2 GTH2 ,&done JCN
.Mouse/y DEI2 ,&y LDR2 LTH2 ,&done JCN
.Mouse/y DEI2 ,&y LDR2 [ STHkr LB_HEIGHT LDZ #00 SWP #30 SFT2 ] ADD2 GTH2 ,&done JCN
( check scrollwheel )
.Mouse/scrolly DEI2 #0000 EQU2 ,&no_scroll JCN .Mouse/scrolly DEI2 #0000 EQU2 ,&no_scroll JCN
.Mouse/scrolly DEI2 #0001 EQU2 ,&scroll_down JCN .Mouse/scrolly DEI2 #0001 EQU2 ,&scroll_down JCN
( scroll_up ) ( scroll_up )
;try_scroll_up_mouse JSR2 STHkr try_scroll_up_mouse
,&no_scroll JMP ,&no_scroll JMP
&scroll_down &scroll_down
;try_scroll_down_mouse JSR2 STHkr try_scroll_down_mouse
&no_scroll &no_scroll
.Mouse/x DEI2 #0008 LTH2 ,&done JCN ( select entry )
.Mouse/x DEI2 .Screen/width DEI2 #0008 SUB2 GTH2 ,&done JCN
.Mouse/y DEI2 TOP_SECTION LTH2 ,&done JCN
.Mouse/y DEI2 .Screen/height DEI2 BOTTOM_SECTION SUB2 GTH2 ,&done JCN
.Mouse/y DEI2 TOP_SECTION SUB2 #03 SFT2 .list/top LDZ2 ADD2 .list/select_index STZ2
#01 .refresh/list STZ ( click handler here )
.Mouse/state DEI #00 EQU ,&no_click JCN .Mouse/state DEI #01 AND #00 EQU ,&done JCN
.list/select_index LDZ2 .list/len LDZ2 GTH2 ,&no_click JCN .Mouse/y DEI2 ,&y LDR2 SUB2 #03 SFT2 STHkr LB_TOP LDZ2 ADD2 STHkr LB_SELECT_IDX STZ2
&no_click STHr ROT ROT JSR2
JMP2r #01 ,&r LDR STZ
( click handler here ) JMP2r
&y $2
&r $1
&done &done
#01 ,&r LDR STZ
POPr
POP2
JMP2r
@mbox_select_handler ( list -- )
#0000 ,&idx STR2
#00 ,&chr STR
STHk
#ff #00 &clear_mbox EQUk ,&ready JCN
#00 #00 ROTk ;selected_mbox ADD2 #0000 SWP2 STA
INC ,&clear_mbox JMP &ready POP2
( bytes ) LDZ2 #0000 &while EQU2k ,&end JCN
STHkr LB_SELECT_IDX LDZ2 ,&idx LDR2 EQU2 ,&write_str JCN
;debug_mbox_search debug
DUP2 print
DUP2 STHkr LB_DATA LDZ2 ADD2 LDA #0a EQU ,&inc JCN
INC2 ,&while JMP
&inc ,&idx LDR2 INC2 ,&idx STR2 INC2 ,&while JMP
&idx $2
&chr $1
&write_str STHkr LB_DATA LDZ2 ADD2
&loop LDAk #0a EQU ,&end JCN
LDAk [ ;selected_mbox #00 ,&chr LDR ADD2 ] STA
,&chr LDR INC ,&chr STR INC2 ,&loop JMP
&end
;selected_mbox debug
POP2 POP2
POPr
#01 .Console/write DEO
;selected_mbox strlen SWP .Console/write DEO .Console/write DEO
;selected_mbox print_str
JMP2r JMP2r
@try_scroll_up_mouse ( -> ) @noop_list_click ( list -- )
.list/len LDZ2 #00 .list/height LDZ LTH2 ,&no_scroll_up JCN POP
.list/top LDZ2 #0000 EQU2 ,&no_scroll_up JCN JMP2r
.list/top LDZ2 #0001 SUB2 .list/top STZ2
;update_sb_pos JSR2 @try_scroll_up_mouse ( list -- )
#01 .refresh/list STZ STH
STHkr LB_LEN LDZ2 #00 STHkr LB_HEIGHT LDZ LTH2 ,&no_scroll_up JCN
STHkr LB_TOP LDZ2 #0000 EQU2 ,&no_scroll_up JCN
STHkr LB_TOP LDZ2 #0001 SUB2 STHkr LB_TOP STZ2
STHkr update_sb_pos
&no_scroll_up &no_scroll_up
POPr
JMP2r JMP2r
@try_scroll_down_mouse ( -> ) @try_scroll_down_mouse ( list -- )
.list/len LDZ2 #00 .list/height LDZ LTH2 ,&no_scroll_down JCN STH
.list/top LDZ2 #00 .list/height LDZ ADD2 .list/len LDZ2 EQU2 ,&no_scroll_down JCN STHkr LB_LEN LDZ2 #00 STHkr LB_HEIGHT LDZ LTH2 ,&no_scroll_down JCN
.list/top LDZ2 INC2 .list/top STZ2 STHkr LB_TOP LDZ2 #00 STHkr LB_HEIGHT LDZ ADD2 STHkr LB_LEN LDZ2 EQU2 ,&no_scroll_down JCN
;update_sb_pos JSR2 STHkr LB_TOP LDZ2k INC2 ROT STZ2
#01 .refresh/list STZ STHkr update_sb_pos
&no_scroll_down &no_scroll_down
POPr
JMP2r JMP2r
@draw_scrollbar ( -> ) @draw_scrollbar ( list ypos -- )
,&y STR2
STH
.Screen/width DEI2 #0008 SUB2 .Screen/x DEO2 .Screen/width DEI2 #0008 SUB2 .Screen/x DEO2
TOP_SECTION .Screen/y DEO2 ,&y LDR2 .Screen/y DEO2
( draw the trough no matter what ) ( draw the trough no matter what )
;blank .Screen/addr DEO2 ;blank .Screen/addr DEO2
.list/height LDZ #00 STHkr LB_HEIGHT LDZ #00
&while_trough EQUk ,&end_trough JCN &while_trough EQUk ,&end_trough JCN
#00 .Screen/sprite DEO #00 .Screen/sprite DEO
.Screen/y DEI2 #0008 ADD2 .Screen/y DEO2 .Screen/y DEI2 #0008 ADD2 .Screen/y DEO2
INC ,&while_trough JMP &end_trough POP2 INC ,&while_trough JMP &end_trough POP2
( stop here if there is no overflow ) ( stop here if there is no overflow )
.list/len LDZ2 #00 .list/height LDZ LTH2 ,&no_handle JCN STHkr LB_LEN LDZ2 #00 STHkr LB_HEIGHT LDZ LTH2 ,&no_handle JCN
,&draw_handle JMP ,&draw_handle JMP
&no_handle &no_handle
POPr
JMP2r JMP2r
&y $2
( if there are more entries than will fit in the view area, draw the handle ) ( if there are more entries than will fit in the view area, draw the handle )
&draw_handle &draw_handle
( store the number of entries per tile of the scrollbar ) ( store the number of entries per tile of the scrollbar )
.list/len LDZ2 #00 .list/height LDZ DIV2 .sb/step STZ2 STHkr LB_LEN LDZ2 #00 STHkr LB_HEIGHT LDZ DIV2 STHkr SB_STEP STZ2
( set the length of the scrollbar ) ( set the length of the scrollbar )
.list/height LDZ .list/len LDZ2 #00 .list/height LDZ SUB2 .sb/step LDZ2 DIV2 NIP SUB .sb/len STZ STHkr LB_HEIGHT LDZ STHkr LB_LEN LDZ2 #00 STHkr LB_HEIGHT LDZ SUB2 STHkr SB_STEP LDZ2 DIV2 NIP SUB STHkr SB_LEN STZ
;scrollbar .Screen/addr DEO2 ;scrollbar .Screen/addr DEO2
TOP_SECTION .sb/pos LDZ2 #30 SFT2 ADD2 .Screen/y DEO2 ,&y LDR2 STHkr SB_POS LDZ2 #30 SFT2 ADD2 .Screen/y DEO2
.sb/len LDZ #00 &while_handle EQUk ,&end_handle JCN STHkr SB_LEN LDZ #00 &while_handle EQUk ,&end_handle JCN
.Screen/y DEI2 .Screen/height DEI2 #0040 SUB2 EQU2 ,&end_handle JCN .Screen/y DEI2 .Screen/height DEI2 #0040 SUB2 EQU2 ,&end_handle JCN
#01 .Screen/sprite DEO #01 .Screen/sprite DEO
INC .Screen/y DEI2 #0008 ADD2 .Screen/y DEO2 ,&while_handle JMP &end_handle POP2 INC .Screen/y DEI2 #0008 ADD2 .Screen/y DEO2 ,&while_handle JMP &end_handle POP2
POPr
JMP2r JMP2r
@update_sb_pos ( -> ) @update_sb_pos ( list -- )
.list/top LDZ2 .sb/step LDZ2 DIV2 .sb/pos STZ2 DUP DUP
LB_TOP LDZ2 ROT SB_STEP LDZ2 DIV2 ROT SB_POS STZ2
JMP2r JMP2r
@ -454,6 +575,8 @@ JMP2r
@scrollbar [ 0707 0707 0707 0707 ] @scrollbar [ 0707 0707 0707 0707 ]
@blank [ 0000 0000 0000 0000 ] @blank [ 0000 0000 0000 0000 ]
@loading "Loading... 00 @loading "Loading... 00
@debug_mbox_search "Finding 20 "selected 20 "mbox 00
@debug_mbox_copy "Copying 20 "mbox 20 "name 00
@font [ @font [
00 00 00 00 00 00 00 00 00 18 18 18 08 00 08 00 00 14 14 00 00 00 00 00 00 24 7e 24 24 7e 24 00 00 00 00 00 00 00 00 00 00 18 18 18 08 00 08 00 00 14 14 00 00 00 00 00 00 24 7e 24 24 7e 24 00
@ -484,5 +607,6 @@ JMP2r
@word $ff @word $ff
@selected_mbox $ff
@list_data $4000 @list_data $4000
@input_buf $4000 @mbox_data $4000