mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-26 22:38:05 +11:00
Compare commits
No commits in common. "a2f164ecc362110ecae89a7bf01bf758d4d835dd" and "898684a7952788db10b1b009ee100649b0a76da2" have entirely different histories.
a2f164ecc3
...
898684a795
4
blk/061
4
blk/061
@ -1,4 +1,3 @@
|
|||||||
," xxx" -- Write xxx to HERE
|
|
||||||
." 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<? -- f Returns whether there's a char waiting in buf.
|
||||||
@ -12,5 +11,6 @@ IN> -- a Address of variable containing current pos in
|
|||||||
KEY -- c Get char c from direct input
|
KEY -- c Get char c from direct input
|
||||||
PC! c a -- Spit c to port a
|
PC! c a -- Spit c to port a
|
||||||
PC@ a -- c Fetch c from port a
|
PC@ a -- c Fetch c from port a
|
||||||
|
WORD -- a Read one word from buffered input and push its
|
||||||
|
addr.
|
||||||
(cont.)
|
(cont.)
|
||||||
|
4
blk/062
4
blk/062
@ -1,5 +1,4 @@
|
|||||||
WORD -- a Read one word from buffered input and push its
|
(cont.)
|
||||||
addr.
|
|
||||||
There are also ascii const emitters:
|
There are also ascii const emitters:
|
||||||
BS
|
BS
|
||||||
CR
|
CR
|
||||||
@ -14,3 +13,4 @@ SPC
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
11
blk/443
11
blk/443
@ -1,12 +1,11 @@
|
|||||||
: ,"
|
: ."
|
||||||
|
34 , ( 34 == litWord )
|
||||||
BEGIN
|
BEGIN
|
||||||
C<
|
C<
|
||||||
( 34 is ASCII for " )
|
( 34 is ASCII for " )
|
||||||
DUP 34 = IF DROP EXIT THEN C,
|
DUP 34 = IF DROP 0 THEN
|
||||||
AGAIN ;
|
DUP C,
|
||||||
|
NOT UNTIL
|
||||||
: ."
|
|
||||||
34 , ( 34 == litWord ) ," 0 C,
|
|
||||||
COMPILE (print)
|
COMPILE (print)
|
||||||
; IMMEDIATE
|
; IMMEDIATE
|
||||||
|
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
TARGETS = forth stage2
|
TARGETS = forth stage2
|
||||||
|
# Those Forth source files are in a particular order
|
||||||
|
FORTHSRCS = core.fs cmp.fs print.fs parse.fs readln.fs fmt.fs blk.fs
|
||||||
|
FORTHSRC_PATHS = ${FORTHSRCS:%=../forth/%} run.fs
|
||||||
OBJS = emul.o libz80/libz80.o
|
OBJS = emul.o libz80/libz80.o
|
||||||
|
SLATEST = ../tools/slatest
|
||||||
|
STRIPFC = ../tools/stripfc
|
||||||
BIN2C = ../tools/bin2c
|
BIN2C = ../tools/bin2c
|
||||||
BLKPACK = ../tools/blkpack
|
BLKPACK = ../tools/blkpack
|
||||||
BLKUNPACK = ../tools/blkunpack
|
BLKUNPACK = ../tools/blkunpack
|
||||||
@ -10,26 +15,40 @@ all: $(TARGETS)
|
|||||||
$(BLKPACK):
|
$(BLKPACK):
|
||||||
$(MAKE) -C ../tools
|
$(MAKE) -C ../tools
|
||||||
|
|
||||||
.PHONY: $(BIN2C) $(BLKUNPACK)
|
.PHONY: $(STRIPFC) $(SLATEST) $(BIN2C)
|
||||||
|
$(STRIPFC): $(BLKPACK)
|
||||||
|
$(SLATEST): $(BLKPACK)
|
||||||
$(BIN2C): $(BLKPACK)
|
$(BIN2C): $(BLKPACK)
|
||||||
$(BLKUNPACK): $(BLKPACK)
|
$(BLKUNPACK): $(BLKPACK)
|
||||||
|
|
||||||
stage0-bin.h: $(BIN2C)
|
# z80c.bin is not in the prerequisites because it's a bootstrap
|
||||||
$(BIN2C) KERNEL < stage0.bin > $@
|
# binary that should be updated manually through make updatebootstrap.
|
||||||
|
forth0.bin:
|
||||||
|
cp z80c.bin $@
|
||||||
|
cat stage1.fs >> $@
|
||||||
|
|
||||||
stage1: stage.c $(OBJS) stage0-bin.h
|
forth0-bin.h: forth0.bin $(BIN2C)
|
||||||
|
$(BIN2C) KERNEL < forth0.bin | tee $@ > /dev/null
|
||||||
|
|
||||||
|
stage1: stage.c $(OBJS) forth0-bin.h
|
||||||
$(CC) stage.c $(OBJS) -o $@
|
$(CC) stage.c $(OBJS) -o $@
|
||||||
|
|
||||||
stage1dbg: stage.c $(OBJS) stage0-bin.h
|
stage1dbg: stage.c $(OBJS) forth0-bin.h
|
||||||
$(CC) -DDEBUG stage.c $(OBJS) -o $@
|
$(CC) -DDEBUG stage.c $(OBJS) -o $@
|
||||||
|
|
||||||
stage1.bin: stage1.fs stage1
|
# We don't really need to use stripfc, but we do it anyway to test that we
|
||||||
./stage1 < stage1.fs > $@
|
# don't mistakenly break our code with that tool. It's easier to debug here.
|
||||||
|
core.bin: $(FORTHSRC_PATHS) stage1
|
||||||
|
cat $(FORTHSRC_PATHS) stop.fs | $(STRIPFC) | ./stage1 > $@
|
||||||
|
|
||||||
stage1-bin.h: stage1.bin $(BIN2C)
|
forth1.bin: core.bin $(SLATEST)
|
||||||
$(BIN2C) KERNEL < stage1.bin > $@
|
cat z80c.bin core.bin > $@
|
||||||
|
$(SLATEST) $@
|
||||||
|
|
||||||
stage2: stage.c $(OBJS) stage1-bin.h blkfs-bin.h
|
forth1-bin.h: forth1.bin $(BIN2C)
|
||||||
|
$(BIN2C) KERNEL < forth1.bin > $@
|
||||||
|
|
||||||
|
stage2: stage.c $(OBJS) forth1-bin.h blkfs-bin.h
|
||||||
$(CC) -DSTAGE2 stage.c $(OBJS) -o $@
|
$(CC) -DSTAGE2 stage.c $(OBJS) -o $@
|
||||||
|
|
||||||
blkfs: $(BLKPACK)
|
blkfs: $(BLKPACK)
|
||||||
@ -38,7 +57,7 @@ blkfs: $(BLKPACK)
|
|||||||
blkfs-bin.h: blkfs $(BIN2C)
|
blkfs-bin.h: blkfs $(BIN2C)
|
||||||
$(BIN2C) BLKFS < blkfs > $@
|
$(BIN2C) BLKFS < blkfs > $@
|
||||||
|
|
||||||
forth: forth.c $(OBJS) stage1-bin.h blkfs-bin.h
|
forth: forth.c $(OBJS) forth1-bin.h blkfs-bin.h
|
||||||
$(CC) forth.c $(OBJS) -o $@
|
$(CC) forth.c $(OBJS) -o $@
|
||||||
|
|
||||||
libz80/libz80.o: libz80/z80.c
|
libz80/libz80.o: libz80/z80.c
|
||||||
@ -51,7 +70,7 @@ emul.o: emul.c
|
|||||||
|
|
||||||
.PHONY: updatebootstrap
|
.PHONY: updatebootstrap
|
||||||
updatebootstrap: stage2
|
updatebootstrap: stage2
|
||||||
cat xcomp.fs | ./stage2 > stage0.bin
|
cat xcomp.fs | ./stage2 > z80c.bin
|
||||||
|
|
||||||
.PHONY: pack
|
.PHONY: pack
|
||||||
pack:
|
pack:
|
||||||
@ -63,5 +82,5 @@ unpack:
|
|||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm -f $(TARGETS) emul.o *-bin.h stage{1,2}.bin blkfs
|
rm -f $(TARGETS) emul.o *-bin.h forth?.bin blkfs
|
||||||
$(MAKE) -C ../tools clean
|
$(MAKE) -C ../tools clean
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include "emul.h"
|
#include "emul.h"
|
||||||
#include "stage1-bin.h"
|
#include "forth1-bin.h"
|
||||||
#include "blkfs-bin.h"
|
#include "blkfs-bin.h"
|
||||||
|
|
||||||
// in sync with glue.asm
|
// in sync with glue.asm
|
||||||
|
10
emul/stage.c
10
emul/stage.c
@ -3,10 +3,10 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "emul.h"
|
#include "emul.h"
|
||||||
#ifdef STAGE2
|
#ifdef STAGE2
|
||||||
#include "stage1-bin.h"
|
#include "forth1-bin.h"
|
||||||
#include "blkfs-bin.h"
|
#include "blkfs-bin.h"
|
||||||
#else
|
#else
|
||||||
#include "stage0-bin.h"
|
#include "forth0-bin.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Staging binaries
|
/* Staging binaries
|
||||||
@ -29,7 +29,8 @@ trouble of compiling defs to binary.
|
|||||||
// By the way: there's a double-echo in stagedbg. It's normal. Don't panic.
|
// By the way: there's a double-echo in stagedbg. It's normal. Don't panic.
|
||||||
|
|
||||||
//#define DEBUG
|
//#define DEBUG
|
||||||
#define RAMSTART 0
|
// in sync with glue.asm
|
||||||
|
#define RAMSTART 0x840
|
||||||
#define STDIO_PORT 0x00
|
#define STDIO_PORT 0x00
|
||||||
// To know which part of RAM to dump, we listen to port 2, which at the end of
|
// To know which part of RAM to dump, we listen to port 2, which at the end of
|
||||||
// its compilation process, spits its HERE addr to port 2 (MSB first)
|
// its compilation process, spits its HERE addr to port 2 (MSB first)
|
||||||
@ -111,6 +112,9 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
#ifndef DEBUG
|
#ifndef DEBUG
|
||||||
// We're done, now let's spit dict data
|
// We're done, now let's spit dict data
|
||||||
|
if (start_here == 0) {
|
||||||
|
start_here = sizeof(KERNEL);
|
||||||
|
}
|
||||||
for (int i=start_here; i<end_here; i++) {
|
for (int i=start_here; i<end_here; i++) {
|
||||||
putchar(m->mem[i]);
|
putchar(m->mem[i]);
|
||||||
}
|
}
|
||||||
|
BIN
emul/stage0.bin
BIN
emul/stage0.bin
Binary file not shown.
@ -1,28 +1,5 @@
|
|||||||
: EFS@
|
|
||||||
256 /MOD 3 PC! 3 PC!
|
|
||||||
1024 0 DO
|
|
||||||
4 PC@
|
|
||||||
BLK( I + C!
|
|
||||||
LOOP
|
|
||||||
;
|
|
||||||
: EFS!
|
|
||||||
256 /MOD 3 PC! 3 PC!
|
|
||||||
1024 0 DO
|
|
||||||
BLK( I + C@ 4 PC!
|
|
||||||
LOOP
|
|
||||||
;
|
|
||||||
|
|
||||||
: INIT
|
|
||||||
CURRENT @ HERE !
|
CURRENT @ HERE !
|
||||||
BLK$
|
HERE @ 256 /MOD 2 PC! 2 PC!
|
||||||
['] EFS@ BLK@* !
|
: EMIT 0 PC! ;
|
||||||
['] EFS! BLK!* !
|
: KEY 0 PC@ ;
|
||||||
RDLN$
|
CURRENT @ 12 RAM+ !
|
||||||
LIT< _sys [entry]
|
|
||||||
." Collapse OS" CRLF
|
|
||||||
INTERPRET
|
|
||||||
;
|
|
||||||
|
|
||||||
(entry) _
|
|
||||||
H@ 256 /MOD 2 PC! 2 PC!
|
|
||||||
H@ 0x08 ! ( update LATEST )
|
|
||||||
|
@ -16,9 +16,4 @@ H@ XOFF !
|
|||||||
(entry) _
|
(entry) _
|
||||||
( Update LATEST )
|
( Update LATEST )
|
||||||
H@ XOFF @ - XOFF @ 8 + !
|
H@ XOFF @ - XOFF @ 8 + !
|
||||||
," CURRENT @ HERE ! "
|
|
||||||
," : EMIT 0 PC! ; "
|
|
||||||
," : KEY 0 PC@ ; "
|
|
||||||
422 470 XPACKR
|
|
||||||
," ' KEY 12 RAM+ ! "
|
|
||||||
H@ 256 /MOD 2 PC! 2 PC!
|
H@ 256 /MOD 2 PC! 2 PC!
|
||||||
|
BIN
emul/z80c.bin
Normal file
BIN
emul/z80c.bin
Normal file
Binary file not shown.
@ -12,15 +12,14 @@
|
|||||||
AGAIN
|
AGAIN
|
||||||
;
|
;
|
||||||
|
|
||||||
: ,"
|
: ."
|
||||||
|
34 , ( 34 == litWord )
|
||||||
BEGIN
|
BEGIN
|
||||||
C<
|
C<
|
||||||
( 34 is ASCII for " )
|
( 34 is ASCII for " )
|
||||||
DUP 34 = IF DROP EXIT THEN C,
|
DUP 34 = IF DROP 0 THEN
|
||||||
AGAIN ;
|
DUP C,
|
||||||
|
NOT UNTIL
|
||||||
: ."
|
|
||||||
34 , ( 34 == litWord ) ," 0 C,
|
|
||||||
COMPILE (print)
|
COMPILE (print)
|
||||||
; IMMEDIATE
|
; IMMEDIATE
|
||||||
|
|
||||||
|
@ -14,12 +14,14 @@ PATHS = \
|
|||||||
$(FDIR)/fmt.fs \
|
$(FDIR)/fmt.fs \
|
||||||
$(FDIR)/link.fs \
|
$(FDIR)/link.fs \
|
||||||
run.fs
|
run.fs
|
||||||
|
SLATEST = $(BASEDIR)/tools/slatest
|
||||||
STRIPFC = $(BASEDIR)/tools/stripfc
|
STRIPFC = $(BASEDIR)/tools/stripfc
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: $(TARGET)
|
all: $(TARGET)
|
||||||
$(TARGET): z80c.bin $(PATHS)
|
$(TARGET): z80c.bin $(SLATEST) $(PATHS)
|
||||||
cp z80c.bin $@
|
cp z80c.bin $@
|
||||||
|
$(SLATEST) $@
|
||||||
cat $(PATHS) | $(STRIPFC) >> $@
|
cat $(PATHS) | $(STRIPFC) >> $@
|
||||||
|
|
||||||
z80c.bin: xcomp.fs
|
z80c.bin: xcomp.fs
|
||||||
|
@ -22,6 +22,4 @@ H@ XOFF !
|
|||||||
372 LOAD ( sdc.z80 )
|
372 LOAD ( sdc.z80 )
|
||||||
393 LOAD ( icore )
|
393 LOAD ( icore )
|
||||||
(entry) _
|
(entry) _
|
||||||
( Update LATEST )
|
|
||||||
H@ XOFF @ - XOFF @ 8 + !
|
|
||||||
H@ 256 /MOD 2 PC! 2 PC!
|
H@ 256 /MOD 2 PC! 2 PC!
|
||||||
|
@ -4,13 +4,14 @@ UPLOAD_TGT = upload
|
|||||||
FONTCOMPILE_TGT = fontcompile
|
FONTCOMPILE_TGT = fontcompile
|
||||||
TTYSAFE_TGT = ttysafe
|
TTYSAFE_TGT = ttysafe
|
||||||
PINGPONG_TGT = pingpong
|
PINGPONG_TGT = pingpong
|
||||||
|
SLATEST_TGT = slatest
|
||||||
STRIPFC_TGT = stripfc
|
STRIPFC_TGT = stripfc
|
||||||
BIN2C_TGT = bin2c
|
BIN2C_TGT = bin2c
|
||||||
EXEC_TGT = exec
|
EXEC_TGT = exec
|
||||||
BLKPACK_TGT = blkpack
|
BLKPACK_TGT = blkpack
|
||||||
BLKUNPACK_TGT = blkunpack
|
BLKUNPACK_TGT = blkunpack
|
||||||
TARGETS = $(MEMDUMP_TGT) $(BLKDUMP_TGT) $(UPLOAD_TGT) $(FONTCOMPILE_TGT) \
|
TARGETS = $(MEMDUMP_TGT) $(BLKDUMP_TGT) $(UPLOAD_TGT) $(FONTCOMPILE_TGT) \
|
||||||
$(TTYSAFE_TGT) $(PINGPONG_TGT) $(STRIPFC_TGT) \
|
$(TTYSAFE_TGT) $(PINGPONG_TGT) $(SLATEST_TGT) $(STRIPFC_TGT) \
|
||||||
$(BIN2C_TGT) $(EXEC_TGT) $(BLKPACK_TGT) $(BLKUNPACK_TGT)
|
$(BIN2C_TGT) $(EXEC_TGT) $(BLKPACK_TGT) $(BLKUNPACK_TGT)
|
||||||
OBJS = common.o
|
OBJS = common.o
|
||||||
|
|
||||||
@ -26,6 +27,7 @@ $(UPLOAD_TGT): $(UPLOAD_TGT).c
|
|||||||
$(FONTCOMPILE_TGT): $(FONTCOMPILE_TGT).c
|
$(FONTCOMPILE_TGT): $(FONTCOMPILE_TGT).c
|
||||||
$(TTYSAFE_TGT): $(TTYSAFE_TGT).c
|
$(TTYSAFE_TGT): $(TTYSAFE_TGT).c
|
||||||
$(PINGPONG_TGT): $(PINGPONG_TGT).c
|
$(PINGPONG_TGT): $(PINGPONG_TGT).c
|
||||||
|
$(SLATEST_TGT): $(SLATEST_TGT).c
|
||||||
$(STRIPFC_TGT): $(STRIPFC_TGT).c
|
$(STRIPFC_TGT): $(STRIPFC_TGT).c
|
||||||
$(BIN2C_TGT): $(BIN2C_TGT).c
|
$(BIN2C_TGT): $(BIN2C_TGT).c
|
||||||
$(EXEC_TGT): $(EXEC_TGT).c
|
$(EXEC_TGT): $(EXEC_TGT).c
|
||||||
|
29
tools/slatest.c
Normal file
29
tools/slatest.c
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
/* Update the "LATEST" offset of target Forth binary according to filesize. */
|
||||||
|
|
||||||
|
#define OFFSET 0x08
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
if (argc != 2) {
|
||||||
|
fprintf(stderr, "Usage: ./slatest fname\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
FILE *fp = fopen(argv[1], "r+");
|
||||||
|
if (!fp) {
|
||||||
|
fprintf(stderr, "Can't open %s.\n", argv[1]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
fseek(fp, 0, SEEK_END);
|
||||||
|
unsigned int bytecount = ftell(fp);
|
||||||
|
fseek(fp, OFFSET, SEEK_SET);
|
||||||
|
char buf[2];
|
||||||
|
buf[0] = bytecount & 0xff;
|
||||||
|
buf[1] = bytecount >> 8;
|
||||||
|
fwrite(buf, 2, 1, fp);
|
||||||
|
fclose(fp);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user