Skip to content

NEX

NEX is provided by the MrKWatkins.OakIO.ZXSpectrumNext package in the MrKWatkins.OakIO.ZXSpectrumNext.Snapshot.Nex namespace. NexFile continues to inherit from ZXSpectrumSnapshotFile in the ZX Spectrum package.

When upgrading from an earlier version, add the Next package and update NEX namespace imports. ZXSpectrumFileFormat.AllFormats and its Load methods no longer discover NEX. Use NexFormat.Instance directly, or pass ZXSpectrumNextFileFormats.AllFormats to IOFileFormat.Load or LoadAsync.

NEX is a snapshot format for the ZX Spectrum Next. Alongside the standard CPU registers and RAM banks, it supports Next-specific features including multiple screen types (Layer 2, ULA, LoRes, HiRes, HiColour), copper code, and a palette. NEX does not store shadow register data.

Details about the NEX format can be found at https://wiki.specnext.dev/NEX_file_format.

API

Class Description
NexFormat Singleton format for reading and writing NEX snapshots.
NexFile Represents a NEX snapshot file.
NexHeader 512-byte header containing registers and hardware configuration.
NexBank A 16 KB RAM bank.
NexScreen An attached screen buffer.

Reading and Writing

// Read
using var stream = File.OpenRead("snapshot.nex");
NexFile nex = NexFormat.Instance.Read(stream);

// Write
using var output = File.Create("output.nex");
nex.Write(output);

Accessing State

// CPU registers
var regs = nex.Registers;
Console.WriteLine($"PC: 0x{regs.PC:X4}  SP: 0x{regs.SP:X4}");

// Header fields
Console.WriteLine($"Version: {nex.Header.VersionString}");
Console.WriteLine($"RAM Required: {nex.Header.RamRequired}");
Console.WriteLine($"Entry Bank: {nex.Header.EntryBank}");

// Banks
foreach (NexBank bank in nex.Banks)
    Console.WriteLine($"Bank {bank.BankNumber}: {bank.Data.Length} bytes");

// Screens
foreach (NexScreen screen in nex.Screens)
    Console.WriteLine($"Screen: {screen.Type}");