Home » Archimedes archive » Archimedes World » AW-1996-02-Disc2.adf » !Z80Dem_Z80Demo » Docs/FileFormat/TAPformat
Docs/FileFormat/TAPformat
This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.
Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.
Tape/disk: | Home » Archimedes archive » Archimedes World » AW-1996-02-Disc2.adf » !Z80Dem_Z80Demo |
Filename: | Docs/FileFormat/TAPformat |
Read OK: | ✔ |
File size: | 0AD5 bytes |
Load address: | 0000 |
Exec address: | 0000 |
File contents
(from the docs for Gerton Lunter's Z80 emulator for the PC) .TAP FILES: ----------- 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 datablocks) ^^ first byte of header, indicating a code block filename ^^^^^^^^^^^^^ header info ^^^^^^^^^^^^^^^^^ checksum of header ^^ length of second block ^^^^^ flag byte ^^ first two bytes of rom ^^^^^ checksum (checkbittoggle would be better) ^^ The emulator will always start reading bytes at the beginning of a block. If less bytes are loaded than are available, the other bytes are skipped, and the last byte loaded is used as checksum. If more bytes are asked for than exist in the block, the loading routine will terminate with the usual tape-loading-error flags set, leaving the error handling to the calling Z80 program. Note that it is possible to join .TAP files by simply stringing them together, for example COPY /B FILE1.TAP + 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.
00000000 28 66 72 6f 6d 20 74 68 65 20 64 6f 63 73 20 66 |(from the docs f| 00000010 6f 72 20 47 65 72 74 6f 6e 20 4c 75 6e 74 65 72 |or Gerton Lunter| 00000020 27 73 20 5a 38 30 20 65 6d 75 6c 61 74 6f 72 20 |'s Z80 emulator | 00000030 66 6f 72 20 74 68 65 20 50 43 29 0a 0a 2e 54 41 |for the PC)...TA| 00000040 50 20 46 49 4c 45 53 3a 0a 2d 2d 2d 2d 2d 2d 2d |P FILES:.-------| 00000050 2d 2d 2d 2d 0a 0a 20 20 20 20 54 68 65 20 2e 54 |----.. The .T| 00000060 41 50 20 66 69 6c 65 73 20 63 6f 6e 74 61 69 6e |AP files contain| 00000070 20 62 6c 6f 63 6b 73 20 6f 66 20 74 61 70 65 2d | blocks of tape-| 00000080 73 61 76 65 64 20 64 61 74 61 2e 20 20 41 6c 6c |saved data. All| 00000090 20 62 6c 6f 63 6b 73 20 73 74 61 72 74 20 77 69 | blocks start wi| 000000a0 74 68 0a 20 20 20 20 74 77 6f 20 62 79 74 65 73 |th. two bytes| 000000b0 20 73 70 65 63 69 66 79 69 6e 67 20 68 6f 77 20 | specifying how | 000000c0 6d 61 6e 79 20 62 79 74 65 73 20 77 69 6c 6c 20 |many bytes will | 000000d0 66 6f 6c 6c 6f 77 20 28 6e 6f 74 20 63 6f 75 6e |follow (not coun| 000000e0 74 69 6e 67 20 74 68 65 20 74 77 6f 0a 20 20 20 |ting the two. | 000000f0 20 6c 65 6e 67 74 68 20 62 79 74 65 73 29 2e 20 | length bytes). | 00000100 20 54 68 65 6e 20 72 61 77 20 74 61 70 65 20 64 | Then raw tape d| 00000110 61 74 61 20 66 6f 6c 6c 6f 77 73 2c 20 69 6e 63 |ata follows, inc| 00000120 6c 75 64 69 6e 67 20 74 68 65 20 66 6c 61 67 20 |luding the flag | 00000130 61 6e 64 0a 20 20 20 20 63 68 65 63 6b 73 75 6d |and. checksum| 00000140 20 62 79 74 65 73 2e 20 20 54 68 65 20 63 68 65 | bytes. The che| 00000150 63 6b 73 75 6d 20 69 73 20 74 68 65 20 62 69 74 |cksum is the bit| 00000160 77 69 73 65 20 58 4f 52 20 6f 66 20 61 6c 6c 20 |wise XOR of all | 00000170 62 79 74 65 73 20 69 6e 63 6c 75 64 69 6e 67 0a |bytes including.| 00000180 20 20 20 20 74 68 65 20 66 6c 61 67 20 62 79 74 | the flag byt| 00000190 65 2e 20 20 46 6f 72 20 65 78 61 6d 70 6c 65 2c |e. For example,| 000001a0 20 77 68 65 6e 20 79 6f 75 20 65 78 65 63 75 74 | when you execut| 000001b0 65 20 74 68 65 20 6c 69 6e 65 20 53 41 56 45 20 |e the line SAVE | 000001c0 22 52 4f 4d 22 20 43 4f 44 45 0a 20 20 20 20 30 |"ROM" CODE. 0| 000001d0 2c 32 20 74 68 69 73 20 77 69 6c 6c 20 72 65 73 |,2 this will res| 000001e0 75 6c 74 3a 0a 0a 0a 20 20 20 20 20 20 20 20 20 |ult:... | 000001f0 20 20 20 20 7c 2d 2d 2d 2d 2d 2d 20 53 70 65 63 | |------ Spec| 00000200 74 72 75 6d 2d 67 65 6e 65 72 61 74 65 64 20 64 |trum-generated d| 00000210 61 74 61 20 2d 2d 2d 2d 2d 2d 2d 7c 20 20 20 20 |ata -------| | 00000220 20 20 20 7c 2d 2d 2d 2d 2d 2d 2d 2d 2d 7c 0a 20 | |---------|. | 00000230 20 20 20 20 20 20 31 33 20 30 30 20 30 30 20 30 | 13 00 00 0| 00000240 33 20 35 32 20 34 66 20 34 64 20 37 78 32 30 20 |3 52 4f 4d 7x20 | 00000250 30 32 20 30 30 20 30 30 20 30 30 20 30 30 20 38 |02 00 00 00 00 8| 00000260 30 20 66 31 20 30 34 20 30 30 20 66 66 20 66 33 |0 f1 04 00 ff f3| 00000270 20 61 66 20 61 33 0a 0a 20 20 20 20 20 20 20 5e | af a3.. ^| 00000280 5e 5e 5e 5e 20 20 20 20 20 20 20 66 69 72 73 74 |^^^^ first| 00000290 20 62 6c 6f 63 6b 20 69 73 20 31 39 20 62 79 74 | block is 19 byt| 000002a0 65 73 20 28 31 37 20 62 79 74 65 73 2b 66 6c 61 |es (17 bytes+fla| 000002b0 67 2b 63 68 65 63 6b 73 75 6d 29 0a 20 20 20 20 |g+checksum). | 000002c0 20 20 20 20 20 20 20 20 20 5e 5e 20 20 20 20 66 | ^^ f| 000002d0 6c 61 67 20 62 79 74 65 20 28 41 20 72 65 67 2c |lag byte (A reg,| 000002e0 20 30 30 20 66 6f 72 20 68 65 61 64 65 72 73 2c | 00 for headers,| 000002f0 20 66 66 20 66 6f 72 20 64 61 74 61 62 6c 6f 63 | ff for databloc| 00000300 6b 73 29 0a 20 20 20 20 20 20 20 20 20 20 20 20 |ks). | 00000310 20 20 20 20 5e 5e 20 66 69 72 73 74 20 62 79 74 | ^^ first byt| 00000320 65 20 6f 66 20 68 65 61 64 65 72 2c 20 69 6e 64 |e of header, ind| 00000330 69 63 61 74 69 6e 67 20 61 20 63 6f 64 65 20 62 |icating a code b| 00000340 6c 6f 63 6b 0a 0a 20 20 20 20 20 20 20 66 69 6c |lock.. fil| 00000350 65 6e 61 6d 65 20 20 20 20 5e 5e 5e 5e 5e 5e 5e |ename ^^^^^^^| 00000360 5e 5e 5e 5e 5e 5e 0a 20 20 20 20 20 20 20 68 65 |^^^^^^. he| 00000370 61 64 65 72 20 69 6e 66 6f 20 20 20 20 20 20 20 |ader info | 00000380 20 20 20 20 20 20 20 20 5e 5e 5e 5e 5e 5e 5e 5e | ^^^^^^^^| 00000390 5e 5e 5e 5e 5e 5e 5e 5e 5e 0a 20 20 20 20 20 20 |^^^^^^^^^. | 000003a0 20 63 68 65 63 6b 73 75 6d 20 6f 66 20 68 65 61 | checksum of hea| 000003b0 64 65 72 20 20 20 20 20 20 20 20 20 20 20 20 20 |der | 000003c0 20 20 20 20 20 20 20 20 20 20 20 20 20 5e 5e 0a | ^^.| 000003d0 20 20 20 20 20 20 20 6c 65 6e 67 74 68 20 6f 66 | length of| 000003e0 20 73 65 63 6f 6e 64 20 62 6c 6f 63 6b 20 20 20 | second block | 000003f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 00000400 20 20 20 20 20 20 5e 5e 5e 5e 5e 0a 20 20 20 20 | ^^^^^. | 00000410 20 20 20 66 6c 61 67 20 62 79 74 65 20 20 20 20 | flag byte | 00000420 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | * 00000440 20 20 20 20 20 20 20 20 20 5e 5e 0a 20 20 20 20 | ^^. | 00000450 20 20 20 66 69 72 73 74 20 74 77 6f 20 62 79 74 | first two byt| 00000460 65 73 20 6f 66 20 72 6f 6d 20 20 20 20 20 20 20 |es of rom | 00000470 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 00000480 20 20 20 20 20 20 20 20 20 20 20 5e 5e 5e 5e 5e | ^^^^^| 00000490 0a 20 20 20 20 20 20 20 63 68 65 63 6b 73 75 6d |. checksum| 000004a0 20 28 63 68 65 63 6b 62 69 74 74 6f 67 67 6c 65 | (checkbittoggle| 000004b0 20 77 6f 75 6c 64 20 62 65 20 62 65 74 74 65 72 | would be better| 000004c0 29 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 |) | 000004d0 20 20 20 20 20 20 5e 5e 0a 0a 0a 20 20 20 20 54 | ^^... T| 000004e0 68 65 20 65 6d 75 6c 61 74 6f 72 20 77 69 6c 6c |he emulator will| 000004f0 20 61 6c 77 61 79 73 20 73 74 61 72 74 20 72 65 | always start re| 00000500 61 64 69 6e 67 20 62 79 74 65 73 20 61 74 20 74 |ading bytes at t| 00000510 68 65 20 62 65 67 69 6e 6e 69 6e 67 20 6f 66 20 |he beginning of | 00000520 61 0a 20 20 20 20 62 6c 6f 63 6b 2e 20 20 49 66 |a. block. If| 00000530 20 6c 65 73 73 20 62 79 74 65 73 20 61 72 65 20 | less bytes are | 00000540 6c 6f 61 64 65 64 20 74 68 61 6e 20 61 72 65 20 |loaded than are | 00000550 61 76 61 69 6c 61 62 6c 65 2c 20 74 68 65 20 6f |available, the o| 00000560 74 68 65 72 20 62 79 74 65 73 20 61 72 65 0a 20 |ther bytes are. | 00000570 20 20 20 73 6b 69 70 70 65 64 2c 20 61 6e 64 20 | skipped, and | 00000580 74 68 65 20 6c 61 73 74 20 62 79 74 65 20 6c 6f |the last byte lo| 00000590 61 64 65 64 20 69 73 20 75 73 65 64 20 61 73 20 |aded is used as | 000005a0 63 68 65 63 6b 73 75 6d 2e 20 20 49 66 20 6d 6f |checksum. If mo| 000005b0 72 65 20 62 79 74 65 73 0a 20 20 20 20 61 72 65 |re bytes. are| 000005c0 20 61 73 6b 65 64 20 66 6f 72 20 74 68 61 6e 20 | asked for than | 000005d0 65 78 69 73 74 20 69 6e 20 74 68 65 20 62 6c 6f |exist in the blo| 000005e0 63 6b 2c 20 74 68 65 20 6c 6f 61 64 69 6e 67 20 |ck, the loading | 000005f0 72 6f 75 74 69 6e 65 20 77 69 6c 6c 0a 20 20 20 |routine will. | 00000600 20 74 65 72 6d 69 6e 61 74 65 20 77 69 74 68 20 | terminate with | 00000610 74 68 65 20 75 73 75 61 6c 20 74 61 70 65 2d 6c |the usual tape-l| 00000620 6f 61 64 69 6e 67 2d 65 72 72 6f 72 20 66 6c 61 |oading-error fla| 00000630 67 73 20 73 65 74 2c 20 6c 65 61 76 69 6e 67 20 |gs set, leaving | 00000640 74 68 65 20 65 72 72 6f 72 0a 20 20 20 20 68 61 |the error. ha| 00000650 6e 64 6c 69 6e 67 20 74 6f 20 74 68 65 20 63 61 |ndling to the ca| 00000660 6c 6c 69 6e 67 20 5a 38 30 20 70 72 6f 67 72 61 |lling Z80 progra| 00000670 6d 2e 0a 0a 20 20 20 20 4e 6f 74 65 20 74 68 61 |m... Note tha| 00000680 74 20 69 74 20 69 73 20 70 6f 73 73 69 62 6c 65 |t it is possible| 00000690 20 74 6f 20 6a 6f 69 6e 20 2e 54 41 50 20 66 69 | to join .TAP fi| 000006a0 6c 65 73 20 62 79 20 73 69 6d 70 6c 79 20 73 74 |les by simply st| 000006b0 72 69 6e 67 69 6e 67 20 74 68 65 6d 0a 20 20 20 |ringing them. | 000006c0 20 74 6f 67 65 74 68 65 72 2c 20 66 6f 72 20 65 | together, for e| 000006d0 78 61 6d 70 6c 65 20 43 4f 50 59 20 2f 42 20 46 |xample COPY /B F| 000006e0 49 4c 45 31 2e 54 41 50 20 2b 20 46 49 4c 45 32 |ILE1.TAP + FILE2| 000006f0 2e 54 41 50 20 41 4c 4c 2e 54 41 50 0a 0a 20 20 |.TAP ALL.TAP.. | 00000700 20 20 46 6f 72 20 63 6f 6d 70 6c 65 74 65 6e 65 | For completene| 00000710 73 73 2c 20 49 27 6c 6c 20 69 6e 63 6c 75 64 65 |ss, I'll include| 00000720 20 74 68 65 20 73 74 72 75 63 74 75 72 65 20 6f | the structure o| 00000730 66 20 61 20 74 61 70 65 20 68 65 61 64 65 72 2e |f a tape header.| 00000740 20 20 41 20 68 65 61 64 65 72 0a 20 20 20 20 61 | A header. a| 00000750 6c 77 61 79 73 20 63 6f 6e 73 69 73 74 73 20 6f |lways consists o| 00000760 66 20 31 37 20 62 79 74 65 73 3a 0a 0a 20 20 20 |f 17 bytes:.. | 00000770 20 20 20 20 20 42 79 74 65 20 20 20 20 4c 65 6e | Byte Len| 00000780 67 74 68 20 20 44 65 73 63 72 69 70 74 69 6f 6e |gth Description| 00000790 0a 20 20 20 20 20 20 20 20 30 20 20 20 20 20 20 |. 0 | 000007a0 20 31 20 20 20 20 20 20 20 54 79 70 65 20 28 30 | 1 Type (0| 000007b0 2c 31 2c 32 20 6f 72 20 33 29 0a 20 20 20 20 20 |,1,2 or 3). | 000007c0 20 20 20 31 20 20 20 20 20 20 20 31 30 20 20 20 | 1 10 | 000007d0 20 20 20 46 69 6c 65 6e 61 6d 65 20 28 70 61 64 | Filename (pad| 000007e0 64 65 64 20 77 69 74 68 20 62 6c 61 6e 6b 73 29 |ded with blanks)| 000007f0 0a 20 20 20 20 20 20 20 20 31 31 20 20 20 20 20 |. 11 | 00000800 20 32 20 20 20 20 20 20 20 4c 65 6e 67 74 68 20 | 2 Length | 00000810 6f 66 20 64 61 74 61 20 62 6c 6f 63 6b 0a 20 20 |of data block. | 00000820 20 20 20 20 20 20 31 33 20 20 20 20 20 20 32 20 | 13 2 | 00000830 20 20 20 20 20 20 50 61 72 61 6d 65 74 65 72 20 | Parameter | 00000840 31 0a 20 20 20 20 20 20 20 20 31 35 20 20 20 20 |1. 15 | 00000850 20 20 32 20 20 20 20 20 20 20 50 61 72 61 6d 65 | 2 Parame| 00000860 74 65 72 20 32 0a 0a 20 20 20 20 54 68 65 20 74 |ter 2.. The t| 00000870 79 70 65 20 69 73 20 30 2c 31 2c 32 20 6f 72 20 |ype is 0,1,2 or | 00000880 33 20 66 6f 72 20 61 20 50 72 6f 67 72 61 6d 2c |3 for a Program,| 00000890 20 4e 75 6d 62 65 72 20 61 72 72 61 79 2c 20 43 | Number array, C| 000008a0 68 61 72 61 63 74 65 72 20 61 72 72 61 79 20 6f |haracter array o| 000008b0 72 0a 20 20 20 20 43 6f 64 65 20 66 69 6c 65 2e |r. Code file.| 000008c0 20 20 41 20 73 63 72 65 65 6e 24 20 66 69 6c 65 | A screen$ file| 000008d0 20 69 73 20 72 65 67 61 72 64 65 64 20 61 73 20 | is regarded as | 000008e0 61 20 43 6f 64 65 20 66 69 6c 65 20 77 69 74 68 |a Code file with| 000008f0 20 73 74 61 72 74 20 61 64 64 72 65 73 73 0a 20 | start address. | 00000900 20 20 20 31 36 33 38 34 20 61 6e 64 20 6c 65 6e | 16384 and len| 00000910 67 74 68 20 36 39 31 32 20 64 65 63 69 6d 61 6c |gth 6912 decimal| 00000920 2e 20 20 49 66 20 74 68 65 20 66 69 6c 65 20 69 |. If the file i| 00000930 73 20 61 20 50 72 6f 67 72 61 6d 20 66 69 6c 65 |s a Program file| 00000940 2c 20 70 61 72 61 6d 65 74 65 72 0a 20 20 20 20 |, parameter. | 00000950 31 20 68 6f 6c 64 73 20 74 68 65 20 61 75 74 6f |1 holds the auto| 00000960 73 74 61 72 74 20 6c 69 6e 65 20 6e 75 6d 62 65 |start line numbe| 00000970 72 20 28 6f 72 20 61 20 6e 75 6d 62 65 72 20 3e |r (or a number >| 00000980 3d 33 32 37 36 38 20 69 66 20 6e 6f 20 4c 49 4e |=32768 if no LIN| 00000990 45 0a 20 20 20 20 70 61 72 61 6d 65 74 65 72 20 |E. parameter | 000009a0 77 61 73 20 67 69 76 65 6e 29 20 61 6e 64 20 70 |was given) and p| 000009b0 61 72 61 6d 65 74 65 72 20 32 20 68 6f 6c 64 73 |arameter 2 holds| 000009c0 20 74 68 65 20 73 74 61 72 74 20 6f 66 20 74 68 | the start of th| 000009d0 65 20 76 61 72 69 61 62 6c 65 0a 20 20 20 20 61 |e variable. a| 000009e0 72 65 61 20 72 65 6c 61 74 69 76 65 20 74 6f 20 |rea relative to | 000009f0 74 68 65 20 73 74 61 72 74 20 6f 66 20 74 68 65 |the start of the| 00000a00 20 70 72 6f 67 72 61 6d 2e 20 20 49 66 20 69 74 | program. If it| 00000a10 27 73 20 61 20 43 6f 64 65 20 66 69 6c 65 2c 0a |'s a Code file,.| 00000a20 20 20 20 20 70 61 72 61 6d 65 74 65 72 20 31 20 | parameter 1 | 00000a30 68 6f 6c 64 73 20 74 68 65 20 73 74 61 72 74 20 |holds the start | 00000a40 6f 66 20 74 68 65 20 63 6f 64 65 20 62 6c 6f 63 |of the code bloc| 00000a50 6b 20 77 68 65 6e 20 73 61 76 65 64 2c 20 61 6e |k when saved, an| 00000a60 64 20 70 61 72 61 6d 65 74 65 72 0a 20 20 20 20 |d parameter. | 00000a70 32 20 68 6f 6c 64 73 20 33 32 37 36 38 2e 20 20 |2 holds 32768. | 00000a80 46 6f 72 20 64 61 74 61 20 66 69 6c 65 73 20 66 |For data files f| 00000a90 69 6e 61 6c 6c 79 2c 20 74 68 65 20 62 79 74 65 |inally, the byte| 00000aa0 20 61 74 20 70 6f 73 69 74 69 6f 6e 20 31 34 20 | at position 14 | 00000ab0 64 65 63 69 6d 61 6c 0a 20 20 20 20 68 6f 6c 64 |decimal. hold| 00000ac0 73 20 74 68 65 20 76 61 72 69 61 62 6c 65 20 6e |s the variable n| 00000ad0 61 6d 65 2e 0a |ame..| 00000ad5