editor progress

This commit is contained in:
~d6 2022-02-07 22:25:32 -05:00
parent 65d1a6cc52
commit 15e37c203a
1 changed files with 91 additions and 32 deletions

123
femto.tal
View File

@ -34,6 +34,11 @@
( go right ESC [ C )
( go left ESC [ D )
( )
( all scroll on ESC [ r )
( region scroll on ESC [ $y0 ; $y1 r )
( scroll down ESC D )
( scroll up ESC M )
( )
( erase cur->eol ESC [ K )
( erase cur->sol ESC [ 1 K )
( erase line ESC [ 2 K )
@ -43,6 +48,13 @@
( )
( set attrs ESC [ $at1 ; ... m )
( reset ESC [ m )
( 0 reset, 1 bright, 2 dim, )
( 4 underscore, 5 blink, )
( 7 reverse, 8 hidden )
( )
( fg (30-37), bg (40-47) )
( black, red, green, yellow, )
( blue, magenta, cyan, white )
|0100
@ -59,20 +71,6 @@
;draw-all JSR2
BRK
@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
@emit-digit ( n^ -> )
LIT '0 ADD emit JMP2r
@emit-dec ( n^ -> )
DUP #63 GTH ,&do3 JCN
DUP #09 GTH ,&do2 JCN
,&do1 JMP
&do3 #64 ;mod-div JSR2 ;emit-digit JSR2
&do2 #0a ;mod-div JSR2 ;emit-digit JSR2
&do1 ;emit-digit JSR2 JMP2r
@bol
#00 ;cursor/col STA
@ -123,36 +121,68 @@
BRK
@quit exit
@ignore BRK
@die #00 #00 DIV
@insert ( c^ -> )
;cursor/col LDA PEN-COL GTH ,&skip JCN ( FIXME )
;cur-pos JSR2 ;shift-right JSR2
;cursor/col LDA INC ;cursor/col STA
;draw-all JSR2
&skip BRK
@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
( FIXME: this is broken, shift-left in particular )
@newline ( c^ -> )
#0a ;cur-pos JSR2 ;shift-right JSR2
#00 ;cursor/col STA
;cursor/row LDA INC ;cursor/row STA
;draw-all JSR2
BRK
@backspace ( -> )
;cursor/col LDA #00 EQU ,&skip JCN
;cursor/col LDA #01 SUB ;cursor/col STA
;cur-pos JSR2 ;buffer/data EQU2 ,&skip JCN
;cursor/col LDA #00 EQU ,&prev-line JCN
;cursor/col LDA #01 SUB ;cursor/col STA
,&finish JMP
&prev-line
;cursor/row LDA #01 SUB ;cursor/row STA
;cur-len JSR2 NIP ;cursor/col STA
&finish
;cur-pos JSR2 ;shift-left JSR2
;draw-all JSR2
&skip BRK
( there's at least one bug -- join lots of lines near start )
@delete ( -> )
;last-pos JSR2 #0001 SUB2
;cur-pos JSR2 LTH2k ,&skip JCN
;cur-pos JSR2 ;shift-left JSR2
;draw-all JSR2
&skip BRK
( TODO: tab? )
@on-key
.Console/read DEI #01 EQU ;bol JCN2
.Console/read DEI #02 EQU ;back JCN2
.Console/read DEI #05 EQU ;eol JCN2
.Console/read DEI #06 EQU ;forward JCN2
.Console/read DEI #0e EQU ;down JCN2
.Console/read DEI #10 EQU ;up JCN2
.Console/read DEI #18 EQU ;quit JCN2
.Console/read DEI #7f EQU ;backspace JCN2
.Console/read DEI #01 EQU ( C-a ) ;bol JCN2
.Console/read DEI #02 EQU ( C-b ) ;back JCN2
.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 #0d EQU ( \r ) ;newline JCN2
.Console/read DEI #0e EQU ( C-n ) ;down JCN2
.Console/read DEI #10 EQU ( C-p ) ;up JCN2
.Console/read DEI #18 EQU ( C-x ) ;quit JCN2
.Console/read DEI #7f EQU ( DEL ) ;backspace JCN2
.Console/read DEI #20 LTH ;ignore JCN2 ( ignore for now )
.Console/read DEI #7e GTH ;ignore JCN2 ( ignore for now )
.Console/read DEI ;insert JMP2
.Console/read DEI ( printable ASCII ) ;insert JMP2
BRK
@min ( x^ y^ -> min^ )
@ -167,7 +197,6 @@
ansi LIT '2 emit LIT 'J emit
ansi LIT 'H emit
#00 STH
( ;buffer/data )
;buffer/offset LDA2
&loop
LDAk #00 EQU ,&eof JCN
@ -194,9 +223,6 @@
INC2 INC2r ,&loop JMP
&end POP2 STH2r JMP2r
@first-line ( -> s* )
;buffer/offset LDA2 JMP2r
( line number relative to the offset, starting at 0 )
@rel-line ( y^ -> s* )
#00 SWP SUB STH ( [-y] )
@ -235,8 +261,8 @@
@shift-left ( addr* -> )
;buffer/limit LDA2 ( addr limit )
#0001 SUB2 SWP2 ( last addr )
&loop GTHk ,&next JCN ( last addr )
,&done JMP ( last addr )
&loop GTH2k ,&next JCN ( last addr )
,&done JMP ( last addr )
&next DUP2 INC2 LDAk ( last addr addr+1 c1^ )
STH SWP2 STHr ( last addr+1 addr c1^ )
ROT ROT ( last addr+1 c1^ addr )
@ -253,9 +279,42 @@
@get-col
;cursor/col LDA ;cur-len JSR2 NIP ;min JSR2 JMP2r
@get-row
;cursor/row LDA JMP2r
@last-pos
;buffer/limit LDA2 #0001 SUB2 JMP2r
(
@doc-start ( -> s* ) ;buffer/data JMP2r
@doc-limit ( -> s* ) ;buffer/limit LDA2 JMP2r
@doc-last ( -> s* ) ;buffer/limit LDA2 #0001 SUB2 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
@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
)
@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
@emit-digit ( n^ -> )
LIT '0 ADD emit JMP2r
@emit-dec ( n^ -> )
DUP #63 GTH ,&do3 JCN
DUP #09 GTH ,&do2 JCN
,&do1 JMP
&do3 #64 ;mod-div JSR2 ;emit-digit JSR2
&do2 #0a ;mod-div JSR2 ;emit-digit JSR2
&do1 ;emit-digit JSR2 JMP2r
|1ffc
( offset is address of the first visible line )
( size is total size of data in bytes )