Compare commits

...

4 Commits

Author SHA1 Message Date
Virgil Dupras
80d730318a Simplify LOAD's INTERPRET exit mechanism 2020-05-13 22:55:52 -04:00
Virgil Dupras
2e9e7047bf Make INTERPRET break on ASCII EOT
This should allow me to simplify LOAD's exit mechanism on block
end.
2020-05-13 21:44:46 -04:00
Virgil Dupras
052d59a3a2 TOWORD: tiny optimization
My mind is getting forthy.
2020-05-13 20:59:00 -04:00
Virgil Dupras
33d37d4ce9 WORD: don't overwrite RAM on words over 31 chars
This allows me to reclaim some RAM I hadn't even noticed I
needlessly monopolise.
2020-05-13 20:39:53 -04:00
12 changed files with 25 additions and 59 deletions

View File

@ -2,4 +2,3 @@ INTERPRET -- Get a line from stdin, compile it in tmp memory,
then execute the compiled contents.
LEAVE -- In a DO..LOOP, exit at the next LOOP call.
QUIT -- Return to interpreter prompt immediately
EXIT! -- Exit current INTERPRET loop.

View File

@ -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

View File

@ -7,6 +7,7 @@ RAMSTART FUTURE USES +55 (key) override
+0c C<* +70 DRIVERS
+0e WORDBUF +80 RAMEND
+2e BOOT C< PTR
+30 FUTURE USES
+4e INTJUMP
+51 CURRENTPTR
+53 (emit) override

15
blk/405
View File

@ -1,12 +1,7 @@
( The NOT is to normalize the negative/positive numbers to 1
or 0. Hadn't we wanted to normalize, we'd have written:
32 CMP 1 - )
: WS? 33 CMP 1+ NOT ;
: WS? 33 < ;
: EOT? 4 = ; ( 4 == ASCII EOT, CTRL+D )
: TOWORD
BEGIN
C< DUP WS? NOT IF EXIT THEN DROP
AGAIN
;
0 ( dummy ) BEGIN
DROP C< DUP WS? NOT OVER EOT? OR
UNTIL ;

19
blk/406
View File

@ -1,16 +1,13 @@
( Read word from C<, copy to WORDBUF, null-terminate, and
return, make HL point to WORDBUF. )
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 )
DUP WS?
UNTIL
( a this point, PS is: a WS )
( null-termination is already written )
2DROP
0x0e RAM+ ;
OVER ! 1+ C< ( a c )
OVER 0x2d ( 2e-1 for NULL ) RAM+ = OVER WS? OR
UNTIL ( a c )
SWAP DROP 0x0e RAM+ ( ws a )
SWAP EOT? IF 4 OVER ! THEN ;

11
blk/409
View File

@ -1,16 +1,7 @@
: INTERPRET
BEGIN
WORD
WORD DUP C@ EOT? IF DROP EXIT THEN
(find)
NOT IF (parse) ELSE EXECUTE THEN
C<? NOT IF LIT< (ok) (find) IF EXECUTE THEN THEN
AGAIN ;
( Drop RSP until I-2 == INTERPRET. )
: EXIT!
['] INTERPRET ( I )
BEGIN ( I )
DUP ( I I )
R> DROP I 2- @ ( I I a )
= UNTIL
DROP ;

View File

@ -9,6 +9,5 @@
['] (boot<) 0x0c RAM+ !
( boot< always has a char waiting. 06 == C<?* )
1 0x06 RAM+ !
INTERPRET
;
INTERPRET BYE ;

View File

@ -1,8 +1,8 @@
( Read one line in input buffer and make IN> 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@

11
blk/432
View File

@ -1,14 +1,3 @@
: _
(boot<)
DUP 4 = IF
( We drop our char, but also "a" from WORD: it won't
have the opportunity to balance PSP because we're
EXIT!ing. )
2DROP
( We're finished interpreting )
EXIT!
THEN
;
( pre-comment for tight LOAD: The 0x08==I check after INTERPRET
is to check whether we're restoring to "_", the word above.
if yes, then we're in a nested load. Also, the 1 in 0x06 is

View File

@ -5,7 +5,7 @@
0x2e RAM+ @ >R ( boot ptr )
BLK@
BLK( 0x2e RAM+ ! ( Point to beginning of BLK )
['] _ 0x08 RAM+ !
['] (boot<) 0x08 RAM+ !
1 0x06 RAM+ ! ( 06 == C<? )
INTERPRET
R> 0x2e RAM+ ! R> 0x06 RAM+ !

Binary file not shown.

View File

@ -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");