display line counts, fix some bugs

This commit is contained in:
~d6 2022-02-11 15:39:49 -05:00
parent 1a8e9e4fb6
commit 8f2028cbdd
1 changed files with 85 additions and 31 deletions

116
femto.tal
View File

@ -48,12 +48,10 @@
%exit { #01 .System/halt DEO BRK }
%ansi { #1b18 DEO #5b18 DEO }
%PEN-COL { ;term/cols LDA2 #0002 SUB2 NIP }
%HEIGHT { ;term/rows LDA2 NIP }
%LAST-LINE { ;term/rows LDA2 #0001 SUB2 NIP }
%PEN-LINE { ;term/rows LDA2 #0002 SUB2 NIP }
%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 }
|0100
;read-filename .Console/vector DEO2
@ -71,7 +69,7 @@
;buffer/data .File/read DEO2
.File/success DEI2 #0000 GTH2 ,&ok JCN
;input-error ;println JSR2 nl exit
;messages/input-error ;print JSR2 nl exit
( calculate buffer limit address using start + size )
&ok .File/success DEI2 ;buffer/data ADD2 ;buffer/limit STA2
@ -101,7 +99,8 @@
LDAk LIT '0 SUB #00 SWP STH2 ADD2r
INC2 ,&loop JMP
&parse-col
INC2 STH2r ;term/rows STA2
( INC2 STH2r ;term/rows STA2 )
INC2 STH2r #0002 SUB2 ;term/rows STA2
&loop2
LDAk LIT 'R EQU ,&done JCN
LIT2r 000a MUL2r
@ -114,6 +113,16 @@
BRK
&parse-error LDAk #00 #00 DIV
@setup-linecount ( -> )
;buffer/data LIT2r 0001
&loop DUP2 ;buffer/limit LDA2 EQU2 ,&done JCN
LDAk #00 EQU ,&done JCN
LDAk #0a NEQ JMP INC2r
INC2 ,&loop JMP
&done POP2
STH2r ;buffer/line-count STA2
JMP2r
@setup-80x24 ( -> )
#0050 ;term/cols STA2
#0014 ;term/rows STA2
@ -122,16 +131,19 @@
JMP2r
@read-filename ( -> )
#12 DEI #0a EQU ,&execute JCN ( did we read \n ? )
#12 DEI ;tmp/pos LDA2 STA ( no, so save in buffer )
;tmp/pos LDA2 INC2 ;tmp/pos STA2 ( pos++ )
BRK ( return )
#12 DEI #0a EQU ,&execute JCN ( did we read \n ? )
#12 DEI ;tmp/pos LDA2 STA ( no, so save in buffer )
;tmp/pos LDA2 INC2 ;tmp/pos STA2 ( pos++ )
BRK ( return )
&execute ( we saw a newline, so do something )
#00 ;tmp/pos LDA2 STA ( null terminate str )
;tmp/data ;tmp/pos STA2 ( reset pos )
;tmp/data ;open-file JSR2 ( open file )
;setup-terminal-size JSR2
&execute ( we saw a newline, so do something )
#00 ;tmp/pos LDA2 STA ( null terminate str )
;tmp/data ;tmp/pos STA2 ( reset pos )
( ;tmp/data ;open-file JSR2 ( open file ) )
;tmp/data ;filename ;str-copy JSR2 ( )
;filename ;open-file JSR2 ( open file )
;setup-linecount JSR2 ( determine # of lines )
;setup-terminal-size JSR2 ( detect terminal dimensions )
BRK
@ -146,7 +158,7 @@
( FIXME: handle long lines )
@forward
;cursor/col LDA PEN-COL GTH ,&skip JCN
;cursor/col LDA pen-col GTH ,&skip JCN
;cursor/col LDA #01 ADD ;cursor/col STA
;draw-cursor JSR2
&skip BRK
@ -173,7 +185,7 @@
( FIXME: need to handle 'end of buffer' stuff )
@down
;cursor/row LDA PEN-LINE GTH ,&screen-down JCN
;cursor/row LDA pen-line GTH ,&screen-down JCN
;cursor/row LDA #01 ADD ;cursor/row STA
;draw-cursor JSR2 BRK
&screen-down
@ -190,14 +202,14 @@
@die #00 #00 DIV
@insert ( c^ -> )
;cursor/col LDA PEN-COL GTH ,&skip JCN ( FIXME )
;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 )
;cursor/col LDA pen-col GTH ,&skip JCN ( FIXME )
;cur-pos JSR2 STA
;cursor/col LDA #01 ADD ;cursor/col STA
;draw-all JSR2
@ -207,6 +219,7 @@
#0a ;cur-pos JSR2 ;shift-right JSR2
#00 ;cursor/col STA
;cursor/row LDA INC ;cursor/row STA
;buffer/line-count LDA2k INC2 SWP2 STA2
;draw-all JSR2
BRK
@ -218,6 +231,7 @@
&prev-line
;cursor/row LDA #01 SUB ;cursor/row STA
;cur-len JSR2 NIP ;cursor/col STA
;buffer/line-count LDA2k #0001 SUB2 SWP2 STA2
&finish
;cur-pos JSR2 ;shift-left JSR2
;draw-all JSR2
@ -227,8 +241,11 @@
@delete ( -> )
;last-pos JSR2 #0001 SUB2
;cur-pos JSR2 LTH2k ,&skip JCN
;cur-pos JSR2 ;shift-left JSR2
;draw-all JSR2
;cur-pos JSR2 LDAk STH
;shift-left JSR2
STHr #0a NEQ ,&not-newline JCN
;buffer/line-count LDA2k #0001 SUB2 SWP2 STA2
&not-newline ;draw-all JSR2
&skip BRK
@escape ( -> )
@ -318,19 +335,35 @@
;term-move-cursor JSR2 JMP2r
@draw-statusbar
#00 #17 ;term-move-cursor JSR2
#00 height ;term-move-cursor JSR2
ansi LIT '7 emit LIT 'm emit
LIT2r 2018
;term/cols LDA2 #0000
&loop GTH2k ,&continue JCN ,&done JMP
&continue DEOkr INC2 ,&loop JMP
&done POP2 POP2 POP2r
#01 height ;term-move-cursor JSR2
;filename ;print JSR2
#20 emit
;buffer/limit LDA2 ;buffer/data SUB2 ;emit-dec2 JSR2
;messages/bytes ;print JSR2
#20 emit
;buffer/line-count LDA2 ;emit-dec2 JSR2
;messages/lines ;print JSR2
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
;term-erase-all JSR2
( ;draw-statusbar JSR2 )
;draw-statusbar JSR2
#00 #00 ;term-move-cursor JSR2
#00 STH
;buffer/offset LDA2
@ -338,13 +371,21 @@
LDAk #00 EQU ,&eof JCN
LDAk #0a EQU ,&eol JCN
LDAk emit INC2 ,&loop JMP
&eol INCr STHkr LAST-LINE ( #17 ) GTH ,&eof JCN
&eol INCr STHkr last-line ( #17 ) GTH ,&eof JCN
cr nl INC2 ,&loop JMP
&eof POP2 POPr
;draw-cursor JSR2
JMP2r
@println ( s* -> )
@str-copy ( src* dst* -> )
STH2 ( src [dst] )
&loop LDAk #00 EQU ,&done JCN
LDAk STH2kr STA
INC2 INC2r ,&loop JMP
&done POP2 #00 STH2r STA
JMP2r
@print ( s* -> )
&loop LDAk #00 EQU ,&eof JCN
LDAk #18 DEO INC2 ,&loop JMP
&eof POP2 JMP2r
@ -434,8 +475,8 @@
@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
@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
@ -447,6 +488,13 @@
@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-digit ( n^ -> )
LIT '0 ADD emit JMP2r
@ -465,12 +513,14 @@
DUP2 #0009 GTH2 ,&do2 JCN
,&do1 JMP
&do5 #2710 ;mod-div2 JSR2 NIP ;emit-digit JSR2
&do4 #03e7 ;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 JMP2r
@input-error "input 20 "error 00
@messages [ &input-error "input 20 "error 00
&bytes 20 "bytes 00
&lines 20 "lines 00 ]
@tmp [ &pos :tmp/data
&data $100 ]
@ -483,10 +533,14 @@
( did we just see ESC? )
@saw-esc 00
( )
@filename $80
( |1ffc )
( offset is address of the first visible line )
( size is total size of data in bytes )
@buffer [ &limit 0000
&offset :buffer/data
&line-count 0000
&line-offset 0000
&data $8000 ]