emmanuel-marty / lzsa

Byte-aligned, efficient lossless packer that is optimized for fast decompression on 8-bit micros
Other
236 stars 30 forks source link
6309 6502 6809 8-bit 8088 assembler c c64 compression ibm-pc retrocomputing suffix-array z80 zx-spectrum

LZSA is a collection of byte-aligned compression formats that are specifically engineered for very fast decompression on 8-bit systems. It can compress files of any size by using blocks of a maximum size of 64 Kb with block-interdependent compression and up to 64 Kb of back-references for matches.

Pareto frontier *ZX Spectrum

Check out The Hollow by Darklite and Offense, winner of the Solskogen 2019 wild compo, that uses LZSA on Z80.

Gabba by Stardust ranked 2nd in the ZX Spectrum demo compo at CAFe demoparty 2019 and also used LZSA on Z80.

Myst Demake for the Apple II by Vince Weaver, uses LZSA on 6502.

The 8 bit guy's Commander X16 ROM uses LZSA on 6502 as well.

RomWBW uses LZSA on Z80 for a variety of hobbyist computers.

The popular rasm assembler for Z80 features LZSA-compressed data sections.

The desolate game port to the ZX Spectrum uses LZSA compression on Z80.

Marsmare: Alienation, the winner of the recent Yandex Retro Games Battle 2020, is using LZSA to compress its assets.

The Lowtech demo for the Apple II+ and IIe, by Wiz/Imphobia, compresses data with LZSA.

The Druid & Droid game for the Amstrad CPC, also uses LZSA for compression.

The LZSA compression tool uses an aggressive optimal packing strategy to try to find the sequence of commands that gives the smallest packed file that decompresses to the original while maintaining the maximum possible decompression speed.

The compression formats give the user choices that range from decompressing faster than LZ4 on 8-bit systems with better compression, to compressing as well as ZX7 with much better decompression speed. LZSA1 is designed to replace LZ4 and LZSA2 to replace ZX7, in 8-bit scenarios.

Compression ratio comparison between LZSA and other optimal packers, for a workload composed of ZX Spectrum and C64 files:

                     Bytes            Ratio            Decompression speed vs. LZ4
LZSA2                676681           52,49% <------   75%   
MegaLZ 4.89          679041           52,68%           Not measured
ZX7                  687133           53,30%           47,73%
LZ5 1.4.1            727107           56,40%           75%
LZSA1                735785           57,08% <------   90%
Lizard -29           776122           60,21%           Not measured
LZ4_HC -19 -B4 -BD   781049           60,59%           100%
Uncompressed         1289127          100%             N/A

Performance over well-known compression corpus files:

                     Uncompressed     LZ4_HC -19 -B4 -BD    LZSA1                LZSA2
Canterbury           2810784          935827 (33,29%)       850792 (30,27%)      770877 (27,43%)
Silesia              211938580        77299725 (36,47%)     73706340 (34,78%)    68928564 (32,52%)
Calgary              3251493          1248780 (38,40%)      1192123 (36,67%)     1110290 (34,15%)
Large                11159482         3771025 (33,79%)      3648393 (32,69%)     3519480 (31,54%)
enwik9               1000000000       371841591 (37,18%)    355360043 (35,54%)   334900611 (33,49%)

As an example of LZSA1's simplicity, a size-optimized decompressor on Z80 has been implemented in 67 bytes.

The compressor is approximately 2X slower than LZ4_HC but compresses better while maintaining similar decompression speeds and decompressor simplicity.

The main differences between LZSA1 and the LZ4 compression format are:

As for LZSA2:

Inspirations:

License:

8-bit assembly code:

External links:

Compressed format

Decompression code is provided for common 8-bit CPUs such as Z80 and 6502. However, if you would like to write your own, or understand the encoding, LZSA compresses data to a format that is fast and simple to decompress on 8-bit CPUs. It is encoded in either a stream of blocks, or as a single raw block, depending on command-line settings. The encoding is deliberately designed to avoid complicated operations on 8-bits (such as 16-bit math).