From CloudModding OoT Wiki
(Redirected from Yaz)

Yaz is the file compression algorithm used in Ocarina of Time and other Nintendo games.

More info about the Yaz algorithm can be found at [1] and source code for compressing/decompressing Yaz blocks can be found at [2]

In 64DD games the '0' and '1' in Yay, Yaz and MIO are read to determine if the archive source is cart or disk respectively. However, due to the lack of Disk Drive games, and emulators capable of supporting them, Yaz is often called Yaz0.

Algorithm

Header

The first 0x10 bytes are reserved for the header.

Offset End Data
0000 0003 Ascii string 'Yaz'
0003 0004 Ascii string '0' or '1'
0004 0008 int Decompressed Size
0008 0010 Padding

Decoding Data

The Yaz data field is split up into variable sized chunks containing a maximum of 25 bytes per chunk.

The first byte in a chunk acts as a "code" byte. Starting with the most significant bit, each bit determines whether the next data should be copied directly to the file stream, or contains a special "copy from decoded file stream" encoding that is either 2 or 3 bytes long.

  • If the next bit is 1, the next byte in the chunk is copied to the file stream, and the chunk and file stream cursors are incremented
  • If the next bit is 0, the next two bytes in the chunk are read, and the chunk cursor is incremented by 2.

The first two bytes of the encoding store the following variables:

  • seekback = (encode & 0x0FFF) + 1
  • n = encode & 0xF000 stores the number of bytes to copy.

seekback is the number of bytes to seek backwards from the file stream's current position to begin the copy.

n determines the number of bytes to copy:

  • If n > 0, then the number of bytes to copy is n + 2, giving you a minimum of 3 and maximum of 0x11 bytes encoded.
  • If n == 0, then the next byte in the chunk is read and stored in n. The number of bytes to copy is n + 0x12, or a maximum of 0xFF + 0x12 bytes encoded