Edit: Did a little reading inbetween. As guessed it is indeed a variant of the Lempel-Ziv-Welch family of compressors. It is based on LZSS with certain fine-tuning of parameters to accomodate 'low-end' CPU like Z80, 6502 etc. If you still want to understand how it is working look here for an explanation on LZSS
I think my main problem of understanding was that I couldn't relate the Elias codes in the given file to the description of how Elias encoding worked.
I can understand that, because the variant of Elias coding used is a very special one.
If I understand this correct, then the decoding of the Elias works as follows
- the result in 'X' is stitched together from inverted Elias coded single
bits of the input stream. That is '%10xxxxxx' in 'bitr' will shift in
a '0' as low bit in 'X' - '%11xxxxxx' will shift in a '1' and '%0xxxxxxx'
will terminate the process.
- the bit-stream for the decoding is interleaved into the copy blocks
- the bit-stream also contains the bits that define the state transitions!
New offsets do not fall under the Elias decoding, but are read as single (or double) bytes.
All this hoopla, just to make the decoder small & fast on an ancient architecture ...
Oh, forgot attached is my take on it - I have a tendency towards heavy commenting.