Z80 emulation
I’m experimenting with writing yet another Z80 CPU emulator. So far it can take
the instruction set definition from
deeptoaster/opcode-table,
convert it to a computed goto form, and boot the ZX81 ROM. The main bugs were in
getting the djnz sense wrong, and converting jp (ix) to a
jump to the address at ix indirect, not jump to the address in ix.
An earlier version took the ZX81 assembly from open81 and converted it to C++.
It was very fast, but the Z80 instruction set is effectively bytecode to a 64
bit machine, and expanding an 8-bit-ish bytecode to multiple 64 bit instructions
blew the 8 KiB ROM up to over 200 KiB. It was nice how the compiler could
eliminate unused flag updates.
Next step is to benchmark different interpreter approaches. For that I need a test suite and benchmark, and I plan to use https://github.com/raxoft/z80test for both.
I want to try moving the most common registers - so A, F, and PC - to variables so the compiler can optimise them. This probably means moving from a computed goto form to tail call. I also want to try decomposing the flags and switching to lazy generation, as ~50 % of the interpreter is for updating the flags but I suspect the flags are only used ~10 % of the time.