Path: chuka.playstation.co.uk!news From: ScoTT Campbell Newsgroups: scee.yaroze.programming.2d_graphics Subject: Re: pmode in GsIMAGE Date: Sun, 28 Feb 1999 01:48:52 +0000 Organization: PlayStation Net Yaroze (SCEE) Lines: 154 Message-ID: <36D8A084.2A4495C4@escotia.freeserve.co.uk> References: <7ba63i$9po27@chuka.playstation.co.uk> NNTP-Posting-Host: modem-115.astelin.dialup.pol.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.5 [en] (Win95; I) X-Accept-Language: en I've pasted the function I use to initialise sprites below. There's even a couple of comments in it! It sets up a sprite regardless of position in the frame buffer too. ie Sprite doesn't need to be on a TP edge.(Can't cross TPs though) You could do some of the testing a bit quicker though. ScoTT void InitSprite(GsSPRITE* spritePtr, unsigned long int spriteAddress, int xPosition, int yPosition) { RECT rect; GsIMAGE timData; // Get info at spriteAddress and put into timData GsGetTimInfo((unsigned long*)(spriteAddress+4), &timData); // Load sprite into frame buffer rect.x = timData.px; rect.y = timData.py; rect.w = timData.pw; rect.h = timData.ph; LoadImage(&rect, timData.pixel); // Assign values to the sprite handler spritePtr->attribute = (unsigned long int) (timData.pmode << 24); // Set sprite to correct display mode spritePtr->attribute &= 0x03000000; // Set all other attribute bits to zero /* Set the width according to the colour mode */ /* And load CLUT if neccessary */ if(spritePtr->attribute & 0x01000000) { spritePtr->w = (timData.pw * 2); // 8-bit clut // Load sprites CLUT into frame buffer rect.x = timData.cx; rect.y = timData.cy; rect.w = timData.cw; rect.h = timData.ch; LoadImage(&rect, timData.clut); spritePtr->cx = timData.cx; spritePtr->cy = timData.cy; spritePtr->tpage = GetTPage(1, 0, (64 * (timData.px / 64)), (256 * (timData.py / 256))); spritePtr->u = (timData.px % 64) * 2; spritePtr->v = timData.py % 256; } else if(spritePtr->attribute & 0x02000000) { spritePtr->w = (timData.pw); // 15-bit direct spritePtr->tpage = GetTPage(2, 0, (64 * (timData.px / 64)), (256 * (timData.py / 256))); spritePtr->u = timData.px % 64; spritePtr->v = timData.py % 256; } else { spritePtr->w = (timData.pw * 4); // 4-bit clut // Load sprites CLUT into frame buffer rect.x = timData.cx; rect.y = timData.cy; rect.w = timData.cw; rect.h = timData.ch; LoadImage(&rect, timData.clut); spritePtr->cx = timData.cx; spritePtr->cy = timData.cy; spritePtr->tpage = GetTPage(0, 0, (64 * (timData.px / 64)), (256 * (timData.py / 256))); spritePtr->u = (timData.px % 64) * 4; spritePtr->v = timData.py % 256; } spritePtr->h = (timData.ph); spritePtr->mx = spritePtr->w/2; spritePtr->my = spritePtr->h/2; spritePtr->x = xPosition; spritePtr->y = yPosition; spritePtr->r = 128; spritePtr->g = 128; spritePtr->b = 128; spritePtr->scalex = ONE; spritePtr->scaley = ONE; spritePtr->rotate = 0; DrawSync(0); }/* InitSprite */ Rikki Prince wrote: > I'm currently trying to write a function which will set up a sprite, just by > passing as few as possible parameters i.e. only the absolutely needed ones > are passed: TIM address, pointer to sprite etc. However, one thing that I > cannot currently get to work is getting the function to work out within > itself whether the TIM is 4bit CLUT, 8bit CLUT or otherwise. From the look > of the GsIMAGE structure in the library reference manual, I should be able > to read the pmode member and work out whether it is 4bit, 8 bit or > otherwise. However, when I put this in a switch statement, it doesn't work. > I've also tried it in an if/else if/else setup, and it still doesn't work. > I've just realised I should have put this earlier in the message, but the > problem I'm having is (constructing sentences and messages!! lol) trying to > set the width of the sprite in the GsSPRITE structure, as when the TIM is > 4bit, you need to *4, and when it's 8bit you need to *2 (something I picked > up from the Ira Rainey tutorial). As this is going to be a function I'll > need to use for different TIMs, and therefore not specific, I need it to > work out for itself whether the TIM is 4/8/16 bit etc. I've got it partly > working, by putting in if((tim.pmode>>3)&0x01) sprite->w=tim.pw*2; the > 'if' part of which I took from the texture load in Peter Passmore's 3d > tutorial, but I believe (well, guess) this bit manipulation tests whether > it's one of 8 or 4 bit, not either individually, which is what I want! > > Basically in conclusion, I need some help on how I can test to see if the > sprite is 4bit/8bit/otherwise, so I can set the width accordingly, something > which seems not to work normally, and only with bits shifts and clever > tricky stuff which the 286 in me 'ead don't seem to be able to cope with. > > Thanks in advance to anyone who can decipher what I've said in the preceding > message, and decides to help this poor little beginner :-) > > Rikki > > PS here's my switch statement which doesn't work, if anyone is interested. > > switch (tim.pmode) > { > case 0 :sprite->w=tim.pw*4; /* If sprite is 4 bit, make width 4 times > bigger */ > break; > case 1 :sprite->w=tim.pw*2; /* If sprite is 8 bit, make width 2 times > bigger */ > break; > default :sprite->w=tim.pw*2; /* Else set it to width got from tim info */ > break; > }