
compiletoflash

\ -----------------------------------------------
\  Loader for Mecrisp - a wish of Glen Worstell
\ -----------------------------------------------

\ Hard-wired constants, depending on particular memory map

120  constant tib-maxlength
$27A constant tib-wholelength
$27B constant tib

: addchartotib ( c -- )
  tib c@ tib-maxlength u>=
  if
    ." Line too long" cr
    drop \ If buffer full, drop character.
  else
    tib c@ 1+ tib c! \ One more character
    tib c@ tib + c! \ Put character into buffer
  then
;

: silentquery ( -- )
  -1 tib-wholelength c!  \ Denotes a fresh filling
   0 tib c!              \ Zero characters

  begin
    key  \ No need handle backspace while loading
    dup 9 = if drop 32 then \ Translate Tab into Space
    dup 27 = if ." Finished loading" cr quit then \ Stop when ESC is pressed
    dup 32 u>= if dup addchartotib then \ No echo necessary while loading
  dup 10 = swap 13 = or \ Finish on LF or CR
  until

;

\ Leave this with quit or by pressing ESC.
: load ( -- ) begin silentquery ." *" interpret again ;

compiletoram

\ Just to try silentquery:
: sq ( -- ) 
  silentquery 
  tib ."  >" type ." <" 

  \ Clear TIB afterwards so that it isn't interpreted.
  -1 tib-wholelength c!  \ Denotes a fresh filling
   0 tib c!              \ Zero characters
;
