The PokéCommunity Forums  

Go Back   The PokéCommunity Forums > ROM Hacking > Tools, Tutorials & Resources
Sign Up Rules/FAQ Live Battle Blogs Mark Forums Read

Notices

Tools, Tutorials & Resources Various tools to help you develop your hacks can be found here.
New threads in this forum are to be approved by a moderator before they are displayed.


Reply
 
Thread Tools
  #1    
Old October 30th, 2010, 12:44 AM
miksy91's Avatar
miksy91
A GB/C Rom Hacker since 2010
 
Join Date: Oct 2008
Location: A small country in the North
Gender: Male
Nature: Relaxed
Here is a tutorial of editing GB/C pointers.
I couldn't find any of these explaining things more than just briefly so I decided to make my own with more examples in it.

Updated pointer tutorial (21.7.2012)

Let's get started with the basics. Pointers are basically two-byte values and as you may be able to guess, they're used to pointing to different kinds of data. What you probably want to know is how to calculate them.

Calculating the offsets where pointers point to is easy. For example 2A 88 points to $882A but this offset here is a memory address in RAM. Same way, 13 3A points to $3A13 and 10 D0 to $D010. The problem is, how to calculate pointers which are used for looking data inside ROM ?

GB/C RAM works like this:
$0000-3FFF - ROM bank 0x0
$4000-7FFF - Variable ROM bank
$8000-9FFF - Video RAM
$A000-BFFF - Save RAM
$C000-CFFF - RAM
$D000-DFFF - WRAM
$E000-FEFF - Echo RAM
$FF00-FF7F - I/O Registers
$FF80-FFFF - HRAM

Basically, the RAM area between $4000 and $7FFF is the one you want to access with pointers pointing inside ROM (in case you're not calling some assembly code from ROM bank 0 for instance but you should know all this if you're even planning to do that). This RAM area between $4000-7FFF is 0x4000 bytes long which is as large as each ROM bank inside a ROM file.

For example in Pokemon Gold (U) ROM, there is lots of blank data (data filled with 00 00 00...) starting at 0x109DCA. If we for example wanted to input some script data in there and make the script pointer of some random person look for the script data in this rom area, we'd have to find the right pointer to it. This rom bank we're in starts at:

0x109DCA / 0x4000 = 0x42 (if your Calculator shows some digits after a comma here, ignore them and just use the integer in the following calculation)
0x42 * 0x4000 = 0x108000

So our rom bank starts at 0x108000 and as rom banks are 0x4000 bytes long (as explained above), this rom bank ends at 0x10BFFF. Basically, when data is looked for in this rom bank, 0x4000 bytes starting at 0x108000 are copied to $4000 in RAM ($4000-7FFF).

Basically, we can use a calculation like this to find the pointer leading to 0x109DCA:
0x109DCA - 0x108000 + 0x4000 = 0x5DCA --> 5D CA

And as explained way above, we'll have to rotate the bytes around to find the pointer that leads to the wanted ram address and so we'll get: CA 5D.

So to look for script in 0x109DCA, you'll have to change the script pointer of this random person, I was talking about earlier, to CA 5D. This of course demands that the script pointer (along with his other event data which is no way related to this thread) is in the same rom bank (between 0x108000-10BFFF).

Because there are more rom banks than just rom banks 0x0 and 0x1, there has to be a way for moving on from rom bank to another. This is often done by calling a specific assembly routine by first loading register a with the byte of the rom bank and register pair hl with the 2-byte pointer to that rom address. You may not have understood a thing about that but it's okay, you won't need that info here :D

Anyway, in the explanation above, I explained how to define the 2-byte pointer pointing to a specific rom/ram address. This time, let's define where a specific "3-byte pointer" points to (we like calling them 3-byte pointers because they also consist of a byte of the accessed rom bank).

Let's pretend we had a pointer of this kind:
A7 48 3A in which A7 48 is the pointer to the accessed rom data and 3A the byte of the accessed rom bank. The offset where this pointer leads is then:

0x3A * 0x4000 + 0x48A7 - 0x4000 = 0xE88A7

Of course when this rom address is accessed, $E8000-EBFFF is again copied into RAM ($4000-7FFF), and we're currently pointing to ram address $48A7.

Notice that all GB/C pointers are formed with two bytes! The rom bank byte itself is used in a specific assembly routine to define the accessed rom bank and doesn't have to be next to the two-byte pointer. Basically in rom you could also find a 3-byte pointer this way:
[2-byte pointer] [xx bytes data] [Rom bank]
__________________
My Rom Hack



Hacks I support





Learn how to hack GB/C games:

Check my GameBoy/Color hacking videos in Youtube
-The video set uses Pokemon Silver (U) rom for demonstrations

Last edited by miksy91; July 21st, 2012 at 01:44 AM.
Reply With Quote
  #2    
Old July 21st, 2012, 01:49 AM
miksy91's Avatar
miksy91
A GB/C Rom Hacker since 2010
 
Join Date: Oct 2008
Location: A small country in the North
Gender: Male
Nature: Relaxed
This old, "buggy" tutorial has been completely redone!
Back in middle 2010, I didn't clearly understand enough of pointers to write a good documentation about them but now there is.

Some feedback from those who read this would be appreciated. Is it easy enough to keep up with?
__________________
My Rom Hack



Hacks I support





Learn how to hack GB/C games:

Check my GameBoy/Color hacking videos in Youtube
-The video set uses Pokemon Silver (U) rom for demonstrations
Reply With Quote
  #3    
Old April 11th, 2014, 03:26 PM
com3tiin's Avatar
com3tiin
Soy chamber...
 
Join Date: Jan 2013
Gender: Male
$4000-7FFF - Variable ROM bank is the same that ROM, no?
Reply With Quote
  #4    
Old April 12th, 2014, 12:33 PM
itari's Avatar
itari
Community Supporter
 
Join Date: Mar 2010
Location: 渦潮隠れの里
Age: 17
Gender: Female
Nature: Relaxed
I like this tutorial! Very easy to understand, I think, but that may just be me.

For those that don't get it, think of it this way:
Pointer = (Offset % 0x4000) + 0x4000
Bank = Offset / 0x4000

Offset = (Bank * 0x4000) + (Pointer % 0x4000)

NOTE: % is the modulo operator!
__________________
Reply With Quote
  #5    
Old April 13th, 2014, 06:20 AM
miksy91's Avatar
miksy91
A GB/C Rom Hacker since 2010
 
Join Date: Oct 2008
Location: A small country in the North
Gender: Male
Nature: Relaxed
Quote:
Originally Posted by com3tiin View Post
$4000-7FFF - Variable ROM bank is the same that ROM, no?
One of the rom banks (apart from rom bank 0 which is at 0x0-0x3FFF in rom) is accessable at the time, and it can be pointed to with pointer values that are between 00 40 and FF 7F (because those pointers point to addresses $4000-$7FFF).

This is also why all the pointers are two bytes long. So when we have to point to an address that is in different rom bank, we'll have to change this variable rom bank to something else (doable with a routine that's in rom bank 0), and then we can point to the addresses of that rom bank with pointer values 00 40 to FF 7F.

Quote:
Originally Posted by itari View Post
I like this tutorial! Very easy to understand, I think, but that may just be me.

For those that don't get it, think of it this way:
Pointer = (Offset % 0x4000) + 0x4000
Bank = Offset / 0x4000

Offset = (Bank * 0x4000) + (Pointer % 0x4000)

NOTE: % is the modulo operator!
That's a pretty good way of summing it up
__________________
My Rom Hack



Hacks I support





Learn how to hack GB/C games:

Check my GameBoy/Color hacking videos in Youtube
-The video set uses Pokemon Silver (U) rom for demonstrations
Reply With Quote
Reply
Quick Reply

Sponsored Links
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Minimum Characters Per Post: 25



All times are UTC -8. The time now is 02:38 PM.


Style by Nymphadora, artwork by Sa-Dui.
Like our Facebook Page Follow us on Twitter © 2002 - 2014 The PokéCommunity™, pokecommunity.com.
Pokémon characters and images belong to The Pokémon Company International and Nintendo. This website is in no way affiliated with or endorsed by Nintendo, Creatures, GAMEFREAK, The Pokémon Company or The Pokémon Company International. We just love Pokémon.
All forum styles, their images (unless noted otherwise) and site designs are © 2002 - 2014 The PokéCommunity / PokéCommunity.com.
PokéCommunity™ is a trademark of The PokéCommunity. All rights reserved. Sponsor advertisements do not imply our endorsement of that product or service. User generated content remains the property of its creator.