The decompression algorithm for LZSS is as follows. See copy_decompress_lzss.c for details on the LZSS algorithm.
- Read 16 bits, which are the encoding flags (F) marking the start of the next LZSS encoded packet.
- For each bit (B) in F, starting from the least significant to the most significant bit, do the following:
- If (B & 0x1), read the next 16 bits and write it to the output buffer. Then advance to the next bit (B) in F and repeat this step.
- Else read the next 16-bits into temp (T), length (L) = (T & 0xf) + 2, and offset (O) = (T >> 4).
- If L == 17, read the next 16-bits (L'); then L += L'.
- If O == LZSS end of data (LZSS_EOD), we've reached the end of the data, and the algorithm is finished.
- At position (P) = output buffer - Offset (O) - 1, read L bytes from position P and write them to the output buffer.
- Go to step 2a.