fix a bunch of navigation bugs
This commit is contained in:
parent
46f0f162eb
commit
ad2f91f329
109
femto.tal
109
femto.tal
|
@ -195,48 +195,45 @@
|
|||
|
||||
( FIXME: handle long lines )
|
||||
@forward
|
||||
;cursor/col LDA pen-col GTH ,&skip JCN
|
||||
;cursor/col LDA #01 ADD ;cursor/col STA
|
||||
;draw-statusbar JSR2
|
||||
;draw-cursor JSR2
|
||||
;cur-pos JSR2 ;last-pos JSR2 GTH2 ,&skip JCN
|
||||
;cur-col JSR2 ;cur-last JSR2 GTH ,&next-line JCN
|
||||
;cur-col JSR2 INC ;cursor/col STA
|
||||
;draw-statusbar JSR2 ;draw-cursor JSR2
|
||||
,&skip JMP
|
||||
&next-line #00 ;cursor/col STA ( TODO: need to ensure cursor is visible )
|
||||
;cursor/row LDA INC ;cursor/row STA
|
||||
;ensure-visible-cursor JSR2
|
||||
;draw-cursor JSR2
|
||||
&skip BRK
|
||||
|
||||
( FIXME: handle long lines )
|
||||
@back
|
||||
;cursor/col LDA #01 LTH ,&skip JCN
|
||||
;cursor/col LDA #01 SUB ;cursor/col STA
|
||||
;cur-col JSR2 #01 LTH ,&skip JCN
|
||||
;cur-col JSR2 #01 SUB ;cursor/col STA
|
||||
;draw-statusbar JSR2
|
||||
;draw-cursor JSR2
|
||||
&skip BRK
|
||||
|
||||
( TODO: integrate ensure-visible-cursor to move by half-screens )
|
||||
@up
|
||||
;cur-line-num JSR2 #0000 EQU2 ,&done JCN
|
||||
;cursor/row LDA #01 LTH ,&screen-up JCN
|
||||
;cursor/row LDA #01 SUB ;cursor/row STA
|
||||
;draw-statusbar JSR2
|
||||
;draw-cursor JSR2 BRK
|
||||
&screen-up
|
||||
;buffer/offset LDA2 DUP2 ;buffer/data EQU2 ,&done JCN
|
||||
#0001 SUB2
|
||||
&loop DUP2 ;buffer/data EQU2 ,&complete JCN
|
||||
#0001 SUB2 LDAk #0a NEQ ,&loop JCN
|
||||
INC2
|
||||
&complete ;buffer/offset STA2
|
||||
;buffer/line-offset LDA2k #0001 SUB2 SWP2 STA2
|
||||
;draw-all JSR2 BRK
|
||||
&done POP2 BRK
|
||||
;cur-line-num JSR2 #0001 SUB2
|
||||
;jump-to-line JSR2
|
||||
;draw-all JSR2
|
||||
&done BRK
|
||||
|
||||
( FIXME: need to handle 'end of buffer' stuff )
|
||||
@down
|
||||
;cur-abs-row JSR2 ;last-abs-row JSR2 EQU2 ,&done JCN
|
||||
;cursor/row LDA pen-line GTH ,&screen-down JCN
|
||||
;cursor/row LDA INC ;cursor/row STA
|
||||
;ensure-visible-cursor JSR2
|
||||
;draw-statusbar JSR2
|
||||
;draw-cursor JSR2 BRK
|
||||
&screen-down
|
||||
#00 ;rel-line JSR2 ;line-len JSR2 INC2 ( add 1 for line ending )
|
||||
;buffer/offset LDA2 ADD2 ;buffer/offset STA2
|
||||
;buffer/line-offset LDA2k INC2 SWP2 STA2
|
||||
;draw-all JSR2
|
||||
&done BRK
|
||||
|
||||
@quit quit!
|
||||
|
@ -244,18 +241,17 @@
|
|||
@ignore BRK
|
||||
|
||||
@insert ( c^ -> )
|
||||
;cursor/col LDA pen-col GTH ,&skip JCN ( FIXME )
|
||||
;cur-pos JSR2 ;shift-right JSR2
|
||||
;cursor/col LDA INC ;cursor/col STA
|
||||
;cur-col JSR2 INC ;cursor/col STA
|
||||
;draw-all JSR2
|
||||
&skip BRK
|
||||
BRK
|
||||
|
||||
@overwrite ( c^ -> )
|
||||
( @overwrite ( c^ -> )
|
||||
;cursor/col LDA pen-col GTH ,&skip JCN ( FIXME )
|
||||
;cur-pos JSR2 STA
|
||||
;cursor/col LDA #01 ADD ;cursor/col STA
|
||||
;draw-all JSR2
|
||||
&skip BRK
|
||||
&skip BRK )
|
||||
|
||||
( TODO: handle last line )
|
||||
@newline ( c^ -> )
|
||||
|
@ -276,8 +272,7 @@
|
|||
@backspace ( -> )
|
||||
;at-buffer-start JSR2 ,&skip JCN
|
||||
;at-line-start JSR2 ,&prev-line JCN
|
||||
;get-col JSR2 #01 SUB ;cursor/col STA
|
||||
( ;cursor/col LDA #01 SUB ;cursor/col STA )
|
||||
;cur-col JSR2 #01 SUB ;cursor/col STA
|
||||
,&finish JMP
|
||||
&prev-line ( TODO: what if row=0 but offset>0 ? )
|
||||
;cursor/row LDA #01 SUB ;cursor/row STA
|
||||
|
@ -323,7 +318,7 @@
|
|||
BRK
|
||||
|
||||
@goto-line ( -> )
|
||||
#0060 ;jump-to-line JSR2
|
||||
#0016 ;jump-to-line JSR2
|
||||
;draw-all JSR2 BRK
|
||||
|
||||
@jump-to-line ( n* -> )
|
||||
|
@ -335,17 +330,23 @@
|
|||
,&late JCN ( n n-rows/2 lines-rows )
|
||||
POP2 ,&finish JMP
|
||||
&early ( n rows/2 )
|
||||
POP2 ,&finish JCN
|
||||
POP2 #0000 ,&finish JMP ( n 0000 )
|
||||
&late ( n n-rows/2 lines-rows )
|
||||
NIP2 ,&finish JCN
|
||||
NIP2
|
||||
&finish ( n o )
|
||||
SUB2k STH2 DUP2
|
||||
;buffer/line-offset STA2
|
||||
;abs-line JSR2 ;buffer/offset STA2
|
||||
#00 ;cursor/col STA
|
||||
POP2 STH2r NIP ;cursor/row STA
|
||||
SUB2k STH2 DUP2 ( n o o [n-o] )
|
||||
;buffer/line-offset STA2 ( n o [n-o] )
|
||||
;abs-line JSR2 ;buffer/offset STA2 ( n [n-o] )
|
||||
#00 ;cursor/col STA ( n [n-o] )
|
||||
POP2 STH2r NIP ;cursor/row STA ( )
|
||||
JMP2r
|
||||
|
||||
@ensure-visible-cursor
|
||||
;cursor/row LDA height LTH ,&noop JCN
|
||||
;cur-line-num JSR2 ;jump-to-line JSR2
|
||||
;draw-all JSR2
|
||||
&noop JMP2r
|
||||
|
||||
@refresh
|
||||
;draw-all JSR2 BRK
|
||||
|
||||
|
@ -404,7 +405,7 @@
|
|||
ansi LIT '2 emit LIT 'J emit JMP2r
|
||||
|
||||
@draw-cursor
|
||||
;get-col JSR2 ;get-row JSR2
|
||||
;cur-col JSR2 ;cur-row JSR2
|
||||
;term-move-cursor JSR2 JMP2r
|
||||
|
||||
@draw-statusbar
|
||||
|
@ -428,7 +429,7 @@
|
|||
;messages/lines ;print JSR2
|
||||
#20 emit
|
||||
LIT '( emit
|
||||
;cursor/col LDA INC ;emit-dec JSR2
|
||||
;cur-col JSR2 INC ;emit-dec JSR2
|
||||
LIT ', emit
|
||||
;cur-abs-row JSR2 INC2 ;emit-dec2 JSR2
|
||||
LIT ') emit
|
||||
|
@ -482,6 +483,9 @@
|
|||
@cur-len ( -> n* )
|
||||
;cur-line JSR2 ;line-len JSR2 JMP2r
|
||||
|
||||
@cur-last ( -> n* )
|
||||
;cur-line JSR2 ;line-len JSR2 #0001 SUB2 NIP JMP2r
|
||||
|
||||
@line-len ( s* -> n* )
|
||||
#0000 STH2
|
||||
&loop LDAk #00 EQU ,&end JCN
|
||||
|
@ -520,8 +524,11 @@
|
|||
@cur-line ( -> s* )
|
||||
;cursor/row LDA ;rel-line JSR2 JMP2r
|
||||
|
||||
@cur-line-num ( -> n* )
|
||||
#00 ;cursor/row LDA ;buffer/line-offset LDA2 ADD2 JMP2r
|
||||
|
||||
@cur-pos ( -> s* )
|
||||
;cur-line JSR2 #00 ;get-col JSR2 ADD2 JMP2r
|
||||
;cur-line JSR2 #00 ;cur-col JSR2 ADD2 JMP2r
|
||||
|
||||
@cur-abs-row ( -> n* )
|
||||
;buffer/line-offset LDA2 #00 ;cursor/row LDA ADD2 JMP2r
|
||||
|
@ -531,8 +538,7 @@
|
|||
|
||||
@shift-right ( c^ addr* -> )
|
||||
ROT STH ( addr [prev^] )
|
||||
;buffer/limit LDA2 ( addr limit [prev^] )
|
||||
#0001 SUB2 SWP2 ( last addr [prev^] )
|
||||
;last-pos JSR2 SWP2 ( last addr [prev^] )
|
||||
&loop LTH2k ,&done JCN ( last addr [prev^] )
|
||||
LDAk STH SWPr ( last addr [prev^ curr^] )
|
||||
DUP2 STHr ( last addr addr prev^ [curr^] )
|
||||
|
@ -546,8 +552,7 @@
|
|||
|
||||
( TODO: change last/addr order and GTH -> LTH to remove hack )
|
||||
@shift-left ( addr* -> )
|
||||
;buffer/limit LDA2 ( addr limit )
|
||||
#0001 SUB2 SWP2 ( last addr )
|
||||
;last-pos JSR2 SWP2 ( last addr )
|
||||
&loop GTH2k ,&next JCN ( last addr )
|
||||
,&done JMP ( last addr )
|
||||
&next DUP2 INC2 LDAk ( last addr addr+1 c1^ )
|
||||
|
@ -559,13 +564,13 @@
|
|||
#00 ;buffer/limit LDA2 STA ( ensure null termination )
|
||||
JMP2r
|
||||
|
||||
( TODO: should be using get-col and get-row almost everywhere )
|
||||
( TODO: should be using cur-col and cur-row almost everywhere )
|
||||
( otherwise, bugs! )
|
||||
|
||||
@get-col
|
||||
@cur-col
|
||||
;cursor/col LDA ;cur-len JSR2 NIP ;min JSR2 JMP2r
|
||||
|
||||
@get-row
|
||||
@cur-row
|
||||
;cursor/row LDA JMP2r
|
||||
|
||||
@last-pos
|
||||
|
@ -577,17 +582,17 @@
|
|||
@fits-in-one-screen ( -> bool^ )
|
||||
;buffer/line-count LDA2 ;term/rows LDA2 INC2 LTH2 JMP2r
|
||||
|
||||
@doc-start ( -> s* ) ;buffer/data JMP2r
|
||||
( @doc-start ( -> s* ) ;buffer/data JMP2r
|
||||
@doc-limit ( -> s* ) ;buffer/limit LDA2 JMP2r
|
||||
@doc-last ( -> s* ) ;buffer/limit LDA2 #0001 SUB2 JMP2r
|
||||
@doc-last ( -> s* ) ;buffer/limit LDA2 #0001 SUB2 JMP2r )
|
||||
|
||||
@page-start ( -> s* ) ;buffer/offset LDA2 JMP2r
|
||||
( @page-start ( -> s* ) ;buffer/offset LDA2 JMP2r
|
||||
@page-limit ( -> s* ) height ;rel-line JSR2 JMP2r
|
||||
@page-last ( -> s* ) height ;rel-line JSR2 #0001 SUB2 JMP2r
|
||||
@page-last ( -> s* ) height ;rel-line JSR2 #0001 SUB2 JMP2r )
|
||||
|
||||
@line-start ( -> s* ) ;cursor/row LDA ;rel-line JSR2 JMP2r
|
||||
( @line-start ( -> s* ) ;cursor/row LDA ;rel-line JSR2 JMP2r
|
||||
@line-limit ( -> s* ) ;cursor/row LDA INC ;rel-line JSR2 JMP2r
|
||||
@line-last ( -> s* ) ;cursor/row LDA INC ;rel-line JSR2 #0001 SUB2 JMP2r
|
||||
@line-last ( -> s* ) ;cursor/row LDA INC ;rel-line JSR2 #0001 SUB2 JMP2r )
|
||||
|
||||
@mod-div ( x^ y^ -> x%d x/y )
|
||||
DIVk STHk MUL SUB STHr JMP2r
|
||||
|
|
Loading…
Reference in New Issue