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