--- BasiliskII/src/Windows/main_windows.cpp 2004/12/05 16:54:14 1.4 +++ 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,10 +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 @@ -72,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 @@ -132,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); } @@ -145,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 @@ -171,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; @@ -297,9 +296,17 @@ int main(int argc, char **argv) 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 @@ -346,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) { @@ -412,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) { @@ -504,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 } @@ -641,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