diff --git a/blk/062 b/blk/062 index 6689076..64dcb0d 100644 --- a/blk/062 +++ b/blk/062 @@ -1,5 +1,7 @@ WORD -- a Read one word from buffered input and push its - addr. + addr. Always null terminated. If ASCII EOT is + encountered, a will point to it (it is cons- + idered a word). There are also ascii const emitters: BS CR LF SPC CRLF NL is an indirect word (see B80) that aliases to CRLF by diff --git a/blk/405 b/blk/405 index 9c19033..33eb3ba 100644 --- a/blk/405 +++ b/blk/405 @@ -1,3 +1,7 @@ : WS? 33 < ; +: EOT? 4 = ; ( 4 == ASCII EOT, CTRL+D ) -: TOWORD 0 ( dummy ) BEGIN DROP C< DUP WS? NOT UNTIL ; +: TOWORD + 0 ( dummy ) BEGIN + DROP C< DUP WS? NOT OVER EOT? OR + UNTIL ; diff --git a/blk/406 b/blk/406 index be9cd1f..39b5ee7 100644 --- a/blk/406 +++ b/blk/406 @@ -1,16 +1,13 @@ ( Read word from C<, copy to WORDBUF, null-terminate, and return WORDBUF. ) : WORD - 0x0e RAM+ ( 0e == WORDBUF ) - TOWORD ( a c ) + 0x0e RAM+ TOWORD ( a c ) + DUP EOT? IF OVER ! EXIT THEN BEGIN ( We take advantage of the fact that char MSB is always zero to pre-write our null-termination ) - OVER ! 1+ ( a+1 ) - C< ( a c ) + OVER ! 1+ C< ( a c ) OVER 0x2d ( 2e-1 for NULL ) RAM+ = OVER WS? OR - UNTIL - ( a this point, PS is: a WS ) - ( null-termination is already written ) - 2DROP - 0x0e RAM+ ; + UNTIL ( a c ) + SWAP DROP 0x0e RAM+ ( ws a ) + SWAP EOT? IF 4 OVER ! THEN ; diff --git a/blk/409 b/blk/409 index 36a5086..d2e3917 100644 --- a/blk/409 +++ b/blk/409 @@ -1,6 +1,6 @@ : INTERPRET BEGIN - WORD + WORD DUP C@ EOT? IF DROP EXIT THEN (find) NOT IF (parse) ELSE EXECUTE THEN C point to it ) : (rdln) - (infl) BEGIN (rdlnc) NOT UNTIL + ( EOT or less triggers line flush ) + (infl) BEGIN (rdlnc) 5 < UNTIL LF IN( IN> ! ; - ( And finally, implement C<* ) : RDLN< IN> @ C@ diff --git a/emul/forth.bin b/emul/forth.bin index c26b75c..86dfe1e 100644 Binary files a/emul/forth.bin and b/emul/forth.bin differ diff --git a/emul/forth.c b/emul/forth.c index f73f00a..0dda057 100644 --- a/emul/forth.c +++ b/emul/forth.c @@ -17,7 +17,6 @@ #define BLK_PORT 0x03 #define BLKDATA_PORT 0x04 -static int running; static FILE *fp; static FILE *blkfp; static int retcode = 0; @@ -27,18 +26,14 @@ static uint8_t iord_stdio() { int c = getc(fp); if (c == EOF) { - running = 0; + c = 4; // ASCII EOT } return (uint8_t)c; } static void iowr_stdio(uint8_t val) { - if (val == 0x04) { // CTRL+D - running = 0; - } else { - putchar(val); - } + putchar(val); } static void iowr_ret(uint8_t val) @@ -123,9 +118,7 @@ int main(int argc, char *argv[]) } // Run! - running = 1; - - while (running && emul_step()); + while (emul_step()); if (tty) { printf("\nDone!\n");