reorganize code

This commit is contained in:
Iris Lightshard 2023-03-18 22:25:09 -06:00
parent 766a98f43b
commit 68783e113b
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398

View file

@ -80,9 +80,7 @@
;on_key .Controller/vector DEO2
BRK
@on_key ( -> )
.Controller/key DEI .Console/error DEO
BRK
( -== message in ==- )
@on_stdin ( -> )
@ -106,8 +104,7 @@ BRK
,&count JMP
&no_mbox_list
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
,&count JMP
&no_mail_list
@ -116,6 +113,7 @@ BRK
&count
decode_is_done ,&done JCN
BRK
&done
#0000 DUP2 .decoding/count STZ2 .decoding/processed STZ2 #00 .decoding STZ
BRK
@ -132,83 +130,247 @@ BRK
BRK
@decode_inc_count ( -- current* )
.decoding/processed LDZ2 INC2 DUP2 .decoding/processed STZ2
JMP2r
@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
.list/bytes LDZ2 .decoding/count LDZ2 NEQ2 ,&no_list JCN
#01 .refresh/list STZ
&no_list
.mboxes/bytes LDZ2 .decoding/count LDZ2 NEQ2 ,&no_mbox JCN
#01 .refresh/mboxes STZ
.mboxes/bytes LDZ2 .decoding/count LDZ2 NEQ2 ,&no_mbox JCN
#01 .refresh/mboxes STZ
&no_mbox
JMP2r
( -== message out ==- )
@send_get_mbox ( -> )
#01 .Console/write DEO
;selected_mbox strlen SWP .Console/write DEO .Console/write DEO
;selected_mbox send_str
JMP2r
@send_str ( str* -- )
&while
LDAk .Console/write DEO
INC2 LDAk ,&while JCN
POP2
JMP2r
( -== input ==- )
@on_key ( -> )
.Controller/key DEI .Console/error DEO
BRK
@on_mouse ( -> )
;mbox_select_handler .mboxes .refresh/mboxes #0000 #00 mouse_event_list
;noop_list_click .list .refresh/list TOP_SECTION MID_SEPARATOR ADD2 #04 mouse_event_list
.resizing LDZ #00 EQU ,&resz_check JCN
( resizing )
.Mouse/x DEI2 .resizing/x LDZ2 SUB2 .resizing/dx STZ2
.Mouse/y DEI2 .resizing/y LDZ2 SUB2 .resizing/dy STZ2
( resizing )
.Mouse/x DEI2 .resizing/x LDZ2 SUB2 .resizing/dx STZ2
.Mouse/y DEI2 .resizing/y LDZ2 SUB2 .resizing/dy STZ2
handle_rsz #01 AND ,&done JCN
handle_rsz #01 AND ,&done JCN
( btn1 release )
#00 .resizing STZ
( btn1 release )
#00 .resizing STZ
BRK
&resz_check
.Mouse/x DEI2 .Screen/width DEI2 #0008 SUB2 LTH2 ,&done JCN
.Mouse/y DEI2 .Screen/height DEI2 #0008 SUB2 LTH2 ,&done JCN
.Mouse/state DEI #01 EOR ,&done JCN
.Mouse/x DEI2 .Screen/width DEI2 #0008 SUB2 LTH2 ,&done JCN
.Mouse/y DEI2 .Screen/height DEI2 #0008 SUB2 LTH2 ,&done JCN
.Mouse/state DEI #01 EOR ,&done JCN
#01 .resizing STZ
.Mouse/x DEI2 .resizing/x STZ2
.Mouse/y DEI2 .resizing/y STZ2
#01 .resizing STZ
.Mouse/x DEI2 .resizing/x STZ2
.Mouse/y DEI2 .resizing/y STZ2
&done
#01 .refresh/fg STZ
BRK
@handle_rsz ( -- mousestate )
( chk_x_rsz )
.Mouse/x DEI2 .Screen/width DEI2 #0002 SUB2 GTH2 ,&inc_x JCN
#ffff .resizing/dx LDZ2 SUB2 #0008 GTH2 ,&dec_x JCN
,&chk_y_rsz JMP
.Mouse/x DEI2 .Screen/width DEI2 #0002 SUB2 GTH2 ,&inc_x JCN
#ffff .resizing/dx LDZ2 SUB2 #0008 GTH2 ,&dec_x JCN
,&chk_y_rsz JMP
&dec_x
.Screen/width DEI2 #0100 LTH2 ,&chk_y_rsz JCN
.Screen/width DEI2 #0008 SUB2 .Screen/width DEO2
,&chk_y_rsz JMP
.Screen/width DEI2 #0100 LTH2 ,&chk_y_rsz JCN
.Screen/width DEI2 #0008 SUB2 .Screen/width DEO2
,&chk_y_rsz JMP
&inc_x
.Screen/width DEI2 #0008 ADD2 .Screen/width DEO2
.Screen/width DEI2 #0008 ADD2 .Screen/width DEO2
,&chk_y_rsz JMP
&chk_y_rsz
.Mouse/y DEI2 .Screen/height DEI2 #0002 SUB2 GTH2 ,&inc_y JCN
#ffff .resizing/dy LDZ2 SUB2 #0008 GTH2 ,&dec_y JCN
,&chk_release JMP
.Mouse/y DEI2 .Screen/height DEI2 #0002 SUB2 GTH2 ,&inc_y JCN
#ffff .resizing/dy LDZ2 SUB2 #0008 GTH2 ,&dec_y JCN
,&chk_release JMP
&dec_y
.Screen/height DEI2 #0100 LTH2 ,&chk_release JCN
.Screen/height DEI2 #0008 SUB2 .Screen/height DEO2
,&chk_release JMP
.Screen/height DEI2 #0100 LTH2 ,&chk_release JCN
.Screen/height DEI2 #0008 SUB2 .Screen/height DEO2
,&chk_release JMP
&inc_y
.Screen/height DEI2 #0008 ADD2 .Screen/height DEO2
,&chk_release JMP
.Screen/height DEI2 #0008 ADD2 .Screen/height DEO2
,&chk_release JMP
&chk_release
#01 .refresh/list 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
#01 .refresh/list 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
JMP2r
@mouse_event_list ( clickhandler* list refresh ypos* multiselect -- )
,&multi STR
,&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 #0001 EQU2 ,&scroll_down JCN
( scroll_up )
STHkr try_scroll_up_mouse
,&no_scroll JMP
( data )
&multi $1
&scroll_down
STHkr try_scroll_down_mouse
&no_scroll
.Mouse/state DEI #01 AND #00 EQU ,&done JCN
( leftclick )
,&multi LDR ,&y LDR2 STHkr mouse_select_on_click
STHr ROT ROT JSR2
#01 ,&r LDR STZ
JMP2r
( data )
&y $2
&r $1
&done
#01 ,&r LDR STZ
POPr
POP2
JMP2r
@mouse_select_on_click ( multi ypos list -- )
STH
,&y STR2
.Controller/button DEI #04 AND AND ,&multiselect JCN
#0001 STHkr LB_SELECT_LEN STZ2
.Mouse/y DEI2 ,&y LDR2 SUB2 #03 SFT2 STHkr LB_TOP LDZ2 ADD2 STHkr LB_SELECT_IDX STZ2
POPr
JMP2r
&multiselect
.Mouse/y DEI2 ,&y LDR2 SUB2 #03 SFT2 STHkr LB_TOP LDZ2 ADD2
DUP2 STHkr LB_SELECT_IDX LDZ2 LTH2 ,&last_to_first JCN
( first_to_last )
STHkr LB_SELECT_IDX LDZ2 SUB2 INC2 STHkr LB_SELECT_LEN STZ2
POPr JMP2r
&last_to_first
DUP2 STHkr LB_SELECT_IDX LDZ2 SWP2 SUB2 INC2 STHkr LB_SELECT_LEN STZ2
STHr LB_SELECT_IDX STZ2
JMP2r
&y $2
@mbox_select_handler ( list -- )
#0000 ,&idx STR2
#00 ,&chr STR
STHk
( clear the previous selection with null bytes )
#ff #00 &clear_mbox EQUk ,&ready JCN
DUP #00 SWP ;selected_mbox ADD2 #00 ROT ROT STA
INC ,&clear_mbox JMP &ready POP2
( get position of the current selection )
( bytes ) LDZ2 #0000 &while EQU2k ,&end JCN
STHkr LB_SELECT_IDX LDZ2 ,&idx LDR2 EQU2 ,&write_str JCN
DUP2 STHkr LB_DATA LDZ2 ADD2 LDA #0a EQU ,&inc JCN
INC2 ,&while JMP
&inc ,&idx LDR2 INC2 ,&idx STR2 INC2 ,&while JMP
( data )
&idx $2
&chr $1
( copy the current selection to the buffer )
&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
POP2 POP2
POPr
send_get_mbox
JMP2r
@noop_list_click ( list -- )
POP
JMP2r
@try_scroll_up_mouse ( list -- )
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
POPr
JMP2r
@try_scroll_down_mouse ( list -- )
STH
STHkr LB_LEN LDZ2 #00 STHkr LB_HEIGHT LDZ LTH2 ,&no_scroll_down JCN
STHkr LB_TOP LDZ2 #00 STHkr LB_HEIGHT LDZ ADD2 STHkr LB_LEN LDZ2 EQU2 ,&no_scroll_down JCN
STHkr LB_TOP LDZ2k INC2 ROT STZ2
STHkr update_sb_pos
&no_scroll_down
POPr
JMP2r
( -== gfx ==- )
@on_screen ( -> )
.refresh/mboxes LDZ #00 EQU ,&no_mboxes JCN
@ -250,6 +412,7 @@ JMP2r
&x $2
@clear_listbox ( top* height -- )
#00 SWP #30 SFT2
,&height STR2
,&top STR2
@ -277,14 +440,6 @@ JMP2r
JMP2r
@strlen ( addr* -- len* )
DUP2
&loop
INC2 LDAk ,&loop JCN
SWP2 SUB2
JMP2r
@store_char ( char list_e_offset -- char )
@ -296,7 +451,10 @@ JMP2r
@shouldnt_draw_word ( list -- flag )
DUP LB_OFFSET LDZ2 DUP2
( above top of view )
STH2 ROT STHk LB_TOP LDZ2 LTH2 ,&clear_rtn JCN
( below bottom of view )
STHr DUP LB_TOP LDZ2 ROT LB_HEIGHT LDZ #00 SWP ADD2 #0001 SUB2 STH2r SWP2 GTH2 ,&no_draw JCN
#00 JMP2r
@ -304,9 +462,11 @@ JMP2r
POP2r POPr
&no_draw
#01
JMP2r
@draw_list_elem ( list -- )
STHk
get_entry_color STH
[ ;word
@ -318,64 +478,67 @@ JMP2r
JMP2r
@get_entry_color ( list -- colorByte )
STHk LB_OFFSET LDZ2
STHkr LB_SELECT_IDX LDZ2
LTH2 ,&normal JCN
STHkr LB_OFFSET LDZ2
STHkr LB_SELECT_IDX LDZ2 STHkr LB_SELECT_LEN LDZ2 ADD2 #0001 SUB2
GTH2 ,&normal JCN
POPr
( selected )
#04 JMP2r
&normal
POPr
#03
JMP2r
@finish_line ( list -- )
STH
;blank .Screen/addr DEO2
&while
.Screen/x DEI2
.Screen/width DEI2 #0010 SUB2
GTH2 ,&end JCN
&while .Screen/x DEI2 .Screen/width DEI2 #0010 SUB2 GTH2 ,&end JCN
STHkr get_entry_color .Screen/sprite DEO
.Screen/x DEI2 #0008 ADD2 .Screen/x DEO2
,&while JMP &end
POPr
JMP2r
@draw_listbox ( .list ypos* -- )
#0000 .Screen/x DEO2
( ypos ) .Screen/y DEO2
#0000 .Screen/x DEO2
( ypos ) .Screen/y DEO2
( .list ) STH
&begin
#0000 STHkr LB_OFFSET STZ2
STHkr LDZ2 #0000 &while EQU2k ,&end JCN
DUP2 STHkr LB_DATA LDZ2 ADD2 LDA
DUP #00 EQU ,&end JCN
( .list ) STH
&begin
#0000 STHkr LB_OFFSET STZ2
STHkr LDZ2 #0000 &while EQU2k ,&end JCN
DUP2 STHkr LB_DATA LDZ2 ADD2 LDA
DUP #00 EQU ,&end JCN
( if not newline, store the character and increment the offsets )
DUP #0a EQU ,&inc_line JCN
STHkr LB_ELEM_OFFSET store_char
,&continue JMP ( continue looping )
&inc_line
POP #0000 STHkr LB_ELEM_OFFSET LDZ ;word ADD2 STA
STHkr shouldnt_draw_word ,&no_draw JCN
STHkr draw_list_elem
#0000 .Screen/x DEO2
.Screen/y DEI2 #0008 ADD2 .Screen/y DEO2
&no_draw
STHkr LB_OFFSET LDZ2 INC2 STHkr LB_OFFSET STZ2
&inc_line
POP #0000 STHkr LB_ELEM_OFFSET LDZ ;word ADD2 STA
STHkr shouldnt_draw_word ,&no_draw JCN
STHkr draw_list_elem
#0000 .Screen/x DEO2
.Screen/y DEI2 #0008 ADD2 .Screen/y DEO2
&no_draw
STHkr LB_OFFSET LDZ2 INC2 STHkr LB_OFFSET STZ2
#00 STHkr LB_ELEM_OFFSET STZ
#00 STHkr LB_ELEM_OFFSET STZ
&continue INC2 ,&while JMP
&end
STHkr LB_OFFSET LDZ2 #0001 SUB2 STHr LB_LEN STZ2 POP2 POP2
JMP2r
@ -389,154 +552,8 @@ JMP2r
JMP2r
@print ( short* -- )
SWP ,&byte JSR
&byte ( byte -- ) DUP #04 SFT ,&char JSR
&char ( char -- ) #0f AND DUP #09 GTH #27 MUL ADD #30 ADD .Console/error DEO
JMP2r
@print_str ( str* -- )
&while
LDAk .Console/write DEO
INC2 LDAk ,&while JCN
POP2
JMP2r
@debug ( str* -- )
&while
LDAk .Console/error DEO
INC2 LDAk ,&while JCN
POP2
JMP2r
@mouse_event_list ( clickhandler* list refresh ypos* multiselect -- )
,&multi STR
,&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 #0001 EQU2 ,&scroll_down JCN
( scroll_up )
STHkr try_scroll_up_mouse
,&no_scroll JMP
&multi $1
&scroll_down
STHkr try_scroll_down_mouse
&no_scroll
( select entry )
( click handler here )
.Mouse/state DEI #01 AND #00 EQU ,&done JCN
,&multi LDR ,&y LDR2 STHkr mouse_select_on_click
STHr ROT ROT JSR2
#01 ,&r LDR STZ
JMP2r
&y $2
&r $1
&done
#01 ,&r LDR STZ
POPr
POP2
JMP2r
@mouse_select_on_click ( multi ypos list -- )
STH
,&y STR2
.Controller/button DEI #04 AND AND ,&multiselect JCN
#0001 STHkr LB_SELECT_LEN STZ2
.Mouse/y DEI2 ,&y LDR2 SUB2 #03 SFT2 STHkr LB_TOP LDZ2 ADD2 STHkr LB_SELECT_IDX STZ2
POPr
JMP2r
&multiselect
( first_to_last )
.Mouse/y DEI2 ,&y LDR2 SUB2 #03 SFT2 STHkr LB_TOP LDZ2 ADD2
DUP2 STHkr LB_SELECT_IDX LDZ2 LTH2 ,&last_to_first JCN
STHkr LB_SELECT_IDX LDZ2 SUB2 INC2 STHkr LB_SELECT_LEN STZ2
POPr JMP2r
&last_to_first
DUP2 STHkr LB_SELECT_IDX LDZ2 SWP2 SUB2 INC2 STHkr LB_SELECT_LEN STZ2
STHr LB_SELECT_IDX STZ2
JMP2r
&y $2
@mbox_select_handler ( list -- )
#0000 ,&idx STR2
#00 ,&chr STR
STHk
( clear the previous selection with null bytes )
#ff #00 &clear_mbox EQUk ,&ready JCN
DUP #00 SWP ;selected_mbox ADD2 #00 ROT ROT STA
INC ,&clear_mbox JMP &ready POP2
( get position of the current selection )
( bytes ) LDZ2 #0000 &while EQU2k ,&end JCN
STHkr LB_SELECT_IDX LDZ2 ,&idx LDR2 EQU2 ,&write_str JCN
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
( copy the current selection to the buffer )
&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
POP2 POP2
POPr
#01 .Console/write DEO
;selected_mbox strlen SWP .Console/write DEO .Console/write DEO
;selected_mbox print_str
JMP2r
@noop_list_click ( list -- )
POP
JMP2r
@try_scroll_up_mouse ( list -- )
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
POPr
JMP2r
@try_scroll_down_mouse ( list -- )
STH
STHkr LB_LEN LDZ2 #00 STHkr LB_HEIGHT LDZ LTH2 ,&no_scroll_down JCN
STHkr LB_TOP LDZ2 #00 STHkr LB_HEIGHT LDZ ADD2 STHkr LB_LEN LDZ2 EQU2 ,&no_scroll_down JCN
STHkr LB_TOP LDZ2k INC2 ROT STZ2
STHkr update_sb_pos
&no_scroll_down
POPr
JMP2r
@draw_scrollbar ( list ypos -- )
,&y STR2
STH
@ -604,13 +621,42 @@ JMP2r
JMP2r
( -== util ==- )
@strlen ( addr* -- len* )
DUP2
&loop
INC2 LDAk ,&loop JCN
SWP2 SUB2
JMP2r
@debug_u16 ( short* -- )
SWP ,&byte JSR
&byte ( byte -- ) DUP #04 SFT ,&char JSR
&char ( char -- ) #0f AND DUP #09 GTH #27 MUL ADD #30 ADD .Console/error DEO
JMP2r
@debug ( str* -- )
&while
LDAk .Console/error DEO
INC2 LDAk ,&while JCN
POP2
JMP2r
( -== data ==- )
@resize_handle [ e2c2 aa1a 3a02 fe00 ]
@cursor [ f8e0 e090 8804 0000 ]
@scrollbar [ 0707 0707 0707 0707 ]
@blank [ 0000 0000 0000 0000 ]
@loading "Loading... 00
@debug_mbox_search "Finding 20 "selected 20 "mbox 00
@debug_mbox_copy "Copying 20 "mbox 20 "name 00
@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