Final Fantasy Tactics Advance/Compression Formats

From Data Crystal
< Final Fantasy Tactics Advance
Revision as of 18:10, 11 March 2009 by Archaemic (talk | contribs) (New page: Final Fantasy Tactics Advance employs several compression formats. Several have been reverse engineered, and information is below: =Main compression methods= Starting around 0x0801F100...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Final Fantasy Tactics Advance employs several compression formats. Several have been reverse engineered, and information is below:

Main compression methods

Starting around 0x0801F100 in the code is a routine for decompressing some data. The first byte seems to indicate type. Bytes checked for are, in order:

  • 0x10
  • 0x01
  • 0x11

If none of these are matched, it prepares three arguments and then branches with link to 0x08141868.

Mode 0x11

In mode 0x11, the first three bytes after the identifier are compared against the value at 0x0801F26C (0x00FFFFFF in the original ROM). If the bytes match, it jumps to 0x0801F274. The destination is then filled with 0x1000 words of value 0. The following bytes are GBA LZ77 format.

LZSS

Several places in the FFTA ROM, a derivative of the LZSS compression scheme is used. In this format, literals (uncompressed data) and compressed data is mixed. The compressed data comes in several forms, and is identified by the highest bit that is set. Upon reading one compressed byte (and additionally however more are specified by that form), the next byte is read as compressed as well. Bytes are only read as uncompressed when specified by a special byte. The following is the list of all of the compressed data forms:

  • Bit 7 set: 0b1XXXXYYY 0bYYYYYYYY
Track back Y bytes from outputted data and copy X+3 bytes.
  • Bit 6 set: 0b01XXXXXX
The next compressed byte is in X+1 bytes
  • Bit 5 set: 0b001XXXXX
Output X+2 zeros
  • Bit 4 set: 0b0001XXXX 0bYYZZZZZZ 0bZZZZZZZZ
Tract back Z bytes from outputted data and copy 4+(Y<<8)|X bytes
  • Bit 3 set: 0b00001???[need verification]
Not observed
  • Bit 2 set: 0b000001??[need verification]
Not observed
  • Bit 1 set: 0b0000001? 0bXXXXXXXX[need verification]
Output 0xFF some-odd times
The number of times = X - 0x1D if X >= 0x20, X + 3 otherwise.
  • Bit 0 set: 0b00000001 0bXXXXXXXX[need verification]
Output X+3 zeros
  • No bits set: 0b00000000[need verification]
Not observed