1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-02 06:40:56 +11:00

Compare commits

..

No commits in common. "d8a6456206f767ee1e673e5fc16e4c64e4e2facf" and "2d2a846b2548aba3899487511d600e8ff8aa2b26" have entirely different histories.

24 changed files with 150 additions and 115 deletions

View File

@ -7,4 +7,3 @@ MOVE a1 a2 u -- Copy u bytes from a1 to a2, starting
with a1, going up. with a1, going up.
MOVE- a1 a2 u -- Copy u bytes from a1 to a2, starting MOVE- a1 a2 u -- Copy u bytes from a1 to a2, starting
with a1+u, going down. with a1+u, going down.
MOVE, a u -- Copy u bytes from a to HERE.

12
blk/288
View File

@ -3,8 +3,14 @@ PC ORG @ 0x22 + ! ( litWord, 0xf7, tight on the 0x100 limit )
number, it's followed by a null-terminated string. When number, it's followed by a null-terminated string. When
called, puts the string's address on PS ) called, puts the string's address on PS )
IY PUSHqq, HL POPqq, ( <-- IP ) IY PUSHqq, HL POPqq, ( <-- IP )
E (HL) LDrr, D 0 LDrn,
DE INCss,
DE ADDIYss,
HL PUSHqq, HL PUSHqq,
( skip to null char )
A XORr, ( look for null )
B A LDrr,
C A LDrr,
CPIR,
( CPIR advances HL regardless of comparison, so goes one
char after NULL. This is good, because that's what we
want... )
HL PUSHqq, IY POPqq, ( --> IP )
JPNEXT, JPNEXT,

View File

@ -1,5 +1,5 @@
( Name of BOOT word ) ( Name of BOOT word )
L1 BSET 4 A, 'B' A, 'O' A, 'O' A, 'T' A, L1 BSET 'B' A, 'O' A, 'O' A, 'T' A, 0 A,
PC ORG @ 1 + ! ( main ) PC ORG @ 1 + ! ( main )
( STACK OVERFLOW PROTECTION: See B76 ) ( STACK OVERFLOW PROTECTION: See B76 )

16
blk/291
View File

@ -5,12 +5,12 @@ PC ORG @ 4 + ! ( find )
BC PUSHqq, BC PUSHqq,
HL PUSHqq, HL PUSHqq,
( First, figure out string len ) ( First, figure out string len )
A (HL) LDrr, A ORr, BC 0 LDddnn,
A XORr,
CPIR,
( C has our length, negative, -1 )
A C LDrr,
NEG,
A DECr,
( special case. zero len? we never find anything. ) ( special case. zero len? we never find anything. )
IFNZ, ( fail-B296 ) IFNZ, ( fail-B296 ) ( cont. )
( Let's do something weird: We'll hold HL by the *tail*.
Because of our dict structure and because we know our
lengths, it's easier to compare starting from the end. )
C A LDrr, B 0 LDrn, ( C holds our length )
BC ADDHLss, HL INCss, ( HL points to after-last-char )
( cont . )

View File

@ -1,3 +1,11 @@
C A LDrr, ( C holds our length )
( Let's do something weird: We'll hold HL by the *tail*.
Because of our dict structure and because we know our
lengths, it's easier to compare starting from the end.
Currently, after CPIR, HL points to char after null. Let's
adjust. Because the compare loop pre-decrements, instead
of DECing HL twice, we DEC it once. )
HL DECss,
BEGIN, ( inner ) BEGIN, ( inner )
( DE is a wordref, first step, do our len correspond? ) ( DE is a wordref, first step, do our len correspond? )
HL PUSHqq, ( --> lvl 1 ) HL PUSHqq, ( --> lvl 1 )

View File

@ -1,4 +1,4 @@
6 A, '(' A, 'u' A, 'f' A, 'l' A, 'w' A, ')' A, '(' A, 'u' A, 'f' A, 'l' A, 'w' A, ')' A, 0 A,
L2 BSET ( abortUnderflow ) L2 BSET ( abortUnderflow )
HL PC 7 - LDddnn, HL PC 7 - LDddnn,
DE RAMSTART 0x02 + LDdd(nn), ( RAM+02 == CURRENT ) DE RAMSTART 0x02 + LDdd(nn), ( RAM+02 == CURRENT )

23
blk/328
View File

@ -1,15 +1,14 @@
CODE S= CODE S=
DE POPqq, HL POPqq, chkPS, DE POPqq,
LDA(DE), HL POPqq,
(HL) CPr, chkPS,
IFZ, ( same size? ) BEGIN,
B A LDrr, ( loop A times ) LDA(DE),
BEGIN, (HL) CPr,
HL INCss, DE INCss, JRNZ, BREAK, ( not equal? break early. NZ is set. )
LDA(DE), A ORr, ( if our char is null, stop )
(HL) CPr, HL INCss,
JRNZ, BREAK, ( not equal? break early. NZ is set. ) DE INCss,
DJNZ, AGAIN, JRNZ, AGAIN,
THEN,
PUSHZ, PUSHZ,
;CODE ;CODE

View File

@ -7,9 +7,7 @@
: MIN ( n n - n ) 2DUP > IF SWAP THEN DROP ; : MIN ( n n - n ) 2DUP > IF SWAP THEN DROP ;
: MAX ( n n - n ) 2DUP < IF SWAP THEN DROP ; : MAX ( n n - n ) 2DUP < IF SWAP THEN DROP ;
: NIP SWAP DROP ; : TUCK SWAP OVER ; : NIP SWAP DROP ; : TUCK SWAP OVER ;
: -^ SWAP - ;
: C@+ ( a -- a+1 c ) DUP C@ SWAP 1+ SWAP ; : C@+ ( a -- a+1 c ) DUP C@ SWAP 1+ SWAP ;
: C!+ ( c a -- a+1 ) TUCK C! 1+ ; : C!+ ( c a -- a+1 ) TUCK C! 1+ ;
: C@- ( a -- a-1 c ) DUP C@ SWAP 1- SWAP ; : C@- ( a -- a-1 c ) DUP C@ SWAP 1- SWAP ;
: C!- ( c a -- a-1 ) TUCK C! 1- ; : C!- ( c a -- a-1 ) TUCK C! 1- ;
: LEAVE R> R> DROP I 1- >R >R ; : UNLOOP R> 2R> 2DROP >R ;

24
blk/357
View File

@ -1,8 +1,16 @@
: (parsed) ( a -- n f ) : (parsed) ( a -- n f )
C@+ OVER C@ 0 ( a len firstchar startat ) DUP C@ ( a c )
SWAP '-' = IF 1+ THEN ( a len startat ) DUP '-' = IF
0 ROT ROT ( len ) ( startat ) DO ( a r ) DROP 1+ ( a+1 ) (parsed) 0 ROT ( f 0 n )
OVER I + C@ ( a r c ) _pdacc ( a r f ) - SWAP EXIT ( 0-n f )
IF DROP 1- 0 UNLOOP EXIT THEN LOOP ( a r ) THEN
( negate if needed ) 0 SWAP _pdacc ( a r f )
SWAP C@ '-' = IF 0 -^ THEN 1 ( r 1 ) ; ?DUP IF 2DROP 0 EXIT THEN
BEGIN ( a r )
SWAP 1+ ( r a+1 )
DUP C@ ( r a c )
ROT SWAP ( a r c )
_pdacc ( a r f )
?DUP UNTIL
1 = ( a r f )
ROT DROP ( r f ) ;

View File

@ -3,9 +3,9 @@
: (parsec) ( a -- n f ) : (parsec) ( a -- n f )
( apostrophe is ASCII 39 ) ( apostrophe is ASCII 39 )
DUP 1+ C@ 39 = OVER 3 + C@ 39 = AND ( a f ) DUP C@ 39 = OVER 2+ C@ 39 = AND ( a f )
NOT IF 0 EXIT THEN ( a 0 ) NOT IF 0 EXIT THEN ( a 0 )
( surrounded by apos, good, return ) ( surrounded by apos, good, return )
2+ C@ 1 ( n 1 ) 1+ C@ 1 ( n 1 )
; ;

21
blk/360
View File

@ -1,10 +1,15 @@
: (parseh) ( a -- n f ) : (parseh) ( a -- n f )
( '0': ASCII 0x30 'x': 0x78 0x7830 ) ( '0': ASCII 0x30 'x': 0x78 0x7830: 30768 )
DUP 1+ @ 0x7830 = NOT IF 0 EXIT THEN ( a 0 ) DUP @ 30768 = NOT IF 0 EXIT THEN ( a 0 )
( We have "0x" prefix ) ( We have "0x" prefix )
DUP C@ ( a len ) 2+
0 SWAP 1+ ( len+1 ) 3 DO ( a r ) 0 ( a r )
OVER I + C@ ( a r c ) _ ( a r n ) BEGIN
DUP 0< IF 2DROP 0 UNLOOP EXIT THEN SWAP C@+ ( r a+1 c )
SWAP 4 LSHIFT + ( a r*16+n ) LOOP ?DUP NOT IF DROP 1 EXIT THEN ( r, 1 )
NIP 1 ; _ ( r a n )
DUP 0< IF ROT 2DROP 0 EXIT THEN ( a 0 )
ROT 16 * + ( a r*16+n )
AGAIN
;

22
blk/362
View File

@ -1,10 +1,16 @@
: (parseb) ( a -- n f ) : (parseb) ( a -- n f )
( '0': ASCII 0x30 'b': 0x62 0x6230 ) ( '0': ASCII 0x30 'b': 0x62 0x6230: 25136 )
DUP 1+ @ 0x6230 = NOT IF 0 EXIT THEN ( a 0 ) DUP @ 25136 = NOT IF 0 EXIT THEN ( a 0 )
( We have "0b" prefix ) ( We have "0b" prefix )
DUP C@ ( a len ) 2+
0 SWAP 1+ ( len+1 ) 3 DO ( a r ) 0 ( a r )
OVER I + C@ ( a r c ) _ ( a r n ) BEGIN
DUP 0< IF 2DROP 0 UNLOOP EXIT THEN SWAP C@+ ( r a+1 c )
SWAP 1 LSHIFT + ( a r*2+n ) LOOP ?DUP NOT IF DROP 1 EXIT THEN ( r 1 )
NIP 1 ; _ ( r a n )
DUP 0< IF ROT 2DROP 0 EXIT THEN ( a 0 )
ROT 2 * + ( a r*2+n )
AGAIN
;

16
blk/366
View File

@ -1,13 +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. )
: _wb 0x0e RAM+ ;
: _eot 0x0401 _wb ! _wb ;
: WORD : WORD
_wb 1+ TOWORD ( a c ) 0x0e RAM+ TOWORD ( a c )
DUP EOT? IF 2DROP _eot EXIT THEN DUP EOT? IF OVER ! EXIT THEN
BEGIN BEGIN
OVER C! 1+ C< ( a c ) ( We take advantage of the fact that char MSB is
OVER 0x2e RAM+ = OVER WS? OR always zero to pre-write our null-termination )
OVER ! 1+ C< ( a c )
OVER 0x2d ( 2e-1 for NULL ) RAM+ = OVER WS? OR
UNTIL ( a c ) UNTIL ( a c )
SWAP _wb - 1- ( ws len ) _wb C! NIP 0x0e RAM+ ( ws a )
EOT? IF _eot ELSE _wb THEN ; SWAP EOT? IF 4 OVER ! THEN ;

View File

@ -1,8 +0,0 @@
: IMMEDIATE
CURRENT @ 1-
DUP C@ 128 OR SWAP C! ;
: IMMED? 1- C@ 0x80 AND ;
: +! TUCK @ + SWAP ! ;
: / /MOD NIP ;
: MOD /MOD DROP ;
: ALLOT HERE +! ;

12
blk/368 Normal file
View File

@ -0,0 +1,12 @@
: +! TUCK @ + SWAP ! ;
: [entry] ( w -- )
H@ SWAP
BEGIN C@+ ( w+1 c ) ?DUP IF C, 0 ELSE 1 THEN UNTIL DROP
H@ SWAP - ( sz )
( write prev value )
H@ CURRENT @ - ,
C, ( write size )
H@ CURRENT !
;
: (entry) WORD [entry] ;

23
blk/369
View File

@ -1,12 +1,11 @@
: '? WORD FIND ; : IMMEDIATE
: ' CURRENT @ 1-
'? (?br) [ 4 , ] EXIT DUP C@ 128 OR SWAP C! ;
LIT< (wnf) FIND DROP EXECUTE : IMMED? 1- C@ 0x80 AND ;
; : -^ SWAP - ;
: ROLL : / /MOD NIP ;
?DUP NOT IF EXIT THEN : MOD /MOD DROP ;
1+ DUP PICK ( n val ) : ALLOT HERE +! ;
SWAP 2 * (roll) ( val ) : CREATE (entry) 11 ( 11 == cellWord ) C, ;
NIP ; : VARIABLE CREATE 2 ALLOT ;
: 2OVER 3 PICK 3 PICK ; : LEAVE R> R> DROP I 1- >R >R ;
: 2SWAP 3 ROLL 3 ROLL ;

26
blk/370
View File

@ -1,14 +1,12 @@
: MOVE ( a1 a2 u -- ) : '? WORD FIND ;
( u ) 0 DO ( a1 a2 ) : '
SWAP C@+ ( a2 a1+1 x ) '? (?br) [ 4 , ] EXIT
ROT C!+ ( a1+1 a2+1 ) LIT< (wnf) FIND DROP EXECUTE
LOOP 2DROP ; ;
: MOVE- ( a1 a2 u -- ) : ROLL
TUCK + 1- ( a1 u a2+u-1 ) ?DUP NOT IF EXIT THEN
ROT 2 PICK + 1- ( u a2+u-1 a1+u-1 ) 1+ DUP PICK ( n val )
ROT ( u ) 0 DO ( a2 a1 ) SWAP 2 * (roll) ( val )
C@- ( a2 a1-1 x ) NIP ;
ROT C!- ( a1-1 a2-1 ) SWAP ( a2 a1 ) : 2OVER 3 PICK 3 PICK ;
LOOP 2DROP ; : 2SWAP 3 ROLL 3 ROLL ;
: MOVE, ( a u -- ) H@ OVER ALLOT SWAP MOVE ;
: PREV 3 - DUP @ - ;

23
blk/371
View File

@ -1,10 +1,13 @@
: [entry] ( w -- ) : MOVE ( a1 a2 u -- )
C@+ ( w+1 len ) TUCK MOVE, ( len ) ( u ) 0 DO ( a1 a2 )
( write prev value ) SWAP C@+ ( a2 a1+1 x )
H@ CURRENT @ - , ROT C!+ ( a1+1 a2+1 )
C, ( write size ) LOOP 2DROP ;
H@ CURRENT ! : MOVE- ( a1 a2 u -- )
; TUCK + 1- ( a1 u a2+u-1 )
: (entry) WORD [entry] ; ROT 2 PICK + 1- ( u a2+u-1 a1+u-1 )
: CREATE (entry) 11 ( 11 == cellWord ) C, ; ROT ( u ) 0 DO ( a2 a1 )
: VARIABLE CREATE 2 ALLOT ; C@- ( a2 a1-1 x )
ROT C!- ( a1-1 a2-1 ) SWAP ( a2 a1 )
LOOP 2DROP ;
: PREV 3 - DUP @ - ;

View File

@ -1,7 +1,13 @@
: EMIT : EMIT
( 0x53==(emit) override ) ( 0x53==(emit) override )
0x53 RAM+ @ ?DUP IF EXECUTE ELSE (emit) THEN ; 0x53 RAM+ @ ?DUP IF EXECUTE ELSE (emit) THEN ;
: (print) C@+ ( a len ) 0 DO C@+ EMIT LOOP DROP ; : (print)
BEGIN
C@+ ( a+1 c )
( exit if null or 0xd )
DUP 0xd = OVER NOT OR IF 2DROP EXIT THEN
EMIT ( a )
AGAIN ;
: BS 8 EMIT ; : LF 10 EMIT ; : CR 13 EMIT ; : BS 8 EMIT ; : LF 10 EMIT ; : CR 13 EMIT ;
: CRLF CR LF ; : SPC 32 EMIT ; : CRLF CR LF ; : SPC 32 EMIT ;
: NL 0x0a RAM+ @ ( NLPTR ) ?DUP IF EXECUTE ELSE CRLF THEN ; : NL 0x0a RAM+ @ ( NLPTR ) ?DUP IF EXECUTE ELSE CRLF THEN ;

View File

@ -2,9 +2,6 @@
BEGIN BEGIN
C< DUP 34 ( ASCII " ) = IF DROP EXIT THEN C, C< DUP 34 ( ASCII " ) = IF DROP EXIT THEN C,
AGAIN ; AGAIN ;
: LIT" : LIT" 34 , ( litWord ) ," 0 C, ; IMMEDIATE
34 , ( litWord ) H@ 0 C, ,"
DUP H@ -^ 1- ( a len ) SWAP C!
; IMMEDIATE
: ." [COMPILE] LIT" COMPILE (print) ; IMMEDIATE : ." [COMPILE] LIT" COMPILE (print) ; IMMEDIATE
: ABORT" [COMPILE] ." COMPILE ABORT ; IMMEDIATE : ABORT" [COMPILE] ." COMPILE ABORT ; IMMEDIATE

View File

@ -1,6 +1,6 @@
: INTERPRET : INTERPRET
BEGIN BEGIN
WORD DUP @ 0x0401 = ( EOT ) IF DROP EXIT THEN WORD DUP C@ EOT? IF DROP EXIT THEN
FIND NOT IF (parse) ELSE EXECUTE THEN FIND NOT IF (parse) ELSE EXECUTE THEN
C<? NOT IF SPC LIT< ok (print) NL THEN C<? NOT IF SPC LIT< ok (print) NL THEN
AGAIN ; AGAIN ;

View File

@ -1,4 +1,4 @@
: LIT< WORD 34 , DUP C@ 1+ MOVE, ; IMMEDIATE : LIT< WORD 34 , BEGIN C@+ DUP C, NOT UNTIL DROP ; IMMEDIATE
: BEGIN H@ ; IMMEDIATE : BEGIN H@ ; IMMEDIATE
: AGAIN COMPILE (br) H@ - _bchk , ; IMMEDIATE : AGAIN COMPILE (br) H@ - _bchk , ; IMMEDIATE
: UNTIL COMPILE (?br) H@ - _bchk , ; IMMEDIATE : UNTIL COMPILE (?br) H@ - _bchk , ; IMMEDIATE

Binary file not shown.

View File

@ -42,8 +42,7 @@ static uint8_t iord_stdio()
static void iowr_stdio(uint8_t val) static void iowr_stdio(uint8_t val)
{ {
// uncomment when you need to debug staging // we don't output stdout in stage0
// putc(val, stderr);
} }
static void iowr_here(uint8_t val) static void iowr_here(uint8_t val)