Emulation – Building a Z80 Emulator Part 1

So this weekend I had the overwhelming urge to start creating an emulator for the first time in a fair few years.  After a little googling around the internet, I stumbled upon the documentation for the Z80 CPU which can be found in the ZX Spectrum 48k (of which I’m a massive fan), and so it became a weekend project.

The Z80 was an 8bit processor created by Zilog sometime in the late 1970s, finding its way into a large number of embedded circuits and desktops into the late 1980s. It was built with the following :

  • 6 x 8 bit registers (that could be treated as 3 16 bit registers)
  • one Accumulator
  • one 8 bit flags register
  • A second bank that mirrored the above
  • 3 x 16 bit index registers (one of which is the stack pointer)
  • 8 bit interrupt vector
  • 8 bit refresh counter
  • 16 bit program counter

More information on the chip can be found HERE

Hiding away on the internet you can find a number of large PDFs describing in detail the opcode’s, registers and all the other parts of legacy chips, this here being the one for the Z80 . It’s been a while since I’ve had the chance to get my head stuck into detailed documentation like this, after a few coffee’s however I was in full development mode and firing up Visual Studio.

Now my first instinct was to jump into a C# project like I usually do for the speed of development, but on second thought the realisation that this code will be performance-critical I opted for a C project instead. I’ll explain some of my findings and code in part two of this blog.

So far I have completed the many LD opcode’s, EX and ADD, I have about 60 ish opcode’s to go before I can begin testing the Emulator. For testing, I will be writing a small number of c test scripts that I will compile down into z80 op-code using the fantastic tool kit over HERE . As I know and can test the results of the c scripts on the GCC compiler and can look out for anomalies when running on the simulated core, I will be able to rapidly debug any issues in the code.

This project is currently hosted on GitHub and hopefully, once it’s complete I’ll open it up for public browsing, followed by a second blog on my experiences getting it all working.

Raspberry Pi Logo Previous post Raspberry PI – Developing with Mono (c#, vb.net +others)
A screenshot of my entry to Ludum Dare 49 Next post Game Jam – Ludum Dare 49