Rob Northen compression (RNC) is a multi-platform compression format created by Rob Northen in 1991. It is a variant of LZSS and Huffman Coding. Decompression libraries have been written for the PC, Mega Drive, Game Boy, SNES and Atari Lynx. RNC is used in a number of games by UK developers (notably Bullfrog and Traveller's Tales), including Sonic 3D: Flickies' Island, Blam! Machinehead, Dungeon Keeper 2, Magic Carpet, Syndicate and Syndicate Wars.
Most RNC compressed files come in a standard 18 byte header:
|Data Type||Description||Size (in Bytes)|
|Compression Method||1 or 2 (In binary)||1|
|Uncompressed Size||Size of the original file||4|
|Compressed Size||Size of the RNC data (excluding header)||4|
|Uncompressed CRC||Checksum of the original file||2|
|Compressed CRC||Checksum of the RNC data||2|
|Leeway||Difference between compressed and uncompressed data in largest pack chunk (if larger than decompressed data)||1|
|Pack Chunks||Amount of pack chunks||1|
Each multi-byte portion of the header is big endian.
RNC Method 1 consists of a bit stream and a byte stream. The bit stream is read from right to left, as little endian 16 bit words. The first two bits of the bit stream are ignored.
Each pack chunk contains the following:
Method two also consists of a bit stream and a byte stream. It also ignores the first two bits. However, the bit stream is read from left to right as bytes. Also, it does not contain Huffman trees or sub chunks. Instead, it uses a fixed prefix coding in the following format:
|Bit Stream||Byte Stream||Description|
|0||X||Literal Byte X|
|10 + Length + Distance||X||Move Length Bytes from (Distance * 256) + X + 1|
|10111XXXX||XXXX * 4 + 12 Bytes||Get XXXX * 4 + 12 Literal Bytes|
|110||X||Move 2 Bytes from X + 1|
|1110 + Distance||X||Get 3 bytes from (Distance * 256) + X + 1|
|1111 + Distance||X Y||If X != 0, Get Y + 8 Bytes from (Distance * 256) + X + 1|
|11110||0||End of File|
|11111||0||End of pack chunk|
The Length and Distance Codes are the following: