⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wince_video.c

📁 这个是延伸mame的在wince平台下的游戏模拟器的代码
💻 C
📖 第 1 页 / 共 2 页
字号:

void adjustDisplay(void)
{

	float counterX, counterY, factorX, factorY;

	// sets orientation

	if( (visible_game_width <= visible_game_height && (GameConfig.vidOrientation == VIDORIENTATION_AUTO_90CW || GameConfig.vidOrientation == VIDORIENTATION_AUTO_90CCW) )
		 || GameConfig.vidOrientation == VIDORIENTATION_PORTRAIT )
	{
		VideoInfo.Rotation = ROTATION_0;
	}
	else
	{
		if( GameConfig.vidOrientation == VIDORIENTATION_AUTO_90CW || GameConfig.vidOrientation == VIDORIENTATION_LANDSCAPE_90CW )
		{
			VideoInfo.Rotation = ROTATION_CW90;
		}
		else
		{
			VideoInfo.Rotation = ROTATION_ACW90;
		}
	}

#ifndef OPENGL_BUILD

	// Retrieve video information and center screen
	
	BeginDraw();		// When BeginDraw is called, VideoInfo structure is filled.
	EndDraw();

	switch( GameConfig.vidScaling )
	{
		case SCALING_AUTO :
			if( visible_game_width > visible_game_height )
			{
				factorX = 1;
				factorY = ((float)visible_game_height / (float)visible_game_width);
			}
			else
			{
				factorX = ((float)visible_game_width / (float)visible_game_height);
				factorY = 1;
			}
			XRes = visible_game_width*4; counterX = (float)XRes;
			YRes = visible_game_height*4; counterY = (float)YRes;
			while( XRes > VideoInfo.xPixelsResolution || YRes > VideoInfo.yPixelsResolution )
			{
				counterX-=factorX;
				counterY-=factorY;
				XRes = (int)counterX;
				YRes = (int)counterY;
			}
			CreateARMBlitLineCode( visible_game_width, visible_game_height, XRes, YRes );
			break;

		case SCALING_NOSCALING :
			CreateARMBlitLineCode( visible_game_width, visible_game_height, visible_game_width, visible_game_height );
			break;

		case SCALING_ENTIRESCR :
			CreateARMBlitLineCode( visible_game_width, visible_game_height, VideoInfo.xPixelsResolution, VideoInfo.yPixelsResolution );
			break;

	}

	switch( GameConfig.vidFx )
	{
		case FX_NONE :
			BlitFunction = (BlitFunctionDef)BlitNormal;
			break;

		case FX_SCANLINES :
			BlitFunction = (BlitFunctionDef)BlitScanlines;
			break;

		case FX_STEPLINES :
			BlitFunction = (BlitFunctionDef)BlitSteplines;
			break;

	}

	// Center horizontally

	xPosCenter = 0;
	if( VideoInfo.xPixelsResolution >= XRes )
	{
		xPosCenter = (VideoInfo.xPixelsResolution - XRes) / 2;
	}
	if( VideoInfo.xPixelsResolution < visible_game_width && GameConfig.vidScaling == SCALING_NOSCALING )
	{
		visible_game_width_offset += ( visible_game_width - VideoInfo.xPixelsResolution ) / 2;
	}

	// Center vertically

	yPosCenter = 0;
	if( VideoInfo.yPixelsResolution >= YRes )
	{
		yPosCenter = (VideoInfo.yPixelsResolution - YRes) / 2;
	}
	if( VideoInfo.yPixelsResolution < visible_game_height && GameConfig.vidScaling == SCALING_NOSCALING )
	{
		visible_game_height_offset += ( visible_game_height - VideoInfo.yPixelsResolution ) / 2;
	}

#else

	adjustOpenGLview( visible_game_width, visible_game_height );

#endif

	// Rotate pad

	RotatePadMapping();

}


/* Create a display screen, or window, large enough to accomodate a bitmap */
/* of the given dimensions. Attributes are the ones defined in driver.h. */
/* Return a osd_bitmap pointer or 0 in case of error. */
struct osd_bitmap *osd_create_display(int width,int height,int attributes, int visible_width, int visible_height,
					                  int visible_width_offset, int visible_height_offset )
{
	int     i;
	game_width = width;
	game_height = height;

	if (attributes & VIDEO_TYPE_VECTOR) {
		visible_game_width = width;
		visible_game_height = height;
		visible_game_width_offset = 0;
		visible_game_height_offset = 0;
	} else {
		visible_game_width = visible_width;
		visible_game_height = visible_height;
		visible_game_width_offset = visible_width_offset;
		visible_game_height_offset = visible_height_offset;
	}

	if (Machine->orientation & ORIENTATION_SWAP_XY)
	{
		int temp;

		temp = game_width;
		game_width = game_height;
		game_height = temp;
		temp = visible_game_width;
		visible_game_width = visible_game_height;
		visible_game_height = temp;
		temp = visible_game_width_offset;
		visible_game_width_offset = visible_game_height_offset;
		visible_game_height_offset = temp;
	}

	if (Machine->orientation & ORIENTATION_FLIP_X)    /* offset by other side */
		visible_game_width_offset = game_width-visible_game_width-visible_game_width_offset;

	if (Machine->orientation & ORIENTATION_FLIP_Y)
		visible_game_height_offset = game_height-visible_game_height-visible_game_height_offset;
	
	adjustDisplay();

	scrbitmap = osd_new_bitmap(width,height,8);
	if (!scrbitmap) return 0;

	for (i = 0;i < 256;i++)
	{
		dirtycolor[i] = 1;
	}
	dirtypalette = 1;

    return scrbitmap;
}


static __inline void update_palette(void)
{
	int i;
	unsigned char *dirty=dirtycolor;

	for (i = 0;i < 256;i++)
	{
		if (dirty[i])
		{
			dirty[i] = 0;

			palette565[i] = (((current_palette[i][0] & 0xF8) << 8) |
							((current_palette[i][1] & 0xFC) << 3) |
							(current_palette[i][2] >> 3));

			palette565dark[i] = ((( (current_palette[i][0]>>1) & 0xF8) << 8) |
							(( (current_palette[i][1]>>1) & 0xFC) << 3) |
							( (current_palette[i][2]>>1) >> 3));

		}
	}
	dirtypalette = 0;

}	

void adjustSpeed()
{
	/* TODO: logical frameskip, by now it only waits for fast devices */

	long ticksForThisFrame;
	float addition;

	addition = ceil((((frameskip+1)*1000)/Machine->drv->frames_per_second));
	ticksForThisFrame = previousTickFrame + addition;
	if( ticksForThisFrame >= getTickts() )
	{
		while( ticksForThisFrame > getTickts() ){}
		if( frameskip > 0 )
			frameskip--;
	}

	previousTickFrame = getTickts();
	frameCount++;

	if( getTickts() >= TicksForOneSecond )	// If after one second is not reached the wanted fps, suppress one frame
	{
		if((frameCount < Machine->drv->frames_per_second) && frameskip < 10)
		{
			frameskip++;
		}
		TicksForOneSecond = getTickts() + 1000;
		frameCountSecond = frameCount;
		frameCount = 0;
	}

}


void osd_update_display(void)
{

	unsigned short *buffer_scr;
	unsigned short *buffer_scrLine;
	unsigned char *buffer_mem_reader;
	unsigned char *buffer_mem_initial = (unsigned char *)(scrbitmap->line[0]);
	int buffer_mem_offset = ((int)(scrbitmap->line[1] - scrbitmap->line[0]));
	int x, y;

	char chStr[20];

#ifdef OPENGL_BUILD

	unsigned short *texturePtr;
	unsigned char *bufferPtr;

	int tx, ty;

#endif

	adjustSpeed();

	/* Manage the palette */
	if (dirtypalette)
		update_palette();

#ifndef OPENGL_BUILD

	BeginDraw();

	buffer_scr = (unsigned short *)VideoInfo.pBitmap;
	buffer_scr += xPosCenter*VideoInfo.xIncrementation;
	buffer_scr += yPosCenter*VideoInfo.yIncrementation; 

	buffer_mem_initial += buffer_mem_offset*visible_game_height_offset;
	buffer_mem_initial += visible_game_width_offset;

	scanlineFlag = 0;

	for( y = 0; y < YRes; y++ )
	{
		buffer_mem_reader = buffer_mem_initial+(buffer_mem_offset*LinesToBlit[y]);
		buffer_scrLine = buffer_scr;

		BlitFunction( buffer_mem_reader, buffer_scrLine );

		buffer_scr+=VideoInfo.yIncrementation;
	}

	if( GameConfig.vidShowFPS )
	{
		sprintf(chStr, "fps: %d ", frameCountSecond );
		print( 10, VideoInfo.yPixelsResolution-20, chStr, VideoInfo.displayVGA );
	}

	EndDraw();

#else

	for( ty = 0; ty < yTextureCount; ty++ )
	{
		for( tx = 0; tx < xTextureCount; tx++ )
		{

			texturePtr = textureBitmap[ tx + (ty*xTextureCount) ];
			bufferPtr = buffer_mem_initial + ( (64*tx) + (buffer_mem_offset*(ty*64)) );

			for( y = 0; y < 64; y++ )
			{
				for( x = 0; x < 64; x++ )
				{
					texturePtr[ x + (y*64) ] = palette565[ bufferPtr[x] ];
				}
				bufferPtr+=buffer_mem_offset;
			}

		}
	}

	OpenGLrender();

#endif

}


// Blit modes

void BlitNormal( long *Source, long *Destination )
{
	ARMBlitLine( Source, Destination, &palette565 );
}

void BlitScanlines( long *Source, long *Destination )
{
	if( scanlineFlag == 0 )
	{
		ARMBlitLine( Source, Destination, &palette565 );
		scanlineFlag = 1;
	}
	else
	{
		ARMBlitLine( Source, Destination, &palette565dark );
		scanlineFlag = 0;
	}
}

void BlitSteplines( long *Source, long *Destination )
{
	if( scanlineFlag == 0 )
	{
		ARMBlitLine( Source, Destination, &palette565 );
		scanlineFlag = 1;
	}
	else
	{
		scanlineFlag = 0;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -