mdcomp icon indicating copy to clipboard operation
mdcomp copied to clipboard

Add in Batman & Robin compression

Open vladikcomper opened this issue 3 years ago • 3 comments

The Adventures of Batman & Robin uses quite powerful, yet fast compression format with the sliding window of 0x6A0 bytes and maximum dictionary reference length of 0x113 bytes.

Below are my notes on this format, based on my research from 2014:

The game uses its own LZSS-based compression format. Unlike many others implementations, this one is notable for storing description fields and dictionary in separate data blocks, most likely to make fetching 16-bit fields faster as M68K would have problems with reading 16-bit words from unaligned locations.

The compressed data starts with 32-bit relative offset, which points to the beginning of the dictionary. Theoretically, this allows for 'global' or shared dictionaries, meaning different compressed data may use same dictionaries with just different description fields streams to handle decompression. However, this may be difficult to implement with the given compression format, unless the data in the question is nearly identical.

Right after the dictionary offset, description fields that operate decompression start. Those fields can be interpreted as one continous bitsteam, but technically, they are being fetched as 16-bit words.

The following combination of codes are possible in the description fields:

	%0			- Uncompressed byte

	%10[disp]		- Set copy count to 2

	%11cc[disp]		- Set copy count to 3..5
	%1100cccc[disp]		- Set copy count to 6..$14
	%11000000cccccccc[disp]	- Set copy count to $15..$113
	%1100000000000000[disp]	- Quit decompression

	[disp]:
	%00ddddd		- Set displacement to 1..$20
	%01ddddddd		- Set displacement to $21..$A0
	%10ddddddddd		- Set displacement to $A1..$2A0
	%11dddddddddd		- Set displacement to $2A1..$6A0

Here's also a working decompressor implementation that also searches for compressed art in the ROM: https://pastebin.com/RahSijzh

vladikcomper avatar Jun 08 '21 08:06 vladikcomper

TODO: Check if B&R compression (much like the sound driver) was actually developed by Zyrinx and was featured in their own games, like Red Zone.

vladikcomper avatar Jun 08 '21 08:06 vladikcomper

The split streams for descriptor/dictionary from issue #8 is important here.

flamewing avatar Jun 08 '21 11:06 flamewing

Blocked by #25

flamewing avatar Nov 17 '21 18:11 flamewing