mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-02 08:30:55 +11:00
Compare commits
No commits in common. "8d3da4c0de00d5c7f4b98cc0710cb23c0af20624" and "d041b91846bc8906206212ab118602c7df9f7f96" have entirely different histories.
8d3da4c0de
...
d041b91846
@ -1,4 +1,4 @@
|
|||||||
TARGETS = forth stage blkfs
|
TARGETS = forth stage
|
||||||
OBJS = emul.o libz80/libz80.o
|
OBJS = emul.o libz80/libz80.o
|
||||||
BIN2C = ../tools/bin2c
|
BIN2C = ../tools/bin2c
|
||||||
BLKPACK = ../tools/blkpack
|
BLKPACK = ../tools/blkpack
|
||||||
@ -18,14 +18,17 @@ $(BLKUNPACK): $(BLKPACK)
|
|||||||
forth-bin.h: $(BIN2C)
|
forth-bin.h: $(BIN2C)
|
||||||
$(BIN2C) KERNEL < forth.bin > $@
|
$(BIN2C) KERNEL < forth.bin > $@
|
||||||
|
|
||||||
stage: stage.c $(OBJS) forth-bin.h
|
stage: stage.c $(OBJS) forth-bin.h blkfs-bin.h
|
||||||
$(CC) stage.c -DBLKFS_PATH=\"`pwd`/blkfs\" $(OBJS) -o $@
|
$(CC) stage.c $(OBJS) -o $@
|
||||||
|
|
||||||
blkfs: $(BLKPACK)
|
blkfs: $(BLKPACK)
|
||||||
$(BLKPACK) ../blk > $@
|
$(BLKPACK) ../blk > $@
|
||||||
|
|
||||||
forth: forth.c $(OBJS) forth-bin.h
|
blkfs-bin.h: blkfs $(BIN2C)
|
||||||
$(CC) forth.c -DBLKFS_PATH=\"`pwd`/blkfs\" $(OBJS) -lncurses -o $@
|
$(BIN2C) BLKFS < blkfs > $@
|
||||||
|
|
||||||
|
forth: forth.c $(OBJS) forth-bin.h blkfs-bin.h
|
||||||
|
$(CC) forth.c $(OBJS) -o $@
|
||||||
|
|
||||||
libz80/libz80.o: libz80/z80.c
|
libz80/libz80.o: libz80/z80.c
|
||||||
$(MAKE) -C libz80/codegen opcodes
|
$(MAKE) -C libz80/codegen opcodes
|
||||||
@ -36,7 +39,7 @@ emul.o: emul.c
|
|||||||
|
|
||||||
|
|
||||||
.PHONY: updatebootstrap
|
.PHONY: updatebootstrap
|
||||||
updatebootstrap: stage xcomp.fs pack
|
updatebootstrap: stage xcomp.fs
|
||||||
./stage < xcomp.fs > forth.bin
|
./stage < xcomp.fs > forth.bin
|
||||||
|
|
||||||
.PHONY: pack
|
.PHONY: pack
|
||||||
@ -49,4 +52,5 @@ unpack:
|
|||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm -f $(TARGETS) emul.o *-bin.h blkfs
|
rm -f $(TARGETS) emul.o *-bin.h stage{1,2}.bin blkfs
|
||||||
|
$(MAKE) -C ../tools clean
|
||||||
|
@ -3,11 +3,6 @@
|
|||||||
This folder contains a couple of tools running under the [libz80][libz80]
|
This folder contains a couple of tools running under the [libz80][libz80]
|
||||||
emulator.
|
emulator.
|
||||||
|
|
||||||
## Requirements
|
|
||||||
|
|
||||||
You need `ncurses` to build the `forth` executable. In debian-based distros,
|
|
||||||
it's `libncurses5-dev`.
|
|
||||||
|
|
||||||
## Not real hardware
|
## Not real hardware
|
||||||
|
|
||||||
In the few emulated apps described below, we don't try to emulate real hardware
|
In the few emulated apps described below, we don't try to emulate real hardware
|
||||||
@ -25,7 +20,7 @@ First, make sure that the `libz80` git submodule is checked out. If not, run
|
|||||||
|
|
||||||
After that, you can run `make` and it builds the `forth` interpreter.
|
After that, you can run `make` and it builds the `forth` interpreter.
|
||||||
|
|
||||||
Run `./forth` to get the Collapse OS prompt. Type `0 LIST` for help.
|
Run `./forth` to get the COllapse OS prompt. Type `0 LIST` for help.
|
||||||
|
|
||||||
## Problems?
|
## Problems?
|
||||||
|
|
||||||
|
91
emul/forth.c
91
emul/forth.c
@ -1,10 +1,10 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <curses.h>
|
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include "emul.h"
|
#include "emul.h"
|
||||||
#include "forth-bin.h"
|
#include "forth-bin.h"
|
||||||
|
#include "blkfs-bin.h"
|
||||||
|
|
||||||
// in sync with glue.asm
|
// in sync with glue.asm
|
||||||
#define RAMSTART 0x900
|
#define RAMSTART 0x900
|
||||||
@ -24,12 +24,7 @@ static uint16_t blkid = 0;
|
|||||||
|
|
||||||
static uint8_t iord_stdio()
|
static uint8_t iord_stdio()
|
||||||
{
|
{
|
||||||
int c;
|
int c = getc(fp);
|
||||||
if (fp != NULL) {
|
|
||||||
c = getc(fp);
|
|
||||||
} else {
|
|
||||||
c = getch();
|
|
||||||
}
|
|
||||||
if (c == EOF) {
|
if (c == EOF) {
|
||||||
c = 4; // ASCII EOT
|
c = 4; // ASCII EOT
|
||||||
}
|
}
|
||||||
@ -38,13 +33,7 @@ static uint8_t iord_stdio()
|
|||||||
|
|
||||||
static void iowr_stdio(uint8_t val)
|
static void iowr_stdio(uint8_t val)
|
||||||
{
|
{
|
||||||
if (fp != NULL) {
|
|
||||||
putchar(val);
|
putchar(val);
|
||||||
} else {
|
|
||||||
if (val >= 0x20 || val == '\n') {
|
|
||||||
echochar(val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void iowr_ret(uint8_t val)
|
static void iowr_ret(uint8_t val)
|
||||||
@ -80,17 +69,41 @@ static void iowr_blkdata(uint8_t val)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int run()
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
#ifdef BLKFS_PATH
|
bool tty = false;
|
||||||
fprintf(stderr, "Using blkfs %s\n", BLKFS_PATH);
|
struct termios termInfo;
|
||||||
blkfp = fopen(BLKFS_PATH, "r+");
|
if (argc == 2) {
|
||||||
if (!blkfp) {
|
fp = fopen(argv[1], "r");
|
||||||
fprintf(stderr, "Can't open\n");
|
if (fp == NULL) {
|
||||||
|
fprintf(stderr, "Can't open %s\n", argv[1]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} else if (argc == 1) {
|
||||||
|
fp = stdin;
|
||||||
|
tty = isatty(fileno(stdin));
|
||||||
|
if (tty) {
|
||||||
|
// Turn echo off: the shell takes care of its own echoing.
|
||||||
|
if (tcgetattr(0, &termInfo) == -1) {
|
||||||
|
printf("Can't setup terminal.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
termInfo.c_lflag &= ~ECHO;
|
||||||
|
termInfo.c_lflag &= ~ICANON;
|
||||||
|
tcsetattr(0, TCSAFLUSH, &termInfo);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Usage: ./forth [filename]\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
blkfp = fopen("blkfs", "r+");
|
||||||
|
if (blkfp) {
|
||||||
|
fprintf(stderr, "Using blkfs file\n");
|
||||||
|
} else {
|
||||||
|
blkfp = fmemopen((char*)BLKFS, sizeof(BLKFS), "r");
|
||||||
|
fprintf(stderr, "Using in-memory read-only blkfs\n");
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
blkfp = NULL;
|
|
||||||
#endif
|
|
||||||
Machine *m = emul_init();
|
Machine *m = emul_init();
|
||||||
m->ramstart = RAMSTART;
|
m->ramstart = RAMSTART;
|
||||||
m->iord[STDIO_PORT] = iord_stdio;
|
m->iord[STDIO_PORT] = iord_stdio;
|
||||||
@ -107,34 +120,16 @@ int run()
|
|||||||
// Run!
|
// Run!
|
||||||
while (emul_step());
|
while (emul_step());
|
||||||
|
|
||||||
|
if (tty) {
|
||||||
|
printf("\nDone!\n");
|
||||||
|
termInfo.c_lflag |= ECHO;
|
||||||
|
termInfo.c_lflag |= ICANON;
|
||||||
|
tcsetattr(0, TCSAFLUSH, &termInfo);
|
||||||
|
emul_printdebug();
|
||||||
|
}
|
||||||
if (blkfp != NULL) {
|
if (blkfp != NULL) {
|
||||||
fclose(blkfp);
|
fclose(blkfp);
|
||||||
}
|
}
|
||||||
|
fclose(fp);
|
||||||
return retcode;
|
return retcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
if (argc == 2) {
|
|
||||||
fp = fopen(argv[1], "r");
|
|
||||||
if (fp == NULL) {
|
|
||||||
fprintf(stderr, "Can't open %s\n", argv[1]);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
int ret = run();
|
|
||||||
fclose(fp);
|
|
||||||
return ret;
|
|
||||||
} else if (argc == 1) {
|
|
||||||
fp = NULL;
|
|
||||||
initscr(); cbreak(); noecho(); nl(); clear();
|
|
||||||
scrollok(stdscr, 1);
|
|
||||||
int ret = run();
|
|
||||||
nocbreak(); echo(); endwin();
|
|
||||||
printf("\nDone!\n");
|
|
||||||
emul_printdebug();
|
|
||||||
return ret;
|
|
||||||
} else {
|
|
||||||
fprintf(stderr, "Usage: ./forth [filename]\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
17
emul/stage.c
17
emul/stage.c
@ -3,10 +3,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "emul.h"
|
#include "emul.h"
|
||||||
#include "forth-bin.h"
|
#include "forth-bin.h"
|
||||||
|
#include "blkfs-bin.h"
|
||||||
#ifndef BLKFS_PATH
|
|
||||||
#error BLKFS_PATH needed
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Staging binaries
|
/* Staging binaries
|
||||||
|
|
||||||
@ -40,7 +37,7 @@ static int running;
|
|||||||
static uint16_t start_here = 0;
|
static uint16_t start_here = 0;
|
||||||
static uint16_t end_here = 0;
|
static uint16_t end_here = 0;
|
||||||
static uint16_t blkid = 0;
|
static uint16_t blkid = 0;
|
||||||
static FILE *blkfp;
|
static unsigned int blkpos = 0;
|
||||||
|
|
||||||
static uint8_t iord_stdio()
|
static uint8_t iord_stdio()
|
||||||
{
|
{
|
||||||
@ -68,22 +65,16 @@ static void iowr_blk(uint8_t val)
|
|||||||
{
|
{
|
||||||
blkid <<= 8;
|
blkid <<= 8;
|
||||||
blkid |= val;
|
blkid |= val;
|
||||||
fseek(blkfp, blkid*1024, SEEK_SET);
|
blkpos = blkid * 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t iord_blkdata()
|
static uint8_t iord_blkdata()
|
||||||
{
|
{
|
||||||
return getc(blkfp);
|
return BLKFS[blkpos++];
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Using blkfs %s\n", BLKFS_PATH);
|
|
||||||
blkfp = fopen(BLKFS_PATH, "r+");
|
|
||||||
if (!blkfp) {
|
|
||||||
fprintf(stderr, "Can't open\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
Machine *m = emul_init();
|
Machine *m = emul_init();
|
||||||
m->ramstart = RAMSTART;
|
m->ramstart = RAMSTART;
|
||||||
m->iord[STDIO_PORT] = iord_stdio;
|
m->iord[STDIO_PORT] = iord_stdio;
|
||||||
|
Loading…
Reference in New Issue
Block a user