Skip to content

Z80N ​

NuGet VersionNuGet Downloads

Test suites for Z80N emulators.

The Z80N is the Z80 variant in the ZX Spectrum Next. It adds instructions in the unused ED prefixed opcodes and is otherwise a Z80, so the suites here only cover the instructions it adds. Run the Z80 suites against your emulator as well; none of them have test cases for the opcodes the Z80N uses, so a working Z80N should pass all of them unchanged.

The Z80N has no silicon implementation. The CPU is the T80N core in the ZX Spectrum Next FPGA, so that core, rather than a datasheet, is the reference the tests are written from.

Getting Started ​

Start by installing the NuGet package into your test project:

dotnet add package MrKWatkins.EmulatorTestSuites.Z80N

The Z80N suites use the Z80 test harnesses, so create a concrete implementation of Z80TestHarness for your emulator exactly as you would for a Z80.

A Z80N also writes to Next registers, which are on a bus of their own inside the FPGA rather than on the I/O bus, so tell the harness when your emulator writes to one:

c#
// Wherever your harness services the emulator's bus activity:
case NextRegisterWrite:
    WriteNextRegister(register, value);
    break;

Doing so lets the suites check both the writes themselves, through TestAssertions.NextRegisterWrites, and where they fall in the instruction, as CycleType.NextRegisterWrite cycles. A harness for a plain Z80 never needs to call it.

Lastly, you will need to add some unit tests in the framework of your choosing. These will be simple calls to the test suite methods, exactly as for the Z80 suites:

c#
public sealed class ExtendedInstructionsTests
{
    [TestCaseSource(nameof(TestCases))]
    public void ExtendedInstructions(ExtendedInstructionsTestCase testCase) => testCase.Execute<MyZ80NEmulatorTestHarness>();

    [Pure]
    public static IEnumerable<ExtendedInstructionsTestCase> TestCases() => ExtendedInstructionsTestSuite.Instance.GetTestCases();
}

Instruction Test Suites ​

Instruction test suites contain tests for a single instruction at a time, and work the same way as the Z80 instruction test suites; the assertions to run are controlled through the same TestAssertions enum, and every suite has a default set that can be overridden.

The instruction test suites are: