/************************************************ * * * SINGLE SPRITE MOVEMENT 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 enables a 4, 8, or 16 bit sprite * * to be moved, rotated, and scaled in response * * to directional controls and button presses * * on the joypad in port 1 of the PlayStation * ************************************************/ // ------------------ // Header Files // ------------------ #include #include // ------------------ // Definitions // ------------------ #define SPRITE_COUNT (1+1) // Total number of sprites #define SCREEN_WIDTH (320) // Sets the width of the screen #define SCREEN_HEIGHT (256) // Sets the height of the screen #define SPRITE_ADDRESS (0x80094000) // Where sprite is located once downloaded // ------------------------------ // Sprite Structure Pointer // ------------------------------ GsSPRITE sprite; // ------------------------------ // Ordering Table Variables // ------------------------------ #define OT_LENGTH (1) GsOT WorldOT[2]; // Sets two Ordering Table headers GsOT_TAG OTTags[2][1<>3)&0x01) { rect.x = tim_info.cx; // x position in the frame buffer rect.y = tim_info.cy; // y position in the 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); // Load all the above into frame buffer } // Initialise Sprite Structure. Switch statement enable 4,8, or 16 bit sprites to be used switch(tim_info.pmode) { // 4 bit sprite case 0x08: sprite.attribute = 0x00000000; sprite.w = tim_info.pw*4; sprite.tpage = GetTPage( 0, 0, tim_info.px, tim_info.py); break; // 8 bit sprite case 0x09: sprite.attribute = 0x01000000; sprite.w = tim_info.pw*2; sprite.tpage = GetTPage( 1, 0, tim_info.px, tim_info.py); break; // 16 bit sprite default: sprite.attribute = 0x02000000; sprite.w = tim_info.pw; sprite.tpage = GetTPage( 2, 0, tim_info.px, tim_info.py); break; } sprite.x = 150; // Sprite display x axis position sprite.y = 100; // Sprite display y axis position sprite.h = tim_info.ph; // Sprite height sprite.u = 0; // Texture page offset x axis sprite.v = 0; // Texture page offset y axis sprite.cx = tim_info.cx; // CLUT x axis position sprite.cy = tim_info.cy; // CLUT y axis position sprite.r = 128; // Sets brightness, 128 = normal sprite.g = 128; // Sets brightness, 128 = normal sprite.b = 128; // Sets brightness, 128 = normal sprite.mx = (tim_info.pw/2); // Sets display point to center of sprite sprite.my = (tim_info.ph/2); // Sets display point to center of sprite sprite.scalex = ONE; // Sets scale ratio to 1:1 on the x axis sprite.scaley = ONE; // Sets scale ratio to 1:1 on the y axis sprite.rotate = 0; // Sets rotation to off DrawSync(0); // Waits until LoadImage() has finished before returning to main() printf ("Hello again Anna!"); // Prints text to PC screen when above is complete } // ------------------------- // Main Program Function // ------------------------- void main() { int i; // Variable to initialise the ordering tables // Set up the PlayStation graphics mode SetVideoMode(MODE_PAL); // Set PSX to use a PAL display GsInitGraph(SCREEN_WIDTH,SCREEN_HEIGHT,4,0,0); // Set up non-interlaced mode GsDefDispBuff(0,0,0,SCREEN_HEIGHT); // Define the Double Buffer positions ResetGraph(0); // Reset all drawing environments if(SCREEN_HEIGHT==256) GsDISPENV.screen.h = SCREEN_HEIGHT; // Fixes PAL display letterbox problem, nearly // Initialise the Ordering Tables for(i=0;i<2;i++) { WorldOT[i].length = OT_LENGTH; WorldOT[i].org = OTTags[i]; } // Run the InitSprite() function InitSprite(); // Set the address of the joypad buffers GetPadBuf(&pad1Buffer,&pad2Buffer); // Main program loop. Keep going until Select is pressed (99=Select) while((InitPads()) != 99) { // Playstation joypad routines if(padCheck & PADLup) { sprite.y -=5; // If UP pressed take 5 away from the sprites y value } if(padCheck & PADLdown) { sprite.y +=5; // If DOWN pressed add 5 to the sprites y value } if(padCheck & PADLleft) { sprite.x -=5; // If LEFT pressed take 5 away from the sprites x value } if(padCheck & PADLright) { sprite.x +=5; // If RIGHT pressed add 5 to the sprites x value } if(padCheck & PADRleft) { sprite.scalex -=20; // If SQUARE pressed take 20 away from the sprites x scale value } if(padCheck & PADRright) { sprite.scalex +=20; // If CIRCLE pressed add 20 to the sprites x scale value } if(padCheck & PADRup) { sprite.scaley -=20; // If TRIANGLE pressed take 20 away from sprites y scale value } if(padCheck & PADRdown) { sprite.scaley +=20; // If CROSS pressed add 20 to the sprites y scale value } if(padCheck & PADL1) { sprite.rotate -=ONE; /* If L1 is pressed take ONE(4096) away from sprites rotate value */ } if(padCheck & PADR1) { sprite.rotate +=ONE; /* If R1 is pressed add ONE(4096) to the sprites rotate value */ } activeBuffer = GsGetActiveBuff(); // Finds out which buffer is being used (active) GsSetWorkBase((PACKET *)GpuPacketArea[activeBuffer]); /* Initialise the space to draw Ordering table to */ GsClearOt( 0, 0, &WorldOT[activeBuffer]); // Clears OT ready to use GsSortSprite( &sprite, &WorldOT[activeBuffer], 0); // Draw sprite into the OT DrawSync(0); // Waits for drawing of other command to finish VSync(0); // Waits for the Vertical retrace on the TV to finish GsSwapDispBuff(); // Swaps the buffers around - active one now becomes drawn to GsSortClear(0,0,0,&WorldOT[activeBuffer]); // Sort the Ordering table GsDrawOt(&WorldOT[activeBuffer]); // Draw the OT into the active buffer } } // ----------------------- // ReadPads() function // ----------------------- static u_long ReadPads(long) // reads from the controllers { return (~(*(pad1Buffer+3) | *(pad1Buffer+2) << 8 | *(pad2Buffer+3) << 16 | *(pad2Buffer+2) << 24)); } // ------------------------------------ // Function to check the pads status // ------------------------------------ static long InitPads() { padCheck = ReadPads(1); if(padCheck & PADselect) return(99); // Sends the value 99 to the main program loop when Select is pressed }