CPal is a global value that's used to 'Current Palette' bad programing style but .. it was done 2 years ago. Also it was used for 'sorting' through TIMs palettes.
The TIM function has a few incarnations.
The first incarnation specifically reads through and decodes a TIM file to a bitmap.
The second incarnation of TIM specifically targets CPal and ecodes a specific rectangular section of the TIM using that Palette.
The first parameter for this tim is the target bitmap
The second parameter is the TIM data.
The third is a Texture structure (defined elsewhere).
The remaining parameters are
X1/ Start X
Y1/ Start Y
X2/ End X
Y2/ End Y
This incarnation does NOT read the palettes it assumes they are already decoded (hence the first TIM call decodes the palettes and sets the bitmaps height and width) the remaining TIM calls actually decode the TIM data by taking the MINX MINY MAXX MAXY UV values and using the palette used with that polygon (triangle or quadric).
XOff is computed as what section of the TIM is being converted as the UV values only have a range of 0-255.
It first sets the bitmaps width and height values (of course!) then decodes each palette to the global palette cache (surprisinly named PAL). PAL contains 16 ot 256 entry palettes used for 4 and 8 bit TIMs. All the palettes of a TIM are dumped into this.
PSX_FF7 definitions you were wondering about:
typedef struct
{
UINT16 Parent;
INT16 Length;
UINT32 Offset;
}
PSX_UNK_BM;
typedef struct
{
UINT8 R;
UINT8 G;
UINT8 B;
UINT8 U;
}
PSX_FF7_CLR;
typedef struct
{
INT16 X;
INT16 Y;
INT16 Z;
UINT16 U;
}
PSX_FF7_VERTEX;
typedef struct
{
UINT16 A;
UINT16 B;
UINT16 C;
UINT16 D;
}
PSX_FF7_POLY;
typedef struct
{
UINT16 Count;
UINT16 TPage;
}
PSX_FF7_PCNT;
typedef struct
{
PSX_FF7_POLY Vertexs;
PSX_FF7_CLR Colors[3];
}
PSX_FF7_TRI;
typedef struct
{
PSX_FF7_POLY Vertexs;
PSX_FF7_CLR Colors[4];
}
PSX_FF7_QUAD;
typedef struct
{
PSX_FF7_POLY Vertexs;
UINT8 U0, V0;
UINT16 PAL;
UINT8 U1, V1;
UINT8 U2, V2;
}
PSX_FF7_TTRI;
typedef struct
{
PSX_FF7_POLY Vertexs;
UINT8 U0, V0;
UINT16 PAL;
UINT8 U1, V1;
UINT8 U2, V2;
UINT8 U3, V3;
UINT16 ZZ1;
}
PSX_FF7_TQUAD;
Anyhow, I think your suggestion on the palette index computation, might prove to be quite useful, I'll have to examine if they are using the 'index' as a Y value from the base index of the pallets in the VRAM of the PSX memory. I suppose 'emulating' the VRAM might be more helpful in dealing with PSX FF7 information decoding?
Cyb