2009-07-28 21:32:10 +00:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
2009-07-13 07:31:43 +00:00
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
2008-09-07 20:26:38 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2008-12-07 22:42:49 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2008-09-07 20:26:38 +00:00
|
|
|
#ifndef _WIN32
|
2009-07-13 06:34:12 +00:00
|
|
|
#include <sys/param.h>
|
2008-09-07 20:26:38 +00:00
|
|
|
#else
|
2009-07-13 06:34:12 +00:00
|
|
|
|
2008-09-07 20:26:38 +00:00
|
|
|
#endif
|
|
|
|
|
2009-01-12 23:59:27 +00:00
|
|
|
#include "Common.h"
|
2009-05-15 08:55:46 +00:00
|
|
|
#include "FileUtil.h"
|
|
|
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <sys/param.h>
|
|
|
|
#endif
|
2009-01-12 23:59:27 +00:00
|
|
|
|
|
|
|
#if defined(HAVE_COCOA) && HAVE_COCOA
|
|
|
|
#import "cocoaApp.h"
|
|
|
|
#endif
|
2008-12-07 22:42:49 +00:00
|
|
|
|
2008-09-07 20:26:38 +00:00
|
|
|
#include "Globals.h"
|
2008-09-10 01:01:28 +00:00
|
|
|
#include "Host.h"
|
2008-09-07 20:26:38 +00:00
|
|
|
#include "ISOFile.h"
|
|
|
|
#include "CPUDetect.h"
|
2008-09-07 21:06:55 +00:00
|
|
|
#include "cmdline.h"
|
|
|
|
#include "Thread.h"
|
|
|
|
#include "PowerPC/PowerPC.h"
|
2009-02-17 20:28:49 +00:00
|
|
|
#include "PluginManager.h"
|
2008-09-07 20:26:38 +00:00
|
|
|
|
2009-01-12 20:52:45 +00:00
|
|
|
|
2008-09-07 20:26:38 +00:00
|
|
|
#include "BootManager.h"
|
|
|
|
void* g_pCodeWindow = NULL;
|
|
|
|
void* main_frame = NULL;
|
|
|
|
|
|
|
|
// OK, this thread boundary is DANGEROUS on linux
|
|
|
|
// wxPostEvent / wxAddPendingEvent is the solution.
|
|
|
|
void Host_NotifyMapLoaded(){}
|
|
|
|
|
2009-08-01 19:16:15 +00:00
|
|
|
void Host_ShowJitResults(unsigned int address){}
|
|
|
|
|
2009-09-07 12:40:43 +00:00
|
|
|
void Host_Message(int Id){}
|
2008-09-07 20:26:38 +00:00
|
|
|
|
|
|
|
void Host_UpdateLogDisplay(){}
|
|
|
|
|
|
|
|
|
|
|
|
void Host_UpdateDisasmDialog(){}
|
|
|
|
|
|
|
|
|
2008-09-07 21:06:55 +00:00
|
|
|
Common::Event updateMainFrameEvent;
|
|
|
|
void Host_UpdateMainFrame()
|
|
|
|
{
|
|
|
|
updateMainFrameEvent.Set();
|
|
|
|
}
|
2008-09-07 20:26:38 +00:00
|
|
|
|
|
|
|
void Host_UpdateBreakPointView(){}
|
|
|
|
|
|
|
|
|
|
|
|
void Host_UpdateMemoryView(){}
|
|
|
|
|
|
|
|
|
|
|
|
void Host_SetDebugMode(bool){}
|
|
|
|
|
|
|
|
|
|
|
|
void Host_SetWaitCursor(bool enable){}
|
|
|
|
|
|
|
|
|
2009-02-16 09:26:47 +00:00
|
|
|
void Host_UpdateStatusBar(const char* _pText, int Filed){}
|
2008-09-07 20:26:38 +00:00
|
|
|
|
2008-09-10 01:01:28 +00:00
|
|
|
void Host_SysMessage(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
char msg[512];
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
vsprintf(msg, fmt, list);
|
|
|
|
va_end(list);
|
|
|
|
|
|
|
|
size_t len = strlen(msg);
|
|
|
|
if (msg[len - 1] != '\n') {
|
|
|
|
msg[len - 1] = '\n';
|
|
|
|
msg[len] = '\0';
|
|
|
|
}
|
|
|
|
fprintf(stderr, msg);
|
|
|
|
}
|
|
|
|
|
2008-12-09 22:08:40 +00:00
|
|
|
void Host_UpdateLeds(int led_bits)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void Host_UpdateSpeakerStatus(int index, int speaker_bits)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void Host_UpdateStatus()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-10-30 16:36:45 +00:00
|
|
|
void Host_SetWiiMoteConnectionState(int _State) {}
|
|
|
|
|
2009-01-12 20:52:45 +00:00
|
|
|
|
|
|
|
//for cocoa we need to hijack the main to get event
|
|
|
|
#if defined(HAVE_COCOA) && HAVE_COCOA
|
2009-01-12 23:59:27 +00:00
|
|
|
|
|
|
|
@interface CocoaThread : NSObject
|
|
|
|
{
|
|
|
|
}
|
|
|
|
- (void)cocoaThreadStart;
|
|
|
|
- (void)cocoaThreadRun:(id)sender;
|
|
|
|
- (void)cocoaThreadQuit:(NSNotification*)note;
|
|
|
|
@end
|
|
|
|
|
|
|
|
static NSString *CocoaThreadHaveFinish = @"CocoaThreadHaveFinish";
|
|
|
|
|
|
|
|
int cocoaArgc;
|
|
|
|
char **cocoaArgv;
|
2009-01-12 20:52:45 +00:00
|
|
|
int appleMain(int argc, char *argv[]);
|
|
|
|
|
2009-01-12 23:59:27 +00:00
|
|
|
@implementation CocoaThread
|
|
|
|
|
|
|
|
- (void)cocoaThreadStart
|
|
|
|
{
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cocoaThreadQuit:) name:CocoaThreadHaveFinish object:nil];
|
|
|
|
[NSThread detachNewThreadSelector:@selector(cocoaThreadRun:) toTarget:self withObject:nil];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)cocoaThreadRun:(id)sender
|
|
|
|
{
|
|
|
|
|
|
|
|
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
|
|
|
//launch main
|
|
|
|
appleMain(cocoaArgc,cocoaArgv);
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:CocoaThreadHaveFinish object:nil];
|
|
|
|
|
|
|
|
[pool release];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)cocoaThreadQuit:(NSNotification*)note
|
|
|
|
{
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-01-12 20:52:45 +00:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
|
2009-01-12 23:59:27 +00:00
|
|
|
cocoaArgc = argc;
|
|
|
|
cocoaArgv = argv;
|
|
|
|
|
2009-01-12 20:52:45 +00:00
|
|
|
cocoaCreateApp();
|
|
|
|
|
2009-01-12 23:59:27 +00:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2009-05-15 08:55:46 +00:00
|
|
|
|
2009-01-12 23:59:27 +00:00
|
|
|
CocoaThread *thread = [[CocoaThread alloc] init];
|
|
|
|
NSEvent *event = [[NSEvent alloc] init];
|
|
|
|
|
|
|
|
[thread cocoaThreadStart];
|
|
|
|
|
|
|
|
//cocoa event loop
|
|
|
|
while(true)
|
|
|
|
{
|
|
|
|
event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ];
|
|
|
|
cocoaSendEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[event release];
|
|
|
|
[thread release];
|
|
|
|
[pool release];
|
2009-01-12 20:52:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int appleMain(int argc, char *argv[])
|
|
|
|
#else
|
2008-09-07 20:26:38 +00:00
|
|
|
// Include SDL header so it can hijack main().
|
2008-12-07 17:09:40 +00:00
|
|
|
#if defined(USE_SDL) && USE_SDL
|
2008-09-07 20:26:38 +00:00
|
|
|
#include <SDL.h>
|
2008-10-20 17:32:15 +00:00
|
|
|
#endif
|
2008-09-07 20:26:38 +00:00
|
|
|
int main(int argc, char* argv[])
|
2009-01-12 20:52:45 +00:00
|
|
|
#endif
|
2008-09-07 20:26:38 +00:00
|
|
|
{
|
2008-09-07 21:02:57 +00:00
|
|
|
gengetopt_args_info args_info;
|
|
|
|
|
|
|
|
if (cmdline_parser (argc, argv, &args_info) != 0)
|
|
|
|
return(1);
|
|
|
|
|
|
|
|
if (args_info.inputs_num < 1)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Please supply at least one argument - the ISO to boot.\n");
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
std::string bootFile(args_info.inputs[0]);
|
|
|
|
|
2008-09-07 21:06:55 +00:00
|
|
|
updateMainFrameEvent.Init();
|
2009-02-06 18:04:24 +00:00
|
|
|
cpu_info.Detect();
|
2009-02-17 20:28:49 +00:00
|
|
|
CPluginManager::GetInstance().ScanForPlugins();
|
2009-05-15 08:55:46 +00:00
|
|
|
|
|
|
|
// check to see if ~/Library/Application Support/Dolphin exists; if not, create it
|
|
|
|
char AppSupportDir[MAXPATHLEN];
|
|
|
|
snprintf(AppSupportDir, sizeof(AppSupportDir), "%s/Library/Application Support", getenv("HOME"));
|
|
|
|
if (!File::Exists(AppSupportDir) || !File::IsDirectory(AppSupportDir))
|
|
|
|
PanicAlert("Could not open ~/Library/Application Support");
|
|
|
|
|
2009-07-13 06:34:12 +00:00
|
|
|
strncat(AppSupportDir, "/Dolphin", sizeof(AppSupportDir));
|
2009-05-15 08:55:46 +00:00
|
|
|
|
|
|
|
if (!File::Exists(AppSupportDir))
|
|
|
|
File::CreateDir(AppSupportDir);
|
|
|
|
|
|
|
|
if (!File::IsDirectory(AppSupportDir))
|
|
|
|
PanicAlert("~/Library/Application Support/Dolphin exists, but is not a directory");
|
|
|
|
|
|
|
|
chdir(AppSupportDir);
|
|
|
|
|
|
|
|
|
2008-09-07 21:02:57 +00:00
|
|
|
BootManager::BootCore(bootFile);
|
2009-02-18 00:08:40 +00:00
|
|
|
while (PowerPC::GetState() != PowerPC::CPU_POWERDOWN)
|
2008-09-07 21:06:55 +00:00
|
|
|
{
|
|
|
|
updateMainFrameEvent.Wait();
|
|
|
|
}
|
2008-09-07 20:26:38 +00:00
|
|
|
|
2008-09-07 21:02:57 +00:00
|
|
|
cmdline_parser_free (&args_info);
|
|
|
|
return(0);
|
2008-09-07 20:26:38 +00:00
|
|
|
}
|