The four commands
The data (after the header, and after unpacking when it is packed with zlib or EZPK) is a stream of commands. Each starts with a one-byte code, followed by 0 to 2 bytes of arguments.
| Bytes | Command | Meaning |
|---|---|---|
00 | Frame | Do nothing for one frame: 1/60 s on an NTSC console, 1/50 s on PAL. Every sound written since the previous 00 sounds during this frame. |
01 rr vv | YM2612 port 0 | Write the value vv to register rr of the YM2612’s first register bank (channels 1 to 3 and the global registers). |
02 rr vv | YM2612 port 1 | Write vv to register rr of the second bank (channels 4 to 6). |
03 vv | SN76489 | Write the byte vv to the PSG port. |
What the registers mean is on The sound chips. Register 2A of port 0 is special: it is the DAC sample, and the commands that write it are timed by the rule on Frames, loop and length.
The start of a log
Gens begins a log with a snapshot of the chips, so that a player that starts from silence reaches the same state: the registers 30 to 8F and A0 to B7 of both ports, then registers 22, 27 and 28 of port 0. The snapshot is ordinary commands in the first frame.
What real files do
- First bytes above 3. The format defines nothing for them. Real files have them (one of five files read has two). Game_Music_Emu’s comment says many GYM streams are full of errors; it skips one byte for each and goes on.
- A command cut by the end of the file. The last command may be short of its arguments. The explorer ignores it and lists it as a problem.
- Commands after the last frame end. The final 00 may be missing. The explorer lists the commands after the last frame end and does not play them (they sound for no time).
- Writes to registers that do not exist. They are passed to the chip, which ignores them.
In the explorer
The Commands tab counts the commands by kind and lists every one: the number, the offset (in the file, or in the unpacked data of a packed file), the frame, the time, the bytes, the chip and the meaning of the register write, using the same register descriptions as the VGM viewer. The first command of the loop is marked.
Divergence from the specification
The description defines only the four commands. Everything in the section on real files is what the players do, not the description: Game_Music_Emu skips an unknown byte and the explorer does the same.
Sources
- vgmrips, “GYM File Format” (Internet Archive copy of 30 September 2020): the four commands.
- Gens,
src/gens/util/sound/gym.c(rofl0r’s copy): how the commands are written and played, and the snapshot at the start. - Game_Music_Emu,
gme/Gym_Emu.cpp,parse_frame: the unknown-byte rule and the comment about errors. - The real files read (
research/gym/dlin the site’s research folder):mega-net-bgm1.gymhas two unknown bytes.