Forth takeover!

This commit is contained in:
Virgil Dupras 2020-05-21 22:16:01 -04:00
parent 0939241db1
commit d777a74be3
8 changed files with 13 additions and 1928 deletions

View File

@ -2,16 +2,18 @@
*Bootstrap post-collapse technology* *Bootstrap post-collapse technology*
Collapse OS is a z80 kernel and a collection of programs, tools and Collapse OS is a Forth operating system and a collection of tools and
documentation that allows you to assemble an OS that, when completed, will be documentation with a single purpose: preserve the ability to program micro-
able to: controllers through civilizational collapse.
It it designed to:
1. Run on minimal and improvised machines. 1. Run on minimal and improvised machines.
2. Interface through improvised means (serial, keyboard, display). 2. Interface through improvised means (serial, keyboard, display).
3. Edit text files. 3. Edit text files.
4. Compile assembler source files for a wide range of MCUs and CPUs. 4. Compile assembler source files for a wide range of MCUs and CPUs.
5. Read and write from a wide range of storage devices. 5. Read and write from a wide range of storage devices.
6. Replicate itself. 6. Assemble itself and deploy to another machine.
Additionally, the goal of this project is to be as self-contained as possible. Additionally, the goal of this project is to be as self-contained as possible.
With a copy of this project, a capable and creative person should be able to With a copy of this project, a capable and creative person should be able to
@ -19,14 +21,6 @@ manage to build and install Collapse OS without external resources (i.e.
internet) on a machine of her design, built from scavenged parts with low-tech internet) on a machine of her design, built from scavenged parts with low-tech
tools. tools.
## Forth reboot in process
You are currently looking at the `forth` branch of the project, which is a
Forth reboot of Collapse OS. You can see why I'm doing this in the [related
github issue][forth-issue].
Documentation is lacking, it's not ready yet, this is a WIP branch.
## Getting started ## Getting started
Usage documentation is in-system, so access to documentation requires you to Usage documentation is in-system, so access to documentation requires you to
@ -53,6 +47,12 @@ Then, run `0 LIST` for an introduction, follow instructions from there.
The project unfinished but is progressing well! See [Collapse OS' website][web] The project unfinished but is progressing well! See [Collapse OS' website][web]
for more information. for more information.
## Looking for the assembler version?
The Forth-based Collapse OS is the second incarnation of the concept. The first
one was entirely written in z80 assembly. If you're interested in that
incarnation, checkout the `z80asm` branch.
## Discussion ## Discussion
For a general discussion of Collapse OS and the ecosystem of technologies and For a general discussion of Collapse OS and the ecosystem of technologies and
@ -64,4 +64,3 @@ channels are also maintained.
[web]: https://collapseos.org [web]: https://collapseos.org
[discussion]: https://www.reddit.com/r/collapseos [discussion]: https://www.reddit.com/r/collapseos
[listserv]: http://lists.sonic.net/mailman/listinfo/collapseos [listserv]: http://lists.sonic.net/mailman/listinfo/collapseos
[forth-issue]: https://github.com/hsoft/collapseos/issues/4

View File

@ -1,470 +0,0 @@
.
.
.
.
. .
. .
. .
...
...
. .
..
..
..
..
.
.
.
.
.
.
.
. .
.
. .
..
.
.
.
.
.
.
.
.
.
.
.
.
.
...
.
. .
.
...
.
.
.
...
.
.
.
.
.
.
.
. .
. .
. .
.
.
..
.
.
...
..
.
.
.
...
..
.
..
.
..
. .
. .
...
.
.
...
.
..
.
..
..
.
...
. .
...
...
.
.
.
.
...
. .
...
. .
...
...
. .
...
.
..
.
.
.
.
.
.
.
.
.
.
...
...
.
.
.
.
.
..
.
.
.
.
...
...
.
..
.
. .
...
. .
. .
..
. .
..
. .
..
..
.
.
.
..
..
. .
. .
. .
..
...
.
..
.
...
...
.
..
.
.
..
.
. .
. .
..
. .
. .
...
. .
. .
...
.
.
.
...
...
.
.
.
..
. .
..
.
..
. .
.
.
.
.
...
. .
...
...
. .
. .
..
. .
. .
. .
. .
...
. .
. .
. .
...
..
. .
..
.
.
...
. .
. .
...
..
..
. .
..
. .
. .
..
.
.
.
..
...
.
.
.
.
. .
. .
. .
. .
...
. .
. .
. .
. .
.
. .
. .
...
...
. .
. .
. .
.
. .
. .
. .
. .
.
.
.
...
.
.
.
...
...
.
.
.
...
.
.
.
.
.
...
.
.
.
...
.
. .
...
.
.
..
.
...
...
.
.
..
. .
..
..
.
.
..
.
.
..
. .
..
.
. .
..
..
..
.
..
.
.
.
. .
..
..
.
.
..
. .
. .
.
.
.
.
.
.
.
..
.
. .
..
. .
. .
..
.
.
.
..
. .
...
. .
. .
..
. .
. .
. .
.
. .
. .
.
..
. .
..
.
..
. .
..
.
..
.
.
.
..
..
.
..
.
...
.
.
..
. .
. .
. .
...
. .
. .
. .
.
. .
. .
...
. .
. .
.
.
. .
. .
.
.
.
...
..
..
...
..
.
.
.
..
.
.
.
.
.
..
.
.
.
..
..
..

View File

@ -1,658 +0,0 @@
.
.
.
.
.
.
. .
. .
. .
.....
. .
.....
. .
.
....
.
...
.
....
.
. .
.
.
.
. .
..
. .
..
.. .
. .
... .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. . .
...
.....
...
. . .
.
.
.....
.
.
.
.
.....
..
..
.
.
.
.
...
. .
. ..
. . .
.. .
. .
...
..
. .
.
.
.
.
....
...
. .
.
.
.
.
.....
...
. .
.
..
.
. .
...
..
. .
. .
.....
.
.
.
.....
.
....
.
.
. .
...
...
.
.
....
. .
. .
...
.....
.
.
.
.
.
.
...
. .
. .
...
. .
. .
...
...
. .
. .
...
.
.
...
.
.
.
.
.
.
.
.
.
..
..
.
..
..
.
.....
.....
.
..
..
.
..
..
.
...
. .
.
.
.
.
...
. .
. ..
. ..
.
. .
...
...
. .
. .
.....
. .
. .
. .
....
. .
. .
....
. .
. .
....
...
. .
.
.
.
. .
...
....
. .
. .
. .
. .
. .
....
.....
.
.
....
.
.
.....
.....
.
.
....
.
.
.
...
. .
.
. ..
. .
. .
...
. .
. .
. .
.....
. .
. .
. .
...
.
.
.
.
.
...
..
.
.
.
.
. .
...
. .
. .
..
.
..
. .
. .
.
.
.
.
.
.
.....
. .
.. ..
. . .
. .
. .
. .
. .
. .
.. .
.. .
. . .
. ..
. ..
. .
...
. .
. .
. .
. .
. .
...
....
. .
. .
....
.
.
.
...
. .
. .
. .
. . .
. ..
....
....
. .
. .
....
. .
. .
. .
...
. .
.
...
.
. .
...
.....
.
.
.
.
.
.
. .
. .
. .
. .
. .
. .
...
. .
. .
. .
. .
. .
. .
.
. .
. .
. .
. .
. . .
. . .
. .
. .
. .
. .
.
. .
. .
. .
. .
. .
. .
.
.
.
.
.....
. .
.
.
.
. .
.....
...
.
.
.
.
.
...
.
.
.
.
.
...
.
.
.
.
.
...
.
. .
. .
.....
.
.
...
.
....
. .
....
.
.
...
. .
...
...
. .
.
. .
...
.
.
...
. .
...
...
. .
.....
.
....
..
. .
.
...
.
...
. .
...
. .
..
.
.
...
. .
. .
.
.
.
.
.
.
. .
..
. .
. .
..
. .
. .
..
.
.
.
..
. .
. . .
. .
. .
. .
...
. .
. .
. .
. .
...
. .
. .
. .
...
...
. .
...
.
.
...
. .
...
.
.
. ..
..
.
.
.
...
.
...
.
...
.
...
.
.
..
. .
. .
. .
. .
...
. .
. .
. .
. .
.
. .
. .
. .
. . .
. .
. .
. .
.
. .
. .
. .
. .
.
.
.
.....
.
.
.
.....
..
.
.
.
.
.
..
.
.
.
.
.
.
.
..
.
.
.
.
.
..
. .
. .

View File

@ -1,658 +0,0 @@
..
..
..
..
..
..
.. ..
.. ..
.. ..
.. ..
.. ..
.......
.. ..
.......
.. ..
.. ..
..
......
.. .
.....
. ..
......
..
..
.. ..
..
..
..
.. ..
..
...
.. ..
.. ..
...
.. .. .
.. ..
... ..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
......
....
......
..
..
..
......
..
..
..
..
......
..
..
..
..
..
..
..
....
.. ..
.. ...
......
... ..
.. ..
....
..
...
..
..
..
..
......
....
.. ..
..
..
..
..
......
....
.. ..
..
...
..
.. ..
....
..
...
....
.. ..
......
..
..
......
..
.....
..
..
.. ..
....
...
..
..
.....
.. ..
.. ..
....
......
..
..
..
..
..
..
....
.. ..
.. ..
....
.. ..
.. ..
....
....
.. ..
.. ..
.....
..
..
...
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
......
......
..
..
..
..
..
..
..
....
.. ..
..
..
..
..
....
.. ..
.. ...
.. . .
.. ...
..
....
....
.. ..
.. ..
......
.. ..
.. ..
.. ..
.....
.. ..
.. ..
.....
.. ..
.. ..
.....
....
.. ..
..
..
..
.. ..
....
....
.. ..
.. ..
.. ..
.. ..
.. ..
....
......
..
..
.....
..
..
......
......
..
..
.....
..
..
..
....
.. ..
..
.. ...
.. ..
.. ..
....
.. ..
.. ..
.. ..
......
.. ..
.. ..
.. ..
......
..
..
..
..
..
......
.....
..
..
..
..
.. ..
...
.. ..
.. ..
....
...
....
.. ..
.. ..
..
..
..
..
..
..
......
.. ..
... ...
.......
.. . ..
.. . ..
.. ..
.. ..
.. ..
.. ..
... ..
......
.. ...
.. ..
.. ..
....
.. ..
.. ..
.. ..
.. ..
.. ..
....
.....
.. ..
.. ..
.....
..
..
..
....
.. ..
.. ..
.. ..
.. . .
.. ..
.. ..
.....
.. ..
.. ..
.....
.. ..
.. ..
.. ..
....
.. ..
..
....
..
.. ..
....
......
..
..
..
..
..
..
.. ..
.. ..
.. ..
.. ..
.. ..
.. ..
....
.. ..
.. ..
.. ..
.. ..
.. ..
....
..
.. ..
.. ..
.. . ..
.. . ..
.......
... ...
.. ..
.. ..
.. ..
....
..
....
.. ..
.. ..
.. ..
.. ..
.. ..
....
..
..
..
......
..
..
..
..
..
......
.....
..
..
..
..
..
.....
..
..
..
..
..
.....
..
..
..
..
..
.....
..
....
.. ..
. .
...
.. ..
..
.....
..
..
......
....
..
.....
.. ..
.....
..
..
.....
.. ..
.. ..
.. ..
.....
....
.. ..
..
.. ..
....
..
..
.....
.. ..
.. ..
.. ..
.....
....
.. ..
......
..
....
...
..
..
.....
..
..
..
.....
.. ..
.. ..
.....
..
..
..
.....
.. ..
.. ..
.. ..
.. ..
..
...
..
..
..
....
..
...
..
..
..
..
..
..
.. ..
.. ..
....
.. ..
.. ..
...
..
..
..
..
..
....
.. ..
.......
.. . ..
.. . ..
.. ..
.....
.. ..
.. ..
.. ..
.. ..
....
.. ..
.. ..
.. ..
....
.....
.. ..
.. ..
.....
..
.....
.. ..
.. ..
.....
..
.. ..
... ..
..
..
..
.....
..
....
..
.....
..
..
.....
..
..
..
...
.. ..
.. ..
.. ..
.. ..
.....
.. ..
.. ..
.. ..
....
..
.. ..
.. . ..
.. . ..
.......
.. ..
.. ..
....
..
....
.. ..
.. ..
.. ..
.. ..
.....
..
......
..
..
..
......
..
..
..
...
..
..
..
..
..
..
..
..
..
..
..
..
...
..
..
..
.. .
.. . ..
. ..

View File

@ -1,15 +0,0 @@
# fonts
This folder contains bitmap fonts that are then converted to ASM data tables.
The format for them is straightforward: dots and spaces. Each line is a line in
the letter (for example, in a 6x8 font, each character is 8 lines of 6
characters each, excluding newline).
They cover the 0x21 to 0x7e range and are placed sequentially in the file.
Dots and spaces allow easy visualisation of the result and is thus rather handy.
Padding is excluded from fonts. For example, 5x7.txt is actually a 6x8 font, but
because characters are always padded, it's useless to keep systematic blank
lines or rows around.

View File

@ -1,7 +1,5 @@
MEMDUMP_TGT = memdump MEMDUMP_TGT = memdump
BLKDUMP_TGT = blkdump
UPLOAD_TGT = upload UPLOAD_TGT = upload
FONTCOMPILE_TGT = fontcompile
TTYSAFE_TGT = ttysafe TTYSAFE_TGT = ttysafe
PINGPONG_TGT = pingpong PINGPONG_TGT = pingpong
BIN2C_TGT = bin2c BIN2C_TGT = bin2c
@ -9,7 +7,7 @@ EXEC_TGT = exec
BLKPACK_TGT = blkpack BLKPACK_TGT = blkpack
BLKUNPACK_TGT = blkunpack BLKUNPACK_TGT = blkunpack
BLKUP_TGT = blkup BLKUP_TGT = blkup
TARGETS = $(MEMDUMP_TGT) $(BLKDUMP_TGT) $(UPLOAD_TGT) $(FONTCOMPILE_TGT) \ TARGETS = $(MEMDUMP_TGT) $(UPLOAD_TGT) \
$(TTYSAFE_TGT) $(PINGPONG_TGT) $(BIN2C_TGT) $(EXEC_TGT) $(BLKPACK_TGT) \ $(TTYSAFE_TGT) $(PINGPONG_TGT) $(BIN2C_TGT) $(EXEC_TGT) $(BLKPACK_TGT) \
$(BLKUNPACK_TGT) $(BLKUP_TGT) $(BLKUNPACK_TGT) $(BLKUP_TGT)
OBJS = common.o OBJS = common.o
@ -21,9 +19,7 @@ all: $(TARGETS)
$(CC) $(CFLAGS) -c $< -o $@ $(CC) $(CFLAGS) -c $< -o $@
$(MEMDUMP_TGT): $(MEMDUMP_TGT).c $(MEMDUMP_TGT): $(MEMDUMP_TGT).c
$(BLKDUMP_TGT): $(BLKDUMP_TGT).c
$(UPLOAD_TGT): $(UPLOAD_TGT).c $(UPLOAD_TGT): $(UPLOAD_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
$(BIN2C_TGT): $(BIN2C_TGT).c $(BIN2C_TGT): $(BIN2C_TGT).c

View File

@ -1,38 +0,0 @@
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include "common.h"
/* Read specified number of bytes in active blkdev at active offset.
*/
int main(int argc, char **argv)
{
if (argc != 3) {
fprintf(stderr, "Usage: ./memdump device bytecount\n");
return 1;
}
unsigned int bytecount = strtol(argv[2], NULL, 16);
if (!bytecount) {
// nothing to spit
return 0;
}
int fd = open(argv[1], O_RDWR|O_NOCTTY);
char s[0x30];
sendcmdp(fd, "i=0");
sprintf(s, "while i<0x%04x getb:puth a:i=i+1", bytecount);
sendcmd(fd, s);
for (int i=0; i<bytecount; i++) {
read(fd, s, 2); // read hex pair
s[2] = 0; // null terminate
unsigned char c = strtol(s, NULL, 16);
putchar(c);
}
read(fd, s, 2); // read prompt
return 0;
}

View File

@ -1,71 +0,0 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <libgen.h>
/* This script converts "space-dot" fonts to binary "glyph rows". One byte for
* each row. In a 5x7 font, each glyph thus use 7 bytes.
* Resulting bytes are aligned to the **left** of the byte. Therefore, for
* a 5-bit wide char, ". . ." translates to 0b10101000
* Left-aligned bytes are easier to work with when compositing glyphs.
*/
int main(int argc, char **argv)
{
if (argc != 2) {
fprintf(stderr, "Usage: ./fontcompile fpath\n");
return 1;
}
char *fn = basename(argv[1]);
if (!fn) {
return 1;
}
int w = 0;
if ((fn[0] >= '3') && (fn[0] <= '8')) {
w = fn[0] - '0';
}
int h = 0;
if ((fn[2] >= '3') && (fn[2] <= '8')) {
h = fn[2] - '0';
}
if (!w || !h || fn[1] != 'x') {
fprintf(stderr, "Not a font filename: (3-8)x(3-8).txt.\n");
return 1;
}
fprintf(stderr, "Reading a %d x %d font\n", w, h);
FILE *fp = fopen(argv[1], "r");
if (!fp) {
fprintf(stderr, "Can't open %s.\n", argv[1]);
return 1;
}
// We start the binary data with our first char, space, which is not in our
// input but needs to be in our output.
for (int i=0; i<h; i++) {
putchar(0);
}
int lineno = 1;
char buf[0x10];
while (fgets(buf, 0x10, fp)) {
size_t l = strlen(buf);
if (l > w+1) { // +1 because of the newline char.
fprintf(stderr, "Line %d too long.\n", lineno);
fclose(fp);
return 1;
}
// line can be narrower than width. It's padded with spaces.
while (l < w+1) {
buf[l] = ' ';
l++;
}
unsigned char c = 0;
for (int i=0; i<w; i++) {
if (buf[i] == '.') {
c |= (1 << (7-i));
}
}
putchar(c);
lineno++;
}
fclose(fp);
return 0;
}