ZX02: A ZX0 Variant Tuned for Tiny 6502 Decompressors

On 30 May 2022 dmsc (Daniel Serpell, also the author of FastBasic) published ZX02, a data compressor designed so that its 6502 decompressor is as small and fast as possible. It is a modified version of Einar Saukas's ZX0 format. The compressor is only slightly changed from the original, but the decompressors, in C and 6502 assembly, are new code by dmsc.

The trade-off

Changing the format costs about 0.5% in compression ratio compared with ZX0, and in return the 6502 unpacker is much shorter. ZX02 is meant for compressing up to roughly 10 KB of data at a time, or for any case where the decompressor's size matters more than the last few bytes of compression. That suits, for example, loading screens, level data or small intros.

Three decompressors

By the end of release day the package included three 6502 versions, benchmarked on a "conan.gfx" test picture:

Decompressor Size (bytes) Speed (cycles per byte)
zx02-fast.asm 175 48.1
zx02-optim.asm 138 58.0
zx02-small.asm 130 72.6

The sizes include initialisation. The author recommended the 138-byte "optim" version for most uses, as the best balance of size and speed.

How well does it compress?

As with any compressor, it depends on the data. Asked about typical ratios, dmsc quoted 4.7:1 on the Conan intro screen and about 2.2:1 on ordinary text files, and advised people to test on their own data.

Field reports

The decompressor has also been used outside the Atari. One developer reported corrupt lines when unpacking images in an Atari Lynx game. The problem turned out to be a mistake in converting the source to another assembler's syntax, not a bug in ZX02. Others said they had used it without trouble to pack third-party Atari programs.

Getting it

Source code and documentation are at github.com/dmsc/zx02. The releases page has pre-built compressors for Linux and Windows, and the 6502 decompressors come as .asm sources.

Credits