editor: add edit buffer

Also, add word "C!+" and fix PSP leak in FILL.
This commit is contained in:
Virgil Dupras 2020-05-01 13:17:40 -04:00
parent 792c781614
commit 5bf3baff05
6 changed files with 14 additions and 19 deletions

View File

@ -7,6 +7,7 @@ Memory
C@ a -- c Set c to byte at address a
C@+ a -- a+1 c Fetch c from a and inc a.
C! c a -- Store byte c in address a
C!+ c a -- a+1 Store byte c in a and inc a.
CURRENT -- a Set a to wordref of last added entry.
CURRENT* -- a A pointer to active CURRENT*. Useful
when we have multiple active dicts.

11
blk/104
View File

@ -1,5 +1,6 @@
( Cursor position in buffer. EDPOS/64 is line number )
VARIABLE EDPOS
CREATE EDBUF 64 ALLOT
: _cpos BLK( + ;
: _lpos 64 * _cpos ;
: _pln ( lineno -- )
@ -7,7 +8,9 @@ VARIABLE EDPOS
I EDPOS @ _cpos = IF '^' EMIT THEN
I C@ DUP 0x20 < IF DROP 0x20 THEN
EMIT
LOOP ( lno )
1+ . ;
( user-facing lines are 1-based )
: T 1- DUP 64 * EDPOS ! _pln ;
LOOP ( lno ) 1+ . ;
: _zbuf EDBUF 64 0 FILL ;
: _type ( -- )
C< DUP 0xd = IF DROP EXIT THEN _zbuf EDBUF BEGIN ( c a )
C!+ C< SWAP OVER 0x0d = UNTIL ( c a )
2DROP ;

15
blk/105
View File

@ -1,16 +1,7 @@
: P
EDPOS @ _cpos C<
64 0 DO ( bpos c )
DUP 0xd = IF DROP 0 THEN
2DUP SWAP I + C!
DUP IF DROP C< THEN
LOOP
2DROP
BLK!!
;
( user-facing lines are 1-based )
: T 1- DUP 64 * EDPOS ! _pln ;
: P _type EDBUF EDPOS @ _cpos 64 MOVE BLK!! ;
: _mvln+ ( ln -- move ln 1 line further )
DUP 14 > IF DROP EXIT THEN
_lpos DUP 64 + 64 MOVE
;

View File

@ -1,6 +1,4 @@
: FILL ( a n b -- )
SWAP 2 PICK + ( a b a+n ) ROT ( b a+n a ) DO ( b )
DUP I C!
LOOP
;
LOOP DROP ;

View File

@ -10,3 +10,5 @@
( a -- a+1 c )
: C@+ DUP C@ SWAP 1+ SWAP ;
( c a -- a+1 )
: C!+ SWAP OVER C! 1+ ;

Binary file not shown.