16-bit row/col for cursor
This commit is contained in:
parent
cdc13dc609
commit
895c305cbe
173
femto.tal
173
femto.tal
|
@ -67,11 +67,6 @@
|
|||
|
||||
%quit! { #01 .System/halt DEO }
|
||||
|
||||
%height { ;term/rows LDA2 NIP }
|
||||
%last-line { ;term/rows LDA2 #0001 SUB2 NIP }
|
||||
%pen-line { ;term/rows LDA2 #0002 SUB2 NIP }
|
||||
%pen-col { ;term/cols LDA2 #0002 SUB2 NIP }
|
||||
|
||||
( startup )
|
||||
|0100 ;startup JMP2
|
||||
|
||||
|
@ -104,15 +99,15 @@
|
|||
&ok .File/success DEI2 ;buffer/data ADD2 ;buffer/limit STA2
|
||||
JMP2r
|
||||
|
||||
@setup-terminal-size
|
||||
@setup-terminal-size ( -> )
|
||||
( ;setup-80x24 JSR2 )
|
||||
#fe #fe ;term-move-cursor JSR2
|
||||
#03e7 #03e7 ;term-move-cursor JSR2
|
||||
;term-get-cursor-position JSR2
|
||||
;tmp/data ;tmp/pos STA2
|
||||
;receive-terminal-size .Console/vector DEO2
|
||||
JMP2r
|
||||
|
||||
@receive-terminal-size
|
||||
@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
|
||||
|
@ -175,42 +170,42 @@
|
|||
( ;setup-80x24 JSR2 ( hardcoded terminal size ) )
|
||||
BRK
|
||||
|
||||
@bol
|
||||
#00 ;cursor/col STA
|
||||
@bol ( -> )
|
||||
#0000 ;cursor/col STA2
|
||||
;draw-statusbar JSR2
|
||||
;draw-cursor JSR2 BRK
|
||||
|
||||
( FIXME: handle long lines )
|
||||
@eol
|
||||
;cur-line JSR2 ;line-len JSR2 NIP ;cursor/col STA
|
||||
@eol ( -> )
|
||||
;cur-line JSR2 ;line-len JSR2 ;cursor/col STA2
|
||||
;draw-statusbar JSR2
|
||||
;draw-cursor JSR2 BRK
|
||||
|
||||
( FIXME: handle long lines )
|
||||
@forward
|
||||
@forward ( -> )
|
||||
;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
|
||||
;cur-col JSR2 ;cur-last JSR2 GTH2 ,&next-line JCN
|
||||
;cur-col JSR2 INC2 ;cursor/col STA2
|
||||
;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
|
||||
&next-line #0000 ;cursor/col STA2
|
||||
;cursor/row LDA2 INC2 ;cursor/row STA2
|
||||
;ensure-visible-cursor JSR2
|
||||
;draw-cursor JSR2
|
||||
&skip BRK
|
||||
|
||||
( FIXME: handle long lines )
|
||||
@back
|
||||
@back ( -> )
|
||||
;cur-col JSR2 #01 LTH ,&skip JCN
|
||||
;cur-col JSR2 #01 SUB ;cursor/col STA
|
||||
;cur-col JSR2 #0001 SUB2 ;cursor/col STA2
|
||||
;draw-statusbar JSR2
|
||||
;draw-cursor JSR2
|
||||
&skip BRK
|
||||
|
||||
@up
|
||||
@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
|
||||
;cursor/row LDA2 #0001 LTH2 ,&screen-up JCN
|
||||
;cursor/row LDA2 #0001 SUB2 ;cursor/row STA2
|
||||
;draw-statusbar JSR2
|
||||
;draw-cursor JSR2 BRK
|
||||
&screen-up
|
||||
|
@ -219,15 +214,15 @@
|
|||
;draw-all JSR2
|
||||
&done BRK
|
||||
|
||||
@down
|
||||
@down ( -> )
|
||||
;cur-abs-row JSR2 ;last-abs-row JSR2 EQU2 ,&done JCN
|
||||
;cursor/row LDA INC ;cursor/row STA
|
||||
;cursor/row LDA2 INC2 ;cursor/row STA2
|
||||
;ensure-visible-cursor JSR2
|
||||
;draw-statusbar JSR2
|
||||
;draw-cursor JSR2 BRK
|
||||
&done BRK
|
||||
|
||||
@page-up
|
||||
@page-up ( -> )
|
||||
;bof-is-visible JSR2 ,&near-eof JCN
|
||||
;buffer/line-offset LDA2
|
||||
;term/rows LDA2 SUB2 #0003 ADD2
|
||||
|
@ -236,8 +231,8 @@
|
|||
;ensure-visible-cursor JSR2
|
||||
;draw-all JSR2 BRK
|
||||
&near-eof
|
||||
#00 ;cursor/row STA
|
||||
#00 ;cursor/col STA
|
||||
#0000 ;cursor/row STA2
|
||||
#0000 ;cursor/col STA2
|
||||
;draw-cursor JSR2 BRK
|
||||
|
||||
@page-down
|
||||
|
@ -251,8 +246,8 @@
|
|||
&near-eof
|
||||
;buffer/line-count LDA2
|
||||
;buffer/line-offset LDA2 INC2
|
||||
SUB2 NIP ;cursor/row STA
|
||||
;cur-len JSR2 ;cursor/col STA
|
||||
SUB2 ;cursor/row STA2
|
||||
;cur-len JSR2 ;cursor/col STA2
|
||||
;draw-cursor JSR2 BRK
|
||||
|
||||
@quit quit!
|
||||
|
@ -261,15 +256,15 @@
|
|||
|
||||
@insert ( c^ -> )
|
||||
;cur-pos JSR2 ;shift-right JSR2
|
||||
;cur-col JSR2 INC ;cursor/col STA
|
||||
;cur-col JSR2 INC2 ;cursor/col STA2
|
||||
;draw-all JSR2
|
||||
BRK
|
||||
|
||||
( TODO: handle last line )
|
||||
@newline ( c^ -> )
|
||||
#0a ;cur-pos JSR2 ;shift-right JSR2
|
||||
#00 ;cursor/col STA
|
||||
;cursor/row LDA INC ;cursor/row STA
|
||||
#0000 ;cursor/col STA2
|
||||
;cursor/row LDA2 INC2 ;cursor/row STA2
|
||||
;buffer/line-count LDA2k INC2 SWP2 STA2
|
||||
;ensure-visible-cursor JSR2
|
||||
;draw-all JSR2
|
||||
|
@ -279,7 +274,7 @@
|
|||
;cur-pos JSR2 ;buffer/data EQU2 JMP2r
|
||||
|
||||
@at-line-start ( -> bool^ )
|
||||
;cursor/col LDA #00 EQU JMP2r
|
||||
;cursor/col LDA2 #0000 EQU2 JMP2r
|
||||
|
||||
@bof-is-visible ( -> bool^ )
|
||||
;buffer/line-offset LDA2 #0000 EQU2 JMP2r
|
||||
|
@ -292,12 +287,12 @@
|
|||
@backspace ( -> )
|
||||
;at-buffer-start JSR2 ,&skip JCN
|
||||
;at-line-start JSR2 ,&prev-line JCN
|
||||
;cur-col JSR2 #01 SUB ;cursor/col STA
|
||||
;cur-col JSR2 #0001 SUB2 ;cursor/col STA2
|
||||
,&finish JMP
|
||||
&prev-line
|
||||
;cur-line-num JSR2 #0001 SUB2
|
||||
;jump-to-line JSR2 ( TODO: fix weird eof behavior )
|
||||
;cur-len JSR2 NIP ;cursor/col STA
|
||||
;cur-len JSR2 ;cursor/col STA2
|
||||
;buffer/line-count LDA2k #0001 SUB2 SWP2 STA2
|
||||
&finish
|
||||
;cur-pos JSR2 ;shift-left JSR2
|
||||
|
@ -319,22 +314,22 @@
|
|||
|
||||
@goto-end ( -> )
|
||||
;more-than-one-screen JSR2 ,&large JCN
|
||||
;buffer/line-count LDA2 NIP #01 SUB ;cursor/row STA
|
||||
;buffer/line-count LDA2 #0001 SUB2 ;cursor/row STA2
|
||||
#0000 ,&continue JMP
|
||||
&large
|
||||
height #01 SUB ;cursor/row STA
|
||||
;term/rows LDA2 #0001 SUB2 ;cursor/row STA2
|
||||
;buffer/line-count LDA2 ;term/rows LDA2 SUB2
|
||||
&continue
|
||||
DUP2 ;buffer/line-offset STA2
|
||||
;abs-line JSR2 ;buffer/offset STA2
|
||||
;cur-len JSR2 NIP ;cursor/col STA
|
||||
;cur-len JSR2 ;cursor/col STA2
|
||||
;draw-all JSR2 BRK
|
||||
|
||||
@goto-start ( -> )
|
||||
;buffer/data ;buffer/offset STA2
|
||||
#0000 ;buffer/line-offset STA2
|
||||
#00 ;cursor/col STA
|
||||
#00 ;cursor/row STA
|
||||
#0000 ;cursor/col STA2
|
||||
#0000 ;cursor/row STA2
|
||||
;draw-all JSR2
|
||||
BRK
|
||||
|
||||
|
@ -358,12 +353,12 @@
|
|||
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 ( )
|
||||
#0000 ;cursor/col STA2 ( n [n-o] )
|
||||
POP2 STH2r ;cursor/row STA2 ( )
|
||||
JMP2r
|
||||
|
||||
@ensure-visible-cursor
|
||||
;cursor/row LDA height LTH ,&noop JCN
|
||||
;cursor/row LDA2 ;term/rows LDA2 LTH2 ,&noop JCN
|
||||
;cur-line-num JSR2 ;jump-to-line JSR2
|
||||
;draw-all JSR2
|
||||
&noop JMP2r
|
||||
|
@ -373,12 +368,11 @@
|
|||
|
||||
@debug
|
||||
;rel-line-error ;error! JMP2
|
||||
( #00 #00 DIV BRK )
|
||||
|
||||
( TODO: M-f and M-b for next/previous word )
|
||||
( M-n and M-p for next/previous paragraph )
|
||||
( maybe M-% for search&replace )
|
||||
@on-key-escaped
|
||||
@on-key-escaped ( -> )
|
||||
#00 ;saw-esc STA
|
||||
.Console/read DEI LIT '< EQU ( M-< ) ;goto-start JCN2
|
||||
.Console/read DEI LIT '> EQU ( M-> ) ;goto-end JCN2
|
||||
|
@ -387,7 +381,7 @@
|
|||
BRK
|
||||
|
||||
@move-to-message-line ( -> )
|
||||
#02 height #02 ADD ;term-move-cursor JSR2 JMP2r
|
||||
#0002 ;term/rows LDA2 #0002 ADD2 ;term-move-cursor JSR2 JMP2r
|
||||
|
||||
( TODO: filename prmopt )
|
||||
@save ( -> )
|
||||
|
@ -429,29 +423,26 @@
|
|||
.Console/read DEI ( printable ASCII ) ;insert JMP2
|
||||
BRK
|
||||
|
||||
@min ( x^ y^ -> min^ )
|
||||
LTHk JMP SWP POP JMP2r
|
||||
|
||||
@min2 ( x* y* -> min* )
|
||||
LTH2k JMP SWP2 POP2 JMP2r
|
||||
|
||||
@term-move-cursor ( col^ row^ -> )
|
||||
ansi INC ( row+1 ) ;emit-dec JSR2
|
||||
LIT '; emit INC ( col+1 ) ;emit-dec JSR2
|
||||
@term-move-cursor ( col* row* -> )
|
||||
ansi INC2 ( row+1 ) ;emit-dec2 JSR2
|
||||
LIT '; emit INC2 ( col+1 ) ;emit-dec2 JSR2
|
||||
LIT 'H emit JMP2r
|
||||
|
||||
@term-get-cursor-position
|
||||
@term-get-cursor-position ( -> )
|
||||
ansi LIT '6 emit LIT 'n emit JMP2r
|
||||
|
||||
@term-erase-all
|
||||
@term-erase-all ( -> )
|
||||
ansi LIT '2 emit LIT 'J emit JMP2r
|
||||
|
||||
@draw-cursor
|
||||
@draw-cursor ( -> )
|
||||
;cur-col JSR2 ;cur-row JSR2
|
||||
;term-move-cursor JSR2 JMP2r
|
||||
|
||||
@draw-statusbar
|
||||
#00 height ;term-move-cursor JSR2
|
||||
@draw-statusbar ( -> )
|
||||
#0000 ;term/rows LDA2 ;term-move-cursor JSR2
|
||||
ansi LIT '7 emit LIT 'm emit
|
||||
LIT2r 2018
|
||||
;term/cols LDA2 #0000
|
||||
|
@ -459,7 +450,7 @@
|
|||
&continue DEOkr INC2 ,&loop JMP
|
||||
&done POP2 POP2 POP2r
|
||||
|
||||
#00 height ;term-move-cursor JSR2
|
||||
#0000 ;term/rows LDA2 ;term-move-cursor JSR2
|
||||
;messages/saved ;print JSR2
|
||||
;filename ;print JSR2
|
||||
#20 emit
|
||||
|
@ -479,31 +470,25 @@
|
|||
ansi LIT '0 emit LIT 'm emit
|
||||
JMP2r
|
||||
|
||||
( @draw-line ( s* -> )
|
||||
&loop LDAk #00 EQU ,&done JCN
|
||||
LDAk #0a EQU ,&done JCN
|
||||
LDAk emit INC2 ,&loop JMP
|
||||
&done POP2 JMP2r )
|
||||
|
||||
@draw-all
|
||||
@draw-all ( -> )
|
||||
;term-erase-all JSR2
|
||||
#00 #00 ;term-move-cursor JSR2
|
||||
#01 STH
|
||||
#0000 #0000 ;term-move-cursor JSR2
|
||||
#0001 STH2
|
||||
;buffer/offset LDA2
|
||||
&loop
|
||||
LDAk #00 EQU ,&eof JCN
|
||||
LDAk #0a EQU ,&eol JCN
|
||||
LDAk emit INC2 ,&loop JMP
|
||||
&eol INCr STHkr height GTH ,&done JCN
|
||||
&eol INC2r STH2kr ;term/rows LDA2 GTH2 ,&done JCN
|
||||
cr nl INC2 ,&loop JMP
|
||||
&eof
|
||||
ansi LIT '3 emit LIT '1 emit LIT 'm emit
|
||||
&eof-loop
|
||||
STHkr height GTH ,&done JCN
|
||||
STH2kr ;term/rows LDA2 GTH2 ,&done JCN
|
||||
cr nl
|
||||
LIT '~ emit INCr
|
||||
LIT '~ emit INC2r
|
||||
,&eof-loop JMP
|
||||
&done POP2 POPr
|
||||
&done POP2 POP2r
|
||||
ansi LIT '0 emit LIT 'm emit
|
||||
;draw-statusbar JSR2
|
||||
;draw-cursor JSR2
|
||||
|
@ -526,7 +511,7 @@
|
|||
;cur-line JSR2 ;line-len JSR2 JMP2r
|
||||
|
||||
@cur-last ( -> n* )
|
||||
;cur-line JSR2 ;line-len JSR2 #0001 SUB2 NIP JMP2r
|
||||
;cur-line JSR2 ;line-len JSR2 #0001 SUB2 JMP2r
|
||||
|
||||
@line-len ( s* -> n* )
|
||||
#0000 STH2
|
||||
|
@ -549,31 +534,31 @@
|
|||
¬-found POP2 POP2r #0000 JMP2r
|
||||
|
||||
( line number relative to the offset, starting at 0 )
|
||||
@rel-line ( y^ -> s* )
|
||||
#00 SWP SUB STH ( [-y] )
|
||||
@rel-line ( y* -> s* )
|
||||
#0000 SWP2 SUB2 STH2 ( [-y] )
|
||||
;buffer/offset LDA2 ( addr* )
|
||||
STHkr #00 EQU ,&done JCN ( addr [-y] )
|
||||
STH2kr #0000 EQU2 ,&done JCN ( addr [-y] )
|
||||
&newline ( addr [-y] )
|
||||
STHkr ,&loop JCN ,&done JMP
|
||||
STH2kr ORA ,&loop JCN ,&done JMP
|
||||
&loop ( addr [-y] )
|
||||
LDAk #00 EQU ,¬-found JCN ( addr [-y] )
|
||||
LDAk #0a EQU ,&found JCN ( addr [-y] )
|
||||
INC2 ,&loop JMP ( addr+1 [-y] )
|
||||
&found INC2 INCr ( addr+1 [-y+1] ) ,&newline JMP
|
||||
&done POPr JMP2r
|
||||
&found INC2 INC2r ( addr+1 [-y+1] ) ,&newline JMP
|
||||
&done POP2r JMP2r
|
||||
¬-found ;rel-line-error ;error! JMP2
|
||||
|
||||
@cur-line ( -> s* )
|
||||
;cursor/row LDA ;rel-line JSR2 JMP2r
|
||||
;cursor/row LDA2 ;rel-line JSR2 JMP2r
|
||||
|
||||
@cur-line-num ( -> n* )
|
||||
#00 ;cursor/row LDA ;buffer/line-offset LDA2 ADD2 JMP2r
|
||||
;cursor/row LDA2 ;buffer/line-offset LDA2 ADD2 JMP2r
|
||||
|
||||
@cur-pos ( -> s* )
|
||||
;cur-line JSR2 #00 ;cur-col JSR2 ADD2 JMP2r
|
||||
;cur-line JSR2 ;cur-col JSR2 ADD2 JMP2r
|
||||
|
||||
@cur-abs-row ( -> n* )
|
||||
;buffer/line-offset LDA2 #00 ;cursor/row LDA ADD2 JMP2r
|
||||
;buffer/line-offset LDA2 ;cursor/row LDA2 ADD2 JMP2r
|
||||
|
||||
@last-abs-row ( -> n* )
|
||||
;buffer/line-count LDA2 #0001 SUB2 JMP2r
|
||||
|
@ -609,13 +594,13 @@
|
|||
( TODO: should be using cur-col and cur-row almost everywhere )
|
||||
( otherwise, bugs! )
|
||||
|
||||
@cur-col
|
||||
;cursor/col LDA ;cur-len JSR2 NIP ;min JSR2 JMP2r
|
||||
@cur-col ( -> col* )
|
||||
;cursor/col LDA2 ;cur-len JSR2 ;min2 JSR2 JMP2r
|
||||
|
||||
@cur-row
|
||||
;cursor/row LDA JMP2r
|
||||
@cur-row ( -> row* )
|
||||
;cursor/row LDA2 JMP2r
|
||||
|
||||
@last-pos
|
||||
@last-pos ( -> addr* )
|
||||
;buffer/limit LDA2 #0001 SUB2 JMP2r
|
||||
|
||||
@more-than-one-screen ( -> bool^ )
|
||||
|
@ -630,12 +615,11 @@
|
|||
@mod-div2 ( x^ y^ -> x%d x/y )
|
||||
DIV2k STH2k MUL2 SUB2 STH2r JMP2r
|
||||
|
||||
@emit
|
||||
( &long SWP2 ,&short JSR )
|
||||
&short SWP ,&byte JSR
|
||||
&byte DUP #04 SFT ,&char JSR
|
||||
&char #0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO
|
||||
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 )
|
||||
|
||||
@emit-digit ( n^ -> )
|
||||
LIT '0 ADD emit JMP2r
|
||||
|
@ -674,7 +658,8 @@
|
|||
@term [ &cols 0050
|
||||
&rows 0018 ]
|
||||
|
||||
@cursor [ &col 00 &row 00 ]
|
||||
( relative cursor positions, e.g. 0 to cols-1 )
|
||||
@cursor [ &col 0000 &row 0000 ]
|
||||
|
||||
( did we just see ESC? )
|
||||
@saw-esc 00
|
||||
|
|
Loading…
Reference in New Issue