// Filename : STOSSPR.C // Coded by : Scott Evans // Created/Modified : 16/2/98, 19/2/98 // Description : Contains functions to handle STOS sprites #include // Function : Load4bitCLUT() // Coded by : Scott Evans // Created/Modified : 18/9/97 // Description : Loads all CLUTs in sprite bank into VRAM // Parameters : hdr - address of sprite bank header // x,y - location in frame buffer to load CLUTs // Returns : Nothing // Notes : Does not wait for loading to finish void Load4bitCLUT(SprHeader *hdr,u_word x,u_word y) { u_byte i; RECT r; setRECT(&r,x,y,16,1); for(i=0;inpal;i++) { LoadImage(&r,(u_long *)((u_byte *)_GetCLUT(hdr)+_4bitCLUTSIZE*i)); r.y++; } } // Function : LoadSprites() // Coded by : Scott Evans // Created/Modified : 18/9/97 // Description : Loads all sprite image data into VRAM // Parameters : pblk - address of sprite parameter block to start from // n - number of sprites to load // tx,ty - location in frame buffer to load sprites // info - address of buffer to store tpage offsets and width/height // flag - if 1 reset x and y (tpage offsets) // Returns : The number of sprites loaded // Notes : Does not wait for loading to finish u_word LoadSprites(SprPblk *pblk,u_word n,u_word tx,u_word ty,SprImgInfo *info,u_byte flag) { static u_word x=0,y=0; u_word i; u_byte sprw,sprh; static u_byte maxh=0; RECT r; if(flag) x=y=maxh=0; // Try and load n sprites into a texture page for(i=0;iw; maxh=((sprh=pblk->h)>maxh ? sprh : maxh); info->w=sprw; info->h=sprh; // Fit in as many sprites per row as possible if(!(x+sprw>TPAGE_WIDTH ? (y+maxh>TPAGE_HEIGHT ? 0 : (x=0,y+=maxh)) : 1)) { maxh=x=y=0; break; } // Store offsets info->u=x; info->v=y; // Image data to frame buffer setRECT(&r,tx+(x>>2),ty+y,sprw>>2,sprh); x+=sprw; LoadImage(&r,(u_long *)_GetSprImgData(pblk)); // Save CLUT y position info->clut_y=pblk->CLUTid; } // Return number of sprites loaded into texture page return(i); } // Function : InitSpriteData() // Coded by : Scott Evans // Created/Modified : 19/2/98 // Description : Initialise the sprite data // Parameters : h - address of sprite bank header // i - pointer to structure to store information // flag - reset texture page offsets // Returns : Total number of sprites in bank // Notes : None u_word InitSpriteData(SprHeader *h,SPRITE_DATA_INFO *i,u_byte flag) { SprPblk *pblock=_GetSprPblks(h); u_word nospr=_GetNoSpr(h),n; // Make sure CLUT x coordinate is on correct boundary i->cx=((i->cx>>4)<<4); // Load all the CLUTs Load4bitCLUT(h,i->cx,i->cy); DrawSync(0); // Make sure texture page is on correct boundary i->tx=(i->tx>>6)<<6; i->ty=(i->ty>>8)<<8; // Load sprites n=LoadSprites(pblock,nospr,i->tx,i->ty,i->offsets,flag); DrawSync(0); // Return the actual number of sprites loaded i->n=n; // Calculate texture page ID i->tpage=GetTPage(TPAGE_4BIT,0,i->tx,i->ty); // Return number of sprites in sprite bank #ifdef DEBUG_INFO sprintf(fm_string,"Loaded %d sprites out of %d\n",n,nospr); PrintFM(fm_string); #endif return(nospr); }