This page aims to explain how Metroid II's music works on the inside.
Bank 4 is dedicated to all the music and sound data and code. The game almost always leaves this bank in the swappable bank area of the system's memory map in order to focus on interpreting the music data.
Just for quick reference, the Game Boy utilizes a stereo PSG composed of four monophonic channels. Their details are listed below.
|1||Pulse-wave - Can generate pulse waves at duty cycles of 12.5%, 25%, 50%, or 75%. Also has a frequency sweep.|
|2||Pulse-wave - Same as above, except lacking the sweep.|
|3||4-bit Wavetable - Can generate customizable waveforms from a table of 32.|
|4||White Noise - Can generate only white noise. Used as percussion in music.|
At 0x11F30 in the ROM starts the list where the game finds the next music track to play. There are 32 2-byte pointers to each of them. Right after this list ends is another list, this time 32 1-byte flags determining how each song in the last list utilizes the stereo panning.
STEREO FLAGS DB - Pulse channel 2 is panned to the right. DE - Pulse channel 1 is panned to the left, and pulse channel 2 is panned to the right. FF - Song is totally center-panned.
|01 - Baby Metroid||FF|
|02 - VS. Queen Metroid||FF|
|03 - Chozo Ruins||FF|
|04 - Main Caves||FF|
|05 - Sub Caves 1||FF|
|06 - Sub Caves 2||FF|
|07 - Sub Caves 3||FF|
|08 - Final Caves||FF|
|09 - Metroid Hive (no intro)||FF|
|0A - Item Acquired||DB|
|0B - Queen Metroid Hallway||FF|
|0C - VS. Metroid||FF|
|0D - Sub Caves 4||FF|
|0E - Earthquake||DE|
|0F - Metroid Defeated||DE|
|10 - Nothing||FF|
|11 - Title||FF|
|12 - Samus Appearance||DE|
|13 - Ending||FF|
|14 - Chozo Ruins (dupe of 03)||FF|
|15 - Main Caves (not intro)||FF|
|16 - Sub Caves 1 (no intro)||FF|
|17 - Sub Caves 2 (no intro)||FF|
|18 - Sub Caves 3 (no intro)||FF|
|19 - Final Caves (dupe of 08)||FF|
|1A - Metroid Hive (dupe of 09)||FF|
|1B - Item Acquired (dupe of 0A)||DB|
|1C - Queen Metroid Hallway (dupe of 0B)||FF|
|1D - VS. Metroid (dupe of 0B)||FF|
|1E - Sub Caves 4 (no intro)||FF|
|1F - Metroid Hive||FF|
|20 - Missile Expansion||DE|
Each song is defined by a header of 0x0B bytes.
SONG HEADER Note Offset - 1 byte - A signed value determining how much to add to or subtract from the song's pitch. Tempo Offset - 2 bytes - Points to the tempo array to be used in the song. Channel Instruction Pointers - 8 bytes (2 for each channel) - Points to the instruction list for each sound channel to play. Can be set to 0000 to completely ignore the channel, and can even point to the same list, as some songs set both pulse channels to the same pointer.
These contains all the pointers to each instruction pattern.
INSTRUCTION LIST COMMANDS 0000 - Stops playing sound through the channel for the rest of the song's playing. 00F0 - Loops the channel starting from the specified offset following the command.
Each offset pointed to by the instruction lists is just a sequence of bytes the game interprets. What they do is detailed below.
Ends the instruction pattern, passing it on to the next pointer in the instruction list.
A rest note.
Echoes the preceding note at a volume of 0x46.
Echoes the preceding note at a volume of 0x66.
Changes the note length, x being the requested index in the currently-loaded tempo array.
Initializes the instrument in the pulse and wave channels. Pulse - Envelope, sweep, and duty cycle are represented by 3 bytes in that order. Wave - First 2 bytes point to the waveform to be loaded, last one defines volume.
Loads the tempo array from the specified 2-byte pointer.
Transposes the song.
Repeats a section of instructions the number of times specified by the byte right after.
Encloses the section mentioned above.
Just about every other byte is a note value. They range from 0x02 to 0x9E, and should all be even values. They are listed below.
In determining what pitch the values play at in the song, the following formula is used.
base note value + (0x18 * note level) + noteoffset - if noteoffset is an odd number (In the case of a negative noteoffset like 0xFE, replace noteoffset with (256 - noteoffset))
From 0x1009E-0x10106 are nine arrays of 0xD bytes. They are loaded as the song tempo in the header or by instruction F2, and each individual notelength byte is loaded by an Ax instruction. The bytes' values represent a number of sound engine ticks to last through, but are organized into a more consistent representation of standard notelengths in each 0xD-byte array.
|Offset||Approx. BPM||1/64 note||1/32 note||1/16 note||1/8 note||1/4 note||1/2 note||3/32 note||3/16 note||3/8 note||Unknown 1||Unknown 2||Unknown 3||1/1 note|