1 |
|
/* |
2 |
|
* main_windows.cpp - Startup code for Windows |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-2004 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2008 Christian Bauer |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
38 |
|
#include "xpram.h" |
39 |
|
#include "timer.h" |
40 |
|
#include "video.h" |
41 |
+ |
#include "cdrom.h" |
42 |
|
#include "emul_op.h" |
43 |
|
#include "prefs.h" |
44 |
|
#include "prefs_editor.h" |
48 |
|
#include "main.h" |
49 |
|
#include "vm_alloc.h" |
50 |
|
#include "sigsegv.h" |
51 |
+ |
#include "util_windows.h" |
52 |
+ |
#include "kernel_windows.h" |
53 |
|
|
54 |
|
#if USE_JIT |
55 |
< |
extern void flush_icache_range(uint32 start, uint32 size); // from compemu_support.cpp |
55 |
> |
extern void flush_icache_range(uint8 *start, uint32 size); // from compemu_support.cpp |
56 |
|
#endif |
57 |
|
|
58 |
|
#ifdef ENABLE_MON |
73 |
|
bool CPUIs68060; |
74 |
|
int FPUType; |
75 |
|
bool TwentyFourBitAddressing; |
73 |
– |
bool ThirtyThreeBitAddressing = false; |
76 |
|
|
77 |
|
|
78 |
|
// Global variables |
79 |
< |
static uint8 last_xpram[XPRAM_SIZE]; // Buffer for monitoring XPRAM changes |
79 |
> |
HANDLE emul_thread = NULL; // Handle of MacOS emulation thread (main thread) |
80 |
|
|
81 |
+ |
static uint8 last_xpram[XPRAM_SIZE]; // Buffer for monitoring XPRAM changes |
82 |
|
static bool xpram_thread_active = false; // Flag: XPRAM watchdog installed |
83 |
|
static volatile bool xpram_thread_cancel = false; // Flag: Cancel XPRAM thread |
84 |
|
static SDL_Thread *xpram_thread = NULL; // XPRAM watchdog |
91 |
|
#define LOCK_INTFLAGS SDL_LockMutex(intflag_lock) |
92 |
|
#define UNLOCK_INTFLAGS SDL_UnlockMutex(intflag_lock) |
93 |
|
|
94 |
+ |
DWORD win_os; // Windows OS id |
95 |
+ |
DWORD win_os_major; // Windows OS version major |
96 |
+ |
|
97 |
|
#if USE_SCRATCHMEM_SUBTERFUGE |
98 |
|
uint8 *ScratchMem = NULL; // Scratch memory for Mac ROM writes |
99 |
|
#endif |
133 |
|
|
134 |
|
void *vm_acquire_mac(size_t size) |
135 |
|
{ |
136 |
< |
void *m = vm_acquire(size, VM_MAP_DEFAULT | VM_MAP_33BIT); |
131 |
< |
if (m == NULL) { |
132 |
< |
ThirtyThreeBitAddressing = false; |
133 |
< |
m = vm_acquire(size); |
134 |
< |
} |
135 |
< |
return m; |
136 |
> |
return vm_acquire(size, VM_MAP_DEFAULT | VM_MAP_32BIT); |
137 |
|
} |
138 |
|
|
139 |
|
|
141 |
|
* SIGSEGV handler |
142 |
|
*/ |
143 |
|
|
144 |
< |
static sigsegv_return_t sigsegv_handler(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction) |
144 |
> |
static sigsegv_return_t sigsegv_handler(sigsegv_info_t *sip) |
145 |
|
{ |
146 |
+ |
const uintptr fault_address = (uintptr)sigsegv_get_fault_address(sip); |
147 |
|
#if ENABLE_VOSF |
148 |
|
// Handle screen fault |
149 |
< |
extern bool Screen_fault_handler(sigsegv_address_t, sigsegv_address_t); |
150 |
< |
if (Screen_fault_handler(fault_address, fault_instruction)) |
149 |
> |
extern bool Screen_fault_handler(sigsegv_info_t *sip); |
150 |
> |
if (Screen_fault_handler(sip)) |
151 |
|
return SIGSEGV_RETURN_SUCCESS; |
152 |
|
#endif |
153 |
|
|
168 |
|
* Dump state when everything went wrong after a SEGV |
169 |
|
*/ |
170 |
|
|
171 |
< |
static void sigsegv_dump_state(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction) |
171 |
> |
static void sigsegv_dump_state(sigsegv_info_t *sip) |
172 |
|
{ |
173 |
+ |
const sigsegv_address_t fault_address = sigsegv_get_fault_address(sip); |
174 |
+ |
const sigsegv_address_t fault_instruction = sigsegv_get_fault_instruction_address(sip); |
175 |
|
fprintf(stderr, "Caught SIGSEGV at address %p", fault_address); |
176 |
< |
if (fault_instruction != SIGSEGV_INVALID_PC) |
176 |
> |
if (fault_instruction != SIGSEGV_INVALID_ADDRESS) |
177 |
|
fprintf(stderr, " [IP=%p]", fault_instruction); |
178 |
|
fprintf(stderr, "\n"); |
179 |
|
uaecptr nextpc; |
214 |
|
int main(int argc, char **argv) |
215 |
|
{ |
216 |
|
char str[256]; |
217 |
+ |
bool cd_boot = false; |
218 |
|
|
219 |
|
// Initialize variables |
220 |
|
RAMBaseHost = NULL; |
246 |
|
} else if (strcmp(argv[i], "--rominfo") == 0) { |
247 |
|
argv[i] = NULL; |
248 |
|
PrintROMInfo = true; |
249 |
+ |
} else if (strcmp(argv[i], "--cdboot") == 0) { |
250 |
+ |
argv[i] = NULL; |
251 |
+ |
cd_boot = true; |
252 |
|
} |
253 |
|
} |
254 |
|
|
269 |
|
// Read preferences |
270 |
|
PrefsInit(argc, argv); |
271 |
|
|
272 |
+ |
// Boot MacOS from CD-ROM? |
273 |
+ |
if (cd_boot) |
274 |
+ |
PrefsReplaceInt32("bootdriver", CDROMRefNum); |
275 |
+ |
|
276 |
|
// Any command line arguments left? |
277 |
|
for (int i=1; i<argc; i++) { |
278 |
|
if (argv[i][0] == '-') { |
281 |
|
} |
282 |
|
} |
283 |
|
|
284 |
+ |
// Check we are using a Windows NT kernel >= 4.0 |
285 |
+ |
OSVERSIONINFO osvi; |
286 |
+ |
ZeroMemory(&osvi, sizeof(OSVERSIONINFO)); |
287 |
+ |
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); |
288 |
+ |
if (!GetVersionEx(&osvi)) { |
289 |
+ |
ErrorAlert("Could not determine OS type"); |
290 |
+ |
QuitEmulator(); |
291 |
+ |
} |
292 |
+ |
win_os = osvi.dwPlatformId; |
293 |
+ |
win_os_major = osvi.dwMajorVersion; |
294 |
+ |
if (win_os != VER_PLATFORM_WIN32_NT || win_os_major < 4) { |
295 |
+ |
ErrorAlert(STR_NO_WIN32_NT_4); |
296 |
+ |
QuitEmulator(); |
297 |
+ |
} |
298 |
+ |
|
299 |
+ |
// Check that drivers are installed |
300 |
+ |
if (!check_drivers()) |
301 |
+ |
QuitEmulator(); |
302 |
+ |
|
303 |
+ |
// Load win32 libraries |
304 |
+ |
KernelInit(); |
305 |
+ |
|
306 |
+ |
// FIXME: default to DIB driver |
307 |
+ |
if (getenv("SDL_VIDEODRIVER") == NULL) |
308 |
+ |
putenv("SDL_VIDEODRIVER=windib"); |
309 |
+ |
|
310 |
|
// Initialize SDL system |
311 |
|
int sdl_flags = 0; |
312 |
|
#ifdef USE_SDL_VIDEO |
353 |
|
vm_init(); |
354 |
|
|
355 |
|
// Create areas for Mac RAM and ROM |
318 |
– |
#ifdef USE_33BIT_ADDRESSING |
319 |
– |
// Speculatively enables 33-bit addressing |
320 |
– |
ThirtyThreeBitAddressing = true; |
321 |
– |
#endif |
356 |
|
RAMBaseHost = (uint8 *)vm_acquire_mac(RAMSize); |
357 |
|
ROMBaseHost = (uint8 *)vm_acquire_mac(0x100000); |
358 |
|
if (RAMBaseHost == VM_MAP_FAILED || ROMBaseHost == VM_MAP_FAILED) { |
415 |
|
QuitEmulator(); |
416 |
|
D(bug("Initialization complete\n")); |
417 |
|
|
418 |
+ |
// Get handle of main thread |
419 |
+ |
emul_thread = GetCurrentThread(); |
420 |
+ |
|
421 |
|
// SDL threads available, start 60Hz thread |
422 |
|
tick_thread_active = ((tick_thread = SDL_CreateThread(tick_func, NULL)) != NULL); |
423 |
|
if (!tick_thread_active) { |
494 |
|
// Exit preferences |
495 |
|
PrefsExit(); |
496 |
|
|
497 |
+ |
// Release win32 libraries |
498 |
+ |
KernelExit(); |
499 |
+ |
|
500 |
|
exit(0); |
501 |
|
} |
502 |
|
|
510 |
|
{ |
511 |
|
#if USE_JIT |
512 |
|
if (UseJIT) |
513 |
< |
flush_icache_range((uintptr)start, size); |
513 |
> |
flush_icache_range((uint8 *)start, size); |
514 |
|
#endif |
515 |
|
} |
516 |
|
|
642 |
|
|
643 |
|
|
644 |
|
/* |
645 |
< |
* Display alert |
645 |
> |
* Get the main window handle |
646 |
|
*/ |
647 |
|
|
648 |
< |
#ifdef ENABLE_GTK |
649 |
< |
static void dl_destroyed(void) |
648 |
> |
#ifdef USE_SDL_VIDEO |
649 |
> |
#include <SDL_syswm.h> |
650 |
> |
HWND GetMainWindowHandle(void) |
651 |
|
{ |
652 |
< |
gtk_main_quit(); |
652 |
> |
SDL_SysWMinfo wmInfo; |
653 |
> |
SDL_VERSION(&wmInfo.version); |
654 |
> |
return SDL_GetWMInfo(&wmInfo) ? wmInfo.window : NULL; |
655 |
|
} |
656 |
+ |
#endif |
657 |
|
|
614 |
– |
static void dl_quit(GtkWidget *dialog) |
615 |
– |
{ |
616 |
– |
gtk_widget_destroy(dialog); |
617 |
– |
} |
658 |
|
|
659 |
< |
void display_alert(int title_id, int prefix_id, int button_id, const char *text) |
660 |
< |
{ |
661 |
< |
char str[256]; |
622 |
< |
sprintf(str, GetString(prefix_id), text); |
623 |
< |
|
624 |
< |
GtkWidget *dialog = gtk_dialog_new(); |
625 |
< |
gtk_window_set_title(GTK_WINDOW(dialog), GetString(title_id)); |
626 |
< |
gtk_container_border_width(GTK_CONTAINER(dialog), 5); |
627 |
< |
gtk_widget_set_uposition(GTK_WIDGET(dialog), 100, 150); |
628 |
< |
gtk_signal_connect(GTK_OBJECT(dialog), "destroy", GTK_SIGNAL_FUNC(dl_destroyed), NULL); |
629 |
< |
|
630 |
< |
GtkWidget *label = gtk_label_new(str); |
631 |
< |
gtk_widget_show(label); |
632 |
< |
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), label, TRUE, TRUE, 0); |
633 |
< |
|
634 |
< |
GtkWidget *button = gtk_button_new_with_label(GetString(button_id)); |
635 |
< |
gtk_widget_show(button); |
636 |
< |
gtk_signal_connect_object(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(dl_quit), GTK_OBJECT(dialog)); |
637 |
< |
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area), button, FALSE, FALSE, 0); |
638 |
< |
GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); |
639 |
< |
gtk_widget_grab_default(button); |
640 |
< |
gtk_widget_show(dialog); |
659 |
> |
/* |
660 |
> |
* Display alert |
661 |
> |
*/ |
662 |
|
|
663 |
< |
gtk_main(); |
663 |
> |
static void display_alert(int title_id, const char *text, int flags) |
664 |
> |
{ |
665 |
> |
HWND hMainWnd = GetMainWindowHandle(); |
666 |
> |
MessageBox(hMainWnd, text, GetString(title_id), MB_OK | flags); |
667 |
|
} |
644 |
– |
#endif |
668 |
|
|
669 |
|
|
670 |
|
/* |
673 |
|
|
674 |
|
void ErrorAlert(const char *text) |
675 |
|
{ |
676 |
< |
#if 0 |
654 |
< |
// TODO: Windows message box |
655 |
< |
if (PrefsFindBool("nogui")) { |
656 |
< |
printf(GetString(STR_SHELL_ERROR_PREFIX), text); |
676 |
> |
if (PrefsFindBool("nogui")) |
677 |
|
return; |
678 |
< |
} |
678 |
> |
|
679 |
|
VideoQuitFullScreen(); |
680 |
< |
display_alert(STR_ERROR_ALERT_TITLE, STR_GUI_ERROR_PREFIX, STR_QUIT_BUTTON, text); |
661 |
< |
#else |
662 |
< |
printf(GetString(STR_SHELL_ERROR_PREFIX), text); |
663 |
< |
#endif |
680 |
> |
display_alert(STR_ERROR_ALERT_TITLE, text, MB_ICONSTOP); |
681 |
|
} |
682 |
|
|
683 |
|
|
687 |
|
|
688 |
|
void WarningAlert(const char *text) |
689 |
|
{ |
690 |
< |
#if 0 |
674 |
< |
// TODO: Windows message box |
675 |
< |
if (PrefsFindBool("nogui")) { |
676 |
< |
printf(GetString(STR_SHELL_WARNING_PREFIX), text); |
690 |
> |
if (PrefsFindBool("nogui")) |
691 |
|
return; |
692 |
< |
} |
693 |
< |
display_alert(STR_WARNING_ALERT_TITLE, STR_GUI_WARNING_PREFIX, STR_OK_BUTTON, text); |
680 |
< |
#else |
681 |
< |
printf(GetString(STR_SHELL_WARNING_PREFIX), text); |
682 |
< |
#endif |
692 |
> |
|
693 |
> |
display_alert(STR_WARNING_ALERT_TITLE, text, MB_ICONINFORMATION); |
694 |
|
} |
695 |
|
|
696 |
|
|