OldBit.Z80Cpu.Spectron
1.0.1
dotnet add package OldBit.Z80Cpu.Spectron --version 1.0.1
NuGet\Install-Package OldBit.Z80Cpu.Spectron -Version 1.0.1
<PackageReference Include="OldBit.Z80Cpu.Spectron" Version="1.0.1" />
<PackageVersion Include="OldBit.Z80Cpu.Spectron" Version="1.0.1" />
<PackageReference Include="OldBit.Z80Cpu.Spectron" />
paket add OldBit.Z80Cpu.Spectron --version 1.0.1
#r "nuget: OldBit.Z80Cpu.Spectron, 1.0.1"
#:package OldBit.Z80Cpu.Spectron@1.0.1
#addin nuget:?package=OldBit.Z80Cpu.Spectron&version=1.0.1
#tool nuget:?package=OldBit.Z80Cpu.Spectron&version=1.0.1
Z80 CPU Emulator
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 a branch that adds some features specifically for to the ZX Spectrum emulator, e.g. memory contention. Main branch is quite generic.
Features
- Full Z80 instruction set
- Undocumented instructions (at least the most common ones)
Implementation
- The emulator is using C# 14 and .NET 10
- 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:
8BitArithmeticInstructions8BitLoadInstructions16BitArithmeticInstructions16BitLoadInstructionsBitSetResetTestInstructionsCallReturnRestartInstructionsControlInstructionsExchangeBlockInstructionsGeneralPurposeArithmeticInstructionsInputOutputInstructionsJumpInstructionsRotateShiftInstructionsUndocumentedInstructions
- The main class is
- 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
- Unit tests
Usage
There are two interfaces that can be used to interact with the emulator:
IMemoryIBus
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[65536];
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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.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 |
|---|---|---|
| 1.0.1 | 434 | 11/13/2025 |
| 0.9.4 | 240 | 11/5/2025 |
| 0.9.3 | 165 | 11/1/2025 |
| 0.9.3-pre.13 | 615 | 7/23/2025 |
| 0.9.3-pre.12 | 237 | 6/4/2025 |
| 0.9.3-pre.11 | 170 | 4/25/2025 |
| 0.9.3-pre.10 | 136 | 4/5/2025 |
| 0.9.3-pre.9 | 165 | 3/31/2025 |
| 0.9.3-pre.8 | 169 | 3/15/2025 |
| 0.9.3-pre.7 | 199 | 3/10/2025 |
| 0.9.3-pre.6 | 224 | 3/7/2025 |
| 0.9.3-pre.5 | 200 | 3/6/2025 |
| 0.9.3-pre.4 | 198 | 2/16/2025 |
| 0.9.3-pre.3 | 101 | 1/31/2025 |
| 0.9.3-pre.2 | 80 | 1/30/2025 |
| 0.9.3-pre.1 | 87 | 1/27/2025 |