A .ym holds no code and no score: it is what a player routine wrote to the Yamaha YM2149 (the Atari ST's sound chip, and the AY-3-8910's twin in the Spectrum and the CPC), one frame of registers per tick, usually fifty a second. Sixteen bytes a frame is a lot, so the registers are stored interleaved -- every frame's r0, then every frame's r1 -- which turns slow-changing registers into long runs, and the file is packed in an LHA archive. What sits on disk is the archive; the tune is inside it.
Level 0 only. ST-Sound reads only the oldest header layout, so a YM is archived with it. The header's own checksum is the byte sum of everything after the first two bytes. The body that follows is -lh5-: LZSS over an 8 KB window with Huffman codes rebuilt every block, bits read most significant first. A block opens with its symbol count and three code-length tables -- a small one that codes the next, the 510 literal-and-length symbols (256 bytes and match lengths 3 to 256), and 14 position classes -- and a position class p above 1 is followed by p-1 raw bits. The CRC-16 (the ARC one: polynomial 0x8005, reflected, starting at zero) is of the unpacked tune. A single zero byte ends the archive.
YM5 and YM6 share this header. After it come the digidrums, each a
32-bit size and that many 8-bit samples, then the song name, author and comment as
NUL-terminated strings, then the register data, then End!.
Name, author, comment, in that order, each ending in a zero. An empty one is the zero alone. This file's comment, not drawn, names who converted it.
Sixteen registers a frame. r0-r13 are the chip's, with the bits it does not use cleared; r14 and r15 carry YM6's special effects (SID voice, digidrum, sync buzzer), whose parameters also ride in the chip registers' spare bits. Interleaved, register k of frame f is at k x frames + f. Drawn: the first twelve frames of r8, voice A's volume.
YM3! is the magic and nothing else: fourteen registers a frame,
interleaved, at 50 Hz on a 2 MHz chip, and the frame count is what fits in the file.
YM2! is the same layout from the Mad Max player, whose drums came from samples built
into the player rather than the file. YM3b adds a 32-bit loop frame as the last four
bytes. YM4! is an intermediate version between YM3b and YM5 and is not drawn here.
MIX1, YMT1 and YMT2 carry the same LeOnArD! but are
ST-Sound's sample-remix and sample-tracker types, not register dumps.
On disk, -lh5- at offset 2 of an LHA member; inside, one of
YM2!, YM3!, YM3b, YM4!, YM5!,
YM6! at zero, and YM4 and later follow it with LeOnArD!.