Anonymous

TAP format: Difference between revisions

From Sinclair Wiki
2,692 bytes added ,  19 January 2011
no edit summary
No edit summary
No edit summary
Line 2: Line 2:
[[Category:File Formats]]
[[Category:File Formats]]
{{Emulator Image Formats}}
{{Emulator Image Formats}}
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 [[:Category:Spectrum|ZX Spectrum]] [[ZX Spectrum Tape Format|"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:
{|border="1"
!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)''
{{Template:CC-BY-SA-techwiki|Spectrum emulator file formats|Spectrum_emulator_file_formats#TAP_format}}