From edc32fc0bd6aea6d5645a03f0f94b72f3cbfa43e Mon Sep 17 00:00:00 2001 From: Michael Buckley Date: Mon, 15 Nov 2021 10:57:25 -0800 Subject: [PATCH] Mac: Implement emulation hack preferences. --- macosx/Snes9x/AppDelegate.h | 2 + macosx/Snes9x/AppDelegate.m | 31 ++- .../S9xEmulationPreferencesViewController.m | 39 ++++ .../S9xEmulationPreferencesViewController.xib | 202 ++++++++++++++++-- .../S9xPreferences/S9xPreferencesConstants.h | 9 + .../S9xPreferences/S9xPreferencesConstants.m | 9 + macosx/mac-os.h | 9 + macosx/mac-os.mm | 42 ++++ macosx/snes9x.xcodeproj/project.pbxproj | 6 +- 9 files changed, 328 insertions(+), 21 deletions(-) diff --git a/macosx/Snes9x/AppDelegate.h b/macosx/Snes9x/AppDelegate.h index 11c52e4d..d8cc147a 100644 --- a/macosx/Snes9x/AppDelegate.h +++ b/macosx/Snes9x/AppDelegate.h @@ -52,5 +52,7 @@ extern NSWindowFrameAutosaveName const kMainWindowIdentifier; - (void)setMacFrameSkip:(int)_macFrameSkip; - (void)setShowFPS:(BOOL)showFPS; +- (void)applyEmulationSettings; + @end diff --git a/macosx/Snes9x/AppDelegate.m b/macosx/Snes9x/AppDelegate.m index 44c9d427..8e3de21e 100644 --- a/macosx/Snes9x/AppDelegate.m +++ b/macosx/Snes9x/AppDelegate.m @@ -108,9 +108,18 @@ NSWindowFrameAutosaveName const kMainWindowIdentifier = @"s9xMainWindow"; @(kKeyEsc).stringValue : @(kVK_Escape), @(kKeyTC).stringValue : @(kVK_ANSI_Comma) }, - kShowFPSPref: @(NO), - kVideoModePref:@(VIDEOMODE_BLOCKY), - kMacFrameSkipPref:@(macFrameSkip) + kShowFPSPref : @(NO), + kVideoModePref : @(VIDEOMODE_BLOCKY), + kMacFrameSkipPref : @(macFrameSkip), + + kSuperFXClockSpeedPercentPref : @(100), + kSoundInterpolationTypePref: @(2), + kCPUOverclockPref : @(0), + + kApplyGameSpecificHacksPref : (@YES), + kAllowInvalidVRAMAccessPref : @(NO), + kSeparateEchoBufferFromRAMPref : @(NO), + kDisableSpriteLimitPref : @(NO), }; [defaults registerDefaults:defaultSettings]; @@ -184,6 +193,7 @@ NSWindowFrameAutosaveName const kMainWindowIdentifier = @"s9xMainWindow"; [self importKeySettings]; [self importGraphicsSettings]; + [self applyEmulationSettings]; [defaults synchronize]; } @@ -520,6 +530,21 @@ NSWindowFrameAutosaveName const kMainWindowIdentifier = @"s9xMainWindow"; [NSUserDefaults.standardUserDefaults synchronize]; } +- (void)applyEmulationSettings +{ + S9xEngine *engine = self.s9xEngine; + NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults; + + [engine setSuperFXClockSpeedPercent:(uint32_t)[defaults integerForKey:kSuperFXClockSpeedPercentPref]]; + [engine setSoundInterpolationType:(int)[defaults integerForKey:kSoundInterpolationTypePref]]; + [engine setCPUOverclockMode:(int)[defaults integerForKey:kCPUOverclockPref]]; + + [engine setApplySpecificGameHacks:[defaults boolForKey:kApplyGameSpecificHacksPref]]; + [engine setAllowInvalidVRAMAccess:[defaults boolForKey:kAllowInvalidVRAMAccessPref]]; + [engine setSeparateEchoBufferFromRAM:[defaults boolForKey:kSeparateEchoBufferFromRAMPref]]; + [engine setDisableSpriteLimit:[defaults boolForKey:kDisableSpriteLimitPref]]; +} + - (IBAction)resume:(id)sender { [self.s9xEngine resume]; diff --git a/macosx/Snes9x/S9xPreferences/S9xEmulationPreferencesViewController.m b/macosx/Snes9x/S9xPreferences/S9xEmulationPreferencesViewController.m index c77530f7..61835f96 100644 --- a/macosx/Snes9x/S9xPreferences/S9xEmulationPreferencesViewController.m +++ b/macosx/Snes9x/S9xPreferences/S9xEmulationPreferencesViewController.m @@ -20,6 +20,9 @@ #import "S9xEmulationPreferencesViewController.h" +#import "AppDelegate.h" +#import "S9xPreferencesConstants.h" + @interface S9xEmulationPreferencesViewController () @end @@ -37,4 +40,40 @@ return self; } +- (void)viewWillAppear +{ + [super viewWillAppear]; + + [NSNotificationCenter.defaultCenter addObserverForName:NSUserDefaultsDidChangeNotification + object:NSUserDefaults.standardUserDefaults + queue:NSOperationQueue.mainQueue + usingBlock:^(NSNotification *notification) + { + [((AppDelegate *)NSApp.delegate) applyEmulationSettings]; + }]; +} + +- (void)viewDidDisappear +{ + [super viewDidDisappear]; + + [NSNotificationCenter.defaultCenter removeObserver:self]; +} + +- (IBAction)resetDefaults:(id)sender +{ + NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults; + + [defaults setInteger:100 forKey:kSuperFXClockSpeedPercentPref]; + [defaults setInteger:2 forKey:kSoundInterpolationTypePref]; + [defaults setInteger:0 forKey:kCPUOverclockPref]; + + [defaults setBool:YES forKey:kApplyGameSpecificHacksPref]; + [defaults setBool:NO forKey:kAllowInvalidVRAMAccessPref]; + [defaults setBool:NO forKey:kSeparateEchoBufferFromRAMPref]; + [defaults setBool:NO forKey:kDisableSpriteLimitPref]; + + [defaults synchronize]; +} + @end diff --git a/macosx/Snes9x/S9xPreferences/S9xEmulationPreferencesViewController.xib b/macosx/Snes9x/S9xPreferences/S9xEmulationPreferencesViewController.xib index 46522f9b..8c75f41c 100644 --- a/macosx/Snes9x/S9xPreferences/S9xEmulationPreferencesViewController.xib +++ b/macosx/Snes9x/S9xPreferences/S9xEmulationPreferencesViewController.xib @@ -1,8 +1,8 @@ - + - + @@ -13,29 +13,201 @@ - - + + - - + + + - + - - - + + + The settings in this tab should only be used for compatibility with old ROM hacks or if you otherwise know what you're doing. + +If any problems occur, click "Set Defaults" to reset the options to normal. + +Some changes may not take effect until you close and re-open the ROM. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + diff --git a/macosx/Snes9x/S9xPreferences/S9xPreferencesConstants.h b/macosx/Snes9x/S9xPreferences/S9xPreferencesConstants.h index 5ff272c5..1ede6fb5 100644 --- a/macosx/Snes9x/S9xPreferences/S9xPreferencesConstants.h +++ b/macosx/Snes9x/S9xPreferences/S9xPreferencesConstants.h @@ -29,4 +29,13 @@ extern NSString * const kShowFPSPref; extern NSString * const kVideoModePref; extern NSString * const kMacFrameSkipPref; +extern NSString * const kSuperFXClockSpeedPercentPref; +extern NSString * const kSoundInterpolationTypePref; +extern NSString * const kCPUOverclockPref; + +extern NSString * const kApplyGameSpecificHacksPref; +extern NSString * const kAllowInvalidVRAMAccessPref; +extern NSString * const kSeparateEchoBufferFromRAMPref; +extern NSString * const kDisableSpriteLimitPref; + NS_ASSUME_NONNULL_END diff --git a/macosx/Snes9x/S9xPreferences/S9xPreferencesConstants.m b/macosx/Snes9x/S9xPreferences/S9xPreferencesConstants.m index 6f304e41..343c93fe 100644 --- a/macosx/Snes9x/S9xPreferences/S9xPreferencesConstants.m +++ b/macosx/Snes9x/S9xPreferences/S9xPreferencesConstants.m @@ -26,3 +26,12 @@ NSString * const kJoypadPlayerPrefs = @"JoypadPlayers"; NSString * const kShowFPSPref = @"ShowFPS"; NSString * const kVideoModePref = @"VideoMode"; NSString * const kMacFrameSkipPref = @"FrameSkip"; + +NSString * const kSuperFXClockSpeedPercentPref = @"SuperFXClockSpeedPercent"; +NSString * const kSoundInterpolationTypePref = @"SoundInterpolationType"; +NSString * const kCPUOverclockPref = @"CPUOverclock"; + +NSString * const kApplyGameSpecificHacksPref = @"ApplyGameSpecificHacks"; +NSString * const kAllowInvalidVRAMAccessPref = @"AllowInvalidVRAMAccess"; +NSString * const kSeparateEchoBufferFromRAMPref = @"SeparateEchoBufferFromRAM"; +NSString * const kDisableSpriteLimitPref = @"DisableSpriteLimit"; diff --git a/macosx/mac-os.h b/macosx/mac-os.h index 8c84ba81..18cd2c74 100644 --- a/macosx/mac-os.h +++ b/macosx/mac-os.h @@ -210,6 +210,15 @@ extern id inputDelegate; - (void)setDeviceSetting:(S9xDeviceSetting)_deviceSetting; +- (void)setSuperFXClockSpeedPercent:(uint32_t)clockSpeed; +- (void)setSoundInterpolationType:(int)type; +- (void)setCPUOverclockMode:(int)mode; + +- (void)setApplySpecificGameHacks:(BOOL)flag; +- (void)setAllowInvalidVRAMAccess:(BOOL)flag; +- (void)setSeparateEchoBufferFromRAM:(BOOL)flag; +- (void)setDisableSpriteLimit:(BOOL)flag; + @end #endif diff --git a/macosx/mac-os.mm b/macosx/mac-os.mm index ca5744dc..938a4b88 100644 --- a/macosx/mac-os.mm +++ b/macosx/mac-os.mm @@ -3358,6 +3358,48 @@ void QuitWithFatalError ( NSString *message) ChangeInputDevice(); } +- (void)setSuperFXClockSpeedPercent:(uint32_t)clockSpeed +{ + Settings.SuperFXClockMultiplier = clockSpeed; +} + +- (void)setSoundInterpolationType:(int)type +{ + Settings.InterpolationMethod = type; +} + +- (void)setCPUOverclockMode:(int)mode +{ + Settings.OverclockMode = mode; +} + +- (void)setApplySpecificGameHacks:(BOOL)flag +{ + Settings.DisableGameSpecificHacks = !flag; +} + +- (void)setAllowInvalidVRAMAccess:(BOOL)flag +{ + Settings.BlockInvalidVRAMAccessMaster = !flag; +} + +- (void)setSeparateEchoBufferFromRAM:(BOOL)flag +{ + Settings.SeparateEchoBuffer = false; +} + +- (void)setDisableSpriteLimit:(BOOL)flag +{ + if ( flag ) + { + Settings.MaxSpriteTilesPerLine = 128; + } + else + { + Settings.MaxSpriteTilesPerLine = 34; + } +} + @dynamic inputDelegate; - (void)setInputDelegate:(id)delegate { diff --git a/macosx/snes9x.xcodeproj/project.pbxproj b/macosx/snes9x.xcodeproj/project.pbxproj index 63077a6d..bb472595 100755 --- a/macosx/snes9x.xcodeproj/project.pbxproj +++ b/macosx/snes9x.xcodeproj/project.pbxproj @@ -1449,12 +1449,12 @@ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CODE_SIGN_ENTITLEMENTS = Snes9x/Snes9x.entitlements; - CODE_SIGN_IDENTITY = "-"; - CODE_SIGN_STYLE = Automatic; + CODE_SIGN_IDENTITY = "Developer ID Application"; + CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = S4YHUE5Y65; ENABLE_HARDENED_RUNTIME = YES; ENABLE_NS_ASSERTIONS = NO; GCC_C_LANGUAGE_STANDARD = gnu11;