char*nextpri=primbuff[0];// pointer to the next primitive in primbuff. Initially, points to the first bit of primbuff[0]
shortdb=0;// index of which buffer is used, values 0, 1
// Embed TIM files
// See https://github.com/ABelliqueux/nolibgs_hello_worlds#embedding-binary-data-in-a-ps-exe
// 16bpp TIM
externunsignedlong_binary_TIM_TIM16_tim_start[];
externunsignedlong_binary_TIM_TIM16_tim_end[];
externunsignedlong_binary_TIM_TIM16_tim_length;
// 8bpp TIM
externunsignedlong_binary_TIM_TIM8_tim_start[];
externunsignedlong_binary_TIM_TIM8_tim_end[];
externunsignedlong_binary_TIM_TIM8_TIM_length;
// 4bpp TIM
externunsignedlong_binary_TIM_TIM4_tim_start[];
externunsignedlong_binary_TIM_TIM4_tim_end[];
externunsignedlong_binary_TIM_TIM4_tim_length;
TIM_IMAGETIM_16;
TIM_IMAGETIM_8;
TIM_IMAGETIM_4;
voidLoadTexture(u_long*tim,TIM_IMAGE*tparam){// This part is from Lameguy64's tutorial series : lameguy64.net/svn/pstutorials/chapter1/3-textures.html login/pw: annoyingmous
OpenTIM(tim);// Open the tim binary data, feed it the address of the data in memory
ReadTIM(tparam);// This read the header of the TIM data and sets the corresponding members of the TIM_IMAGE structure
LoadImage(tparam->prect,tparam->paddr);// Transfer the data from memory to VRAM at position prect.x, prect.y
DrawSync(0);// Wait for the drawing to end
if(tparam->mode&0x8){// check 4th bit // If 4th bit == 1, TIM has a CLUT
LoadImage(tparam->crect,tparam->caddr);// Load it to VRAM at position crect.x, crect.y
setClut(sprt_8b,TIM_8.crect->x,TIM_8.crect->y);// Only difference here is we set the CLUT to the position of the VRAM we loaded the palette earlier (see LoadTexture())
addPrim(ot[db],sprt_8b);
nextpri+=sizeof(SPRT);
// Set Texture page for the 8bit tim : 512, 256 - CLUT is at 0, 480