The data following the 16-bit index is compressed using LZSS compression. The LZSS handler function in the TI toolchain is called _ _TI_decompress_lzss. Refer to the implementation of this function in the RTS source code for details on the format.
The decompression algorithm for LZSS is as follows:
- 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.