Import some extra functions from Win32 libraries. Expose OS versions.

This commit is contained in:
gbeauche 2004-12-05 16:54:14 +00:00
parent 553127f8f3
commit 0c7dbfd290
3 changed files with 141 additions and 1 deletions

View File

@ -0,0 +1,88 @@
/*
* kernel_windows.cpp
*
* Basilisk II (C) 1997-1999 Christian Bauer
*
* Windows platform specific code copyright (C) Lauri Pesonen
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "sysdeps.h"
#include "prefs.h"
#include "kernel_windows.h"
// From main_windows.cpp
extern DWORD win_os;
extern DWORD win_os_major;
static HMODULE hKernel32 = 0;
static HMODULE hUser32 = 0;
static HMODULE hB2Win32 = 0;
UINT (WINAPI *pfnGetWriteWatch) (DWORD,PVOID,SIZE_T,PVOID *,LPDWORD,LPDWORD) = 0;
BOOL (WINAPI *pfnInitializeCriticalSectionAndSpinCount) (LPCRITICAL_SECTION,DWORD) = 0;
BOOL (WINAPI *pfnCancelIo) (HANDLE) = 0;
BOOL (WINAPI *pfnGETCDSECTORS) (BYTE,DWORD,WORD,LPBYTE) = 0;
UINT (WINAPI *pfnSendInput) (UINT,LPVOID,int) = 0;
BOOL (WINAPI *pfnGetDiskFreeSpaceEx) (LPCSTR,PULARGE_INTEGER,PULARGE_INTEGER,PULARGE_INTEGER) = 0;
void KernelInit( void )
{
hKernel32 = LoadLibrary( "kernel32.dll" );
hUser32 = LoadLibrary( "user32.dll" );
if(hKernel32) {
if(win_os == VER_PLATFORM_WIN32_WINDOWS) {
// NT5 RC2 Kernel exports GetWriteWatch(), but VirtualAlloc(MEM_WRITE_WATCH) fails
pfnGetWriteWatch = (UINT (WINAPI *)(DWORD,PVOID,SIZE_T,PVOID *,LPDWORD,LPDWORD))GetProcAddress( hKernel32, "GetWriteWatch" );
}
pfnInitializeCriticalSectionAndSpinCount = (BOOL (WINAPI *)(LPCRITICAL_SECTION,DWORD))GetProcAddress( hKernel32, "InitializeCriticalSectionAndSpinCount" );
pfnCancelIo = (BOOL (WINAPI *)(HANDLE))GetProcAddress( hKernel32, "CancelIo" );
pfnGetDiskFreeSpaceEx = (BOOL (WINAPI *)(LPCSTR,PULARGE_INTEGER,PULARGE_INTEGER,PULARGE_INTEGER))GetProcAddress( hKernel32, "GetDiskFreeSpaceExA" );
}
if(hUser32) {
// Win98 has this one too.
// if(win_os == VER_PLATFORM_WIN32_NT) {
pfnSendInput = (UINT (WINAPI *)(UINT,LPVOID,int))GetProcAddress( hUser32, "SendInput" );
// }
}
if(win_os == VER_PLATFORM_WIN32_WINDOWS) {
hB2Win32 = LoadLibrary( "B2Win32.dll" );
if(hB2Win32) {
pfnGETCDSECTORS = (BOOL (WINAPI *)(BYTE,DWORD,WORD,LPBYTE))GetProcAddress( hB2Win32, "GETCDSECTORS" );
}
}
}
void KernelExit( void )
{
if(hKernel32) {
FreeLibrary( hKernel32 );
hKernel32 = 0;
}
if(hUser32) {
FreeLibrary( hUser32 );
hUser32 = 0;
}
if(hB2Win32) {
FreeLibrary( hB2Win32 );
hB2Win32 = 0;
}
pfnGetWriteWatch = 0;
pfnInitializeCriticalSectionAndSpinCount = 0;
pfnCancelIo = 0;
pfnSendInput = 0;
pfnGETCDSECTORS = 0;
}

View File

@ -0,0 +1,36 @@
/*
* kernel_windows.h
*
* Basilisk II (C) 1997-1999 Christian Bauer
*
* Windows platform specific code copyright (C) Lauri Pesonen
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _KERNEL_WINDOWS_H_
#define _KERNEL_WINDOWS_H_
extern UINT (WINAPI *pfnGetWriteWatch) (DWORD,PVOID,SIZE_T,PVOID *,LPDWORD,LPDWORD);
extern BOOL (WINAPI *pfnInitializeCriticalSectionAndSpinCount) (LPCRITICAL_SECTION,DWORD);
extern BOOL (WINAPI *pfnCancelIo) (HANDLE);
extern BOOL (WINAPI *pfnGETCDSECTORS) (BYTE,DWORD,WORD,LPBYTE);
extern UINT (WINAPI *pfnSendInput) (UINT,LPVOID,int);
extern BOOL (WINAPI *pfnGetDiskFreeSpaceEx) (LPCSTR,PULARGE_INTEGER,PULARGE_INTEGER,PULARGE_INTEGER);
void KernelInit( void );
void KernelExit( void );
#endif // _KERNEL_WINDOWS_H_

View File

@ -48,6 +48,7 @@ using std::string;
#include "main.h"
#include "vm_alloc.h"
#include "sigsegv.h"
#include "kernel_windows.h"
#if USE_JIT
extern void flush_icache_range(uint32 start, uint32 size); // from compemu_support.cpp
@ -89,6 +90,9 @@ static SDL_mutex *intflag_lock = NULL; // Mutex to protect InterruptFlags
#define LOCK_INTFLAGS SDL_LockMutex(intflag_lock)
#define UNLOCK_INTFLAGS SDL_UnlockMutex(intflag_lock)
DWORD win_os; // Windows OS id
DWORD win_os_major; // Windows OS version major
#if USE_SCRATCHMEM_SUBTERFUGE
uint8 *ScratchMem = NULL; // Scratch memory for Mac ROM writes
#endif
@ -282,11 +286,20 @@ int main(int argc, char **argv)
OSVERSIONINFO osvi;
ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (!GetVersionEx(&osvi) || osvi.dwPlatformId != VER_PLATFORM_WIN32_NT || osvi.dwMajorVersion < 4) {
if (!GetVersionEx(&osvi)) {
ErrorAlert("Could not determine OS type");
QuitEmulator();
}
win_os = osvi.dwPlatformId;
win_os_major = osvi.dwMajorVersion;
if (win_os != VER_PLATFORM_WIN32_NT || win_os_major < 4) {
ErrorAlert(STR_NO_WIN32_NT_4);
QuitEmulator();
}
// Load win32 libraries
KernelInit();
// Initialize SDL system
int sdl_flags = 0;
#ifdef USE_SDL_VIDEO
@ -475,6 +488,9 @@ void QuitEmulator(void)
// Exit preferences
PrefsExit();
// Release win32 libraries
KernelExit();
exit(0);
}