opening files, etc

This commit is contained in:
~d6 2022-02-09 02:35:46 -05:00
parent b1c383477a
commit 1c7ed060b8
2 changed files with 67 additions and 44 deletions

2
femto
View File

@ -4,6 +4,6 @@ TTY=`stty -g`
uxnasm femto.tal femto.rom uxnasm femto.tal femto.rom
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
stty raw -echo stty raw -echo
uxncli femto.rom uxncli femto.rom "$@"
stty "$TTY" stty "$TTY"
fi fi

109
femto.tal
View File

@ -55,8 +55,19 @@
( blue, magenta, cyan, white ) ( blue, magenta, cyan, white )
|0100 |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 #8000 .File/length DEO2
;buffer/data .File/read DEO2 ;buffer/data .File/read DEO2
@ -66,15 +77,63 @@
&ok &ok
( save how many bytes were read ) ( save how many bytes were read )
.File/success DEI2 ;buffer/data ADD2 ;buffer/limit STA2 .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 #0050 ;term/cols STA2
#0014 ;term/rows STA2 #0014 ;term/rows STA2
;on-key .Console/vector DEO2 ;on-key .Console/vector DEO2
;draw-all JSR2 ;draw-all JSR2
JMP2r
( use this to detect terminal size ) @read-filename ( -> )
( ;query-terminal-size JSR2 ) #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 BRK
@ -214,42 +273,6 @@
@min ( x^ y^ -> min^ ) @min ( x^ y^ -> min^ )
LTHk JMP SWP POP JMP2r 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^ -> ) @term-move-cursor ( col^ row^ -> )
ansi INC ( row+1 ) ;emit-dec JSR2 ansi INC ( row+1 ) ;emit-dec JSR2
LIT '; emit INC ( col+1 ) ;emit-dec JSR2 LIT '; emit INC ( col+1 ) ;emit-dec JSR2
@ -278,7 +301,7 @@
@draw-all @draw-all
;term-erase-all JSR2 ;term-erase-all JSR2
;draw-statusbar JSR2 ( ;draw-statusbar JSR2 )
#00 #00 ;term-move-cursor JSR2 #00 #00 ;term-move-cursor JSR2
#00 STH #00 STH
;buffer/offset LDA2 ;buffer/offset LDA2
@ -405,7 +428,7 @@
&do2 #000a ;mod-div2 JSR2 NIP ;emit-digit JSR2 &do2 #000a ;mod-div2 JSR2 NIP ;emit-digit JSR2
&do1 NIP ;emit-digit JSR2 JMP2r &do1 NIP ;emit-digit JSR2 JMP2r
@tmp [ &pos :buffer/data &data $100 ] @tmp [ &pos :tmp/data &data $100 ]
@term [ &cols 0050 &rows 0018 ] ( 80x24 ) @term [ &cols 0050 &rows 0018 ] ( 80x24 )
@input-error "input 20 "error 00 @input-error "input 20 "error 00
@ -417,7 +440,7 @@
( did we just see ESC? ) ( did we just see ESC? )
@saw-esc 00 @saw-esc 00
|1ffc ( |1ffc )
( offset is address of the first visible line ) ( offset is address of the first visible line )
( size is total size of data in bytes ) ( size is total size of data in bytes )
@buffer [ &limit 0000 &offset :buffer/data &data $8000 ] @buffer [ &limit 0000 &offset :buffer/data &data $8000 ]