An interesting Aplib-based data compressor

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
User avatar
Alessandro
Dynamite Dan
Posts: 1910
Joined: Wed Nov 15, 2017 11:10 am
Location: Messina, Italy
Contact:

An interesting Aplib-based data compressor

Post by Alessandro »

Following the discussion in this thread, I went to read - with the help of Google Translate ;-) - the two articles, and like Einar, I also found them to be quite well written and documented. Generally speaking,they confirmed what I already knew, i.e.:
  • Exomizer, now at versione 3.02, is the most efficient in terms of compression, although its decompression speed is also the slowest, and the decompressors need an extra 256 byte further space for calculations;
  • ZX7 is the least efficient for large files, but used in conjunction with RCS is the most efficient solution for packing screen files;
  • Aplib seems to stay in the middle - not as efficient as Exomizer, but more than ZX7, and can count on faster Z80 decompressor codes.
The articles fueled my curiosity, and perusing the Web, I found this thread on the CPC Wiki forum about APC 1.2, an Aplib-based compressor made by Sven Dahl for the 6502 and adapted by Antonio Villena for the Z80. The post was written by the same author of the articles above; he also wrote that he fixed a bug in the compressor that made it yield some erratic results.

I downloaded the compressor executable and made a quick test with my typical scenario of use: squeezing AGD-authored levels, and their additional code, of large games into the 16384 bytes of the 128K models' ROM banks. I employed the three levels of Sophia II for the test and compared the results with ZX7 and Exomizer 3.02:

Code: Select all

Lev.  Unc.    ZX7     APC     Exo
-----------------------------------
 1    26758   15574   14875   14978
 2    27051   16291   15604   15647
 3    27488   15844   15245   15306
Surprisingly, APC compresses even better than Exomizer in this particular case, and although the gain might seem small - ranging here from 43 to 103 bytes - it is nonetheless important when you have a maximum threshold of 16384 bytes.

The post's author included two Z80 decompressors written by Dan Weiss (Dwedit), utopian and Jaime Tejedor Gomez (Metalbrain). He optimized one of them for size and the other for speed. The former in particular is 140 bytes long, and with a slight modification at the cost of 4 bytes more, can be made 20% faster. I tried it and it is noticeably faster than the F0 Exomizer 3 Z80 decompression routine (also by Metalbrain and optimized by Antonio Villena and Urusergi), which is also longer at 163 bytes.

These two decompressors were written for the SjASM plus cross-assembler, which uses non-standard formats for labels and other elements (ADD A instead of ADD A,A etc.). I modified them to comply as much as possible with the standard Z80 format and with the Pasmo 0.5.4 beta 2 cross-assembler in particular. I included all of the decompressors in a ZIP file, together with the executable, a .BAT file for easier use and a small text note. You can download it from here.
catmeows
Manic Miner
Posts: 718
Joined: Tue May 28, 2019 12:02 pm
Location: Prague

Re: An interesting Aplib-based data compressor

Post by catmeows »

ApLib uses "last offset" feature that improves a lot compression of structured data. Exomizer has better offset-matchlen encoding, that is why it will be better with more general test data suite (Canterbury etc).
Proud owner of Didaktik M
Post Reply