/************************************************ * * * MULTIPLE SPRITES DISPLAY PROGRAM * * ================================== * * * * Written by Steven Lewis * * * * Downloaded from: * * http://www.netyaroze-europe.com/~slewis/ * * * * E-mail: * * stevenlewis@birminghamhome.freeserve.co.uk * * * ************************************************/ // -------------- // HEADER FILES // -------------- #include #include // ------------- // DEFINITIONS // ------------- #define SCREEN_WIDTH (320) // Width of the screen display #define SCREEN_HEIGHT (256) // Height of the screen display #define SPRITE_COUNT (2) // Number of sprites on screen at a time #define SPRITE1_ADDRESS (0x80094000) // Memory address of sprite 1 #define SPRITE2_ADDRESS (0x800a4000) // Memory address of sprite 2 // ------------------------- // SPRITE STRUCTURE POINTER // ------------------------- GsSPRITE sprite1,sprite2; // Two sprite structures declared, one for each sprite // -------------------------- // ORDERING TABLE VARIABLES // -------------------------- #define OT_LENGTH (1) // Sets the length of the Ordering Table GsOT WorldOT[2]; // Declares two Ordering Table headers, one for each graphics buffer GsOT_TAG OTTags[2][1<>3) & 0x01) { rect.x = tim_info.cx; // x position of CLUT rect.y = tim_info.cy; // y position of CLUT rect.w = tim_info.cw; // width of CLUT rect.h = tim_info.ch; // height of CLUT LoadImage(&rect,tim_info.clut); // Loads all of the above into the frame buffer } // Initialise the sprite structure:'switch' statement enables different TIM types to be used switch(tim_info.pmode) { // If the image is 4-bit case 0x08: sprite1.attribute = 0x00000000; // Sets the sprite attribute sprite1.w = tim_info.pw * 4; // Sets the width of the sprite sprite1.tpage = GetTPage(0,0,tim_info.px,tim_info.py); /* Gets texture page info */ break; // Breaks from the switch statement // If the image is 8-bit case 0x09: sprite1.attribute = 0x01000000; sprite1.w = tim_info.pw * 2; sprite1.tpage = GetTPage(0,0,tim_info.px,tim_info.py); break; // If the image is 16-bit default: sprite1.attribute = 0x02000000; sprite1.w = tim_info.pw; sprite1.tpage = GetTPage(0,0,tim_info.px,tim_info.py); break; } sprite1.x = 50; // x position on screen of the sprite sprite1.y = 100; // y position on screen of the sprite sprite1.h = tim_info.ph; // sprite height sprite1.u = 0; // Texture page offset - x axis sprite1.v = 0; // Texture page offset - y axis sprite1.cx = tim_info.cx; // CLUT x axis position sprite1.cy = tim_info.cy; // CLUT y axis position sprite1.r = 128; // Applies red tint to the sprite - 128 is normal sprite1.g = 128; // Applies green tint to the sprite - 128 is normal sprite1.b = 128; // Applies blue tint to the sprite - 128 is normal sprite1.mx = (sprite1.w/2); // Sets the center point of the image - x axis sprite1.my = (sprite1.h/2); // Sets the center point of the image - y axis sprite1.scalex = ONE; // Sets scale ratio to 1:1 on the x axis sprite1.scaley = ONE; // Sets scale ratio to 1:1 on the y axis sprite1.rotate = 0; // Sets sprite rotation to 'off' DrawSync(0); // Waits for all the above to finish before continuing } // ------------------------------ // INITIALISE SPRITE 2 FUNCTION // ------------------------------ void InitSprite2() { RECT rect; // Creates a retangular structure to put around the sprite GsIMAGE tim_info; // Creates a structure for storing all relevant TIM file information GsGetTimInfo((u_long *)(SPRITE2_ADDRESS+4),&tim_info); /* Gets all information required about the TIM file and stores it at the memory address of tim_info */ // Load sprite into the frame buffer rect.x = tim_info.px; // x position of sprite rect.y = tim_info.py; // y position of sprite rect.w = tim_info.pw; // width of sprite rect.h = tim_info.ph; // height of sprite LoadImage(&rect,tim_info.pixel); // Load all of the above into the frame buffer // Load CLUT into the frame buffer, if the TIM file has one if((tim_info.pmode>>3) & 0x01) { rect.x = tim_info.cx; // x position of CLUT rect.y = tim_info.cy; // y position of CLUT rect.w = tim_info.cw; // width of CLUT rect.h = tim_info.ch; // height of CLUT LoadImage(&rect,tim_info.clut); // Loads all of the above into the frame buffer } // Initialise the sprite structure:'switch' statement enables different TIM types to be used switch(tim_info.pmode) { // If the image is 4-bit case 0x08: sprite2.attribute = 0x00000000; // Sets the sprite attribute sprite2.w = tim_info.pw * 4; // Sets the width of the sprite sprite2.tpage = GetTPage(0,0,tim_info.px,tim_info.py); /* Gets texture page info */ break; // Breaks from the switch statement // If the image is 8-bit case 0x09: sprite2.attribute = 0x01000000; sprite2.w = tim_info.pw * 2; sprite2.tpage = GetTPage(0,0,tim_info.px,tim_info.py); break; // If the image is 16-bit default: sprite2.attribute = 0x02000000; sprite2.w = tim_info.pw; sprite2.tpage = GetTPage(0,0,tim_info.px,tim_info.py); break; } sprite2.x = 225; // x position on screen of the sprite sprite2.y = 85; // y position on screen of the sprite sprite2.h = tim_info.ph; // sprite height sprite2.u = 0; // Texture page offset - x axis sprite2.v = 0; // Texture page offset - y axis sprite2.cx = tim_info.cx; // CLUT x axis position sprite2.cy = tim_info.cy; // CLUT y axis position sprite2.r = 128; // Applies red tint to the sprite - 128 is normal sprite2.g = 128; // Applies green tint to the sprite - 128 is normal sprite2.b = 128; // Applies blue tint to the sprite - 128 is normal sprite2.mx = (sprite2.w/2); sprite2.my = (sprite2.h/2); sprite2.scalex = ONE; // Sets scale ratio to 1:1 on the x axis sprite2.scaley = ONE; // Sets scale ratio to 1:1 on the y axis sprite2.rotate = 0; // Sets sprite rotation to 'off' DrawSync(0); // Waits for all the above to finish before continuing } // ---------------------- // PAD READING FUNCTION // ---------------------- static u_long ReadPads(u_char port) // Reads what is being pressed on the joypads { return(~(*(padBuffer[port]+3)|*(padBuffer[port]+2)<<8)); } // ----------------------------- // PAD INITIALISATION FUNCTION // ----------------------------- static long InitPads() { pad1Check = ReadPads(PORT_ONE); // Calls the above function for joypad 1 pad2Check = ReadPads(PORT_TWO); // Calls the above function for joypad 2 if(pad1Check & PADselect) return(99); // Returns 99 to the main() function if 'select' is pressed }