/* ============================================================================= File: SPRITE02.C Author: Radouan Khechane (rad@cyberdude.com) Date: 21st November 1998 Description: Sprite manipulation on the Net Yaroze PlayStation Copyright (c) 1998 by Radouan Khechane. ============================================================================= */ /* ==================== I N C L U D E S ==================== */ #include // PlayStation library #include "pad.h" // joypad header file /* ==================== D E F I N E S ==================== */ #define OT_LENGTH (1) // length of Ordering Table #define SPRITE_MAX (1) // number of sprites #define SCREEN_WIDTH (320) // screen x resolution #define SCREEN_HEIGHT (240) // screen y resolution #define SPRITE_ADDR (0x80090000) // location of TIM in main memory /* ==================== G L O B A L S ==================== */ GsOT OT_Header[2]; // Ordering Table Headers GsOT_TAG OT_Tag[2][1<x = x; sprite->y = y; switch (image.pmode) // check pixel mode { case 0x08 : // 4bit CLUT sprite->attribute = 0x00000000; sprite->w = image.pw * 4; sprite->tpage = GetTPage(0, 0, image.px, image.py); break; case 0x09 : // 8bit CLUT sprite->attribute = 0x01000000; sprite->w = image.pw * 2; sprite->tpage = GetTPage(1, 0, image.px, image.py); break; default : // 16bit DIRECT sprite->attribute = 0x02000000; sprite->w = image.pw; sprite->tpage = GetTPage(2, 0, image.px, image.py); } // sprite height sprite->h = image.ph; // texture page offset coordinates sprite->u = sprite->v = 0; // CLUT location sprite->cx = image.cx; sprite->cy = image.cy; // RGB brightness of sprite sprite->r = sprite->g = sprite->b = 128; // sprite origin (used for scaling and rotation) sprite->mx = sprite->w / 2; // centre of sprite sprite->my = sprite->h / 2; // centre of sprite // sprite scale (ONE = 4097) sprite->scalex = sprite->scaley = ONE; // original size // sprite rotation (ONE = 4097 = 1 degree) sprite->rotate = 0; // original orientation } /* ================ GetPadInput() read and process any pad input ================ */ void GetPadInput (void) { // read status of controller pad 1 PADstatus = PadRead(1); // move if (PADstatus & PADleft) sprite.x--; // move sprite left if (PADstatus & PADright) sprite.x++; // move sprite right if (PADstatus & PADup) sprite.y--; // move sprite up if (PADstatus & PADdown) sprite.y++; // move sprite down // scale // triangle increases the y scale of the sprite if (PADstatus & PADtriangle) sprite.scaley += 256; // cross decreases the y scale of the sprite if (PADstatus & PADcross) sprite.scaley -= 256; // circle increases the y scale of the sprite if (PADstatus & PADcircle) sprite.scalex += 256; // square decreases the y scale of the sprite if (PADstatus & PADsquare) sprite.scalex -= 256; // rotate // L1 rotates the sprite anti-clockwise by one degree if (PADstatus & PADL1) sprite.rotate -= ONE; // R1 rotates the sprite clockwise by one degree if (PADstatus & PADR1) sprite.rotate += ONE; } /* ================ DisplayInfo() ================ */ void DisplayInfo (void) { // output sprite info to print stream FntPrint(" sprite.x = %d sprite.scalex = %d\n", sprite.x, sprite.scalex); FntPrint(" sprite.y = %d sprite.scaley = %d\n", sprite.y, sprite.scaley); FntPrint(" sprite.rotate = %d (%d degrees)", sprite.rotate, sprite.rotate/ONE); // draw print stream contents FntFlush(-1); } /* ================ DrawScreen() ================ */ void DrawScreen (void) { int activeBuffer; // double buffer index // get drawing buffer number activeBuffer = GsGetActiveBuff(); // set drawing command storage address GsSetWorkBase((PACKET*)GpuPacketArea[activeBuffer]); // initialise odering table GsClearOt(0, 0, &OT_Header[activeBuffer]); // register sprite into the odering table GsSortSprite(&sprite, &OT_Header[activeBuffer], 0); // wait for completion of all drawing DrawSync(0); // wait for vertical retrace VSync(0); // swap double buffers (display and drawing buffer) GsSwapDispBuff(); // register clear (screen) command GsSortClear(0x0, 0x0, 0x0, &OT_Header[activeBuffer]); // register request to draw ordering table GsDrawOt(&OT_Header[activeBuffer]); }