1
0
mirror of https://github.com/hsoft/collapseos.git synced 2025-03-31 09:48:48 +11:00

Replace the "> " prompt with the more traditional "ok" one

This is more than cosmetic, it's also highly usable. The presence
or absence of the "ok" message allows us to know whether the command
aborted. Previously, the "> " prompt appeared when the system expected
a prompt in the INTERPRET context, whether the previous command aborted
or not.

Also, this allows us to get rid of that ugly FLAGS global variable.
This commit is contained in:
Virgil Dupras 2020-04-24 12:10:07 -04:00
parent a699c93509
commit af39b37dd1
14 changed files with 39 additions and 43 deletions

View File

@ -1,6 +1,6 @@
(cont.)
." xxx" -- *I* Compiles string literal xxx followed by a ." xxx" -- *I* Compiles string literal xxx followed by a
call to (print). call to (print).
C<? -- f Returns whether there's a char waiting in buf.
C< -- c Read one char from buffered input. C< -- c Read one char from buffered input.
DUMP n a -- Prints n bytes at addr a in a hexdump format. DUMP n a -- Prints n bytes at addr a in a hexdump format.
Prints in chunks of 8 bytes. Doesn't do partial Prints in chunks of 8 bytes. Doesn't do partial

View File

@ -2,10 +2,10 @@
RAMSTART INITIAL_SP +53 readln's variables RAMSTART INITIAL_SP +53 readln's variables
+02 CURRENT +55 adev's variables +02 CURRENT +55 adev's variables
+04 HERE +57 blk's variables +04 HERE +57 blk's variables
+06 FUTURE USES +59 z80a's variables +06 C<?* +59 z80a's variables
+08 FLAGS +5b FUTURE USES +08 FUTURE USES +5b FUTURE USES
+0a PARSEPTR +70 DRIVERS +0a PARSEPTR +70 DRIVERS
+0c CINPTR +80 RAMEND +0c C<* +80 RAMEND
+0e WORDBUF +0e WORDBUF
+2e BOOT C< PTR +2e BOOT C< PTR
+4e INTJUMP +4e INTJUMP

10
blk/082
View File

@ -1,4 +1,4 @@
(cont.) INITIAL_SP holds the initial Stack Pointer value so INITIAL_SP holds the initial Stack Pointer value so
that we know where to reset it on ABORT that we know where to reset it on ABORT
CURRENT points to the last dict entry. CURRENT points to the last dict entry.
@ -7,10 +7,10 @@ HERE points to current write offset.
IP is the Interpreter Pointer IP is the Interpreter Pointer
FLAGS holds global flags. Only used for prompt output control
for now.
PARSEPTR holds routine address called on (parse) PARSEPTR holds routine address called on (parse)
CINPTR holds routine address called on C< C<* holds routine address called on C<
(cont.) (cont.)

12
blk/083
View File

@ -1,4 +1,7 @@
(cont.) WORDBUF is the buffer used by WORD C<?* is a pointer to a word being called by C<?. If 0 or 1,
will return that value as-is.
WORDBUF is the buffer used by WORD
BOOT C< PTR is used when Forth boots from in-memory BOOT C< PTR is used when Forth boots from in-memory
source. See "Initialization sequence" below. source. See "Initialization sequence" below.
@ -9,8 +12,5 @@ jump to this address. If you use one of those slots for an
interrupt, write a jump to the appropriate offset in that RAM interrupt, write a jump to the appropriate offset in that RAM
location. location.
CURRENTPTR points to current CURRENT. The Forth CURRENT word
doesn't return RAM+2 directly, but rather the value at this (cont.)
address. Most of the time, it points to RAM+2, but sometimes,
when maintaining alternative dicts (during cross compilation
for example), it can point elsewhere. (cont.)

14
blk/084
View File

@ -1,4 +1,10 @@
(cont.) FUTURE USES section is unused for now. CURRENTPTR points to current CURRENT. The Forth CURRENT word
doesn't return RAM+2 directly, but rather the value at this
address. Most of the time, it points to RAM+2, but sometimes,
when maintaining alternative dicts (during cross compilation
for example), it can point elsewhere.
FUTURE USES section is unused for now.
DRIVERS section is reserved for recipe-specific DRIVERS section is reserved for recipe-specific
drivers. Here is a list of known usages: drivers. Here is a list of known usages:
@ -8,9 +14,3 @@ drivers. Here is a list of known usages:

View File

@ -1,5 +1,4 @@
: RAM+ [ RAMSTART LITN ] + ; : RAM+ [ RAMSTART LITN ] + ;
: FLAGS 0x08 RAM+ ;
: (parse*) 0x0a RAM+ ; : (parse*) 0x0a RAM+ ;
: HERE 0x04 RAM+ ; : HERE 0x04 RAM+ ;
: CURRENT* 0x51 RAM+ ; : CURRENT* 0x51 RAM+ ;
@ -8,8 +7,5 @@
( w -- a f ) ( w -- a f )
: (find) CURRENT @ SWAP _find ; : (find) CURRENT @ SWAP _find ;
: QUIT : QUIT (resRS) LIT< INTERPRET (find) DROP EXECUTE ;
0 FLAGS ! (resRS)
LIT< INTERPRET (find) DROP EXECUTE
;
394 407 LOADR 394 407 LOADR

View File

@ -2,7 +2,8 @@
for an abort message ) for an abort message )
: (parse) (parsed) NOT IF ABORT THEN ; : (parse) (parsed) NOT IF ABORT THEN ;
: C< 0x0c RAM+ @ EXECUTE ( 0c == CINPTR ) ; : C<? 0x06 RAM+ @ DUP 2 > IF EXECUTE THEN ( 06 == C<?* ) ;
: C< 0x0c RAM+ @ EXECUTE ( 0c == C<* ) ;
: , HERE @ ! HERE @ 2+ HERE ! ; : , HERE @ ! HERE @ 2+ HERE ! ;

View File

@ -2,13 +2,8 @@
BEGIN BEGIN
WORD WORD
(find) (find)
IF NOT IF (parse*) @ THEN EXECUTE
1 FLAGS ! C<? NOT IF LIT< (ok) (find) IF EXECUTE THEN THEN
EXECUTE
0 FLAGS !
ELSE
(parse*) @ EXECUTE
THEN
AGAIN AGAIN
; ;

View File

@ -3,8 +3,10 @@
LIT< (parse) (find) DROP (parse*) ! LIT< (parse) (find) DROP (parse*) !
( 2e == SYSTEM SCRATCHPAD ) ( 2e == SYSTEM SCRATCHPAD )
CURRENT @ 0x2e RAM+ ! CURRENT @ 0x2e RAM+ !
( 0c == CINPTR ) ( 0c == C<* )
LIT< (boot<) (find) DROP 0x0c RAM+ ! LIT< (boot<) (find) DROP 0x0c RAM+ !
( boot< always has a char waiting. 06 == C<?* )
1 0x06 RAM+ !
LIT< INIT (find) LIT< INIT (find)
IF EXECUTE IF EXECUTE
ELSE DROP INTERPRET THEN ELSE DROP INTERPRET THEN

View File

@ -19,5 +19,6 @@
['] EFS! BLK!* ! ['] EFS! BLK!* !
RDLN$ RDLN$
LIT< _sys [entry] LIT< _sys [entry]
." Collapse OS" CRLF
INTERPRET INTERPRET
; ;

Binary file not shown.

View File

@ -3,7 +3,7 @@
CURRENT @ 1- CURRENT @ 1-
DUP C@ 128 OR SWAP C! DUP C@ 128 OR SWAP C!
; ;
: [ INTERPRET 1 FLAGS ! ; IMMEDIATE : [ INTERPRET ; IMMEDIATE
: ] R> DROP ; : ] R> DROP ;
: LITS 34 , SCPY ; : LITS 34 , SCPY ;
: LIT< WORD LITS ; IMMEDIATE : LIT< WORD LITS ; IMMEDIATE

View File

@ -34,3 +34,4 @@
: SPC 32 EMIT ; : SPC 32 EMIT ;
: (wnf) (print) SPC ABORT" word not found" ; : (wnf) (print) SPC ABORT" word not found" ;
: (ok) SPC ." ok" CRLF ;

View File

@ -54,17 +54,16 @@
( 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)
( Should we prompt? if we're executing a word, FLAGS bit
0, then we shouldn't. )
FLAGS @ 0x1 AND NOT IF '>' EMIT SPC THEN
(infl) (infl)
BEGIN (rdlnc) NOT UNTIL BEGIN (rdlnc) NOT UNTIL
LF IN( IN> ! LF IN( IN> !
; ;
: RDLN<? IN> @ C@ ;
( And finally, implement a replacement for the (c<) routine ) ( And finally, implement a replacement for the (c<) routine )
: (rdln<) : RDLN<
IN> @ C@ ( c ) RDLN<? ( c )
( not EOL? good, inc and return ) ( not EOL? good, inc and return )
DUP IF 1 IN> +! EXIT THEN ( c ) DUP IF 1 IN> +! EXIT THEN ( c )
( EOL ? readline. we still return typed char though ) ( EOL ? readline. we still return typed char though )
@ -79,6 +78,7 @@
the last typed 0x0a and one for the following NULL. ) the last typed 0x0a and one for the following NULL. )
INBUFSZ 4 + ALLOT INBUFSZ 4 + ALLOT
(infl) (infl)
['] (rdln<) 0x0c RAM+ ! ['] RDLN<? 0x06 RAM+ !
['] RDLN< 0x0c RAM+ !
; ;