Pure-JS VGM → XGM2 music converter for Sega Genesis / Mega Drive (SGDK XGM2 driver). A faithful port of SGDK's xgm2tool — no Java, no native binary. Parses a .vgm and emits a compiled XGM2 blob you .incbin into a ROM and play with XGM2_play().
Pure-JS VGM → XGM2 music converter for the Sega Genesis / Mega Drive (SGDK's
XGM2 driver). A faithful port of SGDK's xgm2tool - no Java, no jar, no native
binary. Parse a .vgm (or gzipped .vgz), get the compiled XGM2 blob you
.incbin into a ROM and play with XGM2_play().
Why this exists: XGM2_play() needs a compiled XGM2 blob (split FM/PSG streams
sample table), not raw VGM. SGDK's only official VGM→XGM2 compiler is
xgm2tool, a Java tool - heavy to bundle in a WASM-only toolchain. This is
that tool, ported to JS, so a music path needs zero external dependencies.
(ffmpeg cannot do this - XGM2 is a chiptune register stream, not audio samples.)
Usage
import { readFileSync } from "node:fs";import { vgmToXgm2C } from "romdev-xgm2";const vgm = readFileSync("song.vgm"); // or a gzipped .vgzconst { blob, cSource, lenDefine } = vgmToXgm2C(vgm, "bgm_level1");// blob -> Uint8Array, the XGM2 data (256-byte aligned in ROM)// cSource -> ready-to-#include C: `const u8 bgm_level1[] __attribute__((aligned(256)))` + BGM_LEVEL1_LEN// then in your game: XGM2_play(bgm_level1);