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

📄 wince_mame.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 <wingdi.h>
#include <aygshell.h>
#include <commdlg.h>
#include <gx.h>

#include "resource.h"

#include "wince_gamelist.h"
#include "wince_mame.h"
#include "wince_driver.h"
#include "wince_cfg.h"
#include "vidsys.h"

#define PCMAMEv	"v0.4a"

extern "C" {
	#include "wince_util.h"
	#include "wince_input.h"
	#include "wince_events.h"

	extern cfgStruct DefConfig;
	extern cfgStruct GameConfig;
	extern PadMappingStruct PadMapping;

	extern int initWndActive;

	extern void setFullScreenWindow( HWND hWnd );

	int msdos_init_sound(void);

	int osd_init(void);
	void osd_exit(void);
}

HINSTANCE g_hInstance = 0;
HDC hdc;
HWND hWnd;

int iScreenWidth, iScreenHeight;

GXKeyList g_gxkl;				// GX keys struct

//
// Forward declarations.
//
ATOM MyRegisterClass( HINSTANCE hInstance, LPTSTR szWindowClass );
BOOL InitInstance( HINSTANCE hInstance, int nCmdShow );
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam );

//
// Emulation starts
//
int osd_init(void)
{

	if( !OpenDisplay( hWnd, GameConfig.vid2700G_lowRes ) )
	{
		writeLog("Error creating video display!!");
		return(1);
	}

	if(msdos_init_sound()!=0)
	{
		writeLog("The sound cannot be initilized!!");
		return(1);
	}

	GXOpenInput();
	g_gxkl = GXGetDefaultKeys(GX_NORMALKEYS);
	if( GameConfig.inpKeyUpCode == OPTION_AUTO ) PadMapping.Up = g_gxkl.vkUp; else PadMapping.Up = GameConfig.inpKeyUpCode;
	if( GameConfig.inpKeyDownCode == OPTION_AUTO ) PadMapping.Down = g_gxkl.vkDown;  else PadMapping.Down = GameConfig.inpKeyDownCode;
	if( GameConfig.inpKeyLeftCode == OPTION_AUTO ) PadMapping.Left = g_gxkl.vkLeft;  else PadMapping.Left = GameConfig.inpKeyLeftCode;
	if( GameConfig.inpKeyRightCode == OPTION_AUTO ) PadMapping.Right = g_gxkl.vkRight;  else PadMapping.Right = GameConfig.inpKeyRightCode;
	if( GameConfig.inpKeyACode == OPTION_AUTO ) PadMapping.KeyA = g_gxkl.vkB; else PadMapping.KeyA = GameConfig.inpKeyACode;
	if( GameConfig.inpKeyBCode == OPTION_AUTO ) PadMapping.KeyB = 0; else PadMapping.KeyB = GameConfig.inpKeyBCode;
	if( GameConfig.inpKeyCCode == OPTION_AUTO ) PadMapping.KeyC = 0; else PadMapping.KeyC = GameConfig.inpKeyCCode;
	if( GameConfig.inpKeyDCode == OPTION_AUTO ) PadMapping.KeyD = 0; else PadMapping.KeyD = GameConfig.inpKeyDCode; 
	if( GameConfig.inpKeyECode == OPTION_AUTO ) PadMapping.KeyE = g_gxkl.vkA; else PadMapping.KeyE = GameConfig.inpKeyECode;
	if( GameConfig.inpKeyFCode == OPTION_AUTO ) PadMapping.KeyF = g_gxkl.vkStart; else PadMapping.KeyF = GameConfig.inpKeyFCode;
	if( GameConfig.inpKeyGCode == OPTION_AUTO ) PadMapping.KeyG = g_gxkl.vkC; else PadMapping.KeyG = GameConfig.inpKeyGCode;
	RotatePadMapping();

	return(0);
}

//
// Emulation ends
//
void osd_exit(void)
{

	CloseDisplay();
	GXCloseInput();

}


void pcmameQuit(void)
{
	CloseDisplay();
	closeLog();

	DestroyWindow(hWnd);
	UnregisterClass(L"PCMAME", g_hInstance);
}

//
//  Registers the window class
//
ATOM MyRegisterClass( HINSTANCE hInstance, LPTSTR szWindowClass )
{
	WNDCLASS	wc;

    wc.style			= CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc		= (WNDPROC) WndProc;
    wc.cbClsExtra		= 0;
    wc.cbWndExtra		= 0;
    wc.hInstance		= hInstance;
    wc.hIcon			= NULL;
    wc.hCursor			= 0;
    wc.hbrBackground	= (HBRUSH) GetStockObject(BLACK_BRUSH);
    wc.lpszMenuName		= 0;
    wc.lpszClassName	= szWindowClass;

	return RegisterClass(&wc);
}

//
// Inits instance and initializes PCMAME
//
BOOL InitInstance( HINSTANCE hInstance, int nCmdShow )
{
	RECT rect;    

	TCHAR	szTitle[] = L"PCMAME";				// The title bar text
	TCHAR	szWindowClass[] = L"PCMAME";		// The window class name

	g_hInstance = hInstance;

	hWnd = FindWindow(szWindowClass, szTitle);	
	if (hWnd)
	{
		SetForegroundWindow((HWND) (((DWORD)hWnd) | 0x01));
		return 0;
	} 

	MyRegisterClass(hInstance, szWindowClass);

	SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0);

	iScreenWidth = GetSystemMetrics(SM_CXSCREEN);
	iScreenHeight = GetSystemMetrics(SM_CYSCREEN);

	hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE | WS_NONAVDONEBUTTON,
		0, 0, iScreenWidth, iScreenHeight, 
		NULL, NULL, hInstance, NULL);
	SHFullScreen(hWnd, SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON);
	setFullScreenWindow( hWnd );

	if (!hWnd) 
	{	
		return FALSE;
	}
    
	ShowWindow(hWnd, nCmdShow);
	UpdateWindow(hWnd);
   
	return TRUE;
}


//
// PCMAME
//
int WINAPI WinMain(
	HINSTANCE hInstance,
	HINSTANCE hPrevInstance,
	LPTSTR lpCmdLine,
	int nCmdShow )
{

	int gameIndex;
	int result = 0;

	getMAMEPath();	// Get the path to the executable
	initLog();		// Create log file

	writeLog(" --- PCMAME log start, ");
	writeLog( PCMAMEv );

	if (!InitInstance (hInstance, nCmdShow)) 
	{
		writeLog("ERROR: PCMAME cannot be initialized.");
		pcmameQuit();
		return FALSE;
	}

	// Load default configuration
	setInitialConfiguration();
	loadConfiguration( "default", DefConfig );

	// List of games
	gameIndex = DialogBox( g_hInstance, (LPCTSTR)IDD_dlgListGames, hWnd, (DLGPROC)dlgListGames);

	// Save configuration
	saveConfiguration( "default", DefConfig );

	// Launch selected game or exit
	if( gameIndex > -1 )
	{
		result = gameLaunch( gameIndex );
	}
	else
	{
		pcmameQuit();
		return TRUE;
	}

	if(!result)
	{
		pcmameQuit();
	}
	else{
		while( initWndActive ){ checkMessages(); }
		pcmameQuit();
	}

	return TRUE;
}

⌨️ 快捷键说明

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