Yes, the idea is to use the address returned by
BLOCK before the next task switch. This is why, when loading a block, each time
WORD is called it causes a call to
BLOCK through
'STREAM . This is also why the buffer table is arranged from most recently used to least recently used and
BLOCK starts out as a code definition.
Code:
HEX
CODE BLOCK ( BLK -- ADR )
DEY,
// CFA OF BUFFER POINTS HERE
' T/F >BODY STY, // SET T/F
' T/F >BODY 1+ STY, //
' MRU >BODY LDA, N STA,
' MRU >BODY 1+ LDA, N 1+ STA,
6 # LDY, N )Y LDA, 0 ,X CMP,
0= IF,
INY, N )Y LDA, 1 ,X CMP,
0= IF,
INY, N )Y LDA, 0 ,X STA,
INY, N )Y LDA, 1 ,X STA,
NEXT JMP,
THEN,
THEN,
>FORTH
Fleet Forth is an ITC Forth.
BUFFER has no body, its
CFA points one byte into the body of
BLOCK ( after the
DEY instruction.)
T/F is a
VALUE which determines if a read is performed later in the high level part of
BLOCK/BUFFER .
BLOCK sets it to
TRUE and
BUFFER sets it to
FALSE . If the requested block is the most recently used then
BLOCK just has to replace the block number on the stack with the buffer address in the table and jump to
NEXT . If the requested block is
not the most recently used,
BLOCK transitions to high level to handle it. This is to make
BLOCK as fast as possible while still sharing code with
BUFFER ( by setting
T/F ) to mitigate the speed penalty of having to call
BLOCK each time the same block needs accessed.
[Edit: One correction. Originally I typed BUFFER when I meant BLOCK.]