A block
The blocks follow the header one after another to the end of the file. Each starts with a 16-byte header, little-endian, and then holds as many data bytes as its size says.
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 4 | Tag | The ASCII letters DATA. Game_Music_Emu warns when they are missing from the first block (“Data header missing”) and carries on. |
| 4 | 4 | Size | The number of data bytes that follow the block header. Many files give a wrong one. |
| 8 | 4 | Physical address | Where in the ROM image the first data byte goes. The ROM image is 1 MB: addresses from 0 to $FFFFF, which the mapping registers $00 to $7F select in pages of 8 KB (page = address / $2000). Game_Music_Emu reports an address above the ROM (“Invalid address”) and wraps it into the ROM; it also reports a block that runs past the end (“Invalid size”). |
| 12 | 4 | Reserved | Zero. Game_Music_Emu warns when they are not (“Unknown header data”). |
| 16 | size | Data | The bytes of the tune: HuC6280 code and music data. Nothing marks which is which; the init address of the file header and the interrupt vectors say where code starts. |
Every byte of a block is read from the file as it stands: the explorer’s structure tree names the tag, the size, the physical address, the reserved bytes and the data.
How the data is loaded
A player makes a ROM image of 1 MB, every byte $FF, and copies the data of the block to its physical address. A
mapping register value from $00 to $7F then makes a page of the ROM visible to the processor.
Bytes that no block provides read as $FF. A block that starts in the middle of a page (an address that is not a multiple of
$2000) starts at that offset in the page.
Rules for a valid block
- The tag is
DATA. - The size is the number of bytes that follow; the next block (if any) starts right after them.
- The address and the size keep the block inside the 1 MB ROM (address + size at most
$100000). - The four reserved bytes are zero.
- The file ends at the end of the last block.
Several blocks and wrong sizes
The container allows any number of blocks. Game_Music_Emu’s author found none and loads the first block only, taking its data as everything to the end of the file (it warns “Multiple DATA not supported”, “Extra file data” or “Missing file data” when the size does not match). NEZplug++ loads all of them. The explorer loads all of them in file order, with a size that runs past the end of the file cut to what is there (and listed as a problem on the Size field) and bytes after the last block listed as extra bytes.
Divergence from the specification
There is no specification. The rules above are those of the two player sources; where they differ (the number of blocks that are loaded and what is done with a wrong size) the explorer follows NEZplug++ for the blocks and Game_Music_Emu for the tolerance of a wrong size, and says so on the field.
Sources
- Game_Music_Emu 0.6.1,
gme/Hes_Emu.cpp,load_: the block header, the warnings and the 1 MB ROM. - NEZplug++,
src/nezvm/m_hes.c: the loop over all DATA blocks.