From 91dd545b3daafcf9f61e7650eb7733875a9925bc Mon Sep 17 00:00:00 2001 From: Derek Stevens Date: Mon, 20 Mar 2023 23:32:49 -0600 Subject: [PATCH] README: document message types; taro-ctl: fix 0-length message sending; taro-ls: fix 0-length message reading and list length off-by-1 error --- README.md | 13 +++++++++++-- taro-ctl.cr | 8 +------- taro-ls.tal | 15 ++++++++++++++- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 8ed38cb..cb1008a 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,20 @@ ## messages +Messages are in the format `[1][2:3][...]`: +- byte 1 is the message type +- bytes 2 and 3 are the length of the message, in bytes +- bytes 4 and beyond are the message itself (payload) - won't be present if the length is 0 + Even messages go from `taro-ctl` to the `uxn` windows. - `0`: mailbox list -- `2`: list mail in mailbox +- `2`: list mail in current mailbox Odd messages go from the `uxn` windows to `taro-ctl`. -- `1`: change/refresh mailbox \ No newline at end of file +- `1`: change/refresh mailbox; payload is the mailbox to read +- `3`: mark all as read in current mailbox; no payload +- `5`: search mail; payload is the regex +- `7`: refile mail; payload is a mblaze msg number/range, a space, and then the mailbox name +- `9`: trash mail; payload is a mblaze msg number/range \ No newline at end of file diff --git a/taro-ctl.cr b/taro-ctl.cr index b84b9a8..4bc0e04 100644 --- a/taro-ctl.cr +++ b/taro-ctl.cr @@ -74,19 +74,13 @@ module Taro def write_msg(msgtype : UInt8, data : Slice) msgsz = UInt16.new(data.size > 16384 ? 16384 : data.size) msgtype.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 + msgsz.to_io(@stdin_w, IO::ByteFormat::BigEndian) if msgsz == 16384 @stdin_w.write(data[0..msgsz - 2]) 10_u8.to_io(@stdin_w, IO::ByteFormat::BigEndian) elsif msgsz != 0 @stdin_w.write(data[0..msgsz - 1]) - else - @stdin_w.write("nothing\n".to_slice) end end diff --git a/taro-ls.tal b/taro-ls.tal index 53726bd..b7fdedd 100644 --- a/taro-ls.tal +++ b/taro-ls.tal @@ -145,6 +145,19 @@ BRK &count_2 .Console/read DEI .decoding/count INC STZ #00 .decoding/counting STZ + .decoding/count LDZ2 #0000 NEQ2 ,&has_data JCN + .decoding/msg_type LDZ + DUP MBOX_LIST NEQ ,&no_mbox_empty JCN + POP #0000 .mboxes/bytes STZ2 decode_is_done POP + ,&done JMP + &no_mbox_empty + DUP MAIL_LIST NEQ ,&no_mail_empty JCN + POP + #0000 .list/bytes STZ2 decode_is_done POP + ,&done JMP + &no_mail_empty + POP + &has_data BRK @@ -611,7 +624,7 @@ JMP2r &continue INC2 ,&while JMP &end - STHkr LB_OFFSET LDZ2 #0001 SUB2 STHr LB_LEN STZ2 POP2 POP2 + STHkr LB_OFFSET LDZ2 STHr LB_LEN STZ2 POP2 POP2 JMP2r