From a8921f4188c295ca026ce44264e6fab3df83957f Mon Sep 17 00:00:00 2001 From: jorsi Date: Sat, 12 Sep 2020 22:02:42 -0400 Subject: [PATCH 1/5] add frame skip to preferences --- macosx/Snes9x/AppDelegate.h | 1 + macosx/Snes9x/AppDelegate.m | 10 +++- macosx/Snes9x/S9xPrefsConstants.h | 1 + macosx/Snes9x/S9xPrefsConstants.m | 1 + macosx/Snes9x/S9xPrefsViewController.m | 28 ++++++++- macosx/Snes9x/S9xPrefsViewController.xib | 74 ++++++++++++++++++------ macosx/mac-os.h | 1 + macosx/mac-os.mm | 11 ++++ macosx/mac-render.mm | 6 +- 9 files changed, 113 insertions(+), 20 deletions(-) diff --git a/macosx/Snes9x/AppDelegate.h b/macosx/Snes9x/AppDelegate.h index ec6ff939..6b6ef36f 100644 --- a/macosx/Snes9x/AppDelegate.h +++ b/macosx/Snes9x/AppDelegate.h @@ -41,6 +41,7 @@ - (BOOL)getValuesFromString:(NSString *)str cookie:(uint32 *)cookie value:(int32 *)value; - (void)setVideoMode:(int)videoMode; +- (void)setMacFrameSkip:(int)_macFrameSkip; - (void)setShowFPS:(BOOL)showFPS; @end diff --git a/macosx/Snes9x/AppDelegate.m b/macosx/Snes9x/AppDelegate.m index e54060f7..7cf43904 100644 --- a/macosx/Snes9x/AppDelegate.m +++ b/macosx/Snes9x/AppDelegate.m @@ -119,7 +119,8 @@ static NSWindowFrameAutosaveName const kMainWindowIdentifier = @"s9xMainWindow"; @(kKeyTC).stringValue : @(kVK_ANSI_Comma) }, kShowFPSPref: @(NO), - kVideoModePref:@(VIDEOMODE_BLOCKY) + kVideoModePref:@(VIDEOMODE_BLOCKY), + kMacFrameSkipPref:@(macFrameSkip) }; [defaults registerDefaults:defaultSettings]; @@ -513,6 +514,13 @@ static NSWindowFrameAutosaveName const kMainWindowIdentifier = @"s9xMainWindow"; [NSUserDefaults.standardUserDefaults synchronize]; } +- (void)setMacFrameSkip:(int)_macFrameSkip +{ + [self.s9xEngine setMacFrameSkip:_macFrameSkip]; + [NSUserDefaults.standardUserDefaults setObject:@(_macFrameSkip) forKey:kMacFrameSkipPref]; + [NSUserDefaults.standardUserDefaults synchronize]; +} + - (void)setShowFPS:(BOOL)showFPS { [self.s9xEngine setShowFPS:showFPS]; diff --git a/macosx/Snes9x/S9xPrefsConstants.h b/macosx/Snes9x/S9xPrefsConstants.h index ad6351d0..adb1bd6e 100644 --- a/macosx/Snes9x/S9xPrefsConstants.h +++ b/macosx/Snes9x/S9xPrefsConstants.h @@ -25,3 +25,4 @@ extern NSString * const kJoypadInputPrefs; extern NSString * const kJoypadPlayerPrefs; extern NSString * const kShowFPSPref; extern NSString * const kVideoModePref; +extern NSString * const kMacFrameSkipPref; diff --git a/macosx/Snes9x/S9xPrefsConstants.m b/macosx/Snes9x/S9xPrefsConstants.m index c4228317..5d6beaab 100644 --- a/macosx/Snes9x/S9xPrefsConstants.m +++ b/macosx/Snes9x/S9xPrefsConstants.m @@ -25,3 +25,4 @@ NSString * const kJoypadInputPrefs = @"JoypadInputs"; NSString * const kJoypadPlayerPrefs = @"JoypadPlayers"; NSString * const kShowFPSPref = @"ShowFPS"; NSString * const kVideoModePref = @"VideoMode"; +NSString * const kMacFrameSkipPref = @"MacFrameSkip"; diff --git a/macosx/Snes9x/S9xPrefsViewController.m b/macosx/Snes9x/S9xPrefsViewController.m index 3f6bb424..7d642004 100644 --- a/macosx/Snes9x/S9xPrefsViewController.m +++ b/macosx/Snes9x/S9xPrefsViewController.m @@ -30,6 +30,7 @@ @property (nonatomic, weak) IBOutlet NSButton *showFPSCheckbox; @property (nonatomic, weak) IBOutlet NSPopUpButton *devicePopUp; @property (nonatomic, weak) IBOutlet NSPopUpButton *playerPopUp; +@property (nonatomic, weak) IBOutlet NSTextField *macFrameSkipTextField; @end @implementation S9xPrefsViewController @@ -103,6 +104,11 @@ { NSUInteger index = MIN([NSUserDefaults.standardUserDefaults integerForKey:kVideoModePref], 1); [self.videoModePopup selectItemAtIndex:index]; + + // set maxFrameSkipTextField to user default + NSInteger macFrameSkipDefault = [NSUserDefaults.standardUserDefaults integerForKey:kMacFrameSkipPref]; + [self.macFrameSkipTextField setIntegerValue:macFrameSkipDefault]; + self.showFPSCheckbox.state = [NSUserDefaults.standardUserDefaults boolForKey:kShowFPSPref]; if (self.devicePopUp.selectedItem.tag < 0) @@ -271,6 +277,13 @@ [appDelegate setVideoMode:(int)sender.selectedTag]; } +- (IBAction)setMacFrameSkip:(NSTextField *)sender +{ + AppDelegate *appDelegate = (AppDelegate *)NSApp.delegate; + [appDelegate setMacFrameSkip:(int)sender.integerValue]; + NSLog(@"setMacFrameSkip %ld", sender.integerValue); +} + - (BOOL)handleInput:(S9xJoypadInput *)input fromJoypad:(S9xJoypad *)joypad { id firstResponder = self.view.window.firstResponder; @@ -293,5 +306,18 @@ return NO; } - +- (IBAction) bumpMacFrameSkip:(id)sender +{ + int bumpValue = [sender intValue]; // 1 or -1 + [self.macFrameSkipTextField setIntegerValue:[self.macFrameSkipTextField integerValue] + bumpValue]; + + // constrain value + if ([self.macFrameSkipTextField integerValue] < -1) + [self.macFrameSkipTextField setIntegerValue: -1]; + if ([self.macFrameSkipTextField integerValue] > 200) + [self.macFrameSkipTextField setIntegerValue: 200]; + + [sender setIntValue:0]; // reset stepper value + [self setMacFrameSkip:self.macFrameSkipTextField]; // execute setter +} @end diff --git a/macosx/Snes9x/S9xPrefsViewController.xib b/macosx/Snes9x/S9xPrefsViewController.xib index 9cbe4160..2f7fe060 100644 --- a/macosx/Snes9x/S9xPrefsViewController.xib +++ b/macosx/Snes9x/S9xPrefsViewController.xib @@ -1,14 +1,15 @@ - + - + + @@ -18,11 +19,11 @@ - + - + @@ -30,10 +31,10 @@ - + - + @@ -49,7 +50,7 @@ - + @@ -212,7 +213,7 @@ - @@ -694,43 +708,46 @@ - - + + - + - + + + + - + @@ -741,11 +758,11 @@ + - @@ -766,13 +783,13 @@ + - @@ -783,22 +800,20 @@ + - + - + - - - @@ -807,14 +822,16 @@ + + + - @@ -834,13 +851,12 @@ + - - @@ -851,7 +867,7 @@ - + From d297b2c0e76b5b2195b99c3e412df7d2f2738ce4 Mon Sep 17 00:00:00 2001 From: jorsi Date: Sun, 13 Sep 2020 19:30:43 -0400 Subject: [PATCH 5/5] fix stepper changing text field to wrong values --- macosx/Snes9x/S9xPrefsViewController.m | 13 ++++++++----- macosx/Snes9x/S9xPrefsViewController.xib | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/macosx/Snes9x/S9xPrefsViewController.m b/macosx/Snes9x/S9xPrefsViewController.m index 7b12af05..f351dcb9 100644 --- a/macosx/Snes9x/S9xPrefsViewController.m +++ b/macosx/Snes9x/S9xPrefsViewController.m @@ -322,14 +322,17 @@ - (IBAction) bumpMacFrameSkip:(NSStepper *)sender { int bumpValue = sender.intValue; // 1 or -1 - [self.macFrameSkipTextField setIntegerValue: self.macFrameSkipTextField.integerValue + bumpValue]; + int nextValue = self.macFrameSkipTextField.intValue + bumpValue; // constrain value - if ([self.macFrameSkipTextField integerValue] < 0) - [self.macFrameSkipTextField setIntegerValue: 0]; - if ([self.macFrameSkipTextField integerValue] > 200) - [self.macFrameSkipTextField setIntegerValue: 200]; + if (nextValue < 0) { + nextValue = 0; + } + if (nextValue > 200) { + nextValue = 200; + } + [self.macFrameSkipTextField setIntValue: nextValue]; [sender setIntValue:0]; // reset stepper value [self setMacFrameSkip:self.macFrameSkipTextField.intValue]; // execute setter } diff --git a/macosx/Snes9x/S9xPrefsViewController.xib b/macosx/Snes9x/S9xPrefsViewController.xib index 55554056..970908f5 100644 --- a/macosx/Snes9x/S9xPrefsViewController.xib +++ b/macosx/Snes9x/S9xPrefsViewController.xib @@ -665,7 +665,7 @@ - +