Final Fantasy Tactics Translation Project

String Compression

So far, I have found one method of string compression used in Final Fantasy Tactics. It's quite simple, thankfully. While reading a string, instead of a regular character you will encounter a 0xF0, 0xF1, 0xF2, or 0xF3 byte. This byte and the two bytes following it make up a jump command telling you to jump backward in the text stream and use a certain number of characters as output. For example, 0xF02044 would mean "jump back 0x44 (68 decimal) characters and read 5 of them."

How it Works

The jump command consists of 24 bits. The first 6 bits are always 111100 and indicate that this is a jump command. The value of the next five bits, plus four, is the number of bytes to read from the history (four is the minimum length of a target string, so 0x00 means 4, 0x01 means 5, etc.) The last 13 bits indicate the width of the jump, starting from the first character of the jump command. However, you cannot simply use the value of these 13 bits directly as the width, because certain values for the last byte of the jump command are illegal, namely 0xFE and 0xFF. So, the real width W = w - floor(w ÷ 256) × 2, where w is the value of the last 13 bits. Therefore, the maximum jump width is 8,128 and the maximum target string length is 35. I suppose 0xFE and 0xFF are probably illegal for the second byte as well, but I haven't yet worked out what the consequence of that would be.

Binary representation of 0xF02044
JUMP length width
111100 00001 0000001000100