The current URL is datacrystal.tcrf.net.
Lord Monarch: Tokoton Sentou Densetsu/Notes
Ressources loaders
Ressources data in the game begin by an identifier, that can be :
- 83 : LZ1 compressed data
- 84 : LZ2 compressed data
The load_ressource routine starts at 0x2BAA, reads the header and directs the program to the decoding routine, according to the header.
LZ1 compression scheme
The decompression routine starts at 0x3020.
It's a simplified LZ compression scheme (see LZ2, it's even simpler).
Each time a mask bit is read, the program checks if this is the last (after having read it). If this is the case, a new mask byte is read from the stream (which will be read after the current mask bit is processed ; that means that the data bytes needed for decoding the current mask bit are stored after the new mask byte).
- first 2 bytes : final_size of the decoded buffer. Decoding routine stops when this number is reached
- read first mask byte
- while the decoded stream is smaller than final_size
- read current_mask_bit (then loading another mask byte if needed)
- if current_mask_bit is 1 : uncompressed mode. Move next byte in source stream to dest stream.
- if current_mask_bit is 0 : window_copy_mode. We'll copy (delta_count + 1) bytes from dest[current_position - delta] to dest[current_position].
- next two bytes from the stream are dddddddd and DDDDNNNN under binary format
- delta = DDDDdddddddd and delta_count = NNNN
LZ2 compression scheme
The decompression routine starts at 0x3070.
It's a simplified LZ compression scheme : you can copy already decoded data in the stream. The compressed stream consists of masks (single bytes, read bit per bit, starting by LSB) and data, interleaved.
Each time a mask bit is read, the program checks if this is the last (after having read it). If this is the case, a new mask byte is read from the stream (which will be read after the current mask bit is processed ; that means that the data bytes needed for decoding the current mask bit are stored after the new mask byte).
- first 2 bytes : final_size of the decoded buffer. Decoding routine stops when this number is reached
- read first mask byte
- while the decoded stream is smaller than final_size
- read current_mask_bit (then loading another mask byte if needed)
- if current_mask_bit is 1 : uncompressed mode. Move next byte in source stream to dest stream.
- if current_mask_bit is 0 : it'll be window_copy_mode. We'll copy (delta_count + 1) bytes from dest[current_position - delta] to dest[current_position]. There are 2 ways of defining delta_count and delta.
- read current_mask_bit (then loading another mask byte if needed)
- if current_bit_mask is 0 : small window mode :
- read next two bits in mask (reloading mask if necessary)
- delta_count = 2 + (the number coded by last 2 binary digits) (be careful that the bits in the mask are read "in the wrong order")
- delta = next byte in source.
- if current_bit_mask is 1 : large window mode :
- read next byte in source as dddddddd (in binary)
- read next byte in source as DDDDDccc (in binary)
- delta = 000DDDDD dddddddd
- if ccc = 0 then delta_count = next byte in source else delta_count = bbb + 2