Zafiro.Compilers.Z80DotNet 0.0.21

There is a newer version of this package available.
See the version list below for details.
dotnet add package Zafiro.Compilers.Z80DotNet --version 0.0.21
                    
NuGet\Install-Package Zafiro.Compilers.Z80DotNet -Version 0.0.21
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Zafiro.Compilers.Z80DotNet" Version="0.0.21" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Zafiro.Compilers.Z80DotNet" Version="0.0.21" />
                    
Directory.Packages.props
<PackageReference Include="Zafiro.Compilers.Z80DotNet" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Zafiro.Compilers.Z80DotNet --version 0.0.21
                    
#r "nuget: Zafiro.Compilers.Z80DotNet, 0.0.21"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Zafiro.Compilers.Z80DotNet@0.0.21
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Zafiro.Compilers.Z80DotNet&version=0.0.21
                    
Install as a Cake Addin
#tool nuget:?package=Zafiro.Compilers.Z80DotNet&version=0.0.21
                    
Install as a Cake Tool

Z80.NET

What is this?

Z80.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.

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);

z80.Start();

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.

Compatibility

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.

Resources

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.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.24 88 9/12/2025
0.0.21 88 9/12/2025

fix: Update azure-pipelines.yml to install DotnetDeployer.Tool instead of DotnetDeployer