Welcome to Data Crystal's new home! Data Crystal is now part of the TCRF family (sort of).
The wiki has recently moved; please report any issues in Discord. Pardon the dust.

Metroid/Music data format

From Data Crystal
Jump to navigation Jump to search

This is a sub-page of Metroid.

The Metroid music format was likely decoded by Dirty McDingus, as a complete description of it appears in his disassembly of the game.

Init music index table

This table appears at BBFA in every ROM bank with music (every bank except the graphics and engine banks). It translates song IDs into offsets (given as one byte) into the Init Music Table. Curiously, the songs are not in the same order in the two tables.

The song order is:

  • 0: Ridley
  • 1: Tourian
  • 2: Item room
  • 3: Kraid
  • 4: Norfair
  • 5: Escape
  • 6: Mother Brain
  • 7: Brinstar
  • 8: Game start
  • 9: Power up (i.e. received item or beat boss)
  • A: Ending
  • B: Title screen

Init Music Table

This table is present in every ROM bank with music. It is located at $BD31 in each bank.

The order (as defined by the Init Music Index table) is:

  • 0: Mother Brain
  • 1: Escape
  • 2: Norfair
  • 3: Kraid
  • 4: Item room
  • 5: Ridley
  • 6: Ending
  • 7: Title screen
  • 8: Game start
  • 9: Power up
  • A: Brinstar
  • B: Tourian

The format is:

  • Index into note length table (will be $00, $0B, or $17)
  • Does song loop at end? (zero = no, nonzero = yes)
  • Triangle length counter control
  • Instrument ID for square 1
  • Instrument ID for square 2
  • Address of square 1 music data
  • Address of square 2 music data
  • Address of triangle music data
  • Address of noise music data

All of these are one byte except for the addresses, which take two.

If a song is not used in the current bank, its offsets are given as $0100, $0300, $0500, $0700.

The "triangle length counter control" is how long notes will be held on the triangle channel before being released. It has no effect on the duration: if you took a track and changed this value, the notes may sound longer or shorter, but the next note doesn't come any sooner or later. Values used are $00, $03, $F0, and $F5. The exact meaning is a bit obscure.

The idea appears to be something like this:

  • If both nybbles are zero, the note will play for up to the length of a quarter note. (I'm not entirely sure of this behavior; the code is hard to read. This is what it does for the Brinstar theme, at any rate. The behavior depends on the value of the register Y at $BBC5, but I don't know where Y's value comes from or what it means.)
  • Else, if the low nybble is nonzero, the triangle channel will play for that many frames (one to fifteen), thus creating staccato notes (or pops).
  • Else, if instead the high nybble is nonzero, the triangle channel will play until the next note.

Music data

  • $00 - Ends or loops the song. Affects all channels.
  • $Bx - Sets length of subsequent notes to x (as defined by the song's note lengths table)
  • %11xxxxxx - start of local loop; loop x times
  • $FF - end of local loop
  • $02-7E - indexes into note frequency table. Since the table uses two bytes per entry, the numbers must be even.

The noise channel doesn't use the note frequency table. Instead, $1, $4, $7, and $A choose among four different sounds defined in a table at $B200.

Note lengths tables

These tables are present in every bank with music. The first table is located at $BEF7, with the other two immediately following.

Metroid doesn't define things like quarter notes and eighth notes, nor does it specify a number of frames to hold a note. Instead, the number of frames is stored in a table, and which table is used depends on the song (see Init Music Table).

The number of frames a note is held is as follows (in decimal):

Table 0 (index of $00) - used by Power Up and Kraid

  • 0: 4
  • 1: 8
  • 2: 16
  • 3: 32
  • 4: 64
  • 5: 24
  • 6: 48
  • 7: 12
  • 8: 11
  • 9: 5
  • A: 2

Table 1 (index of $0B) - used by all music that doesn't use tables 0 or 2

  • 0: 6
  • 1: 12
  • 2: 24
  • 3: 48
  • 4: 96
  • 5: 36
  • 6: 72
  • 7: 18
  • 8: 16
  • 9: 8
  • A: 3

Table 2 (index of $17) - used by title screen and ending

  • 0: 16
  • 1: 7
  • 2: 14
  • 3: 28
  • 4: 56
  • 5: 112
  • 6: 42
  • 7: 21
  • 8: 18
  • 9: 2
  • A: 3

Note frequency table

This table is at $BE77 in each bank with music. This is a simple chromatic scale with the exception that D#2 is omitted.

  • 00 - [not possible to use, as $00 is a control code]
  • 02 - [silence; used for playing rests]
  • 04 - C#2
  • 06 - D2
  • 08 - E2 (D#2 was skipped!)
  • 0A - F2
  • 0C - F#2
  • 0E - G2
  • 10 - G#2
  • 12 - A2
  • 14 - A#2
  • 16 - B2
  • 18 - C3
  • 1A - C#3
  • 1C - D3
  • 1E - D#3
  • 20 - E3
  • 22 - F3
  • 24 - F#3
  • 26 - G3
  • 28 - G#3
  • 2A - A
  • 2C - A#3
  • 2E - B3
  • 30 - C4
  • 32 - C#4
  • 34 - D
  • 36 - D#4
  • 38 - E4
  • 3A - F4
  • 3C - F#4
  • 3E - G4
  • 40 - G#4
  • 42 - A4
  • 44 - A#4
  • 46 - B4
  • 48 - C
  • 4A - C#5
  • 4C - D5
  • 4E - D#5
  • 50 - E5
  • 52 - F5
  • 54 - F#5
  • 56 - G5
  • 58 - G#5
  • 5A - A5
  • 5C - A#5
  • 5E - B5
  • 60 - C6
  • 62 - C#6
  • 64 - D6
  • 66 - D#6
  • 68 - E6
  • 6A - F6
  • 6C - F#6
  • 6E - G6
  • 70 - G#6
  • 72 - A
  • 74 - A#6
  • 76 - B6
  • 78 - C7
  • 76 - C#7
  • 78 - D7
  • 7A - D#7
  • 7C - E7
  • 7E - F7