From 64ea7591ab9dce8fef92830400144f0852121039 Mon Sep 17 00:00:00 2001 From: rogerman Date: Wed, 25 Feb 2015 05:50:15 +0000 Subject: [PATCH] Cocoa OpenEmu Plug-in: - Update to SDK v1.0.4. - Change the SPU sync method to N-method. - Fix bug where the enable state of cheats could not be toggled. --- .../openemu/Info (OpenEmu Plug-in).plist | 14 +++-- desmume/src/cocoa/openemu/NDSGameCore.h | 3 +- desmume/src/cocoa/openemu/NDSGameCore.mm | 53 ++++++++++++++----- desmume/src/cocoa/openemu/OESoundInterface.mm | 4 +- 4 files changed, 55 insertions(+), 19 deletions(-) diff --git a/desmume/src/cocoa/openemu/Info (OpenEmu Plug-in).plist b/desmume/src/cocoa/openemu/Info (OpenEmu Plug-in).plist index 8c7a6cbca..395b815d5 100644 --- a/desmume/src/cocoa/openemu/Info (OpenEmu Plug-in).plist +++ b/desmume/src/cocoa/openemu/Info (OpenEmu Plug-in).plist @@ -23,15 +23,21 @@ CSResourcesFileMapped yes NSHumanReadableCopyright - Copyright © 2012-2013 DeSmuME Team. All rights reserved. + Copyright © 2012-2015 DeSmuME Team. All rights reserved. NSPrincipalClass OEGameCoreController OEGameCoreClass NDSGameCore OEGameCorePlayerCount 1 - OEGameCoreSupportsCheatCode - + OEGameCoreOptions + + openemu.system.nds + + OEGameCoreSupportsCheatCode + + + OEProjectURL http://desmume.org/ OESystemIdentifiers @@ -39,7 +45,7 @@ openemu.system.nds SUFeedURL - http://openemu.org/updater/desmume_appcast.xml + https://raw.github.com/OpenEmu/OpenEmu-Update/master/desmume_appcast.xml SUEnableAutomaticChecks 1 diff --git a/desmume/src/cocoa/openemu/NDSGameCore.h b/desmume/src/cocoa/openemu/NDSGameCore.h index d4687fad1..3a787d804 100644 --- a/desmume/src/cocoa/openemu/NDSGameCore.h +++ b/desmume/src/cocoa/openemu/NDSGameCore.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2014 DeSmuME team + Copyright (C) 2012-2015 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 @@ -30,6 +30,7 @@ @interface NDSGameCore : OEGameCore { NSPoint touchLocation; + NSMutableDictionary *addedCheatsDict; CocoaDSCheatManager *cdsCheats; CocoaDSController *cdsController; CocoaDSGPU *cdsGPU; diff --git a/desmume/src/cocoa/openemu/NDSGameCore.mm b/desmume/src/cocoa/openemu/NDSGameCore.mm index 7b218a0f4..085308303 100644 --- a/desmume/src/cocoa/openemu/NDSGameCore.mm +++ b/desmume/src/cocoa/openemu/NDSGameCore.mm @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2014 DeSmuME team + Copyright (C) 2012-2015 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 @@ -92,6 +92,7 @@ volatile bool execute = true; // Set up the cheat system cdsCheats = [[[[CocoaDSCheatManager alloc] init] retain] autorelease]; [cdsCheats setRwlockCoreExecute:&rwlockCoreExecute]; + addedCheatsDict = [[NSMutableDictionary alloc] initWithCapacity:128]; // Set up the DS firmware using the internal firmware cdsFirmware = [[[[CocoaDSFirmware alloc] init] retain] autorelease]; @@ -101,7 +102,7 @@ volatile bool execute = true; CommonSettings.spu_advanced = true; CommonSettings.spuInterpolationMode = SPUInterpolation_Cosine; CommonSettings.SPU_sync_mode = SPU_SYNC_MODE_SYNCHRONOUS; - CommonSettings.SPU_sync_method = SPU_SYNC_METHOD_P; + CommonSettings.SPU_sync_method = SPU_SYNC_METHOD_N; openEmuSoundInterfaceBuffer = [self ringBufferAtIndex:0]; NSInteger result = SPU_ChangeSoundCore(SNDCORE_OPENEMU, (int)SPU_BUFFER_BYTES); @@ -126,6 +127,7 @@ volatile bool execute = true; SPU_ChangeSoundCore(SNDCORE_DUMMY, 0); NDS_DeInit(); + [addedCheatsDict release]; [self setCdsCheats:nil]; [self setCdsController:nil]; [self setCdsGPU:nil]; @@ -247,6 +249,11 @@ volatile bool execute = true; #pragma mark Video +- (BOOL)rendersToOpenGL +{ + return NO; +} + - (OEIntRect)screenRect { OSSpinLockLock(&spinlockDisplayMode); @@ -446,17 +453,39 @@ volatile bool execute = true; - (void)setCheat:(NSString *)code setType:(NSString *)type setEnabled:(BOOL)enabled { - CocoaDSCheatItem *newCheatItem = [[[CocoaDSCheatItem alloc] init] autorelease]; - [newCheatItem setEnabled:enabled]; - [newCheatItem setCheatType:CHEAT_TYPE_ACTION_REPLAY]; // Default to Action Replay for now - [newCheatItem setFreezeType:0]; - [newCheatItem setDescription:@""]; // OpenEmu takes care of this - [newCheatItem setCode:code]; - [newCheatItem setMemAddress:0x00000000]; // UNUSED - [newCheatItem setBytes:1]; // UNUSED - [newCheatItem setValue:0]; // UNUSED + // 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. - [[self cdsCheats] add:newCheatItem]; + // 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]; + } } @end diff --git a/desmume/src/cocoa/openemu/OESoundInterface.mm b/desmume/src/cocoa/openemu/OESoundInterface.mm index 2a744fe86..86d6bd623 100644 --- a/desmume/src/cocoa/openemu/OESoundInterface.mm +++ b/desmume/src/cocoa/openemu/OESoundInterface.mm @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2014 DeSmuME team + Copyright (C) 2012-2015 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 @@ -49,7 +49,7 @@ SoundInterface_struct *SNDCoreList[] = { int SNDOpenEmuInit(int buffer_size) { - [openEmuSoundInterfaceBuffer setLength:buffer_size]; + [openEmuSoundInterfaceBuffer setLength:buffer_size * 4 / SPU_SAMPLE_SIZE]; if (mutexAudioSampleReadWrite == NULL) {