OldBit.Z80Cpu
0.9.2-rc.1
dotnet add package OldBit.Z80Cpu --version 0.9.2-rc.1
NuGet\Install-Package OldBit.Z80Cpu -Version 0.9.2-rc.1
<PackageReference Include="OldBit.Z80Cpu" Version="0.9.2-rc.1" />
paket add OldBit.Z80Cpu --version 0.9.2-rc.1
#r "nuget: OldBit.Z80Cpu, 0.9.2-rc.1"
// 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
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
- 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
- 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 | Versions 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. |
-
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.2-rc.1 | 37 | 10/25/2024 |