Skeetendo

’Cause all games were better on the GBC

You are not logged in.

#1 1970-01-01 00:33:30

Melash
Member
Registered: 2010-10-16
Post 2/132

Music Hacking Resource Document

Introduction

Before we start out, let me make something clear. This is not a step by step tutorial on how to hack the music in GB/GBC games, but more a resource you can use in hacking. It's a little unorganized, but it should help some people out. Sorry it's a bit long and bleak, I tried to make it a little interesting.

Purpose for writing

This document will list the offsets of all music headers in all games, explain the format of the music headers, and the basic format of the music data

Getting Started

Programs needed:

Skills needed:

  • Basic usage of a hex editor

  • Elementary knowledge of pointers

GSC Music

First off, I'll explain a little about how the music works in GBC. There are up to four channels for every music track; Two are the lead tremble part, one is the bass, and the last is the drums. For every music track, there is a music header. The music header points to where the actual music data is located, the notes and such. Here is a full list of where the music headers are located in GSC, sorted by offset:

E9492 - S.S. Aqua
EA267 - Ice Path
EAD42 - Trainer- Basic Tune
EB27C - New Bark Town
EB3FC - Goldenrod City
EB61F - Vermilion City
EBD92 - Unown Ruins
EBDCB - Whirl Islands
EBDD5 - Meet trainer - Freaky Tune
EE35E - Meet Trainer - Japanese Tune 2
EE45F - Special Fanfare?
EE569 - Whirl Islands
EE6C5 - Routes 42-44
EE852 - Indigo Plateau
EE94B - Routes 38-39
EEB75 - Rocket's Hideout
EECE8 - Dragon's Den
EEDCB - Unown Radio Station
EEE3E - Trainer Rocket Tune
EEFB2 - Routes 26-27
EF5B1 - Weird
EF9BC - Dance Theatre
EFB3E - Bug Contest Results
0F0386 - Routes 34-37
0F07FD - Printer Error
F4602 - Killed a Wild Pokemon
F605C - Wild Pokemon (Johto)
F66C3 - Trainer Girl Tune
F6811 - Tin Tower
F6974 - Sprout Tower
F6A99 - Burned Tower
F6BF2 - Meet Mom
F6C72 - Victory Road
F6D79 - Pokemon Lullaby
F6E23 - Pokemon March
F7055 - Intro - Part 1
F7308 - Intro - Part 2
F766D - Rockets Take Radio Tower
F78FD - New Game/Continue
F7B13 - Pokeflute
F7C16 - Bug Contest

Now you know where the headers are located, it's time to learn the format of the music headers. Here is the format of all music formats:

vv ww ww 01 xx xx 02 yy yy 03 zz zz

vv: Byte at beginning of header, not exactly sure what it means
ww ww: 2-byte pointer to first channel
xx xx: 2-byte pointer to second channel
yy yy: 2-byte pointer to third channel
zz zz: 2-byte pointer to fourth channel

If a music track doesn't have a fourth channel, it simply won't have the pointer to it. Okay, so we now know where all the music headers are located, and their format. Now it's time to learn the format of the actual music data. Here's the note structure for Gold and Silver, I'm assuming it's the same for Crystal:


Notes (x = note delay)
0x - No Note
1x - C
2x - C♯
3x - D
4x - D♯
5x - E
6x - F
7x - F♯
8x - G
9x - G♯
Ax - A
Bx - A♯
Cx - B (H)
D0 - Octave 7
D1 - Octave 6
D2 - Octave 5
D3 - Octave 4
D4 - Octave 3
D5 - Octave 2
D6 - Octave 1
D7 - Octave 0
D8 xx yz - xx Frames per note delay unit, Velocity y, Note Length z
DA hh ll - Set Tempo (yes, hh ll, not ll hh, the lower the value the faster)
DB xx - Duty Cycle (00-03), might also be instrument selection for Ch3
DC yz - Velocity y, Note Length z (basicalyl same as D8 without the xx)
E1 xx yz - Vibrato - Delay xx, Depth y, Rate z
E3 xx - Noise Setting (instrument?)
E6 xx xx - Tune (not sure what the arguments for this are..)
EF xx - Panning (unsure of the arguments..)
FD 00 ll hh - Jump (this is used to set the loop point for the song, ll = low byte, hh = high byte)
FE ll hh - Subroutine (ll = low byte, hh = high byte, the return address is the location directly after this command)
FF - End / Return from Subroutine


You can use Sound Edit v1.3 to add in basic notes, but you actually have to go in and manually add in the loop points and other small stuff. Very annoying, but it's the only way to do it.

RBY Music

Since we've already learned the basics of music headers, I won't have to reexplain everything again, I can just give you the offsets. Here are all the locations of music headers in RBY:


822E-8236 Pallet Town
8237-823F Pokecenter
8240-8248 Gym
8249-8254 Viridian / Pewter / Saffron
8255-825D Cerulean / Fuchsia
825E-8266 Celedon
8267-826F Cinnibar
8270-827B Vermilion
827C-8287 Lavender
8288-8290 S.S. Anne
8291-8299 Meet Prof. Oak
829A-82A2 Meet Rival
82A3-82AE Guy Walks you to Museum
82AF-82B7 Safari Zone
82B8-82C0 Pokemon get healed
82C1-82CC Routes 1 / 2
82CD-82D8 Routes 24 / 25
82D9-82E4 Routes 3 / 4 / 5 / 6 / 7 / 8 / 9 / 10 / 16 / 17 / 18 / 19 / 20 / 21 / 22
82E5-82F0 Routes 11 / 12 / 13 / 14 / 15
82F1-82FD Route 23 / Indigo Plateau
7C249-7C254 Title Screen
7C255-7C25D Credits
7C25E-7C266 Hall of FAme Registration
7C267-7C26F PRof Oak's LAb
7C270-7C275 Jigglypuff's Song
7C276-7C281 Bike Riding
7C282-7C28A Surfing
7C28B-7C293 Casino
7C294-7C29F Introduction Battle
7C2A0-7C2AB Power Plant / Unknown Dungeon
7C2AC-7C2B7 Viridian Forest / Seafoam Islands
7C2B8-7C2C3 Mt. Moon / Rock Tunnel / Victory Road
7C2C4-7C2CF Cinnibar Mansion
7C2D0-7C2D8 Pokemon Tower
7C2D9-7C2E1 Silph Co
7C2E2-7C2EA Meet Bad Trainer
7C2EB-7C2F3 Meet Girl Trainer
7C2F4-7C2FC Meet Angry Trainer


The music headers have the same format as GSC. It seems Game Freak doesn't like to change the coding in their games that much. Unfortunately the basic note structure is a little different. Here's the basic note structure for Red and Blue, once again I'm not sure if Yellow is exactly the same:


Notes (x = note delay)
0x - B
1x - C
2x - C♯
3x - D
4x - D♯
5x - E
6x - F
7x - F♯
8x - G
9x - G♯
Ax - A
Bx - A♯
Cx - No Note

Note Delay:
x0: 1/16
x1: 1/8
x2: 1/8.
x3: 1/4
x4:
x5: 1/4.
x6:
x7: 1/2
xB: 1/2.
xF: 1

E0 - Octave 7
E1 - Octave 6
E2 - Octave 5
E3 - Octave 4
E4 - Octave 3
E5 - Octave 2
E6 - Octave 1
E7 - Octave 0

It's almost the same as GSC. The octave data has changed along with several other bytes. So, you can't import songs from RBY to GSC by using a "copy and pasting" method, but you can manually redo it without too much stress. Unfortunately I only have the basic structure, and not the other data, such as loops points and other information.

Credits

All right, that's all the music data I've found. If you have any questions, or would like me to add in more information, please ask, and I'll gladly do so. Credits go to:
Coolboyman - Giving me most of the music data format I have here
Data Crystal - Contained a Gold and Red ROM map where I got my offsets
If I forgot you, please tell me.
Fin.

Offline

#2 2010-12-30 18:25:02

Sawakita
Administrator
Registered: 2010-10-16
Post 69/365

Re: Music Hacking Resource Document

Since RBY music is explained here, I thought it would be better if I post here.
Here's what I can say about first byte in a music-track's header:
Bits 6-7 (where bits are counted as follows: 7654 3210) tell how many channels are there. In fact:

ld a,[de]   ; load byte
ld b,a      ; save it for later
rlca        ; rotate with carry
rlca        ; twice
and a,3     ; reset all bits but bits 0-1
ld c,a      ; save it for later

So here are the combinations:
00 = 1 channel (= 1 pointer)
01 = 2 channel (= 2 pointers)
10 = 3 channel (= 3 pointers)
11 = 4 channel (= 4 pointers)

As far as I've seen until now, other bits are always reset (=0), but I bet that not always they are (since there's a chunk of code that checks them). So if you have, for example, $80 that music will have 3 pointers, if you have $C0, there will be 4 pointers.

Offline

#3 2011-01-23 16:20:31

blackopient
Member
From: Houston, TX
Registered: 2010-11-01
Post 12/15

Re: Music Hacking Resource Document

Well I've got a little melody inserted but I'm not sure how to get it looping. For command FD 00 ll hh, what exactly are the low and high bytes it's asking for?

Offline

#4 2011-01-23 20:24:27

Tauwasser
Member
Registered: 2010-10-16
Post 85/452

Re: Music Hacking Resource Document

Well guys, that's one program I never thought I would see again lol.
A friend of mine programmed it for a hack he and myself did, Pokémon Silverstar (a Pokémon Gold hack). Basically, I dug around in the music engine some and unearthed what commands did what on a register logic basis. He applied his musical talents to determine what they actually did in a semantic sense, since I know squat about music.

The following is original research into this topic (by the creator of the program) translated into English below. Be warned: I make no claims of accuracy of the information whatsoever. All offsets and registers are for the German version of Pokémon Gold.

https://sites.google.com/site/tauwasser/musik_e.rtf

The guy successfully changed Silverstar's title screen music to Evanescence's Bring me to Life, if memory serves.

cYa,

Tauwasser

Offline

#5 2012-12-22 12:17:06

delpo
Member
Registered: 2012-11-26
Post 30/40

Re: Music Hacking Resource Document

Has anyone found any other information beyond what is in this thread?  I am trying to import songs from RB to GS, but there are too many differences in the byte structure for loop points and the other things.  Really, the only similarities are in the note and note length byte structures.

Offline

#6 2012-12-22 23:06:09

comet
Member
Registered: 2012-04-09
Post 69/679

Re: Music Hacking Resource Document

i have crystal's. apparently they're slightly different from gs'

music_commands_new = {
    0xD0: ["octave8"],
    0xD1: ["octave7"],
    0xD2: ["octave6"],
    0xD3: ["octave5"],
    0xD4: ["octave4"],
    0xD5: ["octave3"],
    0xD6: ["octave2"],
    0xD7: ["octave1"],
    0xD8: ["notetype", ["note_length", SingleByteParam], ["intensity", SingleByteParam]], # only 1 param on ch3
    0xD9: ["forceoctave", ["octave", SingleByteParam]],
    0xDA: ["tempo", ["tempo", MultiByteParam]],
    0xDB: ["dutycycle", ["duty_cycle", SingleByteParam]],
    0xDC: ["intensity", ["intensity", SingleByteParam]],
    0xDD: ["soundinput", ["input", SingleByteParam]],
    0xDE: ["unknownmusic0xde", ["unknown", SingleByteParam]], # also updates duty cycle
    0xDF: ["unknownmusic0xdf"],
    0xE0: ["unknownmusic0xe0", ["unknown", SingleByteParam], ["unknown", SingleByteParam]],
    0xE1: ["vibrato", ["delay", SingleByteParam], ["extent", SingleByteParam]],
    0xE2: ["unknownmusic0xe2", ["unknown", SingleByteParam]],
    0xE3: ["togglenoise", ["id", SingleByteParam]], # this can have 0-1 params!
    0xE4: ["panning", ["tracks", SingleByteParam]],
    0xE5: ["volume", ["volume", SingleByteParam]],
    0xE6: ["tone", ["tone", MultiByteParam]], # big endian
    0xE7: ["unknownmusic0xe7", ["unknown", SingleByteParam]],
    0xE8: ["unknownmusic0xe8", ["unknown", SingleByteParam]],
    0xE9: ["globaltempo", ["value", MultiByteParam]],
    0xEA: ["restartchannel", ["address", PointerLabelParam]],
    0xEB: ["newsong", ["id", MultiByteParam]],
    0xEC: ["sfxpriorityon"],
    0xED: ["sfxpriorityoff"],
    0xEE: ["unknownmusic0xee", ["address", PointerLabelParam]],
    0xEF: ["stereopanning", ["tracks", SingleByteParam]],
    0xF0: ["sfxtogglenoise", ["id", SingleByteParam]], # 0-1 params
    0xF1: ["music0xf1"], # nothing
    0xF2: ["music0xf2"], # nothing
    0xF3: ["music0xf3"], # nothing
    0xF4: ["music0xf4"], # nothing
    0xF5: ["music0xf5"], # nothing
    0xF6: ["music0xf6"], # nothing
    0xF7: ["music0xf7"], # nothing
    0xF8: ["music0xf8"], # nothing
    0xF9: ["unknownmusic0xf9"],
    0xFA: ["setcondition", ["condition", SingleByteParam]],
    0xFB: ["jumpif", ["condition", SingleByteParam], ["address", PointerLabelParam]],
    0xFC: ["jumpchannel", ["address", PointerLabelParam]],
    0xFD: ["loopchannel", ["count", SingleByteParam], ["address", PointerLabelParam]],
    0xFE: ["callchannel", ["address", PointerLabelParam]],
    0xFF: ["endchannel"],
}

Offline

#7 2012-12-24 08:15:04

delpo
Member
Registered: 2012-11-26
Post 31/40

Re: Music Hacking Resource Document

Okay, after wasting hours trying to do this, I think there's no point in importing music from RB to GS.  The huge issue is the fact that the music sounds completely different between the gbc and gb due to a difference in the speaker.  What sounds great on the gb sounds cacophonous on the gbc.  Additionally, there are byte formats that I cannot figure out how to change to be compatible with the gbc format.  An example is EA 0A 25, which I could not figure out what it was for at all.

Offline

#8 2013-01-13 05:15:13

FroggestSpirit
Member
Registered: 2012-03-12
Post 25/300
Website

Re: Music Hacking Resource Document

I ported the trainer battle from RBY to GSC before, and it sounded exactly like it did in RBY


This isn't easy to say, but…
Music and ASM hacker

Offline

#9 2013-01-13 05:30:58

Danny-E 33
Administrator
Registered: 2012-06-09
Post 354/1,119

Re: Music Hacking Resource Document

Do you have documentation you could share about the undocumented byte formats for effects and looping like Melash says he does not have?
That would be fantastic.

Offline

#10 2013-01-13 17:21:55

Munchulax
Member
From: Somewhere in Johto
Registered: 2011-08-10
Post 230/410

Re: Music Hacking Resource Document

FroggestSpirit wrote:

I ported the trainer battle from RBY to GSC before, and it sounded exactly like it did in RBY

Really? Assuming you're not joking, this would be a quite the breakthrough in Gen II hacking.

Last edited by Munchulax (2013-01-13 17:22:22)


“To live is the rarest thing in the world. Most people exist, that is all.” ― Oscar Wilde

Offline

#11 2013-01-14 04:39:16

Chaos Rush
Member
Registered: 2010-10-16
Post 48/62

Re: Music Hacking Resource Document

delpo wrote:

The huge issue is the fact that the music sounds completely different between the gbc and gb due to a difference in the speaker.  What sounds great on the gb sounds cacophonous on the gbc.

Um no. The speaker has absolutely nothing to do with it.

I modded my Game Boy Pocket to have a speaker from a GBA SP. Music was exactly the same. (sound quality is higher though)
Also GB games sound exactly the same when played on a GBC. Or a GBA. Or a GBA SP. Or a GBC emulator.

Offline

#12 2013-01-14 16:08:07

FroggestSpirit
Member
Registered: 2012-03-12
Post 30/300
Website

Re: Music Hacking Resource Document

I don't have much extra, but I'll share what I have, and Munchulax, here's the proof aswell.
https://anonfiles.com/file/d8597cffa739 … 140317de5b
This contains 2 documents I wrote, I beleive i started with the one available, and added on.
There is also a rom and a save. Load the save, and you will hear the RBY trainer battle music upon fighting the trainer. (I made the backsprite)

Last edited by FroggestSpirit (2013-01-14 16:12:43)


This isn't easy to say, but…
Music and ASM hacker

Offline

#13 2013-01-14 23:35:48

Raven Freak
New member
Registered: 2012-06-30
Post 3/3

Re: Music Hacking Resource Document

That's some pretty sweet stuff, I'm going to try porting music from GSC to Red for fun now. :V

Offline

#14 2013-01-15 02:36:46

FroggestSpirit
Member
Registered: 2012-03-12
Post 33/300
Website

Re: Music Hacking Resource Document

I actually made a small tool to port gsc to rby (music that is). maybe I should finalize it, add rby to gsc, and release it. (it also adjusts pointers for calls and jumps)


This isn't easy to say, but…
Music and ASM hacker

Offline

#15 2013-01-15 04:45:24

Danny-E 33
Administrator
Registered: 2012-06-09
Post 364/1,119

Re: Music Hacking Resource Document

That information is wonderful!
Do you have anymore information on acceptable values for this?

Note Delay:
x0: 1/16
x1: 1/8
x2: 1/8.
x3: 1/4
x4:
x5: 1/4.
x6:
x7: 1/2
xB: 1/2.
xF: 1

For instance, do you know how to use triplets like in S.S. Anne? (I believe it actually uses triplet sixteenth notes, alongside sixteenth notes, which doesn't make sense to me)
fAnd does the "." have any significance after some of these values that Melash specified?

Offline

#16 2013-01-15 05:04:40

Mateo
Member
From: The Sims 4
Registered: 2009-11-25
Post 2,174/3,580

Re: Music Hacking Resource Document

Well a "dotted half note" (and a dotted from of any note) is held for a different length than a regular half note, so I can only assume that is what he was representing here.

Last edited by Mateo (2013-01-15 05:05:00)

Offline

#17 2013-01-15 05:06:26

stag019
Idea Killer
Registered: 2011-01-05
Post 275/630

Re: Music Hacking Resource Document

http://en.wikipedia.org/wiki/Dotted_note

Wikipedia wrote:

In modern practice the dot increases the duration of the basic note by half of its original value.


You can try to hide yourself in this world of pretend; when the paper's crumpled up, it can't be perfect again.

Offline

#18 2013-01-15 05:09:40

Mateo
Member
From: The Sims 4
Registered: 2009-11-25
Post 2,175/3,580

Re: Music Hacking Resource Document

Thanks stag019, I was actually just pulling that up to link to.

Offline

#19 2013-01-15 05:10:54

stag019
Idea Killer
Registered: 2011-01-05
Post 276/630

Re: Music Hacking Resource Document

That's what my robot is for.
Reports posts.
~google dotted note

<staggerbot019> Dotted note - Wikipedia, the free encyclopedia - In Western musical notation, a dotted note is a note with a small dot written after it . In modern practice the dot increases the duration of the basic note by half of its ... - http://en.wikipedia.org/wiki/Dotted_note


You can try to hide yourself in this world of pretend; when the paper's crumpled up, it can't be perfect again.

Offline

#20 2013-01-15 14:15:15

FroggestSpirit
Member
Registered: 2012-03-12
Post 37/300
Website

Re: Music Hacking Resource Document

It's actually the Dx command in the SS anne. DC sets it to normal speed, and the byte after is the envelope. D6 would be double speed, but I saw a D8 in there, so that must be where it gets the small speed up for triplets.


This isn't easy to say, but…
Music and ASM hacker

Offline

#21 2013-01-15 17:44:56

Danny-E 33
Administrator
Registered: 2012-06-09
Post 368/1,119

Re: Music Hacking Resource Document

Mateo wrote:

Well a "dotted half note" (and a dotted from of any note) is held for a different length than a regular half note, so I can only assume that is what he was representing here.

stag019 wrote:

http://en.wikipedia.org/wiki/Dotted_note

Wikipedia wrote:

In modern practice the dot increases the duration of the basic note by half of its original value.

Well I know music, I just didn't figure out that's what Melash was trying to represent here.. :P Thanks guys.

FroggestSpirit wrote:

It's actually the Dx command in the SS anne. DC sets it to normal speed, and the byte after is the envelope. D6 would be double speed, but I saw a D8 in there, so that must be where it gets the small speed up for triplets.

Interesting. Makes sense.
Could you further define an envelope?

Offline

#22 2013-01-15 18:55:18

FroggestSpirit
Member
Registered: 2012-03-12
Post 39/300
Website

Re: Music Hacking Resource Document

The first nybble is the initial volume, the second nybble is how fast it fades, and direction.
0 and 8 for second nybble have no fade
1-7 fade to no volume, with 1 being the fastest, 7 being the slowest fade
9-F fade to full volume, with 9 being the fastest, and F being the slowest fade
so, C7 would start the volume at C (which is fairly loud since F is the loudest), and it would slowly fade to 0 (mute)


This isn't easy to say, but…
Music and ASM hacker

Offline

#23 2013-01-16 01:50:21

Danny-E 33
Administrator
Registered: 2012-06-09
Post 370/1,119

Re: Music Hacking Resource Document

Okay, okay. I think I get it. I'll test my knowledge some day when I put custom music into Prototype.

Oh, and do you have any documents on the format of the noise channel?

Last edited by Danny-E 33 (2013-01-16 02:36:28)

Offline

#24 2013-01-16 02:40:49

FroggestSpirit
Member
Registered: 2012-03-12
Post 40/300
Website

Re: Music Hacking Resource Document

I wish... That's the one I'm not really knowledgeable in. I do know that you set the drumset with a command, and the 0-B (1-C if using GSC) commands are drums instead of notes. My advice would be to look at a song with drums in it, and maybe try to copy something like that?


This isn't easy to say, but…
Music and ASM hacker

Offline

#25 2013-01-16 04:05:18

Danny-E 33
Administrator
Registered: 2012-06-09
Post 371/1,119

Re: Music Hacking Resource Document

Okay. I'll look into it at some point.
A few other question. Do all channels tempos have to be the same? Does a track only need one channel to include a tempo change and then it's changed for all tracks, or does each channel have to include the tempo change at the same time?
Also, the Dx command that changes volume and fade should have no effect on the triangle since it can only have a volume of 0 or F right? Will that command give some sort of error if it's put into the triangle channel or will it just skip over it and keep reading?

Offline

Board footer

Powered by FluxBB