One feature of VICE I have used in moderation is the ability to paste text into the simulator. Fleet Forth behaves as though the text is typed in. This does introduce a problem. When loading source from screens on blocks or even from a Commodore sequential file, an ABORT stops the load and returns control to Forth's QUIT loop. When text is pasted into the simulator the QUIT loop still has control. an ABORT stops interpreting text which has already been EXPECTed, or ACCEPTed; however, the simulator continues to fill the keyboard buffer until all pasted text has been inserted into the keyboard buffer. The behavior is exactly as if a programmer typing in source ignores errors and continues typing.
Fleet Forth's ABORT , which is called by ABORT" , is extensible.
Code: Select all
: ABORT ( -- )
SINGLE ERR SP! AP! QUIT -;
SINGLE switches off multitasking.
SP! and AP! clear the data and auxiliary stacks.
ERR is a deferred word which normally executes NOOP a Forth no-op.
I set ERR to the word PURGE when I wish to paste Forth source from a Linux text file.
Code: Select all
: PURGE // EMPTY KEYBOARD
BEGIN // BUFFER
BEGIN
KEY? // ANY KEYSTROKES?
WHILE
KEY DROP
REPEAT
1 JIFFIES // WAIT 1/60 SEC
KEY? 0= // BUFFER EMPTY?
UNTIL ;
KEY? is an AnsiForth word which returns TRUE if a character is available.
The 1 jiffy delay is to give VICE time to refill the keyboard buffer. The inner loop empties the keyboard buffer fast enough that without the delay, PURGE returns before VICE is finished adding pasted text to the buffer.