diff --git a/.gitmodules b/.gitmodules index b28b723..6b28b0b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "pat80-emulator/z80"] - path = pat80-emulator/z80 - url = git@github.com:algodesigner/z80.git +[submodule "pat80-emulator/z80-python-emulator"] + path = pat80-emulator/z80-python-emulator + url = https://github.com/penguin86/z80-python-emulator.git diff --git a/README.md b/README.md index c59c048..9aabe28 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,12 @@ There is an experimental and unfinished quick load function using a python termi ![Pat80 Memory Monitor](/assets/media/photos/memory_monitor.jpg) +## Emulator +The pat80 memory monitor (the os) can be run in a z80 emulator. This repository contains an emulator as submodule, already set up to run the os. +To try it, head to `pat80-computer/software/z80-assembly/os/Makefile` and run `make run` to build the rom from assembly and start the emulator. You will see some windows showing the emulated computer's memory and register status and the pat80 memory monitor prompt. + +![Emulator running Memory Monitor](/assets/media/photos/emulator.png) + ## Status The project is heavily work in progress. diff --git a/assets/media/photos/emulator.png b/assets/media/photos/emulator.png new file mode 100644 index 0000000..e93253d Binary files /dev/null and b/assets/media/photos/emulator.png differ diff --git a/pat80-computer/software/z80-assembly/os/Makefile b/pat80-computer/software/z80-assembly/os/Makefile index abccb39..dd56d03 100644 --- a/pat80-computer/software/z80-assembly/os/Makefile +++ b/pat80-computer/software/z80-assembly/os/Makefile @@ -1,11 +1,17 @@ -os: +build: @echo "Building PAT80 rom..." @z80asm -i main.asm -o rom.bin || (exit 1) @echo "Generating label lookup table..." @z80asm -i main.asm -o rom.bin -L 2>&1 | grep "Sys_" > abi-generated.asm @echo "PAT80 Rom size:" @du -h rom.bin + +write: build @echo "Stretching rom to EEPROM size..." @dd if=/dev/zero of=rom.bin bs=1 count=0 seek=8192 @echo "Writing to EEPROM..." @minipro -w rom.bin -p "AT28C64B" + +run: build + @echo "Starting emulator..." + @../../../../pat80-emulator/z80-python-emulator/src/z80sbc.py -b rom.bin diff --git a/pat80-emulator/.gitignore b/pat80-emulator/.gitignore deleted file mode 100644 index 5eb94e9..0000000 --- a/pat80-emulator/.gitignore +++ /dev/null @@ -1 +0,0 @@ -pat80emu diff --git a/pat80-emulator/Makefile b/pat80-emulator/Makefile deleted file mode 100644 index c75bc5a..0000000 --- a/pat80-emulator/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -build: - gcc -g -o pat80emu z80/console.c z80/z80.c main.c -clean: - rm -rf main -all: clean build diff --git a/pat80-emulator/README.md b/pat80-emulator/README.md index c5f5489..4d15da9 100644 --- a/pat80-emulator/README.md +++ b/pat80-emulator/README.md @@ -1,9 +1,7 @@ # PAT80 Emulator -Uses algodesigner's Z80 emulator (see submodule in z80 folder). -Instances the Z80 object (representing the CPU) and: -- intercepts all memory access and returns the corresponding rom value (read from rom file) if PC is in first 32k of memory (TODO) -- intercepts all memory access and stops execution returning error if trying to write to first 32k of memory (TODO) +This folder contains a submodule (you should fetch it if you need to run the os in an emulator). + +Uses cburbridge's Z80 emulator written in python. It opens some windows showing the emulated computer's memory map, the cpu registers state and parallel terminal to interact with the os. ## Usage -Build with `make all` -Run with `./pat80emu` +To run the os in the emulator, head to `pat80-computer/software/z80-assembly/os/Makefile` and run `make run` to build the rom from assembly and start the emulator. diff --git a/pat80-emulator/main.c b/pat80-emulator/main.c deleted file mode 100644 index 6affdab..0000000 --- a/pat80-emulator/main.c +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include "z80/z80.h" - -/* - * The intercept function is invoked on each and every CPU instruction. It - * quits the simulation when the PC register reaches address #0005 by changing - * the virtual CPU status. - */ -static void intercept(void *ctx) -{ - z80 *cpu = ctx; - if (PC == 5) { - puts("\nReached address: 5, terminating the simulation..."); - cpu->status = 1; - } -} - -int main(int argc, char *argv[]) -{ - /* - * Instantiate the CPU, activate the debug mode, set the intercept - * function and run the virtual CPU until the termination criteria - * set by the intercept function, if any, are met. - */ - z80 *cpu = z80_new(); - cpu->debug = 1; - - // TODO: Copy rom to first 32k CPU memory - _RamWrite(0x03, 0x76); // As an example, here is how to set HALT at posizion 0x03. Use a loop to copy memory from a PAT80 OS rom file. - - z80_set_intercept(cpu, cpu, intercept); - z80_run(cpu); - z80_destroy(cpu); -} diff --git a/pat80-emulator/z80 b/pat80-emulator/z80 deleted file mode 160000 index 80df33f..0000000 --- a/pat80-emulator/z80 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 80df33fc873e8eb374c1fcb33458a1b7220d20db diff --git a/pat80-emulator/z80-python-emulator b/pat80-emulator/z80-python-emulator new file mode 160000 index 0000000..a5dbd3e --- /dev/null +++ b/pat80-emulator/z80-python-emulator @@ -0,0 +1 @@ +Subproject commit a5dbd3e829a94a2598b42ba976e61353c580600b