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 -- c Set c to byte at address a
C@+ a -- a+1 c Fetch c from a and inc 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 -- 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 Set a to wordref of last added entry.
CURRENT* -- a A pointer to active CURRENT*. Useful CURRENT* -- a A pointer to active CURRENT*. Useful
when we have multiple active dicts. when we have multiple active dicts.

11
blk/104
View File

@ -1,5 +1,6 @@
( Cursor position in buffer. EDPOS/64 is line number ) ( Cursor position in buffer. EDPOS/64 is line number )
VARIABLE EDPOS VARIABLE EDPOS
CREATE EDBUF 64 ALLOT
: _cpos BLK( + ; : _cpos BLK( + ;
: _lpos 64 * _cpos ; : _lpos 64 * _cpos ;
: _pln ( lineno -- ) : _pln ( lineno -- )
@ -7,7 +8,9 @@ VARIABLE EDPOS
I EDPOS @ _cpos = IF '^' EMIT THEN I EDPOS @ _cpos = IF '^' EMIT THEN
I C@ DUP 0x20 < IF DROP 0x20 THEN I C@ DUP 0x20 < IF DROP 0x20 THEN
EMIT EMIT
LOOP ( lno ) LOOP ( lno ) 1+ . ;
1+ . ; : _zbuf EDBUF 64 0 FILL ;
( user-facing lines are 1-based ) : _type ( -- )
: T 1- DUP 64 * EDPOS ! _pln ; 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 ( user-facing lines are 1-based )
EDPOS @ _cpos C< : T 1- DUP 64 * EDPOS ! _pln ;
64 0 DO ( bpos c ) : P _type EDBUF EDPOS @ _cpos 64 MOVE BLK!! ;
DUP 0xd = IF DROP 0 THEN
2DUP SWAP I + C!
DUP IF DROP C< THEN
LOOP
2DROP
BLK!!
;
: _mvln+ ( ln -- move ln 1 line further ) : _mvln+ ( ln -- move ln 1 line further )
DUP 14 > IF DROP EXIT THEN DUP 14 > IF DROP EXIT THEN
_lpos DUP 64 + 64 MOVE _lpos DUP 64 + 64 MOVE
; ;

View File

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

View File

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

Binary file not shown.