Inside the Sharp MZF tape file
A byte-by-byte tour of the format used to preserve Sharp MZ-80K and MZ-700 cassette software, and how MZF Viewer decides what to show you.
Sharp's MZ-80K, launched in Japan in 1978 and in Europe soon after, came with a built-in cassette deck. All of its software, even its BASIC interpreter, loaded from tape. Today that software survives as .mzf files: the bytes read from each recording, saved to disk. Knowing the layout of an MZF file is the key to reading one. It's also the first thing MZF Viewer does when you open a file.
New to $1200-style hex numbers or "little-endian"? The glossary explains them from scratch.
Two parts: header and body
Every recording on a Sharp MZ tape has two blocks. The first is a fixed-size header that describes the file. The second is the body, which holds the program or data itself. An MZF file keeps both, one after the other:
+------------------------+----------------------------------+
| header (128 bytes) | body (size given in the header) |
+------------------------+----------------------------------+
The 128-byte header
| Offset (hex) | Length | Meaning |
|---|---|---|
00 | 1 | Attribute: what kind of file this is (see below) |
01–11 | 17 | Filename in the Sharp character set, ended by 0D (carriage return) |
12–13 | 2 | Size of the body in bytes |
14–15 | 2 | Load address, where the body goes in memory |
16–17 | 2 | Execution address, where to start running machine code |
18–7F | 104 | Comment area, often empty or used by loaders |
The 16-bit values are little-endian, as usual for the Z80: the low byte comes first. So the bytes 00 12 mean $1200.
A worked example
Here's the start of a header for a machine-code game called GAME. It's an illustrative example, not a real file:
00: 01 47 41 4D 45 0D 0D 0D 0D 0D 0D 0D 0D 0D 0D 0D
10: 0D 0D 00 10 00 12 00 12 ...
01means machine code.47 41 4D 45spells "GAME", followed by0Dpadding.- Size
00 10is$1000, or 4,096 bytes. - Load address
00 12is$1200. - Execution address
00 12is also$1200, so the code starts at its first byte.
$1200 is no accident. On the MZ-80K the monitor ROM uses the memory just below it, so $1200 is where user programs normally load.
The attribute byte
The first byte tells the loader what to do with the body. The two you'll meet most often are:
01: machine code. The body is loaded at the load address and run from the execution address.02: BASIC program. The body is a tokenised BASIC program, to be loaded by a BASIC interpreter that's already running.
Other values exist for data files and for software from later Sharp models. When MZF Viewer meets an attribute it doesn't recognise, the hex dump view (mode=DUMP) is the safest way to look inside.
Why BASIC needs the right "mode"
The MZ-80K had no BASIC in ROM. You loaded an interpreter from tape, and there were several to choose from: Sharp's own SP-5025 family, SA-5510 and others. The MZ-700 had its own 1Z-013B BASIC. To save memory, each one stores keywords such as PRINT and GOTO as single-byte tokens. But they don't all use the same numbers for the same keywords.
The header can't tell you which interpreter saved a BASIC file, so the viewer can't always tell either. That's why MZF Viewer lets you choose the token table:
mode=SPfor SP-5025-style BASIC on the MZ-80Kmode=SAfor SA-5510 BASICmode=1Zfor MZ-700 BASIC
If a listing looks like nonsense, with keywords in odd places, try another mode. Seeing a listing suddenly make sense when you switch is a satisfying moment.
Once the right table is chosen, a short program reads just as it did on a Sharp screen:
10 PRINT "HELLO FROM 1979"
20 GOTO 10
Shown in the MZ80B font, built from the character ROM of the MZ-80B, the MZ-80K's 1981 sibling, so a close relative of the MZ-80K's own characters (see credits).
The Sharp character set
The MZ-80K's version of ASCII, often called Sharp ASCII, matches standard ASCII for the space, digits, capital letters and most punctuation, from $20 to $5D. After that it goes its own way:
$5Eand$5Fare ↑ and ← arrows, where ASCII has^and_.$60–$7F, where ASCII has lower-case letters, hold graphics and symbols for drawing on screen.- Lower-case letters do exist, but they're scattered between
$92and$BDin an unusual order, mixed in with German umlauts.ais$A1,bis$9Aandeis$92. - Most of
$C0–$FFis more graphics: card suits, boxes and line-drawing pieces.
There's a second twist. The codes in a file aren't the codes the screen uses. Screen memory holds display codes, a separate numbering in which space is 0 and A–Z are 1–26. The computer converts from Sharp ASCII to display codes whenever it prints a character. MZF files contain Sharp ASCII, so that's the table that matters when you read them. MZF Viewer converts each character to the closest readable equivalent, so filenames and PRINT strings display sensibly in a modern browser.
To see every character, look at the MZ-80K character set chart (PDF) at mz-80a.com, from Sharp's MZ-80K manual. It has both the ASCII code table and the display code table.
Try it yourself
- Open Cursed Chambers in MZF Viewer, an MZ-80K BASIC adventure.
- Switch to
DUMPand find the attribute byte and filename at the start of the header. - Open Connect Four for the MZ-700 in Z80 mode, and check that the disassembly starts at the load address from the header.
For thousands more files, the MZ-Archive is the place to go. For the history of the machine itself, see sharpmz.no.