Building a Z80 Emulator Part 1

Jan 12

Written by:
1/12/2014 2:55 PM  RssIcon

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 1970’s, finding its way into a large number of embedded circuits and desktops into the late 1980’s. 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 : http://bit.ly/1m01hiE .  Its 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 thoughts 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 its complete I’ll open it up for public browsing, followed by a second blog on my experiences getting it all working.

Tags: Programming , C++ , Z80 , Emulator
Categories: Programming
Location: Blogs Parent Separator Main Blog

Your name:
Title:
Comment:
Security Code
CAPTCHA image
Enter the code shown above in the box below
Add Comment   Cancel