Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:ZX Spectrum Z80 snapshot

From ReverseEngineering.wiki
Format
Platforms Platform:ZX Spectrum
Magic none
Extensions .z80 .sna
On this wiki Facts · Code · Notes · Topics

Memory-and-register snapshot of a ZX Spectrum (.z80): a 30-byte version 1 header, or PC = 0 in that header followed by a 23-byte (v2) or 54/55-byte (v3) extension, then RAM pages that can be run-length compressed; .SNA is the simpler uncompressed alternative.

Version detection (libspectrum z80.c)

The base header is 30 bytes. If the 16-bit PC at bytes 6-7 is zero the file is version 2 or newer and a u16 at offset 30 gives the extra header length: 23 means v2, 54 or 55 (55 is the XZX variant) means v3; any other length is an error. Otherwise it is version 1 and RAM is a single 48 KiB block that is compressed when bit 5 of byte 12 is set.

Base header fields

0 A, 1 F, 2-3 BC, 4-5 HL, 6-7 PC, 8-9 SP, 10 I, 11 R (low 7 bits; bit 7 is bit 0 of byte 12), 12 flags (bit 0 R bit 7, bits 1-3 border colour, bit 5 compressed), 13-14 DE, 15-16 BC', 17-18 DE', 19-20 HL', 21 A', 22 F', 23-24 IY, 25-26 IX, 27 IFF1, 28 IFF2, 29 interrupt mode (bits 0-1), issue 2 emulation (bit 2), joystick type (bits 6-7). In v2/v3 the extension holds the real PC, the hardware mode (48K, 128K, ...), the 0x7FFD port value, AY registers and, in v3, T-state counters.

SNA

27-byte header at fixed offsets (0 I, 1 HL', 3 DE', 5 BC', 7 F', 8 A', 9 HL, 11 DE, 13 BC, 15 IY, 17 IX, 19 interrupt byte with IFF in bit 2, 20 R, 21 F, 22 A, 23 SP, 25 interrupt mode in bits 0-1, 26 border in bits 0-2) followed by 48 KiB of RAM (49179 bytes total); PC is not stored in the header: libspectrum pops it from the stack at SP (RAM offset SP - 0x4000) and adds 2 to SP. The 128K variant (131103 or 147487 bytes) stores pages 5 and 2, the paged-in bank, a 4-byte extra header (read by libspectrum_sna_read_128_header; Unverified: PC, the 0x7FFD port value and a TR-DOS flag) and then the remaining banks. Facts: Fact:ZX Spectrum Z80 snapshot/struct/SNA header (27 bytes), Fact:ZX Spectrum Z80 snapshot/identification/SNA identified by file size.

Sources

fuse-emulator libspectrum z80.c lines 32-42, 223-300, 391-403, commit 0518d5c559bc71580300e2089376ac5d56df5d56 (speccytools mirror).

Code & repositories

  • https://github.com/speccytools/libspectrum @ 0518d5c559bc71580300e2089376ac5d56df5d56 · license: GPL-2.0
    libspectrum (Fuse): tzx_read.c, z80.c (GPL-2.0-or-later)
    Tested on: source read, not run: source reading only · checked 2026-10-18; last activity 2026-10-02