summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2013-01-09 01:50:38 +0000
committerSND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2013-01-09 01:50:38 +0000
commit9af085242bda9ad4da78ef23e9d4ed180aa2c629 (patch)
treec776a5dfefbe475936a461b54d469d244df9de75
parentc5b4bf6974fbfd05b6e75c494d11569756034e36 (diff)
downloadpcsxr-9af085242bda9ad4da78ef23e9d4ed180aa2c629.tar.gz
Use ARC in 64-bit mode on the Mac.
Register when we drag a disc image (or double click) to Pcsxr in the recent menu. Comment out ReleasePlugins() in SysClose: it was causing a pointer to be released twice when you changed a plug-in (specifically, the GPU). Cleaning up the Recent items code. One notable case is only releasing objects we have ownership of (this is pointless in ARC, but necessary in 32-bit code). Had to rewrite -[PluginList setActivePlugin:forType:] because the previous version wasn't ARC-friendly. If we select a disc while the emulator is running, load the disc into the current session. git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@82136 e17a0e51-4ae3-4d35-97c3-1a29b211df97
-rw-r--r--macosx/ARCBridge.h32
-rwxr-xr-xmacosx/ConfigurationController.m19
-rwxr-xr-xmacosx/EmuThread.m262
-rwxr-xr-xmacosx/HotkeyController.m5
-rw-r--r--macosx/Pcsxr.xcodeproj/project.pbxproj6
-rwxr-xr-xmacosx/PcsxrController.h2
-rwxr-xr-xmacosx/PcsxrController.m33
-rwxr-xr-xmacosx/PcsxrDiscHandler.m6
-rwxr-xr-xmacosx/PcsxrMemCardController.m18
-rwxr-xr-xmacosx/PcsxrMemoryObject.m9
-rwxr-xr-xmacosx/PcsxrPlugin.m49
-rwxr-xr-xmacosx/PcsxrPluginHandler.m3
-rwxr-xr-xmacosx/PluginController.m7
-rwxr-xr-xmacosx/PluginList.m111
-rwxr-xr-xmacosx/RecentItemsMenu.m18
-rwxr-xr-xmacosx/hotkeys.m9
-rwxr-xr-xmacosx/main.m7
17 files changed, 375 insertions, 221 deletions
diff --git a/macosx/ARCBridge.h b/macosx/ARCBridge.h
new file mode 100644
index 00000000..3365a467
--- /dev/null
+++ b/macosx/ARCBridge.h
@@ -0,0 +1,32 @@
+//
+// ARCBridge.h
+// PPMacho
+//
+// Created by C.W. Betts on 12/23/12.
+//
+//
+
+#ifndef PPMacho_ARCBridge_h
+#define PPMacho_ARCBridge_h
+
+#if __has_feature(objc_arc)
+
+#define SUPERDEALLOC
+#define RELEASEOBJ(obj)
+#define RETAINOBJ(obj) obj
+#define AUTORELEASEOBJ(obj) obj
+#define AUTORELEASEOBJNORETURN(obj)
+#define BRIDGE(toType, obj) (__bridge toType)(obj)
+
+#else
+
+#define SUPERDEALLOC [super dealloc]
+#define RELEASEOBJ(obj) [obj release]
+#define RETAINOBJ(obj) [obj retain]
+#define AUTORELEASEOBJ(obj) [obj autorelease]
+#define AUTORELEASEOBJNORETURN(obj) [obj autorelease]
+#define BRIDGE(toType, obj) (toType)obj
+
+#endif
+
+#endif
diff --git a/macosx/ConfigurationController.m b/macosx/ConfigurationController.m
index 730dfaf8..80c23c38 100755
--- a/macosx/ConfigurationController.m
+++ b/macosx/ConfigurationController.m
@@ -6,6 +6,7 @@
#import "PcsxrMemCardHandler.h"
#include "psxcommon.h"
#include "plugins.h"
+#import "ARCBridge.h"
NSString *memChangeNotifier = @"PcsxrMemoryCardDidChangeNotifier";
@@ -55,8 +56,7 @@ NSString *memChangeNotifier = @"PcsxrMemoryCardDidChangeNotifier";
int tag = [sender tag];
char *mcd;
NSTextField *label;
- NSOpenPanel *openDlg = [NSOpenPanel openPanel];
- [openDlg retain];
+ NSOpenPanel *openDlg = RETAINOBJ([NSOpenPanel openPanel]);
NSString *path;
if (tag == 1) { mcd = Config.Mcd1; label = mcd1Label; }
@@ -77,7 +77,7 @@ NSString *memChangeNotifier = @"PcsxrMemoryCardDidChangeNotifier";
[ConfigurationController setMemoryCard:tag toPath:mcdPath];
}
- [openDlg release];
+ RELEASEOBJ(openDlg);
}
- (IBAction)mcdNewClicked:(id)sender
@@ -85,8 +85,7 @@ NSString *memChangeNotifier = @"PcsxrMemoryCardDidChangeNotifier";
int tag = [sender tag];
char *mcd;
NSTextField *label;
- NSSavePanel *openDlg = [NSSavePanel savePanel];
- [openDlg retain];
+ NSSavePanel *openDlg = RETAINOBJ([NSSavePanel savePanel]);
NSString *path;
if (tag == 1) { mcd = Config.Mcd1; label = mcd1Label; }
@@ -102,13 +101,13 @@ NSString *memChangeNotifier = @"PcsxrMemoryCardDidChangeNotifier";
NSString *mcdPath = [[openDlg URL] path];
//Workaround/kludge to make sure we create a memory card before posting a notification
- strcpy(mcd, [mcdPath fileSystemRepresentation]);
+ strlcpy(mcd, [mcdPath fileSystemRepresentation], MAXPATHLEN);
CreateMcd(mcd);
[ConfigurationController setMemoryCard:tag toPath:mcdPath];
}
- [openDlg release];
+ RELEASEOBJ(openDlg);
}
- (IBAction)setVideoType:(id)sender
@@ -221,12 +220,12 @@ NSString *memChangeNotifier = @"PcsxrMemoryCardDidChangeNotifier";
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
- [checkBoxDefaults release];
+ RELEASEOBJ(checkBoxDefaults);
if (memCardEdit) {
[memCardEdit close];
- [memCardEdit release];
+ RELEASEOBJ(memCardEdit);
}
- [super dealloc];
+ SUPERDEALLOC;
}
- (NSString *)keyForSender:(id)sender
diff --git a/macosx/EmuThread.m b/macosx/EmuThread.m
index 89a95ef9..ceeeb486 100755
--- a/macosx/EmuThread.m
+++ b/macosx/EmuThread.m
@@ -14,12 +14,13 @@
#include "psxcommon.h"
#include "plugins.h"
#include "misc.h"
+#import "ARCBridge.h"
-EmuThread *emuThread;
-NSString *defrostPath = nil;
+EmuThread *emuThread = nil;
+static NSString *defrostPath = nil;
static int safeEvent;
-static int paused;
-static int runbios;
+static BOOL paused;
+static BOOL runbios;
static pthread_cond_t eventCond;
static pthread_mutex_t eventMutex;
@@ -35,91 +36,89 @@ static NSString * const ThreadInfo = @"PSX Emu Background thread";
- (void)EmuThreadRun:(id)anObject
{
- NSAutoreleasePool *pool = [NSAutoreleasePool new];
-
- [[NSThread currentThread] setName:ThreadInfo];
-
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(emuWindowDidClose:)
- name:@"emuWindowDidClose" object:nil];
-
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(emuWindowWantPause:)
- name:@"emuWindowWantPause" object:nil];
-
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(emuWindowWantResume:)
- name:@"emuWindowWantResume" object:nil];
-
- // we shouldn't change the priority, since we might depend on subthreads
- //[NSThread setThreadPriority:1.0-((1.0-[NSThread threadPriority])/4.0)];
-
- // Do processing here
- if (OpenPlugins() == -1)
- goto done;
-
- setjmp(restartJmp);
-
- int res = CheckCdrom();
- if (res == -1) {
- ClosePlugins();
- SysMessage(_("Could not check CD-ROM!\n"));
- goto done;
- }
-
- // Auto-detect: region first, then rcnt reset
- EmuReset();
-
- LoadCdrom();
-
- if (defrostPath) {
- LoadState([defrostPath fileSystemRepresentation]);
- [defrostPath release]; defrostPath = nil;
+ @autoreleasepool {
+ [[NSThread currentThread] setName:ThreadInfo];
+
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(emuWindowDidClose:)
+ name:@"emuWindowDidClose" object:nil];
+
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(emuWindowWantPause:)
+ name:@"emuWindowWantPause" object:nil];
+
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(emuWindowWantResume:)
+ name:@"emuWindowWantResume" object:nil];
+
+ // we shouldn't change the priority, since we might depend on subthreads
+ //[NSThread setThreadPriority:1.0-((1.0-[NSThread threadPriority])/4.0)];
+
+ // Do processing here
+ if (OpenPlugins() == -1)
+ goto done;
+
+ setjmp(restartJmp);
+
+ int res = CheckCdrom();
+ if (res == -1) {
+ ClosePlugins();
+ SysMessage(_("Could not check CD-ROM!\n"));
+ goto done;
+ }
+
+ // Auto-detect: region first, then rcnt reset
+ EmuReset();
+
+ LoadCdrom();
+
+ if (defrostPath) {
+ LoadState([defrostPath fileSystemRepresentation]);
+ RELEASEOBJ(defrostPath); defrostPath = nil;
+ }
+
+ psxCpu->Execute();
+
+ done:
+ emuThread = nil;
+
+ return;
}
-
- psxCpu->Execute();
-
-done:
- [pool drain];
- emuThread = nil;
-
- return;
}
- (void)EmuThreadRunBios:(id)anObject
{
- NSAutoreleasePool *pool = [NSAutoreleasePool new];
-
- [[NSThread currentThread] setName:ThreadInfo];
-
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(emuWindowDidClose:)
- name:@"emuWindowDidClose" object:nil];
-
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(emuWindowWantPause:)
- name:@"emuWindowWantPause" object:nil];
-
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(emuWindowWantResume:)
- name:@"emuWindowWantResume" object:nil];
-
- // we shouldn't change the priority, since we might depend on subthreads
- //[NSThread setThreadPriority:1.0-((1.0-[NSThread threadPriority])/4.0)];
-
- // Do processing here
- if (OpenPlugins() == -1)
- goto done;
-
- EmuReset();
-
- psxCpu->Execute();
-
-done:
- [pool drain];
- emuThread = nil;
-
- return;
+ @autoreleasepool {
+ [[NSThread currentThread] setName:ThreadInfo];
+
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(emuWindowDidClose:)
+ name:@"emuWindowDidClose" object:nil];
+
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(emuWindowWantPause:)
+ name:@"emuWindowWantPause" object:nil];
+
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(emuWindowWantResume:)
+ name:@"emuWindowWantResume" object:nil];
+
+ // we shouldn't change the priority, since we might depend on subthreads
+ //[NSThread setThreadPriority:1.0-((1.0-[NSThread threadPriority])/4.0)];
+
+ // Do processing here
+ if (OpenPlugins() == -1)
+ goto done;
+
+ EmuReset();
+
+ psxCpu->Execute();
+
+ done:
+ emuThread = nil;
+
+ return;
+ }
}
- (void)dealloc
@@ -127,7 +126,7 @@ done:
// remove all registered observers
[[NSNotificationCenter defaultCenter] removeObserver:self name:nil object:nil];
- [super dealloc];
+ SUPERDEALLOC;
}
- (void)emuWindowDidClose:(NSNotification *)aNotification
@@ -155,56 +154,55 @@ done:
and we can just handle events next time round */
if (pthread_mutex_trylock(&eventMutex) == 0) {
while (safeEvent) {
- NSAutoreleasePool *pool = [NSAutoreleasePool new];
- if (safeEvent & EMUEVENT_STOP) {
- /* signify that the emulation has stopped */
- [emuThread autorelease];
- emuThread = nil;
- paused = NO;
+ @autoreleasepool {
+ if (safeEvent & EMUEVENT_STOP) {
+ /* signify that the emulation has stopped */
+ AUTORELEASEOBJNORETURN(emuThread);
+ emuThread = nil;
+ paused = NO;
+
+ /* better unlock the mutex before killing ourself */
+ pthread_mutex_unlock(&eventMutex);
+
+ ClosePlugins();
+ SysClose();
+
+ //[[NSThread currentThread] autorelease];
+ [NSThread exit];
+ return;
+ }
- /* better unlock the mutex before killing ourself */
- pthread_mutex_unlock(&eventMutex);
-
- ClosePlugins();
- SysClose();
-
- //[[NSThread currentThread] autorelease];
- [pool drain];
- [NSThread exit];
- return;
- }
-
- if (safeEvent & EMUEVENT_RESET) {
+ if (safeEvent & EMUEVENT_RESET) {
#if 0
- /* signify that the emulation has stopped */
- [emuThread autorelease];
- emuThread = nil;
-
- /* better unlock the mutex before killing ourself */
- pthread_mutex_unlock(&eventMutex);
-
- ClosePlugins();
-
- // start a new emulation thread
- [EmuThread run];
-
- //[[NSThread currentThread] autorelease];
- [NSThread exit];
- return;
+ /* signify that the emulation has stopped */
+ [emuThread autorelease];
+ emuThread = nil;
+
+ /* better unlock the mutex before killing ourself */
+ pthread_mutex_unlock(&eventMutex);
+
+ ClosePlugins();
+
+ // start a new emulation thread
+ [EmuThread run];
+
+ //[[NSThread currentThread] autorelease];
+ [NSThread exit];
+ return;
#else
- safeEvent &= ~EMUEVENT_RESET;
- pthread_mutex_unlock(&eventMutex);
-
- longjmp(restartJmp, 0);
+ safeEvent &= ~EMUEVENT_RESET;
+ pthread_mutex_unlock(&eventMutex);
+
+ longjmp(restartJmp, 0);
#endif
+ }
+
+ if (safeEvent & EMUEVENT_PAUSE) {
+ paused = 2;
+ /* wait until we're signalled */
+ pthread_cond_wait(&eventCond, &eventMutex);
+ }
}
-
- if (safeEvent & EMUEVENT_PAUSE) {
- paused = 2;
- /* wait until we're signalled */
- pthread_cond_wait(&eventCond, &eventMutex);
- }
- [pool drain];
}
pthread_mutex_unlock(&eventMutex);
}
@@ -345,7 +343,7 @@ done:
+ (void)resetNow
{
/* signify that the emulation has stopped */
- [emuThread autorelease];
+ AUTORELEASEOBJNORETURN(emuThread);
emuThread = nil;
ClosePlugins();
@@ -395,7 +393,7 @@ done:
if (CheckState(cPath) != 0)
return NO;
- defrostPath = [path retain];
+ defrostPath = RETAINOBJ(path);
[EmuThread reset];
GPU_displayText(_("*PCSXR*: Loaded State"));
diff --git a/macosx/HotkeyController.m b/macosx/HotkeyController.m
index fcb15c4e..716c5d84 100755
--- a/macosx/HotkeyController.m
+++ b/macosx/HotkeyController.m
@@ -8,6 +8,7 @@
*/
#import "HotkeyController.h"
+#import "ARCBridge.h"
#define INPUT_HOLD_TIME 0.1
@@ -34,12 +35,14 @@
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
-
+
+#if !__has_feature(objc_arc)
[hotkeysList release];
[keyNameTable release];
[hotkeyOutlets release];
[super dealloc];
+#endif
}
- (void)mapOutletToIdentifier:(id)outlet forIdentifier:(NSString*)identifier
diff --git a/macosx/Pcsxr.xcodeproj/project.pbxproj b/macosx/Pcsxr.xcodeproj/project.pbxproj
index cf72aa49..32fd992c 100644
--- a/macosx/Pcsxr.xcodeproj/project.pbxproj
+++ b/macosx/Pcsxr.xcodeproj/project.pbxproj
@@ -281,6 +281,7 @@
55A90228147D89380037E18F /* PcsxrMemoryObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PcsxrMemoryObject.m; sourceTree = "<group>"; };
55AD382A160C200000E9EA20 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
55AD382B160C200000E9EA20 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
+ 55BB3493169CD42500850200 /* ARCBridge.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ARCBridge.h; sourceTree = "<group>"; };
55BBA690149454DE003B2CEC /* PcsxrFileHandle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PcsxrFileHandle.h; sourceTree = "<group>"; };
55BBA691149455E1003B2CEC /* PcsxrMemCardHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PcsxrMemCardHandler.h; sourceTree = "<group>"; };
55BBA692149455E1003B2CEC /* PcsxrMemCardHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PcsxrMemCardHandler.m; sourceTree = "<group>"; };
@@ -458,6 +459,7 @@
children = (
2BA178AD0514CE260026D74D /* Resources */,
2B143D00078A2CBD00AF745A /* icons */,
+ 55BB3493169CD42500850200 /* ARCBridge.h */,
7161C2810FDED6D000225F97 /* config.h */,
2BA178A505148D9D0026D74D /* main.m */,
2BBB17DA051E4D0F00B84448 /* Plugin.c */,
@@ -489,8 +491,8 @@
55BBA69B1495839A003B2CEC /* PcsxrFreezeStateHandler.m */,
0280B7AB16764CC3007B8001 /* HotkeyController.h */,
0280B7AC16764CC3007B8001 /* HotkeyController.m */,
- 02717967167884C9004AED62 /* hotkeys.m */,
02717969167884DF004AED62 /* hotkeys.h */,
+ 02717967167884C9004AED62 /* hotkeys.m */,
5550D2711683C923006C56B5 /* RecentItemsMenu.h */,
5550D2721683C923006C56B5 /* RecentItemsMenu.m */,
);
@@ -971,6 +973,7 @@
71F353F40FD98DFE00CBEC28 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ "CLANG_ENABLE_OBJC_ARC[arch=x86_64]" = YES;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
@@ -997,6 +1000,7 @@
71F353F50FD98DFE00CBEC28 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ "CLANG_ENABLE_OBJC_ARC[arch=x86_64]" = YES;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = YES;
GCC_DYNAMIC_NO_PIC = YES;
diff --git a/macosx/PcsxrController.h b/macosx/PcsxrController.h
index 10ae42c0..70f88e81 100755
--- a/macosx/PcsxrController.h
+++ b/macosx/PcsxrController.h
@@ -19,6 +19,8 @@
BOOL sleepInBackground;
BOOL wasPausedBeforeBGSwitch;
}
+@property (readonly) RecentItemsMenu *recentItems;
+
- (IBAction)ejectCD:(id)sender;
- (IBAction)pause:(id)sender;
- (IBAction)preferences:(id)sender;
diff --git a/macosx/PcsxrController.m b/macosx/PcsxrController.m
index ae588ea2..5949adcf 100755
--- a/macosx/PcsxrController.m
+++ b/macosx/PcsxrController.m
@@ -10,6 +10,7 @@
#include "plugins.h"
#include "misc.h"
#include "ExtendedKeys.h"
+#import "ARCBridge.h"
NSDictionary *prefStringKeys;
NSDictionary *prefByteKeys;
@@ -18,6 +19,8 @@ NSString *saveStatePath;
@implementation PcsxrController
+@synthesize recentItems;
+
- (IBAction)ejectCD:(id)sender
{
NSMutableString *deviceName;
@@ -32,8 +35,7 @@ NSString *saveStatePath;
// switch to another ISO if using internal image reader, otherwise eject the CD
if (UsingIso()) {
- NSOpenPanel* openDlg = [NSOpenPanel openPanel];
- [openDlg retain];
+ NSOpenPanel* openDlg = RETAINOBJ([NSOpenPanel openPanel]);
[openDlg setCanChooseFiles:YES];
[openDlg setCanChooseDirectories:NO];
@@ -44,7 +46,7 @@ NSString *saveStatePath;
SetCdOpenCaseTime(time(NULL) + 2);
SetIsoFile((const char *)[[[files objectAtIndex:0] path] fileSystemRepresentation]);
}
- [openDlg release];
+ RELEASEOBJ(openDlg);
} else {
char *driveLetter = CDR_getDriveLetter();
@@ -112,8 +114,7 @@ NSString *saveStatePath;
- (IBAction)runIso:(id)sender
{
- NSOpenPanel* openDlg = [NSOpenPanel openPanel];
- [openDlg retain];
+ NSOpenPanel* openDlg = RETAINOBJ([NSOpenPanel openPanel]);
[openDlg setCanChooseFiles:YES];
[openDlg setCanChooseDirectories:NO];
@@ -124,7 +125,7 @@ NSString *saveStatePath;
[recentItems addRecentItem:url];
[self runURL:url];
}
- [openDlg release];
+ RELEASEOBJ(openDlg);
}
- (IBAction)runBios:(id)sender
@@ -135,8 +136,13 @@ NSString *saveStatePath;
- (void)runURL:(NSURL*)url
{
- SetIsoFile((const char *)[[url path] fileSystemRepresentation]);
- [EmuThread run];
+ if ([EmuThread active] == YES) {
+ SetCdOpenCaseTime(time(NULL) + 2);
+ SetIsoFile([[url path] fileSystemRepresentation]);
+ } else {
+ SetIsoFile((const char *)[[url path] fileSystemRepresentation]);
+ [EmuThread run];
+ }
}
- (IBAction)freeze:(id)sender
@@ -258,11 +264,14 @@ NSString *saveStatePath;
sleepInBackground = [[NSUserDefaults standardUserDefaults] boolForKey:@"PauseInBackground"];
}
+
+#if !__has_feature(objc_arc)
- (void)dealloc
{
[pluginList release];
[super dealloc];
}
+#endif
+ (void)setConfigFromDefaults
{
@@ -439,8 +448,7 @@ NSString *saveStatePath;
strcpy(Config.BiosDir, "Bios/");
strcpy(Config.PatchesDir, "Patches/");
- saveStatePath = @"sstates";
- [saveStatePath retain];
+ saveStatePath = RETAINOBJ(@"sstates");
}
// set plugin path
@@ -499,14 +507,15 @@ NSString *saveStatePath;
for (NSString *uti in [fileHandler supportedUTIs]) {
if ([[NSWorkspace sharedWorkspace] type:utiFile conformsToType:uti]) {
canHandle = YES;
+ break;
}
}
if (canHandle) {
isHandled = [hand handleFile:filename];
- [hand release];
+ RELEASEOBJ(hand);
break;
}
- [hand release];
+ RELEASEOBJ(hand);
}
return isHandled;
diff --git a/macosx/PcsxrDiscHandler.m b/macosx/PcsxrDiscHandler.m
index 79c65704..8d83c8f9 100755
--- a/macosx/PcsxrDiscHandler.m
+++ b/macosx/PcsxrDiscHandler.m
@@ -10,6 +10,8 @@
#import "EmuThread.h"
#include "psxcommon.h"
#include "plugins.h"
+#import "RecentItemsMenu.h"
+#import "PcsxrController.h"
@implementation PcsxrDiscHandler
@@ -24,7 +26,9 @@
- (BOOL)handleFile:(NSString *)theFile
{
- if ([EmuThread active] == TRUE) {
+ PcsxrController *appDelegate = [NSApp delegate];
+ [[appDelegate recentItems] addRecentItem:[NSURL fileURLWithPath:theFile]];
+ if ([EmuThread active] == YES) {
SetCdOpenCaseTime(time(NULL) + 2);
SetIsoFile([theFile fileSystemRepresentation]);
//[EmuThread reset];
diff --git a/macosx/PcsxrMemCardController.m b/macosx/PcsxrMemCardController.m
index 858cc1dc..eebc0fc6 100755
--- a/macosx/PcsxrMemCardController.m
+++ b/macosx/PcsxrMemCardController.m
@@ -10,6 +10,7 @@
#import "PcsxrMemoryObject.h"
#import "ConfigurationController.h"
#include "sio.h"
+#import "ARCBridge.h"
#define MAX_MEMCARD_BLOCKS 15
@@ -42,7 +43,9 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha
- (void)setMemCard1Array:(NSMutableArray *)a
{
if (memCard1Array != a) {
+#if !__has_feature(objc_arc)
[memCard1Array release];
+#endif
memCard1Array = [[NSMutableArray alloc] initWithArray:a];
}
}
@@ -65,7 +68,9 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha
- (void)setMemCard2Array:(NSMutableArray *)a
{
if (memCard2Array != a) {
+#if !__has_feature(objc_arc)
[memCard2Array release];
+#endif
memCard2Array = [[NSMutableArray alloc] initWithArray:a];
}
}
@@ -129,21 +134,20 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha
PcsxrMemoryObject *ob = [[PcsxrMemoryObject alloc] initWithMcdBlock:&info];
[newArray insertObject:ob atIndex:i];
- [ob release];
+ RELEASEOBJ(ob);
}
if (theCard == 1) {
[self setMemCard1Array:newArray];
} else {
[self setMemCard2Array:newArray];
}
- [newArray release];
+ RELEASEOBJ(newArray);
}
- (void)memoryCardDidChangeNotification:(NSNotification *)aNote
{
- LoadMcd(1, Config.Mcd1);
+ LoadMcds(Config.Mcd1, Config.Mcd2);
[self loadMemoryCardInfoForCard:1];
- LoadMcd(2, Config.Mcd2);
[self loadMemoryCardInfoForCard:2];
}
@@ -400,10 +404,10 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
- [memCard1Array release];
- [memCard2Array release];
+ RELEASEOBJ(memCard1Array);
+ RELEASEOBJ(memCard2Array);
- [super dealloc];
+ SUPERDEALLOC;
}
- (BOOL)isMemoryBlockEmptyOnCard:(int)aCard block:(int)aBlock
diff --git a/macosx/PcsxrMemoryObject.m b/macosx/PcsxrMemoryObject.m
index 3cbb04b4..e8e20589 100755
--- a/macosx/PcsxrMemoryObject.m
+++ b/macosx/PcsxrMemoryObject.m
@@ -10,6 +10,7 @@
#import <Foundation/NSString.h>
#import <AppKit/NSColor.h>
#import <AppKit/NSImage.h>
+#import "ARCBridge.h"
@implementation PcsxrMemoryObject
@@ -44,10 +45,10 @@
#endif
NSImage *theImage = [[NSImage alloc] init];
[theImage addRepresentation:imageRep];
- [imageRep release];
+ RELEASEOBJ(imageRep);
[theImage setScalesWhenResized:YES];
[theImage setSize:NSMakeSize(32, 32)];
- return [theImage autorelease];
+ return AUTORELEASEOBJ(theImage);
}
- (id)initWithMcdBlock:(McdBlock *)infoBlock
@@ -55,7 +56,7 @@
if (self = [super init]) {
englishName = [[NSString alloc] initWithCString:infoBlock->Title encoding:NSASCIIStringEncoding];
sjisName = [[NSString alloc] initWithCString:infoBlock->sTitle encoding:NSShiftJISStringEncoding];
- memImage = [[PcsxrMemoryObject imageFromMcd:infoBlock->Icon] retain];
+ memImage = RETAINOBJ([PcsxrMemoryObject imageFromMcd:infoBlock->Icon]);
memName = [[NSString alloc] initWithCString:infoBlock->Name encoding:NSASCIIStringEncoding];
memID = [[NSString alloc] initWithCString:infoBlock->ID encoding:NSASCIIStringEncoding];
memIconCount = infoBlock->IconCount;
@@ -84,6 +85,7 @@
@synthesize memID;
@synthesize memIconCount;
+#if !__has_feature(objc_arc)
- (void)dealloc
{
[englishName release];
@@ -94,6 +96,7 @@
[super dealloc];
}
+#endif
- (NSString *)description
{
diff --git a/macosx/PcsxrPlugin.m b/macosx/PcsxrPlugin.m
index 7c010ef1..b7ecd5d6 100755
--- a/macosx/PcsxrPlugin.m
+++ b/macosx/PcsxrPlugin.m
@@ -10,6 +10,7 @@
#import "PcsxrPlugin.h"
#include "psxcommon.h"
#include "plugins.h"
+#import "ARCBridge.h"
@implementation PcsxrPlugin
@@ -129,13 +130,13 @@
}
if (goodPath == nil) {
- [self release];
+ RELEASEOBJ(self);
return nil;
}
pluginRef = SysLoadLibrary([goodPath fileSystemRepresentation]);
if (pluginRef == nil) {
- [self release];
+ RELEASEOBJ(self);
return nil;
}
@@ -153,13 +154,13 @@
else if (([path rangeOfString: @"net" options:NSCaseInsensitiveSearch]).length != 0)
type = PSE_LT_NET;
else {
- [self release];
+ RELEASEOBJ(self);
return nil;
}
} else {
type = (int)PSE_getLibType();
if (type != PSE_LT_GPU && type != PSE_LT_CDR && type != PSE_LT_SPU && type != PSE_LT_PAD && type != PSE_LT_NET) {
- [self release];
+ RELEASEOBJ(self);
return nil;
}
}
@@ -178,8 +179,8 @@
// save the current modification date
NSDictionary *fattrs = [[NSFileManager defaultManager] attributesOfItemAtPath:[goodPath stringByResolvingSymlinksInPath] error:NULL];
- modDate = [[fattrs fileModificationDate] retain];
- fullPlugPath = [goodPath retain];
+ modDate = RETAINOBJ([fattrs fileModificationDate]);
+ fullPlugPath = RETAINOBJ(goodPath);
active = 0;
@@ -199,30 +200,30 @@
if (pluginRef) SysCloseLibrary(pluginRef);
- [modDate release];
- [path release];
- [name release];
- [fullPlugPath release];
+ RELEASEOBJ(modDate);
+ RELEASEOBJ(path);
+ RELEASEOBJ(name);
+ RELEASEOBJ(fullPlugPath);
- [super dealloc];
+ SUPERDEALLOC;
}
- (void)runCommand:(id)arg
{
- NSAutoreleasePool *pool = [NSAutoreleasePool new];
- NSString *funcName = [arg objectAtIndex:0];
- long (*func)(void);
-
- func = SysLoadSym(pluginRef, [funcName cStringUsingEncoding:NSASCIIStringEncoding]);
- if (SysLibError() == nil) {
- func();
- } else {
- NSBeep();
+ @autoreleasepool {
+ NSString *funcName = [arg objectAtIndex:0];
+ long (*func)(void);
+
+ func = SysLoadSym(pluginRef, [funcName cStringUsingEncoding:NSASCIIStringEncoding]);
+ if (SysLibError() == nil) {
+ func();
+ } else {
+ NSBeep();
+ }
+
+ RELEASEOBJ(arg);
+ return;
}
-
- [arg release];
- [pool drain];
- return;
}
- (long)runAs:(int)aType
diff --git a/macosx/PcsxrPluginHandler.m b/macosx/PcsxrPluginHandler.m
index a2a447d4..9fcad0ee 100755
--- a/macosx/PcsxrPluginHandler.m
+++ b/macosx/PcsxrPluginHandler.m
@@ -7,6 +7,7 @@
//
#import "PcsxrPluginHandler.h"
+#import "ARCBridge.h"
@implementation PcsxrPluginHandler
@@ -80,7 +81,7 @@
NSLocalizedString(@"The installation of the specified plugin failed. Please try again, or make a manual install.", nil),
nil, nil, nil);
}
- [wrapper release];
+ RELEASEOBJ(wrapper);
}
return YES;
}
diff --git a/macosx/PluginController.m b/macosx/PluginController.m
index d89b38fc..24d0da57 100755
--- a/macosx/PluginController.m
+++ b/macosx/PluginController.m
@@ -1,6 +1,7 @@
#import "PluginController.h"
#import "PcsxrPlugin.h"
#import "PcsxrController.h"
+#import "ARCBridge.h"
@implementation PluginController
@@ -50,8 +51,8 @@
// remember the list
pluginType = type;
- plugins = [list retain];
- defaultKey = [[PcsxrPlugin defaultKeyForType:pluginType] retain];
+ plugins = RETAINOBJ(list);
+ defaultKey = RETAINOBJ([PcsxrPlugin defaultKeyForType:pluginType]);
// clear the previous menu items
[pluginMenu removeAllItems];
@@ -72,11 +73,13 @@
[self selectPlugin:pluginMenu];
}
+#if !__has_feature(objc_arc)
- (void)dealloc
{
if (plugins) [plugins release];
if (defaultKey) [defaultKey release];
[super dealloc];
}
+#endif
@end
diff --git a/macosx/PluginList.m b/macosx/PluginList.m
index 72ec6aa0..09469322 100755
--- a/macosx/PluginList.m
+++ b/macosx/PluginList.m
@@ -11,6 +11,7 @@
#import "PcsxrPlugin.h"
#include "psxcommon.h"
#include "plugins.h"
+#import "ARCBridge.h"
//NSMutableArray *plugins;
static PluginList *sPluginList = nil;
@@ -132,18 +133,18 @@ const static int typeList[5] = {PSE_LT_GPU, PSE_LT_SPU, PSE_LT_CDR, PSE_LT_PAD,
- (void)dealloc
{
- [activeGpuPlugin release];
- [activeSpuPlugin release];
- [activeCdrPlugin release];
- [activePadPlugin release];
- [activeNetPlugin release];
+ RELEASEOBJ(activeGpuPlugin);
+ RELEASEOBJ(activeSpuPlugin);
+ RELEASEOBJ(activeCdrPlugin);
+ RELEASEOBJ(activePadPlugin);
+ RELEASEOBJ(activeNetPlugin);
- [pluginList release];
+ RELEASEOBJ(pluginList);
if (sPluginList == self)
sPluginList = nil;
- [super dealloc];
+ SUPERDEALLOC;
}
- (void)refreshPlugins
@@ -174,7 +175,7 @@ const static int typeList[5] = {PSE_LT_GPU, PSE_LT_SPU, PSE_LT_CDR, PSE_LT_PAD,
PcsxrPlugin *plugin = [[PcsxrPlugin alloc] initWithPath:pname];
if (plugin != nil) {
[pluginList addObject:plugin];
- [plugin release];
+ RELEASEOBJ(plugin);
}
}
}
@@ -259,7 +260,90 @@ const static int typeList[5] = {PSE_LT_GPU, PSE_LT_SPU, PSE_LT_CDR, PSE_LT_PAD,
- (BOOL)setActivePlugin:(PcsxrPlugin *)plugin forType:(int)type
{
- PcsxrPlugin **pluginPtr;
+#if 1
+
+ PcsxrPlugin *toCopy = plugin;
+ PcsxrPlugin *pluginPtr = nil;
+
+ switch (type) {
+ case PSE_LT_GPU: pluginPtr = activeGpuPlugin; break;
+ case PSE_LT_CDR: pluginPtr = activeCdrPlugin; break;
+ case PSE_LT_SPU: pluginPtr = activeSpuPlugin; break;
+ case PSE_LT_PAD: pluginPtr = activePadPlugin; break;
+ case PSE_LT_NET: pluginPtr = activeNetPlugin; break;
+ default: return NO;
+ }
+ if (toCopy == pluginPtr) {
+ return YES;
+ }
+
+
+ BOOL active = pluginPtr && [EmuThread active];
+ BOOL wasPaused = NO;
+ if (active) {
+ // TODO: temporary freeze?
+ wasPaused = [EmuThread pauseSafe];
+ ClosePlugins();
+ ReleasePlugins();
+ }
+
+ // stop the old plugin and start the new one
+ if (pluginPtr) {
+ [pluginPtr shutdownAs:type];
+ RELEASEOBJ(pluginPtr);
+ }
+
+ if ([toCopy runAs:type] != 0) {
+ toCopy = nil;
+ }
+ switch (type) {
+ case PSE_LT_GPU:
+ activeGpuPlugin = RETAINOBJ(toCopy);
+ break;
+ case PSE_LT_CDR:
+ activeCdrPlugin = RETAINOBJ(toCopy);
+ break;
+ case PSE_LT_SPU:
+ activeSpuPlugin = RETAINOBJ(toCopy);
+ break;
+ case PSE_LT_PAD:
+ activePadPlugin = RETAINOBJ(toCopy);
+ break;
+ case PSE_LT_NET:
+ activeNetPlugin = RETAINOBJ(toCopy);
+ break;
+ }
+
+
+ // write path to the correct config entry
+ const char *str;
+ if (toCopy != nil) {
+ str = [[plugin path] fileSystemRepresentation];
+ if (str == nil) {
+ str = "Invalid Plugin";
+ }
+ } else {
+ str = "Invalid Plugin";
+ }
+
+ char **dst = [PcsxrPlugin configEntriesForType:type];
+ while (*dst) {
+ strncpy(*dst, str, MAXPATHLEN);
+ dst++;
+ }
+
+ if (active) {
+ LoadPlugins();
+ OpenPlugins();
+
+ if (!wasPaused) {
+ [EmuThread resume];
+ }
+ }
+
+ return toCopy != nil;
+#else
+ PcsxrPlugin *__strong*pluginPtr;
switch (type) {
case PSE_LT_GPU: pluginPtr = &activeGpuPlugin; break;
case PSE_LT_CDR: pluginPtr = &activeCdrPlugin; break;
@@ -284,13 +368,12 @@ const static int typeList[5] = {PSE_LT_GPU, PSE_LT_SPU, PSE_LT_CDR, PSE_LT_PAD,
// stop the old plugin and start the new one
if (*pluginPtr) {
[*pluginPtr shutdownAs:type];
-
- [*pluginPtr release];
+ RELEASEOBJ(*pluginPtr);
}
- *pluginPtr = [plugin retain];
+ *pluginPtr = RETAINOBJ(plugin);
if (*pluginPtr) {
if ([*pluginPtr runAs:type] != 0) {
- [*pluginPtr release];
+ RELEASEOBJ(*pluginPtr);
*pluginPtr = nil;
}
}
@@ -322,6 +405,8 @@ const static int typeList[5] = {PSE_LT_GPU, PSE_LT_SPU, PSE_LT_CDR, PSE_LT_PAD,
}
return *pluginPtr != nil;
+
+#endif
}
@end
diff --git a/macosx/RecentItemsMenu.m b/macosx/RecentItemsMenu.m
index aaf3f01b..a3ffa8ee 100755
--- a/macosx/RecentItemsMenu.m
+++ b/macosx/RecentItemsMenu.m
@@ -7,6 +7,7 @@
//
#import "RecentItemsMenu.h"
+#import "ARCBridge.h"
@implementation RecentItemsMenu
@@ -19,7 +20,9 @@
NSArray* recentDocuments = [[NSDocumentController sharedDocumentController] recentDocumentURLs];
NSInteger index = 0;
for(NSURL* url in recentDocuments) {
- [self addMenuItem:[self createMenuItem:url] atIndex:index];
+ NSMenuItem *tempItem = [self createMenuItem:url];
+ [self addMenuItem:tempItem atIndex:index];
+ RELEASEOBJ(tempItem);
index++;
}
}
@@ -28,13 +31,16 @@
{
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:documentURL];
- NSMenuItem* item = [self findMenuItemByURL:documentURL];
+ NSMenuItem* item = RETAINOBJ([self findMenuItemByURL:documentURL]);
if(item != nil) {
[self removeItem:item];
[self insertItem:item atIndex:0];
+ RELEASEOBJ(item);
}
else {
- [self addMenuItem:[self createMenuItem:documentURL]];
+ NSMenuItem *newitem = [self createMenuItem:documentURL];
+ [self addMenuItem:newitem];
+ RELEASEOBJ(newitem);
}
}
@@ -63,16 +69,14 @@
- (void)addMenuItem:(NSMenuItem*)item atIndex:(NSInteger)index
{
[self insertItem:item atIndex:index]; // insert at the top
- [item release];
}
- (NSMenuItem*)createMenuItem:(NSURL*)documentURL
{
- NSMenuItem *newItem = [[NSMenuItem alloc] initWithTitle:[documentURL relativePath] action:@selector(openRecentItem:) keyEquivalent:@""];
+ NSMenuItem *newItem = [[NSMenuItem alloc] initWithTitle:[documentURL lastPathComponent] action:@selector(openRecentItem:) keyEquivalent:@""];
[newItem setRepresentedObject:documentURL];
- [newItem setEnabled:YES];
+ //[newItem setEnabled:YES];
[newItem setTarget:self];
- [newItem setTag:0];
return newItem;
}
diff --git a/macosx/hotkeys.m b/macosx/hotkeys.m
index 96c1d4b9..257d78f0 100755
--- a/macosx/hotkeys.m
+++ b/macosx/hotkeys.m
@@ -13,6 +13,7 @@
#include "plugins.h"
#include "ExtendedKeys.h"
#import "PcsxrController.h"
+#import "ARCBridge.h"
#define HK_MAX_STATE 10
static id monitor;
@@ -42,7 +43,7 @@ void prevState() {
}
}
-bool handleHotkey(NSString* keyCode) {
+BOOL handleHotkey(NSString* keyCode) {
if([EmuThread active]) { // Don't catch hotkeys if there is no emulation
NSNumber *ident = [hotkeys objectForKey:keyCode];
@@ -78,11 +79,11 @@ bool handleHotkey(NSString* keyCode) {
NSLog(@"Invalid hotkey identifier.");
}
- return true;
+ return YES;
}
}
- return false;
+ return NO;
}
void setupHotkey(int hk, NSString *label, NSDictionary *binding) {
@@ -126,7 +127,7 @@ void attachHotkeys() {
}
void detachHotkeys() {
- [hotkeys release];
+ RELEASEOBJ(hotkeys); hotkeys = nil;
[NSEvent removeMonitor:monitor];
[NSEvent removeMonitor:gpuMonitor];
monitor = nil;
diff --git a/macosx/main.m b/macosx/main.m
index 2508b21e..aeac823a 100755
--- a/macosx/main.m
+++ b/macosx/main.m
@@ -13,8 +13,9 @@
#import <unistd.h>
#include "psxcommon.h"
#include "sio.h"
-#import <IOKit/pwr_mgt/IOPMLib.h>
+#include <IOKit/pwr_mgt/IOPMLib.h>
#import "hotkeys.h"
+#import "ARCBridge.h"
static BOOL sysInited = NO;
//#define EMU_LOG
@@ -116,7 +117,7 @@ void SysMessage(const char *fmt, ...) {
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:msg forKey:NSLocalizedFailureReasonErrorKey];
[NSApp presentError:[NSError errorWithDomain:@"Unknown Domain" code:-1 userInfo:userInfo]];
- [msg release];
+ RELEASEOBJ(msg);
}
void *SysLoadLibrary(const char *lib) {
@@ -157,7 +158,7 @@ void SysRunGui() {
// Close mem and plugins
void SysClose() {
EmuShutdown();
- ReleasePlugins();
+ //ReleasePlugins();
if (powerAssertion != kIOPMNullAssertionID) {
IOPMAssertionRelease(powerAssertion);