/************************************************ * * * SINGLE SPRITE DISPLAY CODE * * ============================== * * * * Written by Steven Lewis * * * * Downloaded from: * * Steve's Yaroze Site * * http://www.netyaroze-europe.com/~slewis/ * * * * e-mail: * * stevenlewis@birminghamhome.freeserve.co.uk * * * * This code displays 4, 8, or 16-bit sprites * * * ************************************************/ // ----------------------------- HEADER FILES ----------------------------------- #include // Should be used in all Yaroze programs #include "pad.h" // File for PlayStation joypad reading routines // ------------------------------------------------------------------------------ // ----------------------------- DEFINITIONS ------------------------------------ #define SCREEN_WIDTH (320) // Sets the width of the screen to be 320 pixels #define SCREEN_HEIGHT (256) // Sets the height of the screen to be 256 pixels #define SPRITE_COUNT (1+1) /* Sets the total number of sprites as the number of sprites in this program plus 1, with the plus 1 being so the Ordering Table PACKET area has plenty of room */ #define TIM_ADDRESS (0x80100000) /* The location at which the TIM file sprite will be loaded into the PlayStations memory. This value will also have to be placed into the batch file which runs this program */ #define OT_LENGTH (1) /* Sets the length of the Ordering Table equal to 1. Subsequently, as there is only one sprite, there is no need for an Ordering Table length larger than this because one sprite does not need to go infront, or behind, any other object on screen */ // ----------------------------------------------------------------------------- // -------------------- ORDERING TABLE RELATED VARIABLES ----------------------- GsOT WorldOT[2]; /* Sets the header for the Ordering Table to be an array of two elements, thus we are creating two headers. The reason for needing two is because we are using the Double Buffering technique to display our sprite. We need one Ordering table to display the on screen sprite, and another to draw correctly to the off screen area. Thus we need one header for each of our two ordering tables */ GsOT_TAG OTTags[2][1<>3)&0x01) { // If the image does have a CLUT then it too is also loaded into the Frame Buffer rect.x = tim_info.cx; // x position in Frame Buffer rect.y = tim_info.cy; // y position in Frame Buffer rect.w = tim_info.cw; // width of the CLUT rect.h = tim_info.ch; // height of the CLUT LoadImage(&rect, tim_info.clut); // Loads all of the above into the Frame Buffer } /* The following 'switch' statement checks to see what type of Sprite is in the TIM file, be it 4 bit, 8 bit, or 16 bit, and sets the sprite structure accordingly */ switch(tim_info.pmode) { // If the image is 4 bit with a CLUT case 0x08: sprite.attribute = 0x00000000; sprite.w = tim_info.pw*4; sprite.tpage = GetTPage(0,0,tim_info.px,tim_info.py); break; // Statement to break from the switch statement // If the image is 8 bit with a CLUT case 0x09: sprite.attribute = 0x01000000; sprite.w = tim_info.pw*2; sprite.tpage = GetTPage(1,0,tim_info.px,tim_info.py); break; // If the image is 16 bit default: sprite.attribute = 0x02000000; sprite.w = tim_info.pw; sprite.tpage = GetTPage(2,0,tim_info.px,tim_info.py); break; } /* The following lines are a continuation of the above sprite structure statements, but these are not dependent on the type of sprite that is being displayed, they work for all sprites, unlike the above */ if(tim_info.pmode==0x02) // If loop to check if the sprite is 16 bit so it can center it properly { sprite.x = ((SCREEN_WIDTH/2)-(tim_info.pw/2)); // Sets the x screen position of the sprite } else { sprite.x = ((SCREEN_WIDTH/2)-(tim_info.pw)); // Sets the x screen position of the sprite } sprite.y = ((SCREEN_HEIGHT/2)-(tim_info.ph/2)); // Sets the y screen position of the sprite sprite.h = tim_info.ph; // Sets the height of the sprite on screen sprite.u = 0; // Sets the texture page offset of the sprite along the x axis sprite.v = 0; // Sets the texture page offset of the sprite along the y axis sprite.cx = tim_info.cx; // Sets the x position of the CLUT, if any sprite.cy = tim_info.cy; // Sets the y position of the CLUT, if any sprite.r = 128; // Used to apply brightness to the sprite, 128 is normal sprite.g = 128; // Used to apply brightness to the sprite, 128 is normal sprite.b = 128; // Used to apply brightness to the sprite, 128 is normal sprite.mx = sprite.w/2; // Sets the center point of the sprite for use with rotation etc sprite.my = sprite.h/2; // Sets the center point of the sprite for use with rotation etc sprite.scalex = 4096; // Sets sprite scaling to default, x axis sprite.scaley = 4096; // Sets sprite scaling to default, y axis sprite.rotate = 0; // Sets rotation to off DrawSync(0); // Waits for the LoadImage() function to finish before continuing printf("Hello Anna!"); /* Sends confirmation to the PC monitor when the sprite has been loaded */ } // --------------------------------------------------------------------------- // ----------------------- Pad Reading Function ------------------------------ static u_long ReadPads(long id) { // This function reads the pads and returns the current pad value return(~(*(pad1Buff+3) | *(pad1Buff+2)<<8 | *(pad2Buff+3)<<16 | *(pad2Buff+2)<<24)); } // --------------------------------------------------------------------------- static long CheckPads() { // This checks the status of the pads to see if a button has been pressed u_long padd = ReadPads(1); /* The following 'if' loop checks to see if the select button has been pressed and if it has, the value 99 is returned to main() where the call to this fuction was made */ if(padd & PADselect) { return(99); } }