mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-27 14:18:06 +11:00
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:
parent
22c7eeaa5d
commit
23f0dc18ca
1
tools/emul/.gitignore
vendored
1
tools/emul/.gitignore
vendored
@ -1,5 +1,6 @@
|
|||||||
/shell
|
/shell
|
||||||
/zasm
|
/zasm
|
||||||
|
/zasm-includes.h
|
||||||
/*-kernel.h
|
/*-kernel.h
|
||||||
/*-user.h
|
/*-user.h
|
||||||
/cfsin
|
/cfsin
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
TARGETS = shell zasm
|
TARGETS = shell zasm
|
||||||
KERNEL_HEADERS = shell-kernel.h zasm-kernel.h
|
KERNEL_HEADERS = shell-kernel.h zasm-kernel.h
|
||||||
USER_HEADERS = zasm-user.h
|
USER_HEADERS = zasm-user.h
|
||||||
|
CFSPACK = ../cfspack/cfspack
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: $(TARGETS)
|
all: $(TARGETS)
|
||||||
@ -13,8 +14,14 @@ $(KERNEL_HEADERS):
|
|||||||
zasm-user.h: zasm_user.asm
|
zasm-user.h: zasm_user.asm
|
||||||
scas -o - -I ../../apps/zasm $< | ./bin2c.sh USERSPACE | tee $@ > /dev/null
|
scas -o - -I ../../apps/zasm $< | ./bin2c.sh USERSPACE | tee $@ > /dev/null
|
||||||
|
|
||||||
shell: shell.c libz80/libz80.o shell-kernel.h ../cfspack/cfspack
|
zasm-includes.h: ../../parts/z80 $(CFSPACK)
|
||||||
zasm: zasm.c libz80/libz80.o zasm-kernel.h zasm-user.h
|
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):
|
$(TARGETS):
|
||||||
cc $< libz80/libz80.o -o $@
|
cc $< libz80/libz80.o -o $@
|
||||||
|
|
||||||
@ -22,7 +29,7 @@ libz80/libz80.o: libz80/z80.c
|
|||||||
make -C libz80/codegen opcodes
|
make -C libz80/codegen opcodes
|
||||||
gcc -Wall -ansi -g -c -o libz80/libz80.o libz80/z80.c
|
gcc -Wall -ansi -g -c -o libz80/libz80.o libz80/z80.c
|
||||||
|
|
||||||
../cfspack/cfspack:
|
$(CFSPACK):
|
||||||
make -C ../cfspack
|
make -C ../cfspack
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "libz80/z80.h"
|
#include "libz80/z80.h"
|
||||||
#include "zasm-kernel.h"
|
#include "zasm-kernel.h"
|
||||||
#include "zasm-user.h"
|
#include "zasm-user.h"
|
||||||
|
#include "zasm-includes.h"
|
||||||
|
|
||||||
/* zasm reads from a specified blkdev, assemble the file and writes the result
|
/* 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
|
* in another specified blkdev. In our emulator layer, we use stdin and stdout
|
||||||
@ -27,7 +28,9 @@
|
|||||||
// in sync with zasm_glue.asm
|
// in sync with zasm_glue.asm
|
||||||
#define USER_CODE 0x4800
|
#define USER_CODE 0x4800
|
||||||
#define STDIO_PORT 0x00
|
#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
|
// Other consts
|
||||||
#define STDIN_BUFSIZE 0x8000
|
#define STDIN_BUFSIZE 0x8000
|
||||||
@ -43,6 +46,11 @@ static int inpt_size;
|
|||||||
static int inpt_ptr;
|
static int inpt_ptr;
|
||||||
static uint8_t middle_of_seek_tell = 0;
|
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)
|
static uint8_t io_read(int unused, uint16_t addr)
|
||||||
{
|
{
|
||||||
addr &= 0xff;
|
addr &= 0xff;
|
||||||
@ -52,7 +60,7 @@ static uint8_t io_read(int unused, uint16_t addr)
|
|||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else if (addr == STDIN_SEEK) {
|
} else if (addr == STDIN_SEEK_PORT) {
|
||||||
if (middle_of_seek_tell) {
|
if (middle_of_seek_tell) {
|
||||||
middle_of_seek_tell = 0;
|
middle_of_seek_tell = 0;
|
||||||
return inpt_ptr & 0xff;
|
return inpt_ptr & 0xff;
|
||||||
@ -63,6 +71,23 @@ static uint8_t io_read(int unused, uint16_t addr)
|
|||||||
middle_of_seek_tell = 1;
|
middle_of_seek_tell = 1;
|
||||||
return inpt_ptr >> 8;
|
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 {
|
} else {
|
||||||
fprintf(stderr, "Out of bounds I/O read: %d\n", addr);
|
fprintf(stderr, "Out of bounds I/O read: %d\n", addr);
|
||||||
return 0;
|
return 0;
|
||||||
@ -77,7 +102,7 @@ static void io_write(int unused, uint16_t addr, uint8_t val)
|
|||||||
#ifndef MEMDUMP
|
#ifndef MEMDUMP
|
||||||
putchar(val);
|
putchar(val);
|
||||||
#endif
|
#endif
|
||||||
} else if (addr == STDIN_SEEK) {
|
} else if (addr == STDIN_SEEK_PORT) {
|
||||||
if (middle_of_seek_tell) {
|
if (middle_of_seek_tell) {
|
||||||
inpt_ptr |= val;
|
inpt_ptr |= val;
|
||||||
middle_of_seek_tell = 0;
|
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;
|
inpt_ptr = (val << 8) & 0xff00;
|
||||||
middle_of_seek_tell = 1;
|
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 {
|
} else {
|
||||||
fprintf(stderr, "Out of bounds I/O write: %d / %d\n", addr, val);
|
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++) {
|
for (int i=0; i<sizeof(USERSPACE); i++) {
|
||||||
mem[i+USER_CODE] = USERSPACE[i];
|
mem[i+USER_CODE] = USERSPACE[i];
|
||||||
}
|
}
|
||||||
|
for (int i=0; i<sizeof(FSDEV); i++) {
|
||||||
|
fsdev[i] = FSDEV[i];
|
||||||
|
}
|
||||||
// read stdin in buffer
|
// read stdin in buffer
|
||||||
inpt_size = 0;
|
inpt_size = 0;
|
||||||
inpt_ptr = 0;
|
inpt_ptr = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user