The 16 bytes
All numbers are little-endian. The header is exactly 16 bytes; the first DATA block starts at byte 16.
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 4 | Magic | The ASCII letters HESM. A file without them is not a HES file. |
| 4 | 1 | Version | 0 in every file. Game_Music_Emu warns about any other value but plays the file; the explorer lists it as a problem. |
| 5 | 1 | Start song | The song a player starts with, counted from 0. It is the value the player puts in the accumulator when it calls the init routine. The header gives no number of songs. |
| 6 | 2 | Init address | The logical address (in the 64 KB the processor sees) of the init routine. A player sets the program counter to it, with the mapping registers below already in place. |
| 8 | 8 | Mapping registers | The initial values of MPR0 to MPR7: byte 8 is MPR0 (logical $0000 to $1FFF), byte 15 is MPR7 ($E000 to $FFFF). See Memory and mapping. |
Rules for a valid header
- The file is at least 16 bytes long and starts with
HESM. - The version is 0.
- The init address and the mapping registers should lead to code: MPR values below
$80are ROM pages that a DATA block has to fill,$F8is RAM and$FFthe hardware page. A page that no block fills reads as$FFbytes. - The file has at least one DATA block; the explorer lists a file without one as a problem.
What the header does not say
There is no number of songs, no length, no title, artist or copyright, and no play address or play rate: the tune’s own interrupt handlers play it (see INIT, timer and interrupts). The only text is the optional block described next, which is part of the data and not of the header.
Text at offset 0x40
Bytes 0x20 to 0x3F of the file (the first 32 bytes of the first DATA block’s data) are not read by any
player. From 0x40 Game_Music_Emu (copy_hes_fields and copy_field in Hes_Emu.cpp, and the
Hes_File reader, which skips 0x20 header bytes and 0x20 unused bytes and then takes the fields) looks for three text
fields in a row: game, author, copyright. Neither NEZplug++ (its text slots are declared and never filled from the file) nor Mednafen reads them.
- Nothing is read unless the byte at
0x40is0x20or more. - Each field is 32 bytes, or 48 bytes when byte
0x1Fof the field is not zero and byte0x2Fis zero. - A field counts as text when every byte up to its first zero is above
0x20and is not0xFF, and every byte after that zero up to the end of the field is zero. - The first field that fails ends the reading: it and the later ones are left empty.
Because they are bytes of the data, they are also loaded into the ROM image like any other; the tune never sees them as anything but data. All other bytes of a file are named: the 16-byte header, then for each block the 16-byte block header and the data.
In the explorer
The structure tree shows the header with each field and, under the mapping registers, one row for each of MPR0 to MPR7 with the page it selects. The Tune tab shows the start song and the init address, and the text fields of the previous section when Game_Music_Emu’s rule finds them (also as children of the first Data node in the tree).
Divergence from the specification
There is no specification. Game_Music_Emu and NEZplug++ read the same 16 bytes in the same way; neither checks anything but the four letters (Game_Music_Emu also warns about a version other than 0). The rules above that the explorer checks beyond that are its own.
Sources
- Game_Music_Emu 0.6.1,
gme/Hes_Emu.cpp: the header structure, the load, and the start (header_t,load_,start_track_). - NEZplug++,
src/nezvm/m_hes.c: the same fields read by a second player.