Introduction
A GYM file is a recording of the sound of a Sega Mega Drive (Genesis in North America). It holds no notes and no audio: it holds the writes that the game made to the console’s two sound chips, the YM2612 (six FM channels, one of which can play samples through a DAC) and the SN76489 (three tone channels and one noise channel), in the order they happened, with a marker for the end of every video frame. A player sends the writes to models of the chips and the chips make the sound.
The format first appeared in the Genecyst emulator as a plain log of sound writes, and Gens writes and plays it too. A raw GYM file has no header at all; the later GYMX files put a 428-byte header with the names of the song, the game and the dumper in front, and may pack the commands with zlib or with EZPK. The pages follow the published description of the format and the source of the players that read it, and say where they differ.
Structure
A raw file is the stream of commands from byte 0. Its first byte is 0 to 3, which is the only test a player has. A GYMX file
starts with the four letters GYMX, then six text fields, the loop start and the packed length, and the commands follow at byte 428.
0Tag GYMX4 bytes4Text fields song, game, copyright, emulator, dumper (32 bytes each), comment (256)416 bytes420Loop start a frame number, 0 for none4 bytes424Packed length 0, or the length of the commands once unpacked4 bytes428Commands 00 frame end, 01 and 02 YM2612 writes, 03 SN76489 write; or a zlib or EZPK stream of themto the end
The header and commands pages give every field, Frames, loop and length says how the frames, the loop and the length work (and how the DAC samples are timed), and The sound chips says what the registers do and how the explorer makes the sound.
What the explorer shows
The explorer reads the whole file: every byte of the header is in the structure tree, a zlib-packed body is inflated and an EZPK-packed body unpacked in the browser, and every command is listed in the Commands tab with what the register write means (the same register descriptions as the VGM viewer). A byte that is not a command, a command cut short, commands after the last frame end, a loop start beyond the last frame and a body that does not inflate are listed as problems.
It then plays the log with the VGM viewer’s YM2612 and SN76489 models, unchanged. The options bar has the region (NTSC 60 or PAL 50 frames a second, with the matching chip clocks), the DAC timing (at the frame start as Gens does, which is the default, spread over the frame as Game_Music_Emu does, or evenly from the frame start as the foobar2000 decoder does), the number of times the loop plays, the longest time to play and a mute switch for each chip.
Divergence from the specification
The format has no author’s specification; the description and the players differ in a few places, and the explorer’s choice is given for each.
- The packed length. The published description says the packed field holds the size of the data “if GZipped”. In every packed file read
(five files from Modland) it holds the size of the data inflated, and the data is a zlib stream (header
78 DA), not a gzip file. The explorer inflates the data and reports a field that does not match the result as a problem. - Packed files in players. Game_Music_Emu refuses a packed file (“Packed GYM file not supported”); the explorer plays it. A second packing, EZPK (YMAMP 2.0b), has no document either; it is read from the code of two readers and checked on 13 real files (EZPK).
- Frame rate. Game_Music_Emu always plays 60 frames a second and reports a length of frames × 50/3 ms. The explorer defaults to NTSC (60) and offers PAL (50) with the PAL clocks.
- Unknown commands. A first byte above 3 is not defined. Real files have them (one of the five packed files has two). Game_Music_Emu skips the byte; so does the explorer, and lists each as a problem.
- The loop. The description says the loop start is how many frames into the song the loop begins. Game_Music_Emu’s track information agrees (an intro of N frames) but its player starts the loop one frame earlier, at the start of frame N−1 counted from 0. The explorer follows the description: the loop begins after N frames.
- The DAC. See Frames, loop and length: three ways to time the samples are offered; the default is Gens’s, with the others as options.
- Level. The chips are the VGM viewer’s, not Game_Music_Emu’s. On sample files the FM level is 0.96 of Game_Music_Emu’s, the PSG level 1.46 and the DAC level 0.69; the PSG and DAC ratios follow from Game_Music_Emu’s volume settings (The sound chips).
- A loop that never starts. A loop start of the number of frames or more would begin the loop after the last frame. The explorer lists it as a problem and ends the tune at the end of the data; Game_Music_Emu ends the track when it never finds the loop start.
Sources
- vgmrips, “GYM File Format” (the page is gone; the copy of 30 September 2020 kept by the Internet Archive): the header, the commands, the loop and packed fields.
- Sega Retro, “GYM”: the history of the format and the accuracy of its frame timing.
- Gens (rofl0r’s copy),
src/gens/util/sound/gym.c: the dump and the play of the format. - Game_Music_Emu (libgme),
gme/Gym_Emu.cpp,Gym_Emu.h: the header test, the frame, the loop, the length, the DAC timing and the unknown commands. - The Modland tree
Megadrive GYMand the Zophar.net GYM archive of 2006 (kept at archive.org): the real files read, raw, unpacked GYMX and zlib-packed GYMX. The Modland files of Super Shinobi 2: thirteen EZPK-packed GYMX files. - The EZPK packing: MasterBoy’s foobar2000 GYM decoder and gme.library (EZPK).
- The sound is the YM2612 and SN76489 of the VGM viewer. The explorer is checked against Game_Music_Emu built from the source above on real and built sample files; the files, their builder and the sources with their SHA-256 are in the site’s research folder.
Links
Software
- Game_Music_Emu – the player library that reads unpacked GYM files
- Gens – the Mega Drive emulator whose dump function wrote the format
Reference
- Sega Retro: GYM – history and notes on the format
- vgmrips: GYM File Format – the header and command description (Internet Archive copy)