We've just updated MediaWiki and its underlying software. If anything doesn't look or work quite right, please mention it to us. --RanAS

RLE1

From SnesLab
Revision as of 23:34, 9 November 2019 by Vitor Vilela (talk | contribs) (Recovered from SMWiki, improvements are welcome.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

RLE1 or LC_RLE1, as named by Lunar Compress, is a lossless data compression format, used by Super Mario World to compress the overworld layer 2 event data's tilemap properties.

Compression

The compression is a simple run-length encoding format. It's one-dimensional, which means the decompressed data gets stored normally in the output buffer unlike LC_RLE2.

The compressed data consists of "chunks", each with a header:

bits
76543210
CLLLLLLL
C:       Command bit
LLLLLLL: Length

Here's a list of the command bit values the LC_RLE1 routine can use during decompression:

0    "Direct Copy"
     Followed by (L+1) bytes of data
1    "RLE"
     Followed by one byte to be repeated (L+1) times

The end of the decompression data is reached when the header byte and the following byte both are $FF. This means that the compression does not support 128 bytes of $FF compressed (because the result will be $FF $FF, which aborts the decompression). However, you can compress 127 bytes instead so that the result becomes $FE $FF)

Decompression

During the decompression, the decompressed chunks can be outputted into a buffer which is either RAM or SRAM. SMW uses the RAM address $7F:0000 as its decompression buffer. The maximum RLE decompression length is 128 bytes.

Usage

You can use the LC_RLE1 compression to mainly compress things like tilemap. Technically you can compress anything with this format, but tilemaps are preferred due to the often-occuring consecutive repeating bytes.

Other

You can see an LC_RLE1 decompression routine setup at SNES $04:DD40 (SMW). The decompression routine itself is located at SNES $04:DD57. The decompression routine does not support data which crosses bank boundaries. Therefore, you will have to take care of that.