# Tape: the EAR input, TAP and TZX ## The hardware path (DOC: FAQ48) The tape signal arrives at the ULA's pin 28, which also drives MIC, EAR and the speaker; the CPU reads it as bit 6 of port FE. Pera Putnik's measurement (FAQ48): bit 6 reads 1 when pin 28 is above 0.70 V "on both Issue 2 and Issue 3, with no inverting or hysteresis". Because the same pin is driven by the last OUT to FE, what bit 6 reads with no tape playing depends on bits 3 and 4 of that OUT and on the board issue (keyboard-border-sound.md), and it changes with a delay after bit 4 goes from 1 to 0 ("from approximately 180 T states ... to 2800 T states", depending on how long it was high; capacitors between pin 28 and the sockets). The board models the tape as a level on EAR, sampled whenever port FE is read. The ROM loader (LD-BYTES at 0556 in the 48K ROM) and every custom loader measure the time between edges by counting loop iterations, so a loader running in contended memory, or with interrupts, sees the contention: tape loading is a contention test in disguise. ## The standard ROM encoding (DOC: FAQ48; TZX 1.20 agrees) | Part | Length | | --- | --- | | pilot pulse | 2,168 T, repeated 8,063 times before a header (flag < 128) or 3,223 before data | | first sync pulse | 667 T | | second sync pulse | 735 T | | a 0 bit | two pulses of 855 T | | a 1 bit | two pulses of 1,710 T | Bytes most significant bit first; a block is a flag byte (00 header, FF data), the data and an XOR checksum. The header is 17 bytes: type (0 program, 1 number array, 2 character array, 3 code), 10-character name, length, two parameters (FAQ48 "Tape Data Structure"). FAQ48 says "the TZX format specification incorrectly states that header pulses contain 8064 leader pulses and data blocks 3220"; TZX revision 1.20 (2006) gives 8,063 and 3,223, so the FAQ's complaint is against an earlier TZX revision and there is no live contradiction (recorded as resolved, C11). **TZX timings are in 3.5 MHz T-states on every machine** (TZX 1.20 "Rules and definitions": "1 T state = (1/3500000)s"). On the 128K models (3.5469 MHz) a tape pulse of n TZX T-states lasts n x 3.5469/3.5 CPU T-states: the tape player runs on wall time, not on the CPU's T. ## TAP (DOC: FAQ formats page) A sequence of blocks, each a 2-byte little-endian length then the bytes as on tape (flag, data, checksum). It holds only standard-speed blocks: everything the ROM can load. ## TZX 1.20 (DOC: TZX format specification, World of Spectrum) Blocks the board's player needs: 10 standard speed, 11 turbo speed, 12 pure tone, 13 pulse sequence, 14 pure data, 15 direct recording (sampled), 18 CSW recording, 19 generalised data, 20 pause or stop, 21/22 group, 23 jump, 24/25 loop, 26/27 call and return, 28 select, 2A stop if 48K, 2B set signal level, and the information blocks 30-35 and 5A that only need skipping. After blocks 10-14 and 19 the level is the opposite of the last pulse played; a pause holds 1 ms of the opposite level before going low. 16, 17, 34 and 40 are deprecated. The format's text is facts only (no licence stated); the parser is ours, written from the specification's tables. ## Tests and the library Tape Test (Woodmass, 2009), TZX Test Files (Woodmass, 2024: five tiny files for loops, calls and jumps), Non-Standard Tape Test (azesmbog) and ld-bytes-emu-tests (a GitLab project in the collection) exercise loaders. The TOSEC `[TAP]` set (4,420 files) is the library; no TZX set is present in the mirror (census.md). ## Out of scope at first Saving to tape (MIC output) beyond recording the level; the +2's built-in cassette deck and the +2A/+3's tape socket behave the same at port FE as far as the pinned sources say (FAQ128 notes only the +2A/+3's bit-6 difference).