Make INTERPRET break on ASCII EOT
This should allow me to simplify LOAD's exit mechanism on block end.
This commit is contained in:
parent
052d59a3a2
commit
2e9e7047bf
4
blk/062
4
blk/062
@ -1,5 +1,7 @@
|
|||||||
WORD -- a Read one word from buffered input and push its
|
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:
|
There are also ascii const emitters:
|
||||||
BS CR LF SPC CRLF
|
BS CR LF SPC CRLF
|
||||||
NL is an indirect word (see B80) that aliases to CRLF by
|
NL is an indirect word (see B80) that aliases to CRLF by
|
||||||
|
6
blk/405
6
blk/405
@ -1,3 +1,7 @@
|
|||||||
: WS? 33 < ;
|
: 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 ;
|
||||||
|
15
blk/406
15
blk/406
@ -1,16 +1,13 @@
|
|||||||
( Read word from C<, copy to WORDBUF, null-terminate, and
|
( Read word from C<, copy to WORDBUF, null-terminate, and
|
||||||
return WORDBUF. )
|
return WORDBUF. )
|
||||||
: WORD
|
: WORD
|
||||||
0x0e RAM+ ( 0e == WORDBUF )
|
0x0e RAM+ TOWORD ( a c )
|
||||||
TOWORD ( a c )
|
DUP EOT? IF OVER ! EXIT THEN
|
||||||
BEGIN
|
BEGIN
|
||||||
( We take advantage of the fact that char MSB is
|
( We take advantage of the fact that char MSB is
|
||||||
always zero to pre-write our null-termination )
|
always zero to pre-write our null-termination )
|
||||||
OVER ! 1+ ( a+1 )
|
OVER ! 1+ C< ( a c )
|
||||||
C< ( a c )
|
|
||||||
OVER 0x2d ( 2e-1 for NULL ) RAM+ = OVER WS? OR
|
OVER 0x2d ( 2e-1 for NULL ) RAM+ = OVER WS? OR
|
||||||
UNTIL
|
UNTIL ( a c )
|
||||||
( a this point, PS is: a WS )
|
SWAP DROP 0x0e RAM+ ( ws a )
|
||||||
( null-termination is already written )
|
SWAP EOT? IF 4 OVER ! THEN ;
|
||||||
2DROP
|
|
||||||
0x0e RAM+ ;
|
|
||||||
|
2
blk/409
2
blk/409
@ -1,6 +1,6 @@
|
|||||||
: INTERPRET
|
: INTERPRET
|
||||||
BEGIN
|
BEGIN
|
||||||
WORD
|
WORD DUP C@ EOT? IF DROP EXIT THEN
|
||||||
(find)
|
(find)
|
||||||
NOT IF (parse) ELSE EXECUTE THEN
|
NOT IF (parse) ELSE EXECUTE THEN
|
||||||
C<? NOT IF LIT< (ok) (find) IF EXECUTE THEN THEN
|
C<? NOT IF LIT< (ok) (find) IF EXECUTE THEN THEN
|
||||||
|
3
blk/411
3
blk/411
@ -9,6 +9,5 @@
|
|||||||
['] (boot<) 0x0c RAM+ !
|
['] (boot<) 0x0c RAM+ !
|
||||||
( boot< always has a char waiting. 06 == C<?* )
|
( boot< always has a char waiting. 06 == C<?* )
|
||||||
1 0x06 RAM+ !
|
1 0x06 RAM+ !
|
||||||
INTERPRET
|
INTERPRET BYE ;
|
||||||
;
|
|
||||||
|
|
||||||
|
4
blk/429
4
blk/429
@ -1,8 +1,8 @@
|
|||||||
( Read one line in input buffer and make IN> point to it )
|
( Read one line in input buffer and make IN> point to it )
|
||||||
: (rdln)
|
: (rdln)
|
||||||
(infl) BEGIN (rdlnc) NOT UNTIL
|
( EOT or less triggers line flush )
|
||||||
|
(infl) BEGIN (rdlnc) 5 < UNTIL
|
||||||
LF IN( IN> ! ;
|
LF IN( IN> ! ;
|
||||||
|
|
||||||
( And finally, implement C<* )
|
( And finally, implement C<* )
|
||||||
: RDLN<
|
: RDLN<
|
||||||
IN> @ C@
|
IN> @ C@
|
||||||
|
BIN
emul/forth.bin
BIN
emul/forth.bin
Binary file not shown.
11
emul/forth.c
11
emul/forth.c
@ -17,7 +17,6 @@
|
|||||||
#define BLK_PORT 0x03
|
#define BLK_PORT 0x03
|
||||||
#define BLKDATA_PORT 0x04
|
#define BLKDATA_PORT 0x04
|
||||||
|
|
||||||
static int running;
|
|
||||||
static FILE *fp;
|
static FILE *fp;
|
||||||
static FILE *blkfp;
|
static FILE *blkfp;
|
||||||
static int retcode = 0;
|
static int retcode = 0;
|
||||||
@ -27,19 +26,15 @@ static uint8_t iord_stdio()
|
|||||||
{
|
{
|
||||||
int c = getc(fp);
|
int c = getc(fp);
|
||||||
if (c == EOF) {
|
if (c == EOF) {
|
||||||
running = 0;
|
c = 4; // ASCII EOT
|
||||||
}
|
}
|
||||||
return (uint8_t)c;
|
return (uint8_t)c;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void iowr_stdio(uint8_t val)
|
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)
|
static void iowr_ret(uint8_t val)
|
||||||
{
|
{
|
||||||
@ -123,9 +118,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run!
|
// Run!
|
||||||
running = 1;
|
while (emul_step());
|
||||||
|
|
||||||
while (running && emul_step());
|
|
||||||
|
|
||||||
if (tty) {
|
if (tty) {
|
||||||
printf("\nDone!\n");
|
printf("\nDone!\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user