summaryrefslogtreecommitdiff
path: root/macosx/EmuThread.m
diff options
context:
space:
mode:
authorSND\weimingzhi_cp <SND\weimingzhi_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2009-11-04 02:46:27 +0000
committerSND\weimingzhi_cp <SND\weimingzhi_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2009-11-04 02:46:27 +0000
commit559fd026bb57e0d71615b237c37a31f287af5940 (patch)
treeab44f09ca16f2e840c6a544a2fba787577c99960 /macosx/EmuThread.m
parenta2da60aec08bb90c8e55f9ff5178701a309dbb9c (diff)
downloadpcsxr-559fd026bb57e0d71615b237c37a31f287af5940.tar.gz
git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@35397 e17a0e51-4ae3-4d35-97c3-1a29b211df97
Diffstat (limited to 'macosx/EmuThread.m')
-rw-r--r--macosx/EmuThread.m94
1 files changed, 82 insertions, 12 deletions
diff --git a/macosx/EmuThread.m b/macosx/EmuThread.m
index cb4ef8fb..f8be4338 100644
--- a/macosx/EmuThread.m
+++ b/macosx/EmuThread.m
@@ -33,7 +33,7 @@ static pthread_mutex_t eventMutex;
- (void)EmuThreadRun:(id)anObject
{
pool = [[NSAutoreleasePool alloc] init];
-
+
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(emuWindowDidClose:)
name:@"emuWindowDidClose" object:nil];
@@ -45,14 +45,14 @@ static pthread_mutex_t eventMutex;
[[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;
-
+
if (setjmp(restartJmp) == 0) {
psxReset();
}
@@ -80,6 +80,42 @@ done:
return;
}
+- (void)EmuThreadRunBios:(id)anObject
+{
+ pool = [[NSAutoreleasePool alloc] init];
+
+ [[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;
+
+ if (setjmp(restartJmp) == 0) {
+ psxReset();
+ }
+
+ psxCpu->Execute();
+
+done:
+ [pool release]; pool = nil;
+ emuThread = nil;
+
+ return;
+}
+
- (void)dealloc
{
// remove all registered observers
@@ -170,39 +206,73 @@ done:
}
}
-
+ (void)run
{
int err;
-
+
if (emuThread) {
[EmuThread resume];
return;
}
-
+
if (pthread_mutex_lock(&eventMutex) != 0) {
err = pthread_cond_init(&eventCond, NULL);
if (err) return;
err = pthread_mutex_init(&eventMutex, NULL);
if (err) return;
-
+
pthread_mutex_lock(&eventMutex);
}
-
+
safeEvent = EMUEVENT_NONE;
paused = NO;
-
+
if (SysInit() != 0) {
pthread_mutex_unlock(&eventMutex);
return;
}
-
- emuThread = [[EmuThread alloc] init];
+
+ emuThread = [[EmuThread alloc] init];
[NSThread detachNewThreadSelector:@selector(EmuThreadRun:)
toTarget:emuThread withObject:nil];
-
+
+ pthread_mutex_unlock(&eventMutex);
+}
+
++ (void)runBios
+{
+ int err;
+
+ if (emuThread) {
+ [EmuThread resume];
+ return;
+ }
+
+ if (pthread_mutex_lock(&eventMutex) != 0) {
+ err = pthread_cond_init(&eventCond, NULL);
+ if (err) return;
+
+ err = pthread_mutex_init(&eventMutex, NULL);
+ if (err) return;
+
+ pthread_mutex_lock(&eventMutex);
+ }
+
+ safeEvent = EMUEVENT_NONE;
+ paused = NO;
+
+ if (SysInit() != 0) {
+ pthread_mutex_unlock(&eventMutex);
+ return;
+ }
+
+ emuThread = [[EmuThread alloc] init];
+
+ [NSThread detachNewThreadSelector:@selector(EmuThreadRunBios:)
+ toTarget:emuThread withObject:nil];
+
pthread_mutex_unlock(&eventMutex);
}