Cocoa Port (OpenEmu Plug-in): Update the OpenEmu plug-in to work using the latest version of the SDK.

This commit is contained in:
rogerman 2017-11-11 23:39:44 -08:00
parent 4abfa4466a
commit 509d117f5f
11 changed files with 287 additions and 194 deletions

View File

@ -546,7 +546,7 @@ void ClientInputHandler::ProcessInputs()
} }
else else
{ {
if ( (this->_execControl != NULL) && (this->_execControl->GetExecutionBehaviorApplied() != ExecutionBehavior_FrameJump) ) if ( (this->_execControl == NULL) || ((this->_execControl != NULL) && (this->_execControl->GetExecutionBehaviorApplied() != ExecutionBehavior_FrameJump)) )
{ {
size_t i = 0; size_t i = 0;

View File

@ -4832,7 +4832,6 @@
"\"$(SRCROOT)/openemu\"", "\"$(SRCROOT)/openemu\"",
); );
GCC_PREFIX_HEADER = openemu/DeSmuME_Prefix_OpenEmu.pch; GCC_PREFIX_HEADER = openemu/DeSmuME_Prefix_OpenEmu.pch;
HEADER_SEARCH_PATHS = "";
INFOPLIST_FILE = "openemu/Info (OpenEmu Plug-in).plist"; INFOPLIST_FILE = "openemu/Info (OpenEmu Plug-in).plist";
MACOSX_DEPLOYMENT_TARGET = 10.11; MACOSX_DEPLOYMENT_TARGET = 10.11;
PRODUCT_NAME = DeSmuME; PRODUCT_NAME = DeSmuME;
@ -4850,7 +4849,6 @@
"\"$(SRCROOT)/openemu\"", "\"$(SRCROOT)/openemu\"",
); );
GCC_PREFIX_HEADER = openemu/DeSmuME_Prefix_OpenEmu.pch; GCC_PREFIX_HEADER = openemu/DeSmuME_Prefix_OpenEmu.pch;
HEADER_SEARCH_PATHS = "";
INFOPLIST_FILE = "openemu/Info (OpenEmu Plug-in).plist"; INFOPLIST_FILE = "openemu/Info (OpenEmu Plug-in).plist";
LLVM_LTO = YES; LLVM_LTO = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11; MACOSX_DEPLOYMENT_TARGET = 10.11;

View File

@ -22,30 +22,44 @@
</BuildActionEntries> </BuildActionEntries>
</BuildAction> </BuildAction>
<TestAction <TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES" language = ""
buildConfiguration = "Debug"> shouldUseLaunchSchemeArgsEnv = "YES">
<Testables> <Testables>
</Testables> </Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction> </TestAction>
<LaunchAction <LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0" launchStyle = "0"
useCustomWorkingDirectory = "NO" useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO" ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES" debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES"> allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "ABB3C6461501BC6D00E0C22E"
BuildableName = "DeSmuME.oecoreplugin"
BlueprintName = "DeSmuME (OpenEmu Plug-in)"
ReferencedContainer = "container:DeSmuME (Latest).xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions> <AdditionalOptions>
</AdditionalOptions> </AdditionalOptions>
</LaunchAction> </LaunchAction>
<ProfileAction <ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES" shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = "" savedToolIdentifier = ""
useCustomWorkingDirectory = "NO" useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES"> debugDocumentVersioning = "YES">
</ProfileAction> </ProfileAction>
<AnalyzeAction <AnalyzeAction

View File

@ -250,7 +250,7 @@
<key>LSMinimumSystemVersion</key> <key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string> <string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSHumanReadableCopyright</key> <key>NSHumanReadableCopyright</key>
<string>Copyright ©2007-2015 DeSmuME Team. All rights reserved.</string> <string>Copyright ©2007-2017 DeSmuME Team. All rights reserved.</string>
<key>NSMainNibFile</key> <key>NSMainNibFile</key>
<string>MainMenu</string> <string>MainMenu</string>
<key>NSPrincipalClass</key> <key>NSPrincipalClass</key>

View File

@ -250,7 +250,7 @@
<key>LSMinimumSystemVersion</key> <key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string> <string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSHumanReadableCopyright</key> <key>NSHumanReadableCopyright</key>
<string>Copyright ©2007-2015 DeSmuME Team. All rights reserved.</string> <string>Copyright ©2007-2017 DeSmuME Team. All rights reserved.</string>
<key>NSMainNibFile</key> <key>NSMainNibFile</key>
<string>MainMenu</string> <string>MainMenu</string>
<key>NSPrincipalClass</key> <key>NSPrincipalClass</key>

View File

@ -28,7 +28,11 @@
#undef BOOL #undef BOOL
#endif #endif
#if defined(MAC_OS_X_VERSION_10_11) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_11) #if defined(PORT_VERSION_OS_X_APP)
#define ENABLE_SHARED_FETCH_OBJECT
#endif
#if defined(ENABLE_SHARED_FETCH_OBJECT) && defined(MAC_OS_X_VERSION_10_11) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_11)
#define ENABLE_APPLE_METAL #define ENABLE_APPLE_METAL
#endif #endif
@ -36,6 +40,8 @@
class GPUEventHandlerOSX; class GPUEventHandlerOSX;
#ifdef ENABLE_SHARED_FETCH_OBJECT
typedef std::map<CGDirectDisplayID, CVDisplayLinkRef> DisplayLinksActiveMap; typedef std::map<CGDirectDisplayID, CVDisplayLinkRef> DisplayLinksActiveMap;
typedef std::map<CGDirectDisplayID, int64_t> DisplayLinkFlushTimeLimitMap; typedef std::map<CGDirectDisplayID, int64_t> DisplayLinkFlushTimeLimitMap;
@ -77,6 +83,8 @@ typedef std::map<CGDirectDisplayID, int64_t> DisplayLinkFlushTimeLimitMap;
@end @end
#endif
@interface CocoaDSGPU : NSObject @interface CocoaDSGPU : NSObject
{ {
UInt32 gpuStateFlags; UInt32 gpuStateFlags;
@ -87,6 +95,7 @@ typedef std::map<CGDirectDisplayID, int64_t> DisplayLinkFlushTimeLimitMap;
OSSpinLock spinlockGpuState; OSSpinLock spinlockGpuState;
GPUEventHandlerOSX *gpuEvent; GPUEventHandlerOSX *gpuEvent;
GPUClientFetchObject *fetchObject; GPUClientFetchObject *fetchObject;
} }
@ -95,8 +104,6 @@ typedef std::map<CGDirectDisplayID, int64_t> DisplayLinkFlushTimeLimitMap;
@property (assign) NSUInteger gpuScale; @property (assign) NSUInteger gpuScale;
@property (assign) NSUInteger gpuColorFormat; @property (assign) NSUInteger gpuColorFormat;
@property (readonly) pthread_rwlock_t *gpuFrameRWLock; @property (readonly) pthread_rwlock_t *gpuFrameRWLock;
@property (readonly, nonatomic) GPUClientFetchObject *fetchObject;
@property (readonly, nonatomic) MacClientSharedObject *sharedData;
@property (assign) BOOL layerMainGPU; @property (assign) BOOL layerMainGPU;
@property (assign) BOOL layerMainBG0; @property (assign) BOOL layerMainBG0;
@ -124,7 +131,13 @@ typedef std::map<CGDirectDisplayID, int64_t> DisplayLinkFlushTimeLimitMap;
@property (assign) NSUInteger render3DTextureScalingFactor; @property (assign) NSUInteger render3DTextureScalingFactor;
@property (assign) BOOL render3DFragmentSamplingHack; @property (assign) BOOL render3DFragmentSamplingHack;
#ifdef ENABLE_SHARED_FETCH_OBJECT
@property (readonly, nonatomic) GPUClientFetchObject *fetchObject;
@property (readonly, nonatomic) MacClientSharedObject *sharedData;
- (void) setOutputList:(NSMutableArray *)theOutputList mutexPtr:(pthread_mutex_t *)theMutex; - (void) setOutputList:(NSMutableArray *)theOutputList mutexPtr:(pthread_mutex_t *)theMutex;
#endif
- (BOOL) gpuStateByBit:(const UInt32)stateBit; - (BOOL) gpuStateByBit:(const UInt32)stateBit;
- (NSString *) render3DRenderingEngineString; - (NSString *) render3DRenderingEngineString;
- (void) clearWithColor:(const uint16_t)colorBGRA5551; - (void) clearWithColor:(const uint16_t)colorBGRA5551;
@ -137,6 +150,8 @@ extern "C"
{ {
#endif #endif
#ifdef ENABLE_SHARED_FETCH_OBJECT
static void* RunFetchThread(void *arg); static void* RunFetchThread(void *arg);
CVReturn MacDisplayLinkCallback(CVDisplayLinkRef displayLink, CVReturn MacDisplayLinkCallback(CVDisplayLinkRef displayLink,
@ -145,6 +160,7 @@ CVReturn MacDisplayLinkCallback(CVDisplayLinkRef displayLink,
CVOptionFlags flagsIn, CVOptionFlags flagsIn,
CVOptionFlags *flagsOut, CVOptionFlags *flagsOut,
void *displayLinkContext); void *displayLinkContext);
#endif
bool OSXOpenGLRendererInit(); bool OSXOpenGLRendererInit();
bool OSXOpenGLRendererBegin(); bool OSXOpenGLRendererBegin();

View File

@ -95,8 +95,6 @@ public:
@dynamic gpuScale; @dynamic gpuScale;
@dynamic gpuColorFormat; @dynamic gpuColorFormat;
@dynamic gpuFrameRWLock; @dynamic gpuFrameRWLock;
@synthesize fetchObject;
@dynamic sharedData;
@dynamic layerMainGPU; @dynamic layerMainGPU;
@dynamic layerMainBG0; @dynamic layerMainBG0;
@ -124,6 +122,10 @@ public:
@dynamic render3DTextureScalingFactor; @dynamic render3DTextureScalingFactor;
@dynamic render3DFragmentSamplingHack; @dynamic render3DFragmentSamplingHack;
#ifdef ENABLE_SHARED_FETCH_OBJECT
@synthesize fetchObject;
@dynamic sharedData;
#endif
- (id)init - (id)init
{ {
@ -186,6 +188,7 @@ public:
} }
#endif #endif
#ifdef ENABLE_SHARED_FETCH_OBJECT
if (fetchObject == NULL) if (fetchObject == NULL)
{ {
fetchObject = new MacOGLClientFetchObject; fetchObject = new MacOGLClientFetchObject;
@ -193,6 +196,7 @@ public:
fetchObject->Init(); fetchObject->Init();
gpuEvent->SetFetchObject(fetchObject); gpuEvent->SetFetchObject(fetchObject);
#endif
[self clearWithColor:0x8000]; [self clearWithColor:0x8000];
@ -253,14 +257,20 @@ public:
{ {
gpuEvent->Render3DLock(); gpuEvent->Render3DLock();
gpuEvent->FramebufferLockWrite(); gpuEvent->FramebufferLockWrite();
#ifdef ENABLE_SHARED_FETCH_OBJECT
pthread_rwlock_wrlock([[self sharedData] rwlockFramebufferAtIndex:0]); pthread_rwlock_wrlock([[self sharedData] rwlockFramebufferAtIndex:0]);
pthread_rwlock_wrlock([[self sharedData] rwlockFramebufferAtIndex:1]); pthread_rwlock_wrlock([[self sharedData] rwlockFramebufferAtIndex:1]);
#endif
GPU->SetCustomFramebufferSize(theDimensions.width, theDimensions.height); GPU->SetCustomFramebufferSize(theDimensions.width, theDimensions.height);
fetchObject->SetFetchBuffers(GPU->GetDisplayInfo());
#ifdef ENABLE_SHARED_FETCH_OBJECT
fetchObject->SetFetchBuffers(GPU->GetDisplayInfo());
pthread_rwlock_unlock([[self sharedData] rwlockFramebufferAtIndex:1]); pthread_rwlock_unlock([[self sharedData] rwlockFramebufferAtIndex:1]);
pthread_rwlock_unlock([[self sharedData] rwlockFramebufferAtIndex:0]); pthread_rwlock_unlock([[self sharedData] rwlockFramebufferAtIndex:0]);
#endif
gpuEvent->FramebufferUnlock(); gpuEvent->FramebufferUnlock();
gpuEvent->Render3DUnlock(); gpuEvent->Render3DUnlock();
} }
@ -304,14 +314,20 @@ public:
// Change the color format. // Change the color format.
gpuEvent->Render3DLock(); gpuEvent->Render3DLock();
gpuEvent->FramebufferLockWrite(); gpuEvent->FramebufferLockWrite();
#ifdef ENABLE_SHARED_FETCH_OBJECT
pthread_rwlock_wrlock([[self sharedData] rwlockFramebufferAtIndex:0]); pthread_rwlock_wrlock([[self sharedData] rwlockFramebufferAtIndex:0]);
pthread_rwlock_wrlock([[self sharedData] rwlockFramebufferAtIndex:1]); pthread_rwlock_wrlock([[self sharedData] rwlockFramebufferAtIndex:1]);
#endif
GPU->SetColorFormat((NDSColorFormat)colorFormat); GPU->SetColorFormat((NDSColorFormat)colorFormat);
fetchObject->SetFetchBuffers(GPU->GetDisplayInfo());
#ifdef ENABLE_SHARED_FETCH_OBJECT
fetchObject->SetFetchBuffers(GPU->GetDisplayInfo());
pthread_rwlock_unlock([[self sharedData] rwlockFramebufferAtIndex:1]); pthread_rwlock_unlock([[self sharedData] rwlockFramebufferAtIndex:1]);
pthread_rwlock_unlock([[self sharedData] rwlockFramebufferAtIndex:0]); pthread_rwlock_unlock([[self sharedData] rwlockFramebufferAtIndex:0]);
#endif
gpuEvent->FramebufferUnlock(); gpuEvent->FramebufferUnlock();
gpuEvent->Render3DUnlock(); gpuEvent->Render3DUnlock();
} }
@ -332,10 +348,12 @@ public:
return gpuEvent->GetFrameRWLock(); return gpuEvent->GetFrameRWLock();
} }
#ifdef ENABLE_SHARED_FETCH_OBJECT
- (void) setOutputList:(NSMutableArray *)theOutputList mutexPtr:(pthread_mutex_t *)theMutex - (void) setOutputList:(NSMutableArray *)theOutputList mutexPtr:(pthread_mutex_t *)theMutex
{ {
[(MacClientSharedObject *)fetchObject->GetClientData() setOutputList:theOutputList mutex:theMutex]; [(MacClientSharedObject *)fetchObject->GetClientData() setOutputList:theOutputList mutex:theMutex];
} }
#endif
- (void) setRender3DRenderingEngine:(NSInteger)rendererID - (void) setRender3DRenderingEngine:(NSInteger)rendererID
{ {
@ -851,15 +869,20 @@ public:
- (void) clearWithColor:(const uint16_t)colorBGRA5551 - (void) clearWithColor:(const uint16_t)colorBGRA5551
{ {
gpuEvent->FramebufferLockWrite(); gpuEvent->FramebufferLockWrite();
#ifdef ENABLE_SHARED_FETCH_OBJECT
const u8 bufferIndex = GPU->GetDisplayInfo().bufferIndex; const u8 bufferIndex = GPU->GetDisplayInfo().bufferIndex;
pthread_rwlock_wrlock([[self sharedData] rwlockFramebufferAtIndex:bufferIndex]); pthread_rwlock_wrlock([[self sharedData] rwlockFramebufferAtIndex:bufferIndex]);
#endif
GPU->ClearWithColor(colorBGRA5551); GPU->ClearWithColor(colorBGRA5551);
#ifdef ENABLE_SHARED_FETCH_OBJECT
pthread_rwlock_unlock([[self sharedData] rwlockFramebufferAtIndex:bufferIndex]); pthread_rwlock_unlock([[self sharedData] rwlockFramebufferAtIndex:bufferIndex]);
#endif
gpuEvent->FramebufferUnlock(); gpuEvent->FramebufferUnlock();
#if !defined(PORT_VERSION_OPENEMU) #ifdef ENABLE_SHARED_FETCH_OBJECT
[[self sharedData] signalFetchAtIndex:bufferIndex]; [[self sharedData] signalFetchAtIndex:bufferIndex];
#endif #endif
} }
@ -886,6 +909,8 @@ public:
@end @end
#ifdef ENABLE_SHARED_FETCH_OBJECT
@implementation MacClientSharedObject @implementation MacClientSharedObject
@synthesize GPUFetchObject; @synthesize GPUFetchObject;
@ -1206,6 +1231,8 @@ public:
@end @end
#endif
#pragma mark - #pragma mark -
GPUEventHandlerOSX::GPUEventHandlerOSX() GPUEventHandlerOSX::GPUEventHandlerOSX()
@ -1245,7 +1272,7 @@ void GPUEventHandlerOSX::DidFrameBegin(bool isFrameSkipRequested, const u8 targe
{ {
this->FramebufferLockWrite(); this->FramebufferLockWrite();
#if !defined(PORT_VERSION_OPENEMU) #ifdef ENABLE_SHARED_FETCH_OBJECT
if (!isFrameSkipRequested) if (!isFrameSkipRequested)
{ {
MacClientSharedObject *sharedViewObject = (MacClientSharedObject *)this->_fetchObject->GetClientData(); MacClientSharedObject *sharedViewObject = (MacClientSharedObject *)this->_fetchObject->GetClientData();
@ -1256,7 +1283,7 @@ void GPUEventHandlerOSX::DidFrameBegin(bool isFrameSkipRequested, const u8 targe
void GPUEventHandlerOSX::DidFrameEnd(bool isFrameSkipped, const NDSDisplayInfo &latestDisplayInfo) void GPUEventHandlerOSX::DidFrameEnd(bool isFrameSkipped, const NDSDisplayInfo &latestDisplayInfo)
{ {
#if !defined(PORT_VERSION_OPENEMU) #ifdef ENABLE_SHARED_FETCH_OBJECT
MacClientSharedObject *sharedViewObject = (MacClientSharedObject *)this->_fetchObject->GetClientData(); MacClientSharedObject *sharedViewObject = (MacClientSharedObject *)this->_fetchObject->GetClientData();
if (!isFrameSkipped) if (!isFrameSkipped)
{ {
@ -1267,7 +1294,7 @@ void GPUEventHandlerOSX::DidFrameEnd(bool isFrameSkipped, const NDSDisplayInfo &
this->FramebufferUnlock(); this->FramebufferUnlock();
#if !defined(PORT_VERSION_OPENEMU) #ifdef ENABLE_SHARED_FETCH_OBJECT
if (!isFrameSkipped) if (!isFrameSkipped)
{ {
[sharedViewObject signalFetchAtIndex:latestDisplayInfo.bufferIndex]; [sharedViewObject signalFetchAtIndex:latestDisplayInfo.bufferIndex];
@ -1371,6 +1398,8 @@ CGLContextObj OSXOpenGLRendererContext = NULL;
CGLPBufferObj OSXOpenGLRendererPBuffer = NULL; CGLPBufferObj OSXOpenGLRendererPBuffer = NULL;
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#ifdef ENABLE_SHARED_FETCH_OBJECT
static void* RunFetchThread(void *arg) static void* RunFetchThread(void *arg)
{ {
MacClientSharedObject *sharedData = (MacClientSharedObject *)arg; MacClientSharedObject *sharedData = (MacClientSharedObject *)arg;
@ -1392,6 +1421,8 @@ CVReturn MacDisplayLinkCallback(CVDisplayLinkRef displayLink,
return kCVReturnSuccess; return kCVReturnSuccess;
} }
#endif
bool OSXOpenGLRendererInit() bool OSXOpenGLRendererInit()
{ {
static bool isContextAlreadyCreated = false; static bool isContextAlreadyCreated = false;

View File

@ -18,18 +18,20 @@
<string>v0.9.12 (OpenEmu Plug-in)</string> <string>v0.9.12 (OpenEmu Plug-in)</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>0.9.12</string> <string>0.9.12</string>
<key>CSResourcesFileMapped</key> <key>CSResourcesFileMapped</key>
<string>yes</string> <string>yes</string>
<key>NSHumanReadableCopyright</key> <key>NSHumanReadableCopyright</key>
<string>Copyright © 2012-2015 DeSmuME Team. All rights reserved.</string> <string>Copyright © 2012-2017 DeSmuME Team. All rights reserved.</string>
<key>NSPrincipalClass</key> <key>NSPrincipalClass</key>
<string>OEGameCoreController</string> <string>OEGameCoreController</string>
<key>OEGameCoreClass</key> <key>OEGameCoreClass</key>
<string>NDSGameCore</string> <string>NDSGameCore</string>
<key>OEGameCorePlayerCount</key>
<string>1</string>
<key>OEGameCoreOptions</key> <key>OEGameCoreOptions</key>
<dict> <dict>
<key>openemu.system.nds</key> <key>openemu.system.nds</key>
@ -38,15 +40,17 @@
<true/> <true/>
</dict> </dict>
</dict> </dict>
<key>OEGameCorePlayerCount</key>
<string>1</string>
<key>OEProjectURL</key> <key>OEProjectURL</key>
<string>http://desmume.org/</string> <string>http://desmume.org/</string>
<key>OESystemIdentifiers</key> <key>OESystemIdentifiers</key>
<array> <array>
<string>openemu.system.nds</string> <string>openemu.system.nds</string>
</array> </array>
<key>SUFeedURL</key>
<string>https://raw.github.com/OpenEmu/OpenEmu-Update/master/desmume_appcast.xml</string>
<key>SUEnableAutomaticChecks</key> <key>SUEnableAutomaticChecks</key>
<string>1</string> <string>1</string>
<key>SUFeedURL</key>
<string>https://raw.github.com/OpenEmu/OpenEmu-Update/master/desmume_appcast.xml</string>
</dict> </dict>
</plist> </plist>

View File

@ -1,5 +1,5 @@
/* /*
Copyright (C) 2012-2015 DeSmuME team Copyright (C) 2012-2017 DeSmuME team
This file is free software: you can redistribute it and/or modify This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -39,7 +39,7 @@
NSInteger displayMode; NSInteger displayMode;
OEIntRect displayRect; OEIntRect displayRect;
OEIntSize displayAspectRatio; OEIntSize displayAspectRatio;
NSInteger inputID[OENDSButtonCount]; // Key = OpenEmu's input ID, Value = DeSmuME's input ID NSUInteger inputID[OENDSButtonCount]; // Key = OpenEmu's input ID, Value = DeSmuME's input ID
OSSpinLock spinlockDisplayMode; OSSpinLock spinlockDisplayMode;
pthread_rwlock_t rwlockCoreExecute; pthread_rwlock_t rwlockCoreExecute;

View File

@ -22,6 +22,8 @@
#import "cocoa_firmware.h" #import "cocoa_firmware.h"
#import "cocoa_GPU.h" #import "cocoa_GPU.h"
#import "cocoa_input.h" #import "cocoa_input.h"
#import "ClientDisplayView.h"
#import "ClientInputHandler.h"
#import "OESoundInterface.h" #import "OESoundInterface.h"
#import "OENDSSystemResponderClient.h" #import "OENDSSystemResponderClient.h"
@ -57,21 +59,21 @@ volatile bool execute = true;
touchLocation.x = 0; touchLocation.x = 0;
touchLocation.y = 0; touchLocation.y = 0;
inputID[OENDSButtonUp] = DSControllerState_Up; inputID[OENDSButtonUp] = NDSInputID_Up;
inputID[OENDSButtonDown] = DSControllerState_Down; inputID[OENDSButtonDown] = NDSInputID_Down;
inputID[OENDSButtonLeft] = DSControllerState_Left; inputID[OENDSButtonLeft] = NDSInputID_Left;
inputID[OENDSButtonRight] = DSControllerState_Right; inputID[OENDSButtonRight] = NDSInputID_Right;
inputID[OENDSButtonA] = DSControllerState_A; inputID[OENDSButtonA] = NDSInputID_A;
inputID[OENDSButtonB] = DSControllerState_B; inputID[OENDSButtonB] = NDSInputID_B;
inputID[OENDSButtonX] = DSControllerState_X; inputID[OENDSButtonX] = NDSInputID_X;
inputID[OENDSButtonY] = DSControllerState_Y; inputID[OENDSButtonY] = NDSInputID_Y;
inputID[OENDSButtonL] = DSControllerState_L; inputID[OENDSButtonL] = NDSInputID_L;
inputID[OENDSButtonR] = DSControllerState_R; inputID[OENDSButtonR] = NDSInputID_R;
inputID[OENDSButtonStart] = DSControllerState_Start; inputID[OENDSButtonStart] = NDSInputID_Start;
inputID[OENDSButtonSelect] = DSControllerState_Select; inputID[OENDSButtonSelect] = NDSInputID_Select;
inputID[OENDSButtonMicrophone] = DSControllerState_Microphone; inputID[OENDSButtonMicrophone] = NDSInputID_Microphone;
inputID[OENDSButtonLid] = DSControllerState_Lid; inputID[OENDSButtonLid] = NDSInputID_Lid;
inputID[OENDSButtonDebug] = DSControllerState_Debug; inputID[OENDSButtonDebug] = NDSInputID_Debug;
// Set up the emulation core // Set up the emulation core
CommonSettings.advanced_timing = true; CommonSettings.advanced_timing = true;
@ -86,7 +88,7 @@ volatile bool execute = true;
// Set up the DS controller // Set up the DS controller
cdsController = [[[[CocoaDSController alloc] init] retain] autorelease]; cdsController = [[[[CocoaDSController alloc] init] retain] autorelease];
[cdsController setMicMode:MicrophoneMode_InternalNoise]; [cdsController startHardwareMicDevice];
// Set up the cheat system // Set up the cheat system
cdsCheats = [[[[CocoaDSCheatManager alloc] init] retain] autorelease]; cdsCheats = [[[[CocoaDSCheatManager alloc] init] retain] autorelease];
@ -140,7 +142,7 @@ volatile bool execute = true;
- (NSInteger) displayMode - (NSInteger) displayMode
{ {
OSSpinLockLock(&spinlockDisplayMode); OSSpinLockLock(&spinlockDisplayMode);
NSInteger theMode = displayMode; const NSInteger theMode = displayMode;
OSSpinLockUnlock(&spinlockDisplayMode); OSSpinLockUnlock(&spinlockDisplayMode);
return theMode; return theMode;
@ -187,46 +189,7 @@ volatile bool execute = true;
return NO; return NO;
} }
#pragma mark - Execution #pragma mark - Starting
- (BOOL)rendersToOpenGL
{
return NO;
}
#pragma mark - ABSTRACT METHODS
- (void)resetEmulation
{
pthread_rwlock_wrlock(&rwlockCoreExecute);
NDS_Reset();
pthread_rwlock_unlock(&rwlockCoreExecute);
execute = true;
}
- (void)executeFrameSkippingFrame:(BOOL)skip
{
if (skip)
{
NDS_SkipNextFrame();
}
[self executeFrame];
}
- (void)executeFrame
{
[cdsController flush];
NDS_beginProcessingInput();
NDS_endProcessingInput();
pthread_rwlock_wrlock(&rwlockCoreExecute);
NDS_exec<false>();
pthread_rwlock_unlock(&rwlockCoreExecute);
SPU_Emulate_user();
}
- (BOOL)loadFileAtPath:(NSString*)path - (BOOL)loadFileAtPath:(NSString*)path
{ {
@ -258,12 +221,75 @@ volatile bool execute = true;
return isRomLoaded; return isRomLoaded;
} }
#pragma mark - Execution
- (NSTimeInterval)frameInterval
{
return DS_FRAMES_PER_SECOND;
}
- (void)executeFrame
{
ClientInputHandler *inputHandler = [cdsController inputHandler];
inputHandler->ProcessInputs();
inputHandler->ApplyInputs();
pthread_rwlock_wrlock(&rwlockCoreExecute);
NDS_exec<false>();
pthread_rwlock_unlock(&rwlockCoreExecute);
SPU_Emulate_user();
}
- (void)resetEmulation
{
pthread_rwlock_wrlock(&rwlockCoreExecute);
NDS_Reset();
pthread_rwlock_unlock(&rwlockCoreExecute);
execute = true;
}
- (void)executeFrameSkippingFrame:(BOOL)skip
{
if (skip)
{
NDS_SkipNextFrame();
}
[self executeFrame];
}
#pragma mark - Video #pragma mark - Video
- (const void *)getVideoBufferWithHint:(void *)hint
{
return GPU->GetDisplayInfo().masterNativeBuffer;
}
- (OEGameCoreRendering)gameCoreRendering
{
return OEGameCoreRendering2DVideo;
}
- (BOOL)hasAlternateRenderingThread
{
return NO;
}
- (BOOL)needsDoubleBufferedFBO
{
return NO;
}
- (OEIntSize)bufferSize
{
return OEIntSizeMake(GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT * 2);
}
- (OEIntRect)screenRect - (OEIntRect)screenRect
{ {
OSSpinLockLock(&spinlockDisplayMode); OSSpinLockLock(&spinlockDisplayMode);
OEIntRect theRect = displayRect; const OEIntRect theRect = displayRect;
OSSpinLockUnlock(&spinlockDisplayMode); OSSpinLockUnlock(&spinlockDisplayMode);
return theRect; return theRect;
@ -272,64 +298,27 @@ volatile bool execute = true;
- (OEIntSize)aspectSize - (OEIntSize)aspectSize
{ {
OSSpinLockLock(&spinlockDisplayMode); OSSpinLockLock(&spinlockDisplayMode);
OEIntSize theAspectRatio = displayAspectRatio; const OEIntSize theAspectRatio = displayAspectRatio;
OSSpinLockUnlock(&spinlockDisplayMode); OSSpinLockUnlock(&spinlockDisplayMode);
return theAspectRatio; return theAspectRatio;
} }
- (OEIntSize)bufferSize
{
return OEIntSizeMake(GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT * 2);
}
- (const void *)videoBuffer
{
return GPU->GetDisplayInfo().masterNativeBuffer;
}
- (GLenum)pixelFormat
{
return GL_RGBA;
}
- (GLenum)pixelType - (GLenum)pixelType
{ {
return GL_UNSIGNED_SHORT_1_5_5_5_REV; return GL_UNSIGNED_SHORT_1_5_5_5_REV;
} }
- (GLenum)pixelFormat
{
return GL_RGBA;
}
- (GLenum)internalPixelFormat - (GLenum)internalPixelFormat
{ {
return GL_RGB5_A1; return GL_RGB5_A1;
} }
- (NSTimeInterval)frameInterval
{
return DS_FRAMES_PER_SECOND;
}
- (void)changeDisplayMode
{
switch (displayMode)
{
case ClientDisplayMode_Main:
[self setDisplayMode:ClientDisplayMode_Touch];
break;
case ClientDisplayMode_Touch:
[self setDisplayMode:ClientDisplayMode_Dual];
break;
case ClientDisplayMode_Dual:
[self setDisplayMode:ClientDisplayMode_Main];
break;
default:
return;
break;
}
}
#pragma mark - Audio #pragma mark - Audio
- (NSUInteger)audioBufferCount - (NSUInteger)audioBufferCount
@ -342,16 +331,16 @@ volatile bool execute = true;
return SPU_NUMBER_CHANNELS; return SPU_NUMBER_CHANNELS;
} }
- (double)audioSampleRate
{
return SPU_SAMPLE_RATE;
}
- (NSUInteger)audioBitDepth - (NSUInteger)audioBitDepth
{ {
return SPU_SAMPLE_RESOLUTION; return SPU_SAMPLE_RESOLUTION;
} }
- (double)audioSampleRate
{
return SPU_SAMPLE_RATE;
}
- (NSUInteger)channelCountForBuffer:(NSUInteger)buffer - (NSUInteger)channelCountForBuffer:(NSUInteger)buffer
{ {
return [self channelCount]; return [self channelCount];
@ -367,6 +356,74 @@ volatile bool execute = true;
return [self audioSampleRate]; return [self audioSampleRate];
} }
#pragma mark - Save States
- (void)saveStateToFileAtPath:(NSString *)fileName completionHandler:(void(^)(BOOL success, NSError *error))block
{
BOOL fileSuccess = [CocoaDSFile saveState:[NSURL fileURLWithPath:fileName]];
if (block != nil)
{
block(fileSuccess, nil);
}
}
- (void)loadStateFromFileAtPath:(NSString *)fileName completionHandler:(void(^)(BOOL success, NSError *error))block
{
BOOL fileSuccess = [CocoaDSFile loadState:[NSURL fileURLWithPath:fileName]];
if (block != nil)
{
block(fileSuccess, nil);
}
}
#pragma mark - Optional
- (NSTrackingAreaOptions)mouseTrackingOptions
{
return 0;
}
#pragma mark - Cheats - Optional
- (void)setCheat:(NSString *)code setType:(NSString *)type setEnabled:(BOOL)enabled
{
// This method can be used for both adding a new cheat or setting the enable
// state on an existing cheat, so be sure to account for both cases.
// First check if the cheat exists.
CocoaDSCheatItem *cheatItem = (CocoaDSCheatItem *)[addedCheatsDict objectForKey:code];
if (cheatItem == nil)
{
// If the cheat doesn't already exist, then create a new one and add it.
cheatItem = [[[CocoaDSCheatItem alloc] init] autorelease];
[cheatItem setCheatType:CHEAT_TYPE_ACTION_REPLAY]; // Default to Action Replay for now
[cheatItem setFreezeType:0];
[cheatItem setDescription:@""]; // OpenEmu takes care of this
[cheatItem setCode:code];
[cheatItem setMemAddress:0x00000000]; // UNUSED
[cheatItem setBytes:1]; // UNUSED
[cheatItem setValue:0]; // UNUSED
[cheatItem setEnabled:enabled];
[[self cdsCheats] add:cheatItem];
// OpenEmu doesn't currently save cheats per game, so assume that the
// cheat list is short and that code strings are unique. This allows
// us to get away with simply saving the cheat code string and hashing
// for it later.
[addedCheatsDict setObject:cheatItem forKey:code];
}
else
{
// If the cheat does exist, then just set its enable state.
[cheatItem setEnabled:enabled];
[[self cdsCheats] update:cheatItem];
}
}
#pragma mark - Input #pragma mark - Input
- (oneway void)didPushNDSButton:(OENDSButton)button forPlayer:(NSUInteger)player - (oneway void)didPushNDSButton:(OENDSButton)button forPlayer:(NSUInteger)player
@ -432,65 +489,25 @@ volatile bool execute = true;
[cdsController setTouchState:NO location:touchLocation]; [cdsController setTouchState:NO location:touchLocation];
} }
- (NSTrackingAreaOptions)mouseTrackingOptions - (void)changeDisplayMode
{ {
return 0; switch (displayMode)
}
- (void)settingWasSet:(id)aValue forKey:(NSString *)keyName
{ {
DLog(@"keyName = %@", keyName); case ClientDisplayMode_Main:
//[self doesNotImplementSelector:_cmd]; [self setDisplayMode:ClientDisplayMode_Touch];
} break;
#pragma mark - Save State case ClientDisplayMode_Touch:
[self setDisplayMode:ClientDisplayMode_Dual];
break;
- (BOOL)saveStateToFileAtPath:(NSString *)fileName case ClientDisplayMode_Dual:
{ [self setDisplayMode:ClientDisplayMode_Main];
return [CocoaDSFile saveState:[NSURL fileURLWithPath:fileName]]; break;
}
- (BOOL)loadStateFromFileAtPath:(NSString *)fileName default:
{ return;
return [CocoaDSFile loadState:[NSURL fileURLWithPath:fileName]]; break;
}
#pragma mark - Miscellaneous
- (void)setCheat:(NSString *)code setType:(NSString *)type setEnabled:(BOOL)enabled
{
// This method can be used for both adding a new cheat or setting the enable
// state on an existing cheat, so be sure to account for both cases.
// First check if the cheat exists.
CocoaDSCheatItem *cheatItem = (CocoaDSCheatItem *)[addedCheatsDict objectForKey:code];
if (cheatItem == nil)
{
// If the cheat doesn't already exist, then create a new one and add it.
cheatItem = [[[CocoaDSCheatItem alloc] init] autorelease];
[cheatItem setCheatType:CHEAT_TYPE_ACTION_REPLAY]; // Default to Action Replay for now
[cheatItem setFreezeType:0];
[cheatItem setDescription:@""]; // OpenEmu takes care of this
[cheatItem setCode:code];
[cheatItem setMemAddress:0x00000000]; // UNUSED
[cheatItem setBytes:1]; // UNUSED
[cheatItem setValue:0]; // UNUSED
[cheatItem setEnabled:enabled];
[[self cdsCheats] add:cheatItem];
// OpenEmu doesn't currently save cheats per game, so assume that the
// cheat list is short and that code strings are unique. This allows
// us to get away with simply saving the cheat code string and hashing
// for it later.
[addedCheatsDict setObject:cheatItem forKey:code];
}
else
{
// If the cheat does exist, then just set its enable state.
[cheatItem setEnabled:enabled];
[[self cdsCheats] update:cheatItem];
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
Copyright (C) 2012-2015 DeSmuME team Copyright (C) 2012-2017 DeSmuME team
This file is free software: you can redistribute it and/or modify This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -83,6 +83,19 @@ void SNDOpenEmuUpdateAudio(s16 *buffer, u32 num_samples)
u32 SNDOpenEmuGetAudioSpace() u32 SNDOpenEmuGetAudioSpace()
{ {
// The latest version of the OpenEmu API (as of 11/11/2017) renames [OERingBuffer usedBytes]
// to [OERingBuffer freeBytes]. Due to poor planning on their part, using [OERingBuffer freeBytes]
// on the current release version of OpenEmu.app, v2.0.5, will cause the plug-in to fail due to
// [OERingBuffer freeBytes] not being available in that version.
//
// Therefore, let's make a note of the problem here and revert OpenEmuBase.framework back to a
// version before the method renaming broke things, then use the older-named method instead.
//
// TODO: Use the newer-named method, [OERingBuffer freeBytes], when a newer version of OpenEmu.app
// is finally released. Or maybe wait for the OpenEmu Team to bring back [OERingBuffer usedBytes]
// and let them deprecate it correctly.
//return (u32)[openEmuSoundInterfaceBuffer freeBytes] / SPU_SAMPLE_SIZE;
return (u32)[openEmuSoundInterfaceBuffer usedBytes] / SPU_SAMPLE_SIZE; return (u32)[openEmuSoundInterfaceBuffer usedBytes] / SPU_SAMPLE_SIZE;
} }