2022-02-09 20:04:12 -05:00
|
|
|
( femto.tal )
|
|
|
|
( )
|
|
|
|
( requires terminal to be in raw mode )
|
2022-02-07 22:57:34 -05:00
|
|
|
( see femto launcher script for more details )
|
2022-02-09 20:04:12 -05:00
|
|
|
( )
|
|
|
|
( ANSI sequences )
|
|
|
|
( )
|
|
|
|
( goto $row,$col ESC [ $row ; $col H )
|
|
|
|
( goto home ESC [ H )
|
|
|
|
( go up ESC [ A )
|
|
|
|
( go down ESC [ B )
|
|
|
|
( go right ESC [ C )
|
|
|
|
( go left ESC [ D )
|
|
|
|
( )
|
|
|
|
( query cursor ESC [ 6 n )
|
|
|
|
( )
|
|
|
|
( 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 )
|
|
|
|
( erase line->bot ESC [ J )
|
|
|
|
( erase line->top ESC [ 1 J )
|
|
|
|
( erase all ESC [ 2 J )
|
|
|
|
( )
|
|
|
|
( 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 )
|
2022-02-06 17:07:11 -05:00
|
|
|
|
2022-02-11 19:15:40 -05:00
|
|
|
( TODO: )
|
|
|
|
( - optimize term drawing )
|
|
|
|
( - get long line truncation/scrolling working )
|
|
|
|
( - line numbers in left column (toggle mode?) )
|
|
|
|
( - help text )
|
|
|
|
( - save file command -> tmp first )
|
|
|
|
( - open file command? )
|
|
|
|
( - close file command? )
|
|
|
|
( - move by word/paragraph )
|
|
|
|
( - search )
|
|
|
|
( - search&replace )
|
|
|
|
( - tab support? )
|
|
|
|
( - windows line-ending support (CRLF) )
|
2022-02-15 21:19:44 -05:00
|
|
|
( FIXME: )
|
|
|
|
( - stop using bytes for row/col/etc. )
|
|
|
|
( - consider storing absolute cursor instead )
|
|
|
|
|
2022-02-06 17:07:11 -05:00
|
|
|
|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 ]
|
|
|
|
|
|
|
|
%dbg { #ff .System/debug DEO }
|
|
|
|
%emit { .Console/write DEO }
|
|
|
|
%sp { #2018 DEO }
|
|
|
|
%nl { #0a18 DEO }
|
|
|
|
%cr { #0d18 DEO }
|
|
|
|
%ansi { #1b18 DEO #5b18 DEO }
|
|
|
|
|
2022-02-13 14:46:50 -05:00
|
|
|
%quit! { #01 .System/halt DEO }
|
|
|
|
|
2022-03-07 12:56:52 -05:00
|
|
|
( zero page )
|
|
|
|
|0000
|
|
|
|
|
2022-02-17 23:33:48 -05:00
|
|
|
( startup )
|
|
|
|
|0100 ;startup JMP2
|
2022-02-06 17:07:11 -05:00
|
|
|
|
2022-03-06 15:35:14 -05:00
|
|
|
( code to run on startup )
|
2022-02-17 23:33:48 -05:00
|
|
|
@startup ;read-filename .Console/vector DEO2 BRK
|
2022-02-09 02:35:46 -05:00
|
|
|
|
2022-02-13 14:46:50 -05:00
|
|
|
( ERROR HANDLING )
|
|
|
|
|
|
|
|
( using error! will print the given message before causing )
|
|
|
|
( the interpreter to halt. )
|
|
|
|
@error! ( msg* -> )
|
|
|
|
LIT '! emit sp
|
|
|
|
&loop LDAk ,&continue JCN ,&done JMP
|
|
|
|
&continue LDAk emit INC2 ,&loop JMP
|
|
|
|
&done POP2 nl
|
|
|
|
dbg BRK
|
|
|
|
|
|
|
|
( error messages )
|
|
|
|
@term-size-parse-error "error 20 "parsing 20 "term 20 "size 00
|
|
|
|
@rel-line-error "invalid 20 "relative 20 "line 20 "number 00
|
|
|
|
|
2022-02-09 02:35:46 -05:00
|
|
|
@open-file ( filename* -> )
|
2022-02-09 20:04:12 -05:00
|
|
|
.File/name DEO2
|
2022-03-03 21:12:26 -05:00
|
|
|
#f000 .File/length DEO2
|
2022-02-09 20:04:12 -05:00
|
|
|
;buffer/data .File/read DEO2
|
2022-02-06 17:07:11 -05:00
|
|
|
|
|
|
|
.File/success DEI2 #0000 GTH2 ,&ok JCN
|
2022-02-13 14:46:50 -05:00
|
|
|
;messages/input-error ;print JSR2 nl quit!
|
2022-02-06 17:07:11 -05:00
|
|
|
|
2022-02-09 20:04:12 -05:00
|
|
|
( calculate buffer limit address using start + size )
|
|
|
|
&ok .File/success DEI2 ;buffer/data ADD2 ;buffer/limit STA2
|
2022-02-09 02:35:46 -05:00
|
|
|
JMP2r
|
2022-02-09 01:05:11 -05:00
|
|
|
|
2022-02-18 00:20:09 -05:00
|
|
|
@setup-terminal-size ( -> )
|
2022-03-07 12:56:52 -05:00
|
|
|
( ;setup-80x24 JMP2 )
|
2022-02-18 00:20:09 -05:00
|
|
|
#03e7 #03e7 ;term-move-cursor JSR2
|
2022-02-09 02:35:46 -05:00
|
|
|
;term-get-cursor-position JSR2
|
|
|
|
;tmp/data ;tmp/pos STA2
|
|
|
|
;receive-terminal-size .Console/vector DEO2
|
|
|
|
JMP2r
|
|
|
|
|
2022-02-18 00:20:09 -05:00
|
|
|
@receive-terminal-size ( -> )
|
2022-02-09 02:35:46 -05:00
|
|
|
.Console/read DEI ;tmp/pos LDA2 STA
|
|
|
|
;tmp/pos LDA2 INC2 ;tmp/pos STA2
|
|
|
|
.Console/read DEI LIT 'R EQU ;parse-terminal-size JCN2
|
|
|
|
BRK
|
|
|
|
|
|
|
|
@parse-terminal-size ( -> )
|
|
|
|
LIT2r 0000 LIT2r 0000
|
2022-02-09 20:04:12 -05:00
|
|
|
;tmp/data LDAk #1b NEQ ,&parse-error JCN ( i ) INC2
|
2022-02-09 02:35:46 -05:00
|
|
|
LDAk LIT '[ NEQ ,&parse-error JCN ( i ) INC2
|
|
|
|
&loop
|
|
|
|
LDAk LIT '; EQU ,&parse-col JCN
|
|
|
|
LIT2r 000a MUL2r
|
|
|
|
LDAk LIT '0 SUB #00 SWP STH2 ADD2r
|
|
|
|
INC2 ,&loop JMP
|
|
|
|
&parse-col
|
2022-02-11 15:39:49 -05:00
|
|
|
INC2 STH2r #0002 SUB2 ;term/rows STA2
|
2022-02-09 02:35:46 -05:00
|
|
|
&loop2
|
|
|
|
LDAk LIT 'R EQU ,&done JCN
|
|
|
|
LIT2r 000a MUL2r
|
|
|
|
LDAk LIT '0 SUB #00 SWP STH2 ADD2r
|
|
|
|
INC2 ,&loop2 JMP
|
|
|
|
&done
|
|
|
|
STH2r ;term/cols STA2 POP2
|
|
|
|
;on-key .Console/vector DEO2
|
|
|
|
;draw-all JSR2
|
|
|
|
BRK
|
2022-02-13 14:46:50 -05:00
|
|
|
&parse-error POP2 ;tmp/data LDA2
|
|
|
|
;term-size-parse-error ;error! JMP2
|
2022-02-09 02:35:46 -05:00
|
|
|
|
2022-02-11 15:39:49 -05:00
|
|
|
@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
|
|
|
|
|
2022-02-09 02:35:46 -05:00
|
|
|
@setup-80x24 ( -> )
|
2022-02-09 01:05:11 -05:00
|
|
|
#0050 ;term/cols STA2
|
|
|
|
#0014 ;term/rows STA2
|
|
|
|
;on-key .Console/vector DEO2
|
|
|
|
;draw-all JSR2
|
2022-02-09 02:35:46 -05:00
|
|
|
JMP2r
|
2022-02-09 01:05:11 -05:00
|
|
|
|
2022-02-09 02:35:46 -05:00
|
|
|
@read-filename ( -> )
|
2022-02-11 15:39:49 -05:00
|
|
|
#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 )
|
2022-02-13 14:46:50 -05:00
|
|
|
;tmp/data ;filename ;str-copy JSR2 ( open file )
|
2022-02-11 15:39:49 -05:00
|
|
|
;filename ;open-file JSR2 ( open file )
|
|
|
|
;setup-linecount JSR2 ( determine # of lines )
|
|
|
|
;setup-terminal-size JSR2 ( detect terminal dimensions )
|
2022-02-06 17:07:11 -05:00
|
|
|
BRK
|
|
|
|
|
2022-02-18 00:20:09 -05:00
|
|
|
@bol ( -> )
|
|
|
|
#0000 ;cursor/col STA2
|
2022-02-12 02:10:27 -05:00
|
|
|
;draw-statusbar JSR2
|
2022-02-06 17:07:11 -05:00
|
|
|
;draw-cursor JSR2 BRK
|
|
|
|
|
|
|
|
( FIXME: handle long lines )
|
2022-02-18 00:20:09 -05:00
|
|
|
@eol ( -> )
|
|
|
|
;cur-line JSR2 ;line-len JSR2 ;cursor/col STA2
|
2022-02-12 02:10:27 -05:00
|
|
|
;draw-statusbar JSR2
|
2022-02-06 17:07:11 -05:00
|
|
|
;draw-cursor JSR2 BRK
|
|
|
|
|
|
|
|
( FIXME: handle long lines )
|
2022-02-18 00:20:09 -05:00
|
|
|
@forward ( -> )
|
2022-02-14 16:47:36 -05:00
|
|
|
;cur-pos JSR2 ;last-pos JSR2 GTH2 ,&skip JCN
|
2022-02-18 00:20:09 -05:00
|
|
|
;cur-col JSR2 ;cur-last JSR2 GTH2 ,&next-line JCN
|
|
|
|
;cur-col JSR2 INC2 ;cursor/col STA2
|
2022-02-14 16:47:36 -05:00
|
|
|
;draw-statusbar JSR2 ;draw-cursor JSR2
|
|
|
|
,&skip JMP
|
2022-02-18 00:20:09 -05:00
|
|
|
&next-line #0000 ;cursor/col STA2
|
2022-03-06 15:35:14 -05:00
|
|
|
;inc-row JSR2
|
2022-02-14 16:47:36 -05:00
|
|
|
;ensure-visible-cursor JSR2
|
|
|
|
;draw-cursor JSR2
|
2022-02-06 17:07:11 -05:00
|
|
|
&skip BRK
|
|
|
|
|
|
|
|
( FIXME: handle long lines )
|
2022-02-18 00:20:09 -05:00
|
|
|
@back ( -> )
|
2022-02-14 16:47:36 -05:00
|
|
|
;cur-col JSR2 #01 LTH ,&skip JCN
|
2022-02-18 00:20:09 -05:00
|
|
|
;cur-col JSR2 #0001 SUB2 ;cursor/col STA2
|
2022-02-12 02:10:27 -05:00
|
|
|
;draw-statusbar JSR2
|
2022-02-06 17:07:11 -05:00
|
|
|
;draw-cursor JSR2
|
|
|
|
&skip BRK
|
|
|
|
|
2022-02-18 00:20:09 -05:00
|
|
|
@up ( -> )
|
2022-02-18 00:34:42 -05:00
|
|
|
;cur-abs-row JSR2 #0000 EQU2 ,&done JCN
|
2022-03-06 15:35:14 -05:00
|
|
|
;cur-rel-row JSR2 #0001 LTH2 ,&screen-up JCN
|
|
|
|
;dec-row JSR2
|
2022-02-12 02:10:27 -05:00
|
|
|
;draw-statusbar JSR2
|
2022-02-06 17:07:11 -05:00
|
|
|
;draw-cursor JSR2 BRK
|
|
|
|
&screen-up
|
2022-02-18 00:34:42 -05:00
|
|
|
;cur-abs-row JSR2 #0001 SUB2
|
2022-02-14 16:47:36 -05:00
|
|
|
;jump-to-line JSR2
|
|
|
|
;draw-all JSR2
|
|
|
|
&done BRK
|
2022-02-06 17:07:11 -05:00
|
|
|
|
2022-02-18 00:20:09 -05:00
|
|
|
@down ( -> )
|
2022-02-13 14:46:50 -05:00
|
|
|
;cur-abs-row JSR2 ;last-abs-row JSR2 EQU2 ,&done JCN
|
2022-03-06 15:35:14 -05:00
|
|
|
;inc-row JSR2
|
2022-02-14 16:47:36 -05:00
|
|
|
;ensure-visible-cursor JSR2
|
2022-02-12 02:10:27 -05:00
|
|
|
;draw-statusbar JSR2
|
2022-02-06 17:07:11 -05:00
|
|
|
;draw-cursor JSR2 BRK
|
2022-02-13 14:46:50 -05:00
|
|
|
&done BRK
|
2022-02-06 17:07:11 -05:00
|
|
|
|
2022-02-18 00:20:09 -05:00
|
|
|
@page-up ( -> )
|
2022-02-18 00:48:59 -05:00
|
|
|
;bof-is-visible JSR2 ,&at-bof JCN
|
2022-02-15 22:03:31 -05:00
|
|
|
;buffer/line-offset LDA2
|
2022-02-18 00:48:59 -05:00
|
|
|
;term/rows LDA2 #0003 SUB2
|
|
|
|
LTH2k ,&near-bof JCN
|
|
|
|
SUB2 DUP2 ;abs-line JSR2 ;buffer/offset STA2
|
|
|
|
;buffer/line-offset STA2
|
2022-02-15 22:03:31 -05:00
|
|
|
;ensure-visible-cursor JSR2
|
|
|
|
;draw-all JSR2 BRK
|
2022-03-06 15:35:14 -05:00
|
|
|
&near-bof POP2 POP2
|
|
|
|
;zero-row JSR2
|
|
|
|
#0000 ;cursor/col STA2
|
2022-02-18 00:48:59 -05:00
|
|
|
;draw-all JSR2 BRK
|
|
|
|
&at-bof
|
2022-03-06 15:35:14 -05:00
|
|
|
;zero-row JSR2
|
2022-02-18 00:20:09 -05:00
|
|
|
#0000 ;cursor/col STA2
|
2022-02-15 22:03:31 -05:00
|
|
|
;draw-cursor JSR2 BRK
|
2022-02-15 21:58:12 -05:00
|
|
|
|
|
|
|
@page-down
|
|
|
|
;eof-is-visible JSR2 ,&near-eof JCN
|
2022-02-15 22:03:31 -05:00
|
|
|
;buffer/line-offset LDA2
|
|
|
|
;term/rows LDA2 ADD2 #0003 SUB2
|
|
|
|
DUP2 ;abs-line JSR2 ;buffer/offset STA2
|
|
|
|
;buffer/line-offset STA2
|
|
|
|
;ensure-visible-cursor JSR2
|
|
|
|
;draw-all JSR2 BRK
|
2022-02-15 21:58:12 -05:00
|
|
|
&near-eof
|
2022-03-07 12:56:52 -05:00
|
|
|
;buffer/line-count LDA2 #0001 SUB2 ;set-abs-row JSR2
|
2022-02-18 00:20:09 -05:00
|
|
|
;cur-len JSR2 ;cursor/col STA2
|
2022-02-15 21:58:12 -05:00
|
|
|
;draw-cursor JSR2 BRK
|
|
|
|
|
2022-02-13 14:46:50 -05:00
|
|
|
@quit quit!
|
2022-02-07 22:25:32 -05:00
|
|
|
|
2022-02-06 17:07:11 -05:00
|
|
|
@ignore BRK
|
2022-02-07 22:25:32 -05:00
|
|
|
|
2022-02-06 17:07:11 -05:00
|
|
|
@insert ( c^ -> )
|
|
|
|
;cur-pos JSR2 ;shift-right JSR2
|
2022-02-18 00:20:09 -05:00
|
|
|
;cur-col JSR2 INC2 ;cursor/col STA2
|
2022-02-07 22:25:32 -05:00
|
|
|
;draw-all JSR2
|
2022-02-14 16:47:36 -05:00
|
|
|
BRK
|
2022-02-07 22:25:32 -05:00
|
|
|
|
2022-03-03 21:12:26 -05:00
|
|
|
@insert-tab ( -> )
|
|
|
|
;config/insert-tabs LDA ,&use-tabs JCN
|
|
|
|
#0000 ;config/tab-width LDA2 SUB2
|
|
|
|
&loop
|
|
|
|
DUP2 #0000 EQU2 ,&done JCN
|
|
|
|
#20 ;cur-pos JSR2 ;shift-right JSR2
|
|
|
|
INC2 ,&loop JMP
|
|
|
|
&done
|
|
|
|
;cur-col JSR2 ;config/tab-width LDA2 ADD2 ;cursor/col STA2
|
|
|
|
;draw-all JSR2 BRK
|
|
|
|
&use-tabs
|
|
|
|
#09 ;insert JMP2
|
|
|
|
|
2022-02-12 02:10:27 -05:00
|
|
|
( TODO: handle last line )
|
2022-02-07 22:25:32 -05:00
|
|
|
@newline ( c^ -> )
|
|
|
|
#0a ;cur-pos JSR2 ;shift-right JSR2
|
2022-02-18 00:20:09 -05:00
|
|
|
#0000 ;cursor/col STA2
|
2022-03-06 15:35:14 -05:00
|
|
|
;inc-row JSR2
|
2022-02-11 15:39:49 -05:00
|
|
|
;buffer/line-count LDA2k INC2 SWP2 STA2
|
2022-02-15 21:19:44 -05:00
|
|
|
;ensure-visible-cursor JSR2
|
2022-02-07 22:25:32 -05:00
|
|
|
;draw-all JSR2
|
|
|
|
BRK
|
|
|
|
|
2022-02-13 14:46:50 -05:00
|
|
|
@at-buffer-start ( -> bool^ )
|
|
|
|
;cur-pos JSR2 ;buffer/data EQU2 JMP2r
|
|
|
|
|
|
|
|
@at-line-start ( -> bool^ )
|
2022-02-18 00:20:09 -05:00
|
|
|
;cursor/col LDA2 #0000 EQU2 JMP2r
|
2022-02-13 14:46:50 -05:00
|
|
|
|
2022-02-15 22:03:31 -05:00
|
|
|
@bof-is-visible ( -> bool^ )
|
|
|
|
;buffer/line-offset LDA2 #0000 EQU2 JMP2r
|
|
|
|
|
2022-02-15 21:58:12 -05:00
|
|
|
@eof-is-visible ( -> bool^ )
|
|
|
|
;buffer/line-offset LDA2 ;term/rows LDA2 ADD2 INC2
|
|
|
|
;buffer/line-count LDA2
|
|
|
|
GTH2 JMP2r
|
|
|
|
|
2022-02-06 17:07:11 -05:00
|
|
|
@backspace ( -> )
|
2022-02-13 14:46:50 -05:00
|
|
|
;at-buffer-start JSR2 ,&skip JCN
|
|
|
|
;at-line-start JSR2 ,&prev-line JCN
|
2022-02-18 00:20:09 -05:00
|
|
|
;cur-col JSR2 #0001 SUB2 ;cursor/col STA2
|
2022-02-07 22:25:32 -05:00
|
|
|
,&finish JMP
|
2022-02-15 21:19:44 -05:00
|
|
|
&prev-line
|
2022-02-18 00:34:42 -05:00
|
|
|
;cur-abs-row JSR2 #0001 SUB2
|
2022-02-15 21:19:44 -05:00
|
|
|
;jump-to-line JSR2 ( TODO: fix weird eof behavior )
|
2022-02-18 00:20:09 -05:00
|
|
|
;cur-len JSR2 ;cursor/col STA2
|
2022-02-11 15:39:49 -05:00
|
|
|
;buffer/line-count LDA2k #0001 SUB2 SWP2 STA2
|
2022-02-07 22:25:32 -05:00
|
|
|
&finish
|
|
|
|
;cur-pos JSR2 ;shift-left JSR2
|
|
|
|
;draw-all JSR2
|
|
|
|
&skip BRK
|
|
|
|
|
|
|
|
@delete ( -> )
|
2022-02-13 14:46:50 -05:00
|
|
|
;last-pos JSR2 #0001 SUB2 ( lst-1 )
|
|
|
|
;cur-pos JSR2 LTH2 ,&skip JCN
|
|
|
|
;cur-pos JSR2 LDAk STH ( cur [c] )
|
|
|
|
;shift-left JSR2 ( [c] )
|
2022-02-11 15:39:49 -05:00
|
|
|
STHr #0a NEQ ,¬-newline JCN
|
|
|
|
;buffer/line-count LDA2k #0001 SUB2 SWP2 STA2
|
|
|
|
¬-newline ;draw-all JSR2
|
2022-02-06 17:07:11 -05:00
|
|
|
&skip BRK
|
|
|
|
|
2022-02-08 22:22:08 -05:00
|
|
|
@escape ( -> )
|
|
|
|
#01 ;saw-esc STA BRK
|
|
|
|
|
2022-02-12 02:25:41 -05:00
|
|
|
@goto-end ( -> )
|
2022-02-13 14:46:50 -05:00
|
|
|
;more-than-one-screen JSR2 ,&large JCN
|
2022-02-18 00:20:09 -05:00
|
|
|
;buffer/line-count LDA2 #0001 SUB2 ;cursor/row STA2
|
2022-02-13 14:46:50 -05:00
|
|
|
#0000 ,&continue JMP
|
|
|
|
&large
|
2022-02-18 00:20:09 -05:00
|
|
|
;term/rows LDA2 #0001 SUB2 ;cursor/row STA2
|
2022-02-13 14:46:50 -05:00
|
|
|
;buffer/line-count LDA2 ;term/rows LDA2 SUB2
|
|
|
|
&continue
|
|
|
|
DUP2 ;buffer/line-offset STA2
|
|
|
|
;abs-line JSR2 ;buffer/offset STA2
|
2022-02-18 00:20:09 -05:00
|
|
|
;cur-len JSR2 ;cursor/col STA2
|
2022-02-13 14:46:50 -05:00
|
|
|
;draw-all JSR2 BRK
|
2022-02-12 02:25:41 -05:00
|
|
|
|
2022-02-08 22:22:08 -05:00
|
|
|
@goto-start ( -> )
|
2022-03-06 15:35:14 -05:00
|
|
|
;zero-row JSR2
|
2022-02-18 00:20:09 -05:00
|
|
|
#0000 ;cursor/col STA2
|
2022-02-08 22:22:08 -05:00
|
|
|
;draw-all JSR2
|
|
|
|
BRK
|
|
|
|
|
2022-02-10 01:40:48 -05:00
|
|
|
@goto-line ( -> )
|
2022-02-14 16:47:36 -05:00
|
|
|
#0016 ;jump-to-line JSR2
|
2022-02-10 01:40:48 -05:00
|
|
|
;draw-all JSR2 BRK
|
|
|
|
|
|
|
|
@jump-to-line ( n* -> )
|
|
|
|
;term/rows LDA2 #0002 DIV2 LTH2k ( n rows/2 n<rows/2? ) ,&early JCN
|
|
|
|
OVR2 SWP2 SUB2 ( n n-rows/2 )
|
|
|
|
;buffer/line-count LDA2 ( n n-rows/2 lines )
|
|
|
|
;term/rows LDA2 SUB2 ( n n-rows/2 lines-rows )
|
|
|
|
GTH2k ( n n-rows/2 lines-rows n-rows/2>lines-rows? )
|
|
|
|
,&late JCN ( n n-rows/2 lines-rows )
|
|
|
|
POP2 ,&finish JMP
|
|
|
|
&early ( n rows/2 )
|
2022-02-14 16:47:36 -05:00
|
|
|
POP2 #0000 ,&finish JMP ( n 0000 )
|
2022-02-10 01:40:48 -05:00
|
|
|
&late ( n n-rows/2 lines-rows )
|
2022-02-14 16:47:36 -05:00
|
|
|
NIP2
|
2022-02-10 01:40:48 -05:00
|
|
|
&finish ( n o )
|
2022-02-14 16:47:36 -05:00
|
|
|
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] )
|
2022-02-18 00:20:09 -05:00
|
|
|
#0000 ;cursor/col STA2 ( n [n-o] )
|
2022-03-03 21:12:26 -05:00
|
|
|
POP2 STH2r ;cursor/row STA2
|
2022-02-10 01:40:48 -05:00
|
|
|
JMP2r
|
|
|
|
|
2022-02-14 16:47:36 -05:00
|
|
|
@ensure-visible-cursor
|
2022-03-06 15:35:14 -05:00
|
|
|
;cur-rel-row JSR2 ;term/rows LDA2 LTH2 ,&noop JCN
|
2022-02-18 00:34:42 -05:00
|
|
|
;cur-abs-row JSR2 ;jump-to-line JSR2
|
2022-02-14 16:47:36 -05:00
|
|
|
;draw-all JSR2
|
|
|
|
&noop JMP2r
|
|
|
|
|
2022-02-13 14:46:50 -05:00
|
|
|
@refresh
|
|
|
|
;draw-all JSR2 BRK
|
|
|
|
|
|
|
|
@debug
|
|
|
|
;rel-line-error ;error! JMP2
|
|
|
|
|
2022-02-15 22:03:31 -05:00
|
|
|
( TODO: M-f and M-b for next/previous word )
|
2022-02-09 20:04:12 -05:00
|
|
|
( M-n and M-p for next/previous paragraph )
|
|
|
|
( maybe M-% for search&replace )
|
2022-02-18 00:20:09 -05:00
|
|
|
@on-key-escaped ( -> )
|
2022-02-08 22:22:08 -05:00
|
|
|
#00 ;saw-esc STA
|
|
|
|
.Console/read DEI LIT '< EQU ( M-< ) ;goto-start JCN2
|
|
|
|
.Console/read DEI LIT '> EQU ( M-> ) ;goto-end JCN2
|
2022-02-10 01:40:48 -05:00
|
|
|
.Console/read DEI LIT 'g EQU ( M-g ) ;goto-line JCN2
|
2022-02-15 21:58:12 -05:00
|
|
|
.Console/read DEI LIT 'v EQU ( M-v ) ;page-up JCN2
|
2022-02-08 22:22:08 -05:00
|
|
|
BRK
|
2022-02-09 20:04:12 -05:00
|
|
|
|
2022-02-15 21:19:44 -05:00
|
|
|
@move-to-message-line ( -> )
|
2022-03-07 12:56:52 -05:00
|
|
|
#0002 ;term/rows LDA2 #0002 ADD2 ;term-move-cursor JMP2
|
2022-02-15 21:19:44 -05:00
|
|
|
|
|
|
|
( 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
|
|
|
|
|
2022-02-09 20:04:12 -05:00
|
|
|
( TODO: C-g or C-h for help )
|
|
|
|
( TODO: C-s for search )
|
|
|
|
( TODO: tab input? )
|
|
|
|
@on-key
|
|
|
|
;saw-esc LDA ;on-key-escaped JCN2
|
2022-02-07 22:25:32 -05:00
|
|
|
.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
|
2022-03-03 21:12:26 -05:00
|
|
|
.Console/read DEI #09 EQU ( \t ) ;insert-tab JCN2
|
2022-02-13 14:46:50 -05:00
|
|
|
.Console/read DEI #0c EQU ( C-l ) ;refresh JCN2
|
2022-02-07 22:25:32 -05:00
|
|
|
.Console/read DEI #0d EQU ( \r ) ;newline JCN2
|
|
|
|
.Console/read DEI #0e EQU ( C-n ) ;down JCN2
|
2022-02-15 21:19:44 -05:00
|
|
|
.Console/read DEI #0f EQU ( C-o ) ;save JCN2
|
2022-02-07 22:25:32 -05:00
|
|
|
.Console/read DEI #10 EQU ( C-p ) ;up JCN2
|
2022-02-15 21:58:12 -05:00
|
|
|
.Console/read DEI #16 EQU ( C-v ) ;page-down JCN2
|
2022-02-07 22:25:32 -05:00
|
|
|
.Console/read DEI #18 EQU ( C-x ) ;quit JCN2
|
2022-02-13 14:46:50 -05:00
|
|
|
.Console/read DEI #1a EQU ( C-z ) ;debug JCN2
|
2022-02-08 22:22:08 -05:00
|
|
|
.Console/read DEI #1b EQU ( ESC ) ;escape JCN2
|
2022-02-07 22:25:32 -05:00
|
|
|
.Console/read DEI #7f EQU ( DEL ) ;backspace JCN2
|
2022-02-06 17:07:11 -05:00
|
|
|
.Console/read DEI #20 LTH ;ignore JCN2 ( ignore for now )
|
|
|
|
.Console/read DEI #7e GTH ;ignore JCN2 ( ignore for now )
|
2022-02-07 22:25:32 -05:00
|
|
|
.Console/read DEI ( printable ASCII ) ;insert JMP2
|
2022-02-06 17:07:11 -05:00
|
|
|
BRK
|
|
|
|
|
2022-02-15 21:58:12 -05:00
|
|
|
@min2 ( x* y* -> min* )
|
|
|
|
LTH2k JMP SWP2 POP2 JMP2r
|
|
|
|
|
2022-02-18 00:48:59 -05:00
|
|
|
@max2 ( x* y* -> min* )
|
|
|
|
GTH2k JMP SWP2 POP2 JMP2r
|
|
|
|
|
2022-02-18 00:20:09 -05:00
|
|
|
@term-move-cursor ( col* row* -> )
|
|
|
|
ansi INC2 ( row+1 ) ;emit-dec2 JSR2
|
|
|
|
LIT '; emit INC2 ( col+1 ) ;emit-dec2 JSR2
|
2022-02-06 17:07:11 -05:00
|
|
|
LIT 'H emit JMP2r
|
|
|
|
|
2022-03-03 21:12:26 -05:00
|
|
|
@term-move-right ( n* -> )
|
|
|
|
ansi ;emit-dec2 JSR2 LIT 'C emit JMP2r
|
|
|
|
|
2022-02-18 00:20:09 -05:00
|
|
|
@term-get-cursor-position ( -> )
|
2022-02-09 01:05:11 -05:00
|
|
|
ansi LIT '6 emit LIT 'n emit JMP2r
|
|
|
|
|
2022-02-18 00:20:09 -05:00
|
|
|
@term-erase-all ( -> )
|
2022-02-09 01:05:11 -05:00
|
|
|
ansi LIT '2 emit LIT 'J emit JMP2r
|
|
|
|
|
2022-02-18 00:20:09 -05:00
|
|
|
@draw-cursor ( -> )
|
2022-03-03 21:12:26 -05:00
|
|
|
;cur-w-col JSR2 ;term/lmargin LDA2 ADD2
|
2022-03-06 15:35:14 -05:00
|
|
|
;cur-rel-row JSR2
|
2022-03-07 12:56:52 -05:00
|
|
|
;term-move-cursor JMP2
|
2022-02-09 01:05:11 -05:00
|
|
|
|
2022-02-18 00:20:09 -05:00
|
|
|
@draw-statusbar ( -> )
|
|
|
|
#0000 ;term/rows LDA2 ;term-move-cursor JSR2
|
2022-03-04 15:30:26 -05:00
|
|
|
;emit-color-reverse JSR2
|
2022-02-09 01:05:11 -05:00
|
|
|
LIT2r 2018
|
|
|
|
;term/cols LDA2 #0000
|
|
|
|
&loop GTH2k ,&continue JCN ,&done JMP
|
|
|
|
&continue DEOkr INC2 ,&loop JMP
|
|
|
|
&done POP2 POP2 POP2r
|
2022-02-11 15:39:49 -05:00
|
|
|
|
2022-02-18 00:20:09 -05:00
|
|
|
#0000 ;term/rows LDA2 ;term-move-cursor JSR2
|
2022-02-11 19:15:40 -05:00
|
|
|
;messages/saved ;print JSR2
|
2022-02-11 15:39:49 -05:00
|
|
|
;filename ;print JSR2
|
|
|
|
#20 emit
|
2022-02-12 02:10:27 -05:00
|
|
|
LIT '[ emit
|
2022-02-11 15:39:49 -05:00
|
|
|
;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
|
2022-02-12 02:10:27 -05:00
|
|
|
#20 emit
|
|
|
|
LIT '( emit
|
2022-02-14 16:47:36 -05:00
|
|
|
;cur-col JSR2 INC ;emit-dec JSR2
|
2022-02-12 02:10:27 -05:00
|
|
|
LIT ', emit
|
2022-02-12 02:25:41 -05:00
|
|
|
;cur-abs-row JSR2 INC2 ;emit-dec2 JSR2
|
2022-02-12 02:10:27 -05:00
|
|
|
LIT ') emit
|
2022-02-11 15:39:49 -05:00
|
|
|
|
2022-03-04 15:30:26 -05:00
|
|
|
;emit-reset JSR2
|
2022-02-09 01:05:11 -05:00
|
|
|
JMP2r
|
|
|
|
|
2022-03-03 21:12:26 -05:00
|
|
|
@draw-linenum ( n* -> )
|
2022-03-04 15:30:26 -05:00
|
|
|
;emit-reset JSR2
|
2022-03-03 21:12:26 -05:00
|
|
|
ansi ;config/color LDA2 emit emit LIT 'm emit
|
|
|
|
;emit-dec2-pad JSR2
|
|
|
|
ansi LIT2 'm '0 emit emit JMP2r
|
|
|
|
|
|
|
|
@emit-tab ( -> )
|
|
|
|
#0000 ;config/tab-width LDA2 SUB2
|
|
|
|
LIT2r 2018
|
|
|
|
&loop ORAk ,&next JCN POP2 POP2r JMP2r
|
|
|
|
&next DEOkr INC2 ,&loop JMP
|
|
|
|
|
2022-03-04 01:47:11 -05:00
|
|
|
@emit-red ( -> )
|
|
|
|
ansi LIT '3 emit LIT '1 emit LIT 'm emit JMP2r
|
|
|
|
|
|
|
|
@emit-reset ( -> )
|
|
|
|
ansi LIT '0 emit LIT 'm emit JMP2r
|
|
|
|
|
|
|
|
@emit-red-dollar ( -> )
|
|
|
|
;emit-red JSR2 LIT '$ emit ;emit-reset JMP2
|
|
|
|
|
2022-03-04 15:30:26 -05:00
|
|
|
@emit-color-reverse ( -> )
|
|
|
|
ansi ;config/color LDA2 emit emit LIT2 '7 '; emit emit LIT 'm emit JMP2r
|
|
|
|
|
2022-02-18 00:20:09 -05:00
|
|
|
@draw-all ( -> )
|
2022-02-09 01:05:11 -05:00
|
|
|
;term-erase-all JSR2
|
2022-02-18 00:20:09 -05:00
|
|
|
#0000 #0000 ;term-move-cursor JSR2
|
2022-03-03 21:12:26 -05:00
|
|
|
;buffer/line-offset LDA2 STH2 LIT2r 0001 ( [k line-offset] )
|
2022-02-06 17:07:11 -05:00
|
|
|
;buffer/offset LDA2
|
2022-03-04 15:30:26 -05:00
|
|
|
&bol
|
|
|
|
ADD2kr STH2r ;draw-linenum JSR2
|
|
|
|
;term/lmargin LDA2 INC2 ,&x STR2
|
|
|
|
( TODO: use this for cursor-line highlighting and long line support )
|
|
|
|
( STH2kr ;cursor/row LDA2 INC2 NEQ2 ,&loop JCN
|
2022-03-06 15:35:14 -05:00
|
|
|
;emit-color-reverse JSR2 )
|
2022-03-04 01:47:11 -05:00
|
|
|
&loop ( offset [k line-offset] )
|
2022-03-04 15:30:26 -05:00
|
|
|
LDAk #00 EQU ,&eof JCN
|
|
|
|
LDAk #0a EQU ,&eol JCN
|
|
|
|
,&x LDR2 ;term/cols LDA2
|
2022-03-04 01:47:11 -05:00
|
|
|
LTH2k ,&ok JCN
|
|
|
|
GTH2 ,&skip JCN
|
|
|
|
;emit-red-dollar JSR2 ,&x LDR2 INC2 ,&x STR2
|
2022-03-04 15:30:26 -05:00
|
|
|
&skip INC2
|
|
|
|
,&loop JMP
|
2022-03-04 01:47:11 -05:00
|
|
|
&ok POP2 POP2
|
2022-03-04 15:30:26 -05:00
|
|
|
LDAk #09 EQU ,&do-tab JCN
|
|
|
|
LDAk emit INC2 ,&x LDR2 INC2 ,&x STR2
|
|
|
|
,&loop JMP
|
|
|
|
&eol INC2r
|
|
|
|
STH2kr ;term/rows LDA2 GTH2 ,&done JCN
|
|
|
|
cr nl INC2 ,&bol JMP
|
|
|
|
&do-tab ;emit-tab JSR2 INC2
|
|
|
|
;config/tab-width LDA2 ,&x LDR2 ADD2 ,&x STR2
|
|
|
|
,&loop JMP
|
2022-03-04 01:47:11 -05:00
|
|
|
[ &x $2 ]
|
2022-02-13 14:46:50 -05:00
|
|
|
&eof
|
2022-03-04 01:47:11 -05:00
|
|
|
;emit-red JSR2
|
2022-02-13 14:46:50 -05:00
|
|
|
&eof-loop
|
2022-02-18 00:20:09 -05:00
|
|
|
STH2kr ;term/rows LDA2 GTH2 ,&done JCN
|
2022-02-13 14:46:50 -05:00
|
|
|
cr nl
|
2022-03-03 21:12:26 -05:00
|
|
|
;term/lmargin LDA2 ;term-move-right JSR2
|
2022-02-18 00:20:09 -05:00
|
|
|
LIT '~ emit INC2r
|
2022-02-13 14:46:50 -05:00
|
|
|
,&eof-loop JMP
|
2022-03-03 21:12:26 -05:00
|
|
|
&done POP2 POP2r POP2r
|
2022-03-04 01:47:11 -05:00
|
|
|
;emit-reset JSR2
|
2022-02-12 02:10:27 -05:00
|
|
|
;draw-statusbar JSR2
|
2022-02-06 17:07:11 -05:00
|
|
|
;draw-cursor JSR2
|
|
|
|
JMP2r
|
|
|
|
|
2022-02-11 15:39:49 -05:00
|
|
|
@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* -> )
|
2022-02-06 17:07:11 -05:00
|
|
|
&loop LDAk #00 EQU ,&eof JCN
|
|
|
|
LDAk #18 DEO INC2 ,&loop JMP
|
|
|
|
&eof POP2 JMP2r
|
|
|
|
|
|
|
|
@cur-len ( -> n* )
|
2022-03-07 12:56:52 -05:00
|
|
|
;cur-line JSR2 ;line-len JMP2
|
2022-02-06 17:07:11 -05:00
|
|
|
|
2022-02-14 16:47:36 -05:00
|
|
|
@cur-last ( -> n* )
|
2022-02-18 00:20:09 -05:00
|
|
|
;cur-line JSR2 ;line-len JSR2 #0001 SUB2 JMP2r
|
2022-02-14 16:47:36 -05:00
|
|
|
|
2022-03-03 21:12:26 -05:00
|
|
|
@cur-width ( -> n* )
|
2022-03-07 12:56:52 -05:00
|
|
|
;cur-line JSR2 ;line-width JMP2
|
2022-03-03 21:12:26 -05:00
|
|
|
|
|
|
|
@cur-w-last ( -> n* )
|
|
|
|
;cur-line JSR2 ;line-width JSR2 #0001 SUB2 JMP2r
|
|
|
|
|
2022-02-06 17:07:11 -05:00
|
|
|
@line-len ( s* -> n* )
|
|
|
|
#0000 STH2
|
|
|
|
&loop LDAk #00 EQU ,&end JCN
|
|
|
|
LDAk #0a EQU ,&end JCN
|
2022-03-03 21:12:26 -05:00
|
|
|
INC2 INC2r ,&loop JMP
|
2022-02-06 17:07:11 -05:00
|
|
|
&end POP2 STH2r JMP2r
|
|
|
|
|
2022-03-03 21:12:26 -05:00
|
|
|
@line-width ( s* -> n* )
|
|
|
|
#0000 STH2
|
|
|
|
&loop LDAk #00 EQU ,&done JCN
|
|
|
|
LDAk #0a EQU ,&done JCN
|
|
|
|
LDAk #09 EQU ,&tabs JCN
|
|
|
|
INC2 INC2r ,&loop JMP
|
|
|
|
&tabs #0004 ADD2 ,&loop JMP
|
|
|
|
&done POP2 STH2r JMP2r
|
|
|
|
|
2022-02-10 01:40:48 -05:00
|
|
|
@abs-line ( y* -> s* )
|
|
|
|
#0000 SWP2 SUB2 STH2 ( [-y] )
|
2022-02-12 02:25:41 -05:00
|
|
|
;buffer/data ( addr )
|
2022-02-10 01:40:48 -05:00
|
|
|
&newline ( addr [-y] )
|
|
|
|
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 INC2r ( addr+1 [-y+1] ) ,&newline JMP
|
|
|
|
&done POP2r JMP2r
|
|
|
|
¬-found POP2 POP2r #0000 JMP2r
|
|
|
|
|
2022-02-06 17:07:11 -05:00
|
|
|
( line number relative to the offset, starting at 0 )
|
2022-02-18 00:20:09 -05:00
|
|
|
@rel-line ( y* -> s* )
|
|
|
|
#0000 SWP2 SUB2 STH2 ( [-y] )
|
2022-02-06 17:07:11 -05:00
|
|
|
;buffer/offset LDA2 ( addr* )
|
2022-02-18 00:20:09 -05:00
|
|
|
STH2kr #0000 EQU2 ,&done JCN ( addr [-y] )
|
2022-02-06 17:07:11 -05:00
|
|
|
&newline ( addr [-y] )
|
2022-02-18 00:20:09 -05:00
|
|
|
STH2kr ORA ,&loop JCN ,&done JMP
|
2022-02-06 17:07:11 -05:00
|
|
|
&loop ( addr [-y] )
|
|
|
|
LDAk #00 EQU ,¬-found JCN ( addr [-y] )
|
|
|
|
LDAk #0a EQU ,&found JCN ( addr [-y] )
|
|
|
|
INC2 ,&loop JMP ( addr+1 [-y] )
|
2022-02-18 00:20:09 -05:00
|
|
|
&found INC2 INC2r ( addr+1 [-y+1] ) ,&newline JMP
|
|
|
|
&done POP2r JMP2r
|
2022-02-13 14:46:50 -05:00
|
|
|
¬-found ;rel-line-error ;error! JMP2
|
2022-02-06 17:07:11 -05:00
|
|
|
|
|
|
|
@cur-line ( -> s* )
|
2022-03-07 12:56:52 -05:00
|
|
|
;cur-rel-row JSR2 ;rel-line JMP2
|
2022-02-14 16:47:36 -05:00
|
|
|
|
2022-02-06 17:07:11 -05:00
|
|
|
@cur-pos ( -> s* )
|
2022-02-18 00:20:09 -05:00
|
|
|
;cur-line JSR2 ;cur-col JSR2 ADD2 JMP2r
|
2022-02-06 17:07:11 -05:00
|
|
|
|
2022-02-12 02:10:27 -05:00
|
|
|
@cur-abs-row ( -> n* )
|
2022-03-06 15:35:14 -05:00
|
|
|
;cur-rel-row JSR2 ;buffer/line-offset LDA2 ADD2 JMP2r
|
2022-02-12 02:10:27 -05:00
|
|
|
|
2022-02-13 14:46:50 -05:00
|
|
|
@last-abs-row ( -> n* )
|
|
|
|
;buffer/line-count LDA2 #0001 SUB2 JMP2r
|
|
|
|
|
2022-02-06 17:07:11 -05:00
|
|
|
@shift-right ( c^ addr* -> )
|
|
|
|
ROT STH ( addr [prev^] )
|
2022-02-14 16:47:36 -05:00
|
|
|
;last-pos JSR2 SWP2 ( last addr [prev^] )
|
2022-02-06 17:07:11 -05:00
|
|
|
&loop LTH2k ,&done JCN ( last addr [prev^] )
|
|
|
|
LDAk STH SWPr ( last addr [prev^ curr^] )
|
|
|
|
DUP2 STHr ( last addr addr prev^ [curr^] )
|
|
|
|
ROT ROT STA ( last addr [curr^] )
|
|
|
|
INC2 ,&loop JMP ( last addr+1 [curr^] )
|
|
|
|
&done NIP2 DUP2 ( addr addr [prev^] )
|
|
|
|
STHr ROT ROT ( addr prev^ addr )
|
|
|
|
STA INC2 ( addr+1 )
|
2022-03-03 21:12:26 -05:00
|
|
|
;buffer/limit STA2 ( )
|
2022-02-06 17:07:11 -05:00
|
|
|
JMP2r
|
|
|
|
|
2022-02-13 14:46:50 -05:00
|
|
|
( TODO: change last/addr order and GTH -> LTH to remove hack )
|
2022-02-06 17:07:11 -05:00
|
|
|
@shift-left ( addr* -> )
|
2022-02-14 16:47:36 -05:00
|
|
|
;last-pos JSR2 SWP2 ( last addr )
|
2022-02-13 14:46:50 -05:00
|
|
|
&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 )
|
|
|
|
STA ,&loop JMP ( last addr+1 )
|
|
|
|
&done POP2 ( last )
|
2022-03-03 21:12:26 -05:00
|
|
|
;buffer/limit STA2 ( )
|
2022-02-13 14:46:50 -05:00
|
|
|
#00 ;buffer/limit LDA2 STA ( ensure null termination )
|
2022-02-06 17:07:11 -05:00
|
|
|
JMP2r
|
|
|
|
|
2022-02-18 00:20:09 -05:00
|
|
|
@cur-col ( -> col* )
|
2022-03-07 12:56:52 -05:00
|
|
|
;cursor/col LDA2 ;cur-len JSR2 ;min2 JMP2
|
2022-02-07 22:25:32 -05:00
|
|
|
|
2022-03-03 21:12:26 -05:00
|
|
|
@cur-w-col ( -> col* )
|
|
|
|
LIT2r 0000 ( [0] )
|
|
|
|
;cur-line JSR2 DUP2 ;cur-col JSR2 ADD2 SWP2 ( lim s [0] )
|
|
|
|
&loop GTH2k ,&next JCN
|
|
|
|
POP2 POP2 STH2r JMP2r
|
|
|
|
&next LDAk #09 EQU ,&tabs JCN INC2 INC2r ,&loop JMP
|
|
|
|
&tabs INC2 ;config/tab-width LDA2 STH2 ADD2r ,&loop JMP
|
|
|
|
|
2022-03-06 15:35:14 -05:00
|
|
|
@cur-rel-row ( -> row* )
|
2022-02-18 00:20:09 -05:00
|
|
|
;cursor/row LDA2 JMP2r
|
2022-02-06 17:07:11 -05:00
|
|
|
|
2022-03-06 15:35:14 -05:00
|
|
|
@set-abs-row ( n* -> )
|
|
|
|
;buffer/line-offset LDA2 SUB2 ;cursor/row STA2 JMP2r
|
|
|
|
|
|
|
|
@set-rel-row ( n* -> )
|
|
|
|
;cursor/row STA2 JMP2r
|
|
|
|
|
|
|
|
@zero-row ( -> )
|
|
|
|
;buffer/data ;buffer/offset STA2
|
|
|
|
#0000 ;buffer/line-offset STA2
|
|
|
|
#0000 ;cursor/row STA2
|
|
|
|
JMP2r
|
|
|
|
|
|
|
|
@inc-row ( -> )
|
|
|
|
;cursor/row LDA2k INC2 SWP2 STA2 JMP2r
|
|
|
|
|
|
|
|
@dec-row ( -> )
|
|
|
|
;cursor/row LDA2k #0001 SUB2 SWP2 STA2
|
|
|
|
|
2022-02-18 00:20:09 -05:00
|
|
|
@last-pos ( -> addr* )
|
2022-02-07 22:25:32 -05:00
|
|
|
;buffer/limit LDA2 #0001 SUB2 JMP2r
|
|
|
|
|
2022-02-13 14:46:50 -05:00
|
|
|
@more-than-one-screen ( -> bool^ )
|
|
|
|
;buffer/line-count LDA2 ;term/rows LDA2 GTH2 JMP2r
|
|
|
|
|
|
|
|
@fits-in-one-screen ( -> bool^ )
|
|
|
|
;buffer/line-count LDA2 ;term/rows LDA2 INC2 LTH2 JMP2r
|
|
|
|
|
2022-02-07 22:25:32 -05:00
|
|
|
@mod-div ( x^ y^ -> x%d x/y )
|
2022-02-09 01:05:11 -05:00
|
|
|
DIVk STHk MUL SUB STHr JMP2r
|
|
|
|
|
|
|
|
@mod-div2 ( x^ y^ -> x%d x/y )
|
|
|
|
DIV2k STH2k MUL2 SUB2 STH2r JMP2r
|
2022-02-07 22:25:32 -05:00
|
|
|
|
2022-03-03 21:12:26 -05:00
|
|
|
@base-10-width ( n* -> w* )
|
|
|
|
LIT2r 0000 ( n [0] )
|
|
|
|
&loop ( n [w] )
|
|
|
|
DUP2 #0000 EQU2 ,&done JCN ( n [w] )
|
|
|
|
#000a DIV2 ( n/10 [w] )
|
|
|
|
INC2r ,&loop JMP ( n/10 [w+1] )
|
|
|
|
&done ( 0 [w] )
|
|
|
|
POP2 STH2r JMP2r
|
2022-02-11 15:39:49 -05:00
|
|
|
|
2022-02-07 22:25:32 -05:00
|
|
|
@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
|
2022-03-07 12:56:52 -05:00
|
|
|
&do1 ;emit-digit JMP2
|
2022-02-07 22:25:32 -05:00
|
|
|
|
2022-02-09 01:05:11 -05:00
|
|
|
@emit-dec2 ( n* -> )
|
|
|
|
DUP2 #270f GTH2 ,&do5 JCN
|
|
|
|
DUP2 #03e7 GTH2 ,&do4 JCN
|
|
|
|
DUP2 #0063 GTH2 ,&do3 JCN
|
|
|
|
DUP2 #0009 GTH2 ,&do2 JCN
|
|
|
|
,&do1 JMP
|
|
|
|
&do5 #2710 ;mod-div2 JSR2 NIP ;emit-digit JSR2
|
2022-02-11 15:39:49 -05:00
|
|
|
&do4 #03e8 ;mod-div2 JSR2 NIP ;emit-digit JSR2
|
2022-02-09 01:05:11 -05:00
|
|
|
&do3 #0064 ;mod-div2 JSR2 NIP ;emit-digit JSR2
|
|
|
|
&do2 #000a ;mod-div2 JSR2 NIP ;emit-digit JSR2
|
2022-03-07 12:56:52 -05:00
|
|
|
&do1 NIP ;emit-digit JMP2
|
2022-02-09 01:05:11 -05:00
|
|
|
|
2022-03-03 21:12:26 -05:00
|
|
|
@emit-dec2-pad ( n* -> )
|
|
|
|
LIT2r 2018 ( preload #20 .Console/write into rst )
|
|
|
|
DUP2 #270f GTH2 ,&do5 JCN DEOkr
|
|
|
|
DUP2 #03e7 GTH2 ,&do4 JCN DEOkr
|
|
|
|
DUP2 #0063 GTH2 ,&do3 JCN DEOkr
|
|
|
|
DUP2 #0009 GTH2 ,&do2 JCN DEOkr
|
|
|
|
,&do1 JMP
|
|
|
|
&do5 #2710 ;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
|
|
|
|
DEOr JMP2r
|
|
|
|
|
2022-02-11 15:39:49 -05:00
|
|
|
@messages [ &input-error "input 20 "error 00
|
2022-02-12 02:10:27 -05:00
|
|
|
&bytes 20 "bytes, 00
|
2022-02-15 21:19:44 -05:00
|
|
|
&save-ok "saved 00
|
|
|
|
&save-failed "failed 00
|
2022-02-12 02:10:27 -05:00
|
|
|
&lines 20 "lines] 00
|
2022-02-11 19:15:40 -05:00
|
|
|
&saved "-- 20 00
|
|
|
|
&unsaved "** 20 00 ]
|
2022-02-08 22:22:08 -05:00
|
|
|
|
2022-02-10 01:40:48 -05:00
|
|
|
@tmp [ &pos :tmp/data
|
|
|
|
&data $100 ]
|
|
|
|
|
|
|
|
@term [ &cols 0050
|
2022-03-03 21:12:26 -05:00
|
|
|
&rows 0018
|
|
|
|
&lmargin 0006 ]
|
|
|
|
|
2022-03-07 12:56:52 -05:00
|
|
|
@prompt [ &vector $2
|
|
|
|
&string $40 ]
|
|
|
|
|
2022-03-03 21:12:26 -05:00
|
|
|
( COLORS )
|
|
|
|
( )
|
|
|
|
( SHORT STRING NAME )
|
|
|
|
( 3033 "30" black )
|
|
|
|
( 3133 "31" red )
|
|
|
|
( 3233 "32" green )
|
|
|
|
( 3333 "33" yellow )
|
|
|
|
( 3433 "34" blue )
|
|
|
|
( 3533 "35" magenta )
|
|
|
|
( 3633 "36" cyan )
|
|
|
|
( 3733 "37" white )
|
|
|
|
( 3030 "00" default )
|
|
|
|
( )
|
|
|
|
( digits are reversed )
|
|
|
|
( to emit from stack in )
|
|
|
|
( last-in-first-out order )
|
|
|
|
@config [ &tab-width 0004
|
|
|
|
&insert-tabs 01
|
|
|
|
&color 3333 ]
|
2022-02-10 01:40:48 -05:00
|
|
|
|
2022-02-18 00:20:09 -05:00
|
|
|
( relative cursor positions, e.g. 0 to cols-1 )
|
|
|
|
@cursor [ &col 0000 &row 0000 ]
|
2022-02-08 22:22:08 -05:00
|
|
|
|
|
|
|
( did we just see ESC? )
|
|
|
|
@saw-esc 00
|
|
|
|
|
2022-03-03 21:12:26 -05:00
|
|
|
( )
|
2022-02-11 15:39:49 -05:00
|
|
|
@filename $80
|
|
|
|
|
2022-02-09 02:35:46 -05:00
|
|
|
( |1ffc )
|
2022-02-06 17:07:11 -05:00
|
|
|
( offset is address of the first visible line )
|
|
|
|
( size is total size of data in bytes )
|
2022-02-10 01:40:48 -05:00
|
|
|
@buffer [ &limit 0000
|
|
|
|
&offset :buffer/data
|
|
|
|
&line-count 0000
|
2022-02-11 15:39:49 -05:00
|
|
|
&line-offset 0000
|
2022-03-03 21:12:26 -05:00
|
|
|
&data $f000 ]
|