Tiles encoding for SNES games, written by Lord J lord_j@hotmail.com, http://www.angelfire.com/pq/jumparound/index.html Monochrome tiles (2 colors palettes) Number of bytes required: tileHeight * tileWidth / 8 Note: Tile width should be 8 or 16. If one consider dynamic height (as seen in games such as FF3us), a mask bank (or tile height bank) must be programmed. Standard height is 8 or 16 pixels. Encoding: a 0 corresponds to the background color, a 1 to the foregroundcolor pixel (0,0) is bit 7 of byte 0 pixel (1,0) is bit 6 of byte 0 ... if tile width is 8 pixel (0,1) is bit 7 of byte 1 if tile width is 16 pixel (7,0) is bit 7 of byte 1 ... pixel (0,1) is bit 7 of byte 2 Example: this C code worked well with 16x11 tiles (FF3us) // base is a BYTE pointer to the concerned tile // if one consider dynamic width to be emulated, additional code // must be implemented for (y=0; y>((7-x%8)))&1; SetBit24bpp((BYTE)(_2bppDefPal[colIdx]>>16),(BYTE)(_2bppDefPal[colIdx]>>8),(BYTE)_2bppDefPal[colIdx],x,y); } } ****************************************************************** 2 bits tiles (4 colors palettes) Number of bytes required: tileHeight * tileWidth * 2 / 8 Note: Tile width should be 8 pixels. Tile lenght should be 8 pixels. Encoding: Even numbered bytes contains lsb of 2 bits color index, odd numbered tiles contains msb of 2 bits color index. Like the monochrome tile, one byte contains info for 8 pixels (the msb of the byte represents the leftmost pixel) Example: // 8x8 tiles for (j=0; j<8; j++) { curTile=tileBuf+(rawSnesString[n]*16)+(j*2); for (i=0; i<8; i++) { // inverted bytes, binary interlaced colIdx = (curTile[0]>>((7-i%8)))&1; colIdx |=((curTile[1]>>((7-i%8)))<<1); colIdx&=0x03; SetBit24bpp((BYTE)(_2bppDefPal[colIdx]>>16),(BYTE)(_2bppDefPal[colIdx]>>8),(BYTE)_2bppDefPal[colIdx],i,j); } } ****************************************************************** Color encoding for 15bpp tiles using a 16 colors palette: One 8x8 pixels tile has 32 bytes, here is an example: ___ [ ] 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F [ ] \ / | `- second row of pixels It is encoded so that each byte represents one row, the MSB being the leftmost pixel. Since each bit represent one pixel, the palette index must be spread on four bytes. The resulting four bytes might be interpreted as masks, or layers. Once you re-assemble the layers, you get the index. Here's an example: I want the color index of the rightmost pixel of the second row: Take bit 0 of byte 0x02(lsb), 0x03, 0x12, 0x13(msb). There, you have the 4 bits index. ****************************************************************** Color encoding for 15bpp tiles using a 8 colors palette: It's the same as the 16 colors palette, except you drop bit 3 in the color index. The example would look like so: ___ [ ] 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 [ ] \ / | `- second row of pixels One 8x8 pixels tile has 24 bytes. That's all. Lord J, Feb. 2000