Skip to content

Commit

Permalink
Merge pull request #286 from ds22x/master
Browse files Browse the repository at this point in the history
Sync to upstream
  • Loading branch information
LibretroAdmin authored Nov 10, 2022
2 parents ae16176 + 486431d commit 2ed8d68
Show file tree
Hide file tree
Showing 25 changed files with 1,478 additions and 564 deletions.
5 changes: 4 additions & 1 deletion apu/apu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ bool8 S9xMixSamples(uint8 *dest, int sample_count)

int S9xGetSampleCount(void)
{
return spc::resampler->avail();
int avail = spc::resampler->avail();
if (Settings.MSU1) // return minimum available samples, otherwise we can run into the assert above due to partial sample generation in msu1
avail = Resampler::min(avail, msu::resampler->avail());
return avail;
}

void S9xLandSamples(void)
Expand Down
1 change: 0 additions & 1 deletion cpuaddr.h
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,6 @@ static inline uint32 StackRelativeIndirectIndexed (AccessMode a) // (d,S),Y
if (a & READ)
OpenBus = (uint8) (addr >> 8);
addr = (addr + Registers.Y.W + ICPU.ShiftedDB) & 0xffffff;
AddCycles(ONE_CYCLE);

return (addr);
}
Expand Down
5 changes: 5 additions & 0 deletions cpuops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1406,11 +1406,13 @@ bOP(70Slow, RelativeSlow, CheckOverflow(), 0, CheckEmulation())
static void Op82 (void)
{
S9xSetPCBase(ICPU.ShiftedPB + RelativeLong(JUMP));
AddCycles(ONE_CYCLE);
}

static void Op82Slow (void)
{
S9xSetPCBase(ICPU.ShiftedPB + RelativeLongSlow(JUMP));
AddCycles(ONE_CYCLE);
}

/* Flag Instructions ******************************************************* */
Expand Down Expand Up @@ -2847,6 +2849,7 @@ static void Op22E1 (void)
// Note: JSL is a new instruction,
// and so doesn't respect the emu-mode stack bounds.
uint32 addr = AbsoluteLong(JSR);
AddCycles(ONE_CYCLE);
PushB(Registers.PB);
PushW(Registers.PCw - 1);
Registers.SH = 1;
Expand All @@ -2856,6 +2859,7 @@ static void Op22E1 (void)
static void Op22E0 (void)
{
uint32 addr = AbsoluteLong(JSR);
AddCycles(ONE_CYCLE);
PushB(Registers.PB);
PushW(Registers.PCw - 1);
S9xSetPCBase(addr);
Expand All @@ -2864,6 +2868,7 @@ static void Op22E0 (void)
static void Op22Slow (void)
{
uint32 addr = AbsoluteLongSlow(JSR);
AddCycles(ONE_CYCLE);
PushB(Registers.PB);
PushW(Registers.PCw - 1);
if (CheckEmulation())
Expand Down
11 changes: 9 additions & 2 deletions gtk/src/gtk_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,15 @@ const char *S9xGetFilename(const char *ex, enum s9x_getdirtype dirtype)
static std::string filename;
fs::path path(S9xGetDirectory(dirtype));
path /= fs::path(Memory.ROMFilename).filename();
path.replace_extension(ex);
filename = path.string();
//Fixes issue with MSU-1 on linux
if(ex[0] == '-') {
path.replace_extension("");
filename = path.string();
filename.append(ex);
} else {
path.replace_extension(ex);
filename = path.string();
}
return filename.c_str();
}

Expand Down
4 changes: 3 additions & 1 deletion macosx/Snes9x/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
(c) Copyright 2004 Alexander and Sander
(c) Copyright 2004 - 2005 Steven Seeger
(c) Copyright 2005 Ryan Vogt
(c) Copyright 2019 - 2021 Michael Donald Buckley
(c) Copyright 2019 - 2022 Michael Donald Buckley
***********************************************************************************/

#import <Cocoa/Cocoa.h>
#import <snes9x_framework/snes9x_framework.h>
#import "S9xPreferences/S9xPreferencesWindowController.h"
#import "Cheats/S9xCheatsViewController.h"

extern NSWindowFrameAutosaveName const kMainWindowIdentifier;

Expand All @@ -31,6 +32,7 @@ extern NSWindowFrameAutosaveName const kMainWindowIdentifier;
@property (nonatomic, strong) NSMutableDictionary<NSString *, NSNumber *> *keys;
@property (nonatomic, strong) NSWindow *gameWindow;
@property (nonatomic, strong) S9xPreferencesWindowController *preferencesWindowController;
@property (nonatomic, strong) NSWindowController *cheatsWindowController;
@property (nonatomic, readonly, assign) S9xDeviceSetting deviceSetting;

- (void)setButtonCode:(S9xButtonCode)buttonCode forKeyCode:(int16)keyCode player:(int8)player;
Expand Down
53 changes: 52 additions & 1 deletion macosx/Snes9x/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ SNES9X for Mac OS (c) Copyright John Stiles
(c) Copyright 2004 Alexander and Sander
(c) Copyright 2004 - 2005 Steven Seeger
(c) Copyright 2005 Ryan Vogt
(c) Copyright 2019 Michael Donald Buckley
(c) Copyright 2019 - 2022 Michael Donald Buckley
***********************************************************************************/

#import <Carbon/Carbon.h>
#import "AppDelegate.h"
#import "S9xPreferencesConstants.h"

NSWindowFrameAutosaveName const kMainWindowIdentifier = @"s9xMainWindow";
NSWindowFrameAutosaveName const kCheatsWindowIdentifier = @"s9xCheatsWindow";

@implementation AppDelegate

Expand Down Expand Up @@ -194,6 +195,9 @@ - (void)setupDefaults
[self importKeySettings];
[self importGraphicsSettings];
[self applyEmulationSettings];

self.s9xEngine.cheatsEnabled = [defaults boolForKey:kEnableCheatsPref];

[defaults synchronize];
}

Expand Down Expand Up @@ -463,6 +467,11 @@ - (BOOL)openURL:(NSURL *)url
[s9xView.leftAnchor constraintGreaterThanOrEqualToAnchor:gameWindow.contentView.leftAnchor].active = YES;
[s9xView.rightAnchor constraintLessThanOrEqualToAnchor:gameWindow.contentView.rightAnchor].active = YES;

if (self.cheatsWindowController != nil)
{
[((S9xCheatsViewController *)self.cheatsWindowController.contentViewController) deselectAll];
[((S9xCheatsViewController *)self.cheatsWindowController.contentViewController) reloadData];
}

[gameWindow makeKeyAndOrderFront:self];
[NSDocumentController.sharedDocumentController noteNewRecentDocumentURL:url];
Expand All @@ -481,6 +490,17 @@ - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
else if (action == @selector(updateDeviceSetting:)) {
menuItem.state = (self.deviceSetting == (S9xDeviceSetting)menuItem.tag) ? NSOnState : NSOffState;
}
else if (action == @selector(toggleCheats:))
{
if (self.s9xEngine.cheatsEnabled)
{
menuItem.title = NSLocalizedString(@"Disable Cheats", nil);
}
else
{
menuItem.title = NSLocalizedString(@"Enable Cheats", nil);
}
}

return !self.isRunningEmulation;
}
Expand Down Expand Up @@ -587,4 +607,35 @@ - (void)deviceSettingChanged:(S9xDeviceSetting)deviceSetting
}


- (IBAction)openCheatsWindow:(id)sender
{
if (self.cheatsWindowController == nil)
{
NSWindow *window = [NSWindow windowWithContentViewController:[[S9xCheatsViewController alloc] initWithNibName:@"S9xCheatsViewController" bundle:nil]];
self.cheatsWindowController = [[NSWindowController alloc] initWithWindow:window];

window = self.cheatsWindowController.window;

window.title = NSLocalizedString(@"Cheats", nil);
window.restorationClass = self.class;
window.frameAutosaveName = kCheatsWindowIdentifier;
window.releasedWhenClosed = NO;

if ( ![window setFrameUsingName:kCheatsWindowIdentifier] )
{
[window center];
}
}

[self.cheatsWindowController showWindow:nil];
[self.cheatsWindowController.window makeKeyAndOrderFront:nil];
[self.cheatsWindowController.window makeKeyWindow];
}

- (IBAction)toggleCheats:(id)sender
{
self.s9xEngine.cheatsEnabled = !self.s9xEngine.cheatsEnabled;
[NSUserDefaults.standardUserDefaults setBool:self.s9xEngine.cheatsEnabled forKey:kEnableCheatsPref];
}

@end
Loading

0 comments on commit 2ed8d68

Please sign in to comment.