I really hope the map graphics aren't as annoying to rip as the monster graphics were.
void ROM::BuildRGBMonsterSprite(unsigned char *&sprite, int tileset, int palnum, int picnum)
{
//Determine if we're loading a small (4x4) or large (6x6) sprite.
int size;
if (picnum < 2)
size = 4;
else
size = 6;
//Determine the index of the first tile in the image.
const unsigned char picindex[4] = { 0x12, 0x22, 0x32, 0x56 };
int tilebase = picindex[picnum];
//Load the 4-color palette and get the corresponding 24-bit values from the NES palette.
unsigned char palette[BATTLE_PALETTE_SIZE][3];
unsigned char NESpalIndex;
for (int i = 0; i < BATTLE_PALETTE_SIZE; i++)
{
NESpalIndex = battlePalettes[palnum][i];
for (int j = 0; j < 3; j++)
palette[i][j] = NESpalette[NESpalIndex][j];
}
//Allocate the sprite.
sprite = new unsigned char[size*8*size*8*3];
//Fill the sprite. This is ugly.
//x and y are the tiles, i and j are pixels within each tile, l is the offset into the tile data
int tilenum = tilebase;
for (int y = 0; y < size; y++)
for (int x = 0; x < size; x++)
{
//Fetch a tile, then fill in the block in the image.
unsigned char *tile = battleTilesets[tileset][tilenum++];
int l = 0;
for (int i = 0; i < 8; i++)
{
//The tile is stored using bitplanes. Tile[l] is the LSB for a row of 8 pixels.
//Tile [l+8] is the MSB of the same row.
unsigned char temp0 = tile[l];
unsigned char temp1 = tile[l+8];
l++;
for (int j = 7; j >= 0; j--) //the MSB is the leftmost pixel
{
int pixel = (temp0 & 1) + ((temp1 & 1)<<1);
temp0 >>= 1; temp1 >>= 1;
for (int k = 0; k < 3; k++)
sprite[3*(size*8*(8*y + i) + 8*x + j) + k] = palette[pixel][k];
}
}
}
//If you thought that was bad, wait until you see the boss graphics!
}
And that wasn't even the weird part. The weird part was the way the game does palette swaps.