From db6c547aa0dcc2431f0817f44ad3b6f02e6242ae Mon Sep 17 00:00:00 2001 From: d6 Date: Sat, 21 Jan 2023 15:41:27 -0500 Subject: [PATCH] terminal junk --- term.py | 46 +++++++++++++++++++++++ term.tal | 111 ++++++++++++++++++------------------------------------- 2 files changed, 81 insertions(+), 76 deletions(-) create mode 100755 term.py diff --git a/term.py b/term.py new file mode 100755 index 0000000..f3958f7 --- /dev/null +++ b/term.py @@ -0,0 +1,46 @@ +#!/usr/bin/python + +from select import select +from subprocess import Popen, PIPE, STDOUT +import sys + +# TODO: byte-by-byte I/O is painful. figure out better buffering +# that doesn't break everything + +# currently line-buffered +def run(args): + #return Popen(args, stdin=PIPE, stdout=PIPE, stderr=STDOUT, bufsize=1, universal_newlines=True) + return Popen(args, stdin=PIPE, stdout=PIPE, stderr=STDOUT, bufsize=0) + +def main(): + args = sys.argv[1:] + if len(args) < 2: + print('usage: %s ROM SHELL') + print('') + print('execute the given uxn terminal program (ROM)') + print('and start a shell process (SHELL).') + sys.exit(1) + rom = args[0] + shell = args[1] + + term = run(['uxnemu', rom]) + term_out = term.stdout.fileno() + + shell = run([shell]) + shell_out = shell.stdout.fileno() + + while shell.poll() is None and term.poll() is None: + # wait 100ms to see if anything is ready to write + ns, _, _ = select([term_out, shell_out], [], [], 0.1) + for n in ns: + if n == term_out: + shell.stdin.write(term.stdout.read(1)) + shell.stdin.flush() + elif n == shell_out: + term.stdin.write(shell.stdout.read(1)) + term.stdin.flush() + else: + raise Exception('unexpected fileno: %d (expected %d or %d)' % (n, term_out, shell_out)) + +if __name__ == "__main__": + main() diff --git a/term.tal b/term.tal index d4d15fb..56c5494 100644 --- a/term.tal +++ b/term.tal @@ -13,8 +13,9 @@ @cur-x $2 ( cursor x: 0 <= cur-x < cols ) @cur-y $2 ( cursor y: 0 <= cur-y < rows ) - @bg-frame $2 - @bg-counter $1 + @buffer $80 ( input buffer ) + @pos $1 ( buffer position ) + @subinput $1 ( reading from subprocess? ) |0100 ( 32 characters = 256 pixels ) @@ -26,72 +27,25 @@ .cols LDZ2 #30 SFT2 .Screen/w DEO2 ( set colors ) - #0ff3 .System/r DEO2 - #0fd5 .System/g DEO2 - #2f66 .System/b DEO2 -( #08f3 .System/r DEO2 + #08f3 .System/r DEO2 #0cd5 .System/g DEO2 - #0b66 .System/b DEO2 ) + #0b66 .System/b DEO2 + + ( set pos, subinput flag ) + .buffer .pos STZ + #00 .subinput STZ ( clear screen for initial draw ) ;clear-screen JSR2 - ( draw background ) - #0000 .bg-frame STZ2 - #00 .bg-counter STZ -( #0000 ;draw-background JSR2 ) - ( set up interrupts ) ;redraw .Screen/vect DEO2 ( set up screen ) ;on-key .Controller/vect DEO2 ( set up keyboard ) + ;on-input .Console/vect DEO2 ( set up stdin ) ( return ) BRK -@draw-background ( frame* -> ) - STH2 - - STH2kr #70 SFT2 ;cyber ADD2 #0048 ADD2 .Screen/addr DEO2 - LIT2r 000f LIT2 0000 - &loop1 - DUP2 #30 SFT2 .Screen/y DEO2 - DUP2 .cols LDZ2 OVR2 SUB2 ,hline JSR - INC2 DUP2 STH2kr LTH2 ,&loop1 JCN - POP2 POP2r - - STH2kr #70 SFT2 ;cyber ADD2 #0040 ADD2 .Screen/addr DEO2 - LIT2r 0020 LIT2 0011 - &loop2 - DUP2 #30 SFT2 .Screen/y DEO2 - .rows LDZ2 OVR2 INC2 SUB2 .cols LDZ2 OVR2 SUB2 ,hline JSR - INC2 DUP2 STH2kr LTH2 ,&loop2 JCN - POP2 POP2r - - POP2r JMP2r - -@dline ( n -> ) - #0000 SWP2 SUB2 STH2 - &loop - .Screen/x DEI2 #0008 ADD2 .Screen/x DEO2 - .Screen/y DEI2 #0008 ADD2 .Screen/y DEO2 - #02 .Screen/sprite DEO - INC2r STH2kr ORA ,&loop JCN - POP2r JMP2r - -@hline ( x1 x2 -> ) - STH2 &loop - DUP2 #30 SFT2 .Screen/x DEO2 - #02 .Screen/sprite DEO - INC2 DUP2 STH2kr LTH2 ,&loop JCN - POP2 POP2r JMP2r - -@vline ( y1 y2 -> ) - STH2 &loop - DUP2 #30 SFT2 .Screen/y DEO2 - #02 .Screen/sprite DEO - INC2 DUP2 STH2kr LTH2 ,&loop JCN - POP2 POP2r JMP2r - @clear-screen #01 .dirty STZ ;screen STH2 @@ -105,14 +59,6 @@ JMP2r @redraw - .bg-counter LDZ DUP ,&done-bg JCN - .bg-frame LDZ2 - ( DUP2 NIP LIT "a ADD #18 DEO #0a #18 DEO ) - DUP2 ;draw-background JSR2 - INC2 #0007 AND2 .bg-frame STZ2 - &done-bg - INC #03 AND .bg-counter STZ - #41 .tint STZ .dirty LDZ #00 EQU ,&done JCN ;screen STH2 @@ -135,11 +81,12 @@ &done BRK @hide-cursor + .tint LDZ #41 .tint STZ - ;draw-cursor JMP2 + ;draw-cursor JSR2 + .tint STZ JMP2r @show-cursor - #44 .tint STZ ;draw-cursor JMP2 @draw-cursor @@ -150,9 +97,18 @@ @on-key .Controller/key DEI #00 EQU ,&skip JCN + #00 .subinput STZ + #41 .tint STZ .Controller/key DEI ;read JSR2 &skip BRK +@on-input + .Console/r DEI #00 EQU ,&skip JCN + #01 .subinput STZ + #41 .tint STZ + .Console/r DEI ;read JSR2 + &skip BRK + @read ( byte^ -> ) DUP #07 EQU ;read-bel JCN2 DUP #08 EQU ;read-bs JCN2 @@ -164,12 +120,21 @@ ;read-normal JMP2 @read-bel JMP2r -@read-bs POP ;scroll JMP2 +@read-bs POP ;scroll JMP2 ( FIXME ) @read-tab POP POP2r #0000 DIV @read-esc JMP2r @read-del JMP2r +@write-line ( -> ) + .pos LDZ .buffer + &loop GTHk ,&next JCN ,&done JMP + &next LDZk .Console/w DEO INC ,&loop JMP + &done #0a .Console/w DEO .buffer .pos STZ JMP2r + @read-cr ( 0d -> ) + .subinput LDZ ,&display JCN + ;write-line JSR2 + &display POP ;hide-cursor JSR2 #0000 .cur-x STZ2 @@ -207,6 +172,9 @@ JMP2r @read-normal ( c -> ) + .subinput LDZ ,&display JCN + .pos LDZ STZk INC .pos STZ + &display ;hide-cursor JSR2 DUP ;cursor-addr JSR2 STA ;draw-tile JSR2 @@ -240,15 +208,6 @@ @ascii ~chr/ascii.tal -( cyber background ) -@cyber - ~chr/cyber.tal - ( screen to store characters for redraw, etc. ) @screen $0800 ( 64 x 32 ) @end-screen - -( northwest=10 north=40 northeast=28 ) -( west=30 center=56 east=38 ) -( southwest=20 south=48 southeast=08 ) -@bg-layout $0800