Music hacking: the ELF method (no Sappy 2006!)

Well, I watched Blazer’s video on how they inserted music into an FE rom… and all I gotta say is that you people need to learn how to work with the bytes. So, I’ve decided to post my difficult to master, but EXTREMELY useful ELF method of inserting music.

THIS METHOD WILL WORK FOR ALL GBA GAMES, UNLESS FOR SOME REASON THEY USE A DIFFERENT MUSIC FORMAT WHICH IS HIGHLY UNLIKELY. Basically, if Sappy 2006 works for this, you can do it this way as well.

NOTE: This tutorial uses a Golden Sun: The Lost Age (Rom name AGFE). If you know the pointer to the music table, then you’ll be all set for Fire Emblem.

THE ELF METHOD

Roms used in this tutorial:

AGFE: Golden Sun: The Lost Age (a lot of people have been asking how I get the music into Pokemon, so I’m making a tutorial. This method works for any song, and it’s more reliable than Sappy’s built in assembler. Sappy doesn’t even work on my computer anyways…)

What you’ll need:
The Mid2gba set
Sappy 1.6
A Midi Program (like Anvil Studio)
A Tile Viewer/Hex Editor. Although Tile Viewer is recommended.

Okay,

STEP 1) Extract your song from Golden Sun: The Lost Age from Sappy.

In order to do this, you’ll have to change Sappy’s equavalent of a ini file (sappy.txt). Where it says Golden Sun, you can replace AGSE with AGFE, then switch the table offset (which is 0x80FC70C, I think for GS; TLA’s is at 0x81C4530). Anyways, after setting those in the sappy.txt file, open up Sappy 1.6 and load in Golden Sun: The Lost Age. Go to the song you want. Here’s a nice table for you with my totally awesome song names:
Golden Sun Songs
0002 Alfafa
0003 Temple 1
0004 Dalia
0005 Apooji
0006 Normal Gaia Rock Town
0007 Bummed Gaia Rock Town
0008 Sad Song
0009 Another Weird Foreign Song
000a Active Foregn Town
000b Ceremony
000c Lemuria
0041 Entrance to Lemuria
000d Normal Town
000e Happy Litte Island
000f Garoh
0010 That town with the dead dude
0011 Kids song 1
0012 Kids song 2
0014 Airs Rock
0015 Aqua Rock
0018 Gaia Rock
0017 Caves
0019 Statue
001a Jupiter Lighthouse
001b Magma Rock
001c Mars Lighthouse
001d Cold Temple
001e Swamp
001f Sandy Temple
0025 Shaman Village
0026 Sheba’s Sad Song
0028 Theme
0029 Sailing
002a Land Travel Before Jupiter Lighthouse
002b Land Travel After Jupiter Lighthouse
002c Golden Sun Rises
003c Ivan Theme
0027 More Evil
0022 Evil Karst and Agaito
0023 Briggs Gets Away!
0024 More Evil Stuff
0035 Even More Evil
003d Can you believe it? More Evil!
003e Prox
003f We’re gonna die!
0040 Sad GS Theme 1
0043 Sad GS Theme 2
0044 GS Theme 1
0046 GS Theme 2
0047 Uber Upbeat GS Theme
0048 Sad GS Theme 3
0049 GS Theme 3
004b GS Theme 4 (short)
004a Healing
02bc Vale
02d0 Mt. Aleph
02d2 Sol Sanctum
02e6 Overworld (Broken Seal)
02bd Happy Town (Broken Seal)
02d4 Caves (Broken Seal)
02be Sad Town (Broken Seal)
02bf Teh McCoy’s Place
02d1 Kolima Forest
02c0 Tret the Tree
02d7 Mercury Lightouse
02d6 Imil
02c1 Xian
02d5 Desert
02c2 Kalay
02e5 The Ship (Broken Seal)
02c6 Tolbi Song
02c3 Running to the Match
02c4 Colosso Waiting Room
004c Challenge
02d9 Tolbi Cave
02da Hey there, Babi!
02c5 Think you’re lucky? (Broken Seal)
0001 Lucky Dice
0037 Bet Lucky Dice!
02d3 Altin Caves
02d8 Dekhan Plateau
02e7 Venus Lighthouse
02ee Battle! (Broken Seal)
02ef Saturos Battle!
02F0 Boss Battle!
0031 Jenna Battle
0032 Felix Battle
0033 Moapa Battle
0034 Posidon Battle
02f1 Fusion Dragon Battle!
02f2 Super Evil Dragon
0036 Doom Dragon Theme
0038 Boat Battle
0039 Karst/Agaito Battle
003a Won!
003b Lost…

(They’re in order of GS:TLA songs, then GS songs, then battle themes. It’s a little jumbled, I know…)

Anyways, go to the song number in sappy, then go to the menu at the top. Under Options, there is a selection called “Loop Limit”. Set this to 1. Then, go to File, then “Export Song to .mid”. MAKE SURE YOUR SONG ISN’T PLAYING OR SAPPY WILL DISPLAY AN ERROR MESSAGE. Great, now you exported the song into a .mid file.

This has to be done because GS has a funky music format.

STEP 2) Editing the song

It is necessary to edit the song to put into another game. You have to do it one track at a time, and the first track has these little things called “modulations” that are added when sappy extracts a song. It is necessary to remove all of these from the song in order for the insturment to make the right sound.

First, go to Anvil Studio (This is a freeware program you can download - it’s very useful; you don’t need to use it but in this Tutorial I use it). Open up your midi; the program will automatically split it into seperate tracks. First, click on View, the click on “Event Viewer”. Make sure you’re on the first track - these modulations only appear on this track. Remove all the modulations by double clicking the event, then pressing “Delete Event”.

Now, save the file. My generic song file is “Worka.mid.”. Now that you’ve got a backup, remove all the tracks except for the first. Save as this file in the Mid2gba/mid folder. It is imperative that you do this for step 3 to work.

STEP 3) Converting your song into GBA format.

This is very simple. If you have a midi in the mid folder in the Mid2gba folder, simply click the program “tr”. In the program, click “??” to convert the song. The program makes a rom file named “Song.gba” with your song data in it.

Step 4) Inserting the song

Open your rom in your Tile Viewer/Hex Viewer (for the sake of this tutorial, I’m talking in Tile Viewer terms). Find some free space, then write down the offset. Then, open up Song.gba. Go to the very end of the rom. The music data is right there. Make all the tiles appear by clicking on a “next page” button. Then, click on “move byte back” until the first tile of your song data begins with the byte BC. MAKE SURE YOU DON’T ACCIDENTALLY CUT OFF PART OF YOUR SONG. Copy this to the free space. Make sure you copy everything to the end of the rom.

Step 5) Inserting the Track

Go to the offset of the song data with the pointers to the tracks. In Sappy 1.6, this offset is shown next to “Loc”. Simply change the offset to the offset of the song you just inserted. Last thing - set the first byte in this tile as the number of tracks in your final song. For example, Kolima Forest has 6 tracks, so set this number as 6.

NOTE ON REPEATING TRACKS:

To repeat a track, simply replace the end byte B1 as B2, place the offset to the beginning of the song after that, then set the bytes after your offest as B1.
For example:

B212 3456
80B1 0000

Tells the song to repeat at the offset 0x654321.

You can also use the byte B3 as a jump command; it is often used in intros.

NOTE ON CHANGING INSTRUMENTS, VOLUME AND PITCH

It is possible to change the instruments, volume and pitch without having to reinsert a track. For example, start at the beginning of your track. Let’s say track 1 for GS:TLA’s Magma Rock. The offset is at 0x82C22C4. There, we see a set of bytes as such:

BC00 BB36
BD5B BE56

The bolded section is the section that affects pitch. If you put in 0xF4 here, it will play an octave lower. Put 0xC here, an octave higher, and so on.

The italicized section is the instrument. By changing this number, you can change the instrument. Note: This number is always one less than the actual MIDI number, for example, Acoustic Grand is 0x00, Bright Acoustic is 0x01, ect.

The underlined section is the volume. It ranges from 0-127 (0x00-0x7F). The larger the number, the louder the track. NOTE: This sometimes appears in the third row. If the song’s track is not louder/quieter, try editing the third row.

Voila. The ELF method. Enjoy.

It’s also possible to meddle with the game’s instruments, as shown in this video, but the tutorial on how to do this is even longer than this one. But I can arrange music upon request, as long as you give me offsets to the songs you want to change.

Prince Marph from FEShrine strikes again. Dat guy and his rainbows

Roight. Music groups.

Every GBA game has music groups. Depending on the quality of the program, there may be just one music group (as in Golden Sun), or there may be a music group for each song (as in Pokemon Advance Generation Games; this is very wasteful, it’s a good idea to create a single music group and repoint everything to there).

HOW MUSIC GROUPS WORK.

For this tutorial, I am using an English Pokemon Ruby (AXVE) rom.

First, let’s find a music group. The group I will be using is at 0x843B424.

Now you will see a bunch of bundles of bytes. Do you notice how there’s a pattern every three sets of rows? Each of those is an instrument.

Blank instruments look like this:
013C 0000
0200 0000
0000 0F00

You will see this anywhere there is no instrument. (actually, the default instrument, it sounds like a beep)

Regular instruments look like this (the pointer, marked in bold is different for each instrument.

003C 0000
2C09 2A08
FF00 FF7F

The first row is a default row, the second row leads directly to the instrument’s sound (which you can change and change the sound of the instrument), and the third is kind of unknown; set it as this word and it should work.

Some instruments offset at different points, for example, drum kits and Pokemon’s String Ensamble, Trumpet and French Horn.

4000 0000
0402 4308
2452 4508

The first row is a default row, the second row leads to a set of offsets. The third row is the programming, so don’t mess with the third row.

Here’s a sample of the data found if you follow the pointer in the second row:
003C 0000
6C28 4608
FFFC 00EF

This looks a lot like our regular music data! In fact, it works exactly the same. Do note however that usually these are followed by similar looking instruments, which lead to the different notes. Basically, the first tells the game to play a certain instrument with certain set of notes (say, Low C - Mid C), the second tells it to play a certain instrument with a different set of notes (Like Mid C to High C).

The third kind are generated by the system and look like this:
0136 0000
0200 0000
0000 0F00

Note how similar these instruments look to the default instrument. The bolded number is a parameter.

The last kind, which I have only encountered in Golden Sun, is generated by the music programming in the game. I don’t know if FE uses it, and it’s impossible to hack, so I can’t say I can give you much information on it.

And that’s music groups in a nutshell.

Because I’m a snarky bitch I have to add my two cents here. Knowing what I know now I would never use the ELF method–it’s flimsy as hell and takes far too long and too much thinking. Go with the Sappy conversion method.