From 52965adb5fbcad888bdb34513b8639e34a1415e3 Mon Sep 17 00:00:00 2001 From: d6 Date: Thu, 3 Mar 2022 21:12:26 -0500 Subject: [PATCH 1/6] draw line numbers, use color, support tabs --- femto.tal | 137 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 116 insertions(+), 21 deletions(-) diff --git a/femto.tal b/femto.tal index cffc433..41f630b 100644 --- a/femto.tal +++ b/femto.tal @@ -89,7 +89,7 @@ @open-file ( filename* -> ) .File/name DEO2 - #8000 .File/length DEO2 + #f000 .File/length DEO2 ;buffer/data .File/read DEO2 .File/success DEI2 #0000 GTH2 ,&ok JCN @@ -266,6 +266,19 @@ ;draw-all JSR2 BRK +@insert-tab ( -> ) + ;config/insert-tabs LDA ,&use-tabs JCN + #0000 ;config/tab-width LDA2 SUB2 + &loop + DUP2 #0000 EQU2 ,&done JCN + #20 ;cur-pos JSR2 ;shift-right JSR2 + INC2 ,&loop JMP + &done + ;cur-col JSR2 ;config/tab-width LDA2 ADD2 ;cursor/col STA2 + ;draw-all JSR2 BRK + &use-tabs + #09 ;insert JMP2 + ( TODO: handle last line ) @newline ( c^ -> ) #0a ;cur-pos JSR2 ;shift-right JSR2 @@ -360,7 +373,7 @@ ;buffer/line-offset STA2 ( n o [n-o] ) ;abs-line JSR2 ;buffer/offset STA2 ( n [n-o] ) #0000 ;cursor/col STA2 ( n [n-o] ) - POP2 STH2r ;cursor/row STA2 ( ) + POP2 STH2r ;cursor/row STA2 JMP2r @ensure-visible-cursor @@ -414,6 +427,7 @@ .Console/read DEI #04 EQU ( C-d ) ;delete JCN2 .Console/read DEI #05 EQU ( C-e ) ;eol JCN2 .Console/read DEI #06 EQU ( C-f ) ;forward JCN2 + .Console/read DEI #09 EQU ( \t ) ;insert-tab JCN2 .Console/read DEI #0c EQU ( C-l ) ;refresh JCN2 .Console/read DEI #0d EQU ( \r ) ;newline JCN2 .Console/read DEI #0e EQU ( C-n ) ;down JCN2 @@ -440,6 +454,9 @@ LIT '; emit INC2 ( col+1 ) ;emit-dec2 JSR2 LIT 'H emit JMP2r +@term-move-right ( n* -> ) + ansi ;emit-dec2 JSR2 LIT 'C emit JMP2r + @term-get-cursor-position ( -> ) ansi LIT '6 emit LIT 'n emit JMP2r @@ -447,12 +464,15 @@ ansi LIT '2 emit LIT 'J emit JMP2r @draw-cursor ( -> ) - ;cur-col JSR2 ;cur-row JSR2 + ;cur-w-col JSR2 ;term/lmargin LDA2 ADD2 + ;cur-row JSR2 ;term-move-cursor JSR2 JMP2r @draw-statusbar ( -> ) #0000 ;term/rows LDA2 ;term-move-cursor JSR2 - ansi LIT '7 emit LIT 'm emit + ansi ;config/color LDA2 emit emit + LIT2 '7 '; emit emit + LIT 'm emit ( esc [ 33 ; 7 m ) LIT2r 2018 ;term/cols LDA2 #0000 &loop GTH2k ,&continue JCN ,&done JMP @@ -479,25 +499,42 @@ ansi LIT '0 emit LIT 'm emit JMP2r +@draw-linenum ( n* -> ) + ansi ;config/color LDA2 emit emit LIT 'm emit + ;emit-dec2-pad JSR2 + ansi LIT2 'm '0 emit emit JMP2r + +@emit-tab ( -> ) + #0000 ;config/tab-width LDA2 SUB2 + LIT2r 2018 + &loop ORAk ,&next JCN POP2 POP2r JMP2r + &next DEOkr INC2 ,&loop JMP + @draw-all ( -> ) ;term-erase-all JSR2 #0000 #0000 ;term-move-cursor JSR2 - #0001 STH2 + ;buffer/line-offset LDA2 STH2 LIT2r 0001 ( [k line-offset] ) + ADD2kr STH2r ;draw-linenum JSR2 ;buffer/offset LDA2 &loop LDAk #00 EQU ,&eof JCN LDAk #0a EQU ,&eol JCN + LDAk #09 EQU ,&do-tab JCN LDAk emit INC2 ,&loop JMP + &do-tab ;emit-tab JSR2 INC2 ,&loop JMP &eol INC2r STH2kr ;term/rows LDA2 GTH2 ,&done JCN - cr nl INC2 ,&loop JMP + cr nl INC2 + ADD2kr STH2r ;draw-linenum JSR2 + ,&loop JMP &eof ansi LIT '3 emit LIT '1 emit LIT 'm emit &eof-loop STH2kr ;term/rows LDA2 GTH2 ,&done JCN cr nl + ;term/lmargin LDA2 ;term-move-right JSR2 LIT '~ emit INC2r ,&eof-loop JMP - &done POP2 POP2r + &done POP2 POP2r POP2r ansi LIT '0 emit LIT 'm emit ;draw-statusbar JSR2 ;draw-cursor JSR2 @@ -522,13 +559,28 @@ @cur-last ( -> n* ) ;cur-line JSR2 ;line-len JSR2 #0001 SUB2 JMP2r +@cur-width ( -> n* ) + ;cur-line JSR2 ;line-width JSR2 JMP2r + +@cur-w-last ( -> n* ) + ;cur-line JSR2 ;line-width JSR2 #0001 SUB2 JMP2r + @line-len ( s* -> n* ) #0000 STH2 &loop LDAk #00 EQU ,&end JCN LDAk #0a EQU ,&end JCN - INC2 INC2r ,&loop JMP + INC2 INC2r ,&loop JMP &end POP2 STH2r JMP2r +@line-width ( s* -> n* ) + #0000 STH2 + &loop LDAk #00 EQU ,&done JCN + LDAk #0a EQU ,&done JCN + LDAk #09 EQU ,&tabs JCN + INC2 INC2r ,&loop JMP + &tabs #0004 ADD2 ,&loop JMP + &done POP2 STH2r JMP2r + @abs-line ( y* -> s* ) #0000 SWP2 SUB2 STH2 ( [-y] ) ;buffer/data ( addr ) @@ -580,7 +632,7 @@ &done NIP2 DUP2 ( addr addr [prev^] ) STHr ROT ROT ( addr prev^ addr ) STA INC2 ( addr+1 ) - ;buffer/limit STA2 ( ) + ;buffer/limit STA2 ( ) JMP2r ( TODO: change last/addr order and GTH -> LTH to remove hack ) @@ -593,16 +645,21 @@ ROT ROT ( last addr+1 c1^ addr ) STA ,&loop JMP ( last addr+1 ) &done POP2 ( last ) - ;buffer/limit STA2 ( ) + ;buffer/limit STA2 ( ) #00 ;buffer/limit LDA2 STA ( ensure null termination ) JMP2r -( TODO: should be using cur-col and cur-row almost everywhere ) -( otherwise, bugs! ) - @cur-col ( -> col* ) ;cursor/col LDA2 ;cur-len JSR2 ;min2 JSR2 JMP2r +@cur-w-col ( -> col* ) + LIT2r 0000 ( [0] ) + ;cur-line JSR2 DUP2 ;cur-col JSR2 ADD2 SWP2 ( lim s [0] ) + &loop GTH2k ,&next JCN + POP2 POP2 STH2r JMP2r + &next LDAk #09 EQU ,&tabs JCN INC2 INC2r ,&loop JMP + &tabs INC2 ;config/tab-width LDA2 STH2 ADD2r ,&loop JMP + @cur-row ( -> row* ) ;cursor/row LDA2 JMP2r @@ -621,11 +678,14 @@ @mod-div2 ( x^ y^ -> x%d x/y ) DIV2k STH2k MUL2 SUB2 STH2r JMP2r -( @emit - &short ( s* -> ) SWP ,&byte JSR - &byte ( b^ -> ) DUP #04 SFT ,&nib JSR - &nib ( n^ -> ) #0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO - JMP2r ) +@base-10-width ( n* -> w* ) + LIT2r 0000 ( n [0] ) + &loop ( n [w] ) + DUP2 #0000 EQU2 ,&done JCN ( n [w] ) + #000a DIV2 ( n/10 [w] ) + INC2r ,&loop JMP ( n/10 [w+1] ) + &done ( 0 [w] ) + POP2 STH2r JMP2r @emit-digit ( n^ -> ) LIT '0 ADD emit JMP2r @@ -650,6 +710,20 @@ &do2 #000a ;mod-div2 JSR2 NIP ;emit-digit JSR2 &do1 NIP ;emit-digit JSR2 JMP2r +@emit-dec2-pad ( n* -> ) + LIT2r 2018 ( preload #20 .Console/write into rst ) + DUP2 #270f GTH2 ,&do5 JCN DEOkr + DUP2 #03e7 GTH2 ,&do4 JCN DEOkr + DUP2 #0063 GTH2 ,&do3 JCN DEOkr + DUP2 #0009 GTH2 ,&do2 JCN DEOkr + ,&do1 JMP + &do5 #2710 ;mod-div2 JSR2 NIP ;emit-digit JSR2 + &do4 #03e8 ;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 + DEOr JMP2r + @messages [ &input-error "input 20 "error 00 &bytes 20 "bytes, 00 &save-ok "saved 00 @@ -662,7 +736,28 @@ &data $100 ] @term [ &cols 0050 - &rows 0018 ] + &rows 0018 + &lmargin 0006 ] + +( COLORS ) +( ) +( SHORT STRING NAME ) +( 3033 "30" black ) +( 3133 "31" red ) +( 3233 "32" green ) +( 3333 "33" yellow ) +( 3433 "34" blue ) +( 3533 "35" magenta ) +( 3633 "36" cyan ) +( 3733 "37" white ) +( 3030 "00" default ) +( ) +( digits are reversed ) +( to emit from stack in ) +( last-in-first-out order ) +@config [ &tab-width 0004 + &insert-tabs 01 + &color 3333 ] ( relative cursor positions, e.g. 0 to cols-1 ) @cursor [ &col 0000 &row 0000 ] @@ -670,7 +765,7 @@ ( did we just see ESC? ) @saw-esc 00 -( ) +( ) @filename $80 ( |1ffc ) @@ -680,4 +775,4 @@ &offset :buffer/data &line-count 0000 &line-offset 0000 - &data $8000 ] + &data $f000 ] From 3fc2c9f16a9df941fb6fbb983d9acc5bc716449c Mon Sep 17 00:00:00 2001 From: d6 Date: Fri, 4 Mar 2022 01:47:11 -0500 Subject: [PATCH 2/6] long line support 50% working --- femto.tal | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/femto.tal b/femto.tal index 41f630b..f484a5d 100644 --- a/femto.tal +++ b/femto.tal @@ -400,7 +400,7 @@ BRK @move-to-message-line ( -> ) - #0002 ;term/rows LDA2 #0002 ADD2 ;term-move-cursor JSR2 JMP2r + #0002 ;term/rows LDA2 #0002 ADD2 ;term-move-cursor JMP2 ( JSR2 JMP2r ) ( TODO: filename prmopt ) @save ( -> ) @@ -466,7 +466,7 @@ @draw-cursor ( -> ) ;cur-w-col JSR2 ;term/lmargin LDA2 ADD2 ;cur-row JSR2 - ;term-move-cursor JSR2 JMP2r + ;term-move-cursor JMP2 ( JSR2 JMP2r ) @draw-statusbar ( -> ) #0000 ;term/rows LDA2 ;term-move-cursor JSR2 @@ -510,24 +510,42 @@ &loop ORAk ,&next JCN POP2 POP2r JMP2r &next DEOkr INC2 ,&loop JMP +@emit-red ( -> ) + ansi LIT '3 emit LIT '1 emit LIT 'm emit JMP2r + +@emit-reset ( -> ) + ansi LIT '0 emit LIT 'm emit JMP2r + +@emit-red-dollar ( -> ) + ;emit-red JSR2 LIT '$ emit ;emit-reset JMP2 + @draw-all ( -> ) ;term-erase-all JSR2 #0000 #0000 ;term-move-cursor JSR2 ;buffer/line-offset LDA2 STH2 LIT2r 0001 ( [k line-offset] ) ADD2kr STH2r ;draw-linenum JSR2 ;buffer/offset LDA2 - &loop + ;term/lmargin LDA2 INC2 ,&x STR2 + &loop ( offset [k line-offset] ) LDAk #00 EQU ,&eof JCN LDAk #0a EQU ,&eol JCN + ,&x LDR2 ;term/cols LDA2 + LTH2k ,&ok JCN + GTH2 ,&skip JCN + ;emit-red-dollar JSR2 ,&x LDR2 INC2 ,&x STR2 + &skip INC2 ,&loop JMP + &ok POP2 POP2 LDAk #09 EQU ,&do-tab JCN - LDAk emit INC2 ,&loop JMP - &do-tab ;emit-tab JSR2 INC2 ,&loop JMP + LDAk emit INC2 ,&x LDR2 INC2 ,&x STR2 ,&loop JMP + &do-tab ;emit-tab JSR2 INC2 ;config/tab-width LDA2 ,&x LDR2 ADD2 ,&x STR2 ,&loop JMP + [ &x $2 ] &eol INC2r STH2kr ;term/rows LDA2 GTH2 ,&done JCN cr nl INC2 ADD2kr STH2r ;draw-linenum JSR2 + ;term/lmargin LDA2 INC2 ,&x STR2 ,&loop JMP &eof - ansi LIT '3 emit LIT '1 emit LIT 'm emit + ;emit-red JSR2 &eof-loop STH2kr ;term/rows LDA2 GTH2 ,&done JCN cr nl @@ -535,7 +553,7 @@ LIT '~ emit INC2r ,&eof-loop JMP &done POP2 POP2r POP2r - ansi LIT '0 emit LIT 'm emit + ;emit-reset JSR2 ;draw-statusbar JSR2 ;draw-cursor JSR2 JMP2r @@ -554,13 +572,13 @@ &eof POP2 JMP2r @cur-len ( -> n* ) - ;cur-line JSR2 ;line-len JSR2 JMP2r + ;cur-line JSR2 ;line-len JMP2 ( JSR2 JMP2r ) @cur-last ( -> n* ) ;cur-line JSR2 ;line-len JSR2 #0001 SUB2 JMP2r @cur-width ( -> n* ) - ;cur-line JSR2 ;line-width JSR2 JMP2r + ;cur-line JSR2 ;line-width JMP2 ( JSR2 JMP2r ) @cur-w-last ( -> n* ) ;cur-line JSR2 ;line-width JSR2 #0001 SUB2 JMP2r @@ -610,7 +628,7 @@ ¬-found ;rel-line-error ;error! JMP2 @cur-line ( -> s* ) - ;cur-row JSR2 ;rel-line JSR2 JMP2r + ;cur-row JSR2 ;rel-line JMP2 ( JSR2 JMP2r ) @cur-pos ( -> s* ) ;cur-line JSR2 ;cur-col JSR2 ADD2 JMP2r @@ -650,7 +668,7 @@ JMP2r @cur-col ( -> col* ) - ;cursor/col LDA2 ;cur-len JSR2 ;min2 JSR2 JMP2r + ;cursor/col LDA2 ;cur-len JSR2 ;min2 JMP2 ( JSR2 JMP2r ) @cur-w-col ( -> col* ) LIT2r 0000 ( [0] ) @@ -696,7 +714,7 @@ ,&do1 JMP &do3 #64 ;mod-div JSR2 ;emit-digit JSR2 &do2 #0a ;mod-div JSR2 ;emit-digit JSR2 - &do1 ;emit-digit JSR2 JMP2r + &do1 ;emit-digit JMP2 ( JSR2 JMP2r ) @emit-dec2 ( n* -> ) DUP2 #270f GTH2 ,&do5 JCN @@ -708,7 +726,7 @@ &do4 #03e8 ;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 + &do1 NIP ;emit-digit JMP2 ( JSR2 JMP2r ) @emit-dec2-pad ( n* -> ) LIT2r 2018 ( preload #20 .Console/write into rst ) From 8860f63e7a9ec32df9e85be2769d9c342be1125a Mon Sep 17 00:00:00 2001 From: d6 Date: Fri, 4 Mar 2022 15:30:26 -0500 Subject: [PATCH 3/6] simple nano highlighting for unxtal --- femto.tal | 48 +++++++++++++++++++++++++++++------------------- tal.nanorc | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 19 deletions(-) create mode 100644 tal.nanorc diff --git a/femto.tal b/femto.tal index f484a5d..a7d2771 100644 --- a/femto.tal +++ b/femto.tal @@ -49,7 +49,6 @@ ( - search&replace ) ( - tab support? ) ( - windows line-ending support (CRLF) ) - ( FIXME: ) ( - stop using bytes for row/col/etc. ) ( - consider storing absolute cursor instead ) @@ -470,9 +469,9 @@ @draw-statusbar ( -> ) #0000 ;term/rows LDA2 ;term-move-cursor JSR2 - ansi ;config/color LDA2 emit emit - LIT2 '7 '; emit emit - LIT 'm emit ( esc [ 33 ; 7 m ) + ;emit-color-reverse JSR2 +( ansi ;config/color LDA2 emit emit + LIT2 '7 '; emit emit LIT 'm emit ) LIT2r 2018 ;term/cols LDA2 #0000 &loop GTH2k ,&continue JCN ,&done JMP @@ -496,10 +495,12 @@ ;cur-abs-row JSR2 INC2 ;emit-dec2 JSR2 LIT ') emit - ansi LIT '0 emit LIT 'm emit + ;emit-reset JSR2 + ( ansi LIT '0 emit LIT 'm emit ) JMP2r @draw-linenum ( n* -> ) + ;emit-reset JSR2 ansi ;config/color LDA2 emit emit LIT 'm emit ;emit-dec2-pad JSR2 ansi LIT2 'm '0 emit emit JMP2r @@ -519,31 +520,40 @@ @emit-red-dollar ( -> ) ;emit-red JSR2 LIT '$ emit ;emit-reset JMP2 +@emit-color-reverse ( -> ) + ansi ;config/color LDA2 emit emit LIT2 '7 '; emit emit LIT 'm emit JMP2r + @draw-all ( -> ) ;term-erase-all JSR2 #0000 #0000 ;term-move-cursor JSR2 ;buffer/line-offset LDA2 STH2 LIT2r 0001 ( [k line-offset] ) - ADD2kr STH2r ;draw-linenum JSR2 ;buffer/offset LDA2 - ;term/lmargin LDA2 INC2 ,&x STR2 + &bol + ADD2kr STH2r ;draw-linenum JSR2 + ;term/lmargin LDA2 INC2 ,&x STR2 +( TODO: use this for cursor-line highlighting and long line support ) +( STH2kr ;cursor/row LDA2 INC2 NEQ2 ,&loop JCN + ;emit-color-reverse JSR2 ) &loop ( offset [k line-offset] ) - LDAk #00 EQU ,&eof JCN - LDAk #0a EQU ,&eol JCN - ,&x LDR2 ;term/cols LDA2 + LDAk #00 EQU ,&eof JCN + LDAk #0a EQU ,&eol JCN + ,&x LDR2 ;term/cols LDA2 LTH2k ,&ok JCN GTH2 ,&skip JCN ;emit-red-dollar JSR2 ,&x LDR2 INC2 ,&x STR2 - &skip INC2 ,&loop JMP + &skip INC2 + ,&loop JMP &ok POP2 POP2 - LDAk #09 EQU ,&do-tab JCN - LDAk emit INC2 ,&x LDR2 INC2 ,&x STR2 ,&loop JMP - &do-tab ;emit-tab JSR2 INC2 ;config/tab-width LDA2 ,&x LDR2 ADD2 ,&x STR2 ,&loop JMP + LDAk #09 EQU ,&do-tab JCN + LDAk emit INC2 ,&x LDR2 INC2 ,&x STR2 + ,&loop JMP + &eol INC2r + STH2kr ;term/rows LDA2 GTH2 ,&done JCN + cr nl INC2 ,&bol JMP + &do-tab ;emit-tab JSR2 INC2 + ;config/tab-width LDA2 ,&x LDR2 ADD2 ,&x STR2 + ,&loop JMP [ &x $2 ] - &eol INC2r STH2kr ;term/rows LDA2 GTH2 ,&done JCN - cr nl INC2 - ADD2kr STH2r ;draw-linenum JSR2 - ;term/lmargin LDA2 INC2 ,&x STR2 - ,&loop JMP &eof ;emit-red JSR2 &eof-loop diff --git a/tal.nanorc b/tal.nanorc new file mode 100644 index 0000000..701ff2a --- /dev/null +++ b/tal.nanorc @@ -0,0 +1,44 @@ +# basic syntax for the uxntal assembly language +# +# mostly sticks to ANSI colors with a few exceptions +# +# comments are known to not handle nesting correctly. +# it's not possible to express nested comments using +# just start and end regexes. + +# use this syntax for .tal files +syntax tal ".*\.tal" + +# characters to insert when comments requested +comment "( | )" + +# raw values +color pink "\"[^ ]+" +color pink "'[^ ]" +color pink "\<[0-9a-f]{2}{1,2}\>" + +# literals +color bold,green "#[0-9a-f]{2}{1,2}\>" + +# absolute addresses +color bold,yellow "(;&?|\.)\S+" +color bold,orange ",&?\S+" +color bold,orange "/\S+" + +# relative pads +color yellow "\$[0-9a-f]{1,4}\>" + +# instructions +color bold,cyan "\<(BRK|LIT|INC|POP|DUP|NIP|SWP|OVR|ROT|EQU|NEQ|GTH|LTH|JMP|JCN|JSR|STH|LDZ|STZ|LDR|STR|LDA|STA|DEI|DEO|ADD|SUB|MUL|DIV|AND|ORA|EOR|SFT)2?k?r?\>" + +# label definitions +color bold,blue "(^|\s)(@|&)\S+" + +# macros +color bold,magenta "%\S+" + +# absolute pads +color yellow "\|[0-9a-f]{2}{1,2}\>" + +# comments +color red start="\(\s" end="\s\)" From 27e5d42652956bb42a973a8a38ae07e9d7bc4d5c Mon Sep 17 00:00:00 2001 From: d6 Date: Fri, 4 Mar 2022 15:31:03 -0500 Subject: [PATCH 4/6] update site --- mksite.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mksite.sh b/mksite.sh index a19da97..cfd7e14 100755 --- a/mksite.sh +++ b/mksite.sh @@ -1,6 +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 tal-mode1.png; do +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 tal-mode1.png tal.nanorc; do echo "-> $NAME" cp $NAME /var/www/plastic-idolatry.com/html/erik/nxu done From f48bce6be3e4bb5d1d2215b87eb7b1ad94008dcd Mon Sep 17 00:00:00 2001 From: d6 Date: Sun, 6 Mar 2022 15:35:14 -0500 Subject: [PATCH 5/6] cursor/row refactors: prepare for absolute row addressing --- femto.tal | 59 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/femto.tal b/femto.tal index a7d2771..152f26b 100644 --- a/femto.tal +++ b/femto.tal @@ -69,6 +69,7 @@ ( startup ) |0100 ;startup JMP2 +( code to run on startup ) @startup ;read-filename .Console/vector DEO2 BRK ( ERROR HANDLING ) @@ -187,7 +188,7 @@ ;draw-statusbar JSR2 ;draw-cursor JSR2 ,&skip JMP &next-line #0000 ;cursor/col STA2 - ;cursor/row LDA2k INC2 SWP2 STA2 + ;inc-row JSR2 ;ensure-visible-cursor JSR2 ;draw-cursor JSR2 &skip BRK @@ -202,8 +203,8 @@ @up ( -> ) ;cur-abs-row JSR2 #0000 EQU2 ,&done JCN - ;cur-row JSR2 #0001 LTH2 ,&screen-up JCN - ;cursor/row LDA2k #0001 SUB2 SWP2 STA2 + ;cur-rel-row JSR2 #0001 LTH2 ,&screen-up JCN + ;dec-row JSR2 ;draw-statusbar JSR2 ;draw-cursor JSR2 BRK &screen-up @@ -214,7 +215,7 @@ @down ( -> ) ;cur-abs-row JSR2 ;last-abs-row JSR2 EQU2 ,&done JCN - ;cursor/row LDA2k INC2 SWP2 STA2 + ;inc-row JSR2 ;ensure-visible-cursor JSR2 ;draw-statusbar JSR2 ;draw-cursor JSR2 BRK @@ -229,14 +230,12 @@ ;buffer/line-offset STA2 ;ensure-visible-cursor JSR2 ;draw-all JSR2 BRK - &near-bof POP2 POP2 &xyz - ;buffer/data ;buffer/offset STA2 - #0000 ;buffer/line-offset STA2 - #0000 ;cursor/row STA2 - #0000 ;cursor/col STA2 + &near-bof POP2 POP2 + ;zero-row JSR2 + #0000 ;cursor/col STA2 ;draw-all JSR2 BRK &at-bof - #0000 ;cursor/row STA2 + ;zero-row JSR2 #0000 ;cursor/col STA2 ;draw-cursor JSR2 BRK @@ -250,8 +249,8 @@ ;draw-all JSR2 BRK &near-eof ;buffer/line-count LDA2 - ;buffer/line-offset LDA2 INC2 - SUB2 ;cursor/row STA2 + ;buffer/line-offset LDA2 INC2 SUB2 + ;cursor/row STA2 ;cur-len JSR2 ;cursor/col STA2 ;draw-cursor JSR2 BRK @@ -282,7 +281,7 @@ @newline ( c^ -> ) #0a ;cur-pos JSR2 ;shift-right JSR2 #0000 ;cursor/col STA2 - ;cursor/row LDA2k INC2 SWP2 STA2 + ;inc-row JSR2 ;buffer/line-count LDA2k INC2 SWP2 STA2 ;ensure-visible-cursor JSR2 ;draw-all JSR2 @@ -344,10 +343,8 @@ ;draw-all JSR2 BRK @goto-start ( -> ) - ;buffer/data ;buffer/offset STA2 - #0000 ;buffer/line-offset STA2 + ;zero-row JSR2 #0000 ;cursor/col STA2 - #0000 ;cursor/row STA2 ;draw-all JSR2 BRK @@ -376,7 +373,7 @@ JMP2r @ensure-visible-cursor - ;cur-row JSR2 ;term/rows LDA2 LTH2 ,&noop JCN + ;cur-rel-row JSR2 ;term/rows LDA2 LTH2 ,&noop JCN ;cur-abs-row JSR2 ;jump-to-line JSR2 ;draw-all JSR2 &noop JMP2r @@ -464,7 +461,7 @@ @draw-cursor ( -> ) ;cur-w-col JSR2 ;term/lmargin LDA2 ADD2 - ;cur-row JSR2 + ;cur-rel-row JSR2 ;term-move-cursor JMP2 ( JSR2 JMP2r ) @draw-statusbar ( -> ) @@ -533,7 +530,7 @@ ;term/lmargin LDA2 INC2 ,&x STR2 ( TODO: use this for cursor-line highlighting and long line support ) ( STH2kr ;cursor/row LDA2 INC2 NEQ2 ,&loop JCN - ;emit-color-reverse JSR2 ) + ;emit-color-reverse JSR2 ) &loop ( offset [k line-offset] ) LDAk #00 EQU ,&eof JCN LDAk #0a EQU ,&eol JCN @@ -638,13 +635,13 @@ ¬-found ;rel-line-error ;error! JMP2 @cur-line ( -> s* ) - ;cur-row JSR2 ;rel-line JMP2 ( JSR2 JMP2r ) + ;cur-rel-row JSR2 ;rel-line JMP2 ( JSR2 JMP2r ) @cur-pos ( -> s* ) ;cur-line JSR2 ;cur-col JSR2 ADD2 JMP2r @cur-abs-row ( -> n* ) - ;cur-row JSR2 ;buffer/line-offset LDA2 ADD2 JMP2r + ;cur-rel-row JSR2 ;buffer/line-offset LDA2 ADD2 JMP2r @last-abs-row ( -> n* ) ;buffer/line-count LDA2 #0001 SUB2 JMP2r @@ -688,9 +685,27 @@ &next LDAk #09 EQU ,&tabs JCN INC2 INC2r ,&loop JMP &tabs INC2 ;config/tab-width LDA2 STH2 ADD2r ,&loop JMP -@cur-row ( -> row* ) +@cur-rel-row ( -> row* ) ;cursor/row LDA2 JMP2r +@set-abs-row ( n* -> ) + ;buffer/line-offset LDA2 SUB2 ;cursor/row STA2 JMP2r + +@set-rel-row ( n* -> ) + ;cursor/row STA2 JMP2r + +@zero-row ( -> ) + ;buffer/data ;buffer/offset STA2 + #0000 ;buffer/line-offset STA2 + #0000 ;cursor/row STA2 + JMP2r + +@inc-row ( -> ) + ;cursor/row LDA2k INC2 SWP2 STA2 JMP2r + +@dec-row ( -> ) + ;cursor/row LDA2k #0001 SUB2 SWP2 STA2 + @last-pos ( -> addr* ) ;buffer/limit LDA2 #0001 SUB2 JMP2r From 37936eda778067b51567df58b62d733ec2944d22 Mon Sep 17 00:00:00 2001 From: d6 Date: Mon, 7 Mar 2022 12:56:52 -0500 Subject: [PATCH 6/6] set up zero page, start cleaning up --- femto.tal | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/femto.tal b/femto.tal index 152f26b..25c1995 100644 --- a/femto.tal +++ b/femto.tal @@ -66,6 +66,9 @@ %quit! { #01 .System/halt DEO } +( zero page ) +|0000 + ( startup ) |0100 ;startup JMP2 @@ -100,7 +103,7 @@ JMP2r @setup-terminal-size ( -> ) - ( ;setup-80x24 JSR2 JMP2r ) + ( ;setup-80x24 JMP2 ) #03e7 #03e7 ;term-move-cursor JSR2 ;term-get-cursor-position JSR2 ;tmp/data ;tmp/pos STA2 @@ -248,9 +251,7 @@ ;ensure-visible-cursor JSR2 ;draw-all JSR2 BRK &near-eof - ;buffer/line-count LDA2 - ;buffer/line-offset LDA2 INC2 SUB2 - ;cursor/row STA2 + ;buffer/line-count LDA2 #0001 SUB2 ;set-abs-row JSR2 ;cur-len JSR2 ;cursor/col STA2 ;draw-cursor JSR2 BRK @@ -396,7 +397,7 @@ BRK @move-to-message-line ( -> ) - #0002 ;term/rows LDA2 #0002 ADD2 ;term-move-cursor JMP2 ( JSR2 JMP2r ) + #0002 ;term/rows LDA2 #0002 ADD2 ;term-move-cursor JMP2 ( TODO: filename prmopt ) @save ( -> ) @@ -462,13 +463,11 @@ @draw-cursor ( -> ) ;cur-w-col JSR2 ;term/lmargin LDA2 ADD2 ;cur-rel-row JSR2 - ;term-move-cursor JMP2 ( JSR2 JMP2r ) + ;term-move-cursor JMP2 @draw-statusbar ( -> ) #0000 ;term/rows LDA2 ;term-move-cursor JSR2 ;emit-color-reverse JSR2 -( ansi ;config/color LDA2 emit emit - LIT2 '7 '; emit emit LIT 'm emit ) LIT2r 2018 ;term/cols LDA2 #0000 &loop GTH2k ,&continue JCN ,&done JMP @@ -493,7 +492,6 @@ LIT ') emit ;emit-reset JSR2 - ( ansi LIT '0 emit LIT 'm emit ) JMP2r @draw-linenum ( n* -> ) @@ -579,13 +577,13 @@ &eof POP2 JMP2r @cur-len ( -> n* ) - ;cur-line JSR2 ;line-len JMP2 ( JSR2 JMP2r ) + ;cur-line JSR2 ;line-len JMP2 @cur-last ( -> n* ) ;cur-line JSR2 ;line-len JSR2 #0001 SUB2 JMP2r @cur-width ( -> n* ) - ;cur-line JSR2 ;line-width JMP2 ( JSR2 JMP2r ) + ;cur-line JSR2 ;line-width JMP2 @cur-w-last ( -> n* ) ;cur-line JSR2 ;line-width JSR2 #0001 SUB2 JMP2r @@ -635,7 +633,7 @@ ¬-found ;rel-line-error ;error! JMP2 @cur-line ( -> s* ) - ;cur-rel-row JSR2 ;rel-line JMP2 ( JSR2 JMP2r ) + ;cur-rel-row JSR2 ;rel-line JMP2 @cur-pos ( -> s* ) ;cur-line JSR2 ;cur-col JSR2 ADD2 JMP2r @@ -675,7 +673,7 @@ JMP2r @cur-col ( -> col* ) - ;cursor/col LDA2 ;cur-len JSR2 ;min2 JMP2 ( JSR2 JMP2r ) + ;cursor/col LDA2 ;cur-len JSR2 ;min2 JMP2 @cur-w-col ( -> col* ) LIT2r 0000 ( [0] ) @@ -739,7 +737,7 @@ ,&do1 JMP &do3 #64 ;mod-div JSR2 ;emit-digit JSR2 &do2 #0a ;mod-div JSR2 ;emit-digit JSR2 - &do1 ;emit-digit JMP2 ( JSR2 JMP2r ) + &do1 ;emit-digit JMP2 @emit-dec2 ( n* -> ) DUP2 #270f GTH2 ,&do5 JCN @@ -751,7 +749,7 @@ &do4 #03e8 ;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 JMP2 ( JSR2 JMP2r ) + &do1 NIP ;emit-digit JMP2 @emit-dec2-pad ( n* -> ) LIT2r 2018 ( preload #20 .Console/write into rst ) @@ -782,6 +780,9 @@ &rows 0018 &lmargin 0006 ] +@prompt [ &vector $2 + &string $40 ] + ( COLORS ) ( ) ( SHORT STRING NAME )