1. Nestor Soriano Vilchez
  2. Z80dotNet



Important notice!!

This project has been moved to GitHub: https://github.com/Konamiman/Z80dotNet. This repository will not be updated anymore.

What is this?

Z80.NET is a Z80 processor simulator that can be used as the core component for developing computer emulators (see for examle NestorMSX), or to exercise pieces of Z80 code in custom test code. It is written in C# targetting the .NET Framework 4 Client Profile.

NOTE: If you are reading this from the overview page of the project site in BitBucket, the links to documentation and code will not work. Please go and open the README file itself in the root of the source code instead. Thanks!

If you like Z80.NET you may want to take a look at ZWatcher too.

Want to say something? Head to the discussion site!

Hello, world!

var z80 = new Z80Processor();
z80.AutoStopOnRetWithStackEmpty = true;

var program = new byte[] {
    0x3E, 0x07, //LD A,7
    0xC6, 0x04, //ADD A,4
    0x3C,       //INC A
    0xC9        //RET
z80.Memory.SetContents(0, program);


Debug.Assert(z80.Registers.A == 12);
Debug.Assert(z80.TStatesElapsedSinceStart == 28);

How to use

For your convenience, you can add Z80.NET to your project as a NuGet package if you want. In that case you may want to take a look at the release notes.

  1. Create an instance of the Z80Processor class.
  2. Optionally, plug your own implementations of one or more of the dependencies.
  3. Configure your instance as appropriate.
  4. Optionally, register one or more interrupt sources.
  5. Optionally, capture the memory access events and/or the instruction execution events.
  6. Start the simulated processor execution by using one of the execution control methods.
  7. Execution will stop (and the execution method invoked will then return) when one of the execution stop conditions is met. You can then check the processor state and, if desired, resume execution.

Execution is completely synchronous: one single thread is used for everything, including firing events. As seen in the Hello World example, you just invoke one of the starting methods and wait until it returns (there are means to force this to happen, see the execution stop conditions). If you want some kind of multithreading, you'll have to implement it by yourself, I just tried to keep things simple. :-)

Interaction of the processor with the hosting code and the outside world (memory and ports) can be achieved by handling the class events, by plugging custom implementations of the dependencies, or both at the same time. Interrupts can be generated by using interrupt sources.


Z80.NET implements all the documented Z80 behavior, plus all the undocumented instructions and flag effects as per The undocumented Z80 documented except for the following:

  • The bit 3 and 5 flags are not modified by the BIT instruction
  • The H, C and P/V flags are not modified by the INI, INIR, IND, INDR, OUTI, OTIR, OUTD and OTDR instructions

The processor class passes the ZEXDOC test fully, and the ZEXALL test fully except for the BIT instruction. You can try these tests yourself by running the ZexallTest project.


The following resources have been used to develop this project:

Last but not least...

...if you like this project please consider donating! My kids need moar shoes!

But who am I?

I'm Konamiman, the MSX freak. No more, no less.