From 1c7ed060b8dd789920d78d24f0e9255c08bb4bd4 Mon Sep 17 00:00:00 2001 From: d6 Date: Wed, 9 Feb 2022 02:35:46 -0500 Subject: [PATCH] opening files, etc --- femto | 2 +- femto.tal | 109 +++++++++++++++++++++++++++++++++--------------------- 2 files changed, 67 insertions(+), 44 deletions(-) diff --git a/femto b/femto index 798ecda..a5244dd 100755 --- a/femto +++ b/femto @@ -4,6 +4,6 @@ TTY=`stty -g` uxnasm femto.tal femto.rom if [ $? -eq 0 ]; then stty raw -echo - uxncli femto.rom + uxncli femto.rom "$@" stty "$TTY" fi diff --git a/femto.tal b/femto.tal index 311ce0a..c78af14 100644 --- a/femto.tal +++ b/femto.tal @@ -55,8 +55,19 @@ ( blue, magenta, cyan, white ) |0100 + ;read-filename .Console/vector DEO2 - ;demo-path .File/name DEO2 +( ;demo-path ;open-file JSR2 ) + + ( use this if hardcoding to 80x24 ) +( ;setup-80x24 JSR2 ) + + ( use this to detect terminal size ) + ( ;setup-terminal-size JSR2 ) + BRK + +@open-file ( filename* -> ) + .File/name DEO2 #8000 .File/length DEO2 ;buffer/data .File/read DEO2 @@ -66,15 +77,63 @@ &ok ( save how many bytes were read ) .File/success DEI2 ;buffer/data ADD2 ;buffer/limit STA2 + JMP2r - ( use this if hardcoding to 80x24 ) +@setup-terminal-size + #fe #fe ;term-move-cursor JSR2 + ;term-get-cursor-position JSR2 + ;tmp/data ;tmp/pos STA2 + ;receive-terminal-size .Console/vector DEO2 + JMP2r + +@receive-terminal-size + .Console/read DEI ;tmp/pos LDA2 STA + ;tmp/pos LDA2 INC2 ;tmp/pos STA2 + .Console/read DEI LIT 'R EQU ;parse-terminal-size JCN2 + BRK + +@parse-terminal-size ( -> ) + LIT2r 0000 LIT2r 0000 + ;tmp/data LDAk #1b NEQ ,&parse-error JCN ( i ) INC2 + LDAk LIT '[ NEQ ,&parse-error JCN ( i ) INC2 + &loop + LDAk LIT '; EQU ,&parse-col JCN + LIT2r 000a MUL2r + LDAk LIT '0 SUB #00 SWP STH2 ADD2r + INC2 ,&loop JMP + &parse-col + INC2 STH2r ;term/rows STA2 + &loop2 + LDAk LIT 'R EQU ,&done JCN + LIT2r 000a MUL2r + LDAk LIT '0 SUB #00 SWP STH2 ADD2r + INC2 ,&loop2 JMP + &done + STH2r ;term/cols STA2 POP2 + ;on-key .Console/vector DEO2 + ;draw-all JSR2 + BRK + &parse-error LDAk #00 #00 DIV + +@setup-80x24 ( -> ) #0050 ;term/cols STA2 #0014 ;term/rows STA2 ;on-key .Console/vector DEO2 ;draw-all JSR2 + JMP2r - ( use this to detect terminal size ) - ( ;query-terminal-size JSR2 ) +@read-filename ( -> ) + #12 DEI #0a EQU ,&execute JCN ( did we read \n ? ) + #12 DEI ;tmp/pos LDA2 STA ( no, so save in buffer ) + ;tmp/pos LDA2 INC2 ;tmp/pos STA2 ( pos++ ) + BRK ( return ) + + &execute ( we saw a newline, so do something ) + #00 ;tmp/pos LDA2 STA ( null terminate str ) + ;tmp/data ;tmp/pos STA2 ( reset pos ) + ;tmp/data ;open-file JSR2 ( open file ) +( ;setup-80x24 JSR2 ) + ;setup-terminal-size JSR2 BRK @@ -214,42 +273,6 @@ @min ( x^ y^ -> min^ ) LTHk JMP SWP POP JMP2r -@query-terminal-size - #fe #fe ;term-move-cursor JSR2 - ;term-get-cursor-position JSR2 - ;tmp/data ;tmp/pos STA2 - ;receive-terminal-size .Console/vector DEO2 - JMP2r - -@receive-terminal-size - .Console/read DEI ;tmp/pos LDA2 STA - ;tmp/pos LDA2 INC2 ;tmp/pos STA2 - .Console/read DEI LIT 'R EQU ;parse-terminal-size JCN2 - BRK - -@parse-terminal-size ( -> ) - LIT2r 0000 LIT2r 0000 - ;tmp/data LDAk #1b NEQ ,&parse-error JCN ( i ) INC2 - LDAk LIT '[ NEQ ,&parse-error JCN ( i ) INC2 - &loop - LDAk LIT '; EQU ,&parse-col JCN - LIT2r 000a MUL2r - LDAk LIT '0 SUB #00 SWP STH2 ADD2r - INC2 ,&loop JMP - &parse-col - INC2 STH2r ;term/rows STA2 - &loop2 - LDAk LIT 'R EQU ,&done JCN - LIT2r 000a MUL2r - LDAk LIT '0 SUB #00 SWP STH2 ADD2r - INC2 ,&loop2 JMP - &done - STH2r ;term/cols STA2 POP2 - ;on-key .Console/vector DEO2 - ;draw-all JSR2 - BRK - &parse-error LDAk #00 #00 DIV - @term-move-cursor ( col^ row^ -> ) ansi INC ( row+1 ) ;emit-dec JSR2 LIT '; emit INC ( col+1 ) ;emit-dec JSR2 @@ -278,7 +301,7 @@ @draw-all ;term-erase-all JSR2 - ;draw-statusbar JSR2 +( ;draw-statusbar JSR2 ) #00 #00 ;term-move-cursor JSR2 #00 STH ;buffer/offset LDA2 @@ -405,7 +428,7 @@ &do2 #000a ;mod-div2 JSR2 NIP ;emit-digit JSR2 &do1 NIP ;emit-digit JSR2 JMP2r -@tmp [ &pos :buffer/data &data $100 ] +@tmp [ &pos :tmp/data &data $100 ] @term [ &cols 0050 &rows 0018 ] ( 80x24 ) @input-error "input 20 "error 00 @@ -417,7 +440,7 @@ ( did we just see ESC? ) @saw-esc 00 -|1ffc +( |1ffc ) ( offset is address of the first visible line ) ( size is total size of data in bytes ) @buffer [ &limit 0000 &offset :buffer/data &data $8000 ]