Notes:Mega Man Legends 2
This page contains notes for the game Mega Man Legends 2.
Contents
Archive files
.BIN files found on the disc containing various assets. A file will occupy a number of $800-byte pages before the next file in the archive. Leftover space on a page will be zeroes.
File header
Every file in the archive starts with a $30-byte header. The purpose of the first three words is consistent across all file types.
Offset | Purpose |
---|---|
$00000000 | File type |
$00000004 | Size of file (uncompressed size if compressed file) |
$00000008 | Number of pages until next file in archive |
File type 2: external color data
A file containing only a header and color data. Some images need to be combined with one of these.
Offset | Purpose |
---|---|
$00000010 | Number of colors included (halfword) |
Halfwords for every color come after the header.
File type 3: compressed TIM
Contains a compressed image, optionally including color data (CLUT), before the image in that case.
Header
Offset | Purpose |
---|---|
$00000010 | Number of colors included (halfword) |
$00000018 | Width of image (halfword). Needs to be doubled depending on codec. |
$0000001A | Height of image (halfword) |
$00000024 | Pointer to start of compressed data (halfword). Add $30 to account for the header. |
Bitmasks for decompression
Directly after the header comes a number of 32-bit words where each bit from left to right corresponds to a 16-bit halfword in the compressed stream. 0 denotes a literal halfword to copy as is. 1 means the halfword is a reference backwards. When 32 bits have been consumed, the next mask is read.
Reference halfwords
The upper 13 bits give an offset in the reference window (ca $2000-byte area) to copy from. The window is at the start of the output stream at first. The lower 3 bits tell how many halfwords, minus 2, to copy from there.
If a reference halfword is $FFFF, however, the position of the reference window is updated to start at what the current output position is when this is encountered.
Checking if full output size has been reached works to determine end of decompression.