// *********************************************************************************** // Programs written by R.Swan - rs108@mdx.ac.uk - www.netyaroze-europe.com/~middex2 // Code for sprite demonstration // The code for handling the joypad (InitialisePad and ReadPad) are in PAD.C // The #defines for analysing the joypad output are in PAD.H // *********************************************************************************** // *********************************************************************************** // Preprocessor functions // *********************************************************************************** // **** include files #include // include standard Yaroze lib #include "pad.c" // normally the joypad handling // routine would be compiled as a // seperate .o file, but to make // the makefile simpler the code is // included here. (As it never changes // there should be no problem) // **** definitions #define TIM_ADDRESSB (0x80090000) // location of TIM in main memory #define TIM_ADDRESSA (0x80090240) // location of TIM in main memory #define TIM_ADDRESSR (0x80090480) // location of TIM in main memory #define TIM_ADDRESSY (0x800906c0) // location of TIM in main memory #define TIM_CURSOR (0x80091000) // location of TIM in main memory #define SCREEN_WIDTH (320) #define SCREEN_HEIGHT (240) #define OTABLE_LENGTH (1) // define length of OTable #define MAX_PACKETS (128000) // guess at length for scratchpad // **** create global variables, structures, headers and arrays (mostly system stuff) static GsOT OTable_Header[2]; // Header files holding OTable info static GsOT_TAG OTable_Array[2][1<x = tX; // set sprites screen coordinates tSprite->y = tY; // based on values passed if (tTim.pmode& 0x01) { tSprite->attribute = (1<<24); // set up for 256 colour sprite tSprite->w = tTim.pw*2; tCLUT = 1; } else { tSprite->attribute = 0; // set up for 16 colour sprite tSprite->w = tTim.pw*4; tCLUT = 0; }; tSprite->h = tTim.ph; tTexturePageX = (tTim.px/64) *64; // calculate texture page tTexturePageY = (tTim.py/256) *256; tTexturePageXOffset = tTim.px % 64; tTexturePageYOffset = tTim.py % 256; tSprite->tpage = GetTPage(tCLUT, 0, tTim.px, tTim.py); // calculate correct texture page tSprite->u = tTexturePageXOffset*4; // offset for sprite from left of tpage tSprite->v = tTexturePageYOffset; // offset for sprite from top of tpage tSprite->cx = tTim.cx; // set sprite to use correct CLUT tSprite->cy = tTim.cy; tSprite->r = tSprite->g = tSprite->b = 128; // make sure the sprite is set to // normal colour intensity tSprite->mx = tSprite->w/2; // set handle of sprite to the center tSprite->my = tSprite->h/2; // (this does not need to be done if // you would rather move the objects // by their top left corner) tSprite->scalex = tSprite->scaley = ONE; // make sure the sprite isn't scaled tSprite->rotate = 0; // make sure its pointing up }; // *********************************************************************************** // Screen drawing routine. Sets up ordering table, and holds commands for which // sprites to b drawn, etc. // *********************************************************************************** // **** Draw all the screen void RenderWorld() { u_long currentBuffer = GsGetActiveBuff(); // determine which buffer is to be used u_long tTemp1; GsClearOt(0, 0, &OTable_Header[currentBuffer]); // clear out OTable sorting info GsSetWorkBase((PACKET*)Packet_Memory[currentBuffer]); // set scratchpad area for the OT for (tTemp1 = 0; tTemp1<20; tTemp1++) { GsSortFastSprite(&Letters[5][tTemp1], &OTable_Header[currentBuffer], 0); GsSortSprite(&Letters[0][tTemp1], &OTable_Header[currentBuffer], 0); GsSortSprite(&Letters[1][tTemp1], &OTable_Header[currentBuffer], 0); GsSortSprite(&Letters[2][tTemp1], &OTable_Header[currentBuffer], 0); GsSortSprite(&Letters[3][tTemp1], &OTable_Header[currentBuffer], 0); GsSortSprite(&Letters[4][tTemp1], &OTable_Header[currentBuffer], 0); // send request to draw sprite to the // ordering table }; // **** REAL DRAWING STUFF DrawSync(0); // wait for completion of all output ScreenDrawTiming = VSync(0); // wait for blank and time it GsSwapDispBuff(); // swap buffer information GsSortClear(0, 0, 0, &OTable_Header[currentBuffer]);// send a request to clear the screen // to the ordering table GsDrawOt(&OTable_Header[currentBuffer]); // draw commands in queue FntFlush(FntOne); // output any text onto the screen }; void UpdateWorld() { u_long tTemp1, tTemp2, tTemp3; if (PauseMode == 1) tTemp3 = 5; else tTemp3 = 0; for (tTemp1 = tTemp3; tTemp1<6; tTemp1++) { for (tTemp2 = 19; tTemp2>0; tTemp2--) { Letters[tTemp1][tTemp2].x = Letters[tTemp1][tTemp2-1].x; Letters[tTemp1][tTemp2].y = Letters[tTemp1][tTemp2-1].y; Letters[tTemp1][tTemp2].rotate = Letters[tTemp1][tTemp2-1].rotate; Letters[tTemp1][tTemp2].scalex = Letters[tTemp1][tTemp2-1].scalex; Letters[tTemp1][tTemp2].scaley = Letters[tTemp1][tTemp2-1].scaley; Letters[tTemp1][tTemp2].r = Letters[tTemp1][tTemp2-1].r; Letters[tTemp1][tTemp2].g = Letters[tTemp1][tTemp2-1].g; Letters[tTemp1][tTemp2].b = Letters[tTemp1][tTemp2-1].b; }; }; if (PauseMode == 0) { for (tTemp1 = 0; tTemp1<5; tTemp1++) { Letters[tTemp1][0].x += XY[tTemp1][0]; Letters[tTemp1][0].y += XY[tTemp1][1]; Letters[tTemp1][0].rotate = Rotation[tTemp1][0]; Letters[tTemp1][0].scalex = Scaling[tTemp1][0]; Letters[tTemp1][0].scaley = Scaling[tTemp1][1]; Letters[tTemp1][0].r = RGB[tTemp1][0]; Letters[tTemp1][0].g = RGB[tTemp1][1]; Letters[tTemp1][0].b = RGB[tTemp1][2]; Rotation[tTemp1][0] = (Rotation[tTemp1][0] + Rotation[tTemp1][1]) % (4096 * 360); Scaling[tTemp1][0] += Scaling[tTemp1][2]; Scaling[tTemp1][1] += Scaling[tTemp1][3]; RGB[tTemp1][0] += RGB[tTemp1][3]; RGB[tTemp1][1] += RGB[tTemp1][4]; RGB[tTemp1][2] += RGB[tTemp1][5]; if ((Letters[tTemp1][0].x < 10) || (Letters[tTemp1][0].x > 310)) { XY[tTemp1][0] = -XY[tTemp1][0]; }; if ((Letters[tTemp1][0].y < 10) || (Letters[tTemp1][0].y > 230)) { XY[tTemp1][1] = -XY[tTemp1][1]; }; if ((Scaling[tTemp1][0] < 1024) || (Scaling[tTemp1][0] > 12000)) { Scaling[tTemp1][2] = -Scaling[tTemp1][2]; }; if ((Scaling[tTemp1][1] < 1024) || (Scaling[tTemp1][1] > 12000)) { Scaling[tTemp1][3] = -Scaling[tTemp1][3]; }; if ((RGB[tTemp1][0] < 10) || (RGB[tTemp1][0] > 127)) { RGB[tTemp1][3] = -RGB[tTemp1][3]; }; if ((RGB[tTemp1][1] < 10) || (RGB[tTemp1][1] > 127)) { RGB[tTemp1][4] = -RGB[tTemp1][4]; }; if ((RGB[tTemp1][2] < 10) || (RGB[tTemp1][2] > 127)) { RGB[tTemp1][5] = -RGB[tTemp1][5]; }; }; }; }; void ReadJoyPad() { u_long PAD; // to hold status of joypad PAD = PadRead(); // read joypad status if (PAD != 0) {InitialPause = 0; PauseMode = 0;}; if (PAD& PADselect) GameRunning = 0; if (PAD& PADcross) PauseMode = 1; else { if (InitialPause != 1) PauseMode = 0; }; if (PAD& PADleft) Letters[5][0].x -= 3; if (PAD& PADright) Letters[5][0].x += 3; if (PAD& PADup) Letters[5][0].y -= 3; if (PAD& PADdown) Letters[5][0].y += 3; };