Primary Zelda Hacking
April 21, 2014, 09:27:37 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: The website has switched hosts and now has the domain zeldahacking.net!
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: The Ultimate Gameboy Hacking Guide - Part 1: The Basics  (Read 573 times)
Lin
ZOLE Creator
Administrator
Hero Member
*****
Online Online

Posts: 580



View Profile
« on: February 21, 2011, 08:23:11 AM »

Hi there. Welcome to a series I'd like to call "The Ultimate Gameboy Hacking Guide". Since there isn't really anything to get you where hacking any Gameboy game is a piece of cake, I decided to write a guide that will teach you what has taken me years to learn in just a few days of reading.

For demonstration, I will be using the Legend of Zelda Oracle of Ages ROM (U) 1.0. All of the assembly instructions will be in the form BGB displays and without any leading $ or 0x sign. All numbers will also be in hexadecimal.

The Ultimate Gameboy Hacking Guide - Part 1: The Basics

Chances are, you read this document because you want to be able to hack Gameboy games. You may have tried, and if you haven't, you probably have no idea where to start. You may have heard the term "pointer", and maybe something like "little-endian word". Well, in this chapter you'll learn what all of those mean. I won't be getting into assembly or anything too complicated in this part, but I will be getting you ready for what's to come and be able to understand what I mean by the words and phrases I use.

So, let's start by getting into the tools we'll be using. Here's the list of tools I use, and I recommend you use too.

Visual Boy Advance - http://vba.ngemu.com/
BGB - http://bgb.bircd.org/
Cygnus Hex Editor Free Edition - http://www.softcircuits.com/cygnus/

Quite a short list, but each plays a very important role. I also recommend always having something available that lets you take notes, such as Notepad.

But anyway, now that you have the tools we'll be using, let's get into the world of Hexadecimal and Binary. You may have heard those words tossed around a few times, especially if you've been hacking by using tools. Hexadecimal is simply the decimal number system but with 6 additional values before 10 - A, B, C, D, E, and F. In decimal, these values are equivalent to 10, 11, 12, 13, 14, and 15. 10 Comes next and has the decimal value of 16. After hexadecimal 19 is 1A, 1B, and so on.

Now, the most common data type you'll hear of is called a Byte. A byte is simply 2 hexadecimal digits put together to range from the decimal values 0-255, or 00-FF in hexadecimal. As well as being two digits, it's also 8 binary bits (A bit is one binary digit, which is 0 or 1). FF, or 255, would have the binary value of 11111111, which is 8 set bits. In order to go above FF, or 255, you have to have another byte. The decimal value of 256 would be the hexadecimal value 100. This is two bytes: 01 and 00. Two bytes together is a word, or short, four bytes is a doubleword (dword), or integer, and eight bytes is a quadroupleword (qword), or long. A single digit in a byte, or just 4 binary bits, is called a nybble. The right nybble is called the "lower nybble" and the left nybble is called the "upper nybble".

So when using phrases like "an 8-bit value", all that means is a byte since a byte contains 8 bits. When dealing with bits, after 1, for every 0 after that 1 doubles the number. For example, 10 would be 2, 100 would be 4, 1000 would be 8, 10000 would be (hexadecimal) 10, and so on. Normally you won't have to calculate these in your head as many scientific calculators (including Windows Calculator) can convert decimal, hexadecimal, and binary between each other. However, it is good to know the decimal-hexadecimal-binary values of the "single-1" and "full-1" values of a byte. "Single-1" is a byte's value with only 1 bit set, so 1, 2, 4, 8, 10, 20, 40, and 80. "Full-1" is a byte with all of the bits set to a certain point, so 1, 3, 7, F, 1F, 3F, 7F, and FF.

Well, now that you have a good understanding (hopefully) of the hexadecimal and binary system, you're ready to move on. If not, you can always look them up online and get even better tutorials on learning them. But for the sake of getting to the good stuff, we must move on. A hex editor, which I linked you to above, is a program that allows the viewing and editing of all the bytes of a file or other data group. This is the most important tool because without it, you can't actually get an idea of the internals of a game.

When talking about a certain byte or spot in a file, or in the case of a Gameboy game, ROM, we use the terms "address" and "offset". Address is a more common one, but people are usually familiar with offset too. An address, or offset (I will be using address), is basically the index of a byte. If we wanted to tell someone where a value was that did a specific thing, we'd give them an address. For example, let's say in the ROM, Mario's jump height is the 6720th byte into the ROM. We'd say "it's at 6720", hexadecimal of course. In order to distinguish hexadecimal from decimal, people add "0x" or "$" before a value, like "0x20" and "$20", although in this guide I won't.

These same rules apply when talking about RAM (memory), and basically any data table. So while Mario's jump height in the ROM might be at 6720, in the RAM it could be stored at C042. Either way, we reference where it's at the same way.

Another term that's great to know about is the term "pointer". A pointer is exactly what you'd think of - a pointer. In a sense, it's a piece of data that points to an address. It's basically the same thing as an address, except it means something will be reading it and doing something with the data it "points" to. For example, Mario may jump at different heights and there's a data table that controls how high he jumps in different areas. The Gameboy isn't going to blindly know where this data table is at - it has to read and follow a pointer which in a way tells it that it's at 4215. Pointers are used for basically everything - not only data tables, but other procedures and even memory addresses.

So now you have a good understanding of hexadecimal, binary, bytes, other data types, pointers, and data indexing. That means you're ready to move onto Part 2 of this guide and learn how to use VBA's Memory Viewer, how Gameboy ROMs work, and how the Gameboy's memory works.

~Lin
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!