Path: chuka.playstation.co.uk!news From: Steve Hunt Newsgroups: scee.yaroze.programming.2d_graphics Subject: 2d1.c Code Fix Date: Sun, 12 Apr 1998 14:43:11 +0100 Organization: PlayStation Net Yaroze (SCEE) Lines: 95 Message-ID: <3530C4EF.1754@itallnight.u-net.com> NNTP-Posting-Host: p71.nas2.is5.u-net.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 3.01Gold (Win95; I) Hi all, Well i've just got my Yaroze and I'm just finding my feet. I've downloaded some demo code and there seems to be a bug in the 2d1.c file. The bug is where it calcs the sprite offset(u,v) and tpage number. The function FindTopLeftOfTexturePage returns incorrect data if your TIM is not tpage x aligned, anyway here is the fixed and optimised code if anyone else has had problems. Enjoy, Steve // find coords wrt tpage top left points void FindTopLeftOfTexturePage(GsIMAGE* imageInfo, int* x, int* y, int* u, int* v, int widthCompression) { int testX, testY; int offset; testX = imageInfo->px; testY = imageInfo->py; *u = 0; *v = 0; // calc offset and alaign testX with texture page offset = testX & 63; testX -= offset; (*u) = offset * widthCompression; // calc offset and alaign testY with texture page offset = testY & 255; testY -= offset; (*v) = offset; *x = testX; *y = testY; } You also need to have this as well: void LinkSpriteToImageInfo (GsSPRITE* sprite, GsIMAGE* imageInfo) { int widthCompression; // on frame buffer int tPageType; int texturePageX, texturePageY, xOffset, yOffset; InitGsSprite(sprite); switch(imageInfo->pmode) { case 0: // 16-bit sprite->attribute |= SIXTEEN_BIT_MASK; widthCompression = 1; tPageType = 2; break; case 8: // 4-bit widthCompression = 4; tPageType = 0; sprite->cx = imageInfo->cx; sprite->cy = imageInfo->cy; break; case 9: // 8-bit sprite->attribute |= EIGHT_BIT_MASK; widthCompression = 2; tPageType = 1; sprite->cx = imageInfo->cx; sprite->cy = imageInfo->cy; break; default: printf("Only 4, 8 and 16 bit modes supported\n"); assert(FALSE); // other modes not supported } FindTopLeftOfTexturePage(imageInfo, &texturePageX, &texturePageY, &xOffset, &yOffset, widthCompression); sprite->tpage = GetTPage(tPageType, 0, texturePageX, texturePageY); sprite->w = imageInfo->pw * widthCompression; sprite->h = imageInfo->ph; sprite->u = xOffset; sprite->v = yOffset; }