( RetroForth Core Block Editor )
( --------------------------------------------------------- )
( This version uses traditional 1k blocks as opposed to the )
( 512 byte blocks used in earlier releases. The native      ) 
( version will eventually use this format as well. )

0 variable lastBlock
pad 1024 + constant blockBase
: block 1024 * blockBase + ;
: select dup lastBlock ! ;

: vl 32 emit 32 emit dup 64 type cr 64 + ;
: dashes '- emit 1 - >r r@ 0 = if ;; then r> dashes ;
: ed.hline '( emit 32 emit 64 dashes 32 emit ') emit cr ;

: view clear
       ed.hline
       lastBlock @ block
       vl vl vl vl vl vl vl vl vl vl vl vl vl vl vl vl 
       ed.hline lastBlock @ . cr
;
: edit 64 * lastBlock @ block + s drop drop view ;
: delete 64 * lastBlock @ block + 61 0 fill view ;

( --------------------------------------------------------- )
( Wrapper function[s] )
( --------------------------------------------------------- )
( The goal is to make the editor friendlier by using )
( keystrokes like 'e' for edit line and 'q' for quit )
( It's not done yet :-> )
( --------------------------------------------------------- )
: ?edit 'e = if 0 edit then dup ;
: ?delete 'd if 0 delete then dup ;
: editor view key dup 
  ?edit ?delete 'q = if ;; then editor ;
( --------------------------------------------------------- )