taro/taro-ls.tal

488 lines
No EOL
14 KiB
Tal

( taro-ls: list mail, navigate mailboxes, and perform actions on mail )
( message types )
%MBOX_LIST { #00 }
%GET_MBOX { #01 }
%MAIL_LIST { #02 }
( UI constants )
%TOP_SECTION { #0020 }
%BOTTOM_SECTION { #0040 }
|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
|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
|30 @Audio0 &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1
|40 @Audio1 &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1
|50 @Audio2 &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1
|60 @Audio3 &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1
|80 @Controller &vector $2 &button $1 &key $1 &func $1
|90 @Mouse &vector $2 &x $2 &y $2 &state $1 &pad $3 &scrollx $2 &scrolly $2
|a0 @File0 &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
|b0 @File1 &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
|c0 @DateTime &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1
( variables )
|0000
@refresh [ &mboxes $1 &list $1 &fg $1 ]
@resizing [ $1 &x $2 &y $2 &dx $2 &dy $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 ]
@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 ]
@sb [ &len $1 &pos $2 &step $2 ]
( program )
|0100 ( -> )
( theme )
#028d .System/r DEO2
#0a8d .System/g DEO2
#098d .System/b DEO2
#0180 .Screen/width DEO2
#0200 .Screen/height DEO2
.Screen/height DEI2 TOP_SECTION BOTTOM_SECTION ADD2 SUB2 #03 SFT2 NIP .list/height STZ
#01 .refresh/fg STZ
;on_screen .Screen/vector DEO2
;on_mouse .Mouse/vector DEO2
;on_stdin .Console/vector DEO2
BRK
@on_stdin ( -> )
.decoding LDZ #01 EQU ,&must_decode JCN
#01 .decoding STZ
#01 .decoding/counting STZ
.Console/read DEI .decoding/msg_type STZ
BRK
&must_decode
.decoding/counting LDZ #01 EQU ,&count_1 JCN
.decoding/counting LDZ #02 EQU ,&count_2 JCN
( decode data )
.Console/read DEI
.decoding/msg_type LDZ
DUP MAIL_LIST NEQ ,&no_mail_list JCN
POP ;list_data .decoding/processed LDZ2 ADD2 STA
decode_inc_count .list/bytes STZ2
,&count JMP
#01 .refresh/list STZ
&no_mail_list
POP
&count
decode_is_done ,&done JCN
BRK
&done
#0000 DUP2 .decoding/count STZ2 .decoding/processed STZ2 #00 .decoding STZ
BRK
&count_1
.Console/read DEI .decoding/count STZ
#02 .decoding/counting STZ
BRK
&count_2
.Console/read DEI .decoding/count INC STZ
#00 .decoding/counting STZ
BRK
@decode_inc_count ( -- current* )
.decoding/processed LDZ2 INC2 DUP2 .decoding/processed STZ2
JMP2r
@decode_is_done ( -- bit )
#01 .refresh/list STZ
.decoding/processed LDZ2 .decoding/count LDZ2 EQU2
JMP2r
@on_mouse ( -> )
#01 .refresh/fg STZ
get_select_idx_by_mouse
.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
handle_rsz #01 AND ,&done JCN
( 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
#01 .resizing STZ
.Mouse/x DEI2 .resizing/x STZ2
.Mouse/y DEI2 .resizing/y STZ2
&done
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
&dec_x
.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
,&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
&dec_y
.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
&chk_release
#01 .refresh/list STZ
.Screen/height DEI2 TOP_SECTION BOTTOM_SECTION ADD2 SUB2 #03 SFT2 NIP .list/height STZ
.Mouse/state DEI
JMP2r
@on_screen ( -> )
.refresh/list LDZ #00 EQU ,&no_list JCN
draw_mail_list
draw_scrollbar
#00 .refresh/list STZ
&no_list
.refresh/fg LDZ #00 EQU ,&no_fg JCN
clear_fg
draw_resize_handle
draw_cursor
#00 .refresh/fg STZ
&no_fg
BRK
@clear_fg ( -> )
.Screen/width DEI2 #0000 &whilex EQU2k ,&endx JCN
DUP2 ,&x STR2
.Screen/height DEI2 #0000 &whiley EQU2k ,&endy JCN
DUP2 ,&y STR2
,&x LDR2 .Screen/x DEO2
,&y LDR2 .Screen/y DEO2
;blank .Screen/addr DEO2
#41 .Screen/sprite DEO
#0008 ADD2 ,&whiley JMP &endy POP2 POP2
#0008 ADD2 ,&whilex JMP &endx POP2 POP2
JMP2r
&x $2
&y $2
@draw_resize_handle ( -> )
.Screen/width DEI2 #0008 SUB2 .Screen/x DEO2
.Screen/height DEI2 #0008 SUB2 .Screen/y DEO2
;resize_handle .Screen/addr DEO2
#02 .Screen/sprite DEO
JMP2r
@strlen ( addr -- len )
DUP2
&loop
INC2 LDAk ,&loop JCN
SWP2 SUB2
JMP2r
@store_char ( char -- char )
#00 .list/elem_offset LDZ ;word ADD2 STA
.list/elem_offset LDZ INC .list/elem_offset STZ
JMP2r
@shouldnt_draw_word ( -- flag )
.list/offset LDZ2 .list/top LDZ2 LTH2 ,&no JCN
.list/offset LDZ2 .list/top LDZ2 #00 .list/height LDZ ADD2 #0001 SUB2 GTH2 ,&no JCN
#00 JMP2r
&no
#01
JMP2r
@draw_list_elem ( -> )
( ;get_entry_color JSR2 #0c NEQ ,&no_store_cart JCN
;store_cart JSR2 )
&no_store_cart
[ ;word
.Screen/x DEI2
.Screen/y DEI2
get_entry_color ] draw_str
finish_line
JMP2r
@get_entry_color ( -- colorByte )
.list/offset LDZ2
.list/select_index LDZ2
NEQ2 ,&normal JCN
( selected )
#04 JMP2r
&normal
#03
JMP2r
@finish_line ( -> )
;blank .Screen/addr DEO2
&while
.Screen/x DEI2
.Screen/width DEI2 #0010 SUB2
GTH2 ,&end JCN
get_entry_color .Screen/sprite DEO
.Screen/x DEI2 #0008 ADD2 .Screen/x DEO2
,&while JMP &end
JMP2r
@draw_mail_list ( -> )
#0000 .Screen/x DEO2
TOP_SECTION .Screen/y DEO2
.decoding LDZ #01 NEQ ,&proceed JCN
;loading .Screen/x DEI2 .Screen/y DEI2 #03 draw_str
JMP2r
&proceed
#0000 .list/offset STZ2
.list/bytes LDZ2 #0000 &while EQU2k ,&end JCN
DUP2 ;list_data ADD2 LDA
DUP #00 EQU ,&end JCN
( if not newline, store the character and increment the offsets )
DUP #0a EQU ,&inc_line JCN
;store_char JSR2
,&continue JMP ( continue looping )
&inc_line
POP #0000 .list/elem_offset LDZ ;word ADD2 STA
shouldnt_draw_word ,&no_draw JCN
draw_list_elem
#0000 .Screen/x DEO2
.Screen/y DEI2 #0008 ADD2 .Screen/y DEO2
&no_draw
.list/offset LDZ2 INC2 .list/offset STZ2
#ff #00 &word_clr EQUk ,&end_clr JCN
#00 OVR SWP DUP ROT ;word ADD2 STA
INC ,&word_clr JMP &end_clr POP2
#00 .list/elem_offset STZ
&continue INC2 ,&while JMP
&end
.list/offset LDZ2 #0001 SUB2 .list/len STZ2 POP2 POP2
JMP2r
@draw_cursor ( -> )
.Mouse/x DEI2 .Screen/x DEO2
.Mouse/y DEI2 .Screen/y DEO2
;cursor .Screen/addr DEO2
#4f .Screen/sprite DEO
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 #18 DEO
JMP2r
@print_str ( str* -- )
&while
LDAk #18 DEO
INC2 LDAk ,&while JCN
POP2
JMP2r
@get_select_idx_by_mouse ( -> )
.Mouse/scrolly DEI2 #0000 EQU2 ,&no_scroll JCN
.Mouse/scrolly DEI2 #0001 EQU2 ,&scroll_down JCN
( scroll_up )
;try_scroll_up_mouse JSR2
,&no_scroll JMP
&scroll_down
;try_scroll_down_mouse JSR2
&no_scroll
.Mouse/x DEI2 #0008 LTH2 ,&done JCN
.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
.Mouse/state DEI #00 EQU ,&no_click JCN
.list/select_index LDZ2 .list/len LDZ2 GTH2 ,&no_click JCN
&no_click
JMP2r
( click handler here )
&done
JMP2r
@try_scroll_up_mouse ( -> )
.list/len LDZ2 #00 .list/height LDZ LTH2 ,&no_scroll_up JCN
.list/top LDZ2 #0000 EQU2 ,&no_scroll_up JCN
.list/top LDZ2 #0001 SUB2 .list/top STZ2
;update_sb_pos JSR2
#01 .refresh/list STZ
&no_scroll_up
JMP2r
@try_scroll_down_mouse ( -> )
.list/len LDZ2 #00 .list/height LDZ LTH2 ,&no_scroll_down JCN
.list/top LDZ2 #00 .list/height LDZ ADD2 .list/len LDZ2 EQU2 ,&no_scroll_down JCN
.list/top LDZ2 INC2 .list/top STZ2
;update_sb_pos JSR2
#01 .refresh/list STZ
&no_scroll_down
JMP2r
@draw_scrollbar ( -> )
.Screen/width DEI2 #0008 SUB2 .Screen/x DEO2
TOP_SECTION .Screen/y DEO2
( draw the trough no matter what )
;blank .Screen/addr DEO2
.list/height LDZ #00
&while_trough EQUk ,&end_trough JCN
#00 .Screen/sprite DEO
.Screen/y DEI2 #0008 ADD2 .Screen/y DEO2
INC ,&while_trough JMP &end_trough POP2
( stop here if there is no overflow )
.list/len LDZ2 #00 .list/height LDZ LTH2 ,&no_handle JCN
,&draw_handle JMP
&no_handle
JMP2r
( if there are more entries than will fit in the view area, draw the handle )
&draw_handle
( store the number of entries per tile of the scrollbar )
.list/len LDZ2 #00 .list/height LDZ DIV2 .sb/step STZ2
( 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
;scrollbar .Screen/addr DEO2
TOP_SECTION .sb/pos LDZ2 #30 SFT2 ADD2 .Screen/y DEO2
.sb/len LDZ #00 &while_handle EQUk ,&end_handle JCN
.Screen/y DEI2 .Screen/height DEI2 #0040 SUB2 EQU2 ,&end_handle JCN
#01 .Screen/sprite DEO
INC .Screen/y DEI2 #0008 ADD2 .Screen/y DEO2 ,&while_handle JMP &end_handle POP2
JMP2r
@update_sb_pos ( -> )
.list/top LDZ2 .sb/step LDZ2 DIV2 .sb/pos STZ2
JMP2r
@draw_str ( addr x y color -- )
STH ( save color )
.Screen/y DEO2 ( set y )
.Screen/x DEO2 ( set x )
( now the string address is at the top of the stack )
&loop
.Screen/x DEI2 .Screen/width DEI2 #0010 SUB2 GTH2 ,&done JCN
LDAk DUP
#7f LTH ,&ascii JCN POP #3f ( replace non_ascii characters with ? )
&ascii DUP #00 NEQ #20 MUL SUB #00 SWP #30 SFT2 ;font ADD2 .Screen/addr DEO2
STHkr .Screen/sprite DEO
.Screen/x DEI2 #0008 ADD2 .Screen/x DEO2
INC2
LDAk #00 NEQ ,&loop JCN &done
POP2
POPr
JMP2r
@resize_handle [ e2c2 aa1a 3a02 fe00 ]
@cursor [ f8e0 e090 8804 0000 ]
@scrollbar [ 0707 0707 0707 0707 ]
@blank [ 0000 0000 0000 0000 ]
@loading "Loading... 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
00 10 3c 50 38 14 78 10 00 00 44 08 10 20 44 00 00 18 20 32 2c 24 1a 00 00 18 10 20 00 00 00 00
00 04 08 08 08 08 04 00 00 20 10 10 10 10 20 00 00 00 44 28 10 28 44 00 00 00 10 10 7c 10 10 00
00 00 00 00 00 0c 08 10 00 00 00 00 3e 00 00 00 00 00 00 00 00 0c 0c 00 00 02 04 08 10 20 40 00
00 38 44 54 54 44 38 00 00 30 10 10 10 10 38 00 00 38 44 04 38 40 7c 00 00 38 44 18 04 44 38 00
00 08 18 28 48 7c 08 00 00 7c 40 78 04 44 38 00 00 38 40 78 44 44 38 00 00 7c 04 08 10 10 10 00
00 38 44 38 44 44 38 00 00 38 44 44 3c 04 38 00 00 18 18 00 00 18 18 00 00 18 18 00 00 18 10 20
00 00 08 10 20 10 08 00 00 00 00 3e 00 3e 00 00 00 00 10 08 04 08 10 00 00 38 44 1c 10 00 10 00
00 38 44 5c 58 40 3c 00 00 10 28 44 7c 44 44 00 00 78 44 78 44 44 78 00 00 38 44 40 40 44 38 00
00 78 44 44 44 44 78 00 00 7c 40 7c 40 40 7c 00 00 7c 40 7c 40 40 40 00 00 38 44 40 4c 44 3c 00
00 44 44 7c 44 44 44 00 00 7c 10 10 10 10 7c 00 00 7c 08 08 48 48 30 00 00 44 48 70 48 44 44 00
00 40 40 40 40 40 7c 00 00 44 6c 7c 54 44 44 00 00 44 64 74 5c 4c 44 00 00 38 44 44 44 44 38 00
00 78 44 44 78 40 40 00 00 38 44 44 4c 4c 3e 00 00 78 44 44 78 44 44 00 00 3c 40 38 04 04 78 00
00 7c 10 10 10 10 10 00 00 44 44 44 44 44 3c 00 00 44 44 28 28 10 10 00 00 44 44 44 54 6c 44 00
00 44 44 38 38 44 44 00 00 44 44 28 10 10 10 00 00 7c 04 18 30 40 7c 00 00 3c 30 30 30 30 3c 00
00 40 20 10 08 04 02 00 00 3c 0c 0c 0c 0c 3c 00 00 10 38 6c 00 00 00 00 00 00 00 00 00 00 7e 00
00 18 08 04 00 00 00 00 00 00 38 04 3c 44 3c 00 00 40 40 78 44 44 78 00 00 00 38 44 40 44 38 00
00 04 04 3c 44 44 3c 00 00 00 38 44 7c 40 3c 00 00 1c 20 78 20 20 20 00 00 00 3c 44 3c 04 44 38
00 40 40 78 44 44 44 00 00 30 00 70 10 10 18 00 00 0c 00 3c 04 04 44 38 00 00 44 48 70 48 44 00
00 70 10 10 10 10 1c 00 00 00 44 6c 7c 54 44 00 00 00 78 44 44 44 44 00 00 00 38 44 44 44 38 00
00 00 78 44 44 78 40 40 00 00 3c 44 44 3d 06 04 00 00 4c 50 60 40 40 00 00 00 3c 40 38 04 78 00
00 20 78 20 20 24 38 00 00 00 44 44 44 44 3c 00 00 00 44 44 28 28 10 00 00 00 44 44 54 7c 28 00
00 00 44 28 10 28 44 00 00 00 44 44 3c 04 78 00 00 00 7c 04 38 40 7c 00 00 1e 10 10 10 00 00 00
00 10 10 10 10 10 10 00 00 00 00 08 08 08 78 00 00 00 00 32 4c 00 00 00 3c 42 99 a1 a1 99 42 3c
]
@word $ff
@list_data $4000
@input_buf $4000