OldBit.Z80Cpu 0.9.2-rc.1

This is a prerelease version of OldBit.Z80Cpu.
There is a newer prerelease version of this package available.
See the version list below for details.
The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package OldBit.Z80Cpu --version 0.9.2-rc.1                
NuGet\Install-Package OldBit.Z80Cpu -Version 0.9.2-rc.1                
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="OldBit.Z80Cpu" Version="0.9.2-rc.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add OldBit.Z80Cpu --version 0.9.2-rc.1                
#r "nuget: OldBit.Z80Cpu, 0.9.2-rc.1"                
#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.
// Install OldBit.Z80Cpu as a Cake Addin
#addin nuget:?package=OldBit.Z80Cpu&version=0.9.2-rc.1&prerelease

// Install OldBit.Z80Cpu as a Cake Tool
#tool nuget:?package=OldBit.Z80Cpu&version=0.9.2-rc.1&prerelease                

Z80 CPU Emulator

Build

Introduction

This is a Z80 CPU emulator written in C#. I have created it as a fun project. It is quite generic and possibly can be used in any project that requires a Z80 CPU emulator.

There is also my own fork of this project that adds some features specific to the ZX Spectrum, like memory contention handling. I simply wanted to keep this project as generic as possible.

Features

  • Full Z80 instruction set
  • Undocumented instructions (at least the most common ones)

Implementation

  • The emulator is written in C# 12 and .NET 8
  • Source files are kept small and clean using partial classes
    • The main class is Z80.cs
    • Instructions are implemented in a separate files based on logical groups:
      • 8BitArithmeticInstructions
      • 8BitLoadInstructions
      • 16BitArithmeticInstructions
      • 16BitLoadInstructions
      • BitSetResetTestInstructions
      • CallReturnRestartInstructions
      • ControlInstructions
      • ExchangeBlockInstructions
      • GeneralPurposeArithmeticInstructions
      • InputOutputInstructions
      • JumpInstructions
      • RotateShiftInstructions
      • UndocumentedInstructions
  • There are 3 types of tests:
    • Unit tests (I have written a very basic Z80 assembly parser to help me write these)
    • Fuse tests (tests that come with the Fuse source code)
    • Zex tests (command line runner of the Z80 instruction exerciser)

Testing

The emulator has been tested using the following test suites:

  • Fuse tests
  • Zex tests
  • My own unit tests

Usage

There are two interfaces that can be used to interact with the emulator:

  • IMemory
  • IBus

The IMemory interface is used to read and write memory, while the IBus interface is used to read and write I/O ports.

As a minimum you need to implement IMemory to be able to run the emulator. The IBus interface is optional.

The following is an example of a simple memory implementation:

public class Memory : IMemory
{
    private readonly byte[] _memory = new byte[65535];

    public byte Read(ushort address) => _memory[address];

    public void Write(ushort address, byte data) => _memory[address] = data;
}

Then you can create an instance of the Z80 class:

var memory = new Memory();

memory.Write(0, 0x3E); // LD A, 0x12
memory.Write(1, 0x12);

var cpu = new Z80(memory);
cpu.Run(7); // Run for 7 cycles

References

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. 
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.9.3-pre.161 32 1/27/2025