Exemple #1
0
void Video::BlitTiled(Region rgn, const Sprite2D* img, bool anchor)
{
	int xrep = ( rgn.w + img->Width - 1 ) / img->Width;
	int yrep = ( rgn.h + img->Height - 1 ) / img->Height;
	for (int y = 0; y < yrep; y++) {
		for (int x = 0; x < xrep; x++) {
			BlitSprite(img, rgn.x + (x*img->Width),
				 rgn.y + (y*img->Height), anchor, &rgn);
		}
	}
}
	void ProcessSprites(){
	
		unsigned char i,bx,by,dx,dy,bt,x,y,tx=1,ty=1,wx,wy;
		unsigned int ramPtr,ssx,ssy;

		free_tile_index=0;	
		if(!spritesOn) return;
	
		for(i=0;i<MAX_SPRITES;i++){
			bx=sprites[i].x;

			if(bx!=(SCREEN_TILES_H*TILE_WIDTH)){
				//get tile's screen section offsets
				
				#if SCROLLING == 1
					ssx=sprites[i].x+Screen.scrollX;
					ssy=sprites[i].y+Screen.scrollY;
				#else
					ssx=sprites[i].x;
					ssy=sprites[i].y;
				#endif

				tx=1;
				ty=1;

				//get the BG tiles that are overlapped by the sprite
				bx=ssx>>3;
				dx=ssx&0x7;
				if(dx>0) tx++;

				//by=ssy>>3;
				//dy=ssy&0x7;
				by=ssy/TILE_HEIGHT;
				dy=ssy%TILE_HEIGHT;
				if(dy>0) ty++;			

				for(y=0;y<ty;y++){

					for(x=0;x<tx;x++){
						wy=by+y;
						wx=bx+x;

						//process X-Y wrapping
						if(wy>=(VRAM_TILES_V*2)){
							wy-=(VRAM_TILES_V*2);
						}else if(wy>=VRAM_TILES_V){
							wy-=VRAM_TILES_V;
						}
						if(wx>=VRAM_TILES_H)wx-=VRAM_TILES_H; //should always be 32

						ramPtr=(wy*VRAM_TILES_H)+wx;
						bt=vram[ramPtr];						

						if( (bt>=RAM_TILES_COUNT)  && (free_tile_index < RAM_TILES_COUNT) ){

							//tile is mapped to flash. Copy it to next free RAM tile.
							//if no ram free ignore tile
							ram_tiles_restore[free_tile_index].addr=ramPtr;
							ram_tiles_restore[free_tile_index].tileIndex=bt;
													
							CopyTileToRam(bt,free_tile_index);

							vram[ramPtr]=free_tile_index;
							bt=free_tile_index;
							free_tile_index++;										
						}
				
						if(bt<RAM_TILES_COUNT){
				

							BlitSprite(i,bt,(y<<8)+x,(dy<<8)+dx);

			
						}


					}//end for X
				}//end for Y
	
			}//	if(bx<(SCREEN_TILES_H*TILE_WIDTH))		
		}