The following four screens contain corrected source for the operators GETDATA PUTDATA and PUTTEXT. The original uncorrected versions are in the DDJ Forth column, Feb 1988.
Screen 5 defines GETDATA using
BEGIN ... DUP IF DROP ... THEN WHILE ... REPEAT
instead of the preferred
BEGIN ... WHILE ... WHILE ... REPEAT THEN
SCR# 1
\ Read BLOCKed file as data file
: GETDATA ( a n - n2)
\ reads n bytes of data from input file into address, n < 64K
\ Returns n2 bytes not read ( ie beyond end of file ).
( calculate # of bytes to move < 64K : ) POSITION 2@
BEGIN 2 PICK ( n ) DUP
IF ( n ) >R 2DUP 1K UM/MOD SWAP DROP 1+ 1K UM*
CAPACITY 2@ DMIN 2OVER D- 0= NOT OR R> UMIN
THEN ?DUP
WHILE >R 2DUP 1K UM/MOD BLOCK + 4 PICK R@ CMOVE
R@ 0 D+ 2SWAP R> /STRING 2SWAP
REPEAT POSITION 2! SWAP DROP ;
SCR# 2
\ Write BLOCKed file as data file
: PUTDATA ( a n)
\ writes n bytes of data to output file from address, n < 64K
( extend the file as needed : )
DUP 0 POSITION 2@ D+ CAPACITY 2@ 2OVER D- DUP 0<
IF 2DUP DABS EXTEND 2OVER CAPACITY 2! THEN 2DROP 2DROP
( calculate # of bytes to move < 64K : ) POSITION 2@