A TAP file stores the blocks a ZX Spectrum writes to tape, without the tones and timings: just the bytes. Several TAP files joined end to end make a valid TAP file. This page follows the Sinclair Wiki’s description of the format, which matches the Spectrum ROM’s own tape routines. Numbers are little-endian.
Blocks
| Offset | Size | Name | Description |
|---|---|---|---|
0 | 2 | Length | Bytes that follow in this block: flag, data and checksum. Not counting these two bytes. |
2 | 1 | Flag | 00 for a header block, FF for a data block. Programs with their own loaders may use other values. |
3 | length − 2 | Data | The block’s contents. |
| end | 1 | Checksum | The XOR of the flag and every data byte. XORing the whole block, checksum included, gives 0. |
A file saved from BASIC is a header block followed by a data block. A loader can also read “headerless” data blocks with no header before them; TAP stores those the same way.
Header block
A header block has the flag 00, 17 bytes of header and the checksum, so
its length is 19.
| Offset in header | Size | Name | Description |
|---|---|---|---|
0 | 1 | Type | See types. |
1 | 10 | File name | Padded with spaces. |
11 | 2 | Data length | Length of the data block’s contents (without its flag and checksum). |
13 | 2 | Parameter 1 | Depends on the type. |
15 | 2 | Parameter 2 | Depends on the type. |
| Type | File | Parameter 1 | Parameter 2 |
|---|---|---|---|
| 0 | Program (BASIC) | The line to start at (SAVE … LINE); 32,768 or more for no auto-start. | Where the variables start, counted from the start of the program. |
| 1 | Number array | The second byte (header offset 14) holds the array’s variable name. | – |
| 2 | Character array | The second byte (header offset 14) holds the array’s variable name. | – |
| 3 | Bytes (code) | The address the bytes were saved from. | 32,768. |
A screen saved with SAVE … SCREEN$ is a bytes file of 6,912 bytes from
address 16,384.
Example
00000000 13 00 00 03 53 43 52 45 45 4E 20 20 20 20 00 1B ....SCREEN ..
00000010 00 40 00 80 D4 .@...
Reading it: length 0x13, 19; flag 00, a header; type 3,
bytes; name SCREEN; data length 0x1B00, 6,912; parameter 1
0x4000, 16,384; parameter 2 0x8000, 32,768; checksum
D4. The data block that follows has length 6,914 (02 1B), flag
FF, the 6,912 bytes of the screen and its checksum.