Date: Sat, 3 May 1997 06:43:31 -0400 (EDT) To: tghack-list@joyce.eng.yale.edu From: David Michel X-Software: MLF v2.3, Copyright 1995, 1996 by Bt X-Original-Id: <1.5.4.16.19970503115136.114f68b4@mail.easynet.fr> Subject: Re: Decoding TG-16 Graphics X-UIDL: 88eac9c6387bfac987d581b1c61aa785 Hi, I will try to explain the gfx encoding, but don't flame me if it's understandable ;) There's two formats, one of 8x8 for all the screen characters and another of 16x16 for sprite characters. All characters use 16 colors. The PC-Engine use a planar mode rather than the well known chunky mode of PCs, if you already have some experience decoding Atari ST or Amiga gfx, you should easily understand the following. In planar mode the 4 bits that form the color index are stored in 4 separate bytes, let's say that we want to extract the color index for the third pixel from the left : color index 3rd pixel +---+---+---+---+ +---+---+---+---+---+---+---+---+ | 3 | 2 | 1 | 0 | byte 1 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | +---+---+---+---+ +---+---+---+---+---+---+---+---+ | | | | | | | | +-----------------------+ | | | | | | +---+---+---+---+---+---+---+---+ | | | byte 2 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | | | | +---+---+---+---+---+---+---+---+ | | | | | | +---------------------------+ | | | | +---+---+---+---+---+---+---+---+ | | byte 3 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | | | +---+---+---+---+---+---+---+---+ | | | | +-------------------------------+ | | +---+---+---+---+---+---+---+---+ | byte 4 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | | +---+---+---+---+---+---+---+---+ | | +-----------------------------------+ It's as simple as that :) The funny part is that those 4 bytes are not placed in order, they are interleaved. Byte 1 & 2 are stored first, and bytes 2 & 3 are stored 16 bytes after, here it's another nice drawing :) +---------------------+ 0 | byte 1 & 2 of line 1| +---------------------+ 2 | byte 1 & 2 of line 2| +---------------------+ 4 | byte 1 & 2 of line 3| +---------------------+ 6 | byte 1 & 2 of line 4| +---------------------+ 8 | byte 1 & 2 of line 5| +---------------------+ 10 | byte 1 & 2 of line 6| +---------------------+ 12 | byte 1 & 2 of line 7| +---------------------+ 14 | byte 1 & 2 of line 8| +---------------------+ +---------------------+ 16 | byte 3 & 4 of line 1| +---------------------+ 18 | byte 3 & 4 of line 2| +---------------------+ 20 | byte 3 & 4 of line 3| +---------------------+ 22 | byte 3 & 4 of line 4| +---------------------+ 24 | byte 3 & 4 of line 5| +---------------------+ 26 | byte 3 & 4 of line 6| +---------------------+ 28 | byte 3 & 4 of line 7| +---------------------+ 30 | byte 3 & 4 of line 8| +---------------------+ For the sprite characters the principe is the same, but in place of using bytes (8 pixels) they use words (16 pixels). But note that the words use Motorola encoding, this means that the first byte of the word is the upper byte! Otherwise sprite planes are not interleaved, they are stored like that : +------------------+ 0 | word 1 of line 1 | +------------------+ 2 | word 2 of line 1 | +------------------+ 4 | word 3 of line 1 | +------------------+ 6 | word 4 of line 1 | +------------------+ 8 | word 1 of line 2 | +------------------+ 10 | word 2 of line 2 | +------------------+ 12 | word 3 of line 2 | +------------------+ 14 | word 4 of line 2 | +------------------+ 16 | ... Well that's all. It's difficult to explain those things, I hope I'm enough clear :) --- David