You are on page 1of 9

Ribon22x’s Scripts Laboratory 1

How to enlarge a ROM to insert more scripts



It’s not very common to see hacks that get in trouble because of running out of space to insert certain
components, but sometimes we need a little more space in our ROMs to store extra content, and we just run out of free
space to do so.

Now I will teach you a way in which you’ll be able to insert more space into a ROM, so that you can create more
scripts than the ones you already have. I will start explaining how to do it and I’ll finish giving a technical explanation of
how I realized this could be done. Needless to say that this tutorial is for people with basic knowledge, because I’ll be
using some terms that you should already know, as I won’t be explaining them.

Also, you should know that this is still in a debugging stage, so I’m not 100% sure that this won’t cause some kind
of trouble in the ROMS at the time of emulating them, although I’ve already tried this and it has worked perfectly fine.

Needed tools:

To achieve our purpose we’ll need some resources, of which you should have at least some notion of what they
are and how to use them. The tools we’ll be using are:

- HEX Workshop

- Advance Map


- A ROM (Obviously XD)

Well, HEX Workshop can be downloaded from its official site, although it’s not mandatory to use this HEX editor,
you can freely use any that you like as long as it has the bytes-insertion option. For this tutorial I’ll be using the version 6
for Windows XP in 32 bits.

It doesn’t matter which version of advance map you use as we’ll be using it just to assign offsets to the minis or
other behaviors.

The HEX Workshop will also be used to insert scripts that won’t be able to be inserted with XSE because of
offsets limitations.
Ribon22x’s Scripts Laboratory 2
How to enlarge a ROM to insert more scripts

Enlarge the ROM:

Although this is the main objective of this tutorial, this is one of the easiest things to get done with, and you’ll
only need the HEX Workshop for this.

Step by step:

1.- The first thing we’ll do is open our ROM using HEX Workshop, which will produce what we see below:
Ribon22x’s Scripts Laboratory 3
How to enlarge a ROM to insert more scripts

2.- Then, we are scrolling down to the bottom of the file until we reach the 0xFFFFFF address.

3.- Done this, we are ready to insert the new bytes. The first thing we’ll do is right-click at the end of the last byte. A
menu like this will be shown:
Ribon22x’s Scripts Laboratory 4
How to enlarge a ROM to insert more scripts

4.- In this menu, click “Insert…” option, the following window will appear:

Where it says “Number of bytes” we must type down the amount of bytes we’ll be inserting, for this example we’ll leave
it at 1000, but later in this tutorial we’ll see the huge amount we can actually insert.

In the second field where it says “Fill with the following hex” make sure it says “ff” so that it fills all the space we are
creating with FF.

Now we hit OK and we’ve just added 1000 bytes to our ROM (The limit we’ll see it later) here’s an image that shows the
offset that our ROM reaches now:

As we can tell, our room has grown in 1000 Bytes. The FF will appear in red until we save, so it doesn’t mean that there’s
something wrong, it’s just a functionality of HEX Workshop that shows the amount of bytes that have been modified but
not saved yet.
Ribon22x’s Scripts Laboratory 5
How to enlarge a ROM to insert more scripts

Well, now we are going to save by clicking on the disc icon that’s on the upper-left corner of the menu:

By clicking it we’ll get a message that will prompt us to make a safety copy of the ROM, that means saving the ROM
twice, one that will be modified and another one without (a copy of the original). The idea is to have a backup in case an
error occurred with the modified ROM.

Alright, we are done with the easiest step, our ROM is already bigger.

Try our ROM

Now to make sure that our ROM hasn’t suffered any problems we are trying it on VisualBoy Advance, but you
must make sure of something first. The option “Save Type” (Options > Emulator > Save Type) must be in “Flash 128k”.

Extra: Here’s the reason why Emerald must have that configuration. Emerald has about 10 extra bytes which make it go
to the offset 0xFFFFFF. *eyebrows*. If you want you can see for yourselves by opening it with an HEX editor.

Insert new scripts:

Well, now is the time to start inserting new scripts, but you must know that we won’t have the comfort of using
a compiler like XSE to insert them because we’ll have to do it by using our favorite hexadecimal editor, and we’ll have to
remember the permutation rules and everything else you learnt about scripting using HEX.

Of course, this is only applicable if you want to make scripts that are then stored in the new offsets added
earlier, because if you want to insert scripts in the older offsets you can do it without a trouble using XSE for example,
but XSE won’t have access to write in the new ones because of some technical issues we’ll go on later on this tutorial.
Ribon22x’s Scripts Laboratory 6
How to enlarge a ROM to insert more scripts

For example, if you want to insert a msgbox that shows a message that is stored in the address 0x816AC56 and
then closes after showing that dialogue, you would normally write the following code in XSE:

msgbox 0x0 816AC56

callstd 0x6

But now you’ll have to insert it with an HEX editor in the following way:

0F 00 56 AC 16 08 09 06


Here’s the image that shows how this would turn out HEX Workshop from the address

The HEXA numbers for each command are shown on XSE by pressing F1 to see the help window.

Another thing you can do is to insert the script in one of the addresses that XSE has access to, compile, and then go to
that address using the HEX editor and copy the generated code and pasting it in the new address.

There are many ways to insert the code, try to use the one that fits you the most.

Calling a script:

Well, this in another part of this tutorial in which you need to be extra careful because it can get tricky. As you
may already know (or not) the Advance Map application only allows to assign script offsets within the range from
#000000 until #FFFFFF, which is a problem, because all the offsets we have just inserted go from #1000000 (#FFFFFF +
1), but there is a solution to this problem, the only thing we need to do is to assign an offset that we have free already
within the range supported by advance map, for example #6E645A, and Advance Map will see this as a valid offset.
Ribon22x’s Scripts Laboratory 7
How to enlarge a ROM to insert more scripts

Step by step:

Assign a valid offset for Advance Map

Now I’ll simulate a call to the script we inserted a while ago, the one which was in the address 0x1000000

We run XSE and go to the offset that we assigned to the script

Now we must input the following code:

#ORG 0x6E645A
goto 0x9000000

For this case since the script was inserted in the address 0x1000000 we must input goto 0x9000000, but if, for example,
the script we wanted to execute was in 0x1353535, then we should input 0x9353535. This is, in short terms, just change
the 1 for a 9 (this will be explained later).
Ribon22x’s Scripts Laboratory 8
How to enlarge a ROM to insert more scripts

Now is the time to test our script, we compile it and go to the mini, which is how we call the valid script from our

Well, in the image you can see how it’s working perfectly well.

Note: Yes, it’s the same message that is originally shown on that mini, but only that this time was called from the address
0x9000000. XD.

Don’t forget to check that the Save Type option is on Flash 128k.
Ribon22x’s Scripts Laboratory 9
How to enlarge a ROM to insert more scripts

Where did my curiosity came from:

Well, to be honest I have been wondering if this was possible for quite some time now, but I just haven’t had
enough time to investigate it. Now if we look up into the technical specifications of the Gameboy Advance we’ll see that
in its RAM memory there are 32 MB destined to the addressing of the ROM (Read-only memory). Of which a Pokémon
game is only using 16MB, that is, only the half of what it has available.

I searched ROMs (of other games) to see what was being done with these extra 16MB that the Pokémon games
weren’t using and I found many that were using it to store additional data of the games, that means that it wasn’t
reserved memory to console processes or something else like that.

That’s how I felt confident enough about the subject and I started looking up for ways to expand the ROM’s

How much bigger can a ROM be expanded?

Well, honestly it would be perfect if we could just have a ROM of 32MB, twice the size of what we usually have,
so we can do whatever we want with that extra space, but I believe that this would cause some disadvantages, although
I haven’t proved this, which leaves you with the freedom to expand it as much as you want, not going beyond the
address 0x1FFFFFF of course, because this is the limit that the RAM can support (Ideally).

Why to change the 1 for a 9?

Like some of you might already have read in other tutorials, you should know that the reserved memory for our
ROM starts from the address 0x0800000 and normally a Pokémon ROM has 16MB, that means that it uses up to the
address 0x8FFFFFF, well since we’re breaking this limit we’ll now start from the address 0x9000000, and we have until
the address 0x9FFFFFF.

How many times can I expand the ROM?

The ROM’s size can be modified as many times as you want, in fact I recommend that you expand it from 1000
to 1000 so that the tools don’t take too long to open it, and also making sure that it doesn’t go beyond the 32MB.

Scripts only?

I’ve only tried the new offsets to store scripts, if you want to you can try inserting graphics and then let me know
what results you get, after all this manual is just starting, there are still advantages and disadvantages to be found.

Well, with that I’m done with the explanation of how to expand a ROM.

If I’m missing something I’ll be updating. Cheers!