View Full Version : [Tutorial] Controlling the sound "manually" + a demonstration of it's uses

August 14th, 2010, 10:30 AM
Like the title says this thread will describe a way to change the playing song wihtout using any of the built in scripting commands.

To change the song what you have to do is write the correct values to the following offsets:


The above locations hold the two bytes that identify the song that is being played but also holds the data for the next song to be played. You can write a sappy song ID to this location, but you have to keep in mind to flip the bytes, e.g.: 0109 => 09 01

Just writing to those offset will not cause the music to change but writing to the following offset will:


Write a 1 to that offset and the game will load the new song.

This can be easily tested with the following script:

#dynamic 0x800000

#org @main
writebytetooffset 0x09 0x3000FC0
writebytetooffset 0x01 0x3000FC1
writebytetooffset 0x1 0x3000FC4

Now, you're probably wondering why you'd ever be interested in this if you have the scripting commands(playsong, sound,...) at your disposal.
Well I have used it for the following:
Demonstration (http://www.youtube.com/watch?v=ibGa5WN_N4k)

See, the normal sound commands only take song ID's as arguments so they can't be called flexible.

This is what you need to make a script that reads values from certain vars and plays a song based on those.

First of all a little piece of ASM code is needed:

.align 2
.global lesson1

push {r0-r2, lr}
ldr r0, .VAR3
ldrh r1, [r0]

ldr r0, .VAR2
ldrh r0, [r0]
mov r2, #16
mul r0, r2
add r1, r0

ldr r0, .VAR1
ldrh r0, [r0]
mov r2, #16
mul r0, r2
mul r0, r2
add r1, r0
ldr r0, .SVAR1
strh r1, [r0]
ldr r0, .VAR0
strh r1, [r0]
pop {r0-r2, pc}

.align 2

.word 0x020270B6 + (0x800D * 2)
.word 0x020370BA
.word 0x020370BC
.word 0x020370BE
.word 0x03000FC0

The above code will load the content of vars 0x8001, 0x8002 and 0x8003 make a Song ID out of the content and store the ID in 0x800D and 0x3000FC0.

The ID is formed as follows:

([0x8001]*0x10 * 0x10)+([0x8002] * 0x10)+([0x8003])

So the most basic form of usage for the ASM code in a actual Script is as follows:

#dynamic 0x800000

#org @main
setvar 0x8001 0x??
setvar 0x8002 0x??
setvar 0x8003 0x??
callasm 0x???????? 'ASM routine's offset + 1
writebytetooffset 0x3000FC4

If anyone wants I can put the my script seen in the Youtube Video in here as well, but it's not commented at the moment and I don't really feel like adding comments. Just ask in the thread.

Also please note that this is the first thing I did involving ASM so it might not be the most efficient way of way of doing this.

I hope this information will help someone and if there are any question feel free to ask.

September 28th, 2011, 9:32 AM
Does this work with trainer battles?