Skip to content

TAP Tape

TAP is a simple tape format for the ZX Spectrum. A TAP file is a flat sequence of blocks, each consisting of a flag byte, raw data bytes, and a checksum byte. There is no metadata about the recording itself — it is purely the data that would have been read from or written to tape.

Details about the SNA format can be found at https://sinclair.wiki.zxnet.co.uk/wiki/TAP_format.

API

Class Description
TapFormat Singleton format for reading and writing TAP files.
TapFile Represents a TAP file as a list of blocks.
TapBlock Base class for all TAP blocks.
HeaderBlock A header block describing the file that follows.
DataBlock A data block containing the file contents.

Reading and Writing

// Read
using var stream = File.OpenRead("tape.tap");
TapFile tap = TapFormat.Instance.Read(stream);

// Write
using var output = File.Create("output.tap");
TapFormat.Instance.Write(tap, output);

Blocks

A TapFile contains a list of TapBlock objects. Each block is either a HeaderBlock or a DataBlock:

foreach (TapBlock block in tap.Blocks)
{
    switch (block)
    {
        case HeaderBlock header:
            Console.WriteLine($"Header: {header.HeaderType} — {header.Filename}");
            break;
        case DataBlock data:
            Console.WriteLine($"Data: {data.Header.BlockLength} bytes");
            break;
    }
}

HeaderBlock carries a TapHeaderType (Program, NumberArray, CharacterArray, or Code), a filename, and format-specific fields such as DataBlockLength and Location.

Creating TAP Files

Factory methods on HeaderBlock and DataBlock create individual blocks, and factory methods on TapFile create a file with correctly-paired header/data block sequences:

// A code block at location 0x8000
TapFile code = TapFile.CreateCode("game", 0x8000, myBytes);

// A loader that auto-runs and loads code blocks
TapFile loader = TapFile.CreateLoader("loader", (0x8000, myBytes));

Conversions

TAP files can be converted to TZX, PZX, and WAV. See Reading, Writing and Converting.