SNA format

From Sinclair Wiki
Jump to navigation Jump to search

The SNA format is a simple snapshot format supported by a large number of emulators. It was based on the format of memory dumps made by the Mirage Microdriver interface. Note the Microdriver's own snapshots use a different file format.

The format seems to have been first used for emulation by Peter McGavin's 'Spectrum' emulator on the Amiga, where the file extension '.snapshot' was used. It was later used by Arnt Gulbrandsen's JPP under MS-DOS.

48K Snapshots

The file begins with a 27-byte header containing the Z80 registers:

$00  I
$01  HL'    
$03  DE'
$05  BC'
$07  AF'
$09  HL
$0B  DE
$0D  BC
$0F  IY
$11  IX
$13  IFF2    [Only bit 2 is defined: 1 for EI, 0 for DI]
$14  R
$15  AF
$17  SP
$19  Interrupt mode: 0, 1 or 2
$1A  Border colour

After the header, all 48k of RAM follows, without any compression. Thus a 48k .SNA file is 49179 bytes long.

The program counter is not stored in the header. Instead, the behaviour of a real Microdriver is emulated: when the snapshot is made, the program counter is pushed onto the stack. To resume execution, an emulator should simulate a RETN instruction, which will copy IFF2 to IFF1 and retrieve the program counter from the top of the stack. This use of the stack can cause problems if the stack pointer is in ROM at the time the snapshot is made, or if the stack is being used to copy data.

The version of the format used by emulators is modified slightly compared to the original, to support saving of the border colour. Instead of the border colour, the original Microdriver stores a copy of the byte at address $0700, which is then used to detect whether the Interface 1 ROM is paged in or not — $71 for the Spectrum ROM, $C9 for the Interface 1 ROM[1]. It does not save the border, as the border colour is held in a write-only register. Peter McGavin's emulator is described in the documentation for JPP as storing 'rubbish' at this location in the header[2].

At least one source[3] incorrectly states that bit 0 of byte $13 holds the state of IFF1.

128K Snapshots

The original format only supports 48K snapshots. Emulators have since extended this format to support saving of 128K snapshots, originally for the Pentagon 128[4]. This extended format consists of a dump in the original 48K format, followed by a short header containing the program counter and last written 128K memory port register value, and then the remaining memory pages not saved in the initial dump.