Advertisement
vladikcomper

Contra Hard Corps - Compression Format

Aug 20th, 2013
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. Header:
  2. First two bytes store uncompressed data size.
  3.  
  4. Block:
  5. Block starts with 8-bit description field, used to determinate if the current byte in the stream is a raw byte or a decompression flag.
  6. If bit 0 is fetched, the next byte is treated as raw byte and send to the uncompressed stream
  7. If bit 1 is fetched, the next byte is treated as a decompression flag.
  8.  
  9. For example, if the description field fetched is %0001010, the following bytes in stream will be decoded as follows:
  10. RR FF.. RR FF.. RR RR RR RR
  11. where RR are raw bytes and FF are decompression flags. Notice, the decompression flags activate different decompression modes that read bytes further, so these sequencies sometimes take more than one byte. Once control is returned to the main decompression loop, the next byte after the whole sequence is read, not the one after the flag itself.
  12.  
  13. Decompression flags consist of one or two bytes. They execute different decompression modes, which may read the following bytes from stream. The upper bits activate different decompression modes with different formats, represented as follows:
  14.  
  15. %0ddnnnnn dddddddd Uncompressed stream copy (Mode 1)
  16. dd..dddddddd = Displacement (0..-1023)
  17. nnnnn = Number of bytes to copy (2..65)
  18.  
  19. %10nndddd Uncompressed stream copy (Mode 2)
  20. nn = Number of bytes to copy (2..5)
  21. dddd = Displacement (0..-15)
  22.  
  23. %11nnnnnn Compressed stream copy
  24. nnnnnn = Number of bytes to copy (8..71)
  25.  
  26. If decompression flag $1F is fetched, decompression is terminated.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement