This commit is contained in:
Erik Osheim 2022-02-09 20:04:12 -05:00
parent 1c7ed060b8
commit 99e2ac5a1c
2 changed files with 67 additions and 59 deletions

125
femto.tal
View File

@ -1,7 +1,40 @@
( femto.tal )
( )
( requires terminal to be in raw mode )
( femto.tal )
( )
( requires terminal to be in raw mode )
( see femto launcher script for more details )
( )
( ANSI sequences )
( )
( goto $row,$col ESC [ $row ; $col H )
( goto home ESC [ H )
( go up ESC [ A )
( go down ESC [ B )
( go right ESC [ C )
( go left ESC [ D )
( )
( query cursor ESC [ 6 n )
( )
( all scroll on ESC [ r )
( region scroll on ESC [ $y0 ; $y1 r )
( scroll down ESC D )
( scroll up ESC M )
( )
( erase cur->eol ESC [ K )
( erase cur->sol ESC [ 1 K )
( erase line ESC [ 2 K )
( erase line->bot ESC [ J )
( erase line->top ESC [ 1 J )
( erase all ESC [ 2 J )
( )
( set attrs ESC [ $at1 ; ... m )
( reset ESC [ m )
( 0 reset, 1 bright, 2 dim, )
( 4 underscore, 5 blink, )
( 7 reverse, 8 hidden )
( )
( fg (30-37), bg (40-47) )
( black, red, green, yellow, )
( blue, magenta, cyan, white )
|00 @System [ &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1 ]
|10 @Console [ &vector $2 &read $1 &pad $5 &write $1 &error $1 ]
@ -13,7 +46,6 @@
%nl { #0a18 DEO }
%cr { #0d18 DEO }
%exit { #01 .System/halt DEO BRK }
%ansi { #1b18 DEO #5b18 DEO }
%PEN-COL { ;term/cols LDA2 #0002 SUB2 NIP }
@ -22,64 +54,33 @@
%LAST-LINE { ;term/rows LDA2 #0001 SUB2 NIP }
%PEN-LINE { ;term/rows LDA2 #0002 SUB2 NIP }
( ANSI sequences )
( goto $row,$col ESC [ $row ; $col H )
( goto home ESC [ H )
( go up ESC [ A )
( go down ESC [ B )
( go right ESC [ C )
( go left ESC [ D )
( )
( query cursor ESC [ 6 n )
( )
( all scroll on ESC [ r )
( region scroll on ESC [ $y0 ; $y1 r )
( scroll down ESC D )
( scroll up ESC M )
( )
( erase cur->eol ESC [ K )
( erase cur->sol ESC [ 1 K )
( erase line ESC [ 2 K )
( erase line->bot ESC [ J )
( erase line->top ESC [ 1 J )
( erase all ESC [ 2 J )
( )
( set attrs ESC [ $at1 ; ... m )
( reset ESC [ m )
( 0 reset, 1 bright, 2 dim, )
( 4 underscore, 5 blink, )
( 7 reverse, 8 hidden )
( )
( fg (30-37), bg (40-47) )
( black, red, green, yellow, )
( blue, magenta, cyan, white )
|0100
;read-filename .Console/vector DEO2
( ;demo-path ;open-file JSR2 )
( ;demo-path ;open-file JSR2 )
( use this if hardcoding to 80x24 )
( ;setup-80x24 JSR2 )
( ;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
.File/name DEO2
#8000 .File/length DEO2
;buffer/data .File/read DEO2
.File/success DEI2 #0000 GTH2 ,&ok JCN
;input-error ;println JSR2 nl exit
&ok
( save how many bytes were read )
.File/success DEI2 ;buffer/data ADD2 ;buffer/limit STA2
( calculate buffer limit address using start + size )
&ok .File/success DEI2 ;buffer/data ADD2 ;buffer/limit STA2
JMP2r
@setup-terminal-size
( ;setup-80x24 JSR2 )
#fe #fe ;term-move-cursor JSR2
;term-get-cursor-position JSR2
;tmp/data ;tmp/pos STA2
@ -94,7 +95,7 @@
@parse-terminal-size ( -> )
LIT2r 0000 LIT2r 0000
;tmp/data LDAk #1b NEQ ,&parse-error JCN ( i ) INC2
;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
@ -123,16 +124,15 @@
JMP2r
@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 )
#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 )
&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-terminal-size JSR2
BRK
@ -244,16 +244,23 @@
;draw-all JSR2
BRK
( TODO: 8-bit meta/alt? )
( TODO: tab? )
@on-key
;saw-esc LDA ,&escaped JCN ,&unmodified JMP
&escaped
( TODO: M-v for page up and M-> for goto end )
( M-f and M-b for next/previous word )
( M-n and M-p for next/previous paragraph )
( maybe M-% for search&replace )
@on-key-escaped
#00 ;saw-esc STA
.Console/read DEI LIT '< EQU ( M-< ) ;goto-start JCN2
.Console/read DEI LIT '> EQU ( M-> ) ;goto-end JCN2
BRK
&unmodified
( TODO: C-g or C-h for help )
( TODO: C-s for search )
( TODO: C-v for page down )
( TODO: 8-bit meta/alt? )
( TODO: tab input? )
@on-key
;saw-esc LDA ;on-key-escaped JCN2
.Console/read DEI #01 EQU ( C-a ) ;bol JCN2
.Console/read DEI #02 EQU ( C-b ) ;back JCN2
.Console/read DEI #04 EQU ( C-d ) ;delete JCN2

View File

@ -1,5 +1,6 @@
#!/bin/sh
for NAME in about.txt math32.tal test-math32.tal tester.py primes32.tal regex.tal repl-regex.tal test-regex.tal grep.tal femto.tal femto.txt femto rainbow.tal drums.tal drums2.tal bfloat16.tal fixed.tal; do
echo "-> $NAME"
cp $NAME /var/www/plastic-idolatry.com/html/erik/nxu
done