From b1c383477aa3ab982744135c1e15cd439422d1b0 Mon Sep 17 00:00:00 2001 From: d6 Date: Wed, 9 Feb 2022 01:05:11 -0500 Subject: [PATCH] improvements --- femto.tal | 89 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 58 insertions(+), 31 deletions(-) diff --git a/femto.tal b/femto.tal index 9275efb..311ce0a 100644 --- a/femto.tal +++ b/femto.tal @@ -16,25 +16,12 @@ %ansi { #1b18 DEO #5b18 DEO } -( %WIDTH { #50 } -%LAST-COL { #4f } -%PEN-COL { #4e } - -%HEIGHT { #18 } -%LAST-LINE { #17 } -%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 ) -( - '[' 5b ) -( - ) - ( ANSI sequences ) ( goto $row,$col ESC [ $row ; $col H ) ( goto home ESC [ H ) @@ -43,6 +30,8 @@ ( 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 ) @@ -77,9 +66,15 @@ &ok ( save how many bytes were read ) .File/success DEI2 ;buffer/data ADD2 ;buffer/limit STA2 -( ;on-key .Console/vector DEO2 ) -( ;draw-all JSR2 ) - ;query-terminal-size JSR2 + + ( use this if hardcoding to 80x24 ) + #0050 ;term/cols STA2 + #0014 ;term/rows STA2 + ;on-key .Console/vector DEO2 + ;draw-all JSR2 + + ( use this to detect terminal size ) + ( ;query-terminal-size JSR2 ) BRK @@ -180,7 +175,6 @@ &skip BRK @escape ( -> ) - #00 #00 DIV #01 ;saw-esc STA BRK @goto-end ( FIXME ) @@ -191,11 +185,11 @@ ;draw-all JSR2 BRK +( TODO: 8-bit meta/alt? ) ( 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 @@ -221,9 +215,8 @@ 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 + #fe #fe ;term-move-cursor JSR2 + ;term-get-cursor-position JSR2 ;tmp/data ;tmp/pos STA2 ;receive-terminal-size .Console/vector DEO2 JMP2r @@ -240,7 +233,6 @@ 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 @@ -258,14 +250,36 @@ 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 +@term-move-cursor ( col^ row^ -> ) + ansi INC ( row+1 ) ;emit-dec JSR2 + LIT '; emit INC ( col+1 ) ;emit-dec JSR2 LIT 'H emit JMP2r +@term-get-cursor-position + ansi LIT '6 emit LIT 'n emit JMP2r + +@term-erase-all + ansi LIT '2 emit LIT 'J emit JMP2r + +@draw-cursor + ;get-col JSR2 ;get-row JSR2 + ;term-move-cursor JSR2 JMP2r + +@draw-statusbar + #00 #17 ;term-move-cursor JSR2 + ansi LIT '7 emit LIT 'm emit + LIT2r 2018 + ;term/cols LDA2 #0000 + &loop GTH2k ,&continue JCN ,&done JMP + &continue DEOkr INC2 ,&loop JMP + &done POP2 POP2 POP2r + ansi LIT '0 emit LIT 'm emit + JMP2r + @draw-all - ansi LIT '2 emit LIT 'J emit - ansi LIT 'H emit + ;term-erase-all JSR2 + ;draw-statusbar JSR2 + #00 #00 ;term-move-cursor JSR2 #00 STH ;buffer/offset LDA2 &loop @@ -363,8 +377,10 @@ @line-last ( -> s* ) ;cursor/row LDA INC ;rel-line JSR2 #0001 SUB2 JMP2r @mod-div ( x^ y^ -> x%d x/y ) - DIVk ( x y x/y ) STHk ( x y x/y [x/y] ) MUL ( x y*x/y [x/y] ) - SUB ( x%y [x/y] ) STHr ( x%y x/y ) JMP2r + DIVk STHk MUL SUB STHr JMP2r + +@mod-div2 ( x^ y^ -> x%d x/y ) + DIV2k STH2k MUL2 SUB2 STH2r JMP2r @emit-digit ( n^ -> ) LIT '0 ADD emit JMP2r @@ -377,9 +393,20 @@ &do2 #0a ;mod-div JSR2 ;emit-digit JSR2 &do1 ;emit-digit JSR2 JMP2r +@emit-dec2 ( n* -> ) + DUP2 #270f GTH2 ,&do5 JCN + DUP2 #03e7 GTH2 ,&do4 JCN + DUP2 #0063 GTH2 ,&do3 JCN + DUP2 #0009 GTH2 ,&do2 JCN + ,&do1 JMP + &do5 #2710 ;mod-div2 JSR2 NIP ;emit-digit JSR2 + &do4 #03e7 ;mod-div2 JSR2 NIP ;emit-digit JSR2 + &do3 #0064 ;mod-div2 JSR2 NIP ;emit-digit JSR2 + &do2 #000a ;mod-div2 JSR2 NIP ;emit-digit JSR2 + &do1 NIP ;emit-digit JSR2 JMP2r + @tmp [ &pos :buffer/data &data $100 ] -( @term [ &cols $2 &rows $2 ] ) -@term [ &cols 0050 &rows 0018 ] +@term [ &cols 0050 &rows 0018 ] ( 80x24 ) @input-error "input 20 "error 00 @demo-path "math32.tal 00