From 23f0dc18ca6920a0a12896dde40ed242698d01c9 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Thu, 16 May 2019 12:07:57 -0400 Subject: [PATCH] zasm emul: add tooling for includes fsdev On build, pack `parts/z80` into a CFS and embed it into the emulated zasm executable as an fsdev. This will allow for the upcoming include directive to have something to go to. For now, this is useless except for inflating the emulated zasm's size. --- tools/emul/.gitignore | 1 + tools/emul/Makefile | 13 ++++++++++--- tools/emul/zasm.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 57 insertions(+), 6 deletions(-) diff --git a/tools/emul/.gitignore b/tools/emul/.gitignore index ca936d9..b485ee4 100644 --- a/tools/emul/.gitignore +++ b/tools/emul/.gitignore @@ -1,5 +1,6 @@ /shell /zasm +/zasm-includes.h /*-kernel.h /*-user.h /cfsin diff --git a/tools/emul/Makefile b/tools/emul/Makefile index 52804eb..d3ba997 100644 --- a/tools/emul/Makefile +++ b/tools/emul/Makefile @@ -1,6 +1,7 @@ TARGETS = shell zasm KERNEL_HEADERS = shell-kernel.h zasm-kernel.h USER_HEADERS = zasm-user.h +CFSPACK = ../cfspack/cfspack .PHONY: all all: $(TARGETS) @@ -13,8 +14,14 @@ $(KERNEL_HEADERS): zasm-user.h: zasm_user.asm scas -o - -I ../../apps/zasm $< | ./bin2c.sh USERSPACE | tee $@ > /dev/null -shell: shell.c libz80/libz80.o shell-kernel.h ../cfspack/cfspack -zasm: zasm.c libz80/libz80.o zasm-kernel.h zasm-user.h +zasm-includes.h: ../../parts/z80 $(CFSPACK) + cp -rf $< zasm-includes + rm zasm-includes/README.md + $(CFSPACK) zasm-includes | ./bin2c.sh FSDEV | tee $@ > /dev/null + rm -rf zasm-includes + +shell: shell.c libz80/libz80.o shell-kernel.h $(CFSPACK) +zasm: zasm.c libz80/libz80.o zasm-kernel.h zasm-user.h zasm-includes.h $(TARGETS): cc $< libz80/libz80.o -o $@ @@ -22,7 +29,7 @@ libz80/libz80.o: libz80/z80.c make -C libz80/codegen opcodes gcc -Wall -ansi -g -c -o libz80/libz80.o libz80/z80.c -../cfspack/cfspack: +$(CFSPACK): make -C ../cfspack .PHONY: clean diff --git a/tools/emul/zasm.c b/tools/emul/zasm.c index a74d2fa..b651e2f 100644 --- a/tools/emul/zasm.c +++ b/tools/emul/zasm.c @@ -3,6 +3,7 @@ #include "libz80/z80.h" #include "zasm-kernel.h" #include "zasm-user.h" +#include "zasm-includes.h" /* zasm reads from a specified blkdev, assemble the file and writes the result * in another specified blkdev. In our emulator layer, we use stdin and stdout @@ -27,7 +28,9 @@ // in sync with zasm_glue.asm #define USER_CODE 0x4800 #define STDIO_PORT 0x00 -#define STDIN_SEEK 0x01 +#define STDIN_SEEK_PORT 0x01 +#define FS_DATA_PORT 0x02 +#define FS_SEEK_PORT 0x03 // Other consts #define STDIN_BUFSIZE 0x8000 @@ -43,6 +46,11 @@ static int inpt_size; static int inpt_ptr; static uint8_t middle_of_seek_tell = 0; +static uint8_t fsdev[0xffff] = {0}; +static uint16_t fsdev_size = 0; +static uint16_t fsdev_ptr = 0; +static uint8_t fsdev_middle_of_seek_tell = 0; + static uint8_t io_read(int unused, uint16_t addr) { addr &= 0xff; @@ -52,7 +60,7 @@ static uint8_t io_read(int unused, uint16_t addr) } else { return 0; } - } else if (addr == STDIN_SEEK) { + } else if (addr == STDIN_SEEK_PORT) { if (middle_of_seek_tell) { middle_of_seek_tell = 0; return inpt_ptr & 0xff; @@ -63,6 +71,23 @@ static uint8_t io_read(int unused, uint16_t addr) middle_of_seek_tell = 1; return inpt_ptr >> 8; } + } else if (addr == FS_DATA_PORT) { + if (fsdev_ptr < fsdev_size) { + return fsdev[fsdev_ptr++]; + } else { + return 0; + } + } else if (addr == FS_SEEK_PORT) { + if (fsdev_middle_of_seek_tell) { + fsdev_middle_of_seek_tell = 0; + return fsdev_ptr & 0xff; + } else { +#ifdef DEBUG + fprintf(stderr, "tell %d\n", fsdev_ptr); +#endif + fsdev_middle_of_seek_tell = 1; + return fsdev_ptr >> 8; + } } else { fprintf(stderr, "Out of bounds I/O read: %d\n", addr); return 0; @@ -77,7 +102,7 @@ static void io_write(int unused, uint16_t addr, uint8_t val) #ifndef MEMDUMP putchar(val); #endif - } else if (addr == STDIN_SEEK) { + } else if (addr == STDIN_SEEK_PORT) { if (middle_of_seek_tell) { inpt_ptr |= val; middle_of_seek_tell = 0; @@ -88,6 +113,21 @@ static void io_write(int unused, uint16_t addr, uint8_t val) inpt_ptr = (val << 8) & 0xff00; middle_of_seek_tell = 1; } + } else if (addr == FS_DATA_PORT) { + if (fsdev_ptr < fsdev_size) { + fsdev[fsdev_ptr++] = val; + } + } else if (addr == FS_SEEK_PORT) { + if (fsdev_middle_of_seek_tell) { + fsdev_ptr |= val; + fsdev_middle_of_seek_tell = 0; +#ifdef DEBUG + fprintf(stderr, "seek %d\n", fsdev_ptr); +#endif + } else { + fsdev_ptr = (val << 8) & 0xff00; + fsdev_middle_of_seek_tell = 1; + } } else { fprintf(stderr, "Out of bounds I/O write: %d / %d\n", addr, val); } @@ -112,6 +152,9 @@ int main() for (int i=0; i