August 13, 2015 by Marco Cecconi
The Zilog Z80 is an 8-bit microprocessor designed by Zilog and sold from July 1976 onwards. It was widely used both in desktop and embedded computer designs as well as for military purposes. The Z80 and its derivatives and clones made up one of the most commonly used CPU families of all time, and, along with the MOS Technology 6502 family, dominated the eight-bit microcomputer market from the late 1970s to the mid-1980s.
z80 (zee-eighty) is an open source project I built in the past few months in my spare time. It emulates my favorite CPU of all time, the Zilog Z80.
Because the Z80 is awesome and it made world-changing machines possible: the WOPR, the Sinclair ZX Spectrum, the Nintendo Game Boy and Galaga.
Because I learnt how to code on it, it was my first Assembly dialect and, whilst I even hand-compiled it at times—and stored it via POKE
in memory—I never felt I mastered it completely. I though writing an emulator for it was good enough to give me the grounding I needed.
z80 works in real time written in C#.
These are are its features:
Z80
), emulates all official opcodes with correct timings, and also implements some undocumented features.Z80Asm
), basically a bunch of functions corresponding to Assembly instructions which write the op-codes to memoryz80.Tests
), a whole bunch of them, more than 2,000 presentlyThe tests are a translation of the documentation, the assembler backend is needed to write tests and stay sane and the emulator is the whole point.
There's a very basic step debugger in the tests (TestSystem
) which basically came for free with them.
If you find any issues report them on github
var ram = new byte[65536];
// Load a ROM image
Array.Clear(ram, 0, ram.Length);
Array.Copy(File.ReadAllBytes("48.rom"), ram, 16384);
// Ports is something you supply to emulate I/O ports
var ports = new SamplePorts();
// Set up memory layout
var myz80 = new z80(new Memory(ram, 16384), ports);
// Run
while (!myz80.Halted)
{
myz80.Parse();
}
// Show the registers
Console.WriteLine(myz80.DumpState());
The following resources have been useful documentation:
The project is open source licensed under a BSD 3 clause license.
Hi, I'm Marco Cecconi. I am the founder of Intelligent Hack, developer, hacker, blogger, conference lecturer. Bio: ex Stack Overflow core team, ex Toptal EM.
Read moreMarch 12, 2023 by Marco Cecconi
Stack Overflow could benefit from adopting a using conversational AI to provide specific answers
Read moreOctober 15, 2021 by Marco Cecconi
Multiple people with my name use my email address and I can read their email, chaos ensues!
Read moreSeptember 29, 2021 by Marco Cecconi
After years of building, our top-notch consultancy to help start-ups and scale-ups create great, scalable products, I think it is high time I added an update to how it is going and what's next for us.
Read moreFebruary 03, 2021 by Marco Cecconi
A lesson in building communities by Stack Overflow's most prominent community manager emeritus, Shog9
Read moreDecember 02, 2020 by Marco Cecconi
Some lessons learned over the past 8 years of remote work in some of the best remote companies on the planet
Read moreNo, I don’t want to subscribe to your newsletter. No, I don’t want to complete a short survey. And no, I don’t want to become a member.
Read more…