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

Comparing BasiliskII/src/MacOSX/Emulator.mm (file contents):
Revision 1.4 by nigel, 2002-12-18T11:50:12Z vs.
Revision 1.13 by gbeauche, 2008-01-01T09:40:32Z

# Line 4 | Line 4
4   *
5   *      $Id$
6   *
7 < *  Basilisk II (C) 1997-2002 Christian Bauer
7 > *  Basilisk II (C) 1997-2008 Christian Bauer
8   *
9   *  This program is free software; you can redistribute it and/or modify
10   *  it under the terms of the GNU General Public License as published by
# Line 24 | Line 24
24   #import "Emulator.h"
25   #import "EmulatorView.h"
26  
27 @implementation Emulator
28
27   #import "sysdeps.h"                     // Types used in Basilisk C++ code
28  
29   #import "main_macosx.h"         // Prototypes for QuitEmuNoExit() and InitEmulator()
30   #import "misc_macosx.h"         // Some other prototypes
31   #import "video_macosx.h"        // Some window/view globals
32  
33 < #import <adb.h>
34 < #import <main.h>
35 < #import <prefs.h>
36 < #import <timer.h>
33 > #import "adb.h"
34 > #import "main.h"
35 > #import "prefs.h"
36 > #import "timer.h"
37  
38 < #undef check()                          // memory.h defines a check macro, clashes with an OS X one?
39 < #import <cpu_emulation.h>
38 > #undef check                            // memory.h defines a check macro, clashes with an OS X one?
39 > #import "cpu_emulation.h"
40  
41   #define DEBUG 0
42 < #import <debug.h>
42 > #import "debug.h"
43 >
44 > @implementation Emulator
45  
46   // NSWindow method, which is invoked via delegation
47  
# Line 94 | Line 94
94          //[win setHasShadow: NO];               // This causes view & window to now be drawn correctly
95          [win useOptimizedDrawing: YES];                
96  
97 //      [win center];
97          [win makeKeyAndOrderFront:self];
98  
100 //      [self resizeWinToWidth:x Height:y];
101
99          if ( redrawDelay )
100                  [speed setFloatValue: 1.0 / redrawDelay];
101          else
# Line 147 | Line 144
144                  [self Resume: self];
145   }
146  
147 + #ifdef NIGEL
148 + - (IBAction) EjectCD: (id)sender;
149 + {
150 +        NSString        *path;
151 +        const char      *cdrom = PrefsFindString("cdrom");
152 +
153 +        if ( cdrom )
154 +        {
155 +        #include <sys/param.h>
156 +        #define KERNEL
157 +        #include <sys/mount.h>
158 +
159 +                struct statfs buf;
160 +                if ( fsstat(path, &buf) < 0 )
161 +                        return;
162 +
163 +                path = [NSString stringWithCString: cdrom];
164 +
165 +                [[NSWorkspace sharedWorkspace] unmountAndEjectDeviceAtPath: path];
166 + //              [path release];
167 +        }
168 + }
169 + #endif
170 +
171   - (IBAction) Interrupt: (id)sender;
172   {
173          WarningSheet (@"Interrupt action not yet supported", win);
# Line 169 | Line 190
190  
191   - (IBAction) Restart: (id)sender
192   {
193 +        if ( ! running )
194 +        {
195 +                running = YES;                                          // Start emulator
196 +                [self runUpdate];
197 +                [self Resume: nil];
198 +        }
199 +
200          if ( running )
201 < //              reset680x0();
201 > #ifdef UAE_CPU_HAS_RESET
202 >                reset680x0();
203 > #else
204          {
205                  uaeCreated = NO;
206                  [redraw suspend];
207                  NSLog (@"%s - uae_cpu reset not yet supported, will try to fake it",
208                                  __PRETTY_FUNCTION__);
209  
210 < //              [screen blacken];
211 <                [screen setNeedsDisplay: YES];
210 >                [screen clear];
211 >                [screen display];
212  
213                  [emul terminate]; QuitEmuNoExit();
214  
215 +
216 +                // OK. We have killed & cleaned up. Now, start afresh:
217 +        #include <sys.h>
218 +                int     argc = 0;
219 +                char **argv;
220 +
221 +                PrefsInit(argc, argv);
222 +                SysInit();
223 +
224                  emul = [NNThread new];
225                  [emul perform:@selector(emulThread) of:self];
226                  [emul start];
227  
228                  if ( display_type != DISPLAY_SCREEN )
229                          [redraw resume];
191                uaeCreated = YES;
230          }
231 + #endif
232   }
233  
234   - (IBAction) Resume: (id)sender
# Line 314 | Line 353 | uint8 lastXPRAM[XPRAM_SIZE];           // Copy of
353   #endif
354          emul   = [NNThread      new];
355          RTC    = [NNTimer       new];
356 <        redraw = [NNTimer       new];
356 >        redraw = [[NNTimer      alloc] initWithAutoRelPool];
357          tick   = [NNTimer       new];
358          xPRAM  = [NNTimer       new];
359  
# Line 351 | Line 390 | uint8 lastXPRAM[XPRAM_SIZE];           // Copy of
390          [redraw invalidate]; [redraw release]; redraw = nil;
391          [RTC    invalidate]; [RTC        release]; RTC    = nil;
392          [xPRAM  invalidate]; [xPRAM      release]; xPRAM  = nil;
354        if ( uaeCreated )
355                QuitEmuNoExit();
393   }
394  
395   - (void) emulThread
396   {
360        extern uint8            *RAMBaseHost, *ROMBaseHost;
397          NSAutoreleasePool       *pool = [NSAutoreleasePool new];
398  
399 <        InitEmulator();
399 >        if ( ! InitEmulator() )
400 >        {
401 >                [redraw suspend];               // Stop the barberpole
402  
403 <        if ( RAMBaseHost == NULL || ROMBaseHost == NULL )
404 <                ErrorSheet(@"Cannot start Emulator",
367 <                                   @"Emulator memory not allocated", nil, win);
403 >                ErrorSheet(@"Cannot start Emulator", @"", @"Quit", win);
404 >        }
405          else
406          {
407                  memcpy(lastXPRAM, XPRAM, XPRAM_SIZE);
# Line 374 | Line 411 | uint8 lastXPRAM[XPRAM_SIZE];           // Copy of
411                  while ( screen == nil ) // If we are still loading from Nib?
412                          [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow: 1.0]];
413  
414 < //              [screen readyToDraw];
378 <                [self   runUpdate];
414 >                [self   runUpdate];             // Set the window close gadget to dimpled
415  
416                  Start680x0();                   // Start 68k and jump to ROM boot routine
417  
418                  puts ("Emulator exited normally");
419          }
420  
385        running = NO;
386        uaeCreated = NO;
387        [self runUpdate];                       // Update button & dimple
421          [pool release];
422 <        [self exitThreads];
422 >        QuitEmulator();
423   }
424  
425   - (void) RTCinterrupt
426   {
427 <        if ( uaeCreated )
428 <                WriteMacInt32 (0x20c, TimerDateTime() );        // Update MacOS time
427 >        if ( ! uaeCreated )
428 >                return;
429 >
430 >        WriteMacInt32 (0x20c, TimerDateTime() );        // Update MacOS time
431 >
432 >        SetInterruptFlag(INTFLAG_1HZ);
433 >        TriggerInterrupt();
434   }
435  
436   - (void) redrawScreen
437   {
438          if ( display_type == DISPLAY_SCREEN )
439          {
440 <                NSLog(@"Why was redrawScreen() called?");
440 >                NSLog(@"We are in fullscreen mode - why was redrawScreen() called?");
441                  return;
442          }
443          [barberPole animate:self];                      // wobble the pole
444          [screen setNeedsDisplay: YES];          // redisplay next time through runLoop
445          // Or, use a direct method. e.g.
446 <        //      [screen cgDrawInto: ...];
446 >        //      [screen display] or [screen cgDrawInto: ...];
447   }
448  
449   #include <main.h>                               // For #define INTFLAG_60HZ

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines