scawful / yaze

Yet Another Zelda3 Editor
Other
33 stars 3 forks source link

Converted LC_LZ2 compression from raw pointers to smart pointers. #1

Closed scawful closed 2 years ago

scawful commented 2 years ago

The format LC_LZ2 is a lossless compression technique used by Super Mario World and The Legend of Zelda: A Link to the Past for the Super Nintendo to compress graphics into a (sometimes) smaller format. The LC_LZ2 decompression routine is setup at SNES $00:B888. The decompression routine itself is located at SNES $00:B8DE. During the decompression, the decompressed chunks are outputted into a buffer which is either RAM or SRAM.

In the ROM class I've implemented a version of the format based on @Skarsnik sneshacking as well as @zarby89 ZScreamDungeon which both implement the format in C and C# respectively.

The ROM::Decompress method has been visually tested and confirmed to decompress the graphics in The Legend of Zelda: A Link to the Past, and now the goal is to implement compression as well. Given the editor is still early in development, I have no edited graphics or overworld tiles yet to compress or test (besides generating my own 3bpp snes tiles like in sneshacking) so I'm only using unit tests to confirm ROM::Compress.

The current pull request represents a transition from the C style buffers and pointers of @skarsnik sneshacking to a more idiomatic C++ smart pointers and container based implementation. The code makes use of the Google abseil-cpp library for string manipulation and error handling.

Further reading on LC_LZ2:

Credit to user @bonimy for the markdown explanation of the format.

LC_LZ2 Format

This format is identical to LZ1, except the repeat command's address is big endian.

The compressed stream consists of chunks, each starting with a 1 byte header.

bits
76543210
CCCLLLLL

CCC:   Command bits  
LLLLL: Length

The header byte $FF marks the end of the data stream.

List of commands

SohamG commented 2 years ago

What in tarnation