Path: chuka.playstation.co.uk!news From: Alex Herbert Newsgroups: scee.yaroze.beginners,scee.yaroze.programming.codewarrior,scee.yaroze.programming.2d_graphics Subject: Re: Still strugglin' with the basics: broken sprite code (long) Date: Wed, 15 Jul 1998 17:53:01 +0000 Organization: PlayStation Net Yaroze (SCEE) Lines: 230 Message-ID: <35ACDE6C.954014D4@ndirect.co.uk> References: <35AC71D4.AA79EB4A@easynet.co.uk> Reply-To: aherbert@ndirect.co.uk NNTP-Posting-Host: dialin2-14.ndirect.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.04 [en] (Win95; I) Xref: chuka.playstation.co.uk scee.yaroze.beginners:409 scee.yaroze.programming.codewarrior:298 scee.yaroze.programming.2d_graphics:434 Philip Gooch wrote: > Hello everyone > > You know how it is when you use other people's code to do the basics and > it works fine so you don't try and tinker with it? > > Except when you do because you want to do things slightly differently, > and then you totally screw it up but can't see what's going wrong? > > Or you decide to try and write something from scratch, having fully > understood the examples you've copied from? > > Well, I'm having a nightmare. I'm just trying to display a sprite, but > I'm taking stuff from the tuto0.c sample Sony code so that I can load > images into the frame buffer in one function, and link them to a sprite > in another. > > What happens is that when I run the program I get the Yaroze boot-up > screen, then the screen flashes briefly before returning to the boot-up > screen. What's weird is that in Codewarrior, if I change my data address > in Linker Settings from the default 0x00000000 to 0x80140000, I get a > very large (700K) executable, except this time the screen goes black and > I get a line of garbage along the bottom. > > Would someone be kind enough to have a look at my source code and tell > me what I'm doing wrong. I was up till 4.30 this morning trying to > figure it out. The TIM file is only about 2K (96*48 pixels) > > Thanks > > Phil > > Here it is: > (my batch file is > local dload redcars.tim 80100000 > local load ny.pxe > go) > > #include > #include "asssert.h" > > #define PLAYER_TIM 0x80100000 > #define SCREEN_WIDTH 512 > #define SCREEN_HEIGHT 256 > #define MAX_SPRITES 1 > #define OT_LENGTH 1 > > // globals > > GsIMAGE gPlayerTextureInfo; > GsSPRITE gPlayerSprite; > GsOT gOrderTable[2]; > PACKET GpuPacketArea[2][MAX_SPRITES*24]; > > // prototypes > void InitGraphics(); > void LoadTimData(u_long address, GsIMAGE *textureInfo); > void LinkSpritetoTimData(GsSPRITE *sprite, GsIMAGE *textureInfo); > void InitSprite(GsSPRITE *sprite); > > void main() > { > > int activeBuffer; > > InitGraphics(); > > while (1) > { > activeBuffer = GsGetActiveBuff(); > > GsSetWorkBase((PACKET *)GpuPacketArea[activeBuffer]); > > GsClearOt(0, 0, &gOrderTable[activeBuffer]); > > GsSortFastSprite(&gPlayerSprite, &gOrderTable[activeBuffer], 0); > > DrawSync(0); > > VSync(0); > > GsSwapDispBuff(); > > GsSortClear(34,34,34, &gOrderTable[activeBuffer]); > > GsDrawOt(&gOrderTable[activeBuffer]); > } > > } > > void InitGraphics() > { > GsOT_TAG OTTags[2][1< > GsInitGraph(SCREEN_WIDTH, SCREEN_HEIGHT, 4, 0, 0); > > GsDefDispBuff(0, 0, 0, SCREEN_HEIGHT); > > SetVideoMode( MODE_PAL ); > > gOrderTable[0].length = OT_LENGTH; > gOrderTable[0].org = OTTags[0]; > gOrderTable[1].length = OT_LENGTH; > gOrderTable[1].org = OTTags[0]; > > LoadTimData(PLAYER_TIM, &gPlayerTextureInfo); > LinkSpritetoTimData(&gPlayerSprite, &gPlayerTextureInfo); > > } > > void LoadTimData(u_long address, GsIMAGE *textureInfo) > { > > RECT rect; > GsGetTimInfo( (u_long *)(address + 4), textureInfo); > > // Load image into frame buffer > rect.x = textureInfo->px; > rect.y = textureInfo->py; > rect.w = textureInfo->pw; // width in 16-bit words (NOT pixels) > rect.h = textureInfo->ph; > LoadImage(&rect, textureInfo->pixel); > > /*printf("image x %d\n", textureInfo->px); > printf("image y %d\n", textureInfo->py); > printf("image w %d\n", textureInfo->pw); > printf("image h %d\n", textureInfo->ph);*/ > > /* pmode takes these values (binary): > 0000 4 bit, no clut > 1000 4 bit, clut > 0001 8 bit, no clut > 1001 8 bit, clut > 0010 16 bit > 0011 24 bit > */ > > // Load the CLUT into the frame buffer, if it has one > if (textureInfo->pmode & 0x8) > { > rect.x = textureInfo->cx; // x pos in frame buffer > rect.y = textureInfo->cy; // y pos in frame buffer > rect.w = textureInfo->cw; // width of CLUT > rect.h = textureInfo->ch; // height of CLUT > LoadImage(&rect, textureInfo->clut); // load data into frame buffer > > /*printf("clut x %d\n", textureInfo->cx); > printf("clut y %d\n", textureInfo->cy); > printf("clut w %d\n", textureInfo->cw); > printf("clut h %d\n", textureInfo->ch);*/ > } > > DrawSync(0); > } > > void LinkSpritetoTimData(GsSPRITE *sprite, GsIMAGE *textureInfo) > { > int pixelsPerWord, texturePage; > > InitSprite(sprite); > > // Get texture page ID > texturePage = GetTPage(textureInfo->pmode & 0x7, 0, textureInfo->px, > textureInfo->py); > > // Work out bit depth (number of pixels per word) > switch (textureInfo->pmode & 0x7) > { > case 0: > pixelsPerWord = 4; // 4 bit > break; > case 1: > pixelsPerWord = 2; // 8 bit > break; > case 2: > pixelsPerWord = 1; // 16 bit > default: > // unexpected pmode value > pixelsPerWord = 0; > printf("Unexpected pmode value\n"); > assert(0); > break; > } > > sprite->attribute = 0 + (1<<6) + (textureInfo->pmode & 0x7) << 24 + > (1<<30) + (1<<31); > sprite->tpage = texturePage; > sprite->cx = textureInfo->cx; // CLUT x axis position > sprite->cy = textureInfo->cy; // CLUT y axis positio > } > > // give sprite default values > void InitSprite(GsSPRITE *sprite) > { > sprite->attribute = 0; > sprite->x = 32; > sprite->y = 32; > sprite->w = 32; // don't want to display whole TIM, just the > first 32*48 segment > sprite->h = 48; > sprite->tpage = 0; > sprite->u = 0; > sprite->v = 0; > sprite->cx = 0; > sprite->cy = 0; > sprite->r = 128; > sprite->g = 128; > sprite->b = 128; > sprite->mx = 0; > sprite->my = 0; > sprite->scalex = ONE; // ONE = 4096 > sprite->scaley = ONE; > sprite->rotate = 0; > } Hi Philip. I've just posted you in the freetalk newsgroup. Wish I'd seen this first. Well, I've had a quick scan over the code, and one thing which jumped out at me was your GsOTTAGs. Try making them global. Hope that helps. Herbs