Z80.NET is a Z80 processor simulator for .NET that can be used as the core component for developing computer emulators or exercising Z80 code. Supports all documented and undocumented instructions and behaviors. (Zafiro fork)
$ dotnet add package Zafiro.Compilers.Z80DotNetZ80.NET is a Z80 processor simulator that can be used as the core component for developing computer emulators (see for example NestorMSX), or to exercise pieces of Z80 code in custom test code. It is written in C# targetting the .NET Framework 4 Client Profile.
If you like Z80.NET you may want to take a look at ZWatcher too.
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);
z80.Start();
Debug.Assert(z80.Registers.A == 12);
Debug.Assert(z80.TStatesElapsedSinceStart == 28);
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.
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 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:
...if you like this project please consider donating! My kids need moar shoes!
I'm Konamiman, the MSX freak. No more, no less.