/************************************************ * * * Display a single 8-bit sprite * * with movement, rotation and scaling * * * * Author: ScoTT Campbell * * Date: 8/10/98 * * * * www.netyaroze-europe.com/~escotia * * * * E-mail: escotia@escotia.freeserve.co.uk * * * * Please mail me about any BUGS etc. * * * ************************************************/ #include // Header for NY functions. Must be included in all programs #include "screen.h" #include "pad.h" /*************************** Primitive related definitions ***************************/ #define SPRITE_ADDRESS (0x80090000) // Address TIM file will be loaded into main memory #define AMOUNT_PRIMITIVES (5) // Make sure there's plenty of space GsSPRITE sprite; // Sprite handler GsBOXF box; // Box handler /*************************************************************************************/ /************************* Ordering Table related definitions ************************/ #define OT_LENGTH (2) // For 1< ONE*2)) { sprite.scalex += 10; sprite.scaley += 10; } } }/* while */ return 0; }/* main */ /*********************************** Local functions *********************************/ void InitGraphics() /* Sets up the graphics mode to 16-bit, no dithering, GPU offset and the macros chosen in screen.h */ { SetVideoMode(VIDEO_MODE); // PAL or NTSC - defined in screen.h GsInitGraph(SCREEN_WIDTH, SCREEN_HEIGHT,4,0,0); // Set up non-interlace GsDefDispBuff(0,0,0,SCREEN_HEIGHT); // Define double buffers if(SCREEN_HEIGHT == 256) GsDISPENV.screen.h = SCREEN_HEIGHT; // Fix 256 line bug which makes bottom 16 lines dissapear }/* InitGraphics */ void InitWorldOTs() { int i; /* Initialise OT's */ for(i=0; i<2; i++) { worldOT[i].org = otElements[i]; // Point header to array of OT_TAGs worldOT[i].length = OT_LENGTH; // Length must be correctly set otherwise memory problems occur GsClearOt(0, 0, &worldOT[i]); // Clear the OTs ready to use } }/* InitWorldOTs */ void InitControllers() // Set addresses of controllers' buffers { GetPadBuf(&pad1Buffer, &pad2Buffer); }/* InitControllers */ void InitSprite(GsSPRITE* spritePtr, unsigned long int spriteAddress, int xPosition, int yPosition) { RECT rect; GsIMAGE timData; // Get info at Sprite_Address and put into timData GsGetTimInfo((unsigned long*)(spriteAddress+4), &timData); // Load sprite into frame buffer rect.x = timData.px; rect.y = timData.py; rect.w = timData.pw; rect.h = timData.ph; LoadImage(&rect, timData.pixel); // Load sprites CLUT into frame buffer rect.x = timData.cx; rect.y = timData.cy; rect.w = timData.cw; rect.h = timData.ch; LoadImage(&rect, timData.clut); // Assign values to the sprite handler spritePtr->attribute = (unsigned long int) (timData.pmode << 24); // Set sprite to correct display mode spritePtr->attribute &= 0x53000000; // Make sprite semi-transparent (overlay) spritePtr->w = (timData.pw * 2); // 8-bit clut so rendered as twice actual width spritePtr->h = (timData.ph); // Set sprites height spritePtr->mx = spritePtr->w/2; // Set display point to center of sprite spritePtr->my = spritePtr->h/2; // " spritePtr->x = xPosition; // Set screen display position spritePtr->y = yPosition; // Set screen display position spritePtr->tpage = GetTPage(1, 0, timData.px, timData.py); // Get VRAM TPage number where sprite is stored spritePtr->u = 0; // No offset within the TPage spritePtr->v = 0; // " spritePtr->cx = timData.cx; // Attach CLUT to handler spritePtr->cy = timData.cy; // " spritePtr->r = 128; // spritePtr->g = 128; // Set brightness to normal spritePtr->b = 128; // spritePtr->scalex = ONE; // Set size in X to 1:1 spritePtr->scaley = ONE; // Set size in Y to 1:1 spritePtr->rotate = 0; // No rotation DrawSync(0); }/* InitSprite */ void InitBox() { box.attribute = 0; // Set box ready to diplay with no transparency box.x = 100; // Set box top left corner display position box.y = 100; box.w = 120; // Set box width box.h = 40; // Set box height box.r = 155; // Set box colour box.g = 180; box.b = 25; } /* InitBox */ void InitText() { FntLoad(960, 256); // Load text into frame buffer (VRAM) FntOpen(16, 16, 256, 200, 0, 512); // Set output position for text }/* InitText */ unsigned long int ReadPads() // SONY function // Read from controllers { return (~(*(pad1Buffer+3) | *(pad1Buffer+2) << 8 | *(pad2Buffer+3) << 16 | *(pad2Buffer+2) << 24)); }/* ReadPads */ /*************************************************************************************/