Browse Source

emul: run Collapse OS inside a limited, fixed window

This will allow us to implement AT-XY, paving the way to all sorts
of nice new things.
pull/103/head
Virgil Dupras 4 years ago
parent
commit
08b0c56ff6
2 changed files with 28 additions and 20 deletions
  1. +10
    -1
      emul/README.md
  2. +18
    -19
      emul/forth.c

+ 10
- 1
emul/README.md View File

@@ -25,16 +25,25 @@ 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.

## Usage

Run `./forth` to get the Collapse OS prompt. Type `0 LIST` for help.

The program is a curses interface with a limited, fixed size so that it can
provide a AT-XY interface (which is yet to implement).

## Problems?

If the libz80-wrapped zasm executable works badly (hangs, spew garbage, etc.),
If the `forth` executable works badly (hangs, spew garbage, etc.),
it's probably because you've broken your bootstrap binaries. They're easy to
mistakenly break. To verify if you've done that, look at your git status. If
`forth.bin` is modified, try resetting it and then run `make clean all`. Things
should go better afterwards.

A modified `blkfs` can also break things (although even with a completely broken
blkfs, you should still get to prompt), you might want to run `make pack` to
ensure that the `blkfs` file is in sync with the contents of the `blk/` folder.

If that doesn't work, there's also the nuclear option of `git reset --hard`
and `git clean -fxd`.



+ 18
- 19
emul/forth.c View File

@@ -5,6 +5,8 @@
#include <termios.h>
#include "emul.h"

#define WCOLS 80
#define WLINES 32
// in sync with glue.asm
#define RAMSTART 0x900
#define STDIO_PORT 0x00
@@ -18,6 +20,7 @@

static FILE *fp;
static int retcode = 0;
WINDOW *bw, *w;

static uint8_t iord_stdio()
{
@@ -25,7 +28,7 @@ static uint8_t iord_stdio()
if (fp != NULL) {
c = getc(fp);
} else {
c = getch();
c = wgetch(w);
}
if (c == EOF) {
c = 4; // ASCII EOT
@@ -39,7 +42,7 @@ static void iowr_stdio(uint8_t val)
putchar(val);
} else {
if (val >= 0x20 || val == '\n') {
echochar(val);
wechochar(w, val);
}
}
}
@@ -49,7 +52,7 @@ static void iowr_ret(uint8_t val)
retcode = val;
}

int run()
int main(int argc, char *argv[])
{
Machine *m = emul_init();
if (m == NULL) {
@@ -59,35 +62,31 @@ int run()
m->iord[STDIO_PORT] = iord_stdio;
m->iowr[STDIO_PORT] = iowr_stdio;
m->iowr[RET_PORT] = iowr_ret;
// Run!
while (emul_step());

emul_deinit();
return retcode;
}

int main(int argc, char *argv[])
{
w = NULL;
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();
while (emul_step());
fclose(fp);
return ret;
} else if (argc == 1) {
fp = NULL;
initscr(); cbreak(); noecho(); nl(); clear();
scrollok(stdscr, 1);
int ret = run();
nocbreak(); echo(); endwin();
bw = newwin(WLINES+2, WCOLS+2, 0, 0);
wborder(bw, 0, 0, 0, 0, 0, 0, 0, 0);
wrefresh(bw);
w = newwin(WLINES, WCOLS, 1, 1);
scrollok(w, 1);
while (emul_step());
nocbreak(); echo(); delwin(w); delwin(bw); endwin();
printf("\nDone!\n");
emul_printdebug();
return ret;
} else {
fprintf(stderr, "Usage: ./forth [filename]\n");
return 1;
retcode = 1;
}
emul_deinit();
return retcode;
}

Loading…
Cancel
Save