ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Windows/main_windows.cpp
(Generate patch)

Comparing BasiliskII/src/Windows/main_windows.cpp (file contents):
Revision 1.2 by gbeauche, 2004-12-03T22:48:08Z vs.
Revision 1.13 by gbeauche, 2008-01-01T09:40:33Z

# Line 1 | Line 1
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
# Line 38 | Line 38 | using std::string;
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"
# Line 47 | Line 48 | using std::string;
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
# Line 70 | Line 73 | int CPUType;
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
# Line 88 | Line 91 | static SDL_mutex *intflag_lock = NULL;
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
# Line 127 | Line 133 | char *strdup(const char *s)
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  
# Line 140 | Line 141 | void *vm_acquire_mac(size_t size)
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  
# Line 166 | Line 168 | static sigsegv_return_t sigsegv_handler(
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;
# Line 210 | Line 214 | static void usage(const char *prg_name)
214   int main(int argc, char **argv)
215   {
216          char str[256];
217 +        bool cd_boot = false;
218  
219          // Initialize variables
220          RAMBaseHost = NULL;
# Line 241 | Line 246 | int main(int argc, char **argv)
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  
# Line 261 | Line 269 | int main(int argc, char **argv)
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] == '-') {
# Line 273 | Line 285 | int main(int argc, char **argv)
285          OSVERSIONINFO osvi;
286          ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
287          osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
288 <        if (!GetVersionEx(&osvi) || osvi.dwPlatformId != VER_PLATFORM_WIN32_NT || osvi.dwMajorVersion < 4) {
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
# Line 324 | Line 353 | int main(int argc, char **argv)
353          vm_init();
354  
355          // Create areas for Mac RAM and ROM
327 #ifdef USE_33BIT_ADDRESSING
328        // Speculatively enables 33-bit addressing
329        ThirtyThreeBitAddressing = true;
330 #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) {
# Line 390 | Line 415 | int main(int argc, char **argv)
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) {
# Line 466 | Line 494 | void QuitEmulator(void)
494          // Exit preferences
495          PrefsExit();
496  
497 +        // Release win32 libraries
498 +        KernelExit();
499 +
500          exit(0);
501   }
502  
# Line 479 | Line 510 | void FlushCodeCache(void *start, uint32
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  
# Line 616 | Line 647 | static int tick_func(void *arg)
647  
648   #ifdef USE_SDL_VIDEO
649   #include <SDL_syswm.h>
650 < static HWND GetMainWindowHandle(void)
650 > HWND GetMainWindowHandle(void)
651   {
652          SDL_SysWMinfo wmInfo;
653 <        wmInfo.version.major = SDL_MAJOR_VERSION;
623 <        wmInfo.version.minor = SDL_MINOR_VERSION;
624 <        wmInfo.version.patch = SDL_PATCHLEVEL;
653 >        SDL_VERSION(&wmInfo.version);
654          return SDL_GetWMInfo(&wmInfo) ? wmInfo.window : NULL;
655   }
656   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines