/* TimZip Encoding Example ( Beta ) F Javier Ventoso Reigosa Please, if you found any bug send me an e-mail to: javier0003@mundivia.es or javier_ventoso@iname.com */ #include #include "pad.h" // GPU packet space #define PACKETMAX 1000 #define PACKETMAX2 (PACKETMAX*24) #define lengthOT 1 // VERY IMPORTANT: Set your tims address like ...f50, ...230, ...df0, etc... // ( always '0' in last position !!! ) #define TIM_ZIP1 (u_long *) 0x80090000 #define TIM_ZIP2 (u_long *) 0x80090f30 // ordering tables GsOT OT[2]; GsOT_TAG zTable[2][1 << lengthOT]; PACKET GpuOutputPacket[2][PACKETMAX2]; GsSPRITE Sprite1, Sprite2; int BuffInd; int ControlPad( void ); /* This function extracts a compress tim ( only 4/8 bits tim ) to VRAM */ void ExtractRLE48Sprite( u_long *timAddr, GsSPRITE *pSprite ) { long ncon; long length; u_char nrep; u_char *pointer; u_char byte_read; short buff_ind = 0; u_char buffer[512]; short y_count = 0; GsIMAGE image; RECT t, c; GsGetTimInfo( timAddr + 1, &image ); // get tim length length = (image.pw * 2) * image.ph; // set pointer to image data pointer = (u_char *) image.pixel; // expanding RLE encoding file for( ncon = 0; ncon < length; ) { byte_read = *pointer; pointer++; if( byte_read > 192 ) { nrep = byte_read - 192; byte_read = *pointer; pointer++; while( nrep ) { buffer[buff_ind] = byte_read; buff_ind++; if( buff_ind >= image.pw*2 ) { setRECT( &t, image.px, image.py + y_count, image.pw, 1 ); LoadImage( &t, (u_long *) buffer ); DrawSync( 0 ); y_count++; buff_ind = 0; } ncon++; nrep--; } } else { buffer[buff_ind] = byte_read; buff_ind++; ncon++; if( buff_ind >= image.pw*2 ) { setRECT( &t, image.px, image.py + y_count, image.pw, 1 ); LoadImage( &t, (u_long *) buffer ); DrawSync( 0 ); y_count++; buff_ind = 0; } } } // load clut setRECT( &c, image.cx, image.cy, image.cw, image.ch ); LoadImage( &c, image.clut ); DrawSync( 0 ); // ------- Adapt sprite initialization code if you need it ---- // ------- ( this works like uncompressed tims ) -------------- // Note: Remember that your 'pixel' and clut must have even // (px/cx) position pSprite->attribute = (image.pmode & 3) << 24; pSprite->x = 0; pSprite->y = 0; if( image.pmode & 3 ) { // 8 bits pSprite->w = (image.pw*2); // sprite width } else { // 4 bits pSprite->w = (image.pw*4); // sprite width } pSprite->h = image.ph; // sprite height pSprite->tpage = GetTPage( image.pmode&3, 0, image.px, image.py ); pSprite->u = image.px & 0x3f; // Texture page offset x axis pSprite->v = image.py & 0xff; // Texture page offset y axis pSprite->cx = image.cx; // CLUT x axis position pSprite->cy = image.cy; // CLUT y axis position pSprite->r = 128; // Regular brightness pSprite->g = 128; // Regular brightness pSprite->b = 128; // Regular brightness pSprite->mx = 0; // Rotation x pos pSprite->my = 0; // Rotation y pos pSprite->scalex = ONE; // Defined as 4096 pSprite->scaley = ONE; // Defined as 4096 pSprite->rotate = 0; // No rotation } static void Draw_Sprites( void ) { u_long cont = 0; for( ;; ) { BuffInd = GsGetActiveBuff(); GsSetWorkBase( (PACKET *) GpuOutputPacket[BuffInd] ); GsClearOt( 0, 0, &OT[BuffInd] ); GsSortSprite( &Sprite1, &OT[BuffInd], 0 ); GsSortSprite( &Sprite2, &OT[BuffInd], 1 ); DrawSync( 0 ); VSync( 0 ); if( !ControlPad() ) { return; } GsSwapDispBuff(); GsSortClear( 0, 0, 100, &OT[BuffInd] ); GsDrawOt( &OT[BuffInd] ); } } void InitVideoMode( void ) { int i; extern DISPENV GsDISPENV; PadInit(); ResetGraph( 0 ); SetVideoMode( MODE_PAL ); GsInitGraph( 512, 256, GsOFSGPU, 1, 0); //--display buffers GsDefDispBuff( 0, 0, 0, 256 ); // fix bug GsDISPENV.screen.h = 256; //--ordering tables for (i = 0; i < 2; i++) { OT[i].length = lengthOT; OT[i].org = zTable[i]; } GsSetLightMode( 0 ); // normal lighting GsSetAmbient( ONE/2,ONE/2,ONE/2 ); // ambient light (RGB) }; int main(void) { InitVideoMode(); // load compress sprite 1 ExtractRLE48Sprite( TIM_ZIP1, &Sprite1 ); Sprite1.x = 0; Sprite1.y = 0; // load compress sprite 2 ExtractRLE48Sprite( TIM_ZIP2, &Sprite2 ); Sprite2.x = 256; Sprite2.y = 0; Draw_Sprites(); ResetGraph(1); return( 0 ); } int ControlPad( void ) { int padread = PadRead(); if( padread & PADstart && padread & PADselect ) return( 0 ); // sprite 1 if( padread & PADLleft ) { Sprite1.x--; } if( padread & PADLright ) { Sprite1.x++; } if( padread & PADLup ) { Sprite1.y--; } if( padread & PADLdown ) { Sprite1.y++; } if( padread & PADL1 ) { Sprite1.rotate += 1024; } if( padread & PADL2 ) { Sprite1.rotate -= 1024; } // sprite 2 if( padread & PADRleft ) { Sprite2.x--; } if( padread & PADRright ) { Sprite2.x++; } if( padread & PADRup ) { Sprite2.y--; } if( padread & PADRdown ) { Sprite2.y++; } if( padread & PADR1 ) { Sprite2.rotate += 1024; } if( padread & PADR2 ) { Sprite2.rotate -= 1024; } return( 1 ); }