diff --git a/desmume/src/frontend/cocoa/ClientInputHandler.cpp b/desmume/src/frontend/cocoa/ClientInputHandler.cpp index 5f3eeaa71..b587a3f24 100644 --- a/desmume/src/frontend/cocoa/ClientInputHandler.cpp +++ b/desmume/src/frontend/cocoa/ClientInputHandler.cpp @@ -546,7 +546,7 @@ void ClientInputHandler::ProcessInputs() } 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; diff --git a/desmume/src/frontend/cocoa/DeSmuME (Latest).xcodeproj/project.pbxproj b/desmume/src/frontend/cocoa/DeSmuME (Latest).xcodeproj/project.pbxproj index 71ca3aeda..4b97701ab 100644 --- a/desmume/src/frontend/cocoa/DeSmuME (Latest).xcodeproj/project.pbxproj +++ b/desmume/src/frontend/cocoa/DeSmuME (Latest).xcodeproj/project.pbxproj @@ -4832,7 +4832,6 @@ "\"$(SRCROOT)/openemu\"", ); GCC_PREFIX_HEADER = openemu/DeSmuME_Prefix_OpenEmu.pch; - HEADER_SEARCH_PATHS = ""; INFOPLIST_FILE = "openemu/Info (OpenEmu Plug-in).plist"; MACOSX_DEPLOYMENT_TARGET = 10.11; PRODUCT_NAME = DeSmuME; @@ -4850,7 +4849,6 @@ "\"$(SRCROOT)/openemu\"", ); GCC_PREFIX_HEADER = openemu/DeSmuME_Prefix_OpenEmu.pch; - HEADER_SEARCH_PATHS = ""; INFOPLIST_FILE = "openemu/Info (OpenEmu Plug-in).plist"; LLVM_LTO = YES; MACOSX_DEPLOYMENT_TARGET = 10.11; diff --git a/desmume/src/frontend/cocoa/DeSmuME (Latest).xcodeproj/xcshareddata/xcschemes/DeSmuME (OpenEmu Plug-in).xcscheme b/desmume/src/frontend/cocoa/DeSmuME (Latest).xcodeproj/xcshareddata/xcschemes/DeSmuME (OpenEmu Plug-in).xcscheme index 85c1ef7c8..f176b3d1a 100644 --- a/desmume/src/frontend/cocoa/DeSmuME (Latest).xcodeproj/xcshareddata/xcschemes/DeSmuME (OpenEmu Plug-in).xcscheme +++ b/desmume/src/frontend/cocoa/DeSmuME (Latest).xcodeproj/xcshareddata/xcschemes/DeSmuME (OpenEmu Plug-in).xcscheme @@ -22,30 +22,44 @@ + language = "" + shouldUseLaunchSchemeArgsEnv = "YES"> + + + + + + LSMinimumSystemVersion ${MACOSX_DEPLOYMENT_TARGET} NSHumanReadableCopyright - Copyright ©2007-2015 DeSmuME Team. All rights reserved. + Copyright ©2007-2017 DeSmuME Team. All rights reserved. NSMainNibFile MainMenu NSPrincipalClass diff --git a/desmume/src/frontend/cocoa/Info.plist b/desmume/src/frontend/cocoa/Info.plist index f32f30556..340e898bb 100644 --- a/desmume/src/frontend/cocoa/Info.plist +++ b/desmume/src/frontend/cocoa/Info.plist @@ -250,7 +250,7 @@ LSMinimumSystemVersion ${MACOSX_DEPLOYMENT_TARGET} NSHumanReadableCopyright - Copyright ©2007-2015 DeSmuME Team. All rights reserved. + Copyright ©2007-2017 DeSmuME Team. All rights reserved. NSMainNibFile MainMenu NSPrincipalClass diff --git a/desmume/src/frontend/cocoa/cocoa_GPU.h b/desmume/src/frontend/cocoa/cocoa_GPU.h index 49b51e477..f9f5213fd 100644 --- a/desmume/src/frontend/cocoa/cocoa_GPU.h +++ b/desmume/src/frontend/cocoa/cocoa_GPU.h @@ -28,14 +28,20 @@ #undef BOOL #endif -#if defined(MAC_OS_X_VERSION_10_11) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_11) -#define ENABLE_APPLE_METAL +#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 #endif #define VIDEO_FLUSH_TIME_LIMIT_OFFSET 8 // The amount of time, in seconds, to wait for a flush to occur on a given CVDisplayLink before stopping it. class GPUEventHandlerOSX; +#ifdef ENABLE_SHARED_FETCH_OBJECT + typedef std::map DisplayLinksActiveMap; typedef std::map DisplayLinkFlushTimeLimitMap; @@ -77,6 +83,8 @@ typedef std::map DisplayLinkFlushTimeLimitMap; @end +#endif + @interface CocoaDSGPU : NSObject { UInt32 gpuStateFlags; @@ -87,6 +95,7 @@ typedef std::map DisplayLinkFlushTimeLimitMap; OSSpinLock spinlockGpuState; GPUEventHandlerOSX *gpuEvent; + GPUClientFetchObject *fetchObject; } @@ -95,8 +104,6 @@ typedef std::map DisplayLinkFlushTimeLimitMap; @property (assign) NSUInteger gpuScale; @property (assign) NSUInteger gpuColorFormat; @property (readonly) pthread_rwlock_t *gpuFrameRWLock; -@property (readonly, nonatomic) GPUClientFetchObject *fetchObject; -@property (readonly, nonatomic) MacClientSharedObject *sharedData; @property (assign) BOOL layerMainGPU; @property (assign) BOOL layerMainBG0; @@ -124,7 +131,13 @@ typedef std::map DisplayLinkFlushTimeLimitMap; @property (assign) NSUInteger render3DTextureScalingFactor; @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; +#endif + - (BOOL) gpuStateByBit:(const UInt32)stateBit; - (NSString *) render3DRenderingEngineString; - (void) clearWithColor:(const uint16_t)colorBGRA5551; @@ -137,6 +150,8 @@ extern "C" { #endif +#ifdef ENABLE_SHARED_FETCH_OBJECT + static void* RunFetchThread(void *arg); CVReturn MacDisplayLinkCallback(CVDisplayLinkRef displayLink, @@ -145,6 +160,7 @@ CVReturn MacDisplayLinkCallback(CVDisplayLinkRef displayLink, CVOptionFlags flagsIn, CVOptionFlags *flagsOut, void *displayLinkContext); +#endif bool OSXOpenGLRendererInit(); bool OSXOpenGLRendererBegin(); diff --git a/desmume/src/frontend/cocoa/cocoa_GPU.mm b/desmume/src/frontend/cocoa/cocoa_GPU.mm index 43506643a..559f099b9 100644 --- a/desmume/src/frontend/cocoa/cocoa_GPU.mm +++ b/desmume/src/frontend/cocoa/cocoa_GPU.mm @@ -95,8 +95,6 @@ public: @dynamic gpuScale; @dynamic gpuColorFormat; @dynamic gpuFrameRWLock; -@synthesize fetchObject; -@dynamic sharedData; @dynamic layerMainGPU; @dynamic layerMainBG0; @@ -124,6 +122,10 @@ public: @dynamic render3DTextureScalingFactor; @dynamic render3DFragmentSamplingHack; +#ifdef ENABLE_SHARED_FETCH_OBJECT +@synthesize fetchObject; +@dynamic sharedData; +#endif - (id)init { @@ -186,6 +188,7 @@ public: } #endif +#ifdef ENABLE_SHARED_FETCH_OBJECT if (fetchObject == NULL) { fetchObject = new MacOGLClientFetchObject; @@ -193,6 +196,7 @@ public: fetchObject->Init(); gpuEvent->SetFetchObject(fetchObject); +#endif [self clearWithColor:0x8000]; @@ -253,14 +257,20 @@ public: { gpuEvent->Render3DLock(); gpuEvent->FramebufferLockWrite(); + +#ifdef ENABLE_SHARED_FETCH_OBJECT pthread_rwlock_wrlock([[self sharedData] rwlockFramebufferAtIndex:0]); pthread_rwlock_wrlock([[self sharedData] rwlockFramebufferAtIndex:1]); +#endif 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:0]); +#endif + gpuEvent->FramebufferUnlock(); gpuEvent->Render3DUnlock(); } @@ -304,14 +314,20 @@ public: // Change the color format. gpuEvent->Render3DLock(); gpuEvent->FramebufferLockWrite(); + +#ifdef ENABLE_SHARED_FETCH_OBJECT pthread_rwlock_wrlock([[self sharedData] rwlockFramebufferAtIndex:0]); pthread_rwlock_wrlock([[self sharedData] rwlockFramebufferAtIndex:1]); +#endif 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:0]); +#endif + gpuEvent->FramebufferUnlock(); gpuEvent->Render3DUnlock(); } @@ -332,10 +348,12 @@ public: return gpuEvent->GetFrameRWLock(); } +#ifdef ENABLE_SHARED_FETCH_OBJECT - (void) setOutputList:(NSMutableArray *)theOutputList mutexPtr:(pthread_mutex_t *)theMutex { [(MacClientSharedObject *)fetchObject->GetClientData() setOutputList:theOutputList mutex:theMutex]; } +#endif - (void) setRender3DRenderingEngine:(NSInteger)rendererID { @@ -851,15 +869,20 @@ public: - (void) clearWithColor:(const uint16_t)colorBGRA5551 { gpuEvent->FramebufferLockWrite(); + +#ifdef ENABLE_SHARED_FETCH_OBJECT const u8 bufferIndex = GPU->GetDisplayInfo().bufferIndex; pthread_rwlock_wrlock([[self sharedData] rwlockFramebufferAtIndex:bufferIndex]); +#endif GPU->ClearWithColor(colorBGRA5551); +#ifdef ENABLE_SHARED_FETCH_OBJECT pthread_rwlock_unlock([[self sharedData] rwlockFramebufferAtIndex:bufferIndex]); +#endif gpuEvent->FramebufferUnlock(); -#if !defined(PORT_VERSION_OPENEMU) +#ifdef ENABLE_SHARED_FETCH_OBJECT [[self sharedData] signalFetchAtIndex:bufferIndex]; #endif } @@ -886,6 +909,8 @@ public: @end +#ifdef ENABLE_SHARED_FETCH_OBJECT + @implementation MacClientSharedObject @synthesize GPUFetchObject; @@ -1206,6 +1231,8 @@ public: @end +#endif + #pragma mark - GPUEventHandlerOSX::GPUEventHandlerOSX() @@ -1245,7 +1272,7 @@ void GPUEventHandlerOSX::DidFrameBegin(bool isFrameSkipRequested, const u8 targe { this->FramebufferLockWrite(); -#if !defined(PORT_VERSION_OPENEMU) +#ifdef ENABLE_SHARED_FETCH_OBJECT if (!isFrameSkipRequested) { 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) { -#if !defined(PORT_VERSION_OPENEMU) +#ifdef ENABLE_SHARED_FETCH_OBJECT MacClientSharedObject *sharedViewObject = (MacClientSharedObject *)this->_fetchObject->GetClientData(); if (!isFrameSkipped) { @@ -1267,7 +1294,7 @@ void GPUEventHandlerOSX::DidFrameEnd(bool isFrameSkipped, const NDSDisplayInfo & this->FramebufferUnlock(); -#if !defined(PORT_VERSION_OPENEMU) +#ifdef ENABLE_SHARED_FETCH_OBJECT if (!isFrameSkipped) { [sharedViewObject signalFetchAtIndex:latestDisplayInfo.bufferIndex]; @@ -1371,6 +1398,8 @@ CGLContextObj OSXOpenGLRendererContext = NULL; CGLPBufferObj OSXOpenGLRendererPBuffer = NULL; #pragma GCC diagnostic pop +#ifdef ENABLE_SHARED_FETCH_OBJECT + static void* RunFetchThread(void *arg) { MacClientSharedObject *sharedData = (MacClientSharedObject *)arg; @@ -1392,6 +1421,8 @@ CVReturn MacDisplayLinkCallback(CVDisplayLinkRef displayLink, return kCVReturnSuccess; } +#endif + bool OSXOpenGLRendererInit() { static bool isContextAlreadyCreated = false; diff --git a/desmume/src/frontend/cocoa/openemu/Info (OpenEmu Plug-in).plist b/desmume/src/frontend/cocoa/openemu/Info (OpenEmu Plug-in).plist index 48dc3dca6..84cfb7b6e 100644 --- a/desmume/src/frontend/cocoa/openemu/Info (OpenEmu Plug-in).plist +++ b/desmume/src/frontend/cocoa/openemu/Info (OpenEmu Plug-in).plist @@ -18,18 +18,20 @@ v0.9.12 (OpenEmu Plug-in) CFBundleSignature ???? + CFBundleSupportedPlatforms + + MacOSX + CFBundleVersion 0.9.12 CSResourcesFileMapped yes NSHumanReadableCopyright - Copyright © 2012-2015 DeSmuME Team. All rights reserved. + Copyright © 2012-2017 DeSmuME Team. All rights reserved. NSPrincipalClass OEGameCoreController OEGameCoreClass NDSGameCore - OEGameCorePlayerCount - 1 OEGameCoreOptions openemu.system.nds @@ -38,15 +40,17 @@ + OEGameCorePlayerCount + 1 OEProjectURL http://desmume.org/ OESystemIdentifiers openemu.system.nds - SUFeedURL - https://raw.github.com/OpenEmu/OpenEmu-Update/master/desmume_appcast.xml SUEnableAutomaticChecks 1 + SUFeedURL + https://raw.github.com/OpenEmu/OpenEmu-Update/master/desmume_appcast.xml diff --git a/desmume/src/frontend/cocoa/openemu/NDSGameCore.h b/desmume/src/frontend/cocoa/openemu/NDSGameCore.h index f4d33a681..cafc75a18 100644 --- a/desmume/src/frontend/cocoa/openemu/NDSGameCore.h +++ b/desmume/src/frontend/cocoa/openemu/NDSGameCore.h @@ -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 it under the terms of the GNU General Public License as published by @@ -39,7 +39,7 @@ NSInteger displayMode; OEIntRect displayRect; 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; pthread_rwlock_t rwlockCoreExecute; diff --git a/desmume/src/frontend/cocoa/openemu/NDSGameCore.mm b/desmume/src/frontend/cocoa/openemu/NDSGameCore.mm index d810b6098..26cff12cc 100644 --- a/desmume/src/frontend/cocoa/openemu/NDSGameCore.mm +++ b/desmume/src/frontend/cocoa/openemu/NDSGameCore.mm @@ -22,6 +22,8 @@ #import "cocoa_firmware.h" #import "cocoa_GPU.h" #import "cocoa_input.h" +#import "ClientDisplayView.h" +#import "ClientInputHandler.h" #import "OESoundInterface.h" #import "OENDSSystemResponderClient.h" @@ -57,21 +59,21 @@ volatile bool execute = true; touchLocation.x = 0; touchLocation.y = 0; - inputID[OENDSButtonUp] = DSControllerState_Up; - inputID[OENDSButtonDown] = DSControllerState_Down; - inputID[OENDSButtonLeft] = DSControllerState_Left; - inputID[OENDSButtonRight] = DSControllerState_Right; - inputID[OENDSButtonA] = DSControllerState_A; - inputID[OENDSButtonB] = DSControllerState_B; - inputID[OENDSButtonX] = DSControllerState_X; - inputID[OENDSButtonY] = DSControllerState_Y; - inputID[OENDSButtonL] = DSControllerState_L; - inputID[OENDSButtonR] = DSControllerState_R; - inputID[OENDSButtonStart] = DSControllerState_Start; - inputID[OENDSButtonSelect] = DSControllerState_Select; - inputID[OENDSButtonMicrophone] = DSControllerState_Microphone; - inputID[OENDSButtonLid] = DSControllerState_Lid; - inputID[OENDSButtonDebug] = DSControllerState_Debug; + inputID[OENDSButtonUp] = NDSInputID_Up; + inputID[OENDSButtonDown] = NDSInputID_Down; + inputID[OENDSButtonLeft] = NDSInputID_Left; + inputID[OENDSButtonRight] = NDSInputID_Right; + inputID[OENDSButtonA] = NDSInputID_A; + inputID[OENDSButtonB] = NDSInputID_B; + inputID[OENDSButtonX] = NDSInputID_X; + inputID[OENDSButtonY] = NDSInputID_Y; + inputID[OENDSButtonL] = NDSInputID_L; + inputID[OENDSButtonR] = NDSInputID_R; + inputID[OENDSButtonStart] = NDSInputID_Start; + inputID[OENDSButtonSelect] = NDSInputID_Select; + inputID[OENDSButtonMicrophone] = NDSInputID_Microphone; + inputID[OENDSButtonLid] = NDSInputID_Lid; + inputID[OENDSButtonDebug] = NDSInputID_Debug; // Set up the emulation core CommonSettings.advanced_timing = true; @@ -86,7 +88,7 @@ volatile bool execute = true; // Set up the DS controller cdsController = [[[[CocoaDSController alloc] init] retain] autorelease]; - [cdsController setMicMode:MicrophoneMode_InternalNoise]; + [cdsController startHardwareMicDevice]; // Set up the cheat system cdsCheats = [[[[CocoaDSCheatManager alloc] init] retain] autorelease]; @@ -105,7 +107,7 @@ volatile bool execute = true; openEmuSoundInterfaceBuffer = [self ringBufferAtIndex:0]; NSInteger result = SPU_ChangeSoundCore(SNDCORE_OPENEMU, (int)SPU_BUFFER_BYTES); - if(result == -1) + if (result == -1) { SPU_ChangeSoundCore(SNDCORE_DUMMY, 0); } @@ -140,7 +142,7 @@ volatile bool execute = true; - (NSInteger) displayMode { OSSpinLockLock(&spinlockDisplayMode); - NSInteger theMode = displayMode; + const NSInteger theMode = displayMode; OSSpinLockUnlock(&spinlockDisplayMode); return theMode; @@ -187,46 +189,7 @@ volatile bool execute = true; return NO; } -#pragma mark - Execution - -- (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(); - pthread_rwlock_unlock(&rwlockCoreExecute); - - SPU_Emulate_user(); -} +#pragma mark - Starting - (BOOL)loadFileAtPath:(NSString*)path { @@ -258,12 +221,75 @@ volatile bool execute = true; 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(); + 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 +- (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 { OSSpinLockLock(&spinlockDisplayMode); - OEIntRect theRect = displayRect; + const OEIntRect theRect = displayRect; OSSpinLockUnlock(&spinlockDisplayMode); return theRect; @@ -272,64 +298,27 @@ volatile bool execute = true; - (OEIntSize)aspectSize { OSSpinLockLock(&spinlockDisplayMode); - OEIntSize theAspectRatio = displayAspectRatio; + const OEIntSize theAspectRatio = displayAspectRatio; OSSpinLockUnlock(&spinlockDisplayMode); 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 { return GL_UNSIGNED_SHORT_1_5_5_5_REV; } +- (GLenum)pixelFormat +{ + return GL_RGBA; +} + - (GLenum)internalPixelFormat { 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 - (NSUInteger)audioBufferCount @@ -342,16 +331,16 @@ volatile bool execute = true; return SPU_NUMBER_CHANNELS; } +- (NSUInteger)audioBitDepth +{ + return SPU_SAMPLE_RESOLUTION; +} + - (double)audioSampleRate { return SPU_SAMPLE_RATE; } -- (NSUInteger)audioBitDepth -{ - return SPU_SAMPLE_RESOLUTION; -} - - (NSUInteger)channelCountForBuffer:(NSUInteger)buffer { return [self channelCount]; @@ -367,6 +356,74 @@ volatile bool execute = true; 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 - (oneway void)didPushNDSButton:(OENDSButton)button forPlayer:(NSUInteger)player @@ -432,65 +489,25 @@ volatile bool execute = true; [cdsController setTouchState:NO location:touchLocation]; } -- (NSTrackingAreaOptions)mouseTrackingOptions +- (void)changeDisplayMode { - return 0; -} - -- (void)settingWasSet:(id)aValue forKey:(NSString *)keyName -{ - DLog(@"keyName = %@", keyName); - //[self doesNotImplementSelector:_cmd]; -} - -#pragma mark - Save State - -- (BOOL)saveStateToFileAtPath:(NSString *)fileName -{ - return [CocoaDSFile saveState:[NSURL fileURLWithPath:fileName]]; -} - -- (BOOL)loadStateFromFileAtPath:(NSString *)fileName -{ - return [CocoaDSFile loadState:[NSURL fileURLWithPath:fileName]]; -} - -#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) + switch (displayMode) { - // 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]; + 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; } } diff --git a/desmume/src/frontend/cocoa/openemu/OESoundInterface.mm b/desmume/src/frontend/cocoa/openemu/OESoundInterface.mm index 86d6bd623..ab72af569 100644 --- a/desmume/src/frontend/cocoa/openemu/OESoundInterface.mm +++ b/desmume/src/frontend/cocoa/openemu/OESoundInterface.mm @@ -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 it under the terms of the GNU General Public License as published by @@ -82,7 +82,20 @@ void SNDOpenEmuUpdateAudio(s16 *buffer, u32 num_samples) } 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; }