Compression Methods

Some data within the Super Mario World ROM is compressed using different algorithms. This page explains how to decompress that data depending on the algorithm.

LC_RLE1

The first byte is a command in the format FLLLLLLL2, where the F stands for the RLE flag, and the L‑s stand for length. Depending on the value of the RLE flag, the bytes that follow the command are interpreted either way:

RLE flag Behaviour
0 The following length bytes are read directly.
1 The following 1 byte is repeated length times.

After that we get another command, another string, rinse and repeat until we read command FF16 followed by another FF16, meaning that the data ends there.

Our implementation of the LC_RLE1 decompressor can be found here.

LC_LZ2

The first byte is a header in the format CCCLLLLL2, where the C‑s stand for command, and the L‑s stand for length. Depending on the command, the bytes that follow the header are interpreted in a variety of ways:

Command Behaviour
0002 (Direct Copy) The following length + 1 bytes are read directly.
0012 (Byte Fill) The following 1 byte is repeated length + 1 times.
0102 (Word Fill) The following 2 bytes are alternated until length + 1 bytes are written.
0112 (Incresing Fill) The following 1 byte is repeated length + 1 times, but after each write the value is incremented by 1.
1002 (Repeat) The following 1 word is interpreted as an index to the output buffer from which length + 1 bytes are copied.
1112 (Long Length) This extends the header to 2 bytes and changes its format to
111CCCLL LLLLLLLL2.

After that we get another command, another string, rinse and repeat until we read header FF16 which means that the data ends there.

Our implementation of the LC_LZ2 decompressor can be found here.