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

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.
This commit is contained in:
Virgil Dupras 2020-05-23 14:20:50 -04:00
parent 1d4b75add2
commit 08b0c56ff6
2 changed files with 28 additions and 20 deletions

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. 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. 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? ## 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 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 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 `forth.bin` is modified, try resetting it and then run `make clean all`. Things
should go better afterwards. 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` If that doesn't work, there's also the nuclear option of `git reset --hard`
and `git clean -fxd`. and `git clean -fxd`.

View File

@ -5,6 +5,8 @@
#include <termios.h> #include <termios.h>
#include "emul.h" #include "emul.h"
#define WCOLS 80
#define WLINES 32
// in sync with glue.asm // in sync with glue.asm
#define RAMSTART 0x900 #define RAMSTART 0x900
#define STDIO_PORT 0x00 #define STDIO_PORT 0x00
@ -18,6 +20,7 @@
static FILE *fp; static FILE *fp;
static int retcode = 0; static int retcode = 0;
WINDOW *bw, *w;
static uint8_t iord_stdio() static uint8_t iord_stdio()
{ {
@ -25,7 +28,7 @@ static uint8_t iord_stdio()
if (fp != NULL) { if (fp != NULL) {
c = getc(fp); c = getc(fp);
} else { } else {
c = getch(); c = wgetch(w);
} }
if (c == EOF) { if (c == EOF) {
c = 4; // ASCII EOT c = 4; // ASCII EOT
@ -39,7 +42,7 @@ static void iowr_stdio(uint8_t val)
putchar(val); putchar(val);
} else { } else {
if (val >= 0x20 || val == '\n') { if (val >= 0x20 || val == '\n') {
echochar(val); wechochar(w, val);
} }
} }
} }
@ -49,7 +52,7 @@ static void iowr_ret(uint8_t val)
retcode = val; retcode = val;
} }
int run() int main(int argc, char *argv[])
{ {
Machine *m = emul_init(); Machine *m = emul_init();
if (m == NULL) { if (m == NULL) {
@ -59,35 +62,31 @@ int run()
m->iord[STDIO_PORT] = iord_stdio; m->iord[STDIO_PORT] = iord_stdio;
m->iowr[STDIO_PORT] = iowr_stdio; m->iowr[STDIO_PORT] = iowr_stdio;
m->iowr[RET_PORT] = iowr_ret; m->iowr[RET_PORT] = iowr_ret;
// Run! w = NULL;
while (emul_step());
emul_deinit();
return retcode;
}
int main(int argc, char *argv[])
{
if (argc == 2) { if (argc == 2) {
fp = fopen(argv[1], "r"); fp = fopen(argv[1], "r");
if (fp == NULL) { if (fp == NULL) {
fprintf(stderr, "Can't open %s\n", argv[1]); fprintf(stderr, "Can't open %s\n", argv[1]);
return 1; return 1;
} }
int ret = run(); while (emul_step());
fclose(fp); fclose(fp);
return ret;
} else if (argc == 1) { } else if (argc == 1) {
fp = NULL; fp = NULL;
initscr(); cbreak(); noecho(); nl(); clear(); initscr(); cbreak(); noecho(); nl(); clear();
scrollok(stdscr, 1); bw = newwin(WLINES+2, WCOLS+2, 0, 0);
int ret = run(); wborder(bw, 0, 0, 0, 0, 0, 0, 0, 0);
nocbreak(); echo(); endwin(); wrefresh(bw);
w = newwin(WLINES, WCOLS, 1, 1);
scrollok(w, 1);
while (emul_step());
nocbreak(); echo(); delwin(w); delwin(bw); endwin();
printf("\nDone!\n"); printf("\nDone!\n");
emul_printdebug(); emul_printdebug();
return ret;
} else { } else {
fprintf(stderr, "Usage: ./forth [filename]\n"); fprintf(stderr, "Usage: ./forth [filename]\n");
return 1; retcode = 1;
} }
emul_deinit();
return retcode;
} }