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..56adac4c 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 = @"FrameSkip"; diff --git a/macosx/Snes9x/S9xPrefsViewController.m b/macosx/Snes9x/S9xPrefsViewController.m index 3f6bb424..f351dcb9 100644 --- a/macosx/Snes9x/S9xPrefsViewController.m +++ b/macosx/Snes9x/S9xPrefsViewController.m @@ -30,6 +30,9 @@ @property (nonatomic, weak) IBOutlet NSButton *showFPSCheckbox; @property (nonatomic, weak) IBOutlet NSPopUpButton *devicePopUp; @property (nonatomic, weak) IBOutlet NSPopUpButton *playerPopUp; +@property (nonatomic, weak) IBOutlet NSTextField *macFrameSkipTextField; +@property (nonatomic, weak) IBOutlet NSStepper *macFrameSkipStepper; +@property (nonatomic, weak) IBOutlet NSButton *macFrameSkipAutomaticButton; @end @implementation S9xPrefsViewController @@ -103,6 +106,22 @@ { NSUInteger index = MIN([NSUserDefaults.standardUserDefaults integerForKey:kVideoModePref], 1); [self.videoModePopup selectItemAtIndex:index]; + + NSInteger macFrameSkipDefault = [NSUserDefaults.standardUserDefaults integerForKey:kMacFrameSkipPref]; + // if macFrameSkip is equal to -1, set automatic checkbox + // to be checked, disable the ability to change frame skip values + // from stepper/text field, else leave automatic checkbox + // unchecked and set textfield to value + if (macFrameSkipDefault == -1) { + [self.macFrameSkipTextField setEnabled: false]; + [self.macFrameSkipStepper setEnabled: false]; + [self.macFrameSkipTextField setIntValue: 0]; // show something at least + [self.macFrameSkipAutomaticButton setIntValue: 1]; + } else { + [self.macFrameSkipTextField setIntValue: (int)macFrameSkipDefault]; + [self.macFrameSkipAutomaticButton setIntValue: 0]; + } + self.showFPSCheckbox.state = [NSUserDefaults.standardUserDefaults boolForKey:kShowFPSPref]; if (self.devicePopUp.selectedItem.tag < 0) @@ -271,6 +290,12 @@ [appDelegate setVideoMode:(int)sender.selectedTag]; } +- (IBAction)setMacFrameSkip:(int)value +{ + AppDelegate *appDelegate = (AppDelegate *)NSApp.delegate; + [appDelegate setMacFrameSkip:value]; +} + - (BOOL)handleInput:(S9xJoypadInput *)input fromJoypad:(S9xJoypad *)joypad { id firstResponder = self.view.window.firstResponder; @@ -294,4 +319,43 @@ return NO; } +- (IBAction) bumpMacFrameSkip:(NSStepper *)sender +{ + int bumpValue = sender.intValue; // 1 or -1 + int nextValue = self.macFrameSkipTextField.intValue + bumpValue; + + // constrain value + 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 +} + +- (IBAction)onChangeMacFrameSkipTextField:(NSTextField *)sender +{ + [self setMacFrameSkip:sender.intValue]; +} + +- (IBAction) onCheckMacFrameSkipAutomaticButton:(NSButton *)sender +{ + if (sender.intValue == 1) { + // when automatic is checked, disable macFrameSkipTextField and + // macFrameSkipStepper, then set macFrameSkip to -1 (automatic) + [self.macFrameSkipTextField setEnabled:false]; + [self.macFrameSkipStepper setEnabled:false]; + [self setMacFrameSkip:-1]; + } else { + // when automatic is unchecked, enable macFrameSkipTextField and + // macFrameSkipStepper, then set macFrameSkip to value of text field + [self.macFrameSkipTextField setEnabled:true]; + [self.macFrameSkipStepper setEnabled:true]; + [self setMacFrameSkip:self.macFrameSkipTextField.intValue]; + } +} @end diff --git a/macosx/Snes9x/S9xPrefsViewController.xib b/macosx/Snes9x/S9xPrefsViewController.xib index 9cbe4160..970908f5 100644 --- a/macosx/Snes9x/S9xPrefsViewController.xib +++ b/macosx/Snes9x/S9xPrefsViewController.xib @@ -1,14 +1,17 @@ - + - + + + + @@ -18,11 +21,11 @@ - + - + @@ -30,10 +33,10 @@ - + - + @@ -49,7 +52,7 @@ - + @@ -212,7 +215,7 @@ @@ -662,26 +708,33 @@ + + + + + + + @@ -694,6 +747,7 @@ + @@ -704,6 +758,7 @@ + @@ -724,12 +779,11 @@ - - + @@ -744,19 +798,20 @@ - + + + - @@ -767,11 +822,14 @@ + + + @@ -783,21 +841,19 @@ - - + - @@ -811,7 +867,7 @@ - + diff --git a/macosx/mac-os.h b/macosx/mac-os.h index a3ae4d3d..f7106456 100644 --- a/macosx/mac-os.h +++ b/macosx/mac-os.h @@ -192,6 +192,7 @@ extern id inputDelegate; - (BOOL)loadROM:(NSURL *)fileURL; - (void)setVideoMode:(int)videoMode; +- (void)setMacFrameSkip:(int)_macFrameSkip; - (void)setShowFPS:(BOOL)showFPS; @end diff --git a/macosx/mac-os.mm b/macosx/mac-os.mm index 64f7011c..5c8e3531 100644 --- a/macosx/mac-os.mm +++ b/macosx/mac-os.mm @@ -3235,6 +3235,17 @@ void QuitWithFatalError ( NSString *message) videoMode = mode; } +- (void)setMacFrameSkip:(int)_macFrameSkip +{ + macFrameSkip = _macFrameSkip; + + // contrains to -1 to 200 + if (macFrameSkip < -1) + macFrameSkip = -1; + if (macFrameSkip > 200) + macFrameSkip = 200; +} + @dynamic inputDelegate; - (void)setInputDelegate:(id)delegate { diff --git a/macosx/mac-render.mm b/macosx/mac-render.mm index dbdf7529..71d57b7e 100644 --- a/macosx/mac-render.mm +++ b/macosx/mac-render.mm @@ -297,6 +297,10 @@ void S9xPutImage (int width, int height) for (int i = 0; i < 60; i++) frameCalc += drawnFrames[i]; + // avoid dividing by 0 + if (frameCalc == 0) + frameCalc = 1; + IPPU.DisplayedRenderedFrameCount = (Memory.ROMFramesPerSecond * 60) / frameCalc; } @@ -408,4 +412,4 @@ void S9xTextMode (void) void S9xGraphicsMode (void) { return; -} \ No newline at end of file +}