\ editor.fth -- the block editor, in FORTH. \ \ This file is FORTH source: the node compiles it itself, a line at a time, \ as if it were typed. No line is longer than 79 characters. \ \ A block is a screen of 16 lines of 64 characters. SCR is the screen being \ edited. The editor is a vocabulary, EDITOR: its words are ordinary FORTH \ words used at the ordinary prompt, so everything else is there as well. \ \ n EDIT edit screen n: list it and make EDITOR the CONTEXT vocabulary \ L list the screen N B the next, the one before \ n T type line n \ n P text put the rest of the input line on line n \ n E erase line n WIPE blank the whole screen \ n D delete line n; the lines below move up; it is held in PAD \ n S spread: a blank line at n; the lines from n move down \ n H hold line n in PAD n R replace line n from PAD \ n I insert PAD's line at n \ DONE write what has changed and go back to FORTH \ a b COPY copy screen a to screen b (in FORTH) \ \ Every change is UPDATEd; nothing reaches storage until FLUSH or DONE, or \ until the buffer is wanted for another block. FORTH DEFINITIONS \ ( baddr -- ) 64 characters; a zero shows as a blank, others as a dot : (.LINE) 64 0 DO DUP I + C@ DUP 0= IF DROP 32 THEN DUP 32 < OVER 126 > OR IF DROP 46 THEN EMIT LOOP DROP ; \ ( n -- baddr ) where line n of screen SCR is : (LINE) DUP 0< OVER 15 > OR ABORT" Line out of range" 64 * SCR @ BLOCK + ; \ v3's three: a line shown, a line set from a string, the screen shown : L ( n -- ) (LINE) (.LINE) CR ; : S ( baddr u n -- ) (LINE) DUP 64 BLANK SWAP 0 MAX 64 MIN CMOVE UPDATE ; : SHOW ( -- ) ." Screen " SCR @ 0 .R ." :" CR 16 0 DO I 2 .R ." : " I (LINE) (.LINE) CR LOOP ; : COPY ( from to -- ) SWAP BLOCK SWAP BUFFER 1024 CMOVE UPDATE ; VOCABULARY EDITOR EDITOR DEFINITIONS : T ( n -- ) DUP (LINE) SWAP 2 .R ." : " (.LINE) CR ; : L ( -- ) SHOW ; : E ( n -- ) (LINE) 64 BLANK UPDATE ; : P ( n -- ) (LINE) DUP 64 BLANK 0 WORD COUNT 64 MIN ROT SWAP CMOVE UPDATE ; : H ( n -- ) (LINE) PAD 64 CMOVE ; : R ( n -- ) PAD SWAP (LINE) 64 CMOVE UPDATE ; : D ( n -- ) DUP H DUP 15 < IF DUP 1+ (LINE) OVER (LINE) ROT 15 SWAP - 64 * CMOVE ELSE DROP THEN 15 E ; : S ( n -- ) DUP 15 < IF DUP (LINE) OVER 1+ (LINE) 3 PICK 15 SWAP - 64 * CMOVE> THEN E ; : I ( n -- ) DUP S R ; : WIPE ( -- ) SCR @ BLOCK 1024 BLANK UPDATE ; : N ( -- ) 1 SCR +! L ; : B ( -- ) -1 SCR +! L ; : DONE ( -- ) FLUSH [COMPILE] FORTH ; FORTH DEFINITIONS : EDIT ( n -- ) DUP BLOCK DROP SCR ! EDITOR [ EDITOR ] L [ FORTH ] ;