Skip to content

Commit

Permalink
add frame skip to preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
orsi committed Sep 13, 2020
1 parent 7d6a63f commit a8921f4
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 20 deletions.
1 change: 1 addition & 0 deletions macosx/Snes9x/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion macosx/Snes9x/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ - (void)setupDefaults
@(kKeyTC).stringValue : @(kVK_ANSI_Comma)
},
kShowFPSPref: @(NO),
kVideoModePref:@(VIDEOMODE_BLOCKY)
kVideoModePref:@(VIDEOMODE_BLOCKY),
kMacFrameSkipPref:@(macFrameSkip)
};

[defaults registerDefaults:defaultSettings];
Expand Down Expand Up @@ -513,6 +514,13 @@ - (void)setVideoMode:(int)videoMode
[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];
Expand Down
1 change: 1 addition & 0 deletions macosx/Snes9x/S9xPrefsConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ extern NSString * const kJoypadInputPrefs;
extern NSString * const kJoypadPlayerPrefs;
extern NSString * const kShowFPSPref;
extern NSString * const kVideoModePref;
extern NSString * const kMacFrameSkipPref;
1 change: 1 addition & 0 deletions macosx/Snes9x/S9xPrefsConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ SNES9X for Mac OS (c) Copyright John Stiles
NSString * const kJoypadPlayerPrefs = @"JoypadPlayers";
NSString * const kShowFPSPref = @"ShowFPS";
NSString * const kVideoModePref = @"VideoMode";
NSString * const kMacFrameSkipPref = @"MacFrameSkip";
28 changes: 27 additions & 1 deletion macosx/Snes9x/S9xPrefsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ @interface S9xPrefsViewController ()
@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
Expand Down Expand Up @@ -103,6 +104,11 @@ - (void)refresh
{
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)
Expand Down Expand Up @@ -271,6 +277,13 @@ - (IBAction)setVideoMode:(NSPopUpButton *)sender
[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;
Expand All @@ -293,5 +306,18 @@ - (BOOL)handleInput:(S9xJoypadInput *)input fromJoypad:(S9xJoypad *)joypad

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
74 changes: 57 additions & 17 deletions macosx/Snes9x/S9xPrefsViewController.xib

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions macosx/mac-os.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ extern id<S9xInputDelegate> inputDelegate;
- (BOOL)loadROM:(NSURL *)fileURL;

- (void)setVideoMode:(int)videoMode;
- (void)setMacFrameSkip:(int)_macFrameSkip;
- (void)setShowFPS:(BOOL)showFPS;

@end
Expand Down
11 changes: 11 additions & 0 deletions macosx/mac-os.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3235,6 +3235,17 @@ - (void)setVideoMode:(int)mode
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<S9xInputDelegate>)delegate
{
Expand Down
6 changes: 5 additions & 1 deletion macosx/mac-render.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -408,4 +412,4 @@ void S9xTextMode (void)
void S9xGraphicsMode (void)
{
return;
}
}

0 comments on commit a8921f4

Please sign in to comment.