From 5b8a0e36e4573b125ec510ff56e2a49e154443dc Mon Sep 17 00:00:00 2001 From: Sven Riwoldt Date: Sat, 15 Mar 2025 16:13:21 +0100 Subject: [PATCH] Init --- README.md | 46 + fuse_tests/README | 73 + fuse_tests/tests.expected | 18395 ++++++++++++++++ fuse_tests/tests.in | 9011 ++++++++ fuse_tests/tests.py | 268 + roms/BASIC.HEX | 304 + roms/INTMINI.HEX | 15 + roms/ROM.HEX | 257 + roms/basic.asm | 4341 ++++ roms/intmini.asm | 202 + src/units/16bit_arith.asm | 32 + src/units/16bit_load.asm | 34 + src/units/8bit_arith.asm | 96 + src/units/8bit_load.asm | 127 + src/units/bit_set.asm | 240 + src/units/call_return.asm | 28 + src/units/exchange.asm | 14 + src/units/general_purp.asm | 14 + src/units/input_output.asm | 25 + src/units/jump_group.asm | 12 + src/units/rotate_shift.asm | 65 + src/units/test_register.py | 32 + src/units/test_z80.py | 233 + src/z80/__init__.py | 0 src/z80/__pycache__/__init__.cpython-312.pyc | Bin 0 -> 166 bytes src/z80/__pycache__/gui.cpython-312.pyc | Bin 0 -> 12294 bytes .../__pycache__/instructions.cpython-312.pyc | Bin 0 -> 101615 bytes src/z80/__pycache__/io.cpython-312.pyc | Bin 0 -> 5250 bytes src/z80/__pycache__/registers.cpython-312.pyc | Bin 0 -> 4721 bytes src/z80/__pycache__/util.cpython-312.pyc | Bin 0 -> 13292 bytes src/z80/gui.py | 276 + src/z80/instructions.py | 2352 ++ src/z80/io.py | 106 + src/z80/registers.py | 101 + src/z80/util.py | 321 + src/z80sbc.py | 119 + 36 files changed, 37139 insertions(+) create mode 100755 README.md create mode 100755 fuse_tests/README create mode 100755 fuse_tests/tests.expected create mode 100755 fuse_tests/tests.in create mode 100755 fuse_tests/tests.py create mode 100755 roms/BASIC.HEX create mode 100755 roms/INTMINI.HEX create mode 100755 roms/ROM.HEX create mode 100755 roms/basic.asm create mode 100755 roms/intmini.asm create mode 100755 src/units/16bit_arith.asm create mode 100755 src/units/16bit_load.asm create mode 100755 src/units/8bit_arith.asm create mode 100755 src/units/8bit_load.asm create mode 100755 src/units/bit_set.asm create mode 100755 src/units/call_return.asm create mode 100755 src/units/exchange.asm create mode 100755 src/units/general_purp.asm create mode 100755 src/units/input_output.asm create mode 100755 src/units/jump_group.asm create mode 100755 src/units/rotate_shift.asm create mode 100755 src/units/test_register.py create mode 100755 src/units/test_z80.py create mode 100755 src/z80/__init__.py create mode 100644 src/z80/__pycache__/__init__.cpython-312.pyc create mode 100644 src/z80/__pycache__/gui.cpython-312.pyc create mode 100644 src/z80/__pycache__/instructions.cpython-312.pyc create mode 100644 src/z80/__pycache__/io.cpython-312.pyc create mode 100644 src/z80/__pycache__/registers.cpython-312.pyc create mode 100644 src/z80/__pycache__/util.cpython-312.pyc create mode 100755 src/z80/gui.py create mode 100755 src/z80/instructions.py create mode 100755 src/z80/io.py create mode 100755 src/z80/registers.py create mode 100755 src/z80/util.py create mode 100755 src/z80sbc.py diff --git a/README.md b/README.md new file mode 100755 index 0000000..a3f90b6 --- /dev/null +++ b/README.md @@ -0,0 +1,46 @@ +## Z80 CPU Emulator + +This is a Zilog Z80 CPU emulator, written in Python. +It runs a 1978 Microsoft Basic 4.7 ROM taken from [Grant Searle's Z80 SBC project](http://searle.hostei.com/grant/z80/SimpleZ80.html) + +### Why? +Just for fun. I like the Z80 CPU - it was in many devices I played with as a +kid. + +### Is it useful? +No. It runs really slowly, and is a completely non-optimal software design for +an emulator, but (in my opinion) the code is readable. If you want a CPU emulator, +probably don't use Python. That said, an optimised python coded emulator could run +a lot faster than this :-) + +### Running +BASIC: +``` +cd src +python z80sbc.py +``` +Unit tests: +``` +cd src +PYTHONPATH=`pwd`:$PYTHONPATH python ../tests/test_z80.py +PYTHONPATH=`pwd`:$PYTHONPATH python ../tests/test_registers.py +``` + +Fuse tests: +``` +cd src +PYTHONPATH=`pwd`:$PYTHONPATH python ../fuse_tests/tests.py +``` + +### Missing and todo +- Most undocumented opcodes +- Undocumented flags for `CPI` and `CPIR`. + +### Credits + +[Grant Searle's Z80 SBC project](http://searle.hostei.com/grant/z80/SimpleZ80.html) + +[FUSE - Free Unix Spectrum Emulator](http://fuse-emulator.sourceforge.net/) for the instruction set tests + +### License +Public domain; do what you like. diff --git a/fuse_tests/README b/fuse_tests/README new file mode 100755 index 0000000..d313e7e --- /dev/null +++ b/fuse_tests/README @@ -0,0 +1,73 @@ +File formats +============ + +tests.in +-------- + +Each test has the format: + + +AF BC DE HL AF' BC' DE' HL' IX IY SP PC +I R IFF1 IFF2 IM + + specifies whether the Z80 is halted. + specifies the number of tstates to run the test for, in + decimal; the number actually executed may be higher, as the final + instruction is allowed to complete. + +Then followed by lines specifying the initial memory setup. Each has +the format: + + ... -1 + +eg + +1234 56 78 9a -1 + +says to put 0x56 at 0x1234, 0x78 at 0x1235 and 0x9a at 0x1236. + +Finally, -1 to end the test. Blank lines may follow before the next test. + +tests.expected +-------------- + +Each test output starts with the test description, followed by a list +of 'events': each has the format + +