femto term size

This commit is contained in:
Erik Osheim 2022-02-08 22:22:08 -05:00
parent ed484be3c2
commit b734ca5eab
2 changed files with 89 additions and 13 deletions

2
femto
View File

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

View File

@ -16,13 +16,19 @@
%ansi { #1b18 DEO #5b18 DEO }
%WIDTH { #50 }
( %WIDTH { #50 }
%LAST-COL { #4f }
%PEN-COL { #4e }
%HEIGHT { #18 }
%LAST-LINE { #17 }
%PEN-LINE { #16 }
%PEN-LINE { #16 } )
%PEN-COL { ;term/cols LDA2 #0002 SUB2 NIP }
%HEIGHT { ;term/rows LDA2 NIP }
%LAST-LINE { ;term/rows LDA2 #0001 SUB2 NIP }
%PEN-LINE { ;term/rows LDA2 #0002 SUB2 NIP }
( useful ASCII )
( - ESC 1b )
@ -69,9 +75,11 @@
;input-error ;println JSR2 nl exit
&ok
( save how many bytes were read )
.File/success DEI2 ;buffer/data ADD2 ;buffer/limit STA2
;on-key .Console/vector DEO2
;draw-all JSR2
( ;on-key .Console/vector DEO2 )
( ;draw-all JSR2 )
;query-terminal-size JSR2
BRK
@ -171,8 +179,28 @@
;draw-all JSR2
&skip BRK
@escape ( -> )
#00 #00 DIV
#01 ;saw-esc STA BRK
@goto-end ( FIXME )
@goto-start ( -> )
;buffer/data ;buffer/offset STA2
#00 ;cursor/col STA
#00 ;cursor/row STA
;draw-all JSR2
BRK
( TODO: tab? )
@on-key
;saw-esc LDA ,&escaped JCN ,&unmodified JMP
&escaped
#00 #00 DIV
#00 ;saw-esc STA
.Console/read DEI LIT '< EQU ( M-< ) ;goto-start JCN2
.Console/read DEI LIT '> EQU ( M-> ) ;goto-end JCN2
BRK
&unmodified
.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
@ -182,6 +210,7 @@
.Console/read DEI #0e EQU ( C-n ) ;down JCN2
.Console/read DEI #10 EQU ( C-p ) ;up JCN2
.Console/read DEI #18 EQU ( C-x ) ;quit JCN2
.Console/read DEI #1b EQU ( ESC ) ;escape JCN2
.Console/read DEI #7f EQU ( DEL ) ;backspace JCN2
.Console/read DEI #20 LTH ;ignore JCN2 ( ignore for now )
.Console/read DEI #7e GTH ;ignore JCN2 ( ignore for now )
@ -191,6 +220,44 @@
@min ( x^ y^ -> min^ )
LTHk JMP SWP POP JMP2r
@query-terminal-size
ansi #ff ;emit-dec JSR2 LIT '; emit
#ff ;emit-dec JSR2 LIT 'H emit
ansi LIT '6 emit LIT 'n emit
;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
( #00 #00 DIV )
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
@draw-cursor
ansi ;get-row JSR2 INC ;emit-dec JSR2
LIT '; emit ;get-col JSR2 INC ;emit-dec JSR2
@ -274,12 +341,6 @@
;buffer/limit STA2 ( )
JMP2r
@input-error "input 20 "error 00
@demo-path "math32.tal 00
( col is 0-79, row is 0-23 )
@cursor [ &col 00 &row 00 ]
@get-col
;cursor/col LDA ;cur-len JSR2 NIP ;min JSR2 JMP2r
@ -316,6 +377,19 @@
&do2 #0a ;mod-div JSR2 ;emit-digit JSR2
&do1 ;emit-digit JSR2 JMP2r
@tmp [ &pos :buffer/data &data $100 ]
( @term [ &cols $2 &rows $2 ] )
@term [ &cols 0050 &rows 0018 ]
@input-error "input 20 "error 00
@demo-path "math32.tal 00
( col is 0-79, row is 0-23 )
@cursor [ &col 00 &row 00 ]
( did we just see ESC? )
@saw-esc 00
|1ffc
( offset is address of the first visible line )
( size is total size of data in bytes )