converted to absolute cursor, fixed a lot of bugs

This commit is contained in:
~d6 2022-03-26 15:29:00 -04:00
parent 42ea10b6f9
commit df70eb0848
1 changed files with 48 additions and 57 deletions

105
femto.tal
View File

@ -281,14 +281,10 @@
@up ( -> )
;cur-abs-row JSR2 #0000 EQU2 ,&done JCN
;cur-rel-row JSR2 #0001 LTH2 ,&screen-up JCN
;dec-row JSR2
;ensure-visible-cursor JSR2
;draw-statusbar JSR2
&done ;draw-cursor JSR2 BRK
&screen-up
;cur-abs-row JSR2 #0001 SUB2
;jump-to-line JSR2
;draw-all JSR2 BRK
@down ( -> )
;cur-abs-row JSR2 ;last-abs-row JSR2 EQU2 ,&done JCN
@ -297,31 +293,42 @@
;draw-statusbar JSR2
&done ;draw-cursor JSR2 BRK
@center-view
;term/rows LDZ2 INC2 #0002 DIV2 STH2k
.cursor/row LDZ2 LTH2 ,&standard JCN
POP2r
#0000 .buffer/line-offset STZ2
;data .buffer/offset STZ2
,&done JMP
&standard
.cursor/row LDZ2 STH2r SUB2
DUP2 .buffer/line-offset STZ2
;abs-line JSR2 .buffer/offset STZ2
&done
;draw-all JSR2 BRK
@page-up ( -> )
;bof-is-visible JSR2 ,&at-bof JCN
.buffer/line-offset LDZ2
.term/rows LDZ2 #0003 SUB2
LTH2k ,&near-bof JCN
SUB2 DUP2 ;abs-line JSR2 .buffer/offset STZ2
.buffer/line-offset STZ2
;ensure-visible-cursor JSR2
;draw-all JSR2 BRK
&near-bof POP2 POP2
.term/rows LDZ2 #0002 SUB2 STH2k
.buffer/line-offset LDZ2 LTH2 ,&move-full JCN
POP2r
;zero-row JSR2
#0000 .cursor/col STZ2
,&done JMP
&move-full
.cursor/row LDZ2 STH2kr SUB2 .cursor/row STZ2
.buffer/line-offset LDZ2 STH2r SUB2
DUP2 .buffer/line-offset STZ2
;abs-line JSR2 .buffer/offset STZ2
&done
;draw-all JSR2 BRK
&at-bof
;zero-row JSR2
#0000 .cursor/col STZ2
;draw-cursor JSR2 BRK
@page-down
;eof-is-visible JSR2 ,&near-eof JCN
.buffer/line-offset LDZ2
.term/rows LDZ2 ADD2 #0003 SUB2
DUP2 ;abs-line JSR2 .buffer/offset STZ2
.buffer/line-offset STZ2
;ensure-visible-cursor JSR2
.term/rows LDZ2 #0002 SUB2 STH2k
.buffer/line-offset LDZ2 ADD2
DUP2 .buffer/line-offset STZ2
;abs-line JSR2 .buffer/offset STZ2
.cursor/row LDZ2 STH2r ADD2 .cursor/row STZ2
;draw-all JSR2 BRK
&near-eof
.buffer/line-count LDZ2 #0001 SUB2 ;set-abs-row JSR2
@ -411,23 +418,6 @@
;delete JMP2
&skip BRK
( @backspace ( -> )
#01 .state/modified STZ
;at-buffer-start JSR2 ,&skip JCN
;at-line-start JSR2 ,&prev-line JCN
;cur-col JSR2 #0001 SUB2 .cursor/col STZ2
,&finish JMP
&prev-line
;cur-abs-row JSR2 #0001 SUB2
;jump-to-line JSR2 ( TODO: fix weird eof behavior )
;cur-len JSR2 .cursor/col STZ2
.buffer/line-count LDZ2k #0001 SUB2 ROT STZ2
&finish
;cur-pos JSR2 ;shift-left JSR2
;draw-all JSR2 BRK
&skip
;draw-cursor JSR2 BRK )
@backspace-prompt ( -> )
#00 .tmp/pos LDZ2 #0001 SUB2 ( 0 pos-1 )
STH2k STA ( data[pos-1] <- 0 )
@ -450,12 +440,11 @@
#01 .state/saw-esc STZ BRK
@goto-end ( -> )
;more-than-one-screen JSR2 ,&large JCN
.buffer/line-count LDZ2 #0001 SUB2 .cursor/row STZ2
#0000 ,&continue JMP
&large
.term/rows LDZ2 #0001 SUB2 .cursor/row STZ2
.buffer/line-count LDZ2 .term/rows LDZ2 SUB2
.buffer/line-count LDZ2 #0001 SUB2 .cursor/row STZ2
.buffer/line-count LDZ2 .term/rows LDZ2 LTH2k ,&use-zero JCN
SUB2 #0002 ADD2 ,&continue JMP
&use-zero
POP2 POP2 #0000
&continue
DUP2 .buffer/line-offset STZ2
;abs-line JSR2 .buffer/offset STZ2
@ -508,7 +497,7 @@
BRK
@jump-to-line ( n* -> )
.term/rows LDZ2 #0002 DIV2 LTH2k ( n rows/2 n<rows/2? ) ,&early JCN
.term/rows LDZ2 INC2 #0002 DIV2 LTH2k ( n rows/2 n<rows/2? ) ,&early JCN
OVR2 SWP2 SUB2 ( n n-rows/2 )
.buffer/line-count LDZ2 ( n n-rows/2 lines )
.term/rows LDZ2 SUB2 ( n n-rows/2 lines-rows )
@ -524,7 +513,8 @@
.buffer/line-offset STZ2 ( n o [n-o] )
;abs-line JSR2 .buffer/offset STZ2 ( n [n-o] )
#0000 .cursor/col STZ2 ( n [n-o] )
POP2 STH2r .cursor/row STZ2
( POP2 STH2r .cursor/row STZ2 )
POP2r .cursor/row STZ2
JMP2r
@ensure-visible-cursor
@ -533,9 +523,6 @@
;draw-all JSR2
&noop JMP2r
@refresh
;draw-all JSR2 BRK
@debug
;messages/rel-line-error ;error! JMP2
@ -697,7 +684,7 @@
.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 #0c EQU ( C-l ) ;center-view JCN2
.Console/read DEI #0d EQU ( \r ) ;newline JCN2
.Console/read DEI #0e EQU ( C-n ) ;down JCN2
.Console/read DEI #0f EQU ( C-o ) ;save JCN2
@ -962,7 +949,9 @@
&not-found ;messages/rel-line-error ;error! JMP2
@cur-line ( -> s* )
;cur-rel-row JSR2 ;rel-line JMP2
;cur-rel-row JSR2 .term/rows LDZ2 LTH2 ,&safe JCN
.cursor/row LDZ2 ;abs-line JMP2
&safe ;cur-rel-row JSR2 ;rel-line JMP2
@cur-pos ( -> s* )
;cur-line JSR2 ;cur-col JSR2 ADD2 JMP2r
@ -1013,10 +1002,12 @@
&tabs INC2 .config/tab-width LDZ2 STH2 ADD2r ,&loop JMP
@cur-rel-row ( -> row* )
.cursor/row LDZ2 JMP2r
( .cursor/row LDZ2 JMP2r )
.cursor/row LDZ2 .buffer/line-offset LDZ2 SUB2 JMP2r
@set-abs-row ( n* -> )
.buffer/line-offset LDZ2 SUB2 .cursor/row STZ2 JMP2r
( .buffer/line-offset LDZ2 SUB2 .cursor/row STZ2 JMP2r )
.cursor/row STZ2 JMP2r
( @set-rel-row ( n* -> )
.cursor/row STZ2 JMP2r )
@ -1036,8 +1027,8 @@
@last-pos ( -> addr* )
.buffer/limit LDZ2 #0001 SUB2 JMP2r
@more-than-one-screen ( -> bool^ )
.buffer/line-count LDZ2 .term/rows LDZ2 GTH2 JMP2r
( @more-than-one-screen ( -> bool^ )
.buffer/line-count LDZ2 .term/rows LDZ2 GTH2 JMP2r )
( @fits-in-one-screen ( -> bool^ )
.buffer/line-count LDZ2 .term/rows LDZ2 INC2 LTH2 JMP2r )