ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/MacOSX/main_macosx.mm
(Generate patch)

Comparing BasiliskII/src/MacOSX/main_macosx.mm (file contents):
Revision 1.16 by gbeauche, 2006-05-08T16:56:07Z vs.
Revision 1.23 by asvitkine, 2011-03-11T16:43:09Z

# Line 5 | Line 5
5   *                                              Based (in a small way) on the default main.m,
6                                                  and on Basilisk's main_unix.cpp
7   *
8 < *  Basilisk II (C) 1997-2005 Christian Bauer
8 > *  Basilisk II (C) 1997-2008 Christian Bauer
9   *
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
# Line 40 | Line 40
40   using std::string;
41  
42   #include "cpu_emulation.h"
43 < #include "macos_util_macosx.h"
44 < #include "main.h"
43 > #include "sys.h"
44 > #include "rom_patches.h"
45 > #include "xpram.h"
46 > #include "video.h"
47   #include "prefs.h"
48   #include "prefs_editor.h"
49 < #include "rom_patches.h"
48 < #include "sigsegv.h"
49 < #include "sys.h"
49 > #include "macos_util_macosx.h"
50   #include "user_strings.h"
51   #include "version.h"
52 < #include "video.h"
52 > #include "main.h"
53   #include "vm_alloc.h"
54 < #include "xpram.h"
54 > #include "sigsegv.h"
55  
56   #if USE_JIT
57 < extern void flush_icache_range(uint8 *start, uint32 size);  // from compemu_support.cpp
57 > extern void flush_icache_range(uint8 *start, uint32 size); // from compemu_support.cpp
58   #endif
59  
60   #ifdef ENABLE_MON
# Line 73 | Line 73 | const char ROM_FILE_NAME[] = "ROM";
73   const int SCRATCH_MEM_SIZE = 0x10000;   // Size of scratch memory area
74  
75  
76 + static char *bundle = NULL;             // If in an OS X application bundle, its path
77 +
78 +
79   // CPU and FPU type, addressing mode
80   int CPUType;
81   bool CPUIs68060;
82   int FPUType;
83   bool TwentyFourBitAddressing;
81 bool ThirtyThreeBitAddressing = false;
84  
85  
86   // Global variables
# Line 114 | Line 116 | static bool lm_area_mapped = false;    // F
116   *  Helpers to map memory that can be accessed from the Mac side
117   */
118  
119 < // NOTE: VM_MAP_33BIT is only used when compiling a 64-bit JIT on specific platforms
119 > // NOTE: VM_MAP_32BIT is only used when compiling a 64-bit JIT on specific platforms
120   void *vm_acquire_mac(size_t size)
121   {
122 <        void *m = vm_acquire(size, VM_MAP_DEFAULT | VM_MAP_33BIT);
121 < #ifdef USE_33BIT_ADDRESSING
122 <        if (m == VM_MAP_FAILED) {
123 <                printf("WARNING: Cannot acquire memory in 33-bit address space (%s)\n", strerror(errno));
124 <                ThirtyThreeBitAddressing = false;
125 <                m = vm_acquire(size);
126 <        }
127 < #endif
128 <        return m;
122 >        return vm_acquire(size, VM_MAP_DEFAULT | VM_MAP_32BIT);
123   }
124  
125   static int vm_acquire_mac_fixed(void *addr, size_t size)
126   {
127 <        int ret = vm_acquire_fixed(addr, size, VM_MAP_DEFAULT | VM_MAP_33BIT);
134 < #ifdef USE_33BIT_ADDRESSING
135 <        if (ret < 0) {
136 <                printf("WARNING: Cannot acquire fixed memory in 33-bit address space (%s)\n", strerror(errno));
137 <                ThirtyThreeBitAddressing = false;
138 <                ret = vm_acquire_fixed(addr, size);
139 <        }
140 < #endif
141 <        return ret;
127 >        return vm_acquire_fixed(addr, size, VM_MAP_DEFAULT | VM_MAP_32BIT);
128   }
129  
130  
# Line 146 | Line 132 | static int vm_acquire_mac_fixed(void *ad
132   *  SIGSEGV handler
133   */
134  
135 < static sigsegv_return_t sigsegv_handler(sigsegv_address_t fault_address,
150 <                                                                                sigsegv_address_t fault_instruction)
135 > static sigsegv_return_t sigsegv_handler(sigsegv_info_t *sip)
136   {
137 +        const uintptr fault_address = (uintptr)sigsegv_get_fault_address(sip);
138   #if ENABLE_VOSF
139          // Handle screen fault
140 <        extern bool Screen_fault_handler(sigsegv_address_t, sigsegv_address_t);
141 <        if (Screen_fault_handler(fault_address, fault_instruction))
140 >        extern bool Screen_fault_handler(sigsegv_info_t *sip);
141 >        if (Screen_fault_handler(sip))
142                  return SIGSEGV_RETURN_SUCCESS;
143   #endif
144  
# Line 169 | Line 155 | static sigsegv_return_t sigsegv_handler(
155          return SIGSEGV_RETURN_FAILURE;
156   }
157  
172
158   /*
159   *  Dump state when everything went wrong after a SEGV
160   */
161  
162 < static void sigsegv_dump_state(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction)
162 > static void sigsegv_dump_state(sigsegv_info_t *sip)
163   {
164 +        const sigsegv_address_t fault_address = sigsegv_get_fault_address(sip);
165 +        const sigsegv_address_t fault_instruction = sigsegv_get_fault_instruction_address(sip);
166          fprintf(stderr, "Caught SIGSEGV at address %p", fault_address);
167 <        if (fault_instruction != SIGSEGV_INVALID_PC)
167 >        if (fault_instruction != SIGSEGV_INVALID_ADDRESS)
168                  fprintf(stderr, " [IP=%p]", fault_instruction);
169          fprintf(stderr, "\n");
170          uaecptr nextpc;
# Line 197 | Line 184 | static void sigsegv_dump_state(sigsegv_a
184  
185  
186   /*
187 + * Screen fault handler
188 + */
189 +
190 + bool Screen_fault_handler(sigsegv_info_t *sip)
191 + {
192 +        return true;
193 + }
194 +
195 +
196 + /*
197   *  Main program
198   */
199  
200   static void usage(const char *prg_name)
201   {
202 <        printf("Usage: %s [OPTION...]\n", prg_name);
203 <        printf("\nUnix options:\n");
204 <        printf("  --help\n    display this usage message\n");
205 <        printf("  --config FILE\n    read/write configuration from/to FILE\n");
206 <        printf("  --break ADDRESS\n    set ROM breakpoint\n");
207 <        printf("  --rominfo\n    dump ROM information\n");
208 <        LoadPrefs(); // read the prefs file so PrefsPrintUsage() will print the correct default values
202 >        printf(
203 >                "Usage: %s [OPTION...]\n"
204 >                "\nUnix options:\n"
205 >                "  --config FILE\n    read/write configuration from/to FILE\n"
206 >                "  --break ADDRESS\n    set ROM breakpoint\n"
207 >                "  --rominfo\n    dump ROM information\n", prg_name
208 >        );
209 >        LoadPrefs(NULL); // read the prefs file so PrefsPrintUsage() will print the correct default values
210          PrefsPrintUsage();
211          exit(0);
212   }
213  
214   int main(int argc, char **argv)
215   {
216 +        const char *vmdir = NULL;
217 +        char str[256];
218 +
219          // Initialize variables
220          RAMBaseHost = NULL;
221          ROMBaseHost = NULL;
# Line 230 | Line 231 | int main(int argc, char **argv)
231                  if (strcmp(argv[i], "--help") == 0) {
232                          usage(argv[0]);
233                  } else if (strncmp(argv[i], "-psn_", 5) == 0) {// OS X process identifier
234 <                        i++;
234 >                        argv[i++] = NULL;
235                  } else if (strcmp(argv[i], "--break") == 0) {
236 <                        i++;
237 <                        if (i < argc)
236 >                        argv[i++] = NULL;
237 >                        if (i < argc) {
238                                  ROMBreakpoint = strtol(argv[i], NULL, 0);
239 +                                argv[i] = NULL;
240 +                        }
241                  } else if (strcmp(argv[i], "--config") == 0) {
242                          argv[i++] = NULL;
243                          if (i < argc) {
# Line 243 | Line 246 | int main(int argc, char **argv)
246                                  argv[i] = NULL;
247                          }
248                  } else if (strcmp(argv[i], "--rominfo") == 0) {
249 +                        argv[i] = NULL;
250                          PrintROMInfo = true;
251 <                } else if (argv[i][0] == '-') {
252 <                        fprintf(stderr, "Unrecognized option '%s'\n", argv[i]);
253 <                        usage(argv[0]);
251 >                }
252 >        }
253 >
254 >        // Remove processed arguments
255 >        for (int i=1; i<argc; i++) {
256 >                int k;
257 >                for (k=i; k<argc; k++)
258 >                        if (argv[k] != NULL)
259 >                                break;
260 >                if (k > i) {
261 >                        k -= i;
262 >                        for (int j=i+k; j<argc; j++)
263 >                                argv[j-k] = argv[j];
264 >                        argc -= k;
265                  }
266          }
267  
268          // Read preferences
269 <        PrefsInit(argc, argv);
269 >        PrefsInit(vmdir, argc, argv);
270 >
271 >        // Any command line arguments left?
272 >        for (int i=1; i<argc; i++) {
273 >                if (argv[i][0] == '-') {
274 >                        fprintf(stderr, "Unrecognized option '%s'\n", argv[i]);
275 >                        usage(argv[0]);
276 >                }
277 >        }
278  
279          // Init system routines
280          SysInit();
281  
282 +        // Set the current directory somewhere useful.
283 +        // Handy for storing the ROM file
284 +        bundle = strstr(argv[0], "BasiliskII.app/Contents/MacOS/BasiliskII");
285 +        if (bundle)
286 +        {
287 +                while (*bundle != '/')
288 +                        ++bundle;
289 +
290 +                *bundle = 0;  // Throw away Contents/... on end of argv[0]
291 +                bundle = argv[0];
292 +
293 +                chdir(bundle);
294 +        }
295 +
296          // Open display, attach to window server,
297          // load pre-instantiated classes from MainMenu.nib, start run loop
298          int i = NSApplicationMain(argc, (const char **)argv);
# Line 274 | Line 311 | int main(int argc, char **argv)
311  
312   bool InitEmulator (void)
313   {
314 +        const char *vmdir = NULL;
315          char str[256];
316  
317  
# Line 303 | Line 341 | bool InitEmulator (void)
341          // Initialize VM system
342          vm_init();
343  
306 #ifdef USE_33BIT_ADDRESSING
307        // Speculatively enables 33-bit addressing
308        ThirtyThreeBitAddressing = true;
309 #endif
310
344   #if REAL_ADDRESSING
345          // Flag: RAM and ROM are contigously allocated from address 0
346          bool memory_mapped_from_zero = false;
# Line 389 | Line 422 | bool InitEmulator (void)
422          // Get rom file path from preferences
423          const char *rom_path = PrefsFindString("rom");
424          if ( ! rom_path )
425 +          if ( bundle )
426 +                WarningAlert("No rom pathname set. Trying BasiliskII.app/ROM");
427 +          else
428                  WarningAlert("No rom pathname set. Trying ./ROM");
429  
430          // Load Mac ROM
# Line 413 | Line 449 | bool InitEmulator (void)
449  
450  
451          // Initialize everything
452 <        if (!InitAll())
452 >        if (!InitAll(vmdir))
453                  QuitEmulator();
454          D(bug("Initialization complete\n"));
455  
# Line 497 | Line 533 | void QuitEmulator(void)
533   void FlushCodeCache(void *start, uint32 size)
534   {
535   #if USE_JIT
536 <    if (UseJIT)
536 >        if (UseJIT)
537                  flush_icache_range((uint8 *)start, size);
538   #endif
539   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines