“The Website Previously Known as Legendary Pokémon.”

Legacy, Weeklymech

Basics

by Arty2

Introduction

This is the first article in my weekly column about game mechanics. The first few articles will be about data patterns in the GBA games (most are similar with older ones) and then shall follow some articles about specific game functions. Here are a few bits of knowledge you will need to know in order to understand future articles. Note that I am not a programmer myself but I’ll try to pass on the few things I know many of them cannot be found on the internet (unfortunately).

If you have something to add feel free to comment and I’d be happy to see people contributing to these articles. After every article will follow some related links that will help you get additional information.

Always remember that ROM images are illegal if you do not own the actual game and should only be used for personal backup reasons. If you like a game, please buy it and help the producers make new games.

Basics

First, there is the bit, which has two possible values, on or off, true or false, 1 or 0; exactly like a light switch. You may know that the common numeral system is called decimal, because it uses ten digits, 0-9. Normally, when a number grows too large it overflows to the left such as 09 to 10 and 099 to 100.

There are a few more systems including binary and hexadecimal (hex), which we are going to analyse here.

Hexadecimal includes the following digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. It overflows in the same way as in decimall: 0F to 10 and 0FF to 100. Same applies for binary but binary has only two digits: 0 and 1 (just like a bit). In binary, 0 = decimal 0 and 1 = decimal 1 but 10 = decimal 2, 100 = decimal 4 and 1000 is decimal 8. Add 1 to 10 and you have 11 = decimal 3.
Now lets learn how to convert from binary to hex. For example have the following number: 1000101001010011. Now we are going to break it into sets of four: 1000 1010 0101 0011. 1000 is easy to convert, it’s just 8 (see above) but what about 1010? Consider the following table:


   8 4 2 1
   1 0 1 0

You can see that 8 and 2 are on (have a 1 instead of 0), so 8+2 = 10 (decimal) = A (hex). We continue doing the same with the rest of the number and we have the following:


   1000 1010 0101 0011   (binary)
     8   10   5    3     (decimal)
     8   A    5    3     (hexadecimal)

Of course, you can always use a scientific calculator (or your Windows/Linux/Mac calculator of choice) for these conversions but knowing the above makes the whole thing easier to deal with. Now here’s how PC’s and Nintendo games work: they swap the high byte and low byte of two byte values. So, whereas the highest move’s number is 0AFF, then in the ROM data, it will be stored with the 0A and FF reversed. So our previous example will be stored as 538A, or if our number was something like 10EAB65 it would be stored as 65AB0E01 (mention that 1 is actually 01).

Another interesting fact is that GameBoy (and some other) games always round down when it comes to calculating things. We’ll call that floor() while ceil() will be our round-up name and round() the normal rounding we learnt in highschool.

Here’s a few programs you are going to need before our next article:

  • Game oriented hex editor (for example Thingy32)
  • General hex editor (for example ICY Hex Explorer)
  • Relative searcher (for example SearchR X)

Related links

About the author

Arty2

Heracles is an Athens-based architect and designer.
He founded LegendaryPKMN in 2001.