This article describes the format of an image file. An image in this context refers to a representation of the data stored on a specific storage media such as a floppy diskette or an audio cassette tape.
Note: The .TAP format is a container format and does not describe the contents of the data blocks contained within. The .TAP format is generally used to store data generated by the ZX Spectrum "SAVE" ROM routine
Due to the structure of the tap format, files in this format can simply be concatenated to combine them into a single, longer tape. Under Unix, including Mac OS X:
cat side1.tap side2.tap > bothsides.tap
Or under DOS / Windows:
copy /b side1.tap + side2.tap bothsides.tap
There are at least three similar formats, .SPC, .STA and .LTP, which can also be concatenated as described above.
The .TAP files contain blocks of tape-saved data. All blocks start with two bytes specifying how many bytes will follow (not counting the two length bytes). Then raw tape data follows, including the flag and checksum bytes. The checksum is the bitwise XOR of all bytes including the flag byte. For example, when you execute the line SAVE "ROM" CODE 0,2 this will result:
|------ Spectrum-generated data -------| |---------| 13 00 00 03 52 4f 4d 7x20 02 00 00 00 00 80 f1 04 00 ff f3 af a3 ^^^^^...... first block is 19 bytes (17 bytes+flag+checksum) ^^... flag byte (A reg, 00 for headers, ff for data blocks) ^^ first byte of header, indicating a code block file name ..^^^^^^^^^^^^^ header info ..............^^^^^^^^^^^^^^^^^ checksum of header .........................^^ length of second block ........................^^^^^ flag byte ...........................................^^ first two bytes of rom .................................^^^^^ checksum (checkbittoggle would be a better name!).............^^
Note that it is possible to join .TAP files by simply stringing them together; for example, in DOS / Windows: COPY /B FILE1.TAP + FILE2.TAP ALL.TAP ; or in Unix/Linux: cp file1.tap all.tap && cat file2.tap >> all.tap
For completeness, I'll include the structure of a tape header. A header always consists of 17 bytes:
|0||1||Type (0,1,2 or 3)|
|1||10||Filename (padded with blanks)|
|11||2||Length of data block|
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.
(originally from TECHINFO.DOC supplied with Z80 by Gerton Lunter)
The block length stored in the SPC format is two less than stored in TAP, and the parity byte in SPC does not include the flag byte in its calculation. The format is otherwise identical to TAP. Used by the SP emulator (under DOS) by J. Swiatek and K. Makowski.
The block length stored in the STA format is two less than stored in TAP, and the parity byte is not stored at all. The format is otherwise identical to TAP. Used by Speculator (under RISC OS) by Dave Lawrence. Documented in J. G. Harston's tape formats document.
The block length stored in the LTP format is two less than stored in TAP. The format is otherwise identical to TAP. Used by Nuclear ZX (under DOS) by Radovan Garabik and Lubomir Salanci. Documented as part of the Nuclear ZX documentation.
The ZXT format is identical to .TAP, except that it has a 128-byte +3DOS header. This is used to manipulate tape files on the Spectrum +3, since +3DOS does not record the exact length of headerless files. The 8-byte BASIC header is set to the ASCII string 'TAPEFILE'. Documented as part of the TAPROM documentation.
Because they have +3DOS headers, .ZXT files cannot be simply concatenated.
Article license information
This article uses material from the "Spectrum emulator file formats" article on the ZX Spectrum technical information wiki at Wikia and is released under the Creative Commons Attribution-Share Alike License.