TAP Format

The .TAP file format is a container used to store data in a format identical to the Spectrum's SAVE rom routine.

.TAP files can be concatenated together so forming a new tape is as easy as joining multiple .TAP files together to form a new one. For example on Linux or MacOS:

1cat part1.tap part2.tap > final.tap

In DOS and Windows:

1copy /b part1.tap + part2.tap final.tap

At a bare minimum, a .TAP file consists of two blocks; a header block followed by a data block.

Each block consists of the Block Wrapper which then contains data within it.

Block Wrapper

Header and Data blocks consists of a 2-byte word with the length of the block (including the checksum), the block type, then the block's data and finishing with a single checksum byte.

The block type is either 0x00 for a Header and 0xFF for a Data block.

The checksum byte is in reality a binary XOR of all bytes in the block and not a true checksum.

Byte Field Description
70Length of block
158n
0Block Type
1n-2 bytes of data
  
n-1Check sum byte

Header Block

The header block defines the type, filename, length and additional information about the file.

The file name is up to 10 characters padded with spaces.

The length at offset 11 is the number of bytes data in the data block. This excludes the block type and checksum byte.

Parameter's 1 and 2 are determined by the file type. If not used then they are set to 0.

Byte Description
0File Type
1File Name padded with spaces
2
 
9
10
1170Length of data block
12158
1370Parameter 1
14 15        Name for types 1 and 2        8
1570Parameter 2
16158
Type File Description Param 1 Param 2
0 BASIC Program Line number to start Start of variable area relative to program start
1 Number Array Variable name, e.g. if DIM a() then this is 0x80 a=0x81, y=0x99
2 Character Array Variable name, e.g. if DIM a$() then this is 0x80 a=0xC1, y=0xD9
3 CODE Start when saved 32768

Data Block

For BASIC programs (type 0) the data block consists of a series of lines stored as it is in memory, i.e. in it's tokenised state.

For CODE files it consists of the raw bytes in the order they appear in memory.

For both array types they have a specific structure which won't be described here as they are not of any real use outside a basic program. Only types 0 and 3 are of any use these days.

Examples

An example of creating a .TAP file is available, which shows a basic loader which then loads a Machine code program.