6502 inflate routine

DEFLATE is a popular compression format. It is used in ZIP, GZ, PNG and many other formats. The specification of DEFLATE is available in RFC 1951.

In 2001 I wrote a DEFLATE decompression routine (called "inflate") in 6502 assembly language. In 2007 I optimized it so it is about 30% shorter and 10% faster.

Compilation

The routine uses three memory areas:

You must define locations of these areas when compiling, for example:

xasm inflate.asx /l /d:inflate=$b700 /d:inflate_data=$b900 /d:inflate_zp=$f0

Usage

Compressed and uncompressed data must fit in the memory. Before calling inflate you only need to set the locations of compressed and uncompressed data in page zero variables:

    mwa #compressedData inflate_zp
    mwa #uncompressedData inflate_zp+2
    jsr inflate

As the compressed data is read sequentially and only once, it is possible to overlap compressed and uncompressed data, that is the data being uncompressed can be stored in place of some compressed data which has been already read.

Compression

I wrote a simple command-line utility called deflater which compresses a file in the DEFLATE format using the standard zlib library. A Windows binary is available for download. For other platforms you will need to compile the program yourself.

Download

inflate source code, deflater source code and Windows binary