very basic save support + docs

This commit is contained in:
~d6 2022-02-15 21:19:44 -05:00
parent ad2f91f329
commit 45a3056406
1 changed files with 29 additions and 30 deletions

View File

@ -37,13 +37,9 @@
( blue, magenta, cyan, white )
( TODO: )
( - set up term scrolling at start )
( - optimize term drawing )
( - get long line truncation/scrolling working )
( - unify insertion/overwrite code )
( - display cursor coords )
( - page up/page down )
( - jump to end of buffer )
( - line numbers in left column (toggle mode?) )
( - help text )
( - save file command -> tmp first )
@ -55,6 +51,10 @@
( - tab support? )
( - windows line-ending support (CRLF) )
( FIXME: )
( - stop using bytes for row/col/etc. )
( - consider storing absolute cursor instead )
|00 @System [ &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1 ]
|10 @Console [ &vector $2 &read $1 &pad $5 &write $1 &error $1 ]
|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ]
@ -134,7 +134,6 @@
LDAk LIT '0 SUB #00 SWP STH2 ADD2r
INC2 ,&loop JMP
&parse-col
( INC2 STH2r ;term/rows STA2 )
INC2 STH2r #0002 SUB2 ;term/rows STA2
&loop2
LDAk LIT 'R EQU ,&done JCN
@ -181,7 +180,6 @@
;setup-terminal-size JSR2 ( detect terminal dimensions )
BRK
@bol
#00 ;cursor/col STA
;draw-statusbar JSR2
@ -214,7 +212,6 @@
;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
@ -227,7 +224,6 @@
;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 INC ;cursor/row STA
@ -246,19 +242,13 @@
;draw-all JSR2
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 )
( TODO: handle last line )
@newline ( c^ -> )
#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
;ensure-visible-cursor JSR2
;draw-all JSR2
BRK
@ -268,14 +258,14 @@
@at-line-start ( -> bool^ )
;cursor/col LDA #00 EQU JMP2r
( TODO: handle first line )
@backspace ( -> )
;at-buffer-start JSR2 ,&skip JCN
;at-line-start JSR2 ,&prev-line JCN
;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
&prev-line
;cur-line-num JSR2 #0001 SUB2
;jump-to-line JSR2 ( TODO: fix weird eof behavior )
;cur-len JSR2 NIP ;cursor/col STA
;buffer/line-count LDA2k #0001 SUB2 SWP2 STA2
&finish
@ -365,6 +355,24 @@
.Console/read DEI LIT 'g EQU ( M-g ) ;goto-line JCN2
BRK
@move-to-message-line ( -> )
#02 height #02 ADD ;term-move-cursor JSR2 JMP2r
( TODO: filename prmopt )
@save ( -> )
;buffer/limit LDA2 ;buffer/data SUB2 STH2 ( [size] )
;tmp-file-name .File/name DEO2
STH2kr .File/length DEO2
;buffer/data .File/write DEO2
;move-to-message-line JSR2
.File/success DEI2 STH2r EQU2 ( ok? ) ,&ok JCN
;messages/save-failed ,&finish JMP
&ok ;messages/save-ok
&finish ;print JSR2 BRK
@tmp-file-name "file.tmp 00
( TODO: C-g or C-h for help )
( TODO: C-s for search )
( TODO: C-v for page down )
@ -380,6 +388,7 @@
.Console/read DEI #0c EQU ( C-l ) ;refresh JCN2
.Console/read DEI #0d EQU ( \r ) ;newline JCN2
.Console/read DEI #0e EQU ( C-n ) ;down JCN2
.Console/read DEI #0f EQU ( C-o ) ;save JCN2
.Console/read DEI #10 EQU ( C-p ) ;up JCN2
.Console/read DEI #18 EQU ( C-x ) ;quit JCN2
.Console/read DEI #1a EQU ( C-z ) ;debug JCN2
@ -582,18 +591,6 @@
@fits-in-one-screen ( -> bool^ )
;buffer/line-count LDA2 ;term/rows LDA2 INC2 LTH2 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 STHk MUL SUB STHr JMP2r
@ -632,6 +629,8 @@
@messages [ &input-error "input 20 "error 00
&bytes 20 "bytes, 00
&save-ok "saved 00
&save-failed "failed 00
&lines 20 "lines] 00
&saved "-- 20 00
&unsaved "** 20 00 ]