1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-26 19:48:06 +11:00

Compare commits

..

No commits in common. "f023f9bcb4f62f6bf5e20a237e1f772859fcda49" and "0b3a328e6547b3b56808497dc6276724fd6eced6" have entirely different histories.

66 changed files with 510 additions and 419 deletions

View File

@ -8,8 +8,8 @@ reference.
Contents Contents
4 DOES> 6 Compilation vs meta-comp. 4 DOES> 6 Compilation vs meta-comp.
8 I/O 14 Addressed devices 8 I/O 11 Chained comparisons
18 Signed-ness 14 Addressed devices 18 Signed-ness

16
blk/011 Normal file
View File

@ -0,0 +1,16 @@
Chained comparisons
The unit "cmp.fs" contains words to facilitate chained
comparisons with a single reference number. This allows, for
example, to easily express "a == b or a == c" or "a > b and a <
c".
The way those chained comparison words work is that, unlike
single comparison operators, they don't have a "n1 n2 -- f"
signature, but rather a "n1 f n2 -- n1 f" signature. That is,
each operator "carries over" the reference number in addition
to the latest flag.
(cont.)

16
blk/012 Normal file
View File

@ -0,0 +1,16 @@
(cont.) You open a chain with "<>{" and you close a chain with
"<>}". Then, in between those words, you can chain operators.
For example, to check whether A == B or A == C, you would
write:
A <>{ B &= C |= <>}
The first operator must be of the "&" type because the chain
starts with its flag to true. For example, "<>{ <>}" yields
true.
To check whether A is in between B and C inclusively, you would
write:
A <>{ B 1 - &> C 1 + &< <>}

View File

@ -4,6 +4,8 @@ I/O
result in n as well as whether parsing was a result in n as well as whether parsing was a
success in f (false = failure, true = success in f (false = failure, true =
success) success)
(parse*) -- a Variable holding the current pointer for
system number parsing. By default, (parse).
(print) a -- Print string at addr a. (print) a -- Print string at addr a.
. n -- Print n in its decimal form . n -- Print n in its decimal form
.x n -- Print n's LSB in hex form. Always 2 .x n -- Print n's LSB in hex form. Always 2
@ -11,6 +13,4 @@ I/O
.X n -- Print n in hex form. Always 4 characters. .X n -- Print n in hex form. Always 4 characters.
Numbers are never considered negative. Numbers are never considered negative.
"-1 .X" --> ffff "-1 .X" --> ffff
(cont.) (cont.)

View File

@ -4,7 +4,7 @@ RAMSTART INITIAL_SP +55 (key) override
+04 HERE +59 blk's variables +04 HERE +59 blk's variables
+06 C<? +5b z80a's variables +06 C<? +5b z80a's variables
+08 C<* override +5d adev's variables +08 C<* override +5d adev's variables
+0a RESERVED +5f FUTURE USES +0a PARSEPTR +5f FUTURE USES
+0c C<* +70 DRIVERS +0c C<* +70 DRIVERS
+0e WORDBUF +80 RAMEND +0e WORDBUF +80 RAMEND
+2e BOOT C< PTR +2e BOOT C< PTR

View File

@ -10,7 +10,7 @@ very few things.
In a normal system, BOOT is in icore and does a few things: In a normal system, BOOT is in icore and does a few things:
1. Find "(c<)" a set CINPTR to it (what C< calls). 1. Find "(parse)" and set "(parse*)" to it.
2. Initialize all overrides to 0. 2. Find "(c<)" a set CINPTR to it (what C< calls).
3. Write LATEST in BOOT C< PTR ( see below ) 3. Write LATEST in SYSTEM SCRATCHPAD ( see below )
4. Find "INIT". If found, execute. Otherwise, "INTERPRET"(cont) 4. Find "INIT". If found, execute. Otherwise, "INTERPRET"(cont)

View File

@ -1,7 +1,7 @@
On a bare system (only boot+icore), this sequence will result (cont.) On a bare system (only boot+icore), this sequence will
in (c<) reading characters from memory starting from CURRENT result in "(parse)" reading only decimals and (c<) reading
(this is why we put CURRENT in BOOT C< PTR, it tracks current characters from memory starting from CURRENT (this is why we
pos ). put CURRENT in SYSTEM SCRATCHPAD, it tracks current pos ).
This means that you can put initialization code in source form This means that you can put initialization code in source form
right into your binary, right after your last compiled dict right into your binary, right after your last compiled dict

View File

@ -2,7 +2,7 @@
: ASKIP ( a -- a+n ) : ASKIP ( a -- a+n )
DUP @ ( a n ) DUP @ ( a n )
( ?br or br or NUMBER ) ( ?br or br or NUMBER )
DUP 0x67 = OVER 0x53 = OR OVER 0x20 = OR OVER 0x24 = OR DUP <>{ 0x67 &= 0x53 |= 0x20 |= 0x24 |= <>}
IF DROP 4 + EXIT THEN IF DROP 4 + EXIT THEN
( regular word ) ( regular word )
0x22 = NOT IF 2+ EXIT THEN 0x22 = NOT IF 2+ EXIT THEN

View File

@ -1,7 +1,7 @@
: RLWORD ( ol o a1 a2 -- ) : RLWORD ( ol o a1 a2 -- )
SWAP DUP C@ ( ol o a2 a1 n ) SWAP DUP C@ ( ol o a2 a1 n )
DUP 0x0e = OVER 0x2b = OR NOT IF DUP <>{ 0x0e &= 0x2b |= <>} NOT IF ( unwind all args )
( unwind all args ) 2DROP 2DROP EXIT THEN 2DROP 2DROP EXIT THEN
0x2b = IF 2+ THEN ( ol o a2 a1 ) 0x2b = IF 2+ THEN ( ol o a2 a1 )
1+ ( ol o a2 a1+1 ) 1+ ( ol o a2 a1+1 )
BEGIN ( ol o a2 a1 ) BEGIN ( ol o a2 a1 )

View File

@ -8,7 +8,7 @@
ELSE ( w ) ELSE ( w )
0x02 RAM+ @ SWAP ( cur w ) _find ( a f ) 0x02 RAM+ @ SWAP ( cur w ) _find ( a f )
IF DUP IMMED? NOT IF ABORT THEN EXECUTE IF DUP IMMED? NOT IF ABORT THEN EXECUTE
ELSE (parse) LITN THEN ELSE (parse*) @ EXECUTE LITN THEN
THEN THEN
AGAIN AGAIN
; ;

0
blk/356 Normal file
View File

0
blk/382 Normal file
View File

View File

@ -1,5 +1,6 @@
: RAM+ [ RAMSTART LITN ] + ; : RAM+ [ RAMSTART LITN ] + ;
: BIN+ [ BIN( @ LITN ] + ; : BIN+ [ BIN( @ LITN ] + ;
: (parse*) 0x0a RAM+ ;
: HERE 0x04 RAM+ ; : HERE 0x04 RAM+ ;
: CURRENT* 0x51 RAM+ ; : CURRENT* 0x51 RAM+ ;
: CURRENT CURRENT* @ ; : CURRENT CURRENT* @ ;
@ -12,4 +13,4 @@
0 0x08 RAM+ ! ( 08 == C<* override ) 0 0x08 RAM+ ! ( 08 == C<* override )
LIT< INTERPRET (find) DROP EXECUTE LIT< INTERPRET (find) DROP EXECUTE
; ;
394 413 LOADR 394 407 LOADR

View File

@ -4,11 +4,5 @@
: < CMP -1 = ; : < CMP -1 = ;
: > CMP 1 = ; : > CMP 1 = ;
: 0< 32767 > ; : 0< 32767 > ;
: >= < NOT ;
: <= > NOT ;
: 0>= 0< NOT ;
( a -- a+1 c )
: C@+ DUP C@ SWAP 1+ SWAP ;
( c a -- a+1 )
: C!+ SWAP OVER C! 1+ ;

21
blk/398
View File

@ -1,11 +1,16 @@
( strings being sent to parse routines are always null ( This is only the "early parser" in earlier stages. No need
terminated ) for an abort message )
: (parse) (parsed) NOT IF ABORT THEN ;
: (parsec) ( a -- n f ) : C<? 0x06 RAM+ @ ;
( apostrophe is ASCII 39 ) : C<
DUP C@ 39 = OVER 2+ C@ 39 = AND ( a f ) 0x08 RAM+ @ ( 08 == C<* override )
NOT IF 0 EXIT THEN ( a 0 ) DUP NOT IF DROP 0x0c RAM+ @ THEN ( 0c == C<* )
( surrounded by apos, good, return ) EXECUTE
1+ C@ 1 ( n 1 )
; ;
: , HERE @ ! HERE @ 2+ HERE ! ;
: C, HERE @ C! HERE @ 1+ HERE ! ;

20
blk/399
View File

@ -1,14 +1,12 @@
( returns negative value on error ) ( The NOT is to normalize the negative/positive numbers to 1
: _ ( c -- n ) or 0. Hadn't we wanted to normalize, we'd have written:
( '0' is ASCII 48 ) 32 CMP 1 - )
48 - : WS? 33 CMP 1+ NOT ;
DUP 0< ( bad ) OVER 10 < ( good ) OR IF EXIT THEN
( 'a' is ASCII 97. 59 = 97 - 48 ) : TOWORD
49 - BEGIN
DUP 0< IF EXIT THEN ( bad ) C< DUP WS? NOT IF EXIT THEN DROP
DUP 6 < IF 10 + EXIT THEN ( good ) AGAIN
( bad )
255 -
; ;

29
blk/400
View File

@ -1,15 +1,16 @@
: (parseh) ( a -- n f ) ( Read word from C<, copy to WORDBUF, null-terminate, and
( '0': ASCII 0x30 'x': 0x78 0x7830: 30768 ) return, make HL point to WORDBUF. )
DUP @ 30768 = NOT IF 0 EXIT THEN ( a 0 ) : WORD
( We have "0x" prefix ) 0x0e RAM+ ( 0e == WORDBUF )
2+ TOWORD ( a c )
0 ( a r )
BEGIN BEGIN
SWAP C@+ ( r a+1 c ) ( We take advantage of the fact that char MSB is
DUP NOT IF 2DROP 1 EXIT THEN ( r, 1 ) always zero to pre-write our null-termination )
_ ( r a n ) OVER ! 1+ ( a+1 )
DUP 0< IF ROT 2DROP 0 EXIT THEN ( a 0 ) C< ( a c )
ROT 16 * + ( a r*16+n ) DUP WS?
AGAIN UNTIL
; ( a this point, PS is: a WS )
( null-termination is already written )
2DROP
0x0e RAM+ ;

14
blk/401
View File

@ -1,10 +1,10 @@
( returns negative value on error ) : SCPY
: _ ( c -- n ) BEGIN ( a )
( '0' is ASCII 48 ) DUP C@ ( a c )
48 - DUP C, ( a c )
DUP 0< ( bad ) OVER 2 < ( good ) OR IF EXIT THEN NOT IF DROP EXIT THEN
( bad ) 1+ ( a+1 )
255 - AGAIN
; ;

27
blk/402
View File

@ -1,16 +1,15 @@
: (parseb) ( a -- n f ) : [entry]
( '0': ASCII 0x30 'b': 0x62 0x6230: 25136 ) HERE @ ( w h )
DUP @ 25136 = NOT IF 0 EXIT THEN ( a 0 ) SWAP SCPY ( h )
( We have "0b" prefix ) ( Adjust HERE -1 because SCPY copies the null )
2+ HERE @ 1- ( h h' )
0 ( a r ) DUP HERE ! ( h h' )
BEGIN SWAP - ( sz )
SWAP C@+ ( r a+1 c ) ( write prev value )
DUP NOT IF 2DROP 1 EXIT THEN ( r 1 ) HERE @ CURRENT @ - ,
_ ( r a n ) ( write size )
DUP 0< IF ROT 2DROP 0 EXIT THEN ( a 0 ) C,
ROT 2 * + ( a r*2+n ) HERE @ CURRENT !
AGAIN
; ;
: (entry) WORD [entry] ;

15
blk/403
View File

@ -1,8 +1,9 @@
: (parse) ( a -- n ) : INTERPRET
(parsec) IF EXIT THEN BEGIN
(parseh) IF EXIT THEN WORD
(parseb) IF EXIT THEN (find)
(parsed) IF EXIT THEN NOT IF (parse*) @ THEN EXECUTE
( nothing works ) C<? NOT IF LIT< (ok) (find) IF EXECUTE THEN THEN
LIT< (wnf) (find) IF EXECUTE ELSE ABORT THEN AGAIN
; ;

17
blk/404
View File

@ -1,12 +1,11 @@
: C<? 0x06 RAM+ @ ; ( system c< simply reads source from binary, starting at
: C< LATEST. Convenient way to bootstrap a new system. )
0x08 RAM+ @ ( 08 == C<* override ) : (boot<)
DUP NOT IF DROP 0x0c RAM+ @ THEN ( 0c == C<* ) ( 2e == BOOT C< PTR )
EXECUTE 0x2e RAM+ @ ( a )
DUP C@ ( a c )
SWAP 1 + ( c a+1 )
0x2e RAM+ ! ( c )
; ;
: , HERE @ ! HERE @ 2+ HERE ! ;
: C, HERE @ C! HERE @ 1+ HERE ! ;

23
blk/405
View File

@ -1,12 +1,15 @@
( The NOT is to normalize the negative/positive numbers to 1 : BOOT
or 0. Hadn't we wanted to normalize, we'd have written: 0x02 RAM+ CURRENT* !
32 CMP 1 - ) LIT< (parse) (find) DROP (parse*) !
: WS? 33 CMP 1+ NOT ; CURRENT @ 0x2e RAM+ ! ( 2e == BOOT C< PTR )
0 0x08 RAM+ ! ( 08 == C<* override )
: TOWORD 0 0x53 RAM+ ! ( 53 == (emit) override )
BEGIN 0 0x55 RAM+ ! ( 55 == (key) override )
C< DUP WS? NOT IF EXIT THEN DROP ( 0c == C<* )
AGAIN LIT< (boot<) (find) DROP 0x0c RAM+ !
( boot< always has a char waiting. 06 == C<?* )
1 0x06 RAM+ !
LIT< INIT (find)
IF EXECUTE ELSE DROP INTERPRET THEN
; ;

30
blk/406
View File

@ -1,16 +1,14 @@
( Read word from C<, copy to WORDBUF, null-terminate, and ( LITN has to be defined after the last immediate usage of
return, make HL point to WORDBUF. ) it to avoid bootstrapping issues )
: WORD : LITN 32 , , ( 32 == NUMBER ) ;
0x0e RAM+ ( 0e == WORDBUF )
TOWORD ( a c ) : IMMED? 1- C@ 0x80 AND ;
BEGIN
( We take advantage of the fact that char MSB is ( ';' can't have its name right away because, when created, it
always zero to pre-write our null-termination ) is not an IMMEDIATE yet and will not be treated properly by
OVER ! 1+ ( a+1 ) xcomp. )
C< ( a c ) : _
DUP WS? ['] EXIT ,
UNTIL R> DROP ( exit : )
( a this point, PS is: a WS ) ; IMMEDIATE
( null-termination is already written )
2DROP
0x0e RAM+ ;

26
blk/407
View File

@ -1,10 +1,16 @@
: SCPY XCURRENT @ ( to PSP )
BEGIN ( a ) : :
DUP C@ ( a c ) (entry)
DUP C, ( a c ) ( We cannot use LITN as IMMEDIATE because of bootstrapping
NOT IF DROP EXIT THEN issues. Same thing for ",".
1+ ( a+1 ) 32 == NUMBER 14 == compiledWord )
AGAIN [ 32 H@ ! 2 ALLOT 14 H@ ! 2 ALLOT ] C,
; BEGIN
WORD
(find)
( is word )
IF DUP IMMED? IF EXECUTE ELSE , THEN
( maybe number )
ELSE (parse*) @ EXECUTE LITN THEN
AGAIN ;
( from PSP ) ';' SWAP 4 - C!

15
blk/408
View File

@ -1,15 +0,0 @@
: [entry]
HERE @ ( w h )
SWAP SCPY ( h )
( Adjust HERE -1 because SCPY copies the null )
HERE @ 1- ( h h' )
DUP HERE ! ( h h' )
SWAP - ( sz )
( write prev value )
HERE @ CURRENT @ - ,
( write size )
C,
HERE @ CURRENT !
;
: (entry) WORD [entry] ;

View File

@ -1,9 +0,0 @@
: INTERPRET
BEGIN
WORD
(find)
NOT IF (parse) ELSE EXECUTE THEN
C<? NOT IF LIT< (ok) (find) IF EXECUTE THEN THEN
AGAIN
;

11
blk/410
View File

@ -1,11 +0,0 @@
( system c< simply reads source from binary, starting at
LATEST. Convenient way to bootstrap a new system. )
: (boot<)
( 2e == BOOT C< PTR )
0x2e RAM+ @ ( a )
DUP C@ ( a c )
SWAP 1 + ( c a+1 )
0x2e RAM+ ! ( c )
;

14
blk/411
View File

@ -1,14 +0,0 @@
: BOOT
0x02 RAM+ CURRENT* !
CURRENT @ 0x2e RAM+ ! ( 2e == BOOT C< PTR )
0 0x08 RAM+ ! ( 08 == C<* override )
0 0x53 RAM+ ! ( 53 == (emit) override )
0 0x55 RAM+ ! ( 55 == (key) override )
( 0c == C<* )
LIT< (boot<) (find) DROP 0x0c RAM+ !
( boot< always has a char waiting. 06 == C<?* )
1 0x06 RAM+ !
LIT< INIT (find)
IF EXECUTE ELSE DROP INTERPRET THEN
;

14
blk/412
View File

@ -1,14 +0,0 @@
( LITN has to be defined after the last immediate usage of
it to avoid bootstrapping issues )
: LITN 32 , , ( 32 == NUMBER ) ;
: IMMED? 1- C@ 0x80 AND ;
( ';' can't have its name right away because, when created, it
is not an IMMEDIATE yet and will not be treated properly by
xcomp. )
: _
['] EXIT ,
R> DROP ( exit : )
; IMMEDIATE

16
blk/413
View File

@ -1,16 +0,0 @@
XCURRENT @ ( to PSP )
: :
(entry)
( We cannot use LITN as IMMEDIATE because of bootstrapping
issues. Same thing for ",".
32 == NUMBER 14 == compiledWord )
[ 32 H@ ! 2 ALLOT 14 H@ ! 2 ALLOT ] C,
BEGIN
WORD
(find)
( is word )
IF DUP IMMED? IF EXECUTE ELSE , THEN
( maybe number )
ELSE (parse) LITN THEN
AGAIN ;
( from PSP ) ';' SWAP 4 - C!

View File

@ -8,6 +8,7 @@ a full intepreter, which can then be relinked with the
Relinker. There is no loader for these libraries because you Relinker. There is no loader for these libraries because you
will typically XPACK (B267) them. will typically XPACK (B267) them.
422 core 438 print 422 core 438 cmp
442 fmt 447 readln 442 print 446 parse
453 blk 453 readln 459 fmt
464 blk

View File

@ -8,3 +8,7 @@
DROP DROP
; ;
( a -- a+1 c )
: C@+ DUP C@ SWAP 1+ SWAP ;
( c a -- a+1 )
: C!+ SWAP OVER C! 1+ ;

22
blk/438
View File

@ -1,13 +1,13 @@
: EMIT ( Words useful for complex comparison operations )
( 0x53==(emit) override )
83 RAM+ @ DUP IF EXECUTE ELSE DROP (emit) THEN ; : >= < NOT ;
: <= > NOT ;
: 0>= 0< NOT ;
( n1 -- n1 true )
: <>{ 1 ;
( n1 f -- f )
: <>} SWAP DROP ;
: (print)
BEGIN
C@+ ( a+1 c )
( exit if null )
DUP NOT IF 2DROP EXIT THEN
EMIT ( a )
AGAIN
;

25
blk/439
View File

@ -1,16 +1,15 @@
: ,"
BEGIN
C<
( 34 is ASCII for " )
DUP 34 = IF DROP EXIT THEN C,
AGAIN ;
: ." : _|&
34 , ( 34 == litWord ) ," 0 C, ( n1 n2 cell )
COMPILE (print) >R >R DUP R> R> ( n1 n1 n2 cell )
; IMMEDIATE @ EXECUTE ( n1 f )
;
: ABORT" [COMPILE] ." COMPILE ABORT ; IMMEDIATE ( n1 f n2 -- n1 f )
: _|
: (uflw) ABORT" stack underflow" ; CREATE , DOES>
( n1 f n2 cell )
ROT IF 2DROP 1 EXIT THEN ( n1 true )
_|&
;

22
blk/440
View File

@ -1,9 +1,15 @@
: BS 8 EMIT ; : _&
: LF 10 EMIT ; CREATE , DOES>
: CR 13 EMIT ; ( n1 f n2 cell )
: CRLF CR LF ; ROT NOT IF 2DROP 0 EXIT THEN ( n1 true )
: SPC 32 EMIT ; _|&
;
: (wnf) (print) SPC ABORT" word not found" ;
: (ok) SPC ." ok" CRLF ;
( All words below have this signature:
n1 f n2 -- n1 f )
' = _| |=
' = _& &=
' > _| |>
' > _& &>
' < _| |<
' < _& &<

27
blk/442
View File

@ -1,16 +1,13 @@
: _ : EMIT
999 SWAP ( stop indicator ) ( 0x53==(emit) override )
DUP 0 = IF '0' EXIT THEN ( 0 is a special case ) 83 RAM+ @ DUP IF EXECUTE ELSE DROP (emit) THEN ;
: (print)
BEGIN BEGIN
DUP 0 = IF DROP EXIT THEN C@+ ( a+1 c )
10 /MOD ( r q ) ( exit if null )
SWAP '0' + SWAP ( d q ) DUP NOT IF 2DROP EXIT THEN
AGAIN ; EMIT ( a )
: . ( n -- ) AGAIN
( handle negative ) ;
DUP 0< IF '-' EMIT -1 * THEN
_
BEGIN
DUP '9' > IF DROP EXIT THEN ( stop indicator )
EMIT
AGAIN ;

32
blk/443
View File

@ -1,16 +1,16 @@
: ? @ . ; : ,"
: _ BEGIN
DUP 9 > IF 10 - 'a' + C<
ELSE '0' + THEN ( 34 is ASCII for " )
; DUP 34 = IF DROP EXIT THEN C,
( For hex display, there are no negatives ) AGAIN ;
: .x
256 MOD ( ensure < 0x100 ) : ."
16 /MOD ( l h ) 34 , ( 34 == litWord ) ," 0 C,
_ EMIT ( l ) COMPILE (print)
_ EMIT ; IMMEDIATE
;
: .X : ABORT" [COMPILE] ." COMPILE ABORT ; IMMEDIATE
256 /MOD ( l h )
.x .x : (uflw) ABORT" stack underflow" ;
;

25
blk/444
View File

@ -1,16 +1,9 @@
: _ ( a -- a+8 ) : BS 8 EMIT ;
DUP ( save for 2nd loop ) : LF 10 EMIT ;
':' EMIT DUP .x SPC : CR 13 EMIT ;
4 0 DO : CRLF CR LF ;
DUP @ 256 /MOD SWAP : SPC 32 EMIT ;
.x .x SPC 2+
LOOP : (wnf) (print) SPC ABORT" word not found" ;
DROP : (ok) SPC ." ok" CRLF ;
8 0 DO
C@+
DUP 0x20 < OVER 0x7e > OR
IF DROP '.' THEN
EMIT
LOOP
CRLF
;

11
blk/446 Normal file
View File

@ -0,0 +1,11 @@
( strings being sent to parse routines are always null
terminated )
: (parsec) ( a -- n f )
( apostrophe is ASCII 39 )
DUP C@ 39 = NOT IF 0 EXIT THEN ( a 0 )
DUP 2+ C@ 39 = NOT IF 0 EXIT THEN ( a 0 )
( surrounded by apos, good, return )
1+ C@ 1 ( n 1 )
;

24
blk/447
View File

@ -1,13 +1,15 @@
64 CONSTANT INBUFSZ ( returns negative value on error )
: RDLNMEM+ 0x57 RAM+ @ + ; : _ ( c -- n )
( current position in INBUF ) ( '0' is ASCII 48 )
: IN> 0 RDLNMEM+ ; 48 -
( points to INBUF ) DUP 0< IF EXIT THEN ( bad )
: IN( 2 RDLNMEM+ ; DUP 10 < IF EXIT THEN ( good )
( points to INBUF's end ) ( 'a' is ASCII 97. 59 = 97 - 48 )
: IN) INBUFSZ 2+ RDLNMEM+ ; 49 -
DUP 0< IF EXIT THEN ( bad )
DUP 6 < IF 10 + EXIT THEN ( good )
( bad )
255 -
;
( flush input buffer )
( set IN> to IN( and set IN> @ to null )
: (infl) 0 IN( DUP IN> ! ! ;

27
blk/448
View File

@ -1,16 +1,15 @@
( handle backspace: go back one char in IN>, if possible, then : (parseh) ( a -- n f )
emit SPC + BS ) ( '0': ASCII 0x30 'x': 0x78 0x7830: 30768 )
: (inbs) DUP @ 30768 = NOT IF 0 EXIT THEN ( a 0 )
( already at IN( ? ) ( We have "0x" prefix )
IN> @ IN( = IF EXIT THEN 2+
IN> @ 1- IN> ! 0 ( a r )
SPC BS BEGIN
SWAP C@+ ( r a+1 c )
DUP NOT IF 2DROP 1 EXIT THEN ( r, 1 )
_ ( r a n )
DUP 0< IF ROT 2DROP 0 EXIT THEN ( a 0 )
ROT 16 * + ( a r*16+n )
AGAIN
; ;
: KEY
85 RAM+ @ ( (key) override )
DUP IF EXECUTE ELSE DROP (key) THEN ;
( cont.: read one char into input buffer and returns whether we
should continue, that is, whether CR was not met. )

27
blk/449
View File

@ -1,16 +1,11 @@
: (rdlnc) ( -- f ) ( returns negative value on error )
( buffer overflow? same as if we typed a newline ) : _ ( c -- n )
IN> @ IN) = IF 0x0a ELSE KEY THEN ( c ) ( '0' is ASCII 48 )
DUP 0x7f = IF DROP 0x8 THEN ( del? same as backspace ) 48 -
DUP 0x0a = IF DROP 0xd THEN ( lf? same as cr ) DUP 0< IF EXIT THEN ( bad )
( echo back ) DUP 2 < IF EXIT THEN ( good )
DUP EMIT ( c ) ( bad )
( bacspace? handle and exit ) 255 -
DUP 0x8 = IF (inbs) EXIT THEN ;
( write and advance )
DUP ( keep as result ) ( c c )
( We take advantage of the fact that c's MSB is always zero and
thus ! automatically null-terminates our string )
IN> @ ! 1 IN> +! ( c )
( if newline, replace with zero to indicate EOL )
DUP 0xd = IF DROP 0 THEN ;

30
blk/450
View File

@ -1,16 +1,16 @@
( Read one line in input buffer and make IN> point to it ) : (parseb) ( a -- n f )
: (rdln) ( '0': ASCII 0x30 'b': 0x62 0x6230: 25136 )
(infl) BEGIN (rdlnc) NOT UNTIL DUP @ 25136 = NOT IF 0 EXIT THEN ( a 0 )
LF IN( IN> ! ; ( We have "0b" prefix )
2+
( And finally, implement C<* ) 0 ( a r )
: RDLN< BEGIN
IN> @ C@ SWAP C@+ ( r a+1 c )
DUP IF ( not EOL? good, inc and return ) DUP NOT IF 2DROP 1 EXIT THEN ( r 1 )
1 IN> +! _ ( r a n )
ELSE ( EOL ? readline. we still return null though ) DUP 0< IF ROT 2DROP 0 EXIT THEN ( a 0 )
(rdln) ROT 2 * + ( a r*2+n )
THEN AGAIN
( update C<? flag )
IN> @ C@ 0 > 0x06 RAM+ ! ( 06 == C<? )
; ;

18
blk/451
View File

@ -1,12 +1,10 @@
( Initializes the readln subsystem ) : (parse) ( a -- n )
: RDLN$ (parsec) IF EXIT THEN
( 57 == rdln's memory ) (parseh) IF EXIT THEN
H@ 0x57 RAM+ ! (parseb) IF EXIT THEN
( 2 for IN>, plus 2 for extra bytes after buffer: 1 for (parsed) IF EXIT THEN
the last typed 0x0a and one for the following NULL. ) ( nothing works )
INBUFSZ 4 + ALLOT LIT< (wnf) (find) IF EXECUTE ELSE ABORT THEN
(infl)
['] RDLN< 0x0c RAM+ !
1 0x06 RAM+ ! ( 06 == C<? )
; ;
' (parse) (parse*) !

22
blk/453
View File

@ -1,13 +1,13 @@
: BLKMEM+ 0x59 RAM+ @ + ; 64 CONSTANT INBUFSZ
( n -- Fetches block n and write it to BLK( ) : RDLNMEM+ 0x57 RAM+ @ + ;
: BLK@* 0 BLKMEM+ ; ( current position in INBUF )
( n -- Write back BLK( to storage at block n ) : IN> 0 RDLNMEM+ ;
: BLK!* 2 BLKMEM+ ; ( points to INBUF )
( Current blk pointer in ( ) : IN( 2 RDLNMEM+ ;
: BLK> 4 BLKMEM+ ; ( points to INBUF's end )
( Whether buffer is dirty ) : IN) INBUFSZ 2+ RDLNMEM+ ;
: BLKDTY 6 BLKMEM+ ;
: BLK( 8 BLKMEM+ ;
: BLK) BLK( 1024 + ;
( flush input buffer )
( set IN> to IN( and set IN> @ to null )
: (infl) 0 IN( DUP IN> ! ! ;

22
blk/454
View File

@ -1,12 +1,16 @@
: BLK$ ( handle backspace: go back one char in IN>, if possible, then
H@ 0x59 RAM+ ! emit SPC + BS )
( 1024 for the block, 8 for variables ) : (inbs)
1032 ALLOT ( already at IN( ? )
( LOAD detects end of block with ASCII EOT. This is why IN> @ IN( = IF EXIT THEN
we write it there. EOT == 0x04 ) IN> @ 1- IN> !
4 C, SPC BS
0 BLKDTY !
-1 BLK> !
; ;
: KEY
85 RAM+ @ ( (key) override )
DUP IF EXECUTE ELSE DROP (key) THEN ;
( cont.: read one char into input buffer and returns whether we
should continue, that is, whether CR was not met. )

29
blk/455
View File

@ -1,13 +1,16 @@
: BLK! ( -- ) : (rdlnc) ( -- f )
BLK> @ BLK!* @ EXECUTE ( buffer overflow? same as if we typed a newline )
0 BLKDTY ! IN> @ IN) = IF 0x0a ELSE KEY THEN ( c )
; DUP 0x7f = IF DROP 0x8 THEN ( del? same as backspace )
: FLUSH BLKDTY @ IF BLK! THEN ; DUP 0x0a = IF DROP 0xd THEN ( lf? same as cr )
: BLK@ ( n -- ) ( echo back )
FLUSH DUP EMIT ( c )
DUP BLK> @ = IF DROP EXIT THEN ( bacspace? handle and exit )
DUP BLK> ! BLK@* @ EXECUTE DUP 0x8 = IF (inbs) EXIT THEN
; ( write and advance )
DUP ( keep as result ) ( c c )
: BLK!! 1 BLKDTY ! ; ( We take advantage of the fact that c's MSB is always zero and
thus ! automatically null-terminates our string )
IN> @ ! 1 IN> +! ( c )
( if newline, replace with zero to indicate EOL )
DUP 0xd = IF DROP 0 THEN ;

23
blk/456
View File

@ -1,11 +1,16 @@
: .2 DUP 10 < IF SPC THEN . ; ( Read one line in input buffer and make IN> point to it )
: (rdln)
(infl) BEGIN (rdlnc) NOT UNTIL
LF IN( IN> ! ;
: LIST ( And finally, implement C<* )
BLK@ : RDLN<
16 0 DO IN> @ C@
I 1+ .2 SPC DUP IF ( not EOL? good, inc and return )
64 I * BLK( + (print) 1 IN> +!
CRLF ELSE ( EOL ? readline. we still return null though )
LOOP (rdln)
THEN
( update C<? flag )
IN> @ C@ 0 > 0x06 RAM+ ! ( 06 == C<? )
; ;

24
blk/457
View File

@ -1,16 +1,12 @@
: _ ( Initializes the readln subsystem )
(boot<) : RDLN$
DUP 4 = IF ( 57 == rdln's memory )
( We drop our char, but also "a" from WORD: it won't H@ 0x57 RAM+ !
have the opportunity to balance PSP because we're ( 2 for IN>, plus 2 for extra bytes after buffer: 1 for
EXIT!ing. ) the last typed 0x0a and one for the following NULL. )
2DROP INBUFSZ 4 + ALLOT
( We're finished interpreting ) (infl)
EXIT! ['] RDLN< 0x0c RAM+ !
THEN 1 0x06 RAM+ ! ( 06 == C<? )
; ;
( 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
to avoid tons of "ok" displays. )

18
blk/459
View File

@ -1,2 +1,16 @@
( b1 b2 -- ) : _
: LOADR 1+ SWAP DO I DUP . CRLF LOAD LOOP ; 999 SWAP ( stop indicator )
DUP 0 = IF '0' EXIT THEN ( 0 is a special case )
BEGIN
DUP 0 = IF DROP EXIT THEN
10 /MOD ( r q )
SWAP '0' + SWAP ( d q )
AGAIN ;
: . ( n -- )
( handle negative )
DUP 0< IF '-' EMIT -1 * THEN
_
BEGIN
DUP '9' > IF DROP EXIT THEN ( stop indicator )
EMIT
AGAIN ;

16
blk/460 Normal file
View File

@ -0,0 +1,16 @@
: ? @ . ;
: _
DUP 9 > IF 10 - 'a' +
ELSE '0' + THEN
;
( For hex display, there are no negatives )
: .x
256 MOD ( ensure < 0x100 )
16 /MOD ( l h )
_ EMIT ( l )
_ EMIT
;
: .X
256 /MOD ( l h )
.x .x
;

16
blk/461 Normal file
View File

@ -0,0 +1,16 @@
: _ ( a -- a+8 )
DUP ( save for 2nd loop )
':' EMIT DUP .x SPC
4 0 DO
DUP @ 256 /MOD SWAP
.x .x SPC 2+
LOOP
DROP
8 0 DO
C@+
DUP <>{ 0x20 &< 0x7e |> <>}
IF DROP '.' THEN
EMIT
LOOP
CRLF
;

View File

13
blk/464 Normal file
View File

@ -0,0 +1,13 @@
: BLKMEM+ 0x59 RAM+ @ + ;
( n -- Fetches block n and write it to BLK( )
: BLK@* 0 BLKMEM+ ;
( n -- Write back BLK( to storage at block n )
: BLK!* 2 BLKMEM+ ;
( Current blk pointer in ( )
: BLK> 4 BLKMEM+ ;
( Whether buffer is dirty )
: BLKDTY 6 BLKMEM+ ;
: BLK( 8 BLKMEM+ ;
: BLK) BLK( 1024 + ;

12
blk/465 Normal file
View File

@ -0,0 +1,12 @@
: BLK$
H@ 0x59 RAM+ !
( 1024 for the block, 8 for variables )
1032 ALLOT
( LOAD detects end of block with ASCII EOT. This is why
we write it there. EOT == 0x04 )
4 C,
0 BLKDTY !
-1 BLK> !
;

13
blk/466 Normal file
View File

@ -0,0 +1,13 @@
: BLK! ( -- )
BLK> @ BLK!* @ EXECUTE
0 BLKDTY !
;
: FLUSH BLKDTY @ IF BLK! THEN ;
: BLK@ ( n -- )
FLUSH
DUP BLK> @ = IF DROP EXIT THEN
DUP BLK> ! BLK@* @ EXECUTE
;
: BLK!! 1 BLKDTY ! ;

11
blk/467 Normal file
View File

@ -0,0 +1,11 @@
: .2 DUP 10 < IF SPC THEN . ;
: LIST
BLK@
16 0 DO
I 1+ .2 SPC
64 I * BLK( + (print)
CRLF
LOOP
;

16
blk/468 Normal file
View File

@ -0,0 +1,16 @@
: _
(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
to avoid tons of "ok" displays. )

View File

2
blk/470 Normal file
View File

@ -0,0 +1,2 @@
( b1 b2 -- )
: LOADR 1+ SWAP DO I DUP . CRLF LOAD LOOP ;

1
blk/501 Normal file
View File

@ -0,0 +1 @@

Binary file not shown.

View File

@ -17,6 +17,6 @@ H@ 256 /MOD 2 PC! 2 PC!
PC ORG @ 8 + ! PC ORG @ 8 + !
," CURRENT @ HERE ! " ," CURRENT @ HERE ! "
," : (emit) 0 PC! ; : (key) 0 PC@ ; " ," : (emit) 0 PC! ; : (key) 0 PC@ ; "
422 459 XPACKR 422 470 XPACKR
," ' (key) 12 RAM+ ! " ," ' (key) 12 RAM+ ! "
H@ 256 /MOD 2 PC! 2 PC! H@ 256 /MOD 2 PC! 2 PC!

View File

@ -23,9 +23,11 @@ H@ 256 /MOD 2 PC! 2 PC!
(entry) _ (entry) _
( Update LATEST ) ( Update LATEST )
PC ORG @ 8 + ! PC ORG @ 8 + !
422 437 XPACKR ( core ) 422 441 XPACKR ( core cmp )
446 452 XPACKR ( parse )
358 360 XPACKR ( acia.fs ) 358 360 XPACKR ( acia.fs )
438 452 XPACKR ( print fmt readln ) 442 445 XPACKR ( print )
453 463 XPACKR ( readln fmt )
123 132 XPACKR ( linker ) 123 132 XPACKR ( linker )
," : _ ACIA$ RDLN$ (ok) ; _ " ," : _ ACIA$ RDLN$ (ok) ; _ "
H@ 256 /MOD 2 PC! 2 PC! H@ 256 /MOD 2 PC! 2 PC!

View File

@ -18,7 +18,7 @@ H@ 256 /MOD 2 PC! 2 PC!
( Update LATEST ) ( Update LATEST )
PC ORG @ 8 + ! PC ORG @ 8 + !
," CURRENT @ HERE ! " ," CURRENT @ HERE ! "
422 459 XPACKR ( core print readln fmt blk ) 422 470 XPACKR ( core cmp print parse readln fmt blk )
499 500 XPACKR ( trs80.fs ) 499 500 XPACKR ( trs80.fs )
," : _ BLK$ FD$ (ok) RDLN$ ; _ " ," : _ BLK$ FD$ (ok) RDLN$ ; _ "
H@ 256 /MOD 2 PC! 2 PC! H@ 256 /MOD 2 PC! 2 PC!

View File

@ -1,2 +1,6 @@
0x70 <>{ 0x70 &= 0x58 |= 0x20 |= <>} #
0x71 <>{ 0x70 &= 0x58 |= 0x20 |= <>} NOT #
0x42 <>{ 0x40 &> 0x44 &< <>} #
0x44 <>{ 0x40 &> 0x44 &< <>} NOT #
0x22 0x8065 < # 0x22 0x8065 < #
-1 0 > # -1 0 > #