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

📄 vidsys.cpp

📁 这个是延伸mame的在wince平台下的游戏模拟器的代码
💻 CPP
字号:
/* PocketCultMAME - MAME Emulator for PocketPC
   (c) Copyright 2006 Manuel Castrillo Mart韓ez

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#define WIN32_LEAN_AND_MEAN		// Exclude rarely-used stuff from Windows headers
#include <windows.h>
#include <gx.h>

#include "vidsys.h"

#ifdef OPENGL_BUILD
#include "wince_opengl.h"
#endif

#ifdef DIRECTDRAW_BUILD
#include "wince_ddraw.h"
#endif

RawFrameBufferInfo g_RFBinfo;
GXDisplayProperties g_gxdp;

// Intel 2700G registers

#define GSCTRL	(0x3FE2000/sizeof(DWORD))
#define GDRCTRL	(0x3FE2040/sizeof(DWORD))
#define GSADR	(0x3FE20C0/sizeof(DWORD))
#define DSCTRL	(0x3FE2154/sizeof(DWORD))

unsigned long *i2700Gbase;		// Pointer for Intel 2700G registers
unsigned long backup_GSADR, backup_GSCTRL, backup_GDRCTRL;

extern "C" {
VidSysInfo VideoInfo;
}


void *BeginDraw( void )
{

	long xPitch, yPitch;
	long xWidth, yHeight;

	switch( VideoInfo.drawingMethod )
	{

		case using_gapi :
			VideoInfo.pOrigin = GXBeginDraw();
			xPitch = g_gxdp.cbxPitch >> 1;
			yPitch = g_gxdp.cbyPitch >> 1;
			xWidth = g_gxdp.cxWidth;
			yHeight = g_gxdp.cyHeight;
			break;

		case using_rawframebuffer :
			xPitch = g_RFBinfo.cxStride >> 1;
			yPitch = g_RFBinfo.cyStride >> 1;
			xWidth = g_RFBinfo.cxPixels;
			yHeight = g_RFBinfo.cyPixels;
			break;

		case using_i2700G_QVGAforzed :
			xPitch = g_RFBinfo.cxStride >> 1;
			yPitch = g_RFBinfo.cyStride >> 2;
			xWidth = g_RFBinfo.cxPixels >> 1;
			yHeight = g_RFBinfo.cyPixels >> 1;
			break;

#ifdef DIRECTDRAW_BUILD
		case using_directdraw :
			ddrawBeginDraw();
			xPitch = g_RFBinfo.cxStride >> 1;
			yPitch = g_RFBinfo.cyStride >> 1;
			xWidth = g_RFBinfo.cxPixels;
			yHeight = g_RFBinfo.cyPixels;
			break;
#endif

	}

	
	// Screen orientation

	switch( VideoInfo.Rotation )
	{
		case ROTATION_0:
			VideoInfo.xIncrementation = xPitch;
			VideoInfo.yIncrementation = yPitch;
			VideoInfo.xPixelsResolution = xWidth;
			VideoInfo.yPixelsResolution = yHeight;
			VideoInfo.pBitmap = VideoInfo.pOrigin;
			break;
		
		case ROTATION_CW90 :
			VideoInfo.xIncrementation = -yPitch;
			VideoInfo.yIncrementation = xPitch;
			VideoInfo.xPixelsResolution = yHeight;
			VideoInfo.yPixelsResolution = xWidth;
			VideoInfo.pBitmap = ((unsigned short *)VideoInfo.pOrigin + ((yHeight-1) * yPitch));
			break;

		case ROTATION_ACW90 :
			VideoInfo.xIncrementation = yPitch;
			VideoInfo.yIncrementation = -xPitch;
			VideoInfo.xPixelsResolution = yHeight;
			VideoInfo.yPixelsResolution = xWidth;
			VideoInfo.pBitmap = ((unsigned short *)VideoInfo.pOrigin + (xWidth * xPitch));
			break;

	}

	
	// VGA display? (VGA as 640x480 screen or square screen 480x480)

	VideoInfo.displayVGA = FALSE;
	if( (VideoInfo.xPixelsResolution >= 640) || (VideoInfo.yPixelsResolution >= 640) )
	{
		if( (VideoInfo.xPixelsResolution >= 480) || (VideoInfo.yPixelsResolution >= 480) )
		{
			VideoInfo.displayVGA = TRUE;
		}
	}

	return( VideoInfo.pBitmap );

}



void EndDraw(void)
{

	switch( VideoInfo.drawingMethod )
	{
		case using_gapi :
			GXEndDraw();
			break;

		case using_rawframebuffer :
			break;

#ifdef DIRECTDRAW_BUILD

		case using_directdraw :
			ddrawEndDraw();
			break;

#endif

		case using_i2700G_QVGAforzed :
			break;
	}

}



bool OpenDisplay( HWND hWnd, int force )
{

	int result = TRUE;

#ifndef OPENGL_BUILD

	if( force != FORCE_GAPI )
	{
		// Tries to set RawFrameBuffer as drawing method
		HDC hdc = GetDC( hWnd );
		result = ExtEscape(hdc, GETRAWFRAMEBUFFER, 0, NULL, sizeof(RawFrameBufferInfo), (char *) &g_RFBinfo);
		if( result )
		{
			ReleaseDC(hWnd, hdc);
			VideoInfo.pBitmap = g_RFBinfo.pFramePointer;
			VideoInfo.pOrigin = g_RFBinfo.pFramePointer;
			
#ifdef DIRECTDRAW_BUILD

			if( force == FORCE_DDRAW )
			{
				VideoInfo.drawingMethod = using_directdraw;
				VideoInfo.SwapMethod = SWAP_NONE;
				result = ddrawInit( hWnd, force );
				return result;
			}

#endif

			VideoInfo.SwapMethod = SWAP_NONE;

			if( force != FORCE_i2700Gqvga  )
			{
				VideoInfo.drawingMethod = using_rawframebuffer;
			}
			else
			{
				VideoInfo.drawingMethod = using_i2700G_QVGAforzed;

				// Change registers for QVGA display

				i2700Gbase = (unsigned long *)g_RFBinfo.pFramePointer;

				backup_GSADR = i2700Gbase[GSADR];
				backup_GSCTRL = i2700Gbase[GSCTRL];
				backup_GDRCTRL = i2700Gbase[GDRCTRL];

				i2700Gbase[GSCTRL] = (backup_GSCTRL & 0xFFC00000) | ((320-1)|((240-1)<<11));
				i2700Gbase[GSADR] = ((480/16)-1) << 22;
				i2700Gbase[GDRCTRL] = 0xA0000000; 
				i2700Gbase[DSCTRL] &= 0xFFF0FFFF;

			}

			return(TRUE);
		}
	}

	// Sets GAPI as drawing method
	GXOpenDisplay(hWnd, GX_FULLSCREEN);
	g_gxdp = GXGetDisplayProperties();
	VideoInfo.drawingMethod = using_gapi;
	VideoInfo.SwapMethod = SWAP_NONE;
	return(TRUE);

#else

	result = OpenGLinit( hWnd );

	if( result )
	{
		VideoInfo.drawingMethod = using_opengl;
		VideoInfo.displayVGA = true;
		return(true);
	}
	else
	{
		return(false);
	}

#endif

}


int CloseDisplay()
{

#ifndef OPENGL_BUILD

	switch( VideoInfo.drawingMethod )
	{
		case using_gapi :
			return( GXCloseDisplay() );

		case using_rawframebuffer :
			break;

#ifdef DIRECTDRAW_BUILD
		case using_directdraw :
			ddrawRelease();
			break;
#endif

		case using_i2700G_QVGAforzed :
			i2700Gbase[GSADR] = backup_GSADR;
			i2700Gbase[GSCTRL] = backup_GSCTRL;
			i2700Gbase[GDRCTRL] = backup_GDRCTRL;
			break;
	}

#else

	OpenGLclose();

#endif

	return(0);
}

⌨️ 快捷键说明

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