2
* E-UAE - The portable Amiga emulator
4
* Main entry point for our Cocoa-ized app and support
7
* Based on SDLMain.m from libSDL.
8
* Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
9
* Non-NIB-Code & other changes: Max Horn <max@quendi.de>
27
#import <sys/param.h> /* for MAXPATHLEN */
30
/* Use this flag to determine whether we use CPS (docking) or not */
34
/* Portions of CPS.h */
35
typedef struct CPSProcessSerNum
41
extern OSErr CPSGetCurrentProcess (CPSProcessSerNum *psn);
42
extern OSErr CPSEnableForegroundOperation (CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
43
extern OSErr CPSSetFrontProcess (CPSProcessSerNum *psn);
45
#endif /* SDL_USE_CPS */
51
NSString *getApplicationName (void)
54
NSString *appName = 0;
56
/* Determine the application name */
57
dict = (NSDictionary *) CFBundleGetInfoDictionary (CFBundleGetMainBundle ());
59
appName = [dict objectForKey: @"CFBundleName"];
61
if (![appName length])
62
appName = [[NSProcessInfo processInfo] processName];
67
/* Fix warnings generated when using the setAppleMenu method and compiling
69
@interface NSApplication (EUAE)
70
- (void)setAppleMenu:(NSMenu *)menu;
74
@interface EUAE_Application : NSApplication
77
@implementation EUAE_Application
79
/* Invoked from the Quit menu item */
80
- (void)terminate:(id)sender
83
/* Post a SDL_QUIT event */
85
event.type = SDL_QUIT;
86
SDL_PushEvent (&event);
92
- (void)sendEvent:(NSEvent *)anEvent
94
if (NSKeyDown == [anEvent type] || NSKeyUp == [anEvent type]) {
95
if ([anEvent modifierFlags] & NSCommandKeyMask)
96
[super sendEvent: anEvent];
98
[super sendEvent: anEvent];
104
/* The main class of the application, the application's delegate */
105
@implementation EUAE_Main
107
/* Set the working directory to the .app's parent directory */
108
- (void) setupWorkingDirectory:(BOOL)shouldChdir
111
char parentdir[MAXPATHLEN];
112
CFURLRef url = CFBundleCopyBundleURL (CFBundleGetMainBundle());
113
CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent (0, url);
115
if (CFURLGetFileSystemRepresentation (url2, true, (UInt8 *)parentdir, MAXPATHLEN)) {
116
chdir (parentdir) == 0; /* chdir to the binary app's parent */
123
static void setApplicationMenu (void)
125
/* warning: this code is very odd */
127
NSMenuItem *menuItem;
131
appName = getApplicationName ();
132
appleMenu = [[NSMenu alloc] initWithTitle:@""];
135
title = [@"About " stringByAppendingString:appName];
136
[appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
138
[appleMenu addItem:[NSMenuItem separatorItem]];
140
title = [@"Hide " stringByAppendingString:appName];
141
/* E-UAE: Removed @"h" key equivalent so it doesn't interfere with using the command key as an emulated amiga key */
142
[appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@""];
144
/* E-UAE: Removed @"h" key equivalent so it doesn't interfere with using the command key as an emulated amiga key */
145
menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@""];
146
[menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
148
[appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
150
[appleMenu addItem:[NSMenuItem separatorItem]];
152
title = [@"Quit " stringByAppendingString:appName];
153
/* E-UAE: Removed @"q" key equivalent so it doesn't interfere with using the command key as an emulated amiga key */
154
[appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@""];
157
/* Put menu into the menubar */
158
menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
159
[menuItem setSubmenu:appleMenu];
160
[[NSApp mainMenu] addItem:menuItem];
162
/* Tell the application object that this is now the application menu */
163
[NSApp setAppleMenu:appleMenu];
165
/* Finally give up our references to the objects */
170
/* Create a window menu */
171
static void setupWindowMenu (void)
174
NSMenuItem *windowMenuItem;
175
NSMenuItem *menuItem;
177
windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
179
/* "Minimize" item */
180
/* E-UAE: Removed @"m" key equivalent so it doesn't interfere with using the command key as an emulated amiga key */
181
menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@""];
182
[windowMenu addItem:menuItem];
185
/* Put menu into the menubar */
186
windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
187
[windowMenuItem setSubmenu:windowMenu];
188
[[NSApp mainMenu] addItem:windowMenuItem];
190
/* Tell the application object that this is now the window menu */
191
[NSApp setWindowsMenu:windowMenu];
193
/* Finally give up our references to the objects */
194
[windowMenu release];
195
[windowMenuItem release];
198
/* Replacement for NSApplicationMain */
199
static void CustomApplicationMain (int argc, char **argv)
201
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
202
EUAE_Main *euae_main;
204
/* Ensure the application object is initialised */
205
[EUAE_Application sharedApplication];
209
CPSProcessSerNum PSN;
210
/* Tell the dock about us */
211
if (!CPSGetCurrentProcess(&PSN))
212
if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
213
if (!CPSSetFrontProcess(&PSN))
214
[EUAE_Application sharedApplication];
216
#endif /* SDL_USE_CPS */
218
/* Set up the menubar */
219
[NSApp setMainMenu:[[NSMenu alloc] init]];
220
setApplicationMenu ();
223
/* Create SDLMain and make it the app delegate */
224
euae_main = [[EUAE_Main alloc] init];
225
[NSApp setDelegate:euae_main];
227
/* Start the main event loop */
234
- (BOOL) applicationShouldOpenUntitledFile:(NSApplication *)sender
239
extern NSString *finderLaunchFilename;
240
- (BOOL) application:(NSApplication *)theApplication openFile:(NSString *)filename
242
if (filename != nil) {
243
if (finderLaunchFilename != nil)
244
[finderLaunchFilename release];
245
finderLaunchFilename = [[NSString alloc] initWithString:filename];
252
/* Called when the internal event loop has just started running */
253
- (void) applicationDidFinishLaunching: (NSNotification *) note
255
/* Set the working directory to the .app's parent directory */
256
[self setupWorkingDirectory:gFinderLaunch];
259
setenv ("SDL_ENABLEAPPEVENTS", "1", 1);
266
/* Hand off to main application code */
267
real_main (gArgc, gArgv);
270
/* We're done, thank you for playing */
281
/* Main entry point to executable - should *not* be SDL_main! */
282
int main (int argc, char **argv)
284
char logfile_path[MAX_PATH] = "~/Library/Logs/E-UAE.log";
286
/* Copy the arguments into a global variable */
287
/* This is passed if we are launched by double-clicking */
288
if (argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
292
cfgfile_subst_home (logfile_path, MAX_PATH);
293
set_logfile (logfile_path);
300
CustomApplicationMain (argc, argv);
307
void setup_brkhandler (void)
313
* Handle target-specific cfgfile options
315
void target_save_options (FILE *f, const struct uae_prefs *p)
319
int target_parse_option (struct uae_prefs *p, const char *option, const char *value)
324
void target_default_options (struct uae_prefs *p)