I think you'd want at least 2 buffers, simply to facilitate copying BLOCKs easily. You can always do it with external memory (i.e. memory managed by the application, rather than the system), but I think having at least 2 would be worthwhile.
With 2 buffers available, to copy a block you'd do something like:
Code:
: COPY-BLOCK ( from-block to-block )
BUFFER \ Get the buffer for to-block
UPDATE \ Mark it as dirty
SWAP BLOCK \ load from-block
SWAP 1024 MOVE ; \ Copy data, data will be save when the buffer is flushed
With 1 buffer, that won't work.
You know what? This is really ambiguous.
The reason this is ambiguous, as written, is that it's possible for the system, to flush the updated buffer when BLOCK is called, and thus the buffer will not be marked as dirty after the copy.
This is better:
Code:
: COPY-BLOCK ( from-block to-block )
SWAP BLOCK \ Read in the source block
SWAP BUFFER \ designate the buffer
UPDATE \ mark it as dirty
1024 MOVE ; \ copy the data, data is saved when the buffer is flushed
This is more straightforward, and, interestingly, if you have a single buffer, this just may work. I don't know how MOVE is defined when the source and destination addressed are the same (it should just NOP).
You also need to make sure that BLOCK and BUFFER aren't aliased. Some systems have BUFFER simply call BLOCK.
The stock FIG Forth has 8 buffers, but they're only 128 bytes each.
As for the invalidation, I honestly don't know why terminal I/O should invalidate a buffer, unless there's some underlying redirection mechanism going on that could direct EMIT to a buffer. But, as I understand it, the only place that really happens is when the compiler is switched up between using the terminal buffer for input vs a block for input, and that's only for reading.
Ah, here it is:
Quote:
While the standard does not address multitasking per se, the items listed in 7.3.2 Block buffer regions that may render block-buffer addresses invalid are due to multitasking considerations.
The basic point is not that these words can corrupt a buffer, but rather these words are notable for allowing task switching (which can do anything).
So, that makes sense.
Anyway, I think you need "more than one" buffer, the system kind of breaks down if you don't have at least 2.
Playing 8 puzzle with one square isn't fun.