1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-02 18:20:55 +11:00

Compare commits

..

No commits in common. "c2d8fc845d88631f1e25d38b369d796c40930803" and "04a6784de4827b1617dbe0650345b0b737253124" have entirely different histories.

10 changed files with 173 additions and 124 deletions

View File

@ -7,7 +7,7 @@ AVRABIN = zasm/avra
SHELLAPPS = zasm ed SHELLAPPS = zasm ed
SHELLTGTS = ${SHELLAPPS:%=cfsin/%} SHELLTGTS = ${SHELLAPPS:%=cfsin/%}
# Those Forth source files are in a particular order # Those Forth source files are in a particular order
FORTHSRCS = core.fs str.fs parse.fs readln.fs fmt.fs z80a.fs dummy.fs FORTHSRCS = core.fs str.fs parse.fs readln.fs fmt.fs high.fs z80a.fs dummy.fs
FORTHSRC_PATHS = ${FORTHSRCS:%=../forth/%} FORTHSRC_PATHS = ${FORTHSRCS:%=../forth/%}
CFSIN_CONTENTS = $(SHELLTGTS) cfsin/user.h CFSIN_CONTENTS = $(SHELLTGTS) cfsin/user.h
OBJS = emul.o libz80/libz80.o OBJS = emul.o libz80/libz80.o

Binary file not shown.

View File

@ -1,26 +1,20 @@
: H@ HERE @ ; : H HERE @ ;
: -^ SWAP - ; : -^ SWAP - ;
: [LITN] LITN ; IMMEDIATE : [LITN] LITN ; IMMEDIATE
: LIT ROUTINE S [LITN] , ; : LIT ROUTINE S [LITN] , ;
: LITS LIT SCPY ; : LITS LIT SCPY ;
: LIT< WORD LITS ; IMMEDIATE : LIT< WORD LITS ; IMMEDIATE
: _err LIT< word-not-found (print) ABORT ;
: ' WORD (find) SKIP? _err ;
: ['] WORD (find) SKIP? _err LITN ; IMMEDIATE
: COMPILE ' LITN ['] , , ; IMMEDIATE : COMPILE ' LITN ['] , , ; IMMEDIATE
: [COMPILE] ' , ; IMMEDIATE : [COMPILE] ' , ; IMMEDIATE
: BEGIN H@ ; IMMEDIATE : BEGIN H ; IMMEDIATE
: AGAIN COMPILE (bbr) H@ -^ C, ; IMMEDIATE : AGAIN COMPILE (bbr) H -^ C, ; IMMEDIATE
: UNTIL COMPILE SKIP? COMPILE (bbr) H@ -^ C, ; IMMEDIATE : UNTIL COMPILE SKIP? COMPILE (bbr) H -^ C, ; IMMEDIATE
: ( BEGIN LIT< ) WORD SCMP NOT UNTIL ; IMMEDIATE : ( BEGIN LIT< ) WORD SCMP NOT UNTIL ; IMMEDIATE
( Hello, hello, krkrkrkr... do you hear me? ( Hello, hello, krkrkrkr... do you hear me?
Ah, voice at last! Some lines above need comments Ah, voice at last! Some lines above need comments
BTW: Forth lines limited to 64 cols because of default BTW: Forth lines limited to 64 cols because of default
input buffer size in Collapse OS input buffer size in Collapse OS
"_": words starting with "_" are meant to be "private",
that is, only used by their immediate surrondings.
COMPILE: Tough one. Get addr of caller word (example above COMPILE: Tough one. Get addr of caller word (example above
(bbr)) and then call LITN on it. ) (bbr)) and then call LITN on it. )
@ -30,21 +24,21 @@
: IF ( -- a | a: br cell addr ) : IF ( -- a | a: br cell addr )
COMPILE SKIP? ( if true, don't branch ) COMPILE SKIP? ( if true, don't branch )
COMPILE (fbr) COMPILE (fbr)
H@ ( push a ) H ( push a )
1 ALLOT ( br cell allot ) 1 ALLOT ( br cell allot )
; IMMEDIATE ; IMMEDIATE
: THEN ( a -- | a: br cell addr ) : THEN ( a -- | a: br cell addr )
DUP H@ -^ SWAP ( a-H a ) DUP H -^ SWAP ( a-H a )
C! C!
; IMMEDIATE ; IMMEDIATE
: ELSE ( a1 -- a2 | a1: IF cell a2: ELSE cell ) : ELSE ( a1 -- a2 | a1: IF cell a2: ELSE cell )
COMPILE (fbr) COMPILE (fbr)
1 ALLOT 1 ALLOT
DUP H@ -^ SWAP ( a-H a ) DUP H -^ SWAP ( a-H a )
C! C!
H@ 1 - ( push a. -1 for allot offset ) H 1 - ( push a. -1 for allot offset )
; IMMEDIATE ; IMMEDIATE
: CREATE : CREATE
@ -53,18 +47,18 @@
, ( write it ) , ( write it )
; ;
: VARIABLE CREATE 2 ALLOT ; : VARIABLE CREATE 2 ALLOT ;
: CONSTANT CREATE H@ ! DOES> @ ; : CONSTANT CREATE H ! DOES> @ ;
: = CMP NOT ; : = CMP NOT ;
: < CMP 0 1 - = ; : < CMP 0 1 - = ;
: > CMP 1 = ; : > CMP 1 = ;
: / /MOD SWAP DROP ; : / /MOD SWAP DROP ;
: MOD /MOD DROP ; : MOD /MOD DROP ;
( In addition to pushing H@ this compiles 2 >R so that loop ( In addition to pushing H this compiles 2 >R so that loop
variables are sent to PS at runtime ) variables are sent to PS at runtime )
: DO : DO
COMPILE SWAP COMPILE >R COMPILE >R COMPILE SWAP COMPILE >R COMPILE >R
H@ H
; IMMEDIATE ; IMMEDIATE
( One could think that we should have a sub word to avoid all ( One could think that we should have a sub word to avoid all
@ -73,7 +67,7 @@
: LOOP : LOOP
COMPILE R> 1 LITN COMPILE + COMPILE DUP COMPILE >R COMPILE R> 1 LITN COMPILE + COMPILE DUP COMPILE >R
COMPILE I' COMPILE = COMPILE SKIP? COMPILE (bbr) COMPILE I' COMPILE = COMPILE SKIP? COMPILE (bbr)
H@ -^ C, H -^ C,
COMPILE R> COMPILE DROP COMPILE R> COMPILE DROP COMPILE R> COMPILE DROP COMPILE R> COMPILE DROP
; IMMEDIATE ; IMMEDIATE
@ -90,16 +84,3 @@
SYSVNXT @ , SYSVNXT @ ,
2 SYSVNXT +! 2 SYSVNXT +!
; ;
: ."
LIT
BEGIN
C< DUP ( c c )
( 34 is ASCII for " )
DUP 34 = IF DROP DROP 0 0 THEN
C,
0 = UNTIL
COMPILE (print)
; IMMEDIATE
: ABORT" [COMPILE] ." COMPILE ABORT ; IMMEDIATE

View File

@ -124,7 +124,7 @@ C@ a -- c Set c to byte at address a
C! c a -- Store byte c in address a C! c a -- Store byte c in address a
CURRENT -- a Set a to wordref of last added entry. CURRENT -- a Set a to wordref of last added entry.
HERE -- a Push HERE's address HERE -- a Push HERE's address
H@ -- a HERE @ H -- a HERE @
*** Arithmetic / Bits *** *** Arithmetic / Bits ***

View File

@ -7,5 +7,5 @@
current HERE value. The staging executable needs it to know current HERE value. The staging executable needs it to know
what to dump. ) what to dump. )
H@ 256 / 2 PC! HERE @ 256 / 2 PC!
H@ 2 PC! HERE @ 2 PC!

View File

@ -21,6 +21,11 @@
; ;
; PutC: Write character specified in A onto the device. ; PutC: Write character specified in A onto the device.
; ;
; *** ASCII ***
.equ BS 0x08
.equ CR 0x0d
.equ LF 0x0a
.equ DEL 0x7f
; *** Const *** ; *** Const ***
; Base of the Return Stack ; Base of the Return Stack
.equ RS_ADDR 0xf000 .equ RS_ADDR 0xf000
@ -134,7 +139,7 @@ forthMain:
call find call find
ld (PARSEPTR), de ld (PARSEPTR), de
; Set up CINPTR ; Set up CINPTR
; do we have a (c<) impl? ; do we have a C< impl?
ld hl, .cinName ld hl, .cinName
call find call find
jr z, .skip jr z, .skip
@ -150,7 +155,7 @@ forthMain:
jp EXECUTE+2 jp EXECUTE+2
.cinName: .cinName:
.db "(c<)", 0 .db "C<", 0
BEGIN: BEGIN:
.dw compiledWord .dw compiledWord
@ -733,9 +738,36 @@ PRINT:
inc hl inc hl
jr .loop jr .loop
; ( c port -- )
.db "PC!"
.fill 4
.dw $-PRINT
.db 0
PSTORE:
.dw nativeWord
pop bc
pop hl
call chkPS
out (c), l
jp next
; ( port -- c )
.db "PC@"
.fill 4
.dw $-PSTORE
.db 0
PFETCH:
.dw nativeWord
pop bc
call chkPS
ld h, 0
in l, (c)
push hl
jp next
.db "C," .db "C,"
.fill 5 .fill 5
.dw $-PRINT .dw $-PFETCH
.db 0 .db 0
CWR: CWR:
.dw nativeWord .dw nativeWord
@ -991,10 +1023,43 @@ FIND_:
push de push de
jp next jp next
.db "'"
.fill 6
.dw $-FIND_
.db 0
FIND:
.dw compiledWord
.dw WORD
.dw FIND_
.dw CSKIP
.dw FINDERR
.dw EXIT
.db "[']"
.fill 4
.dw $-FIND
.db 0b01 ; IMMEDIATE
FINDI:
.dw compiledWord
.dw WORD
.dw FIND_
.dw CSKIP
.dw FINDERR
.dw LITN
.dw EXIT
FINDERR:
.dw compiledWord
.dw DROP ; Drop str addr, we don't use it
.dw LIT
.db "word not found", 0
.dw PRINT
.dw ABORT
; ( -- c ) ; ( -- c )
.db "KEY" .db "KEY"
.fill 4 .fill 4
.dw $-FIND_ .dw $-FINDI
.db 0 .db 0
KEY: KEY:
.dw nativeWord .dw nativeWord
@ -1005,11 +1070,8 @@ KEY:
jp next jp next
; This is an indirect word that can be redirected through "CINPTR" ; This is an indirect word that can be redirected through "CINPTR"
; This is not a real word because it's not meant to be referred to in Forth
; code: it is replaced in readln.fs. ; code: it is replaced in readln.fs.
.db "C<"
.fill 5
.dw $-KEY
.db 0
CIN: CIN:
.dw compiledWord .dw compiledWord
.dw NUMBER .dw NUMBER
@ -1026,7 +1088,7 @@ CIN:
; 32 CMP 1 - ; 32 CMP 1 -
.db "WS?" .db "WS?"
.fill 4 .fill 4
.dw $-CIN .dw $-KEY
.db 0 .db 0
ISWS: ISWS:
.dw compiledWord .dw compiledWord
@ -1258,10 +1320,23 @@ STORE:
ld (iy+1), h ld (iy+1), h
jp next jp next
; ( n a -- )
.db "C!"
.fill 5
.dw $-STORE
.db 0
CSTORE:
.dw nativeWord
pop hl
pop de
call chkPS
ld (hl), e
jp next
; ( a -- n ) ; ( a -- n )
.db "@" .db "@"
.fill 6 .fill 6
.dw $-STORE .dw $-CSTORE
.db 0 .db 0
FETCH: FETCH:
.dw nativeWord .dw nativeWord
@ -1271,10 +1346,24 @@ FETCH:
push hl push hl
jp next jp next
; ( a -- c )
.db "C@"
.fill 5
.dw $-FETCH
.db 0
CFETCH:
.dw nativeWord
pop hl
call chkPS
ld l, (hl)
ld h, 0
push hl
jp next
; ( a -- ) ; ( a -- )
.db "DROP" .db "DROP"
.fill 3 .fill 3
.dw $-FETCH .dw $-CFETCH
.db 0 .db 0
DROP: DROP:
.dw nativeWord .dw nativeWord
@ -1448,13 +1537,49 @@ DIVMOD:
jp next jp next
.db "OR"
.fill 5
.dw $-DIVMOD
.db 0
OR:
.dw nativeWord
pop hl
pop de
call chkPS
ld a, e
or l
ld l, a
ld a, d
or h
ld h, a
push hl
jp next
.db "XOR"
.fill 4
.dw $-OR
.db 0
XOR:
.dw nativeWord
pop hl
pop de
call chkPS
ld a, e
xor l
ld l, a
ld a, d
xor h
ld h, a
push hl
jp next
; It might look peculiar to have specific words for "0" and "1", but although ; It might look peculiar to have specific words for "0" and "1", but although
; it slightly beefs ups the ASM part of the binary, this one-byte-save-per-use ; it slightly beefs ups the ASM part of the binary, this one-byte-save-per-use
; really adds up when we compare total size. ; really adds up when we compare total size.
.db "0" .db "0"
.fill 6 .fill 6
.dw $-DIVMOD .dw $-XOR
.db 0 .db 0
ZERO: ZERO:
.dw nativeWord .dw nativeWord

14
forth/high.fs Normal file
View File

@ -0,0 +1,14 @@
( Higher level stuff that generally requires all core units )
: ."
LIT
BEGIN
C< DUP ( c c )
( 34 is ASCII for " )
DUP 34 = IF DROP DROP 0 0 THEN
C,
0 = UNTIL
COMPILE (print)
; IMMEDIATE
: ABORT" [COMPILE] ." COMPILE ABORT ; IMMEDIATE

View File

@ -21,9 +21,9 @@
( Initializes the readln subsystem ) ( Initializes the readln subsystem )
: (c<$) : (c<$)
H@ IN( ! HERE @ IN( !
INBUFSZ ALLOT INBUFSZ ALLOT
H@ IN) ! HERE @ IN) !
(infl) (infl)
; ;
@ -69,8 +69,8 @@
IN( @ IN> ! IN( @ IN> !
; ;
( And finally, implement a replacement for the (c<) routine ) ( And finally, implement a replacement for the C< routine )
: (c<) : C<
IN> @ C@ ( c ) IN> @ C@ ( 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 )

View File

@ -43,6 +43,7 @@
; ;
0x04 OP1r INCr, 0x04 OP1r INCr,
0x46 OP1r LDr(HL), 0x46 OP1r LDr(HL),
0x70 OP1r LD(HL)r,
( r -- ) ( r -- )
: OP1r0 : OP1r0
@ -51,10 +52,7 @@
C@ ( r op ) C@ ( r op )
OR A, OR A,
; ;
0x70 OP1r0 LD(HL)r,
0xa0 OP1r0 ANDr, 0xa0 OP1r0 ANDr,
0xb0 OP1r0 ORr,
0xa8 OP1r0 XORr,
( qq -- also works for ss ) ( qq -- also works for ss )
: OP1qq : OP1qq
@ -109,25 +107,12 @@
C@ ( b r op ) C@ ( b r op )
ROT ( r op b ) ROT ( r op b )
8 * ( r op b<<3 ) 8 * ( r op b<<3 )
OR OR A, OR OR Z,
; ;
0xc0 OP2br SETbr, 0xc0 OP2br SETbr,
0x80 OP2br RESbr, 0x80 OP2br RESbr,
0x40 OP2br BITbr, 0x40 OP2br BITbr,
( cell contains both bytes. MSB is spit as-is, LSB is ORed with r )
( r -- )
: OP2r
CREATE ,
DOES>
@ 256 /MOD ( r lsb msb )
A, ( r lsb )
SWAP 8 * ( lsb r<<3 )
OR A,
;
0xed41 OP2r OUT(C)r,
0xed40 OP2r INr(C),
( dd nn -- ) ( dd nn -- )
: OP3ddnn : OP3ddnn
CREATE C, CREATE C,

View File

@ -83,59 +83,3 @@ CODE AND
H A LDrr, H A LDrr,
HL PUSHqq, HL PUSHqq,
;CODE ;CODE
CODE OR
HL POPqq,
DE POPqq,
chkPS,
A E LDrr,
L ORr,
L A LDrr,
A D LDrr,
H ORr,
H A LDrr,
HL PUSHqq,
;CODE
CODE XOR
HL POPqq,
DE POPqq,
chkPS,
A E LDrr,
L XORr,
L A LDrr,
A D LDrr,
H XORr,
H A LDrr,
HL PUSHqq,
;CODE
CODE C!
HL POPqq,
DE POPqq,
chkPS,
E LD(HL)r,
;CODE
CODE C@
HL POPqq,
chkPS,
L LDr(HL),
H 0 LDrn,
HL PUSHqq,
;CODE
CODE PC!
BC POPqq,
HL POPqq,
chkPS,
L OUT(C)r,
;CODE
CODE PC@
BC POPqq,
chkPS,
H 0 LDrn,
L INr(C),
HL PUSHqq,
;CODE