So you want to
be a ROM Hacker? Now's a great time to learn. We're at what is most
likely the tail end of the SNES hacking era. Things are only going
to get more complicated from here. If you intend on getting in on
the fun the 32 bit era promises, learning the 16 bit basics now would
probably be a good idea.
What I'll be doing
over the next few weeks is writing a tutorial while hacking Genjuo
Ryodan. At the moment I don't intend to do a full translation of the
game. If some random good samaritan from Japan who is fluent in Japanese
and English decides to offer his or her assistance, I would be extremely
grateful, but I won't be actively seeking a translator. Instead, I'll
be releasing all my work as I go along, and perhaps someone will decide
to contribute. Yes, basically, this is an "open source"
translation project.
Getting Started:
Acquire the following:
Naga
Hexecute
Hex
Workshop
Genjuo
Ryodan
Rom
We won't be using
all of these right now however. This week we'll be going over the
basics. The VERY basics. Many of you will want to go read cnn or something
until next week when we'll be getting into the "fun" stuff.
The rest of you who are absolute newbies will want to pay close attention
to what follows.
The
Basics of Bases
How
many fingers is the normal human child born with? 10.
How
many fingers is your computer born with? uh.... ?
Believe
it or not, your computer does not count with the same number system
you do. Neither do consoles. Unless you're in posession of a Setun
computer or some such, your computer counts using two numbers. 0 and
1. On and Off. This my friends, is called the Binary Number System.
You will NEED to know how to convert between binary and decimal numbers
if you intend on getting down and dirty in some hot and heavy hacking
action.
So
how does this mysterious numbering system work?
It's
easy as pie my friends.
Do
you remember in grade school going over the difference between the
ones, tens, and hundreds place in math class? They'd draw these little
boxes to help you count and identify how many hundreds there were
in 347. Binary works the same way. You've got different places, and
the places matter. Big time. Just like you can't reorder 347 to 437
and have it be the same number, you cant just move around binary numbers
and have them hold the same meaning. Lets look at the decimal number
205 in binary.

As
the above diagram shows, 8 binary digits are used to represent the
number 205. The binary digits, just like the decimal numbers you're
used to, go from left to right with the digit with the greatest value
to the left and the smallest value on the right.
This
brings us to an important excersize. Exactly how do you convert between
decimal and binary?
Well,
first off, lets go from binary to decimal. See that binary number
in that graphic above? 11001101. As the graphic shows, each of those
binary "bits" or digits equates to a decimal number. The
value to the far left equates to 128 or 2 raised to the 7th power
in exponential notation. In fact, each of those binary digits equates
to a power of 2. That's why it's called the "Binary" system.
Bi being a prefix meaning 2 (Dec coincidentally is the prefix for
10 even though December is the 12th month of the year. For this we
have a bunch of pompus Roman Emperors to thank. Yay Augustus and Julius!).
In any case, to convert binary numbers to decimal numbers, we work
from the right to the left, multiplying the binary digit by a power
of 2. Here's how it works out in this case:
1*1=1
0*2=0
1*4=4
1*8=8
0*16=0
0*32=0
1*64=64
1*128=128
Now
we add the numbers togeather.
1+4+8+64+128=205
Wow!
What a suprise! 205. Who would have predicted that number would result
from that string of binary bits! Now that I'm done being a sarcastic
smartass, lets learn how to convert 205 back into binary. Pretend
like you don't know the answer. It's more fun that way.
To
figure out what the binary representation is of a decimal number,
we're going to have to devide by 2 until we hit 0, paying particular
attention to remainders and ignoring any numbers after the decimal
place that result from our division, as such:
205/2=102
remainder 1
102/2=51
remainder 0
51/2=25
remainder 1
25/2=12
remainder 1
12/2=6 remainder
0
6/2=3 remainder
0
3/2=1 remainder
1
1/2=0 remainder
1
Now
we read the remainders from the bottom of the list to the top and
write them left to right, as such:
11001101
Low
and behold, we're back where we started!
Well,
what about hexadecimal. I always here some random loser romhacker
talking about hexadecimal. How does that work?
Yo,
dis shit id phat. It be da bomb yo.
Hexadecimal
is rather easy. Before we get into converting back and forth between
decimal and hex, let me introduce you to the new way of counting.
Ever hear of new math? This is nothing like that.
0
1 2 3 4 5 6 7 8 9 A B C D E F. Those right there are your new numbers.
Learn them well and never forget them. How about we count in hexadecimal
up to 30 and watch the progression of numbers.
0
1 2 3 4 5 6 7 8
9 A B C D E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E
Well
now. That wasn't too hard, was it. What? You don't believe me that
1E is 30 (even if you do, please play along. It makes this so much
more fun)? Lets convert 1E to decimal and find out. Converting hexadecimal
to decimal is done pretty much the same way converting binary to hexadecimal
was done.
1E
The
digit on the far right is said to be in the "0's place"
and the digit to the left of the 0 is in the "1's place".
Just like we did with the binary conversion, we're going to be multiplying
by a power of some number. What would that number be here? In the
case of binary (base 2) it was 2. So in the case of hexadecimal (base
16), I suppose it would be 16, ne?
E
* 16^0
1
* 16^1
E
is the hexadecimal equivalent of 14. (A=10, B=11, C=12, ...) Anything
to the 0 power is 1. And anything to the 1st power is itself. Therefore:
14*1=14
1*16=16
16+14=30.
Tada. Ladies and gentlemen, we have just converted a hexadecimal number
to decimal! Yay for us.
Well
now, how would I convert a decimal number to hexadecimal? How about
we try that division stuff that worked so well before for binary?
Sounds like a plan to me. Lets try again with 30.
30/16=1
Remainder 14
1/16=0
Remainder 1
Now
we read from the bottom up, remembering to convert remainders larger
than 9 to their Hexadecimal digit equivalents. So we've got 1 and
14 which is E. 1E. Yay. Another successful conversion!
Tune
in next week for a rousing lesson on fonts where we'll actually get
into hacking Genjuo Ryodan.