From 88cee235b1de6aed0ce0ad5b0be30bc6416dbd5f Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Tue, 16 Apr 2019 14:26:45 -0400 Subject: [PATCH] zasm: have a whole kernel in emulation instead of a simple wrapper zasm is going to need to call to kernel code... --- apps/zasm/emul/.gitignore | 2 +- apps/zasm/emul/Makefile | 6 +++--- apps/zasm/emul/glue.asm | 22 ++++++++++++++++++++++ apps/zasm/emul/wrapper.asm | 15 --------------- apps/zasm/emul/zasm.c | 19 +++++++++---------- 5 files changed, 35 insertions(+), 29 deletions(-) create mode 100644 apps/zasm/emul/glue.asm delete mode 100644 apps/zasm/emul/wrapper.asm diff --git a/apps/zasm/emul/.gitignore b/apps/zasm/emul/.gitignore index e4c0035..367abc6 100644 --- a/apps/zasm/emul/.gitignore +++ b/apps/zasm/emul/.gitignore @@ -1,4 +1,4 @@ libz80 -wrapper.h +kernel.h zasm.h zasm diff --git a/apps/zasm/emul/Makefile b/apps/zasm/emul/Makefile index a22e427..34b0740 100644 --- a/apps/zasm/emul/Makefile +++ b/apps/zasm/emul/Makefile @@ -1,11 +1,11 @@ -zasm: zasm.c libz80/libz80.so wrapper.h zasm.h +zasm: zasm.c libz80/libz80.so kernel.h zasm.h cc $< -l z80 -L./libz80 -Wl,-rpath ./libz80 -o $@ libz80/libz80.so: libz80/Makefile make -C libz80 -wrapper.h: wrapper.asm - scas -o - $< | ./bin2c.sh WRAPPER > $@ +kernel.h: glue.asm + scas -o - $< | ./bin2c.sh KERNEL > $@ zasm.h: ../zasm.asm scas -o - $< | ./bin2c.sh ZASM > $@ diff --git a/apps/zasm/emul/glue.asm b/apps/zasm/emul/glue.asm new file mode 100644 index 0000000..24966d6 --- /dev/null +++ b/apps/zasm/emul/glue.asm @@ -0,0 +1,22 @@ +; Glue code for the emulated environment +RAMSTART .equ 0x8000 +RAMEND .equ 0xffff +ZASM_CODE .equ RAMSTART +ZASM_INPUT .equ 0xa000 +ZASM_OUTPUT .equ 0xd000 + +jr init +init: + di + ld hl, RAMEND + ld sp, hl + ld hl, ZASM_INPUT + ld de, ZASM_OUTPUT + call ZASM_CODE + ; signal the emulator we're done + ; BC contains the number of written bytes + ld a, b + out (c), a + halt + +#include "core.asm" diff --git a/apps/zasm/emul/wrapper.asm b/apps/zasm/emul/wrapper.asm deleted file mode 100644 index 6bcb1f9..0000000 --- a/apps/zasm/emul/wrapper.asm +++ /dev/null @@ -1,15 +0,0 @@ -; setup the stack -ld hl, 0xffff -ld sp, hl -; zasm input -ld hl, 0x9000 -; zasm output -ld de, 0xc000 -call zasm -; signal the emulator we're done -; BC contains the number of written bytes -ld a, b -out (c), a -halt -zasm: -; beginning of the code diff --git a/apps/zasm/emul/zasm.c b/apps/zasm/emul/zasm.c index 7e688cb..3cb911a 100644 --- a/apps/zasm/emul/zasm.c +++ b/apps/zasm/emul/zasm.c @@ -1,7 +1,7 @@ #include #include #include "libz80/z80.h" -#include "wrapper.h" +#include "kernel.h" #include "zasm.h" /* zasm is a "pure memory" application. It starts up being told memory location @@ -12,9 +12,10 @@ * spit the contents of the dest memory to stdout. */ -// in sync with wrapper.asm -#define READFROM 0x9000 -#define WRITETO 0xc000 +// in sync with glue.asm +#define READFROM 0xa000 +#define WRITETO 0xd000 +#define ZASM_CODE_OFFSET 0x8000 static Z80Context cpu; static uint8_t mem[0xffff]; @@ -48,13 +49,11 @@ static void mem_write(int unused, uint16_t addr, uint8_t val) int main() { // initialize memory - int wrapperlen = sizeof(WRAPPER); - for (int i=0; i