From cc64e29e35fc6cef4b348dda344ace2580dfd5dc Mon Sep 17 00:00:00 2001 From: d_m Date: Fri, 1 Mar 2024 21:49:46 -0500 Subject: [PATCH] uxn11 subprocess compat --- term.tal | 177 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 127 insertions(+), 50 deletions(-) diff --git a/term.tal b/term.tal index e11bb4a..e27d1a9 100644 --- a/term.tal +++ b/term.tal @@ -78,13 +78,32 @@ ( special graphics [] changes 95-126 ) -|00 @System [ &vect $2 &expansion $2 &title $2 &metadata $2 &r $2 &g $2 &b $2 ] -|10 @Console [ &vect $2 &r $1 &exec $2 &mode $1 &dead $1 &exit $1 &w $1 ] -|20 @Screen [ &vect $2 &w $2 &h $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &px $1 &sprite $1 ] -|80 @Controller [ &vect $2 &button $1 &key $1 &fn $1 ] -|90 @Mouse [ &vect $2 &x $2 &y $2 &state $1 &pad $3 &scrollx $2 &scrolly $2 ] -|a0 @File1 [ &vect $2 &ok $2 &stat $2 &del $1 &append $1 &name $2 &len $2 &r $2 &w $2 ] -|b0 @File2 [ &vect $2 &ok $2 &stat $2 &del $1 &append $1 &name $2 &len $2 &r $2 &w $2 ] +|00 @System [ + &vect $2 &expansion $2 &title $2 &metadata $2 + &r $2 &g $2 &b $2 ] + +|10 @Console [ + &vect $2 &stdin $1 &pad1 $4 &type $1 + &stdout $1 &stderr $1 &proc-put $1 &pad2 $1 ¶m $2 &opts $1 &host-put $1 ] + +|20 @Screen [ + &vect $2 &w $2 &h $2 &auto $1 &pad $1 + &x $2 &y $2 &addr $2 &px $1 &sprite $1 ] + +|80 @Controller [ + &vect $2 &button $1 &key $1 &fn $1 ] + +|90 @Mouse [ + &vect $2 &x $2 &y $2 &state $1 &pad1 $1 + &pad2 $2 &scrollx $2 &scrolly $2 &pad3 $2 ] + +|a0 @File1 [ + &vect $2 &ok $2 &stat $2 &del $1 &append $1 + &name $2 &len $2 &r $2 &w $2 ] + +|b0 @File2 [ + &vect $2 &ok $2 &stat $2 &del $1 &append $1 + &name $2 &len $2 &r $2 &w $2 ] |0000 @tint $1 ( draw mode. 01=regular, 04=inverted ) @@ -123,8 +142,12 @@ ( user configuration ) @debug $1 ( use debug log? ) @show-banner $1 ( show banner on startup? ) - @visual-bell $1 ( use visual belL? 01: visual bell, 00: do nothing ) - @border-pad $2 ( use border? must be either 0000 or 0010 ) + @visual-bell $1 ( flash visual bell? otherwise do nothing ) + @border-pad $2 ( use border? should be 0000 or 0010 ) + + ( subprocess ) + @put-port $1 + @get-type $1 |0100 ( metadata ) @@ -157,18 +180,50 @@ ;on-mouse .Mouse/vect DEO2 ( set up mouse callback ) ;on-read .Console/vect DEO2 ( set up stdin callback ) - setup-subprocess ( set up experimental subprocess support ) + setup-shell ( set up experimental subprocess support ) reset-terminal ( initialize terminal state and settings ) setup-debugging ( set up debugging if requested ) draw-banner ( draw banner if requested ) BRK +@env "TERM=ansi 00 + +@query + ( expansion cmd ) 03 + ( console device ) 10 + ( uuid ) 0123 1250 d878 4462 bc41 d092 7645 a2fa + ( version ) 00 + ( flags ) &flags 0000 + +@has-subprocess ( -> bool^ ) + ;query .System/expansion DEO2 + ;query/flags LDA2 #00ff EQU2 JMP2r + ( these only work with a patched uxnemu ) ( on other emulators they should be no-ops ) -@setup-subprocess ( -> ) - ;shell .Console/exec DEO2 ( set up bash subprocess ) - #80 .Console/mode DEO ( start bash subprocess ) +@setup-shell ( -> ) + has-subprocess ?{ + ( without subprocess, just use stdin/stdout ) + .Console/stdout .put-port STZ + #01 .get-type STZ + JMP2r + } + + ( with subprocess, use proc put/get ) + .Console/proc-put .put-port STZ + #21 .get-type STZ + + ( setenv 'TERM=ansi' ) + ;env .Console/param DEO2 + #11 .Console/host-put DEO + + ( exec 'bash -i' ) + #81 .Console/opts DEO + ;shell .Console/param DEO2 + #01 .Console/host-put DEO + + ( TODO: run stty to communicate terminal size? ) JMP2r @setup-debugging ( -> ) @@ -201,8 +256,11 @@ #01 .tcem STZ ( show cursor ) #00 .paste STZ ( bracketed paste is off ) - init-screen ( ; prepare for initial draw ) - draw-border ( ; draw border ) + ( prepare for initial draw ) + init-screen + + ( draw border ) + .border-pad LDZ2 ORA ?draw-border JMP2r @update-dimensions ( -> ) @@ -219,7 +277,7 @@ .rows LDZ2 #000c MUL2 ADD2 .Screen/h DEO2 JMP2r -@shell "bash 00 "-i 00 00 +@shell "bash 20 "-l 20 "-i 00 @load-theme ( -> ) ;&path .File1/name DEO2 @@ -278,15 +336,13 @@ ( uses the existing .Screen/x and .Screen/y ) ( returns them to their starting values when finished ) @erase-fg-cell ( -> ) - ;cp437/nul .Screen/addr DEO2 ( ; use nul character to erase ) - #43 .Screen/sprite DEO ( ; s/s<-40 ) + #40 .Screen/sprite DEO ( ; s/s<-40 ) .Screen/y DEI2k STH2k ( zp^ y* [y*] ) #0004 ADD2 ROT DEO2 ( [y*] ; s/y<-y+4 ) - #43 .Screen/sprite DEO STH2r ( y* ; s/s<-40 ) + #40 .Screen/sprite DEO STH2r ( y* ; s/s<-40 ) .Screen/y DEO2 JMP2r ( ; s/y<-y ) @draw-border ( -> ) - .border-pad LDZ2 ORA ?{ JMP2r } ;cp437/space .Screen/addr DEO2 #04 .Screen/sprite #0000 draw-border/row @@ -378,7 +434,7 @@ ( send ESC [ $c ) @arrow ( c^ -> ) - .Console/w STH + ( .Console/proc-put ) .put-port LDZ STH ( TODO: send ESC-$c in VT-52 mode ) ( TODO: send ESC-O-$c in "cursor key mode set" ) #1b STHkr DEO LIT "[ STHkr DEO STHr DEO @@ -387,11 +443,11 @@ @paste-from-buf ( size* -> ) ;paste-buf SWP2 OVR2 ADD2 SWP2 ( limit* start* ) &loop ( limit* pos* ) - LDAk .Console/w DEO INC2 ( limit* pos+1* ) + LDAk ( .Console/proc-put ) .put-port LDZ DEO INC2 ( limit* pos+1* ) GTH2k ?&loop POP2 POP2 JMP2r @bracket-paste ( c^ -> ) - .Console/w STH + ( .Console/proc-put ) .put-port LDZ STH #1b STHkr DEO LIT "[ STHkr DEO LIT "2 STHkr DEO @@ -606,16 +662,16 @@ .Controller/key DEI DUP #08 NEQ ?&done POP #7f ( send DEL instead of BS ) - &done .Console/w DEO BRK + &done ( .Console/proc-put ) .put-port LDZ DEO BRK @ctrl ( -> is-down? ) .Controller/button DEI #01 AND JMP2r @alt ( -> is-down? ) .Controller/button DEI #02 AND JMP2r ( alt-XYZ emits ESC and then emits XYZ ) @on-alt-key ( -> BRK ) - #1b .Console/w DEO + #1b ( .Console/proc-put ) .put-port LDZ DEO ctrl ?on-ctrl-key - .Controller/key DEI .Console/w DEO BRK + .Controller/key DEI ( .Console/proc-put ) .put-port LDZ DEO BRK ( control seqs: ) ( ctrl-sp -> 00 ) @@ -650,10 +706,15 @@ &rs #1e !&done &us #1f !&done &c1 LIT "@ SUB - &done .Console/w DEO BRK + &done ( .Console/proc-put ) .put-port LDZ DEO BRK + +@read-or-brk ( -> BRK? ) + .Console/type DEI .get-type LDZ EQU ?{ BRK } JMP2r @on-read-priv ( -> BRK ) - .Console/r DEI + read-or-brk + ( .Console/type DEI #21 EQU ?{ BRK } ) + .Console/stdin DEI DUP LIT "; EQU ?next-arg DUP LIT "0 LTH ?end-arg-priv DUP LIT "9 GTH ?end-arg-priv @@ -663,7 +724,9 @@ POP ;on-read-priv .Console/vect DEO2 BRK @on-read-csi ( -> BRK ) - .Console/r DEI + read-or-brk + ( .Console/type DEI #21 EQU ?{ BRK } ) + .Console/stdin DEI DUP LIT "? EQU ?start-priv DUP LIT "; EQU ?next-arg DUP LIT "0 LTH ?end-arg @@ -671,7 +734,9 @@ !add-to-arg @on-read-osc ( -> BRK ) - .Console/r DEI + read-or-brk + ( .Console/type DEI #21 EQU ?{ BRK } ) + .Console/stdin DEI DUP #07 ( bell ) EQU ?&end-osc #9c ( esc-\ ) EQU ?&end-osc BRK &end-osc ;on-read .Console/vect DEO2 BRK @@ -763,11 +828,11 @@ DUP LIT "G EQU ?exec-cha ( CHA: move cursor to abs col ) DUP LIT "H EQU ?exec-cup ( CUP: move cursor [row;col] ) DUP LIT "I EQU ?exec-cht ( CHT: forward by tab stops ) - DUP LIT "J EQU ?exec-ed ( ED: erase display ) + DUP LIT "J EQU ?exec-ed ( ED: erase screen ) DUP LIT "K EQU ?exec-el ( EL: erase line ) DUP LIT "L EQU ?exec-il ( IL: insert $n blank lines ) DUP LIT "M EQU ?exec-dl ( DL: delete $n lines ) - DUP LIT "P EQU ?exec-dch ( DCH: delete n chars ) + DUP LIT "P EQU ?exec-dch ( DCH: delete $n chars ) DUP LIT "S EQU ?exec-su ( SU: scroll up ) DUP LIT "T EQU ?exec-sd ( SD: scroll down ) DUP LIT "X EQU ?exec-ech ( ECH: erase $n characters ) @@ -781,9 +846,7 @@ ( TODO: $r;$c f - HVP: horizontal/vertical position ) DUP LIT "g EQU ?exec-tbc ( TBC: clear tab stops ) DUP LIT "h EQU ?exec-sm ( SM: set mode ) - ( TODO: ?-$n-h - DECSET: set dec options ) DUP LIT "l EQU ?exec-rm ( RM: reset mode ) - ( TODO: ?-$n-l - DECRST: reset dec options ) DUP LIT "m EQU ?exec-sgr ( SGR: set graphical rendering ) DUP LIT "n EQU ?exec-dsr ( DSR: device status reports ) ( TODO: ?-$n-n - dec device status ) @@ -883,12 +946,12 @@ @dsr ( n* -> ) #0006 NEQ2 ?&done - #1b .Console/w DEO - LIT "[ .Console/w DEO + #1b ( .Console/proc-put ) .put-port LDZ DEO + LIT "[ ( .Console/proc-put ) .put-port LDZ DEO .cur-y LDZ2 INC2 emit-dec2 - LIT "; .Console/w DEO + LIT "; ( .Console/proc-put ) .put-port LDZ DEO .cur-x LDZ2 INC2 emit-dec2 - LIT "R .Console/w DEO + LIT "R ( .Console/proc-put ) .put-port LDZ DEO &done BRK @cnl ( n* -> ) clear-cursor #0000 .cur-x STZ2 !down-n @@ -958,7 +1021,9 @@ JMP2r @on-read-esc ( -> BRK ) - .Console/r DEI + read-or-brk + ( .Console/type DEI #21 EQU ?{ BRK } ) + .Console/stdin DEI DUP debug-esc &after ( TODO: SP-F, SP-G, SP-L, SP-M, SP-N ) @@ -1002,6 +1067,10 @@ ( "A" -> UK ) ( "B" -> USASCII ) ( "0" -> DEC special graphics, line drawing ) +( '(' = designate G0 charset ) +( ')' = designate G1 charset ) +( '*' = designate G2 charset ) +( '+' = designate G3 charset ) @start-charset ( c^ -> BRK ) POP ;on-read-skip .Console/vect DEO2 BRK @@ -1013,7 +1082,8 @@ ( TODO: 8-bit input not ready for prime time yet ) @on-read ( -> BRK ) - .Console/r DEI ( DUP #7f GTH ?read-8bit ) read BRK + read-or-brk + .Console/stdin DEI ( DUP #7f GTH ?read-8bit ) read BRK @read-8bit ( c^ -> BRK ) DUP debug-esc #80 SUB !on-read-esc/after @@ -1037,8 +1107,8 @@ DUP #08 EQU ?read-bs DUP #09 EQU ?read-tab ( HT ) DUP #0a EQU ?read-lf ( NL - LF ) - DUP #0b EQU ?read-lf ( VT - treated as LF ) - DUP #0c EQU ?read-lf ( FF - treated as LF ) + DUP #0b EQU ?read-lf ( VT - treat as LF ) + DUP #0c EQU ?read-lf ( FF - treat as LF ) DUP #0d EQU ?read-cr ( CR ) ( DUP #0e EQU ?&skip ( TODO: SO - shift out; G0 charset ) ) ( DUP #0f EQU ?&skip ( TODO: SI - shift in; G1 charset ) ) @@ -1251,7 +1321,7 @@ JMP2r ( ) @highlight-cell ( cell* -> ) - NIP LITr 47 ( c^ [tint^] ) + NIP LITr 07 ( c^ [tint^] ) #00 SWP #40 SFT2 ;cp437 ADD2 ( addr* [tint^] ) .Screen/addr DEO2k ( addr* s^ [tint^] ) STHkr .Screen/sprite DEO ( addr* s^ [tint^] ) @@ -1284,14 +1354,21 @@ ( emit a signed short as a decimal ) @emit-sdec2 ( n* -> ) - DUP2k #1f SFT2 EQUk ?&s LIT2 "- 18 DEO + DUP2k #1f SFT2 EQUk ?&s LIT "- ( .Console/proc-put ) .put-port LDZ DEO &s MUL2 SUB2 ( fall-through to emit-dec2 ) ( emit an unsigned short as a decimal ) @emit-dec2 ( n* -> ) - LITr ff00 &read #000a DIV2k STH2k MUL2 SUB2 STH2r INCr ORAk ?&read - POP2 &write NIP #30 ADD #18 DEO OVRr ADDr STHkr ?&write - POP2r JMP2r + LIT2r ff00 ( n* [ff^ 0^] ) + &read ( ... x* ) + #000a DIV2k STH2k ( x* 10* x/10* [ff^ i^ x/10*] ) + MUL2 SUB2 STH2r ( x%10* x/10* [ff^ i^] ) + INCr ORAk ?&read ( x%10* x/10* [ff^ i+1^] ) + POP2 ( x0* ... xn* [ff^ i+1^] ) + &write + NIP #30 ADD ( .Console/proc-put ) .put-port LDZ DEO ( x0* ... xn-1* [ff^ j^] ) + OVRr ADDr STHkr ?&write ( x* ... xn-1* [ff^ j-1^] ) + POP2r JMP2r ( ) @debug-log "debug_term.log 00 @scratch $40 &pos $2 @@ -1319,7 +1396,7 @@ &name "determ 0a &details "ansi 20 "terminal 20 "emulator 0a &author "by 20 "d_m 0a - &date "13 20 "nov 20 "2023 00 + &date "1 20 "mar 20 2024 00 02 ( device mask ) 41 0d07 ( 24x24 icon ) 83 =icon-2-bit @@ -1328,9 +1405,9 @@ 0d 0a 20 20 c9 cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd bb 0d 0a 20 20 ba 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ba 0d 0a - 20 20 ba 20 20 "d "e "t "e "r "m 20 20 "v "1 "1 20 20 ba 0d 0a + 20 20 ba 20 20 "d "e "t "e "r "m 20 20 "v "1 "4 20 20 ba 0d 0a 20 20 ba 20 20 20 20 "b "y 20 "d "_ "m 20 20 20 20 20 ba 0d 0a - 20 20 ba 20 20 "1 "3 20 "n "o "v 20 "2 "0 "2 "3 20 20 ba 0d 0a + 20 20 ba 20 20 20 "1 20 "m "a "r 20 "2 "0 "2 "4 20 20 ba 0d 0a 20 20 ba 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ba 0d 0a 20 20 c8 cd cd cb cd cd cd cd cd cd cd cd cd cb cd cd bc 0d 0a 20 20 c9 cb cb ce cb cb cb cb cb cb cb cb cb ce cb cb bb 0d 0a