DEFLATE is a popular compression format, used in ZIP, GZip, 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 than before.

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 zero-page 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

There are several ways to get DEFLATE compressed data. Originally I wrote a command-line utility called deflater which uses the standard zlib library. However, better compression can be obtained with 7-Zip. It supports the GZip format which is a thin layer on top of DEFLATE. My program gzip2deflate extracts DEFLATE from a GZip file. It reads GZip on standard input and writes DEFLATE to standard output. I recommend using it like this:

7z a -tgzip -mx=9 -so dummy INPUT_FILE | gzip2deflate >OUTPUT_FILE.dfl

If you don’t have 7-Zip, use:

gzip -c -9 INPUT_FILE | gzip2deflate >OUTPUT_FILE.dfl

A Windows binary of gzip2deflate is available for download. For other platforms you will need to compile the program yourself.

Download

inflate source code, gzip2deflate source code and Windows binary