Welcome to Data Crystal's new home! Data Crystal is now part of the TCRF family (sort of).
The wiki has recently moved; please report any issues in Discord. Pardon the dust.

Pointer: Difference between revisions

From Data Crystal
Jump to navigation Jump to search
m (Reverted edit of 67.81.124.211, changed back to last version by Gau)
No edit summary
Line 5: Line 5:


SNES pointers are [[Endianness|little endian]]. Therefore, if you find your pointer comes out to $123456, then your pointer will be written to the ROM as 56 34 12 or, more likely, as 56 34 12 00.
SNES pointers are [[Endianness|little endian]]. Therefore, if you find your pointer comes out to $123456, then your pointer will be written to the ROM as 56 34 12 or, more likely, as 56 34 12 00.
= Game Boy Pointers =
Game Boy (and Game Boy Color) pointers are typically two bytes long. They are often contained in the same bank as the data that it is supposed to point to, and is usually directly above or below the data. To calculate a pointer from a Game Boy game:
<ol><li> Take the offset that you wish to point to</li>
<li>Take the last four digits of the offset, and cut off the rest</li>
<li>The most significant bit will always be 0, and the second most significant bit will always be 1. In other words:</li>
* If the offset is from 0000-3FFF, add 4000 to the offset.
* If the offset is from 4000-7FFF, do not add anything to the offset.
* If the offset is from 8000-BFFF, subtract 4000 from the offset.
* If the offset is from C000-FFFF, subtract 8000 from the offset.
<li>Because Game Boy is little endian, switch the first two digits with the last two.</li></ol>
Example: $1201FA is the offset you wish to point to.
<ol><li>Take the offset $1201FA</li>
<li>Take the last four digits: $01FA</li>
<li>Since $01FA is between 0000-3FFF, you add 4000, so you get $41FA</li>
<li>Because Game Boy is little endian, you take the <span style="color:#FF0000;">41</span><span style="color:#0000FF;">FA</span>, switch the <span style="color:#FF0000;">41</span> and <span style="color:#0000FF;">FA</span> around to get <span style="color:#0000FF;">FA</span><span style="color:#FF0000;">41</span></li></ol>


== LoROM ==
== LoROM ==

Revision as of 20:12, 29 August 2008

A pointer is a number that refers to a specific location in a ROM or memory. They may also be referred to as addresses or offsets. The exact way pointers work vary among different systems, and, in fact, some systems have multiple pointer schemes. It has become convention, at least within the PK Hack Community to use the 0x prefix to indicate a pointer referring to the ROM file and to use the $ prefix to indicate a pointer in the format used by the machine. Both prefixes indicate the following number is in Hexadecimal. Different machines may use different byte orders, be careful.

SNES Pointers

The SNES has serveral different pointer schemes. The main two are #LoROM for smaller ROMs and #HiROM for larger ROMs, but extensions of both of those exist.

SNES pointers are little endian. Therefore, if you find your pointer comes out to $123456, then your pointer will be written to the ROM as 56 34 12 or, more likely, as 56 34 12 00.

Game Boy Pointers

Game Boy (and Game Boy Color) pointers are typically two bytes long. They are often contained in the same bank as the data that it is supposed to point to, and is usually directly above or below the data. To calculate a pointer from a Game Boy game:

  1. Take the offset that you wish to point to
  2. Take the last four digits of the offset, and cut off the rest
  3. The most significant bit will always be 0, and the second most significant bit will always be 1. In other words:
    • If the offset is from 0000-3FFF, add 4000 to the offset.
    • If the offset is from 4000-7FFF, do not add anything to the offset.
    • If the offset is from 8000-BFFF, subtract 4000 from the offset.
    • If the offset is from C000-FFFF, subtract 8000 from the offset.
  4. Because Game Boy is little endian, switch the first two digits with the last two.

Example: $1201FA is the offset you wish to point to.

  1. Take the offset $1201FA
  2. Take the last four digits: $01FA
  3. Since $01FA is between 0000-3FFF, you add 4000, so you get $41FA
  4. Because Game Boy is little endian, you take the 41FA, switch the 41 and FA around to get FA41

LoROM

Some information on LoROM would be nice. No LoROM games are currently in the database. For now, the information can be found at Zophar's Domain. Perhaps the author of the SNES pointer document there should be contacted about the use of that information.

HiROM

Supports games up to 4 megabytes or 32 megabits. An extension called #ExHiROM can be used for ROMs as large as 8 megabytes or 64 megabits. One game which uses HiROM is EarthBound. For pointers to ROM data, just add 0xC00000, but note that most ROMs have a 512 byte header, so you will also have to subtract 0x200 to adjust for the header. So, if we were going to reference the 155,387th byte of the ROM, you would subtract 512 and add 0xC00000, resulting in C25CFB. Finally, a dollar sign is added to the beginning of the pointer to show that it is a SNES pointer: $C25CFB. Remember that will be written to the ROM as FB 5C C2 00, since SNES pointers are little endian.