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.
This commit is contained in:
Virgil Dupras 2019-05-16 12:07:57 -04:00
parent 22c7eeaa5d
commit 23f0dc18ca
3 changed files with 57 additions and 6 deletions

View File

@ -1,5 +1,6 @@
/shell
/zasm
/zasm-includes.h
/*-kernel.h
/*-user.h
/cfsin

View File

@ -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

View File

@ -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<sizeof(USERSPACE); i++) {
mem[i+USER_CODE] = USERSPACE[i];
}
for (int i=0; i<sizeof(FSDEV); i++) {
fsdev[i] = FSDEV[i];
}
// read stdin in buffer
inpt_size = 0;
inpt_ptr = 0;