LC LZ2

From SMWiki
(Difference between revisions)
Jump to: navigation, search
m (the note was completely wrong)
 
Line 35: Line 35:
 
         CCC:        Real command
 
         CCC:        Real command
 
         LLLLLLLLLL: Length
 
         LLLLLLLLLL: Length
        Of note: In long commands, anything that says (L+1) earlier is just L, you don't add 1.
 
Seeing that the long length command uses ten bits for its length, the maximum length is 1024 bytes/1kB, while the normal length is 32 bytes.
 
  
 
== Decompression ==
 
== Decompression ==

Latest revision as of 15:16, 18 January 2014

LC_LZ2, as named by Lunar Compress, is a lossless data compression format, used by Super Mario World to compress graphics. It is also used by A Link to the Past and Super Mario World 2: Yoshi's Island.

Contents

[edit] Compression

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

bits
76543210
CCCLLLLL

CCC:   Command bits
LLLLL: Length

If the header byte is $FF, the end of the compressed data has been reached, and decompression will be aborted.

Here is a list of commands bits which the LC_LZ2 decompression function can use during the decompression:

000    "Direct Copy"
       Followed by (L+1) bytes of data
001    "Byte Fill"
       Followed by one byte to be repeated (L+1) times
010    "Word Fill"
       Followed by two bytes. Output first byte, then second, then first,
       then second, etc. until (L+1) bytes has been outputted
011    "Increasing Fill"
       Followed by one byte to be repeated (L+1) times, but the byte is
       increased by 1 after each write
100    "Repeat"
       Followed by two bytes (ABCD byte order) containing address (in the
       output buffer) to copy (L+1) bytes from
101    (Unused command)
110    (Unused command)
111    "Long length"
       This command has got a two-byte header:
       111CCCLL LLLLLLLL
       CCC:        Real command
       LLLLLLLLLL: Length

[edit] Decompression

During the decompression, the decompressed chunks are outputted into a buffer which is either RAM or SRAM. SMW uses the RAM address $7E:AD00 as its decompression buffer.

[edit] Usage

You can use the LC_LZ2 compression to mainly compress graphics. Technically you can compress anything with this format, but graphics is preferred due to their big size. Seeing the SNES isn't fast, the decompression takes a while to finish, so whenever you overuse the compression the loading time will increase.

[edit] Other

You can see an LC_LZ2 decompression routine setup at SNES $00:B888. The decompression routine itself is located at SNES $00:B8DE.

[edit] External links

Personal tools