--- BasiliskII/src/Windows/main_windows.cpp 2004/12/05 15:28:39 1.3 +++ BasiliskII/src/Windows/main_windows.cpp 2008/01/01 09:40:33 1.13 @@ -1,7 +1,7 @@ /* * main_windows.cpp - Startup code for Windows * - * Basilisk II (C) 1997-2004 Christian Bauer + * Basilisk II (C) 1997-2008 Christian Bauer * * 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 @@ -48,9 +48,11 @@ using std::string; #include "main.h" #include "vm_alloc.h" #include "sigsegv.h" +#include "util_windows.h" +#include "kernel_windows.h" #if USE_JIT -extern void flush_icache_range(uint32 start, uint32 size); // from compemu_support.cpp +extern void flush_icache_range(uint8 *start, uint32 size); // from compemu_support.cpp #endif #ifdef ENABLE_MON @@ -71,12 +73,12 @@ int CPUType; bool CPUIs68060; int FPUType; bool TwentyFourBitAddressing; -bool ThirtyThreeBitAddressing = false; // Global variables -static uint8 last_xpram[XPRAM_SIZE]; // Buffer for monitoring XPRAM changes +HANDLE emul_thread = NULL; // Handle of MacOS emulation thread (main thread) +static uint8 last_xpram[XPRAM_SIZE]; // Buffer for monitoring XPRAM changes static bool xpram_thread_active = false; // Flag: XPRAM watchdog installed static volatile bool xpram_thread_cancel = false; // Flag: Cancel XPRAM thread static SDL_Thread *xpram_thread = NULL; // XPRAM watchdog @@ -89,6 +91,9 @@ static SDL_mutex *intflag_lock = NULL; #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 @@ -128,12 +133,7 @@ char *strdup(const char *s) void *vm_acquire_mac(size_t size) { - void *m = vm_acquire(size, VM_MAP_DEFAULT | VM_MAP_33BIT); - if (m == NULL) { - ThirtyThreeBitAddressing = false; - m = vm_acquire(size); - } - return m; + return vm_acquire(size, VM_MAP_DEFAULT | VM_MAP_32BIT); } @@ -141,12 +141,13 @@ void *vm_acquire_mac(size_t size) * SIGSEGV handler */ -static sigsegv_return_t sigsegv_handler(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction) +static sigsegv_return_t sigsegv_handler(sigsegv_info_t *sip) { + const uintptr fault_address = (uintptr)sigsegv_get_fault_address(sip); #if ENABLE_VOSF // Handle screen fault - extern bool Screen_fault_handler(sigsegv_address_t, sigsegv_address_t); - if (Screen_fault_handler(fault_address, fault_instruction)) + extern bool Screen_fault_handler(sigsegv_info_t *sip); + if (Screen_fault_handler(sip)) return SIGSEGV_RETURN_SUCCESS; #endif @@ -167,10 +168,12 @@ static sigsegv_return_t sigsegv_handler( * Dump state when everything went wrong after a SEGV */ -static void sigsegv_dump_state(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction) +static void sigsegv_dump_state(sigsegv_info_t *sip) { + const sigsegv_address_t fault_address = sigsegv_get_fault_address(sip); + const sigsegv_address_t fault_instruction = sigsegv_get_fault_instruction_address(sip); fprintf(stderr, "Caught SIGSEGV at address %p", fault_address); - if (fault_instruction != SIGSEGV_INVALID_PC) + if (fault_instruction != SIGSEGV_INVALID_ADDRESS) fprintf(stderr, " [IP=%p]", fault_instruction); fprintf(stderr, "\n"); uaecptr nextpc; @@ -282,11 +285,28 @@ 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(); } + // Check that drivers are installed + if (!check_drivers()) + QuitEmulator(); + + // Load win32 libraries + KernelInit(); + + // FIXME: default to DIB driver + if (getenv("SDL_VIDEODRIVER") == NULL) + putenv("SDL_VIDEODRIVER=windib"); + // Initialize SDL system int sdl_flags = 0; #ifdef USE_SDL_VIDEO @@ -333,10 +353,6 @@ int main(int argc, char **argv) vm_init(); // Create areas for Mac RAM and ROM -#ifdef USE_33BIT_ADDRESSING - // Speculatively enables 33-bit addressing - ThirtyThreeBitAddressing = true; -#endif RAMBaseHost = (uint8 *)vm_acquire_mac(RAMSize); ROMBaseHost = (uint8 *)vm_acquire_mac(0x100000); if (RAMBaseHost == VM_MAP_FAILED || ROMBaseHost == VM_MAP_FAILED) { @@ -399,6 +415,9 @@ int main(int argc, char **argv) QuitEmulator(); D(bug("Initialization complete\n")); + // Get handle of main thread + emul_thread = GetCurrentThread(); + // SDL threads available, start 60Hz thread tick_thread_active = ((tick_thread = SDL_CreateThread(tick_func, NULL)) != NULL); if (!tick_thread_active) { @@ -475,6 +494,9 @@ void QuitEmulator(void) // Exit preferences PrefsExit(); + // Release win32 libraries + KernelExit(); + exit(0); } @@ -488,7 +510,7 @@ void FlushCodeCache(void *start, uint32 { #if USE_JIT if (UseJIT) - flush_icache_range((uintptr)start, size); + flush_icache_range((uint8 *)start, size); #endif } @@ -625,12 +647,10 @@ static int tick_func(void *arg) #ifdef USE_SDL_VIDEO #include -static HWND GetMainWindowHandle(void) +HWND GetMainWindowHandle(void) { SDL_SysWMinfo wmInfo; - wmInfo.version.major = SDL_MAJOR_VERSION; - wmInfo.version.minor = SDL_MINOR_VERSION; - wmInfo.version.patch = SDL_PATCHLEVEL; + SDL_VERSION(&wmInfo.version); return SDL_GetWMInfo(&wmInfo) ? wmInfo.window : NULL; } #endif