Coordinate Systems

From TLoZ: ALTTP Hacking Resources
Jump to: navigation, search

See also: Standard Notation

Different parts of the game (both in ROM and in RAM) use different coordinate systems for different purposes when representing visual data, which makes producing and editing the game more difficult but saves either some computation time during actual gameplay or some space in the ROM.

Frame of Reference

The SNES display is 256x224 pixels in size (256 wide and 224 high) and the game displays larger elements (such as a 256x256 pixel room) by scrolling.

All coordinates use the top-left corner as their origin, meaning an X coordinate increases while going to the right across the screen and a Y coordinate increases while going down the screen. This applies to all objects: All rooms, areas, tiles, sprites, blocks, et cetera, all use their top-left corner as the coordinate origin (0,0) point.

Pixel Coordinates

These are simply the direct pixel values where something is: How many pixels to the right from the leftmost pixel, and how many pixels down from the topmost pixel. Only sprites (such as the player and enemies, particle effects, and push-blocks actively being pushed) and screen scrolling use direct pixel coordinates.

Tile Coordinates

The fundamental unit of SNES graphics is the 8x8 pixel tile; Larger units are created by combining multiple 8x8 tiles, and smaller units are created by 8x8 tiles with many transparent pixels. Tile coordinates are simply pixel coordinates divided by 8, either by straight integer division (ignoring the remainder) or shifting bitwise rightward by 3. If you multiply a tile coordinate by 8 (or shift bitwise leftward by 3), you get the pixel coordinate of its top-left corner.

Tilemap Coordinates

See also: Metarooms

ALTTP in some places uses a special "baked" coordinate system that is a single value, sometimes referred to as the "VRAM address". (Using the name "VRAM address" is not wrong in this case, but because actual addresses in SNES VRAM depend on multiple factors such as the current display mode, use of the name "VRAM address" is discouraged to avoid confusion.)

Tilemap coordinates are used only for interiors, which are always 512x512 pixels in size, meaning the tilemap coordinates represent a range of tile coordinates from ($00,$00) to ($3F,$3F).

Conversion

Let (Xp,Yp) be pixel coordinates, (Xt,Yt) be tile coordinates, and (TM) be tilemap coordinates.

Pixel Coordinates to Tile Coordinates
Xt = Xp / 8
Yt = Yp / 8
Tile Coordinates to Pixel Coordinates
Xp = Xt * 8
Yp = Yt * 8
Tile Coordinates to Tilemap Coordinates
TM = ( Xt + Yt * $40 ) * 2
Tilemap Coordinates to Tile Coordinates
Xt = ( TM / 2 ) % $40
Yt = ( TM / 2 ) / $40

Other Coordinate Systems

The game encodes coordinates in a few other ways throughout ROM and RAM (such as 16x16 tile coordinates), but one way or another they are simply tile coordinates with a little extra math applied for compression/decompression that will be noted where relevant.