/* * "ESCSPRIT.C" * * Part of The Escotia Playstation Library * * Author: ScoTT Campbell * Date: 10/9/98 * * Updated: 25/10/98 * */ #include "..\headers\escsprit.h" /*******************************/ /* Start of GsSPRITE functions */ /*******************************/ 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); // Assign values to the sprite handler spritePtr->attribute = (unsigned long int) (timData.pmode << 24); // Set sprite to correct display mode spritePtr->attribute &= 0x03000000; // Set all other attribute bits to zero /* Set the width according to the colour mode */ /* And load CLUT if neccessary */ if(spritePtr->attribute & 0x01000000) { spritePtr->w = (timData.pw * 2); // 8-bit clut // 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); spritePtr->cx = timData.cx; spritePtr->cy = timData.cy; spritePtr->tpage = GetTPage(1, 0, (64 * (timData.px / 64)), (256 * (timData.py / 256))); spritePtr->u = (timData.px % 64) * 2; spritePtr->v = timData.py % 256; } else if(spritePtr->attribute & 0x02000000) { spritePtr->w = (timData.pw); // 15-bit direct spritePtr->tpage = GetTPage(2, 0, (64 * (timData.px / 64)), (256 * (timData.py / 256))); spritePtr->u = timData.px % 64; spritePtr->v = timData.py % 256; } else { spritePtr->w = (timData.pw * 4); // 4-bit clut // 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); spritePtr->cx = timData.cx; spritePtr->cy = timData.cy; spritePtr->tpage = GetTPage(0, 0, (64 * (timData.px / 64)), (256 * (timData.py / 256))); spritePtr->u = (timData.px % 64) * 4; spritePtr->v = timData.py % 256; } spritePtr->h = (timData.ph); spritePtr->mx = spritePtr->w/2; spritePtr->my = spritePtr->h/2; spritePtr->x = xPosition; spritePtr->y = yPosition; spritePtr->r = 128; spritePtr->g = 128; spritePtr->b = 128; spritePtr->scalex = ONE; spritePtr->scaley = ONE; spritePtr->rotate = 0; DrawSync(0); }/* InitSprite */ void CopySprite(GsSPRITE* source, GsSPRITE* destination) { destination->attribute = source->attribute; destination->x = source->x; destination->y = source->y; destination->w = source->w; destination->h = source->h; destination->tpage = source->tpage; destination->u = source->u; destination->v = source->v; destination->cx = source->cx; destination->cy = source->cy; destination->r = source->r; destination->g = source->g; destination->b = source->b; destination->mx = source->mx; destination->my = source->my; destination->scalex = source->scalex; destination->scaley = source->scaley; destination->rotate = source-> rotate; }/* CopySprite */ void InitVerticalSpriteSet(GsSPRITE* spriteArray, unsigned long int spriteAddress, unsigned int numberInSet, unsigned int spriteHeight, unsigned int xPosition, unsigned int yPosition) { int i; unsigned int startU, currentU; unsigned int startV, currentV; 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); for(i=0;i 256 ) /* Not enough room for a sprites - somethings went wrong */ { return; } } DrawSync(0); }/* InitVerticalSpriteSet */ void InitHorizontalSpriteSet(GsSPRITE* spriteArray, unsigned long int spriteAddress, unsigned int numberInSet, unsigned int spriteWidth, unsigned int xPosition, unsigned int yPosition) { int i; unsigned int startU, currentU; unsigned int startV, currentV; 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); for(i=0;i 256 ) /* Not enough room for a sprites - somethings went wrong */ { return; } } DrawSync(0); }/* InitHorizontalSpriteSet */ void InitSpriteSet(GsSPRITE* spriteArray, unsigned long int spriteAddress, unsigned int numberInSet, unsigned int spriteWidth, unsigned int spriteHeight, unsigned int xPosition, unsigned int yPosition) { int i; unsigned int startU, currentU; unsigned int startV, currentV; 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); for(i=0;i 256 ) /* Not enough room for a sprite so move to next line of sprites */ { currentU = startU; currentV += spriteHeight; } } DrawSync(0); }/* InitSpriteSet */ void SetSpritePosition(GsSPRITE* spritePtr, int xPosition, int yPosition) { spritePtr->x = xPosition; spritePtr->y = yPosition; }/* SetSpritePosition */ void SetSpriteXPosition(GsSPRITE* spritePtr, int xPosition) { spritePtr->x = xPosition; }/* SetSpriteXPosition */ void SetSpriteYPosition(GsSPRITE* spritePtr, int yPosition) { spritePtr->y = yPosition; }/* SetSpriteYPosition */ void MoveSprite(GsSPRITE* spritePtr, int xAmount, int yAmount) { spritePtr->x += xAmount; spritePtr->y += yAmount; }/* MoveSprite */ void SetSpriteAttributes(GsSPRITE* spritePtr, unsigned long int attributes) { unsigned long int colourMode; /* Get the sprite colour mode */ colourMode = spritePtr->attribute; colourMode &= 0x03000000; /* Clear all the bits we control */ spritePtr->attribute &= 0x04FFFFBF; /* Set the bits we want */ spritePtr->attribute |= attributes; /* Make sure sprite has same colour mode */ spritePtr->attribute &= 0xFCFFFFFF; spritePtr->attribute |= colourMode; }/* SetSpriteAttributes */ void SetSpriteColour(GsSPRITE* spritePtr, int red, int green, int blue) { spritePtr->r = red; spritePtr->g = green; spritePtr->b = blue; }/* SetSpriteColour */ void SetSpriteColourVector(GsSPRITE* spritePtr, CVECTOR* colourVectorPtr) { spritePtr->r = colourVectorPtr->r; spritePtr->g = colourVectorPtr->g; spritePtr->b = colourVectorPtr->b; }/* SetSpriteColourVector */ void SetSpriteRotationCentre(GsSPRITE* spritePtr, int x, int y) { spritePtr->mx = x; spritePtr->my = y; }/* SetSpriteRotationCentre */ void MoveSpriteRotationCentre(GsSPRITE* spritePtr, int xAmount, int yAmount) { spritePtr->mx += xAmount; spritePtr->my += yAmount; }/* MoveSpriteRotationCentre */ void RotateSprite(GsSPRITE* spritePtr, long int rotation) { long int degree360 = 360 * 4096; spritePtr->rotate += rotation; /* Normalise value so that we never get overflow */ spritePtr->rotate = spritePtr->rotate % degree360; }/* RotateSprite */ void SetSpriteSize(GsSPRITE* spritePtr, short int size) { short int maxScale = (4096 * 8) - 1; if(size > maxScale) size = maxScale; spritePtr->scalex = size; spritePtr->scaley = size; }/* SetSpriteSize */ void ScaleSprite(GsSPRITE* spritePtr, short int scaleFactor) { short int maxScale = (4096 * 8) - 1; short int scaleNumber = scaleFactor; // Incase I want to change the value passed in into a ratio short int space; /* Find out how much we can add to scalex without overflow */ space = maxScale - spritePtr->scalex; if((scaleNumber < 0) && (spritePtr->scalex < abs(scaleNumber))) /* scalex will be -ve so set to 0 */ spritePtr->scalex = 0; else if((scaleNumber >0) && (space < scaleNumber)) /* scalex will overflow so set to maximum value */ spritePtr->scalex = maxScale; else /* Not a special case so just add scaleNumber */ spritePtr->scalex += scaleNumber; /* Find out how much we can add to scaley without overflow */ space = maxScale - spritePtr->scaley; if((scaleNumber < 0) && (spritePtr->scaley < abs(scaleNumber))) /* scaley will be -ve so set to 0 */ spritePtr->scaley = 0; else if((scaleNumber >0) && (space < scaleNumber)) /* scaley will overflow so set to maximum value */ spritePtr->scaley = maxScale; else /* Not a special case so just add scaleNumber */ spritePtr->scaley += scaleNumber; }/* ScaleSprite */ void ScaleSpriteInX(GsSPRITE* spritePtr, short int scaleFactor) { short int maxScale = (4096 * 8) - 1; short int scaleNumber = scaleFactor; // Incase I want to change the value passed in into a ratio short int space; space = maxScale - spritePtr->scalex; if((scaleNumber < 0) && (spritePtr->scalex < abs(scaleNumber))) /* scalex will be -ve so set to 0 */ spritePtr->scalex = 0; else if((scaleNumber >0) && (space < scaleNumber)) /* scalex will overflow so set to maximum value */ spritePtr->scalex = maxScale; else /* Not a special case so just add scaleNumber */ spritePtr->scalex += scaleNumber; }/* ScaleSpriteInX */ void ScaleSpriteInY(GsSPRITE* spritePtr, short int scaleFactor) { short int maxScale = (4096 * 8) - 1; short int scaleNumber = scaleFactor; // Incase I want to change the value passed in into a ratio short int space; /* Find out how much we can add to scaley without overflow */ space = maxScale - spritePtr->scaley; if((scaleNumber < 0) && (spritePtr->scaley < abs(scaleNumber))) /* scaley will be -ve so set to 0 */ spritePtr->scaley = 0; else if((scaleNumber >0) && (space < scaleNumber)) /* scaley will overflow so set to maximum value */ spritePtr->scaley = maxScale; else /* Not a special case so just add scaleNumber */ spritePtr->scaley += scaleNumber;; }/* ScaleSpriteInY */ /*****************************/ /* End of GsSPRITE functions */ /*****************************/