TAP format: Difference between revisions

From Sinclair Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
Line 1: Line 1:
[[category:Specifications]
[[Category:Emulator Tape Image Formats]]
[[Category:Emulator Tape Image Formats]]
[[Category:File Formats]]
[[Category:File Formats]]

Revision as of 20:48, 24 March 2011

[[category:Specifications] 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

Format Description

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:

Byte 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.

(originally from TECHINFO.DOC supplied with Z80 by Gerton Lunter)

Article license information

This article uses material from the "Spectrum emulator file formats" article on the ZX Spectrum technical information wiki at Fandom (formerly Wikia) and is released under the Creative Commons Attribution-Share Alike License.