ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/MacOSX/main_macosx.mm
Revision: 1.21
Committed: 2009-07-23T19:19:14Z (15 years, 3 months ago) by asvitkine
Branch: MAIN
Changes since 1.20: +3 -2 lines
Log Message:
BasiliskII side of changes to support .sheepvm bundles for SheepShaver

File Contents

# User Rev Content
1 nigel 1.1 /*
2 asvitkine 1.21 * $Id: main_macosx.mm,v 1.20 2008/02/04 01:00:53 nigel Exp $
3 nigel 1.1 *
4     * main_macosx.mm - Startup code for MacOS X
5     * Based (in a small way) on the default main.m,
6     and on Basilisk's main_unix.cpp
7     *
8 gbeauche 1.19 * Basilisk II (C) 1997-2008 Christian Bauer
9 nigel 1.1 *
10     * This program is free software; you can redistribute it and/or modify
11     * it under the terms of the GNU General Public License as published by
12     * the Free Software Foundation; either version 2 of the License, or
13     * (at your option) any later version.
14     *
15     * This program is distributed in the hope that it will be useful,
16     * but WITHOUT ANY WARRANTY; without even the implied warranty of
17     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18     * GNU General Public License for more details.
19     *
20     * You should have received a copy of the GNU General Public License
21     * along with this program; if not, write to the Free Software
22     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23     */
24 nigel 1.14
25     #import <AppKit/AppKit.h>
26     #undef check
27    
28 nigel 1.10 #define PTHREADS // Why is this here?
29 nigel 1.1 #include "sysdeps.h"
30    
31     #ifdef HAVE_PTHREADS
32     # include <pthread.h>
33     #endif
34    
35     #if REAL_ADDRESSING || DIRECT_ADDRESSING
36     # include <sys/mman.h>
37     #endif
38    
39 nigel 1.8 #include <string>
40     using std::string;
41    
42 nigel 1.1 #include "cpu_emulation.h"
43     #include "macos_util_macosx.h"
44     #include "main.h"
45     #include "prefs.h"
46     #include "prefs_editor.h"
47     #include "rom_patches.h"
48 nigel 1.8 #include "sigsegv.h"
49 nigel 1.1 #include "sys.h"
50     #include "user_strings.h"
51     #include "version.h"
52     #include "video.h"
53     #include "vm_alloc.h"
54     #include "xpram.h"
55    
56 nigel 1.8 #if USE_JIT
57 gbeauche 1.16 extern void flush_icache_range(uint8 *start, uint32 size); // from compemu_support.cpp
58 nigel 1.8 #endif
59    
60 nigel 1.1 #ifdef ENABLE_MON
61     # include "mon.h"
62     #endif
63    
64     #define DEBUG 0
65     #include "debug.h"
66    
67    
68     #include "main_macosx.h" // To bridge between main() and misc. classes
69    
70    
71     // Constants
72     const char ROM_FILE_NAME[] = "ROM";
73     const int SCRATCH_MEM_SIZE = 0x10000; // Size of scratch memory area
74    
75    
76 nigel 1.20 static char *bundle = NULL; // If in an OS X application bundle, its path
77    
78    
79 nigel 1.1 // CPU and FPU type, addressing mode
80     int CPUType;
81     bool CPUIs68060;
82     int FPUType;
83     bool TwentyFourBitAddressing;
84    
85    
86     // Global variables
87    
88     #ifdef HAVE_PTHREADS
89    
90     static pthread_mutex_t intflag_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect InterruptFlags
91     #define LOCK_INTFLAGS pthread_mutex_lock(&intflag_lock)
92     #define UNLOCK_INTFLAGS pthread_mutex_unlock(&intflag_lock)
93    
94     #else
95    
96     #define LOCK_INTFLAGS
97     #define UNLOCK_INTFLAGS
98    
99     #endif
100    
101     #if USE_SCRATCHMEM_SUBTERFUGE
102     uint8 *ScratchMem = NULL; // Scratch memory for Mac ROM writes
103     #endif
104    
105 nigel 1.3 #ifdef ENABLE_MON
106 nigel 1.1 static struct sigaction sigint_sa; // sigaction for SIGINT handler
107     static void sigint_handler(...);
108 nigel 1.3 #endif
109 nigel 1.1
110     #if REAL_ADDRESSING
111     static bool lm_area_mapped = false; // Flag: Low Memory area mmap()ped
112     #endif
113    
114    
115 nigel 1.8 /*
116 nigel 1.15 * Helpers to map memory that can be accessed from the Mac side
117 nigel 1.14 */
118    
119 gbeauche 1.17 // NOTE: VM_MAP_32BIT is only used when compiling a 64-bit JIT on specific platforms
120 nigel 1.14 void *vm_acquire_mac(size_t size)
121     {
122 gbeauche 1.17 return vm_acquire(size, VM_MAP_DEFAULT | VM_MAP_32BIT);
123 nigel 1.14 }
124    
125 nigel 1.15 static int vm_acquire_mac_fixed(void *addr, size_t size)
126     {
127 gbeauche 1.17 return vm_acquire_fixed(addr, size, VM_MAP_DEFAULT | VM_MAP_32BIT);
128 nigel 1.15 }
129    
130 nigel 1.14
131     /*
132 nigel 1.10 * SIGSEGV handler
133     */
134    
135 gbeauche 1.18 static sigsegv_return_t sigsegv_handler(sigsegv_info_t *sip)
136 nigel 1.10 {
137 gbeauche 1.18 const uintptr fault_address = (uintptr)sigsegv_get_fault_address(sip);
138 nigel 1.10 #if ENABLE_VOSF
139     // Handle screen fault
140 gbeauche 1.18 extern bool Screen_fault_handler(sigsegv_info_t *sip);
141     if (Screen_fault_handler(sip))
142 nigel 1.10 return SIGSEGV_RETURN_SUCCESS;
143     #endif
144    
145     #ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION
146     // Ignore writes to ROM
147     if (((uintptr)fault_address - (uintptr)ROMBaseHost) < ROMSize)
148     return SIGSEGV_RETURN_SKIP_INSTRUCTION;
149    
150     // Ignore all other faults, if requested
151     if (PrefsFindBool("ignoresegv"))
152     return SIGSEGV_RETURN_SKIP_INSTRUCTION;
153     #endif
154    
155     return SIGSEGV_RETURN_FAILURE;
156     }
157    
158    
159     /*
160 nigel 1.8 * Dump state when everything went wrong after a SEGV
161     */
162    
163 gbeauche 1.18 static void sigsegv_dump_state(sigsegv_info_t *sip)
164 nigel 1.8 {
165 gbeauche 1.18 const sigsegv_address_t fault_address = sigsegv_get_fault_address(sip);
166     const sigsegv_address_t fault_instruction = sigsegv_get_fault_instruction_address(sip);
167 nigel 1.8 fprintf(stderr, "Caught SIGSEGV at address %p", fault_address);
168 gbeauche 1.18 if (fault_instruction != SIGSEGV_INVALID_ADDRESS)
169 nigel 1.8 fprintf(stderr, " [IP=%p]", fault_instruction);
170     fprintf(stderr, "\n");
171     uaecptr nextpc;
172     extern void m68k_dumpstate(uaecptr *nextpc);
173     m68k_dumpstate(&nextpc);
174     #if USE_JIT && JIT_DEBUG
175     extern void compiler_dumpstate(void);
176     compiler_dumpstate();
177     #endif
178     VideoQuitFullScreen();
179     #ifdef ENABLE_MON
180     char *arg[4] = {"mon", "-m", "-r", NULL};
181     mon(3, arg);
182 nigel 1.15 #endif
183 nigel 1.8 QuitEmulator();
184     }
185    
186 nigel 1.1
187     /*
188 nigel 1.20 * Screen fault handler
189     */
190    
191     bool Screen_fault_handler(sigsegv_info_t *sip)
192     {
193     return true;
194     }
195    
196    
197     /*
198 nigel 1.1 * Main program
199     */
200    
201     static void usage(const char *prg_name)
202     {
203     printf("Usage: %s [OPTION...]\n", prg_name);
204     printf("\nUnix options:\n");
205     printf(" --help\n display this usage message\n");
206 nigel 1.8 printf(" --config FILE\n read/write configuration from/to FILE\n");
207 nigel 1.1 printf(" --break ADDRESS\n set ROM breakpoint\n");
208     printf(" --rominfo\n dump ROM information\n");
209 nigel 1.8 LoadPrefs(); // read the prefs file so PrefsPrintUsage() will print the correct default values
210 nigel 1.1 PrefsPrintUsage();
211     exit(0);
212     }
213    
214     int main(int argc, char **argv)
215     {
216     // Initialize variables
217     RAMBaseHost = NULL;
218     ROMBaseHost = NULL;
219     srand(time(NULL));
220     tzset();
221    
222     // Print some info
223     printf(GetString(STR_ABOUT_TEXT1), VERSION_MAJOR, VERSION_MINOR);
224     printf(" %s\n", GetString(STR_ABOUT_TEXT2));
225    
226     // Parse command line arguments
227     for (int i=1; i<argc; i++) {
228     if (strcmp(argv[i], "--help") == 0) {
229     usage(argv[0]);
230     } else if (strncmp(argv[i], "-psn_", 5) == 0) {// OS X process identifier
231     i++;
232     } else if (strcmp(argv[i], "--break") == 0) {
233     i++;
234     if (i < argc)
235     ROMBreakpoint = strtol(argv[i], NULL, 0);
236 nigel 1.8 } else if (strcmp(argv[i], "--config") == 0) {
237     argv[i++] = NULL;
238     if (i < argc) {
239     extern string UserPrefsPath; // from prefs_unix.cpp
240     UserPrefsPath = argv[i];
241     argv[i] = NULL;
242     }
243 nigel 1.1 } else if (strcmp(argv[i], "--rominfo") == 0) {
244     PrintROMInfo = true;
245     } else if (argv[i][0] == '-') {
246     fprintf(stderr, "Unrecognized option '%s'\n", argv[i]);
247     usage(argv[0]);
248     }
249     }
250    
251 nigel 1.10 // Read preferences
252     PrefsInit(argc, argv);
253    
254 nigel 1.1 // Init system routines
255     SysInit();
256    
257 nigel 1.20 // Set the current directory somewhere useful.
258     // Handy for storing the ROM file
259     bundle = strstr(argv[0], "BasiliskII.app/Contents/MacOS/BasiliskII");
260     if (bundle)
261     {
262     while (*bundle != '/')
263     ++bundle;
264    
265     *bundle = 0; // Throw away Contents/... on end of argv[0]
266     bundle = argv[0];
267    
268     chdir(bundle);
269     }
270    
271 nigel 1.1 // Open display, attach to window server,
272     // load pre-instantiated classes from MainMenu.nib, start run loop
273     int i = NSApplicationMain(argc, (const char **)argv);
274     // We currently never get past here, because QuitEmulator() does an exit()
275    
276     // Exit system routines
277     SysExit();
278    
279     // Exit preferences
280     PrefsExit();
281    
282     return i;
283     }
284    
285 nigel 1.7 #define QuitEmulator() { QuitEmuNoExit() ; return NO; }
286 nigel 1.1
287     bool InitEmulator (void)
288     {
289 asvitkine 1.21 const char *vmdir = NULL;
290 nigel 1.1 char str[256];
291    
292    
293 nigel 1.10 // Install the handler for SIGSEGV
294     if (!sigsegv_install_handler(sigsegv_handler)) {
295     sprintf(str, GetString(STR_SIG_INSTALL_ERR), "SIGSEGV", strerror(errno));
296     ErrorAlert(str);
297     QuitEmulator();
298     }
299 nigel 1.8
300     // Register dump state function when we got mad after a segfault
301     sigsegv_set_dump_state(sigsegv_dump_state);
302    
303 nigel 1.1 // Read RAM size
304     RAMSize = PrefsFindInt32("ramsize") & 0xfff00000; // Round down to 1MB boundary
305     if (RAMSize < 1024*1024) {
306     WarningAlert(GetString(STR_SMALL_RAM_WARN));
307     RAMSize = 1024*1024;
308     }
309 nigel 1.15 if (RAMSize > 1023*1024*1024) // Cap to 1023MB (APD crashes at 1GB)
310     RAMSize = 1023*1024*1024;
311 nigel 1.1
312     #if REAL_ADDRESSING || DIRECT_ADDRESSING
313     RAMSize = RAMSize & -getpagesize(); // Round down to page boundary
314     #endif
315    
316     // Initialize VM system
317     vm_init();
318    
319     #if REAL_ADDRESSING
320     // Flag: RAM and ROM are contigously allocated from address 0
321     bool memory_mapped_from_zero = false;
322 nigel 1.15
323     // Make sure to map RAM & ROM at address 0 only on platforms that
324     // supports linker scripts to relocate the Basilisk II executable
325     // above 0x70000000
326     #if HAVE_LINKER_SCRIPT
327     const bool can_map_all_memory = true;
328     #else
329 nigel 1.1 const bool can_map_all_memory = false;
330     #endif
331    
332     // Try to allocate all memory from 0x0000, if it is not known to crash
333 nigel 1.15 if (can_map_all_memory && (vm_acquire_mac_fixed(0, RAMSize + 0x100000) == 0)) {
334 nigel 1.1 D(bug("Could allocate RAM and ROM from 0x0000\n"));
335     memory_mapped_from_zero = true;
336     }
337 nigel 1.15
338 nigel 1.10 #ifndef PAGEZERO_HACK
339 nigel 1.1 // Otherwise, just create the Low Memory area (0x0000..0x2000)
340 nigel 1.15 else if (vm_acquire_mac_fixed(0, 0x2000) == 0) {
341 nigel 1.1 D(bug("Could allocate the Low Memory globals\n"));
342     lm_area_mapped = true;
343     }
344    
345     // Exit on failure
346     else {
347     sprintf(str, GetString(STR_LOW_MEM_MMAP_ERR), strerror(errno));
348     ErrorAlert(str);
349     QuitEmulator();
350     }
351 nigel 1.10 #endif
352 nigel 1.4 #else
353     *str = 0; // Eliminate unused variable warning
354 nigel 1.10 #endif /* REAL_ADDRESSING */
355 nigel 1.1
356     // Create areas for Mac RAM and ROM
357     #if REAL_ADDRESSING
358     if (memory_mapped_from_zero) {
359     RAMBaseHost = (uint8 *)0;
360     ROMBaseHost = RAMBaseHost + RAMSize;
361     }
362     else
363     #endif
364     {
365 nigel 1.14 uint8 *ram_rom_area = (uint8 *)vm_acquire_mac(RAMSize + 0x100000);
366     if (ram_rom_area == VM_MAP_FAILED) {
367 nigel 1.1 ErrorAlert(STR_NO_MEM_ERR);
368     QuitEmulator();
369     }
370 nigel 1.14 RAMBaseHost = ram_rom_area;
371     ROMBaseHost = RAMBaseHost + RAMSize;
372 nigel 1.1 }
373    
374     #if USE_SCRATCHMEM_SUBTERFUGE
375     // Allocate scratch memory
376 nigel 1.15 ScratchMem = (uint8 *)vm_acquire_mac(SCRATCH_MEM_SIZE);
377 nigel 1.1 if (ScratchMem == VM_MAP_FAILED) {
378     ErrorAlert(STR_NO_MEM_ERR);
379     QuitEmulator();
380     }
381     ScratchMem += SCRATCH_MEM_SIZE/2; // ScratchMem points to middle of block
382     #endif
383    
384     #if DIRECT_ADDRESSING
385     // RAMBaseMac shall always be zero
386     MEMBaseDiff = (uintptr)RAMBaseHost;
387     RAMBaseMac = 0;
388     ROMBaseMac = Host2MacAddr(ROMBaseHost);
389     #endif
390     #if REAL_ADDRESSING
391 nigel 1.15 RAMBaseMac = Host2MacAddr(RAMBaseHost);
392     ROMBaseMac = Host2MacAddr(ROMBaseHost);
393 nigel 1.1 #endif
394     D(bug("Mac RAM starts at %p (%08x)\n", RAMBaseHost, RAMBaseMac));
395     D(bug("Mac ROM starts at %p (%08x)\n", ROMBaseHost, ROMBaseMac));
396    
397     // Get rom file path from preferences
398     const char *rom_path = PrefsFindString("rom");
399 nigel 1.6 if ( ! rom_path )
400 nigel 1.20 if ( bundle )
401     WarningAlert("No rom pathname set. Trying BasiliskII.app/ROM");
402     else
403 nigel 1.6 WarningAlert("No rom pathname set. Trying ./ROM");
404 nigel 1.1
405     // Load Mac ROM
406     int rom_fd = open(rom_path ? rom_path : ROM_FILE_NAME, O_RDONLY);
407     if (rom_fd < 0) {
408     ErrorAlert(STR_NO_ROM_FILE_ERR);
409     QuitEmulator();
410     }
411     printf(GetString(STR_READING_ROM_FILE));
412     ROMSize = lseek(rom_fd, 0, SEEK_END);
413     if (ROMSize != 64*1024 && ROMSize != 128*1024 && ROMSize != 256*1024 && ROMSize != 512*1024 && ROMSize != 1024*1024) {
414     ErrorAlert(STR_ROM_SIZE_ERR);
415     close(rom_fd);
416     QuitEmulator();
417     }
418     lseek(rom_fd, 0, SEEK_SET);
419     if (read(rom_fd, ROMBaseHost, ROMSize) != (ssize_t)ROMSize) {
420     ErrorAlert(STR_ROM_FILE_READ_ERR);
421     close(rom_fd);
422     QuitEmulator();
423     }
424    
425    
426     // Initialize everything
427 asvitkine 1.21 if (!InitAll(vmdir))
428 nigel 1.1 QuitEmulator();
429     D(bug("Initialization complete\n"));
430    
431    
432     #ifdef ENABLE_MON
433     // Setup SIGINT handler to enter mon
434     sigemptyset(&sigint_sa.sa_mask);
435     sigint_sa.sa_handler = (void (*)(int))sigint_handler;
436     sigint_sa.sa_flags = 0;
437     sigaction(SIGINT, &sigint_sa, NULL);
438     #endif
439    
440    
441     return YES;
442     }
443    
444     #undef QuitEmulator()
445    
446    
447     /*
448     * Quit emulator
449     */
450    
451     void QuitEmuNoExit()
452     {
453     D(bug("QuitEmulator\n"));
454    
455     // Exit 680x0 emulation
456     Exit680x0();
457    
458     // Deinitialize everything
459     ExitAll();
460    
461     // Free ROM/RAM areas
462     if (RAMBaseHost != VM_MAP_FAILED) {
463 nigel 1.14 vm_release(RAMBaseHost, RAMSize + 0x100000);
464 nigel 1.1 RAMBaseHost = NULL;
465 nigel 1.15 ROMBaseHost = NULL;
466 nigel 1.1 }
467    
468     #if USE_SCRATCHMEM_SUBTERFUGE
469     // Delete scratch memory area
470     if (ScratchMem != (uint8 *)VM_MAP_FAILED) {
471     vm_release((void *)(ScratchMem - SCRATCH_MEM_SIZE/2), SCRATCH_MEM_SIZE);
472     ScratchMem = NULL;
473     }
474     #endif
475    
476     #if REAL_ADDRESSING
477     // Delete Low Memory area
478     if (lm_area_mapped)
479     vm_release(0, 0x2000);
480     #endif
481    
482     // Exit VM wrappers
483     vm_exit();
484    
485     // Exit system routines
486     SysExit();
487    
488     // Exit preferences
489     PrefsExit();
490     }
491    
492     void QuitEmulator(void)
493     {
494     QuitEmuNoExit();
495 nigel 1.6
496     // Stop run loop?
497     [NSApp terminate: nil];
498    
499 nigel 1.1 exit(0);
500     }
501    
502    
503     /*
504     * Code was patched, flush caches if neccessary (i.e. when using a real 680x0
505     * or a dynamically recompiling emulator)
506     */
507    
508     void FlushCodeCache(void *start, uint32 size)
509     {
510 nigel 1.8 #if USE_JIT
511 nigel 1.20 if (UseJIT)
512 gbeauche 1.16 flush_icache_range((uint8 *)start, size);
513 nigel 1.8 #endif
514 nigel 1.1 }
515    
516    
517     /*
518     * SIGINT handler, enters mon
519     */
520    
521     #ifdef ENABLE_MON
522     static void sigint_handler(...)
523     {
524     uaecptr nextpc;
525     extern void m68k_dumpstate(uaecptr *nextpc);
526     m68k_dumpstate(&nextpc);
527     VideoQuitFullScreen();
528     char *arg[4] = {"mon", "-m", "-r", NULL};
529     mon(3, arg);
530     QuitEmulator();
531     }
532     #endif
533    
534    
535 nigel 1.14 #ifdef HAVE_PTHREADS
536     /*
537     * Pthread configuration
538     */
539    
540     void Set_pthread_attr(pthread_attr_t *attr, int priority)
541     {
542     pthread_attr_init(attr);
543     #if defined(_POSIX_THREAD_PRIORITY_SCHEDULING)
544     // Some of these only work for superuser
545     if (geteuid() == 0) {
546     pthread_attr_setinheritsched(attr, PTHREAD_EXPLICIT_SCHED);
547     pthread_attr_setschedpolicy(attr, SCHED_FIFO);
548     struct sched_param fifo_param;
549     fifo_param.sched_priority = ((sched_get_priority_min(SCHED_FIFO)
550     + sched_get_priority_max(SCHED_FIFO))
551     / 2 + priority);
552     pthread_attr_setschedparam(attr, &fifo_param);
553     }
554     if (pthread_attr_setscope(attr, PTHREAD_SCOPE_SYSTEM) != 0) {
555     #ifdef PTHREAD_SCOPE_BOUND_NP
556     // If system scope is not available (eg. we're not running
557     // with CAP_SCHED_MGT capability on an SGI box), try bound
558     // scope. It exposes pthread scheduling to the kernel,
559     // without setting realtime priority.
560     pthread_attr_setscope(attr, PTHREAD_SCOPE_BOUND_NP);
561     #endif
562     }
563     #endif
564     }
565     #endif // HAVE_PTHREADS
566    
567    
568 nigel 1.1 /*
569     * Mutexes
570     */
571    
572     #ifdef HAVE_PTHREADS
573    
574     struct B2_mutex {
575 nigel 1.10 B2_mutex() {
576     pthread_mutexattr_t attr;
577     pthread_mutexattr_init(&attr);
578     // Initialize the mutex for priority inheritance --
579     // required for accurate timing.
580     #ifdef HAVE_PTHREAD_MUTEXATTR_SETPROTOCOL
581     pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT);
582     #endif
583     #if defined(HAVE_PTHREAD_MUTEXATTR_SETTYPE) && defined(PTHREAD_MUTEX_NORMAL)
584     pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL);
585     #endif
586     #ifdef HAVE_PTHREAD_MUTEXATTR_SETPSHARED
587     pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_PRIVATE);
588     #endif
589     pthread_mutex_init(&m, &attr);
590     pthread_mutexattr_destroy(&attr);
591     }
592     ~B2_mutex() {
593     pthread_mutex_trylock(&m); // Make sure it's locked before
594     pthread_mutex_unlock(&m); // unlocking it.
595     pthread_mutex_destroy(&m);
596     }
597 nigel 1.1 pthread_mutex_t m;
598     };
599    
600     B2_mutex *B2_create_mutex(void)
601     {
602     return new B2_mutex;
603     }
604    
605     void B2_lock_mutex(B2_mutex *mutex)
606     {
607     pthread_mutex_lock(&mutex->m);
608     }
609    
610     void B2_unlock_mutex(B2_mutex *mutex)
611     {
612     pthread_mutex_unlock(&mutex->m);
613     }
614    
615     void B2_delete_mutex(B2_mutex *mutex)
616     {
617     delete mutex;
618     }
619    
620     #else
621    
622     struct B2_mutex {
623     int dummy;
624     };
625    
626     B2_mutex *B2_create_mutex(void)
627     {
628     return new B2_mutex;
629     }
630    
631     void B2_lock_mutex(B2_mutex *mutex)
632     {
633     }
634    
635     void B2_unlock_mutex(B2_mutex *mutex)
636     {
637     }
638    
639     void B2_delete_mutex(B2_mutex *mutex)
640     {
641     delete mutex;
642     }
643    
644     #endif
645    
646    
647     /*
648     * Interrupt flags (must be handled atomically!)
649     */
650    
651     uint32 InterruptFlags = 0;
652    
653     void SetInterruptFlag(uint32 flag)
654     {
655     LOCK_INTFLAGS;
656     InterruptFlags |= flag;
657     UNLOCK_INTFLAGS;
658     }
659    
660     void ClearInterruptFlag(uint32 flag)
661     {
662     LOCK_INTFLAGS;
663     InterruptFlags &= ~flag;
664     UNLOCK_INTFLAGS;
665     }
666    
667    
668     /*
669     * Display error alert
670     */
671    
672     void ErrorAlert(const char *text)
673     {
674     NSString *title = [NSString stringWithCString:
675     GetString(STR_ERROR_ALERT_TITLE) ];
676     NSString *error = [NSString stringWithCString: text];
677     NSString *button = [NSString stringWithCString: GetString(STR_QUIT_BUTTON) ];
678    
679     NSLog(error);
680 nigel 1.10 if ( PrefsFindBool("nogui") )
681     return;
682     VideoQuitFullScreen();
683 nigel 1.1 NSRunCriticalAlertPanel(title, error, button, nil, nil);
684     }
685    
686    
687     /*
688     * Display warning alert
689     */
690    
691     void WarningAlert(const char *text)
692     {
693     NSString *title = [NSString stringWithCString:
694     GetString(STR_WARNING_ALERT_TITLE) ];
695     NSString *warning = [NSString stringWithCString: text];
696     NSString *button = [NSString stringWithCString: GetString(STR_OK_BUTTON) ];
697    
698     NSLog(warning);
699 nigel 1.10 if ( PrefsFindBool("nogui") )
700     return;
701     VideoQuitFullScreen();
702 nigel 1.1 NSRunAlertPanel(title, warning, button, nil, nil);
703     }
704    
705    
706     /*
707     * Display choice alert
708     */
709    
710     bool ChoiceAlert(const char *text, const char *pos, const char *neg)
711     {
712     NSString *title = [NSString stringWithCString:
713     GetString(STR_WARNING_ALERT_TITLE) ];
714     NSString *warning = [NSString stringWithCString: text];
715     NSString *yes = [NSString stringWithCString: pos];
716     NSString *no = [NSString stringWithCString: neg];
717    
718     return NSRunInformationalAlertPanel(title, warning, yes, no, nil);
719     }