2007-12-08 03:52:30 +00:00
|
|
|
#import "ApplicationDelegate.h"
|
2016-01-13 10:32:34 -05:00
|
|
|
#import "PreferencesWindowController.h"
|
2007-12-09 03:26:33 +00:00
|
|
|
#import "GSH_OpenGLMacOSX.h"
|
2008-01-28 04:03:33 +00:00
|
|
|
#import "PH_HidMacOSX.h"
|
2016-04-11 18:16:07 -04:00
|
|
|
#import "../../tools/PsfPlayer/Source/SH_OpenAL.h"
|
2007-12-08 03:52:30 +00:00
|
|
|
#import "Globals.h"
|
2016-04-11 18:16:07 -04:00
|
|
|
#import "PreferenceDefs.h"
|
2015-05-06 22:26:38 -04:00
|
|
|
#import "../ee/PS2OS.h"
|
2016-01-15 10:10:06 -05:00
|
|
|
#import "../ScopedVmPauser.h"
|
2012-08-22 11:24:59 +00:00
|
|
|
#import "../PS2VM_Preferences.h"
|
|
|
|
#import "../AppConfig.h"
|
2007-12-08 03:52:30 +00:00
|
|
|
|
2012-08-22 11:24:59 +00:00
|
|
|
@implementation ApplicationDelegate
|
2007-12-08 03:52:30 +00:00
|
|
|
|
2012-08-22 11:24:59 +00:00
|
|
|
-(void)applicationDidFinishLaunching: (NSNotification*)notification
|
2007-12-08 03:52:30 +00:00
|
|
|
{
|
2016-04-11 18:16:07 -04:00
|
|
|
CAppConfig::GetInstance().RegisterPreferenceBoolean(PREFERENCE_AUDIO_ENABLEOUTPUT, true);
|
|
|
|
|
2007-12-08 03:52:30 +00:00
|
|
|
g_virtualMachine->Initialize();
|
2012-08-22 11:24:59 +00:00
|
|
|
|
|
|
|
outputWindowController = [[OutputWindowController alloc] initWithWindowNibName: @"OutputWindow"];
|
|
|
|
[outputWindowController.window setContentSize: NSMakeSize(640.0, 448.0)];
|
|
|
|
[outputWindowController.window center];
|
|
|
|
[outputWindowController showWindow: nil];
|
2012-09-05 00:08:05 +00:00
|
|
|
[outputWindowController setDelegate: self];
|
2015-12-19 23:35:22 -05:00
|
|
|
[self setupOpenGlContext];
|
2012-08-22 11:24:59 +00:00
|
|
|
|
|
|
|
NSOpenGLContext* context = [outputWindowController.openGlView openGLContext];
|
2007-12-09 03:26:33 +00:00
|
|
|
void* lowLevelContext = [context CGLContextObj];
|
2008-01-24 05:00:30 +00:00
|
|
|
g_virtualMachine->CreateGSHandler(CGSH_OpenGLMacOSX::GetFactoryFunction(reinterpret_cast<CGLContextObj>(lowLevelContext)));
|
2008-01-28 04:03:33 +00:00
|
|
|
g_virtualMachine->CreatePadHandler(CPH_HidMacOSX::GetFactoryFunction());
|
2016-04-11 18:16:07 -04:00
|
|
|
[self setupSoundHandler];
|
2012-08-22 11:24:59 +00:00
|
|
|
#ifdef _DEBUG
|
2007-12-22 01:46:08 +00:00
|
|
|
//Check arguments
|
|
|
|
NSArray* args = [[NSProcessInfo processInfo] arguments];
|
2008-01-28 04:03:33 +00:00
|
|
|
|
2007-12-22 01:46:08 +00:00
|
|
|
NSString* bootFromElfPath = nil;
|
|
|
|
if([args count] > 1)
|
|
|
|
{
|
|
|
|
bootFromElfPath = [args objectAtIndex:1];
|
|
|
|
}
|
2012-03-11 20:20:00 +00:00
|
|
|
|
2012-08-22 11:24:59 +00:00
|
|
|
//if(bootFromElfPath != nil)
|
|
|
|
//{
|
|
|
|
// [self BootFromElf:bootFromElfPath];
|
|
|
|
//}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-09-05 00:08:05 +00:00
|
|
|
-(void)applicationDidBecomeActive: (NSNotification*)notification
|
|
|
|
{
|
|
|
|
[self updatePresentationParams];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void)outputWindowDidResize: (NSSize)size
|
|
|
|
{
|
|
|
|
[self updatePresentationParams];
|
|
|
|
}
|
|
|
|
|
2012-08-22 11:24:59 +00:00
|
|
|
-(void)applicationWillTerminate: (NSNotification*)notification
|
|
|
|
{
|
|
|
|
g_virtualMachine->Pause();
|
|
|
|
}
|
|
|
|
|
2015-12-19 23:35:22 -05:00
|
|
|
-(void)setupOpenGlContext
|
|
|
|
{
|
|
|
|
NSOpenGLPixelFormatAttribute pixelFormatAttributes[] =
|
|
|
|
{
|
|
|
|
NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
|
|
|
|
NSOpenGLPFADoubleBuffer, YES,
|
|
|
|
NSOpenGLPFADepthSize, 24,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
NSOpenGLPixelFormat* pixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes: pixelFormatAttributes] autorelease];
|
|
|
|
NSOpenGLContext* context = [[[NSOpenGLContext alloc] initWithFormat: pixelFormat shareContext:nil] autorelease];
|
|
|
|
[outputWindowController.openGlView setPixelFormat: pixelFormat];
|
|
|
|
[outputWindowController.openGlView setOpenGLContext: context];
|
|
|
|
}
|
|
|
|
|
2016-04-11 18:16:07 -04:00
|
|
|
-(void)setupSoundHandler
|
|
|
|
{
|
|
|
|
auto audioEnabled = CAppConfig::GetInstance().GetPreferenceBoolean(PREFERENCE_AUDIO_ENABLEOUTPUT);
|
|
|
|
if(audioEnabled)
|
|
|
|
{
|
|
|
|
g_virtualMachine->CreateSoundHandler(&CSH_OpenAL::HandlerFactory);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_virtualMachine->DestroySoundHandler();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-13 10:32:34 -05:00
|
|
|
-(IBAction)showPreferences: (id)sender
|
|
|
|
{
|
2016-01-15 10:10:06 -05:00
|
|
|
CScopedVmPauser vmPaused(*g_virtualMachine);
|
2016-01-13 10:32:34 -05:00
|
|
|
[[PreferencesWindowController defaultController] show];
|
2016-01-24 20:46:19 -05:00
|
|
|
auto gs = g_virtualMachine->GetGSHandler();
|
|
|
|
if(gs != nullptr) gs->NotifyPreferencesChanged();
|
2016-04-11 18:24:01 -04:00
|
|
|
[self setupSoundHandler];
|
2016-01-13 10:32:34 -05:00
|
|
|
}
|
|
|
|
|
2012-08-22 11:24:59 +00:00
|
|
|
-(IBAction)bootElfMenuSelected: (id)sender
|
|
|
|
{
|
|
|
|
NSOpenPanel* openPanel = [NSOpenPanel openPanel];
|
|
|
|
NSArray* fileTypes = [NSArray arrayWithObject: @"elf"];
|
|
|
|
openPanel.allowedFileTypes = fileTypes;
|
|
|
|
openPanel.canChooseDirectories = NO;
|
2015-04-13 20:22:27 -04:00
|
|
|
if([openPanel runModal] != NSModalResponseOK)
|
2007-12-22 01:46:08 +00:00
|
|
|
{
|
2012-08-22 11:24:59 +00:00
|
|
|
return;
|
2007-12-22 01:46:08 +00:00
|
|
|
}
|
2012-08-22 11:24:59 +00:00
|
|
|
NSURL* url = openPanel.URL;
|
|
|
|
NSString* filePath = [url path];
|
|
|
|
[self bootFromElf: filePath];
|
2007-12-08 03:52:30 +00:00
|
|
|
}
|
|
|
|
|
2012-09-05 00:08:05 +00:00
|
|
|
-(IBAction)bootDiskImageMenuSelected: (id)sender
|
2007-12-08 03:52:30 +00:00
|
|
|
{
|
|
|
|
NSOpenPanel* openPanel = [NSOpenPanel openPanel];
|
2015-04-13 22:23:16 -07:00
|
|
|
NSArray* fileTypes = [NSArray arrayWithObjects: @"iso", @"isz", @"cso", nil];
|
2012-08-22 11:24:59 +00:00
|
|
|
openPanel.allowedFileTypes = fileTypes;
|
|
|
|
openPanel.canChooseDirectories = NO;
|
2015-04-13 20:22:27 -04:00
|
|
|
if([openPanel runModal] != NSModalResponseOK)
|
2007-12-08 03:52:30 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2012-08-22 11:24:59 +00:00
|
|
|
NSURL* url = openPanel.URL;
|
|
|
|
NSString* filePath = [url path];
|
|
|
|
CAppConfig::GetInstance().SetPreferenceString(PS2VM_CDROM0PATH, [filePath UTF8String]);
|
|
|
|
|
|
|
|
[self bootFromCdrom0];
|
2007-12-22 01:46:08 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 11:24:59 +00:00
|
|
|
-(IBAction)bootCdrom0MenuSelected: (id)sender
|
2008-01-24 20:02:39 +00:00
|
|
|
{
|
2012-08-22 11:24:59 +00:00
|
|
|
[self bootFromCdrom0];
|
2008-01-24 20:02:39 +00:00
|
|
|
}
|
|
|
|
|
2012-09-05 00:08:05 +00:00
|
|
|
-(IBAction)fitToScreenMenuSelected: (id)sender
|
|
|
|
{
|
2012-09-05 21:27:28 +00:00
|
|
|
CAppConfig::GetInstance().SetPreferenceInteger(PREF_CGSHANDLER_PRESENTATION_MODE, CGSHandler::PRESENTATION_MODE_FIT);
|
2012-09-05 00:08:05 +00:00
|
|
|
[self updatePresentationParams];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(IBAction)fillScreenMenuSelected: (id)sender
|
|
|
|
{
|
2012-09-05 21:27:28 +00:00
|
|
|
CAppConfig::GetInstance().SetPreferenceInteger(PREF_CGSHANDLER_PRESENTATION_MODE, CGSHandler::PRESENTATION_MODE_FILL);
|
2012-09-05 00:08:05 +00:00
|
|
|
[self updatePresentationParams];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(IBAction)actualSizeMenuSelected: (id)sender
|
|
|
|
{
|
2012-09-05 21:27:28 +00:00
|
|
|
CAppConfig::GetInstance().SetPreferenceInteger(PREF_CGSHANDLER_PRESENTATION_MODE, CGSHandler::PRESENTATION_MODE_ORIGINAL);
|
2012-09-05 00:08:05 +00:00
|
|
|
[self updatePresentationParams];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(IBAction)fullScreenMenuSelected: (id)sender
|
|
|
|
{
|
|
|
|
[outputWindowController.window toggleFullScreen: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(IBAction)pauseResumeMenuSelected: (id)sender
|
2007-12-27 20:35:09 +00:00
|
|
|
{
|
|
|
|
if(g_virtualMachine->GetStatus() == CVirtualMachine::RUNNING)
|
|
|
|
{
|
|
|
|
g_virtualMachine->Pause();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_virtualMachine->Resume();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-05 00:08:05 +00:00
|
|
|
-(IBAction)saveStateMenuSelected: (id)sender
|
2007-12-27 20:35:09 +00:00
|
|
|
{
|
|
|
|
g_virtualMachine->SaveState("state.st0.zip");
|
|
|
|
}
|
|
|
|
|
2012-09-05 00:08:05 +00:00
|
|
|
-(IBAction)loadStateMenuSelected: (id)sender
|
2007-12-27 20:35:09 +00:00
|
|
|
{
|
2008-05-03 02:07:13 +00:00
|
|
|
if(g_virtualMachine->LoadState("state.st0.zip"))
|
|
|
|
{
|
|
|
|
NSRunCriticalAlertPanel(@"Error occured while trying to load state.", @"", NULL, NULL, NULL);
|
|
|
|
}
|
2007-12-27 20:35:09 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 11:24:59 +00:00
|
|
|
-(void)bootFromElf : (NSString*)fileName
|
2007-12-22 01:46:08 +00:00
|
|
|
{
|
2012-08-22 11:24:59 +00:00
|
|
|
g_virtualMachine->Pause();
|
2007-12-08 03:52:30 +00:00
|
|
|
g_virtualMachine->Reset();
|
|
|
|
try
|
|
|
|
{
|
2015-02-28 11:14:25 -05:00
|
|
|
CPS2OS* os = g_virtualMachine->m_ee->m_os;
|
2007-12-08 03:52:30 +00:00
|
|
|
os->BootFromFile([fileName fileSystemRepresentation]);
|
2015-04-20 20:33:40 -04:00
|
|
|
[self updateTitle];
|
2008-01-24 20:02:39 +00:00
|
|
|
g_virtualMachine->Resume();
|
|
|
|
}
|
2012-08-22 11:24:59 +00:00
|
|
|
catch(const std::exception& exception)
|
2008-01-24 20:02:39 +00:00
|
|
|
{
|
2012-08-22 11:24:59 +00:00
|
|
|
NSString* errorMessage = [[NSString alloc] initWithUTF8String: exception.what()];
|
2008-01-24 20:02:39 +00:00
|
|
|
NSRunCriticalAlertPanel(@"Load ELF error:", errorMessage, NULL, NULL, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 11:24:59 +00:00
|
|
|
-(void)bootFromCdrom0
|
2008-01-24 20:02:39 +00:00
|
|
|
{
|
2012-08-22 11:24:59 +00:00
|
|
|
g_virtualMachine->Pause();
|
2008-01-24 20:02:39 +00:00
|
|
|
g_virtualMachine->Reset();
|
|
|
|
try
|
|
|
|
{
|
2015-02-28 11:14:25 -05:00
|
|
|
CPS2OS* os = g_virtualMachine->m_ee->m_os;
|
2015-12-06 14:53:35 -05:00
|
|
|
os->BootFromCDROM();
|
2015-04-20 20:33:40 -04:00
|
|
|
[self updateTitle];
|
2008-01-24 20:02:39 +00:00
|
|
|
g_virtualMachine->Resume();
|
2007-12-08 03:52:30 +00:00
|
|
|
}
|
2012-08-22 11:24:59 +00:00
|
|
|
catch(const std::exception& exception)
|
2007-12-08 03:52:30 +00:00
|
|
|
{
|
2012-08-22 11:24:59 +00:00
|
|
|
NSString* errorMessage = [[NSString alloc] initWithUTF8String: exception.what()];
|
2007-12-08 03:52:30 +00:00
|
|
|
NSRunCriticalAlertPanel(@"Load ELF error:", errorMessage, NULL, NULL, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-20 20:33:40 -04:00
|
|
|
-(void)updateTitle
|
|
|
|
{
|
|
|
|
CPS2OS* os = g_virtualMachine->m_ee->m_os;
|
|
|
|
auto executableName = os->GetExecutableName();
|
|
|
|
outputWindowController.window.title = [NSString stringWithFormat: @"Play! - %s", executableName];
|
|
|
|
}
|
|
|
|
|
2012-08-22 11:24:59 +00:00
|
|
|
-(BOOL)validateUserInterfaceItem: (id<NSValidatedUserInterfaceItem>)item
|
|
|
|
{
|
2015-02-28 11:14:25 -05:00
|
|
|
bool hasElf = g_virtualMachine->m_ee->m_os->GetELF() != NULL;
|
2012-09-05 21:27:28 +00:00
|
|
|
auto presentationMode = static_cast<CGSHandler::PRESENTATION_MODE>(CAppConfig::GetInstance().GetPreferenceInteger(PREF_CGSHANDLER_PRESENTATION_MODE));
|
2012-09-05 00:08:05 +00:00
|
|
|
if(
|
|
|
|
item == pauseResumeMenuItem ||
|
|
|
|
item == loadStateMenuItem ||
|
|
|
|
item == saveStateMenuItem)
|
|
|
|
{
|
|
|
|
return hasElf;
|
|
|
|
}
|
|
|
|
if(item.action == @selector(fitToScreenMenuSelected:))
|
|
|
|
{
|
2012-09-05 21:27:28 +00:00
|
|
|
[(NSMenuItem*)item setState: (presentationMode == CGSHandler::PRESENTATION_MODE_FIT) ? NSOnState : NSOffState];
|
2012-09-05 00:08:05 +00:00
|
|
|
}
|
|
|
|
if(item.action == @selector(fillScreenMenuSelected:))
|
2012-08-22 11:24:59 +00:00
|
|
|
{
|
2012-09-05 21:27:28 +00:00
|
|
|
[(NSMenuItem*)item setState: (presentationMode == CGSHandler::PRESENTATION_MODE_FILL) ? NSOnState : NSOffState];
|
2012-09-05 00:08:05 +00:00
|
|
|
}
|
|
|
|
if(item.action == @selector(actualSizeMenuSelected:))
|
|
|
|
{
|
2012-09-05 21:27:28 +00:00
|
|
|
[(NSMenuItem*)item setState: (presentationMode == CGSHandler::PRESENTATION_MODE_ORIGINAL) ? NSOnState : NSOffState];
|
2012-08-22 11:24:59 +00:00
|
|
|
}
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2012-09-05 00:08:05 +00:00
|
|
|
-(void)updatePresentationParams
|
2012-09-05 21:27:28 +00:00
|
|
|
{
|
|
|
|
auto presentationMode = static_cast<CGSHandler::PRESENTATION_MODE>(CAppConfig::GetInstance().GetPreferenceInteger(PREF_CGSHANDLER_PRESENTATION_MODE));
|
2012-09-05 00:08:05 +00:00
|
|
|
NSSize contentSize = [outputWindowController contentSize];
|
2012-09-05 21:27:28 +00:00
|
|
|
CGSHandler::PRESENTATION_PARAMS presentationParams;
|
2012-09-05 00:08:05 +00:00
|
|
|
presentationParams.windowWidth = static_cast<unsigned int>(contentSize.width);
|
|
|
|
presentationParams.windowHeight = static_cast<unsigned int>(contentSize.height);
|
|
|
|
presentationParams.mode = presentationMode;
|
2015-02-28 11:14:25 -05:00
|
|
|
g_virtualMachine->m_ee->m_gs->SetPresentationParams(presentationParams);
|
|
|
|
g_virtualMachine->m_ee->m_gs->Flip();
|
2012-09-05 00:08:05 +00:00
|
|
|
}
|
|
|
|
|
2007-12-08 03:52:30 +00:00
|
|
|
@end
|