Spectrum tape interface

From SinclairFAQ
Jump to: navigation, search
  • This article is about the ZX Spectrum ROM load/save format. For the .TAP emulator format see TAP format

The Spectrum ROM routines save files to tape in two blocks, a header and a data block. Each of these blocks is encoded as a sequence of pulses.

There are also a wide variety of "custom loaders" which have been used for Spectrum software, for purposes such as copy protection or faster loading times. This article deals only with the format written by the Spectrum ROM.

Pulses

A 'pulse' here is either a mark or a space, so 2 pulses makes a complete square wave cycle.

Pilot tone: before each block is a sequence of 8063 (header) or 3223 (data) pulses, each of length 2168 T-states.

Sync pulses: the pilot tone is followed by two sync pulses of 667 and 735 T-states resp.

A '0' bit is encoded as 2 pulses of 855 T-states each.

A '1' bit is encoded as 2 pulses of 1710 T-states each (ie. twice the length of a '0')

(Does initial polarity matter?)

Blocks

Header block

The header, which is 17 bytes long, is as follows:

Byte (decimal) Length Description
0 1 Type (0,1,2 or 3)
1 10 Filename (padded with blanks)
11 2 Length of data block
13 2 Parameter 1
15 2 Parameter 2

The type is 0,1,2 or 3 for a Program, Number array, Character array or Code file. A SCREEN$ file is regarded as a Code file with start address 16384 and length 6912 decimal. If the file is a Program file, parameter 1 holds the autostart line number (or a number >=32768 if no LINE parameter was given) and parameter 2 holds the start of the variable area relative to the start of the program. If it's a Code file, parameter 1 holds the start of the code block when saved, and parameter 2 holds 32768. For data files finally, the byte at position 14 decimal holds the variable name.

Data block

(Someone who knows the formats for data arrays should complete this section. Is it the same as the format in RAM? The latter can be found at [1])

Program files are stored as a sequence of lines each stored the same way it is in RAM:

Line number[2BE] Length[2] Text[] 0x0D[1]

Note that numeric literals will be stored in both text and binary (text[] 0x0E[1] zxfloat[5]).

Code files are stored as a flat sequence of bytes, in the order they appear in RAM.