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.

Final Fantasy/World map data

From Data Crystal
< Final Fantasy
Revision as of 14:17, 21 November 2005 by Gilgamesh (talk | contribs)
Jump to navigation Jump to search

Final Fantasy I (and Final Fantasy II as well) uses a 256×256-tile world map in this data format. The map data is not stored raw, but uses simple compression in a kind of run-length encoding. The ROM (in iNES format) stores its world map data starting at $4010.

Row pointers

From $4010 to $4210 there are 256 little-endian 16-bit integer values representing addresses in the NES memory map (with the $4010 ROM bank currently in place) that mark the left-hand-side beginnings of each 256-tile row of the map. (Because memory pointers are used in this fashion, it is entirely possible for more than one pointer to point to the identical memory location if they use identical row data, such as a 256-tile row of ocean.) Since this bank will loaded into the NES memory map at readable address $8000, all memory pointers in the ROM must point to the row's ROM file address + 0x3FF0. To translate a memory pointer back into a ROM file address, you subtract 0x3FF0 instead.

Row data

Because the row pointers point to active NES memory in which the $4010 must be active, all of the map data is confined to this bank. Unrelated data begins at file address $7F50, so all row data referenced by pointers must be located starting at $4210 and ending before $7F50, giving you 0x3D40 bytes to store your map row data.

Row data is stored sequentially as such:

  • Byte values indicate a row's tiles from the left-edge, from left-to-right through the tiles, ending at the row's right edge.
  • A single byte ranging 0x00 to 0x7F describes a single tile of a specific value. The next byte describes the tile to its right.
  • A byte ranging 0x80 to 0xFE is the same as its value subtracted by 0x80 (or exclusive-or'ed by 0x80), but the immediately following byte indicates repetition of the tile value. A repetition byte value of 0x01 means no repetition, 0x02 means repeat once, 0x03 means repeat twice, 0x04 means repeat three times, and so on. 0x00 means to repeat 255 times, so that it can fill an entire row. A repetition value of 0xFF is prohibited.
  • A byte value of 0xFF after the row's final tile terminates the row data.

So, for example:

0x04
1 tile valued 0x04
0x73
1 tile valued 0x73
0x96 0x01
1 tile valued 0x16
0x96 0x05
5 consecutive tiles valued 0x16
0x96 0x00 0xFF
256 consecutive tiles (an entire row) valued 0x16, and a row terminator