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

📄 pm.c

📁 BIOS emulator and interface to Realmode X86 Emulator Library Can emulate a PCI Graphic Controller V
💻 C
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************					SciTech OS Portability Manager Library**  ========================================================================**    The contents of this file are subject to the SciTech MGL Public*    License Version 1.0 (the "License"); you may not use this file*    except in compliance with the License. You may obtain a copy of*    the License at http://www.scitechsoft.com/mgl-license.txt**    Software distributed under the License is distributed on an*    "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or*    implied. See the License for the specific language governing*    rights and limitations under the License.**    The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.**    The Initial Developer of the Original Code is SciTech Software, Inc.*    All Rights Reserved.**  ========================================================================** Language:		ANSI C* Environment:	Win32** Description:	Implementation for the OS Portability Manager Library, which*				contains functions to implement OS specific services in a*				generic, cross platform API. Porting the OS Portability*				Manager library is the first step to porting any SciTech*				products to a new platform.*****************************************************************************/#define	WIN32_LEAN_AND_MEAN#define	STRICT#include <windows.h>#include <mmsystem.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include "pmapi.h"#include "drvlib/os/os.h"#include "pm_help.h"/*--------------------------- Global variables ----------------------------*/ibool			_PM_haveWinNT;		/* True if we are running on NT		*/static uint		VESABuf_len = 1024;	/* Length of the VESABuf buffer		*/static void 	*VESABuf_ptr = NULL;/* Near pointer to VESABuf          */static uint 	VESABuf_rseg;   	/* Real mode segment of VESABuf     */static uint		VESABuf_roff;		/* Real mode offset of VESABuf      */HANDLE			_PM_hDevice = NULL;	/* Handle to Win32 VxD				*/extern ushort	_PM_gdt;			/* GDT for our Ring-0 Call Gate		*/static ibool	inited = false;		/* Flags if we are initialised		*/static void 	(PMAPIP fatalErrorCleanup)(void) = NULL;static char *szMachineNameKey = "System\\CurrentControlSet\\control\\ComputerName\\ComputerName";static char *szMachineNameKeyNT = "System\\CurrentControlSet001\\control\\ComputerName\\ActiveComputerName";static char *szMachineName = "ComputerName";/*----------------------------- Implementation ----------------------------*//****************************************************************************REMARKS:Initialise the PM library and connect to our helper device driver. If wecannot connect to our helper device driver, we bail out with an errormessage. Our Windows 9x VxD is dynamically loadable, so it can be loadedafter the system has started.****************************************************************************/void PMAPI PM_init(void){	DWORD	outBuf[1];	/* Buffer to receive data from VxD	*/	DWORD	count;		/* Count of bytes returned from VxD	*/	/* Determine if we are running under Windows NT or not */	_PM_haveWinNT = false;	if ((GetVersion() & 0x80000000UL) == 0)		_PM_haveWinNT = true;	/* Create a file handle for the static VxD if possible, otherwise	 * dynamically load the PMHELP helper VxD. Note that if an old version	 * of SDD is loaded, we use the PMHELP VxD instead.	 */	if (!inited) {		_PM_hDevice = CreateFile(SDDHELP_VXD_MODULE, 0,0,0, CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0);		if (_PM_hDevice != INVALID_HANDLE_VALUE) {			if (!DeviceIoControl(_PM_hDevice, PMHELP_GETVER32, NULL, 0,					outBuf, sizeof(outBuf), &count, NULL) || outBuf[0] < PMHELP_VERSION) {				/* Old version of SDDHELP loaded, so use PMHELP instead */				CloseHandle(_PM_hDevice);				_PM_hDevice = INVALID_HANDLE_VALUE;				}			}		if (_PM_hDevice == INVALID_HANDLE_VALUE) {			/* The VxD was not staticly loaded, so try creating a file handle			 * to a dynamic version of the VxD if possible.			 */			_PM_hDevice = CreateFile(PMHELP_VXD_NAME, 0,0,0, CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0);			if (_PM_hDevice == INVALID_HANDLE_VALUE)				PM_fatalError("Unable to connect to PMHELP.VXD or SDDHELP.VXD!");			}		/* Call the VxD to determine the version number */		if (!DeviceIoControl(_PM_hDevice, PMHELP_GETVER32, NULL, 0,				outBuf, sizeof(outBuf), &count, NULL) || outBuf[0] < PMHELP_VERSION)			PM_fatalError("Older version of PMHELP.VXD found!");		/* Obtain the 32->16 callgate from the VxD to enable IOPL */		if (!DeviceIoControl(_PM_hDevice, PMHELP_GETCALLGATE32, NULL, 0, outBuf, sizeof(outBuf), &count, NULL))			PM_fatalError("Unable to obtain call gate selector!");		_PM_gdt = (ushort)outBuf[0];		/* Indicate that we have been initialised */		inited = true;		}}/****************************************************************************REMARKS:We do have BIOS access under Windows 9x, but not under Windows NT.****************************************************************************/ibool PMAPI PM_haveBIOSAccess(void){	if (PM_getOSType() == _OS_WINNT)		return false;	else		return true;}/****************************************************************************REMARKS:Return the operating system type identifier.****************************************************************************/long PMAPI PM_getOSType(void){	if ((GetVersion() & 0x80000000UL) == 0)		return _OS_WINNT;	else		return _OS_WIN95;}/****************************************************************************REMARKS:Return the runtime type identifier.****************************************************************************/int PMAPI PM_getModeType(void){	return PM_386;}/****************************************************************************REMARKS:Add a file directory separator to the end of the filename.****************************************************************************/void PMAPI PM_backslash(	char *s){	uint pos = strlen(s);	if (s[pos-1] != '\\') {		s[pos] = '\\';		s[pos+1] = '\0';		}}/****************************************************************************REMARKS:Add a user defined PM_fatalError cleanup function.****************************************************************************/void PMAPI PM_setFatalErrorCleanup(	void (PMAPIP cleanup)(void)){	fatalErrorCleanup = cleanup;}/****************************************************************************REMARKS:Report a fatal error condition and halt the program.****************************************************************************/void PMAPI PM_fatalError(	const char *msg){	if (fatalErrorCleanup)		fatalErrorCleanup();	MessageBox(NULL,msg,"Fatal Error!", MB_ICONEXCLAMATION);	exit(1);}/****************************************************************************REMARKS:Allocate the real mode VESA transfer buffer for communicating with the BIOS.****************************************************************************/void * PMAPI PM_getVESABuf(	uint *len,	uint *rseg,	uint *roff){	DWORD	outBuf[4];	/* Buffer to receive data from VxD	*/	DWORD	count;		/* Count of bytes returned from VxD	*/	/* We require the helper VxD to be loaded staticly in order to support	 * the VESA transfer buffer. We do not support dynamically allocating	 * real mode memory buffers from Win32 programs (we need a 16-bit DLL	 * for this, and Windows 9x becomes very unstable if you free the	 * memory blocks out of order).	 */	if (!inited)		PM_init();	if (!VESABuf_ptr) {		if (DeviceIoControl(_PM_hDevice, PMHELP_GETVESABUF32, NULL, 0,				outBuf, sizeof(outBuf), &count, NULL)) {			if (!outBuf[0])				return NULL;			VESABuf_ptr = (void*)outBuf[0];			VESABuf_len = outBuf[1];			VESABuf_rseg = outBuf[2];			VESABuf_roff = outBuf[3];			}		}	*len = VESABuf_len;	*rseg = VESABuf_rseg;	*roff = VESABuf_roff;	return VESABuf_ptr;}/****************************************************************************REMARKS:Check if a key has been pressed.****************************************************************************/int	PMAPI PM_kbhit(void){	/* Not used in Windows */	return true;}/****************************************************************************REMARKS:Wait for and return the next keypress.****************************************************************************/int	PMAPI PM_getch(void){	/* Not used in Windows */	return 0xD;}/****************************************************************************REMARKS:Set the location of the OS console cursor.****************************************************************************/void PM_setOSCursorLocation(	int x,	int y){	/* Nothing to do for Windows */    (void)x;	(void)y;}/****************************************************************************REMARKS:Set the width of the OS console.****************************************************************************/void PM_setOSScreenWidth(	int width,	int height){	/* Nothing to do for Windows */	(void)width;	(void)height;}/****************************************************************************REMARKS:Set the real time clock handler (used for software stereo modes).****************************************************************************/ibool PMAPI PM_setRealTimeClockHandler(	PM_intHandler ih,	int frequency){	/* We do not support this from Win32 programs. Rather the VxD handles	 * this stuff it will take care of hooking the stereo flip functions at	 * the VxD level.	 */	(void)ih;	(void)frequency;	return false;}/****************************************************************************REMARKS:Set the real time clock frequency (for stereo modes).****************************************************************************/void PMAPI PM_setRealTimeClockFrequency(	int frequency){	/* Not supported under Win32 */	(void)frequency;}/****************************************************************************REMARKS:Restore the original real time clock handler.****************************************************************************/void PMAPI PM_restoreRealTimeClockHandler(void){	/* Not supported under Win32 */}/****************************************************************************REMARKS:Return the current operating system path or working directory.****************************************************************************/const char * PMAPI PM_getCurrentPath(void){	static char cwd[256];	GetCurrentDirectory(sizeof(cwd),cwd);	return cwd;}/****************************************************************************REMARKS:Return the drive letter for the boot drive.****************************************************************************/char PMAPI PM_getBootDrive(void){	return 'c';}/****************************************************************************REMARKS:Return the path to the VBE/AF driver files.****************************************************************************/const char * PMAPI PM_getVBEAFPath(void)

⌨️ 快捷键说明

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