From c4cdc180681c41fed3e26debc674c42352c1dc48 Mon Sep 17 00:00:00 2001 From: Michael Buckley Date: Mon, 7 Sep 2020 13:54:19 -0700 Subject: [PATCH] Mac: Return hardware and software reset menu items --- macosx/Snes9x/AppDelegate.m | 15 +++++++++++++ macosx/Snes9x/Base.lproj/MainMenu.xib | 16 ++++++++++++-- macosx/mac-os.h | 2 ++ macosx/mac-os.mm | 32 ++++++++++++++++++++++++--- 4 files changed, 60 insertions(+), 5 deletions(-) diff --git a/macosx/Snes9x/AppDelegate.m b/macosx/Snes9x/AppDelegate.m index a49991e1..e54060f7 100644 --- a/macosx/Snes9x/AppDelegate.m +++ b/macosx/Snes9x/AppDelegate.m @@ -471,6 +471,11 @@ static NSWindowFrameAutosaveName const kMainWindowIdentifier = @"s9xMainWindow"; - (BOOL)validateMenuItem:(NSMenuItem *)menuItem { + SEL action = menuItem.action; + if (action == @selector(resume:) || action == @selector(softwareReset:) || action == @selector(hardwareReset:)) { + return [self.s9xEngine isRunning] && [self.s9xEngine isPaused]; + } + return !self.isRunningEmulation; } @@ -520,6 +525,16 @@ static NSWindowFrameAutosaveName const kMainWindowIdentifier = @"s9xMainWindow"; [self.s9xEngine resume]; } +- (IBAction)softwareReset:(id)sender +{ + [self.s9xEngine softwareReset]; +} + +- (IBAction)hardwareReset:(id)sender +{ + [self.s9xEngine hardwareReset]; +} + - (BOOL)handleInput:(S9xJoypadInput *)input fromJoypad:(S9xJoypad *)joypad { if (NSApp.keyWindow != nil && NSApp.keyWindow == self.prefsWindowController.window) diff --git a/macosx/Snes9x/Base.lproj/MainMenu.xib b/macosx/Snes9x/Base.lproj/MainMenu.xib index 106573e8..e5258657 100644 --- a/macosx/Snes9x/Base.lproj/MainMenu.xib +++ b/macosx/Snes9x/Base.lproj/MainMenu.xib @@ -1,8 +1,8 @@ - + - + @@ -104,6 +104,18 @@ + + + + + + + + + + + + diff --git a/macosx/mac-os.h b/macosx/mac-os.h index 3b6e9e9f..a3ae4d3d 100644 --- a/macosx/mac-os.h +++ b/macosx/mac-os.h @@ -168,6 +168,8 @@ extern id inputDelegate; - (void)start; - (void)stop; +- (void)softwareReset; +- (void)hardwareReset; - (BOOL)isRunning; - (BOOL)isPaused; diff --git a/macosx/mac-os.mm b/macosx/mac-os.mm index 9828acd7..66a68f5e 100644 --- a/macosx/mac-os.mm +++ b/macosx/mac-os.mm @@ -1710,6 +1710,7 @@ int PromptFreezeDefrost (Boolean freezing) const char letters[] = "123456789ABC", *filename; frzselecting = true; + [s9xView updatePauseOverlay]; oldInactiveMode = inactiveMode; if (inactiveMode == 3) inactiveMode = 2; @@ -2036,7 +2037,7 @@ int PromptFreezeDefrost (Boolean freezing) usleep(30000); UpdateFreezeDefrostScreen(current_selection, image, draw, ctx); - } while (result == -2); + } while (result == -2 && frzselecting); CocoaPlayFreezeDefrostSound(); @@ -2050,6 +2051,9 @@ int PromptFreezeDefrost (Boolean freezing) inactiveMode = oldInactiveMode; frzselecting = false; + pauseEmulation = false; + + [s9xView updatePauseOverlay]; return (result); } @@ -2610,6 +2614,7 @@ static void Initialize (void) } frzselecting = false; + [s9xView updatePauseOverlay]; S9xSetControllerCrosshair(X_MOUSE1, 0, NULL, NULL); S9xSetControllerCrosshair(X_MOUSE2, 0, NULL, NULL); @@ -2936,8 +2941,7 @@ void QuitWithFatalError ( NSString *message) - (void)updatePauseOverlay { dispatch_async(dispatch_get_main_queue(), ^{ - NSLog(@"%d", pauseEmulation); - self.subviews[0].hidden = !pauseEmulation; + self.subviews[0].hidden = (frzselecting || !pauseEmulation); CGFloat scaleFactor = MAX(self.window.backingScaleFactor, 1.0); glScreenW = self.frame.size.width * scaleFactor; glScreenH = self.frame.size.height * scaleFactor; @@ -3030,6 +3034,21 @@ void QuitWithFatalError ( NSString *message) S9xExit(); } +- (void)softwareReset +{ + SNES9X_SoftReset(); + SNES9X_Go(); + [self resume]; +} + + +- (void)hardwareReset +{ + SNES9X_Reset(); + SNES9X_Go(); + [self resume]; +} + - (BOOL)isRunning { return running; @@ -3172,6 +3191,7 @@ void QuitWithFatalError ( NSString *message) - (BOOL)loadROM:(NSURL *)fileURL { running = false; + frzselecting = false; while (!Settings.StopEmulation) { @@ -3183,6 +3203,12 @@ void QuitWithFatalError ( NSString *message) SNES9X_Go(); s9xView.window.title = fileURL.lastPathComponent.stringByDeletingPathExtension; [s9xView.window makeKeyAndOrderFront:nil]; + + dispatch_async(dispatch_get_main_queue(), ^ + { + [s9xView.window makeFirstResponder:s9xView]; + }); + [self start]; return YES; }