├── README.md ├── fuse_tests ├── README ├── tests.expected ├── tests.in └── tests.py ├── roms ├── BASIC.HEX ├── INTMINI.HEX ├── ROM.HEX ├── basic.asm └── intmini.asm └── src ├── units ├── 16bit_arith.asm ├── 16bit_load.asm ├── 8bit_arith.asm ├── 8bit_load.asm ├── bit_set.asm ├── call_return.asm ├── exchange.asm ├── general_purp.asm ├── input_output.asm ├── jump_group.asm ├── rotate_shift.asm ├── test_register.py └── test_z80.py ├── z80 ├── __init__.py ├── gui.py ├── instructions.py ├── io.py ├── registers.py └── util.py └── z80sbc.py /README.md: -------------------------------------------------------------------------------- 1 | ## Z80 CPU Emulator 2 | 3 | This is a Zilog Z80 CPU emulator, written in Python. 4 | 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) 5 | 6 | ### Why? 7 | Just for fun. I like the Z80 CPU - it was in many devices I played with as a 8 | kid. 9 | 10 | ### Is it useful? 11 | No. It runs really slowly, and is a completely non-optimal software design for 12 | an emulator, but (in my opinion) the code is readable. If you want a CPU emulator, 13 | probably don't use Python. That said, an optimised python coded emulator could run 14 | a lot faster than this :-) 15 | 16 | ### Running 17 | BASIC: 18 | ``` 19 | cd src 20 | python z80sbc.py 21 | ``` 22 | Unit tests: 23 | ``` 24 | cd src 25 | PYTHONPATH=`pwd`:$PYTHONPATH python ../tests/test_z80.py 26 | PYTHONPATH=`pwd`:$PYTHONPATH python ../tests/test_registers.py 27 | ``` 28 | 29 | Fuse tests: 30 | ``` 31 | cd src 32 | PYTHONPATH=`pwd`:$PYTHONPATH python ../fuse_tests/tests.py 33 | ``` 34 | 35 | ### Missing and todo 36 | - Most undocumented opcodes 37 | - Undocumented flags for `CPI` and `CPIR`. 38 | 39 | ### Credits 40 | 41 | [Grant Searle's Z80 SBC project](http://searle.hostei.com/grant/z80/SimpleZ80.html) 42 | 43 | [FUSE - Free Unix Spectrum Emulator](http://fuse-emulator.sourceforge.net/) for the instruction set tests 44 | 45 | ### License 46 | Public domain; do what you like. 47 | -------------------------------------------------------------------------------- /fuse_tests/README: -------------------------------------------------------------------------------- 1 | File formats 2 | ============ 3 | 4 | tests.in 5 | -------- 6 | 7 | Each test has the format: 8 | 9 | 10 | AF BC DE HL AF' BC' DE' HL' IX IY SP PC 11 | I R IFF1 IFF2 IM 12 | 13 | specifies whether the Z80 is halted. 14 | specifies the number of tstates to run the test for, in 15 | decimal; the number actually executed may be higher, as the final 16 | instruction is allowed to complete. 17 | 18 | Then followed by lines specifying the initial memory setup. Each has 19 | the format: 20 | 21 | ... -1 22 | 23 | eg 24 | 25 | 1234 56 78 9a -1 26 | 27 | says to put 0x56 at 0x1234, 0x78 at 0x1235 and 0x9a at 0x1236. 28 | 29 | Finally, -1 to end the test. Blank lines may follow before the next test. 30 | 31 | tests.expected 32 | -------------- 33 | 34 | Each test output starts with the test description, followed by a list 35 | of 'events': each has the format 36 | 37 |