all repos — taro @ 1cad71b488988d912a62f8c29e10711d56968c16

mblaze frontend in uxn + crystal

first commit - resizable uxn window lists inbox and crystal module can talk to it
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAmQRWgcACgkQO3+8IhRO
Y5hXkg/+PdIjAnfA2/OoToHTRX2hGAH80qDyOR2jaSrAQe9BnC/E/O3HRNCoB9wa
6dLqQnYGG5tYOxmp9lHj31ABKDEKFAihAzhdH10jFOCKI5vYwwUJ5I7MZjrRTSF1
5S0svmpMnrEKYAT6qpX3gIJ4h+/mMYqJ4loW6/LyyT0G0cZbjkmp12lgWjP/MF56
ma1PSKHDlugarryZem7MVveWrM6MZLJLst5jP3vVSiOfdv/GUvuIDs0JD75bBqgN
Af/J/tsZ//GSS0XvnDq1H+N1wgcJyyfdLDK8mip46QP8BMgxuKgFvDgkA5976uM4
81JgfKzMPBKxhT9yTxOYIrdBHiEK7Wx3RvVgtqfQY+s6E9gj3tSKyfiPj24gjHKs
85tI/OcueUomS7hUfophfCgaPUt5rttIjr8XJr3V67O024AXhQwZku6WuLW1GaGm
Pc84mDT4hh2+JR2mEb+eHAEFvkf7d/JXaizpI7Ut+y8We9LrfccajJo6yXfXz2Hx
/XLbFuAyz6z8VnBFZzP2TaVPML1JLlxcZECqbcxaCFRM+eln5HQqjyiFuKFZmY1F
R2t+6ZWN7JB1G5OXuw9Wg/lUx1WJ2QvRWS3QkVSlDhibZFIS8sI1RbSqyhuqeCFX
SYkbrlu0x0uefVBm5u4paqa5VhIApNBEXzTKaljPpujcFMoHHGA=
=61oo
-----END PGP SIGNATURE-----
commit

1cad71b488988d912a62f8c29e10711d56968c16

4 files changed, 495 insertions(+), 0 deletions(-)

jump to
A .gitignore

@@ -0,0 +1,4 @@

+*.rom +*.rom.sym +test* +taro-ctl
A build.sh

@@ -0,0 +1,5 @@

+#!/bin/sh + +uxnasm taro-ls.tal taro-ls.rom + +crystal build taro-ctl.cr
A taro-ctl.cr

@@ -0,0 +1,111 @@

+require "process" +require "io/memory" +require "io" + +module Taro + enum WinType + LIST + READER + COMPOSE + end + + class ChildWindow + @status : Channel(String) + @stdout_w : IO::FileDescriptor + @stdout_r : IO::FileDescriptor + @stdin_w : IO::FileDescriptor + @stdin_r : IO::FileDescriptor + + def initialize(w : WinType = WinType::LIST) + @stdout_r, @stdout_w = IO.pipe + @stdin_r, @stdin_w = IO.pipe + @status = Channel(String).new + + uxnrom : String = "" + + case w + when WinType::LIST then uxnrom = "taro-ls" + when WinType::READER then uxnrom = "taro-reader" + when WinType::COMPOSE then uxnrom = "taro-compose" + end + + uxnargs = ["-s", "1", "#{uxnrom}.rom"] + + spawn do + Process.run(command: "uxnemu", args: uxnargs, input: @stdin_r, output: @stdout_w, error: Process::Redirect::Inherit) + @status.send("ls closed") + end + end + + def lifetime + return @status + end + + def write_msg(msgtype : UInt8, data : Slice) + msgsz = UInt16.new(data.size > 16384 ? 16384 : data.size) + msgtype.to_io(@stdin_w, IO::ByteFormat::BigEndian) + 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) + else + @stdin_w.write(data[0..msgsz - 1]) + end + end + + def read_msg() + slc = Slice.new(16384) + @stdout_r.read(slc) + return slc[0].to_u8, slc[1..slc.size - 1] + end + + end + + class MblazeProxy + def list_mail(box : String = "INBOX") + mailCmd = " + mbox=${MBOX_ROOT}/#{box} + + mdirs ${mbox} | xargs minc > /dev/null + mlist ${mbox} | msort -dr | mseq -S | mscan" + + io = IO::Memory.new + Process.run(mailCmd, shell: true, output: io) + return io.to_s + end + end + + class TaroCtl + + @mblaze : MblazeProxy + @lsWin : ChildWindow + @readWins : Array(ChildWindow) + @composeWins : Array(ChildWindow) + + def initialize + @lsWin = ChildWindow.new + @readWins = Array(ChildWindow).new + @composeWins = Array(ChildWindow).new + + @mblaze = MblazeProxy.new + list = @mblaze.list_mail + + @lsWin.write_msg(2_u8, list.to_slice) + end + + def mainWindow + @lsWin + end + end + +end + +taro = Taro::TaroCtl.new + +loop do + select + when taro.mainWindow.lifetime.receive? + break + end +end
A taro-ls.tal

@@ -0,0 +1,375 @@

+( a blank file ) + +%MAIL_LIST { #02 } + +|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 + +@resizing [ $1 &x $2 &y $2 &dx $2 &dy $2 ] +@decoding [ $1 &msg_type $1 &counting $1 &count $2 &processed $2 ] +@list [ &bytes $2 &len $1 &offset $2 &elem_offset $1 &top $2 &height $1 &select_index $2 ] +@sb [ &len $1 &pos $1 &step $1 ] + +( 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 #0060 SUB2 #03 SFT2 NIP .list/height 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 + &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 ) + .decoding/processed LDZ2 .decoding/count LDZ2 EQU2 +JMP2r + +@on_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 + BRK + + &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 + + .Screen/height DEI2 #0060 SUB2 #03 SFT2 NIP .list/height STZ + .Mouse/state DEI + +JMP2r + +@on_screen ( -> ) + + + draw_mail_list + draw_resize_handle + clear_fg + draw_cursor + +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 ( -> ) + ;get-entry-color JSR2 #03 EQU ,&end JCN + ;blank .Screen/addr DEO2 + &while + .Screen/x DEI2 + .Screen/width DEI2 #0018 SUB2 + + GTH2 ,&end JCN + #04 .Screen/sprite DEO + .Screen/x DEI2 #0008 ADD2 .Screen/x DEO2 + + ,&while JMP &end + +JMP2r + +@draw_mail_list ( -> ) + +#0008 .Screen/x DEO2 +#0020 .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 + #0008 .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 + +@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 #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 ] +@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