diff --git a/BizHawk.Client.EmuHawk/GlobalWin.cs b/BizHawk.Client.EmuHawk/GlobalWin.cs index 757abd40dc..1b0a3e0ef3 100644 --- a/BizHawk.Client.EmuHawk/GlobalWin.cs +++ b/BizHawk.Client.EmuHawk/GlobalWin.cs @@ -1,6 +1,6 @@ -using BizHawk.Client.Common; -using BizHawk.Bizware.BizwareGL; +using BizHawk.Bizware.BizwareGL; +// ReSharper disable StyleCop.SA1401 namespace BizHawk.Client.EmuHawk { public static class GlobalWin @@ -21,7 +21,7 @@ namespace BizHawk.Client.EmuHawk public static Bizware.BizwareGL.Drivers.OpenTK.IGL_TK IGL_GL; public static Sound Sound; - public static OSDManager OSD = new OSDManager(); + public static readonly OSDManager OSD = new OSDManager(); public static DisplayManager DisplayManager; public static GLManager GLManager; diff --git a/BizHawk.Client.EmuHawk/MainForm.Designer.cs b/BizHawk.Client.EmuHawk/MainForm.Designer.cs index 69959bfae8..88eb744eee 100644 --- a/BizHawk.Client.EmuHawk/MainForm.Designer.cs +++ b/BizHawk.Client.EmuHawk/MainForm.Designer.cs @@ -1222,7 +1222,7 @@ this.EmulationSubMenu.Name = "EmulationSubMenu"; this.EmulationSubMenu.Size = new System.Drawing.Size(73, 19); this.EmulationSubMenu.Text = "&Emulation"; - this.EmulationSubMenu.DropDownOpened += new System.EventHandler(this.emulationToolStripMenuItem_DropDownOpened); + this.EmulationSubMenu.DropDownOpened += new System.EventHandler(this.EmulationMenuItem_DropDownOpened); // // PauseMenuItem // @@ -1354,7 +1354,7 @@ this.DisplayFPSMenuItem.Name = "DisplayFPSMenuItem"; this.DisplayFPSMenuItem.Size = new System.Drawing.Size(198, 22); this.DisplayFPSMenuItem.Text = "Display FPS"; - this.DisplayFPSMenuItem.Click += new System.EventHandler(this.DisplayFPSMenuItem_Click); + this.DisplayFPSMenuItem.Click += new System.EventHandler(this.DisplayFpsMenuItem_Click); // // DisplayFrameCounterMenuItem // @@ -1856,14 +1856,14 @@ this.Coresnes9xMenuItem.Name = "Coresnes9xMenuItem"; this.Coresnes9xMenuItem.Size = new System.Drawing.Size(177, 22); this.Coresnes9xMenuItem.Text = "Snes9x"; - this.Coresnes9xMenuItem.Click += new System.EventHandler(this.Coresnes9xMenuItem_Click); + this.Coresnes9xMenuItem.Click += new System.EventHandler(this.CoreSnes9xMenuItem_Click); // // gBAWithMGBAToolStripMenuItem // this.gBAWithMGBAToolStripMenuItem.Name = "gBAWithMGBAToolStripMenuItem"; this.gBAWithMGBAToolStripMenuItem.Size = new System.Drawing.Size(239, 22); this.gBAWithMGBAToolStripMenuItem.Text = "GBA with mGBA"; - this.gBAWithMGBAToolStripMenuItem.Click += new System.EventHandler(this.gBAWithMGBAToolStripMenuItem_Click); + this.gBAWithMGBAToolStripMenuItem.Click += new System.EventHandler(this.GbaWithmGBAMenuItem_Click); // // toolStripMenuItem16 // @@ -2179,14 +2179,14 @@ this.quickNESToolStripMenuItem.Name = "quickNESToolStripMenuItem"; this.quickNESToolStripMenuItem.Size = new System.Drawing.Size(125, 22); this.quickNESToolStripMenuItem.Text = "&QuickNes"; - this.quickNESToolStripMenuItem.Click += new System.EventHandler(this.quickNESToolStripMenuItem_Click); + this.quickNESToolStripMenuItem.Click += new System.EventHandler(this.QuickNesToolStripMenuItem_Click); // // nesHawkToolStripMenuItem // this.nesHawkToolStripMenuItem.Name = "nesHawkToolStripMenuItem"; this.nesHawkToolStripMenuItem.Size = new System.Drawing.Size(125, 22); this.nesHawkToolStripMenuItem.Text = "&NesHawk"; - this.nesHawkToolStripMenuItem.Click += new System.EventHandler(this.nesHawkToolStripMenuItem_Click); + this.nesHawkToolStripMenuItem.Click += new System.EventHandler(this.NesHawkToolStripMenuItem_Click); // // toolStripSeparator34 // @@ -2198,7 +2198,7 @@ this.NESPPUViewerMenuItem.Name = "NESPPUViewerMenuItem"; this.NESPPUViewerMenuItem.Size = new System.Drawing.Size(233, 22); this.NESPPUViewerMenuItem.Text = "&PPU Viewer"; - this.NESPPUViewerMenuItem.Click += new System.EventHandler(this.NESPPUViewerMenuItem_Click); + this.NESPPUViewerMenuItem.Click += new System.EventHandler(this.NesPPUViewerMenuItem_Click); // // NESNametableViewerMenuItem // @@ -2219,7 +2219,7 @@ this.musicRipperToolStripMenuItem.Name = "musicRipperToolStripMenuItem"; this.musicRipperToolStripMenuItem.Size = new System.Drawing.Size(233, 22); this.musicRipperToolStripMenuItem.Text = "Music Ripper"; - this.musicRipperToolStripMenuItem.Click += new System.EventHandler(this.musicRipperToolStripMenuItem_Click); + this.musicRipperToolStripMenuItem.Click += new System.EventHandler(this.MusicRipperMenuItem_Click); // // toolStripSeparator17 // @@ -2255,7 +2255,7 @@ this.VSSettingsMenuItem.Name = "VSSettingsMenuItem"; this.VSSettingsMenuItem.Size = new System.Drawing.Size(233, 22); this.VSSettingsMenuItem.Text = "VS Settings..."; - this.VSSettingsMenuItem.Click += new System.EventHandler(this.VSSettingsMenuItem_Click); + this.VSSettingsMenuItem.Click += new System.EventHandler(this.VsSettingsMenuItem_Click); // // MovieSettingsMenuItem // @@ -2300,28 +2300,28 @@ this.VSInsertCoinP1MenuItem.Name = "VSInsertCoinP1MenuItem"; this.VSInsertCoinP1MenuItem.Size = new System.Drawing.Size(149, 22); this.VSInsertCoinP1MenuItem.Text = "Insert Coin P1"; - this.VSInsertCoinP1MenuItem.Click += new System.EventHandler(this.VSInsertCoinP1MenuItem_Click); + this.VSInsertCoinP1MenuItem.Click += new System.EventHandler(this.VsInsertCoinP1MenuItem_Click); // // VSInsertCoinP2MenuItem // this.VSInsertCoinP2MenuItem.Name = "VSInsertCoinP2MenuItem"; this.VSInsertCoinP2MenuItem.Size = new System.Drawing.Size(149, 22); this.VSInsertCoinP2MenuItem.Text = "Insert Coin P2"; - this.VSInsertCoinP2MenuItem.Click += new System.EventHandler(this.VSInsertCoinP2MenuItem_Click); + this.VSInsertCoinP2MenuItem.Click += new System.EventHandler(this.VsInsertCoinP2MenuItem_Click); // // VSServiceSwitchMenuItem // this.VSServiceSwitchMenuItem.Name = "VSServiceSwitchMenuItem"; this.VSServiceSwitchMenuItem.Size = new System.Drawing.Size(149, 22); this.VSServiceSwitchMenuItem.Text = "Service Switch"; - this.VSServiceSwitchMenuItem.Click += new System.EventHandler(this.VSServiceSwitchMenuItem_Click); + this.VSServiceSwitchMenuItem.Click += new System.EventHandler(this.VsServiceSwitchMenuItem_Click); // // barcodeReaderToolStripMenuItem // this.barcodeReaderToolStripMenuItem.Name = "barcodeReaderToolStripMenuItem"; this.barcodeReaderToolStripMenuItem.Size = new System.Drawing.Size(233, 22); this.barcodeReaderToolStripMenuItem.Text = "Barcode Reader"; - this.barcodeReaderToolStripMenuItem.Click += new System.EventHandler(this.barcodeReaderToolStripMenuItem_Click); + this.barcodeReaderToolStripMenuItem.Click += new System.EventHandler(this.BarcodeReaderMenuItem_Click); // // PCESubMenu // @@ -2355,7 +2355,7 @@ this.PCEGraphicsSettingsMenuItem.Name = "PCEGraphicsSettingsMenuItem"; this.PCEGraphicsSettingsMenuItem.Size = new System.Drawing.Size(258, 22); this.PCEGraphicsSettingsMenuItem.Text = "Graphics Settings"; - this.PCEGraphicsSettingsMenuItem.Click += new System.EventHandler(this.PCEGraphicsSettingsMenuItem_Click); + this.PCEGraphicsSettingsMenuItem.Click += new System.EventHandler(this.PceGraphicsSettingsMenuItem_Click); // // toolStripSeparator32 // @@ -2367,7 +2367,7 @@ this.PCEBGViewerMenuItem.Name = "PCEBGViewerMenuItem"; this.PCEBGViewerMenuItem.Size = new System.Drawing.Size(258, 22); this.PCEBGViewerMenuItem.Text = "&BG Viewer"; - this.PCEBGViewerMenuItem.Click += new System.EventHandler(this.PCEBGViewerMenuItem_Click); + this.PCEBGViewerMenuItem.Click += new System.EventHandler(this.PceBgViewerMenuItem_Click); // // PCEtileViewerToolStripMenuItem // @@ -2381,7 +2381,7 @@ this.PceSoundDebuggerToolStripMenuItem.Name = "PceSoundDebuggerToolStripMenuItem"; this.PceSoundDebuggerToolStripMenuItem.Size = new System.Drawing.Size(258, 22); this.PceSoundDebuggerToolStripMenuItem.Text = "&Sound Debugger"; - this.PceSoundDebuggerToolStripMenuItem.Click += new System.EventHandler(this.PceSoundDebuggerToolStripMenuItem_Click); + this.PceSoundDebuggerToolStripMenuItem.Click += new System.EventHandler(this.PceSoundDebuggerMenuItem_Click); // // toolStripSeparator25 // @@ -2505,14 +2505,14 @@ this.SMSenableBIOSToolStripMenuItem.Name = "SMSenableBIOSToolStripMenuItem"; this.SMSenableBIOSToolStripMenuItem.Size = new System.Drawing.Size(241, 22); this.SMSenableBIOSToolStripMenuItem.Text = "Enable BIOS"; - this.SMSenableBIOSToolStripMenuItem.Click += new System.EventHandler(this.SMS_BIOS_Click); + this.SMSenableBIOSToolStripMenuItem.Click += new System.EventHandler(this.SmsBiosMenuItem_Click); // // SMSEnableFMChipMenuItem // this.SMSEnableFMChipMenuItem.Name = "SMSEnableFMChipMenuItem"; this.SMSEnableFMChipMenuItem.Size = new System.Drawing.Size(241, 22); this.SMSEnableFMChipMenuItem.Text = "&Enable FM Chip"; - this.SMSEnableFMChipMenuItem.Click += new System.EventHandler(this.SMSEnableFMChipMenuItem_Click); + this.SMSEnableFMChipMenuItem.Click += new System.EventHandler(this.SmsEnableFmChipMenuItem_Click); // // SMSOverclockMenuItem // @@ -2645,7 +2645,6 @@ this.AtariSubMenu.Name = "AtariSubMenu"; this.AtariSubMenu.Size = new System.Drawing.Size(44, 19); this.AtariSubMenu.Text = "&Atari"; - this.AtariSubMenu.DropDownOpened += new System.EventHandler(this.AtariSubMenu_DropDownOpened); // // AtariSettingsToolStripMenuItem // @@ -3039,7 +3038,7 @@ this.DGBsettingsToolStripMenuItem.Name = "DGBsettingsToolStripMenuItem"; this.DGBsettingsToolStripMenuItem.Size = new System.Drawing.Size(125, 22); this.DGBsettingsToolStripMenuItem.Text = "Settings..."; - this.DGBsettingsToolStripMenuItem.Click += new System.EventHandler(this.DGBsettingsToolStripMenuItem_Click); + this.DGBsettingsToolStripMenuItem.Click += new System.EventHandler(this.DgbSettingsMenuItem_Click); // // GenesisSubMenu // @@ -3122,7 +3121,7 @@ this.settingsToolStripMenuItem1.Name = "settingsToolStripMenuItem1"; this.settingsToolStripMenuItem1.Size = new System.Drawing.Size(152, 22); this.settingsToolStripMenuItem1.Text = "&Settings..."; - this.settingsToolStripMenuItem1.Click += new System.EventHandler(this.settingsToolStripMenuItem1_Click_1); + this.settingsToolStripMenuItem1.Click += new System.EventHandler(this.AppleIISettingsMenuItem_Click); // // C64SubMenu // @@ -3835,7 +3834,7 @@ this.ClearSRAMContextMenuItem.Name = "ClearSRAMContextMenuItem"; this.ClearSRAMContextMenuItem.Size = new System.Drawing.Size(216, 22); this.ClearSRAMContextMenuItem.Text = "Close and Clear SRAM"; - this.ClearSRAMContextMenuItem.Click += new System.EventHandler(this.ClearSRAMContextMenuItem_Click); + this.ClearSRAMContextMenuItem.Click += new System.EventHandler(this.ClearSramContextMenuItem_Click); // // ShowMenuContextMenuSeparator // diff --git a/BizHawk.Client.EmuHawk/MainForm.Events.cs b/BizHawk.Client.EmuHawk/MainForm.Events.cs index 0c2dbee8a5..3e2ea25636 100644 --- a/BizHawk.Client.EmuHawk/MainForm.Events.cs +++ b/BizHawk.Client.EmuHawk/MainForm.Events.cs @@ -27,7 +27,7 @@ using BizHawk.Emulation.Cores.Computers.Commodore64; namespace BizHawk.Client.EmuHawk { - partial class MainForm + public partial class MainForm { #region File Menu @@ -51,7 +51,7 @@ namespace BizHawk.Client.EmuHawk SaveRAMSubMenu.Enabled = hasSaveRam; if (SaveRAMSubMenu.Font.Bold != needBold) { - var font = new System.Drawing.Font(SaveRAMSubMenu.Font, needBold ? FontStyle.Bold : FontStyle.Regular); + var font = new Font(SaveRAMSubMenu.Font, needBold ? FontStyle.Bold : FontStyle.Regular); SaveRAMSubMenu.Font = font; } @@ -72,62 +72,52 @@ namespace BizHawk.Client.EmuHawk SaveState0MenuItem.Font = new Font( SaveState0MenuItem.Font.FontFamily, SaveState0MenuItem.Font.Size, - _stateSlots.HasSlot(0) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular - ); + _stateSlots.HasSlot(0) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular); SaveState1MenuItem.Font = new Font( SaveState1MenuItem.Font.FontFamily, SaveState1MenuItem.Font.Size, - _stateSlots.HasSlot(1) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular - ); + _stateSlots.HasSlot(1) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular); SaveState2MenuItem.Font = new Font( SaveState2MenuItem.Font.FontFamily, SaveState2MenuItem.Font.Size, - _stateSlots.HasSlot(2) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular - ); + _stateSlots.HasSlot(2) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular); SaveState3MenuItem.Font = new Font( SaveState3MenuItem.Font.FontFamily, SaveState3MenuItem.Font.Size, - _stateSlots.HasSlot(3) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular - ); + _stateSlots.HasSlot(3) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular); SaveState4MenuItem.Font = new Font( SaveState4MenuItem.Font.FontFamily, SaveState4MenuItem.Font.Size, - _stateSlots.HasSlot(4) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular - ); + _stateSlots.HasSlot(4) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular); SaveState5MenuItem.Font = new Font( SaveState5MenuItem.Font.FontFamily, SaveState5MenuItem.Font.Size, - _stateSlots.HasSlot(5) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular - ); + _stateSlots.HasSlot(5) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular); SaveState6MenuItem.Font = new Font( SaveState6MenuItem.Font.FontFamily, SaveState6MenuItem.Font.Size, - _stateSlots.HasSlot(6) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular - ); + _stateSlots.HasSlot(6) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular); SaveState7MenuItem.Font = new Font( SaveState7MenuItem.Font.FontFamily, SaveState7MenuItem.Font.Size, - _stateSlots.HasSlot(7) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular - ); + _stateSlots.HasSlot(7) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular); SaveState8MenuItem.Font = new Font( SaveState8MenuItem.Font.FontFamily, SaveState8MenuItem.Font.Size, - _stateSlots.HasSlot(8) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular - ); + _stateSlots.HasSlot(8) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular); SaveState9MenuItem.Font = new Font( SaveState9MenuItem.Font.FontFamily, SaveState9MenuItem.Font.Size, - _stateSlots.HasSlot(9) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular - ); + _stateSlots.HasSlot(9) ? (FontStyle.Italic | FontStyle.Bold) : FontStyle.Regular); SaveState1MenuItem.ShortcutKeyDisplayString = Global.Config.HotkeyBindings["Save State 1"].Bindings; SaveState2MenuItem.ShortcutKeyDisplayString = Global.Config.HotkeyBindings["Save State 2"].Bindings; @@ -320,12 +310,16 @@ namespace BizHawk.Client.EmuHawk { var oac = new OpenAdvancedChooser(this); if (oac.ShowHawkDialog() == DialogResult.Cancel) + { return; + } if (oac.Result == OpenAdvancedChooser.Command.RetroLaunchNoGame) { - var argsNoGame = new LoadRomArgs(); - argsNoGame.OpenAdvanced = new OpenAdvanced_LibretroNoGame(Global.Config.LibretroCore); + var argsNoGame = new LoadRomArgs + { + OpenAdvanced = new OpenAdvanced_LibretroNoGame(Global.Config.LibretroCore) + }; LoadRom("", argsNoGame); return; } @@ -340,12 +334,16 @@ namespace BizHawk.Client.EmuHawk filter = oac.SuggestedExtensionFilter; } else if (oac.Result == OpenAdvancedChooser.Command.ClassicLaunchGame) + { args.OpenAdvanced = new OpenAdvanced_OpenRom(); - else throw new InvalidOperationException("Automatic Alpha Sanitizer"); + } + else + { + throw new InvalidOperationException("Automatic Alpha Sanitizer"); + } - - //----------------- - //CLONE OF CODE FROM OpenRom (mostly) + /*************************/ + /* CLONE OF CODE FROM OpenRom (mostly) */ var ofd = new OpenFileDialog { InitialDirectory = PathManager.GetRomsPath(Emulator.SystemId), @@ -364,9 +362,7 @@ namespace BizHawk.Client.EmuHawk var file = new FileInfo(ofd.FileName); Global.Config.LastRomPath = file.DirectoryName; _lastOpenRomFilter = ofd.FilterIndex; - //----------------- - - + /*************************/ LoadRom(file.FullName, args); } @@ -464,8 +460,9 @@ namespace BizHawk.Client.EmuHawk { if (!Emulator.Attributes().Released) { - var result = MessageBox.Show - (this, "Thanks for using Bizhawk! The emulation core you have selected " + + var result = MessageBox.Show( + this, + "Thanks for using Bizhawk! The emulation core you have selected " + "is currently BETA-status. We appreciate your help in testing Bizhawk. " + "You can record a movie on this core if you'd like to, but expect to " + "encounter bugs and sync problems. Continue?", "BizHawk", MessageBoxButtons.YesNo); @@ -592,7 +589,10 @@ namespace BizHawk.Client.EmuHawk private void StopMovieWithoutSavingMenuItem_Click(object sender, EventArgs e) { if (Global.Config.EnableBackupMovies) + { Global.MovieSession.Movie.SaveBackup(); + } + StopMovie(saveChanges: false); } @@ -712,7 +712,7 @@ namespace BizHawk.Client.EmuHawk #region Emulation Menu - private void emulationToolStripMenuItem_DropDownOpened(object sender, EventArgs e) + private void EmulationMenuItem_DropDownOpened(object sender, EventArgs e) { PauseMenuItem.Checked = _didMenuPause ? _wasPaused : EmulatorPaused; @@ -822,9 +822,9 @@ namespace BizHawk.Client.EmuHawk ToggleFullscreen(); } - private void DisplayFPSMenuItem_Click(object sender, EventArgs e) + private void DisplayFpsMenuItem_Click(object sender, EventArgs e) { - ToggleFPS(); + ToggleFps(); } private void DisplayFrameCounterMenuItem_Click(object sender, EventArgs e) @@ -903,7 +903,11 @@ namespace BizHawk.Client.EmuHawk Frameskip8MenuItem.Checked = Global.Config.FrameSkip == 8; Frameskip9MenuItem.Checked = Global.Config.FrameSkip == 9; MinimizeSkippingMenuItem.Enabled = !NeverSkipMenuItem.Checked; - if (!MinimizeSkippingMenuItem.Enabled) MinimizeSkippingMenuItem.Checked = true; + if (!MinimizeSkippingMenuItem.Enabled) + { + MinimizeSkippingMenuItem.Checked = true; + } + AudioThrottleMenuItem.Enabled = Global.Config.SoundEnabled; AudioThrottleMenuItem.Checked = Global.Config.SoundThrottle; VsyncEnabledMenuItem.Checked = Global.Config.VSync; @@ -1037,8 +1041,9 @@ namespace BizHawk.Client.EmuHawk if (new ProfileConfig().ShowDialog() == DialogResult.OK) { GlobalWin.OSD.AddMessage("Profile settings saved"); - //We hide the FirstBoot items since the user setup a Profile - //Is it a bad thing to do this constantly? + + // We hide the FirstBoot items since the user setup a Profile + // Is it a bad thing to do this constantly? Global.Config.FirstBoot = false; ProfileFirstBootLabel.Visible = false; } @@ -1059,6 +1064,7 @@ namespace BizHawk.Client.EmuHawk { RewireSound(); } + old = Global.Config.VSyncThrottle; Global.Config.VSyncThrottle = false; if (old) @@ -1203,11 +1209,8 @@ namespace BizHawk.Client.EmuHawk Coresnes9xMenuItem.Checked = Global.Config.SNES_InSnes9x; Coresnes9xMenuItem.Visible = VersionInfo.DeveloperBuild; - LibsnesCore.SnesSyncSettings sss = (LibsnesCore.SnesSyncSettings)Global.Config.GetCoreSyncSettings(); - if (sss == null) - { - sss = new LibsnesCore.SnesSyncSettings(); - } + LibsnesCore.SnesSyncSettings sss = (LibsnesCore.SnesSyncSettings)Global.Config.GetCoreSyncSettings() + ?? new LibsnesCore.SnesSyncSettings(); CorebsnesPerformanceMenuItem.Checked = sss.Profile == "Performance"; CorebsnesCompatibilityMenuItem.Checked = sss.Profile == "Compatibility"; @@ -1215,11 +1218,8 @@ namespace BizHawk.Client.EmuHawk private void CorebsnesPerformanceMenuItem_Click(object sender, EventArgs e) { - LibsnesCore.SnesSyncSettings sss = (LibsnesCore.SnesSyncSettings)Global.Config.GetCoreSyncSettings(); - if (sss == null) - { - sss = new LibsnesCore.SnesSyncSettings(); - } + LibsnesCore.SnesSyncSettings sss = (LibsnesCore.SnesSyncSettings)Global.Config.GetCoreSyncSettings() + ?? new LibsnesCore.SnesSyncSettings(); string orig = sss.Profile; @@ -1234,11 +1234,8 @@ namespace BizHawk.Client.EmuHawk private void CorebsnesCompatibilityMenuItem_Click(object sender, EventArgs e) { - LibsnesCore.SnesSyncSettings sss = (LibsnesCore.SnesSyncSettings)Global.Config.GetCoreSyncSettings(); - if (sss == null) - { - sss = new LibsnesCore.SnesSyncSettings(); - } + LibsnesCore.SnesSyncSettings sss = (LibsnesCore.SnesSyncSettings)Global.Config.GetCoreSyncSettings() + ?? new LibsnesCore.SnesSyncSettings(); string orig = sss.Profile; @@ -1251,7 +1248,7 @@ namespace BizHawk.Client.EmuHawk } } - private void Coresnes9xMenuItem_Click(object sender, EventArgs e) + private void CoreSnes9xMenuItem_Click(object sender, EventArgs e) { Global.Config.SNES_InSnes9x ^= true; @@ -1368,9 +1365,9 @@ namespace BizHawk.Client.EmuHawk { externalToolToolStripMenuItem.DropDownItems.Clear(); - foreach(ToolStripMenuItem item in ExternalToolManager.ToolStripMenu) + foreach (ToolStripMenuItem item in ExternalToolManager.ToolStripMenu) { - if(item.Enabled) + if (item.Enabled) { item.Click += delegate { @@ -1381,6 +1378,7 @@ namespace BizHawk.Client.EmuHawk { item.Image = Properties.Resources.ExclamationRed; } + externalToolToolStripMenuItem.DropDownItems.Add(item); } @@ -1496,13 +1494,13 @@ namespace BizHawk.Client.EmuHawk #region NES - private void quickNESToolStripMenuItem_Click(object sender, EventArgs e) + private void QuickNesToolStripMenuItem_Click(object sender, EventArgs e) { Global.Config.NES_InQuickNES = true; FlagNeedsReboot(); } - private void nesHawkToolStripMenuItem_Click(object sender, EventArgs e) + private void NesHawkToolStripMenuItem_Click(object sender, EventArgs e) { Global.Config.NES_InQuickNES = false; FlagNeedsReboot(); @@ -1515,7 +1513,7 @@ namespace BizHawk.Client.EmuHawk VSControlsMenuItem.Enabled = VSSettingsMenuItem.Enabled = - ((Emulator is NES) && (Emulator as NES).IsVS); + Emulator is NES && ((NES)Emulator).IsVS; NESSoundChannelsMenuItem.Enabled = GlobalWin.Tools.IsAvailable(); MovieSettingsMenuItem.Enabled = Emulator is NES && !Global.MovieSession.Movie.IsActive; @@ -1548,7 +1546,7 @@ namespace BizHawk.Client.EmuHawk } } - private void NESPPUViewerMenuItem_Click(object sender, EventArgs e) + private void NesPPUViewerMenuItem_Click(object sender, EventArgs e) { GlobalWin.Tools.Load(); } @@ -1558,7 +1556,7 @@ namespace BizHawk.Client.EmuHawk GlobalWin.Tools.Load(); } - private void musicRipperToolStripMenuItem_Click(object sender, EventArgs e) + private void MusicRipperMenuItem_Click(object sender, EventArgs e) { GlobalWin.Tools.Load(); } @@ -1571,9 +1569,13 @@ namespace BizHawk.Client.EmuHawk private void NESGraphicSettingsMenuItem_Click(object sender, EventArgs e) { if (Emulator is NES) + { new NESGraphicsConfig().ShowDialog(this); + } else if (Emulator is QuickNES) + { new QuickNesConfig().ShowDialog(this); + } } private void NESSoundChannelsMenuItem_Click(object sender, EventArgs e) @@ -1581,9 +1583,9 @@ namespace BizHawk.Client.EmuHawk GlobalWin.Tools.Load(); } - private void VSSettingsMenuItem_Click(object sender, EventArgs e) + private void VsSettingsMenuItem_Click(object sender, EventArgs e) { - if (Emulator is NES && (Emulator as NES).IsVS) + if (Emulator is NES && ((NES)Emulator).IsVS) { new NESVSSettings().ShowHawkDialog(); } @@ -1598,9 +1600,9 @@ namespace BizHawk.Client.EmuHawk } } - private void VSInsertCoinP1MenuItem_Click(object sender, EventArgs e) + private void VsInsertCoinP1MenuItem_Click(object sender, EventArgs e) { - if (Emulator is NES && (Emulator as NES).IsVS) + if (Emulator is NES && ((NES)Emulator).IsVS) { if (!Global.MovieSession.Movie.IsPlaying || Global.MovieSession.Movie.IsFinished) { @@ -1610,9 +1612,9 @@ namespace BizHawk.Client.EmuHawk } } - private void VSInsertCoinP2MenuItem_Click(object sender, EventArgs e) + private void VsInsertCoinP2MenuItem_Click(object sender, EventArgs e) { - if (Emulator is NES && (Emulator as NES).IsVS) + if (Emulator is NES && ((NES)Emulator).IsVS) { if (!Global.MovieSession.Movie.IsPlaying || Global.MovieSession.Movie.IsFinished) { @@ -1622,9 +1624,9 @@ namespace BizHawk.Client.EmuHawk } } - private void VSServiceSwitchMenuItem_Click(object sender, EventArgs e) + private void VsServiceSwitchMenuItem_Click(object sender, EventArgs e) { - if (Emulator is NES && (Emulator as NES).IsVS) + if (Emulator is NES && ((NES)Emulator).IsVS) { if (!Global.MovieSession.Movie.IsPlaying || Global.MovieSession.Movie.IsFinished) { @@ -1637,9 +1639,13 @@ namespace BizHawk.Client.EmuHawk private void NesControllerSettingsMenuItem_Click(object sender, EventArgs e) { if (Emulator is NES) + { new NesControllerSettings().ShowDialog(); + } else if (Emulator is QuickNES) + { GenericCoreConfig.DoDialog(this, "QuickNES Controller Settings", true, false); + } } private void MovieSettingsMenuItem_Click(object sender, EventArgs e) @@ -1650,7 +1656,7 @@ namespace BizHawk.Client.EmuHawk } } - private void barcodeReaderToolStripMenuItem_Click(object sender, EventArgs e) + private void BarcodeReaderMenuItem_Click(object sender, EventArgs e) { GlobalWin.Tools.Load(); } @@ -1678,12 +1684,12 @@ namespace BizHawk.Client.EmuHawk } } - private void PCEGraphicsSettingsMenuItem_Click(object sender, EventArgs e) + private void PceGraphicsSettingsMenuItem_Click(object sender, EventArgs e) { new PCEGraphicsConfig().ShowDialog(); } - private void PCEBGViewerMenuItem_Click(object sender, EventArgs e) + private void PceBgViewerMenuItem_Click(object sender, EventArgs e) { GlobalWin.Tools.Load(); } @@ -1693,7 +1699,7 @@ namespace BizHawk.Client.EmuHawk GlobalWin.Tools.Load(); } - private void PceSoundDebuggerToolStripMenuItem_Click(object sender, EventArgs e) + private void PceSoundDebuggerMenuItem_Click(object sender, EventArgs e) { GlobalWin.Tools.Load(); } @@ -1807,14 +1813,14 @@ namespace BizHawk.Client.EmuHawk PutCoreSyncSettings(ss); } - private void SMS_BIOS_Click(object sender, EventArgs e) + private void SmsBiosMenuItem_Click(object sender, EventArgs e) { var ss = ((SMS)Emulator).GetSyncSettings(); ss.UseBIOS ^= true; PutCoreSyncSettings(ss); } - private void SMSEnableFMChipMenuItem_Click(object sender, EventArgs e) + private void SmsEnableFmChipMenuItem_Click(object sender, EventArgs e) { var ss = ((SMS)Emulator).GetSyncSettings(); ss.EnableFM ^= true; @@ -1921,7 +1927,7 @@ namespace BizHawk.Client.EmuHawk } catch (IOException ex) { - var Message = String.Format("Invalid file format. Reason: {0} \nForce transfer? This may cause the calculator to crash.", ex.Message); + var Message = $"Invalid file format. Reason: {ex.Message} \nForce transfer? This may cause the calculator to crash."; if (MessageBox.Show(Message, "Upload Failed", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes) { @@ -1947,11 +1953,6 @@ namespace BizHawk.Client.EmuHawk #region Atari - private void AtariSubMenu_DropDownOpened(object sender, EventArgs e) - { - - } - private void AtariSettingsToolStripMenuItem_Click(object sender, EventArgs e) { GenericCoreConfig.DoDialog(this, "Atari 2600 Settings"); @@ -1996,9 +1997,13 @@ namespace BizHawk.Client.EmuHawk { var gb = Emulator as Gameboy; if (gb.IsCGBMode()) + { CGBColorChooserForm.DoCGBColorChooserFormDialog(this); + } else + { ColorChooserForm.DoColorChooserFormDialog(this); + } } private void LoadGBInSGBMenuItem_Click(object sender, EventArgs e) @@ -2043,7 +2048,7 @@ namespace BizHawk.Client.EmuHawk GBAVBANextMenuItem.Checked = Global.Config.GBA_UsemGBA == false; } - private void gBAWithMGBAToolStripMenuItem_Click(object sender, EventArgs e) + private void GbaWithmGBAMenuItem_Click(object sender, EventArgs e) { Global.Config.GBA_UsemGBA ^= true; FlagNeedsReboot(); @@ -2146,12 +2151,12 @@ namespace BizHawk.Client.EmuHawk private void SnesObj1MenuItem_Click(object sender, EventArgs e) { - this.SNES_ToggleObj1(); + SNES_ToggleObj1(); } private void SnesObj2MenuItem_Click(object sender, EventArgs e) { - this.SNES_ToggleObj2(); + SNES_ToggleObj2(); } private void SnesObj3MenuItem_Click(object sender, EventArgs e) @@ -2228,9 +2233,6 @@ namespace BizHawk.Client.EmuHawk var s = ((N64)Emulator).GetSettings(); MupenStyleLagMenuItem.Checked = s.UseMupenStyleLag; - //var ss = (N64SyncSettings)Emulator.GetSyncSettings(); - //N64ExpansionSlotMenuItem.Checked = !ss.DisableExpansionSlot; - N64ExpansionSlotMenuItem.Checked = (Emulator as N64).UsingExpansionSlot; N64ExpansionSlotMenuItem.Enabled = !(Emulator as N64).IsOverridingUserExpansionSlotSetting; } @@ -2296,19 +2298,13 @@ namespace BizHawk.Client.EmuHawk private void SaturnPreferencesMenuItem_Click(object sender, EventArgs e) { GenericCoreConfig.DoDialog(this, "Saturn Settings"); - /* -- delete me, out of date - using (var dlg = new SaturnPrefs()) - { - dlg.ShowDialog(this); - } - * */ } #endregion #region DGB - private void DGBsettingsToolStripMenuItem_Click(object sender, EventArgs e) + private void DgbSettingsMenuItem_Click(object sender, EventArgs e) { config.GB.DGBPrefs.DoDGBPrefsDialog(this); } @@ -2345,7 +2341,7 @@ namespace BizHawk.Client.EmuHawk #region Apple II - private void settingsToolStripMenuItem1_Click_1(object sender, EventArgs e) + private void AppleIISettingsMenuItem_Click(object sender, EventArgs e) { GenericCoreConfig.DoDialog(this, "Apple II Settings"); } @@ -2354,7 +2350,7 @@ namespace BizHawk.Client.EmuHawk { if (Emulator is AppleII) { - AppleDisksSubMenu.Enabled = (Emulator as AppleII).DiskCount > 1; + AppleDisksSubMenu.Enabled = ((AppleII)Emulator).DiskCount > 1; } } @@ -2487,8 +2483,16 @@ namespace BizHawk.Client.EmuHawk OpenRomContextMenuItem.Visible = Emulator.IsNull() || _inFullscreen; bool showMenuVisible = _inFullscreen; - if (!MainMenuStrip.Visible) showMenuVisible = true; //need to always be able to restore this as an emergency measure - if (_chromeless) showMenuVisible = true; //I decided this was always possible in chromeless mode, we'll see what they think + if (!MainMenuStrip.Visible) + { + showMenuVisible = true; // need to always be able to restore this as an emergency measure + } + + if (_chromeless) + { + showMenuVisible = true; // I decided this was always possible in chromeless mode, we'll see what they think + } + ShowMenuContextMenuItem.Visible = ShowMenuContextMenuSeparator.Visible = showMenuVisible; @@ -2550,8 +2554,7 @@ namespace BizHawk.Client.EmuHawk PathManager.SaveStatePrefix(Global.Game) + ".QuickSave" + Global.Config.SaveSlot + - ".State.bak" - ); + ".State.bak"); if (file.Exists) { @@ -2592,9 +2595,15 @@ namespace BizHawk.Client.EmuHawk SavestateTextContextMenuItem.Checked = false; switch (Global.Config.SaveStateType) { - case Config.SaveStateTypeE.Binary: SavestateBinaryContextMenuItem.Checked = true; break; - case Config.SaveStateTypeE.Text: SavestateTextContextMenuItem.Checked = true; break; - case Config.SaveStateTypeE.Default: SavestateTypeDefaultContextMenuItem.Checked = true; break; + case Config.SaveStateTypeE.Binary: + SavestateBinaryContextMenuItem.Checked = true; + break; + case Config.SaveStateTypeE.Text: + SavestateTextContextMenuItem.Checked = true; + break; + case Config.SaveStateTypeE.Default: + SavestateTypeDefaultContextMenuItem.Checked = true; + break; } } @@ -2647,18 +2656,18 @@ namespace BizHawk.Client.EmuHawk private void AddSubtitleContextMenuItem_Click(object sender, EventArgs e) { - //TODO: rethink this? + // TODO: rethink this? var subForm = new SubtitleMaker(); subForm.DisableFrame(); int index = -1; var sub = new Subtitle(); - for (int x = 0; x < Global.MovieSession.Movie.Subtitles.Count; x++) + for (int i = 0; i < Global.MovieSession.Movie.Subtitles.Count; i++) { - sub = Global.MovieSession.Movie.Subtitles[x]; + sub = Global.MovieSession.Movie.Subtitles[i]; if (Emulator.Frame == sub.Frame) { - index = x; + index = i; break; } } @@ -2697,13 +2706,12 @@ namespace BizHawk.Client.EmuHawk PathManager.SaveStatePrefix(Global.Game) + ".QuickSave" + Global.Config.SaveSlot + - ".State" - ); + ".State"); GlobalWin.OSD.AddMessage("Save slot " + Global.Config.SaveSlot + " restored."); } - private void ClearSRAMContextMenuItem_Click(object sender, EventArgs e) + private void ClearSramContextMenuItem_Click(object sender, EventArgs e) { CloseRom(clearSram: true); } @@ -2721,7 +2729,7 @@ namespace BizHawk.Client.EmuHawk private void DumpStatusButton_Click(object sender, EventArgs e) { string details = Emulator.CoreComm.RomStatusDetails; - if (!String.IsNullOrEmpty(details)) + if (!string.IsNullOrEmpty(details)) { GlobalWin.Sound.StopSound(); LogWindow.ShowReport("Dump Status Report", details, this); @@ -2771,6 +2779,7 @@ namespace BizHawk.Client.EmuHawk Global.Config.Input_Hotkey_OverrideOptions = 0; break; } + UpdateKeyPriorityIcon(); } @@ -2784,8 +2793,8 @@ namespace BizHawk.Client.EmuHawk private void ProfileFirstBootLabel_Click(object sender, EventArgs e) { - //We do not check if the user is actually setting a profile here. - //This is intentional. + // We do not check if the user is actually setting a profile here. + // This is intentional. var profileForm = new ProfileConfig(); profileForm.ShowDialog(); Global.Config.FirstBoot = false; @@ -2802,7 +2811,12 @@ namespace BizHawk.Client.EmuHawk if (result == DialogResult.Yes) { - System.Threading.ThreadPool.QueueUserWorkItem((s) => { using (System.Diagnostics.Process.Start(VersionInfo.HomePage)) { } }); + System.Threading.ThreadPool.QueueUserWorkItem(s => + { + using (System.Diagnostics.Process.Start(VersionInfo.HomePage)) + { + } + }); } else if (result == DialogResult.No) { @@ -2835,6 +2849,7 @@ namespace BizHawk.Client.EmuHawk { _wasPaused = true; } + PauseEmulator(); } } @@ -2842,7 +2857,9 @@ namespace BizHawk.Client.EmuHawk private void timerMouseIdle_Tick(object sender, EventArgs e) { if (_inFullscreen && Global.Config.DispChrome_Fullscreen_AutohideMouse) + { AutohideCursor(true); + } } private void MainForm_Enter(object sender, EventArgs e) @@ -2866,8 +2883,7 @@ namespace BizHawk.Client.EmuHawk if (Global.Config.ShowContextMenu && e.Button == MouseButtons.Right) { MainFormContextMenu.Show( - PointToScreen(new Point(e.X, e.Y + MainformMenu.Height)) - ); + PointToScreen(new Point(e.X, e.Y + MainformMenu.Height))); } } @@ -2919,7 +2935,7 @@ namespace BizHawk.Client.EmuHawk { try { - FormDragDrop_internal(sender, e); + FormDragDrop_Internal(sender, e); } catch (Exception ex) { @@ -2927,7 +2943,7 @@ namespace BizHawk.Client.EmuHawk } } - private void FormDragDrop_internal(object sender, DragEventArgs e) + private void FormDragDrop_Internal(object sender, DragEventArgs e) { _FormDragDrop_internal(sender, e); /* diff --git a/BizHawk.Client.EmuHawk/MainForm.Hotkey.cs b/BizHawk.Client.EmuHawk/MainForm.Hotkey.cs index 6300f9ca54..47495147cb 100644 --- a/BizHawk.Client.EmuHawk/MainForm.Hotkey.cs +++ b/BizHawk.Client.EmuHawk/MainForm.Hotkey.cs @@ -43,9 +43,11 @@ namespace BizHawk.Client.EmuHawk case "Screen Raw to Clipboard": // Ctrl+C clash. any tool that has such acc must check this. // maybe check if mainform has focus instead? - if (GlobalWin.Tools.IsLoaded()) - if (GlobalWin.Tools.Get().ContainsFocus) - break; + if (GlobalWin.Tools.IsLoaded() && GlobalWin.Tools.Get().ContainsFocus) + { + break; + } + TakeScreenshotToClipboard(); break; case "Screen Client to Clipboard": @@ -67,7 +69,7 @@ namespace BizHawk.Client.EmuHawk FlushSaveRAM(); break; case "Display FPS": - ToggleFPS(); + ToggleFps(); break; case "Frame Counter": ToggleFrameCounter(); @@ -77,6 +79,7 @@ namespace BizHawk.Client.EmuHawk { ToggleLagCounter(); } + break; case "Input Display": ToggleInputDisplay(); @@ -341,9 +344,11 @@ namespace BizHawk.Client.EmuHawk { type = " (on)"; } + Global.CheatList.ToList().ForEach(x => x.Toggle()); GlobalWin.OSD.AddMessage("Cheats toggled" + type); } + break; case "TAStudio": GlobalWin.Tools.Load(); @@ -358,45 +363,93 @@ namespace BizHawk.Client.EmuHawk // RAM Search case "Do Search": if (GlobalWin.Tools.IsLoaded()) + { GlobalWin.Tools.RamSearch.DoSearch(); - else return false; + } + else + { + return false; + } + break; case "New Search": if (GlobalWin.Tools.IsLoaded()) + { GlobalWin.Tools.RamSearch.NewSearch(); - else return false; + } + else + { + return false; + } + break; case "Previous Compare To": if (GlobalWin.Tools.IsLoaded()) + { GlobalWin.Tools.RamSearch.NextCompareTo(reverse: true); - else return false; + } + else + { + return false; + } + break; case "Next Compare To": if (GlobalWin.Tools.IsLoaded()) + { GlobalWin.Tools.RamSearch.NextCompareTo(); - else return false; + } + else + { + return false; + } + break; case "Previous Operator": if (GlobalWin.Tools.IsLoaded()) + { GlobalWin.Tools.RamSearch.NextOperator(reverse: true); - else return false; + } + else + { + return false; + } + break; case "Next Operator": if (GlobalWin.Tools.IsLoaded()) + { GlobalWin.Tools.RamSearch.NextOperator(); - else return false; + } + else + { + return false; + } + break; - //TAStudio + // TAStudio case "Add Branch": if (GlobalWin.Tools.IsLoaded()) + { GlobalWin.Tools.TAStudio.AddBranchExternal(); - else return false; + } + else + { + return false; + } + break; case "Delete Branch": if (GlobalWin.Tools.IsLoaded()) + { GlobalWin.Tools.TAStudio.RemoveBranchExtrenal(); - else return false; + } + else + { + return false; + } + break; case "Show Cursor": if (GlobalWin.Tools.IsLoaded()) @@ -404,72 +457,154 @@ namespace BizHawk.Client.EmuHawk GlobalWin.Tools.TAStudio.SetVisibleIndex(); GlobalWin.Tools.TAStudio.RefreshDialog(); } - else return false; + else + { + return false; + } + break; case "Toggle Follow Cursor": if (GlobalWin.Tools.IsLoaded()) + { GlobalWin.Tools.TAStudio.TasPlaybackBox.FollowCursor ^= true; - else return false; + } + else + { + return false; + } + break; case "Toggle Auto-Restore": if (GlobalWin.Tools.IsLoaded()) + { GlobalWin.Tools.TAStudio.TasPlaybackBox.AutoRestore ^= true; - else return false; + } + else + { + return false; + } + break; case "Toggle Turbo Seek": if (GlobalWin.Tools.IsLoaded()) + { GlobalWin.Tools.TAStudio.TasPlaybackBox.TurboSeek ^= true; - else return false; + } + else + { + return false; + } + break; case "Clear Frames": if (GlobalWin.Tools.IsLoaded()) + { GlobalWin.Tools.TAStudio.ClearFramesExternal(); - else return false; + } + else + { + return false; + } + break; case "Insert Frame": if (GlobalWin.Tools.IsLoaded()) + { GlobalWin.Tools.TAStudio.InsertFrameExternal(); - else return false; + } + else + { + return false; + } + break; case "Delete Frames": if (GlobalWin.Tools.IsLoaded()) + { GlobalWin.Tools.TAStudio.DeleteFramesExternal(); - else return false; + } + else + { + return false; + } + break; case "Clone Frames": if (GlobalWin.Tools.IsLoaded()) + { GlobalWin.Tools.TAStudio.CloneFramesExternal(); - else return false; + } + else + { + return false; + } + break; case "Analog Increment": if (GlobalWin.Tools.IsLoaded()) + { GlobalWin.Tools.TAStudio.AnalogIncrementByOne(); - else return false; + } + else + { + return false; + } + break; case "Analog Decrement": if (GlobalWin.Tools.IsLoaded()) + { GlobalWin.Tools.TAStudio.AnalogDecrementByOne(); - else return false; + } + else + { + return false; + } + break; case "Analog Incr. by 10": if (GlobalWin.Tools.IsLoaded()) + { GlobalWin.Tools.TAStudio.AnalogIncrementByTen(); - else return false; + } + else + { + return false; + } + break; case "Analog Decr. by 10": if (GlobalWin.Tools.IsLoaded()) + { GlobalWin.Tools.TAStudio.AnalogDecrementByTen(); - else return false; + } + else + { + return false; + } + break; case "Analog Maximum": if (GlobalWin.Tools.IsLoaded()) + { GlobalWin.Tools.TAStudio.AnalogMax(); - else return false; + } + else + { + return false; + } + break; case "Analog Minimum": if (GlobalWin.Tools.IsLoaded()) + { GlobalWin.Tools.TAStudio.AnalogMin(); - else return false; + } + else + { + return false; + } + break; // SNES @@ -506,10 +641,10 @@ namespace BizHawk.Client.EmuHawk GlobalWin.Tools.VirtualPad.BumpAnalogValue(null, Global.Config.Analog_LargeChange); break; case "Y Down Small": - GlobalWin.Tools.VirtualPad.BumpAnalogValue(null, -(Global.Config.Analog_SmallChange)); + GlobalWin.Tools.VirtualPad.BumpAnalogValue(null, -Global.Config.Analog_SmallChange); break; case "Y Down Large": - GlobalWin.Tools.VirtualPad.BumpAnalogValue(null, -(Global.Config.Analog_LargeChange)); + GlobalWin.Tools.VirtualPad.BumpAnalogValue(null, -Global.Config.Analog_LargeChange); break; case "X Up Small": GlobalWin.Tools.VirtualPad.BumpAnalogValue(Global.Config.Analog_SmallChange, null); @@ -518,10 +653,10 @@ namespace BizHawk.Client.EmuHawk GlobalWin.Tools.VirtualPad.BumpAnalogValue(Global.Config.Analog_LargeChange, null); break; case "X Down Small": - GlobalWin.Tools.VirtualPad.BumpAnalogValue(-(Global.Config.Analog_SmallChange), null); + GlobalWin.Tools.VirtualPad.BumpAnalogValue(-Global.Config.Analog_SmallChange, null); break; case "X Down Large": - GlobalWin.Tools.VirtualPad.BumpAnalogValue(-(Global.Config.Analog_LargeChange), null); + GlobalWin.Tools.VirtualPad.BumpAnalogValue(-Global.Config.Analog_LargeChange, null); break; } diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index f7d677c842..b9aa1d8d70 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -18,17 +18,11 @@ using BizHawk.Bizware.BizwareGL; using BizHawk.Emulation.Common; using BizHawk.Emulation.Common.IEmulatorExtensions; -using BizHawk.Emulation.Cores.Atari.Atari2600; using BizHawk.Emulation.Cores.Calculators; using BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES; -using BizHawk.Emulation.Cores.Consoles.Sega.gpgx; -using BizHawk.Emulation.Cores.Nintendo.Gameboy; using BizHawk.Emulation.Cores.Nintendo.GBA; using BizHawk.Emulation.Cores.Nintendo.NES; using BizHawk.Emulation.Cores.Nintendo.SNES; -using BizHawk.Emulation.Cores.PCEngine; -using BizHawk.Emulation.Cores.Sega.MasterSystem; -using BizHawk.Emulation.DiscSystem; using BizHawk.Emulation.Cores.Nintendo.N64; using BizHawk.Client.EmuHawk.WinFormExtensions; @@ -60,7 +54,7 @@ namespace BizHawk.Client.EmuHawk LinkCableOn = Properties.Resources.connect_16x16; LinkCableOff = Properties.Resources.noconnect_16x16; UpdateCoreStatusBarButton(); - if (Global.Config.FirstBoot == true) + if (Global.Config.FirstBoot) { ProfileFirstBootLabel.Visible = true; } @@ -71,7 +65,11 @@ namespace BizHawk.Client.EmuHawk // New version notification UpdateChecker.CheckComplete += (s2, e2) => { - if (IsDisposed) return; + if (IsDisposed) + { + return; + } + this.BeginInvoke(() => { UpdateNotification.Visible = UpdateChecker.IsNewVersionAvailable; }); }; UpdateChecker.BeginCheck(); // Won't actually check unless enabled by user @@ -83,13 +81,15 @@ namespace BizHawk.Client.EmuHawk // its.. weird. dont ask. } - CoreComm CreateCoreComm() + private CoreComm CreateCoreComm() { - CoreComm ret = new CoreComm(ShowMessageCoreComm, NotifyCoreComm); - ret.ReleaseGLContext = (o) => GlobalWin.GLManager.ReleaseGLContext(o); - ret.RequestGLContext = (major,minor,forward) => GlobalWin.GLManager.CreateGLContext(major,minor,forward); - ret.ActivateGLContext = (gl) => GlobalWin.GLManager.Activate((GLManager.ContextRef)gl); - ret.DeactivateGLContext = () => GlobalWin.GLManager.Deactivate(); + CoreComm ret = new CoreComm(ShowMessageCoreComm, NotifyCoreComm) + { + ReleaseGLContext = o => GlobalWin.GLManager.ReleaseGLContext(o), + RequestGLContext = (major, minor, forward) => GlobalWin.GLManager.CreateGLContext(major, minor, forward), + ActivateGLContext = gl => GlobalWin.GLManager.Activate((GLManager.ContextRef)gl), + DeactivateGLContext = () => GlobalWin.GLManager.Deactivate() + }; return ret; } @@ -134,12 +134,16 @@ namespace BizHawk.Client.EmuHawk // we could background thread this later instead if we wanted to be real clever NES.BootGodDB.GetDatabaseBytes = () => { - string xmlPath = Path.Combine( PathManager.GetExeDirectoryAbsolute(), "gamedb", "NesCarts.xml" ); - string x7zPath = Path.Combine( PathManager.GetExeDirectoryAbsolute(), "gamedb", "NesCarts.7z" ); - bool loadXml = File.Exists( xmlPath ); + string xmlPath = Path.Combine(PathManager.GetExeDirectoryAbsolute(), "gamedb", "NesCarts.xml"); + string x7zPath = Path.Combine(PathManager.GetExeDirectoryAbsolute(), "gamedb", "NesCarts.7z"); + bool loadXml = File.Exists(xmlPath); using (var NesCartFile = new HawkFile(loadXml ? xmlPath : x7zPath)) { - if (!loadXml) { NesCartFile.BindFirst(); } + if (!loadXml) + { + NesCartFile.BindFirst(); + } + return NesCartFile .GetStream() .ReadAllBytes(); @@ -170,6 +174,7 @@ namespace BizHawk.Client.EmuHawk { cmdLoadSlot = arg.Substring(arg.IndexOf('=') + 1); } + if (arg.StartsWith("--load-state=")) { cmdLoadState = arg.Substring(arg.IndexOf('=') + 1); @@ -187,9 +192,12 @@ namespace BizHawk.Client.EmuHawk var list = arg.Substring(arg.IndexOf('=') + 1); var items = list.Split(','); _currAviWriterFrameList = new HashSet(); - for (int j = 0; j < items.Length; j++) - _currAviWriterFrameList.Add(int.Parse(items[j])); - //automatically set dump length to maximum frame + foreach (string item in items) + { + _currAviWriterFrameList.Add(int.Parse(item)); + } + + // automatically set dump length to maximum frame _autoDumpLength = _currAviWriterFrameList.OrderBy(x => x).Last(); } else if (arg.StartsWith("--dump-name=")) @@ -220,7 +228,7 @@ namespace BizHawk.Client.EmuHawk Database.LoadDatabase(Path.Combine(PathManager.GetExeDirectoryAbsolute(), "gamedb", "gamedb.txt")); - //TODO GL - a lot of disorganized wiring-up here + // TODO GL - a lot of disorganized wiring-up here CGC.CGCBinPath = Path.Combine(PathManager.GetDllDirectory(), "cgc.exe"); PresentationPanel = new PresentationPanel(); PresentationPanel.GraphicsControl.MainWindow = true; @@ -228,7 +236,7 @@ namespace BizHawk.Client.EmuHawk Controls.Add(PresentationPanel); Controls.SetChildIndex(PresentationPanel, 0); - //TODO GL - move these event handlers somewhere less obnoxious line in the On* overrides + // TODO GL - move these event handlers somewhere less obnoxious line in the On* overrides Load += (o, e) => { AllowDrop = true; @@ -240,11 +248,12 @@ namespace BizHawk.Client.EmuHawk { if (GlobalWin.Tools.AskSave()) { - //zero 03-nov-2015 - close game after other steps. tools might need to unhook themselves from a core. + // zero 03-nov-2015 - close game after other steps. tools might need to unhook themselves from a core. Global.MovieSession.Movie.Stop(); GlobalWin.Tools.Close(); CloseGame(); - //does this need to be last for any particular reason? do tool dialogs persist settings when closing? + + // does this need to be last for any particular reason? do tool dialogs persist settings when closing? SaveConfig(); } else @@ -292,17 +301,24 @@ namespace BizHawk.Client.EmuHawk Global.ActiveController = new Controller(NullController.Instance.Definition); Global.AutoFireController = AutofireNullControls; Global.AutofireStickyXORAdapter.SetOnOffPatternFromConfig(); - try { GlobalWin.Sound = new Sound(Handle); } + try + { + GlobalWin.Sound = new Sound(Handle); + } catch { string message = "Couldn't initialize sound device! Try changing the output method in Sound config."; if (Global.Config.SoundOutputMethod == Config.ESoundOutputMethod.DirectSound) + { message = "Couldn't initialize DirectSound! Things may go poorly for you. Try changing your sound driver to 44.1khz instead of 48khz in mmsys.cpl."; + } + MessageBox.Show(message, "Initialization Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Global.Config.SoundOutputMethod = Config.ESoundOutputMethod.Dummy; GlobalWin.Sound = new Sound(Handle); } + GlobalWin.Sound.StartSound(); InputManager.RewireInputChain(); GlobalWin.Tools = new ToolManager(this); @@ -327,7 +343,7 @@ namespace BizHawk.Client.EmuHawk if (cmdRom != null) { // Commandline should always override auto-load - LoadRom(cmdRom, new MainForm.LoadRomArgs() { OpenAdvanced = new OpenAdvanced_OpenRom() }); + LoadRom(cmdRom, new LoadRomArgs { OpenAdvanced = new OpenAdvanced_OpenRom() }); if (Global.Game == null) { MessageBox.Show("Failed to load " + cmdRom + " specified on commandline"); @@ -359,10 +375,10 @@ namespace BizHawk.Client.EmuHawk } // Copy pasta from drag & drop - string errorMsg; - string warningMsg; if (MovieImport.IsValidMovieExtension(Path.GetExtension(cmdMovie))) { + string errorMsg; + string warningMsg; var imported = MovieImport.ImportFile(cmdMovie, out errorMsg, out warningMsg); if (!string.IsNullOrEmpty(errorMsg)) { @@ -397,7 +413,6 @@ namespace BizHawk.Client.EmuHawk // If user picked a game, then do the autoload logic if (!Global.Game.IsNullInstance) { - if (File.Exists(Global.Config.RecentMovies.MostRecent)) { StartNewMovie(MovieService.Get(Global.Config.RecentMovies.MostRecent), false); @@ -461,7 +476,7 @@ namespace BizHawk.Client.EmuHawk PresentationPanel.Control.Paint += (o, e) => { - //I would like to trigger a repaint here, but this isnt done yet + // I would like to trigger a repaint here, but this isnt done yet }; } @@ -469,19 +484,19 @@ namespace BizHawk.Client.EmuHawk public int ProgramRunLoop() { - CheckMessages(); //can someone leave a note about why this is needed? + CheckMessages(); // can someone leave a note about why this is needed? LogConsole.PositionConsole(); - //needs to be done late, after the log console snaps on top - //fullscreen should snap on top even harder! + // needs to be done late, after the log console snaps on top + // fullscreen should snap on top even harder! if (_needsFullscreenOnLoad) { _needsFullscreenOnLoad = false; ToggleFullscreen(); } - //incantation required to get the program reliably on top of the console window - //we might want it in ToggleFullscreen later, but here, it needs to happen regardless + // incantation required to get the program reliably on top of the console window + // we might want it in ToggleFullscreen later, but here, it needs to happen regardless BringToFront(); Activate(); BringToFront(); @@ -539,6 +554,7 @@ namespace BizHawk.Client.EmuHawk { break; } + if (Global.Config.DispSpeedupFeatures != 0) { Thread.Sleep(0); @@ -555,17 +571,16 @@ namespace BizHawk.Client.EmuHawk /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { - //NOTE: this gets called twice sometimes. once by using() in Program.cs and once from winforms internals when the form is closed... - + // NOTE: this gets called twice sometimes. once by using() in Program.cs and once from winforms internals when the form is closed... if (GlobalWin.DisplayManager != null) { GlobalWin.DisplayManager.Dispose(); GlobalWin.DisplayManager = null; } - if (disposing && (components != null)) + if (disposing) { - components.Dispose(); + components?.Dispose(); } base.Dispose(disposing); @@ -591,10 +606,7 @@ namespace BizHawk.Client.EmuHawk } _emulatorPaused = value; - if (OnPauseChanged != null) - { - OnPauseChanged(this, new PauseChangedEventArgs(_emulatorPaused)); - } + OnPauseChanged?.Invoke(this, new PauseChangedEventArgs(_emulatorPaused)); } } @@ -615,25 +627,29 @@ namespace BizHawk.Client.EmuHawk #region Properties - public string CurrentlyOpenRom; //todo - delete me and use only args instead - public LoadRomArgs CurrentlyOpenRomArgs; - public bool PauseAVI = false; - public bool PressFrameAdvance = false; - public bool HoldFrameAdvance = false; // necessary for tastudio > button - public bool PressRewind = false; // necessary for tastudio < button - public bool FastForward = false; - public bool TurboFastForward = false; - public bool RestoreReadWriteOnStop = false; + public string CurrentlyOpenRom { get; set; } // todo - delete me and use only args instead + public LoadRomArgs CurrentlyOpenRomArgs { get; set; } + public bool PauseAVI { get; set; } + public bool PressFrameAdvance { get; set; } + public bool HoldFrameAdvance { get; set; } // necessary for tastudio > button + public bool PressRewind { get; set; } // necessary for tastudio < button + public bool FastForward { get; set; } + public bool TurboFastForward { get; set; } + public bool RestoreReadWriteOnStop { get; set; } - //runloop won't exec lua - public bool SuppressLua; + // runloop won't exec lua + public bool SuppressLua { get; set; } - public long MouseWheelTracker; + public long MouseWheelTracker { get; set; } private int? _pauseOnFrame; public int? PauseOnFrame // If set, upon completion of this frame, the client wil pause { - get { return _pauseOnFrame; } + get + { + return _pauseOnFrame; + } + set { _pauseOnFrame = value; @@ -648,26 +664,11 @@ namespace BizHawk.Client.EmuHawk } } - public bool IsSeeking - { - get { return PauseOnFrame.HasValue; } - } + public bool IsSeeking => PauseOnFrame.HasValue; - public bool IsTurboSeeking - { - get - { - return PauseOnFrame.HasValue && Global.Config.TurboSeek; - } - } + public bool IsTurboSeeking => PauseOnFrame.HasValue && Global.Config.TurboSeek; - public bool IsTurboing - { - get - { - return Global.ClientControls["Turbo"] || IsTurboSeeking; - } - } + public bool IsTurboing => Global.ClientControls["Turbo"] || IsTurboSeeking; #endregion @@ -693,7 +694,7 @@ namespace BizHawk.Client.EmuHawk /// /// Controls whether the app generates input events. should be turned off for most modal dialogs /// - public bool AllowInput(bool yield_alt) + public bool AllowInput(bool yieldAlt) { // the main form gets input if (ActiveForm == this) @@ -701,21 +702,27 @@ namespace BizHawk.Client.EmuHawk return true; } - //even more special logic for TAStudio: - //TODO - implement by event filter in TAStudio + // even more special logic for TAStudio: + // TODO - implement by event filter in TAStudio if (ActiveForm is TAStudio) { - if(yield_alt) return false; - var ts = ActiveForm as TAStudio; - if(ts.IsInMenuLoop) + if (yieldAlt) + { return false; + } + + var ts = ActiveForm as TAStudio; + if (ts.IsInMenuLoop) + { + return false; + } } // modals that need to capture input for binding purposes get input, of course - if (ActiveForm is HotkeyConfig || - ActiveForm is ControllerConfig || - ActiveForm is TAStudio || - ActiveForm is VirtualpadTool) + if (ActiveForm is HotkeyConfig + || ActiveForm is ControllerConfig + || ActiveForm is TAStudio + || ActiveForm is VirtualpadTool) { return true; } @@ -731,9 +738,13 @@ namespace BizHawk.Client.EmuHawk // TODO: make this an actual property, set it when loading a Rom, and pass it dialogs, etc // This is a quick hack to reduce the dependency on Global.Emulator - public IEmulator Emulator + private IEmulator Emulator { - get { return Global.Emulator; } + get + { + return Global.Emulator; + } + set { Global.Emulator = value; @@ -758,16 +769,18 @@ namespace BizHawk.Client.EmuHawk base.OnDeactivate(e); } - public void ProcessInput() + private void ProcessInput() { - ControllerInputCoalescer conInput = Global.ControllerInputCoalescer as ControllerInputCoalescer; + ControllerInputCoalescer conInput = (ControllerInputCoalescer)Global.ControllerInputCoalescer; for (;;) { - // loop through all available events var ie = Input.Instance.DequeueEvent(); - if (ie == null) { break; } + if (ie == null) + { + break; + } // useful debugging: // Console.WriteLine(ie); @@ -789,6 +802,7 @@ namespace BizHawk.Client.EmuHawk SendAltKeyChar(c); } } + if (ie.LogicalButton.Alt && ie.LogicalButton.Button == "Space") { SendPlainAltKey(32); @@ -838,6 +852,7 @@ namespace BizHawk.Client.EmuHawk HotkeyCoalescer.Receive(ie); } } + break; case 2: // Hotkeys override Input handled = false; @@ -852,7 +867,7 @@ namespace BizHawk.Client.EmuHawk HotkeyCoalescer.Receive(ie); // Check for hotkeys that may not be handled through Checkhotkey() method, reject controller input mapped to these - if (!triggers.Any(trigger => IsInternalHotkey(trigger))) + if (!triggers.Any(IsInternalHotkey)) { conInput.Receive(ie); } @@ -860,7 +875,6 @@ namespace BizHawk.Client.EmuHawk break; } - } // foreach event // also handle floats @@ -871,14 +885,14 @@ namespace BizHawk.Client.EmuHawk { var P = GlobalWin.DisplayManager.UntransformPoint(new Point((int)o.Item2, 0)); float x = P.X / (float)_currentVideoProvider.BufferWidth; - return new Tuple("WMouse X", x * 20000 - 10000); + return new Tuple("WMouse X", (x * 20000) - 10000); } if (o.Item1 == "WMouse Y") { var P = GlobalWin.DisplayManager.UntransformPoint(new Point(0, (int)o.Item2)); float y = P.Y / (float)_currentVideoProvider.BufferHeight; - return new Tuple("WMouse Y", y * 20000 - 10000); + return new Tuple("WMouse Y", (y * 20000) - 10000); } return o; @@ -889,9 +903,13 @@ namespace BizHawk.Client.EmuHawk { var ioa = OpenAdvancedSerializer.ParseWithLegacy(CurrentlyOpenRomPoopForAdvancedLoaderPleaseRefactorME); if (ioa is OpenAdvanced_LibretroNoGame) + { LoadRom("", CurrentlyOpenRomArgs); + } else + { LoadRom(ioa.SimplePath, CurrentlyOpenRomArgs); + } } public void PauseEmulator() @@ -935,7 +953,9 @@ namespace BizHawk.Client.EmuHawk using (var bb = Global.Config.Screenshot_CaptureOSD ? CaptureOSD() : MakeScreenshotImage()) { using (var img = bb.ToSysdrawingBitmap()) + { Clipboard.SetImage(img); + } } GlobalWin.OSD.AddMessage("Screenshot (raw) saved to clipboard."); @@ -946,7 +966,9 @@ namespace BizHawk.Client.EmuHawk using (var bb = GlobalWin.DisplayManager.RenderOffscreen(_currentVideoProvider, Global.Config.Screenshot_CaptureOSD)) { using (var img = bb.ToSysdrawingBitmap()) + { Clipboard.SetImage(img); + } } GlobalWin.OSD.AddMessage("Screenshot (client) saved to clipboard."); @@ -958,20 +980,28 @@ namespace BizHawk.Client.EmuHawk string prefix = PathManager.ScreenshotPrefix(Global.Game); var ts = DateTime.Now; - string fname_bare = string.Format(fmt, prefix, ts, ""); + string fnameBare = string.Format(fmt, prefix, ts, ""); string fname = string.Format(fmt, prefix, ts, " (0)"); - //if the (0) filename exists, do nothing. we'll bump up the number later - //if the bare filename exists, move it to (0) - //otherwise, no related filename exists, and we can proceed with the bare filename - if (File.Exists(fname)) { } - else if (File.Exists(fname_bare)) - File.Move(fname_bare, fname); - else fname = fname_bare; + // if the (0) filename exists, do nothing. we'll bump up the number later + // if the bare filename exists, move it to (0) + // otherwise, no related filename exists, and we can proceed with the bare filename + if (File.Exists(fname)) + { + } + else if (File.Exists(fnameBare)) + { + File.Move(fnameBare, fname); + } + else + { + fname = fnameBare; + } + int seq = 0; while (File.Exists(fname)) { - var sequence = string.Format(" ({0})", seq++); + var sequence = $" ({seq++})"; fname = string.Format(fmt, prefix, ts, sequence); } @@ -989,15 +1019,17 @@ namespace BizHawk.Client.EmuHawk using (var bb = Global.Config.Screenshot_CaptureOSD ? CaptureOSD() : MakeScreenshotImage()) { using (var img = bb.ToSysdrawingBitmap()) + { img.Save(fi.FullName, ImageFormat.Png); + } } + /* using (var fs = new FileStream(path + "_test.bmp", FileMode.OpenOrCreate, FileAccess.Write)) QuickBmpFile.Save(Emulator.VideoProvider(), fs, r.Next(50, 500), r.Next(50, 500)); */ GlobalWin.OSD.AddMessage(fi.Name + " saved."); } - //static Random r = new Random(); public void FrameBufferResized() { @@ -1015,16 +1047,17 @@ namespace BizHawk.Client.EmuHawk for (; zoom >= 1; zoom--) { lastComputedSize = GlobalWin.DisplayManager.CalculateClientSize(_currentVideoProvider, zoom); - if ((((lastComputedSize.Width) + borderWidth) < area.Width) - && (((lastComputedSize.Height) + borderHeight) < area.Height)) + if (lastComputedSize.Width + borderWidth < area.Width + && lastComputedSize.Height + borderHeight < area.Height) { break; } } - Console.WriteLine("Selecting display size " + lastComputedSize.ToString()); + + Console.WriteLine("Selecting display size " + lastComputedSize); // Change size - Size = new Size((lastComputedSize.Width) + borderWidth, ((lastComputedSize.Height) + borderHeight)); + Size = new Size(lastComputedSize.Width + borderWidth, lastComputedSize.Height + borderHeight); PerformLayout(); PresentationPanel.Resized = true; @@ -1044,16 +1077,13 @@ namespace BizHawk.Client.EmuHawk } } - public bool IsInFullscreen - { - get { return _inFullscreen; } - } + public bool IsInFullscreen => _inFullscreen; public void SynchChrome() { if (_inFullscreen) { - //TODO - maybe apply a hack tracked during fullscreen here to override it + // TODO - maybe apply a hack tracked during fullscreen here to override it FormBorderStyle = FormBorderStyle.None; MainMenuStrip.Visible = Global.Config.DispChrome_MenuFullscreen && !_chromeless; MainStatusBar.Visible = Global.Config.DispChrome_StatusBarFullscreen && !_chromeless; @@ -1064,11 +1094,17 @@ namespace BizHawk.Client.EmuHawk MainMenuStrip.Visible = Global.Config.DispChrome_MenuWindowed && !_chromeless; MaximizeBox = MinimizeBox = Global.Config.DispChrome_CaptionWindowed && !_chromeless; if (Global.Config.DispChrome_FrameWindowed == 0 || _chromeless) - FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + { + FormBorderStyle = FormBorderStyle.None; + } else if (Global.Config.DispChrome_FrameWindowed == 1) - FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow; + { + FormBorderStyle = FormBorderStyle.SizableToolWindow; + } else if (Global.Config.DispChrome_FrameWindowed == 2) - FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable; + { + FormBorderStyle = FormBorderStyle.Sizable; + } } } @@ -1076,24 +1112,26 @@ namespace BizHawk.Client.EmuHawk { AutohideCursor(false); - //prohibit this operation if the current controls include LMouse + // prohibit this operation if the current controls include LMouse if (allowSuppress) { if (Global.ActiveController.HasBinding("WMouse L")) + { return; + } } if (!_inFullscreen) { SuspendLayout(); #if WINDOWS - //Work around an AMD driver bug in >= vista: - //It seems windows will activate opengl fullscreen mode when a GL control is occupying the exact space of a screen (0,0 and dimensions=screensize) - //AMD cards manifest a problem under these circumstances, flickering other monitors. - //It isnt clear whether nvidia cards are failing to employ this optimization, or just not flickering. - //(this could be determined with more work; other side affects of the fullscreen mode include: corrupted taskbar, no modal boxes on top of GL control, no screenshots) - //At any rate, we can solve this by adding a 1px black border around the GL control - //Please note: It is important to do this before resizing things, otherwise momentarily a GL control without WS_BORDER will be at the magic dimensions and cause the flakeout + // Work around an AMD driver bug in >= vista: + // It seems windows will activate opengl fullscreen mode when a GL control is occupying the exact space of a screen (0,0 and dimensions=screensize) + // AMD cards manifest a problem under these circumstances, flickering other monitors. + // It isnt clear whether nvidia cards are failing to employ this optimization, or just not flickering. + // (this could be determined with more work; other side affects of the fullscreen mode include: corrupted taskbar, no modal boxes on top of GL control, no screenshots) + // At any rate, we can solve this by adding a 1px black border around the GL control + // Please note: It is important to do this before resizing things, otherwise momentarily a GL control without WS_BORDER will be at the magic dimensions and cause the flakeout if (Global.Config.DispFullscreenHacks && Global.Config.DispMethod == Config.EDispMethod.OpenGL) { //ATTENTION: this causes the statusbar to not work well, since the backcolor is now set to black instead of SystemColors.Control. @@ -1102,8 +1140,8 @@ namespace BizHawk.Client.EmuHawk Padding = new Padding(1); BackColor = Color.Black; - //FUTURE WORK: - //re-add this padding back into the display manager (so the image will get cut off a little but, but a few more resolutions will fully fit into the screen) + // FUTURE WORK: + // re-add this padding back into the display manager (so the image will get cut off a little but, but a few more resolutions will fully fit into the screen) } #endif @@ -1111,7 +1149,7 @@ namespace BizHawk.Client.EmuHawk _inFullscreen = true; SynchChrome(); - WindowState = FormWindowState.Maximized; //be sure to do this after setting the chrome, otherwise it wont work fully + WindowState = FormWindowState.Maximized; // be sure to do this after setting the chrome, otherwise it wont work fully ResumeLayout(); PresentationPanel.Resized = true; @@ -1123,10 +1161,10 @@ namespace BizHawk.Client.EmuHawk WindowState = FormWindowState.Normal; #if WINDOWS - //do this even if DispFullscreenHacks arent enabled, to restore it in case it changed underneath us or something + // do this even if DispFullscreenHacks arent enabled, to restore it in case it changed underneath us or something Padding = new Padding(0); - //it's important that we set the form color back to this, because the statusbar icons blend onto the mainform, not onto the statusbar-- - //so we need the statusbar and mainform backdrop color to match + // it's important that we set the form color back to this, because the statusbar icons blend onto the mainform, not onto the statusbar-- + // so we need the statusbar and mainform backdrop color to match BackColor = SystemColors.Control; #endif @@ -1140,7 +1178,7 @@ namespace BizHawk.Client.EmuHawk } } - public void OpenLuaConsole() + private void OpenLuaConsole() { #if WINDOWS GlobalWin.Tools.Load(); @@ -1176,14 +1214,26 @@ namespace BizHawk.Client.EmuHawk _unthrottled = false; } - void ThrottleMessage() + private void ThrottleMessage() { string ttype = ":(none)"; - if (Global.Config.SoundThrottle) { ttype = ":Sound"; } - if (Global.Config.VSyncThrottle) { ttype = string.Format(":Vsync{0}", Global.Config.VSync ? "[ena]" : "[dis]"); } - if (Global.Config.ClockThrottle) { ttype = ":Clock"; } + if (Global.Config.SoundThrottle) + { + ttype = ":Sound"; + } + + if (Global.Config.VSyncThrottle) + { + ttype = $":Vsync{(Global.Config.VSync ? "[ena]" : "[dis]")}"; + } + + if (Global.Config.ClockThrottle) + { + ttype = ":Clock"; + } + string xtype = _unthrottled ? "Unthrottled" : "Throttled"; - string msg = string.Format("{0}{1} ", xtype, ttype); + string msg = $"{xtype}{ttype} "; GlobalWin.OSD.AddMessage(msg); } @@ -1209,13 +1259,16 @@ namespace BizHawk.Client.EmuHawk } } - private LibsnesCore AsSNES { get { return Emulator as LibsnesCore; } } + private LibsnesCore AsSNES => Emulator as LibsnesCore; // TODO: Clean Me! - - public void SNES_ToggleBG1(bool? setto = null) + private void SNES_ToggleBG1(bool? setto = null) { - if (!(Emulator is LibsnesCore)) return; + if (!(Emulator is LibsnesCore)) + { + return; + } + var s = AsSNES.GetSettings(); if (setto.HasValue) { @@ -1230,9 +1283,13 @@ namespace BizHawk.Client.EmuHawk GlobalWin.OSD.AddMessage(s.ShowBG1_1 ? "BG 1 Layer On" : "BG 1 Layer Off"); } - public void SNES_ToggleBG2(bool? setto = null) + private void SNES_ToggleBG2(bool? setto = null) { - if (!(Emulator is LibsnesCore)) return; + if (!(Emulator is LibsnesCore)) + { + return; + } + var s = AsSNES.GetSettings(); if (setto.HasValue) { @@ -1247,9 +1304,13 @@ namespace BizHawk.Client.EmuHawk GlobalWin.OSD.AddMessage(s.ShowBG2_1 ? "BG 2 Layer On" : "BG 2 Layer Off"); } - public void SNES_ToggleBG3(bool? setto = null) + private void SNES_ToggleBG3(bool? setto = null) { - if (!(Emulator is LibsnesCore)) return; + if (!(Emulator is LibsnesCore)) + { + return; + } + var s = AsSNES.GetSettings(); if (setto.HasValue) { @@ -1266,7 +1327,11 @@ namespace BizHawk.Client.EmuHawk public void SNES_ToggleBG4(bool? setto = null) { - if (!(Emulator is LibsnesCore)) return; + if (!(Emulator is LibsnesCore)) + { + return; + } + var s = AsSNES.GetSettings(); if (setto.HasValue) { @@ -1281,9 +1346,13 @@ namespace BizHawk.Client.EmuHawk GlobalWin.OSD.AddMessage(s.ShowBG4_1 ? "BG 4 Layer On" : "BG 4 Layer Off"); } - public void SNES_ToggleObj1(bool? setto = null) + private void SNES_ToggleObj1(bool? setto = null) { - if (!(Emulator is LibsnesCore)) return; + if (!(Emulator is LibsnesCore)) + { + return; + } + var s = AsSNES.GetSettings(); if (setto.HasValue) { @@ -1298,9 +1367,13 @@ namespace BizHawk.Client.EmuHawk GlobalWin.OSD.AddMessage(s.ShowOBJ_0 ? "OBJ 1 Layer On" : "OBJ 1 Layer Off"); } - public void SNES_ToggleObj2(bool? setto = null) + private void SNES_ToggleObj2(bool? setto = null) { - if (!(Emulator is LibsnesCore)) return; + if (!(Emulator is LibsnesCore)) + { + return; + } + var s = AsSNES.GetSettings(); if (setto.HasValue) { @@ -1314,9 +1387,13 @@ namespace BizHawk.Client.EmuHawk GlobalWin.OSD.AddMessage(s.ShowOBJ_1 ? "OBJ 2 Layer On" : "OBJ 2 Layer Off"); } - public void SNES_ToggleOBJ3(bool? setto = null) + private void SNES_ToggleOBJ3(bool? setto = null) { - if (!(Emulator is LibsnesCore)) return; + if (!(Emulator is LibsnesCore)) + { + return; + } + var s = AsSNES.GetSettings(); if (setto.HasValue) { @@ -1331,9 +1408,13 @@ namespace BizHawk.Client.EmuHawk GlobalWin.OSD.AddMessage(s.ShowOBJ_2 ? "OBJ 3 Layer On" : "OBJ 3 Layer Off"); } - public void SNES_ToggleOBJ4(bool? setto = null) + private void SNES_ToggleOBJ4(bool? setto = null) { - if (!(Emulator is LibsnesCore)) return; + if (!(Emulator is LibsnesCore)) + { + return; + } + var s = AsSNES.GetSettings(); if (setto.HasValue) { @@ -1370,7 +1451,9 @@ namespace BizHawk.Client.EmuHawk ofd.Filter = "Libretro Cores (*.dll)|*.dll"; if (ofd.ShowDialog() == DialogResult.Cancel) + { return false; + } Global.Config.LibretroCore = ofd.FileName; @@ -1433,7 +1516,7 @@ namespace BizHawk.Client.EmuHawk private readonly bool _autoCloseOnDump; private int _lastOpenRomFilter; - //chrome is never shown, even in windowed mode + // chrome is never shown, even in windowed mode private readonly bool _chromeless; // Resources @@ -1472,7 +1555,7 @@ namespace BizHawk.Client.EmuHawk str += $"({size.Width}x{size.Height})={AR} - "; } - //we need to display FPS somewhere, in this case + // we need to display FPS somewhere, in this case if (Global.Config.DispSpeedupFeatures == 0) { str += $"({_lastFps:0} fps) - "; @@ -1603,7 +1686,7 @@ namespace BizHawk.Client.EmuHawk // GBA meteor core might not know how big the saveram ought to be, so just send it the whole file // GBA vba-next core will try to eat anything, regardless of size - if (Emulator is GBA || Emulator is VBANext || Emulator is MGBAHawk) + if (Emulator is VBANext || Emulator is MGBAHawk) { sram = File.ReadAllBytes(PathManager.SaveRamPath(Global.Game)); } @@ -1617,6 +1700,7 @@ namespace BizHawk.Client.EmuHawk // MessageBox.Show("Error: tried to load saveram, but core would not accept it?"); return; } + // why do we silently truncate\pad here instead of warning\erroring? sram = new byte[oldram.Length]; using (var reader = new BinaryReader( @@ -1661,9 +1745,11 @@ namespace BizHawk.Client.EmuHawk var writer = new BinaryWriter(new FileStream(path, FileMode.Create, FileAccess.Write)); var saveram = Emulator.AsSaveRam().CloneSaveRam(); - + if (saveram != null) + { writer.Write(saveram, 0, saveram.Length); + } writer.Close(); } @@ -1690,12 +1776,7 @@ namespace BizHawk.Client.EmuHawk var system = ""; if (!Global.Game.IsNullInstance) { - //New Code - //We use SystemID as that has the system we are playing on. system = Emulator.SystemId; - //Old Code below. - //system = Global.Game.System; - } TI83SubMenu.Visible = false; @@ -1763,20 +1844,14 @@ namespace BizHawk.Client.EmuHawk // TODO: fix SNES9x here if (Emulator is LibsnesCore) { - if ((Emulator as LibsnesCore).IsSGB) - { - SNESSubMenu.Text = "&SGB"; - } - else - { - SNESSubMenu.Text = "&SNES"; - } + SNESSubMenu.Text = ((LibsnesCore)Emulator).IsSGB ? "&SGB" : "&SNES"; SNESSubMenu.Visible = true; } else { SNESSubMenu.Visible = false; } + break; case "Coleco": ColecoSubMenu.Visible = true; @@ -1843,12 +1918,12 @@ namespace BizHawk.Client.EmuHawk var ioa = OpenAdvancedSerializer.ParseWithLegacy(rom); - LoadRomArgs args = new LoadRomArgs() + var args = new LoadRomArgs { OpenAdvanced = ioa }; - //if(ioa is this or that) - for more complex behaviour + // if(ioa is this or that) - for more complex behaviour string romPath = ioa.SimplePath; if (!LoadRom(romPath, args)) @@ -1894,7 +1969,6 @@ namespace BizHawk.Client.EmuHawk // skips outputting the audio. There's also a third way which is when no throttle // method is selected, but the clock throttle determines that by itself and // everything appears normal here. - var rewind = Global.Rewinder.RewindActive && (Global.ClientControls["Rewind"] || PressRewind); var fastForward = Global.ClientControls["Fast Forward"] || FastForward; var turbo = IsTurboing; @@ -1912,7 +1986,8 @@ namespace BizHawk.Client.EmuHawk _throttle.SetCoreFps(Emulator.VsyncRate()); _throttle.signal_paused = EmulatorPaused; _throttle.signal_unthrottle = _unthrottled || turbo; - //zero 26-mar-2016 - vsync and vsync throttle here both is odd, but see comments elsewhere about triple buffering + + // zero 26-mar-2016 - vsync and vsync throttle here both is odd, but see comments elsewhere about triple buffering _throttle.signal_overrideSecondaryThrottle = (fastForward || rewind) && (Global.Config.SoundThrottle || Global.Config.VSyncThrottle || Global.Config.VSync); _throttle.SetSpeedPercent(speedPercent); } @@ -1949,15 +2024,16 @@ namespace BizHawk.Client.EmuHawk } } - void AutohideCursor(bool hide) + private void AutohideCursor(bool hide) { if (hide && !_cursorHidden) { if (_blankCursor == null) { - var ms = new System.IO.MemoryStream(BizHawk.Client.EmuHawk.Properties.Resources.BlankCursor); + var ms = new MemoryStream(Properties.Resources.BlankCursor); _blankCursor = new Cursor(ms); } + PresentationPanel.Control.Cursor = _blankCursor; _cursorHidden = true; } @@ -1989,9 +2065,8 @@ namespace BizHawk.Client.EmuHawk { return; } - //private Size _lastVideoSize = new Size(-1, -1), _lastVirtualSize = new Size(-1, -1); + var video = _currentVideoProvider; - //bool change = false; Size currVideoSize = new Size(video.BufferWidth, video.BufferHeight); Size currVirtualSize = new Size(video.VirtualWidth, video.VirtualHeight); if (currVideoSize != _lastVideoSize || currVirtualSize != _lastVirtualSize) @@ -2028,7 +2103,7 @@ namespace BizHawk.Client.EmuHawk var num = args.Length / 2; for (int i = 0; i < num; i++) { - sb.AppendFormat("{0} ({1})|{1}", args[i * 2], args[i * 2 + 1]); + sb.AppendFormat("{0} ({1})|{1}", args[i * 2], args[(i * 2) + 1]); if (i != num - 1) { sb.Append('|'); @@ -2146,8 +2221,7 @@ namespace BizHawk.Client.EmuHawk "No sync settings found, using currently configured settings for this core.", "No sync settings found", MessageBoxButtons.OK, - MessageBoxIcon.Warning - ); + MessageBoxIcon.Warning); } } } @@ -2155,7 +2229,6 @@ namespace BizHawk.Client.EmuHawk { e.Settings = Global.Config.GetCoreSyncSettings(e.Core); } - } private static void CoreSettings(object sender, RomLoader.SettingsLoadArgs e) @@ -2217,12 +2290,14 @@ namespace BizHawk.Client.EmuHawk } if (string.IsNullOrEmpty(path)) + { path = PathManager.DefaultIniPath; + } ConfigService.Save(path, Global.Config); } - private static void ToggleFPS() + private static void ToggleFps() { Global.Config.DisplayFPS ^= true; } @@ -2257,7 +2332,6 @@ namespace BizHawk.Client.EmuHawk Global.Config.SoundVolume = 100; } - //GlobalWin.Sound.ApplyVolumeSettings(); GlobalWin.OSD.AddMessage("Volume " + Global.Config.SoundVolume); } @@ -2269,7 +2343,6 @@ namespace BizHawk.Client.EmuHawk Global.Config.SoundVolume = 0; } - //GlobalWin.Sound.ApplyVolumeSettings(); GlobalWin.OSD.AddMessage("Volume " + Global.Config.SoundVolume); } @@ -2647,8 +2720,7 @@ namespace BizHawk.Client.EmuHawk private static void VsyncMessage() { GlobalWin.OSD.AddMessage( - "Display Vsync set to " + (Global.Config.VSync ? "on" : "off") - ); + "Display Vsync set to " + (Global.Config.VSync ? "on" : "off")); } private static bool StateErrorAskUser(string title, string message) @@ -2657,8 +2729,7 @@ namespace BizHawk.Client.EmuHawk message, title, MessageBoxButtons.YesNo, - MessageBoxIcon.Question - ); + MessageBoxIcon.Question); return result == DialogResult.Yes; } @@ -2678,14 +2749,14 @@ namespace BizHawk.Client.EmuHawk }); } - private const int WM_DEVICECHANGE = 0x0219; + private const int WmDevicechange = 0x0219; // Alt key hacks protected override void WndProc(ref Message m) { switch (m.Msg) { - case WM_DEVICECHANGE: + case WmDevicechange: GamePad.Initialize(); GamePad360.Initialize(); break; @@ -2806,6 +2877,7 @@ namespace BizHawk.Client.EmuHawk if (Global.ClientControls["Frame Advance"] || PressFrameAdvance || HoldFrameAdvance) { _runloopFrameAdvance = true; + // handle the initial trigger of a frame advance if (_frameAdvanceTimestamp == 0) { @@ -2855,6 +2927,7 @@ namespace BizHawk.Client.EmuHawk { InitializeFpsData(); } + _lastFastForwardingOrRewinding = isFastForwardingOrRewinding; // client input-related duties @@ -2862,7 +2935,7 @@ namespace BizHawk.Client.EmuHawk Global.CheatList.Pulse(); - //zero 03-may-2014 - moved this before call to UpdateToolsBefore(), since it seems to clear the state which a lua event.framestart is going to want to alter + // zero 03-may-2014 - moved this before call to UpdateToolsBefore(), since it seems to clear the state which a lua event.framestart is going to want to alter Global.ClickyVirtualPadController.FrameTick(); Global.LuaAndAdaptor.FrameTick(); @@ -2894,9 +2967,13 @@ namespace BizHawk.Client.EmuHawk if (isFastForwardingOrRewinding) { if (Global.Config.SoundEnabledRWFF) + { atten *= Global.Config.SoundVolumeRWFF / 100.0f; + } else + { atten = 0; + } } // Mute if using Frame Advance/Frame Progress @@ -2908,9 +2985,12 @@ namespace BizHawk.Client.EmuHawk Global.MovieSession.HandleMovieOnFrameLoop(); - //why not skip audio if the user doesnt want sound + // why not skip audio if the user doesnt want sound bool renderSound = (Global.Config.SoundEnabled && !IsTurboing) || (_currAviWriter?.UsesAudio ?? false); - if (!renderSound) atten = 0; + if (!renderSound) + { + atten = 0; + } bool render = !_throttle.skipNextFrame || (_currAviWriter?.UsesVideo ?? false); Emulator.FrameAdvance(Global.ControllerOutput, render, renderSound); @@ -2938,6 +3018,7 @@ namespace BizHawk.Client.EmuHawk { Global.AutoFireController.IncrementStarts(); } + Global.AutofireStickyXORAdapter.IncrementLoops(IsLagFrame); PressFrameAdvance = false; @@ -2964,9 +3045,11 @@ namespace BizHawk.Client.EmuHawk { TasMovieRecord record = (Global.MovieSession.Movie as TasMovie)[Emulator.Frame]; if (!record.Lagged.HasValue && IsSeeking) + { // haven't yet greenzoned the frame, hence it's after editing // then we want to pause here. taseditor fasion PauseEmulator(); + } } } @@ -2984,7 +3067,6 @@ namespace BizHawk.Client.EmuHawk if (Global.ClientControls["Rewind"] || PressRewind) { UpdateToolsAfter(); - //PressRewind = false; } GlobalWin.Sound.UpdateSound(atten); @@ -3010,25 +3092,27 @@ namespace BizHawk.Client.EmuHawk _framesSinceLastFpsUpdate = 0; _timestampLastFpsUpdate = currentTimestamp; - var fps_string = $"{_lastFps:0} fps"; + var fpsString = $"{_lastFps:0} fps"; if (isRewinding) { - fps_string += IsTurboing || isFastForwarding ? + fpsString += IsTurboing || isFastForwarding ? " <<<<" : " <<"; } else if (isFastForwarding) { - fps_string += IsTurboing ? + fpsString += IsTurboing ? " >>>>" : " >>"; } - GlobalWin.OSD.FPS = fps_string; + GlobalWin.OSD.FPS = fpsString; - //need to refresh window caption in this case + // need to refresh window caption in this case if (Global.Config.DispSpeedupFeatures == 0) + { SetWindowText(); + } } private void InitializeFpsData() @@ -3043,9 +3127,9 @@ namespace BizHawk.Client.EmuHawk #region AVI Stuff /// - /// start avi recording, unattended + /// start AVI recording, unattended /// - /// match the short name of an ivideowriter + /// match the short name of an /// filename to save to private void RecordAv(string videowritername, string filename) { @@ -3053,7 +3137,7 @@ namespace BizHawk.Client.EmuHawk } /// - /// start avi recording, asking user for filename and options + /// start AV recording, asking user for filename and options /// private void RecordAv() { @@ -3074,7 +3158,9 @@ namespace BizHawk.Client.EmuHawk IVideoWriter aw = null; if (string.IsNullOrEmpty(videowritername) && !string.IsNullOrEmpty(Global.Config.VideoWriter)) + { videowritername = Global.Config.VideoWriter; + } if (unattended && !string.IsNullOrEmpty(videowritername)) { @@ -3096,7 +3182,7 @@ namespace BizHawk.Client.EmuHawk try { - bool usingAvi = aw is AviWriter; //SO GROSS! + bool usingAvi = aw is AviWriter; // SO GROSS! if (_dumpaudiosync) { @@ -3127,10 +3213,12 @@ namespace BizHawk.Client.EmuHawk } else { - //THIS IS REALLY SLOPPY! - //PLEASE REDO ME TO NOT CARE WHICH AVWRITER IS USED! - if(usingAvi && !string.IsNullOrEmpty(Global.Config.AVICodecToken)) + // THIS IS REALLY SLOPPY! + // PLEASE REDO ME TO NOT CARE WHICH AVWRITER IS USED! + if (usingAvi && !string.IsNullOrEmpty(Global.Config.AVICodecToken)) + { aw.SetDefaultVideoCodecToken(); + } var token = aw.AcquireVideoCodecToken(this); if (token == null) @@ -3153,7 +3241,7 @@ namespace BizHawk.Client.EmuHawk string ext = aw.DesiredExtension(); string pathForOpenFile; - //handle directories first + // handle directories first if (ext == "") { var fbd = new FolderBrowserEx(); @@ -3162,6 +3250,7 @@ namespace BizHawk.Client.EmuHawk aw.Dispose(); return; } + pathForOpenFile = fbd.SelectedPath; } else @@ -3169,7 +3258,7 @@ namespace BizHawk.Client.EmuHawk var sfd = new SaveFileDialog(); if (Global.Game != null) { - sfd.FileName = PathManager.FilesystemSafeName(Global.Game) + "." + ext; //dont use Path.ChangeExtension, it might wreck game names with dots in them + sfd.FileName = PathManager.FilesystemSafeName(Global.Game) + "." + ext; // dont use Path.ChangeExtension, it might wreck game names with dots in them sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.AvPathFragment, null); } else @@ -3224,6 +3313,7 @@ namespace BizHawk.Client.EmuHawk _aviSoundInputAsync = new SyncToAsyncProvider(_currentSoundProvider); } } + _dumpProxy = new SimpleSyncSoundProvider(); RewireSound(); } @@ -3273,14 +3363,16 @@ namespace BizHawk.Client.EmuHawk { if (_currAviWriter != null) { - //TODO ZERO - this code is pretty jacked. we'll want to frugalize buffers better for speedier dumping, and we might want to rely on the GL layer for padding + // TODO ZERO - this code is pretty jacked. we'll want to frugalize buffers better for speedier dumping, and we might want to rely on the GL layer for padding try { - //is this the best time to handle this? or deeper inside? + // is this the best time to handle this? or deeper inside? if (_currAviWriterFrameList != null) { if (!_currAviWriterFrameList.Contains(Emulator.Frame)) + { goto HANDLE_AUTODUMP; + } } IVideoProvider output; @@ -3289,7 +3381,6 @@ namespace BizHawk.Client.EmuHawk { BitmapBuffer bbin = null; Bitmap bmpin = null; - Bitmap bmpout = null; try { if (Global.Config.AVI_CaptureOSD) @@ -3303,7 +3394,7 @@ namespace BizHawk.Client.EmuHawk bbin.DiscardAlpha(); - bmpout = new Bitmap(_avwriterResizew, _avwriterResizeh, PixelFormat.Format32bppArgb); + var bmpout = new Bitmap(_avwriterResizew, _avwriterResizeh, PixelFormat.Format32bppArgb); bmpin = bbin.ToSysdrawingBitmap(); using (var g = Graphics.FromImage(bmpout)) { @@ -3325,8 +3416,8 @@ namespace BizHawk.Client.EmuHawk } finally { - if (bbin != null) bbin.Dispose(); - if (bmpin != null) bmpin.Dispose(); + bbin?.Dispose(); + bmpin?.Dispose(); } } else @@ -3337,7 +3428,9 @@ namespace BizHawk.Client.EmuHawk disposableOutput = (IDisposable)output; } else + { output = _currentVideoProvider; + } } _currAviWriter.SetFrame(Emulator.Frame); @@ -3353,10 +3446,7 @@ namespace BizHawk.Client.EmuHawk (_currAviWriter as AudioStretcher).DumpAV(output, _aviSoundInputAsync, out samp, out nsamp); } - if (disposableOutput != null) - { - disposableOutput.Dispose(); - } + disposableOutput?.Dispose(); _dumpProxy.PutSamples(samp, nsamp); } @@ -3389,10 +3479,8 @@ namespace BizHawk.Client.EmuHawk { return ac.SelectedMemberIndex; } - else - { - return null; - } + + return null; } #endregion @@ -3421,7 +3509,7 @@ namespace BizHawk.Client.EmuHawk // Retry loading the ROM here. This leads to recursion, as the original call to LoadRom has not exited yet, // but unless the user tries and fails to set his firmware a lot of times, nothing should happen. // Refer to how RomLoader implemented its LoadRom method for a potential fix on this. - LoadRom(e.RomPath, CurrentLoadRomArgs); + LoadRom(e.RomPath, _currentLoadRomArgs); } } } @@ -3455,46 +3543,46 @@ namespace BizHawk.Client.EmuHawk public class LoadRomArgs { - public bool? Deterministic; - public IOpenAdvanced OpenAdvanced; + public bool? Deterministic { get; set; } + public IOpenAdvanced OpenAdvanced { get; set; } } - LoadRomArgs CurrentLoadRomArgs; + private LoadRomArgs _currentLoadRomArgs; // Still needs a good bit of refactoring public bool LoadRom(string path, LoadRomArgs args) { path = HawkFile.Util_ResolveLink(path); - //default args - if (args == null) args = new LoadRomArgs(); + // default args + if (args == null) + { + args = new LoadRomArgs(); + } - //if this is the first call to LoadRom (they will come in recursively) then stash the args + // if this is the first call to LoadRom (they will come in recursively) then stash the args bool firstCall = false; - if (CurrentLoadRomArgs == null) + if (_currentLoadRomArgs == null) { firstCall = true; - CurrentLoadRomArgs = args; + _currentLoadRomArgs = args; } else { - args = CurrentLoadRomArgs; + args = _currentLoadRomArgs; } try { // If deterministic emulation is passed in, respect that value regardless, else determine a good value (currently that simply means movies require deterministic emulaton) - bool deterministic = args.Deterministic.HasValue ? - args.Deterministic.Value : - Global.MovieSession.QueuedMovie != null; - //Global.MovieSession.Movie.IsActive; + bool deterministic = args.Deterministic ?? Global.MovieSession.QueuedMovie != null; if (!GlobalWin.Tools.AskSave()) { return false; } - bool asLibretro = (args.OpenAdvanced is OpenAdvanced_Libretro || args.OpenAdvanced is OpenAdvanced_LibretroNoGame); + bool asLibretro = args.OpenAdvanced is OpenAdvanced_Libretro || args.OpenAdvanced is OpenAdvanced_LibretroNoGame; var loader = new RomLoader { @@ -3518,32 +3606,43 @@ namespace BizHawk.Client.EmuHawk var nextComm = CreateCoreComm(); - //we need to inform LoadRom which Libretro core to use... + // we need to inform LoadRom which Libretro core to use... IOpenAdvanced ioa = args.OpenAdvanced; if (ioa is IOpenAdvancedLibretro) { var ioaretro = ioa as IOpenAdvancedLibretro; - //prepare a core specification - //if it wasnt already specified, use the current default - if (ioaretro.CorePath == null) ioaretro.CorePath = Global.Config.LibretroCore; + // prepare a core specification + // if it wasnt already specified, use the current default + if (ioaretro.CorePath == null) + { + ioaretro.CorePath = Global.Config.LibretroCore; + } + nextComm.LaunchLibretroCore = ioaretro.CorePath; if (nextComm.LaunchLibretroCore == null) + { throw new InvalidOperationException("Can't load a file via Libretro until a core is specified"); + } } CoreFileProvider.SyncCoreCommInputSignals(nextComm); var result = loader.LoadRom(path, nextComm); - //we need to replace the path in the OpenAdvanced with the canonical one the user chose. - //It can't be done until loder.LoadRom happens (for CanonicalFullPath) - //i'm not sure this needs to be more abstractly engineered yet until we have more OpenAdvanced examples + // we need to replace the path in the OpenAdvanced with the canonical one the user chose. + // It can't be done until loder.LoadRom happens (for CanonicalFullPath) + // i'm not sure this needs to be more abstractly engineered yet until we have more OpenAdvanced examples if (ioa is OpenAdvanced_Libretro) { var oaretro = ioa as OpenAdvanced_Libretro; oaretro.token.Path = loader.CanonicalFullPath; } - if (ioa is OpenAdvanced_OpenRom) ((OpenAdvanced_OpenRom)ioa).Path = loader.CanonicalFullPath; + + if (ioa is OpenAdvanced_OpenRom) + { + ((OpenAdvanced_OpenRom)ioa).Path = loader.CanonicalFullPath; + } + string loaderName = "*" + OpenAdvancedSerializer.Serialize(ioa); if (result) @@ -3583,11 +3682,7 @@ namespace BizHawk.Client.EmuHawk if (Emulator.CoreComm.RomStatusDetails == null && loader.Rom != null) { - Emulator.CoreComm.RomStatusDetails = string.Format( - "{0}\r\nSHA1:{1}\r\nMD5:{2}\r\n", - loader.Game.Name, - loader.Rom.RomData.HashSHA1(), - loader.Rom.RomData.HashMD5()); + Emulator.CoreComm.RomStatusDetails = $"{loader.Game.Name}\r\nSHA1:{loader.Rom.RomData.HashSHA1()}\r\nMD5:{loader.Rom.RomData.HashMD5()}\r\n"; } if (Emulator.HasBoardInfo()) @@ -3657,18 +3752,19 @@ namespace BizHawk.Client.EmuHawk Console.WriteLine(" {0} : {1}", f.FirmwareId, f.Hash); } } - ApiHawk.ClientApi.OnRomLoaded(); + + ClientApi.OnRomLoaded(); return true; } else { - //This shows up if there's a problem + // This shows up if there's a problem // TODO: put all these in a single method or something - //The ROM has been loaded by a recursive invocation of the LoadROM method. + // The ROM has been loaded by a recursive invocation of the LoadROM method. if (!(Emulator is NullEmulator)) { - ApiHawk.ClientApi.OnRomLoaded(); + ClientApi.OnRomLoaded(); return true; } @@ -3686,7 +3782,7 @@ namespace BizHawk.Client.EmuHawk { if (firstCall) { - CurrentLoadRomArgs = null; + _currentLoadRomArgs = null; } } } @@ -3743,7 +3839,9 @@ namespace BizHawk.Client.EmuHawk Global.Rewinder.Uninitialize(); if (GlobalWin.Tools.IsLoaded()) + { GlobalWin.Tools.Get().Restart(); + } Global.CheatList.SaveOnClose(); Emulator.Dispose(); @@ -3761,8 +3859,8 @@ namespace BizHawk.Client.EmuHawk public void CloseRom(bool clearSram = false) { - //This gets called after Close Game gets called. - //Tested with NESHawk and SMB3 (U) + // This gets called after Close Game gets called. + // Tested with NESHawk and SMB3 (U) if (GlobalWin.Tools.AskSave()) { CloseGame(clearSram); @@ -3853,7 +3951,9 @@ namespace BizHawk.Client.EmuHawk bool wasCountingRerecords = Global.MovieSession.Movie.IsCountingRerecords; if (fromLua) + { Global.MovieSession.Movie.IsCountingRerecords = false; + } if (SavestateManager.LoadStateFile(path, userFriendlyStateName)) { @@ -3945,6 +4045,7 @@ namespace BizHawk.Client.EmuHawk { GlobalWin.OSD.AddMessage("Unable to save state " + path); } + if (!fromLua) { UpdateStatusSlots(); @@ -3961,7 +4062,7 @@ namespace BizHawk.Client.EmuHawk bool handled; ClientApi.OnBeforeQuickSave(this, quickSlotName, out handled); - if(handled) + if (handled) { return; } @@ -3982,7 +4083,9 @@ namespace BizHawk.Client.EmuHawk // Make backup first if (Global.Config.BackupSavestates) - BizHawk.Common.Util.TryMoveBackupFile(path, path + ".bak"); + { + Util.TryMoveBackupFile(path, path + ".bak"); + } SaveState(path, quickSlotName, false); @@ -4002,7 +4105,9 @@ namespace BizHawk.Client.EmuHawk // allow named state export for tastudio, since it's safe, unlike loading one // todo: make it not save laglog in that case if (GlobalWin.Tools.IsLoaded()) + { GlobalWin.Tools.TAStudio.NamedStatePending = true; + } if (IsSavestateSlave) { @@ -4034,7 +4139,9 @@ namespace BizHawk.Client.EmuHawk } if (GlobalWin.Tools.IsLoaded()) + { GlobalWin.Tools.TAStudio.NamedStatePending = false; + } } private void LoadStateAs() @@ -4163,7 +4270,7 @@ namespace BizHawk.Client.EmuHawk } } - public void StopMovie(bool saveChanges = true) + private void StopMovie(bool saveChanges = true) { if (IsSlave && Master.WantsToControlStopMovie) { @@ -4215,15 +4322,25 @@ namespace BizHawk.Client.EmuHawk double timestampDeltaMs = (double)(currentTimestamp - _frameRewindTimestamp) / Stopwatch.Frequency * 1000.0; isRewinding = timestampDeltaMs >= Global.Config.FrameProgressDelayMs; - //clear this flag once we get out of the progress stage + // clear this flag once we get out of the progress stage if (isRewinding) + { _frameRewindWasPaused = false; + } - //if we're freely running, there's no need for reverse frame progress semantics (that may be debateable though) - if (!EmulatorPaused) isRewinding = true; + // if we're freely running, there's no need for reverse frame progress semantics (that may be debateable though) + if (!EmulatorPaused) + { + isRewinding = true; + } if (_frameRewindWasPaused) - if (IsSeeking) isRewinding = false; + { + if (IsSeeking) + { + isRewinding = false; + } + } } if (isRewinding) diff --git a/BizHawk.sln.DotSettings b/BizHawk.sln.DotSettings index 527a9070ef..576466ab23 100644 --- a/BizHawk.sln.DotSettings +++ b/BizHawk.sln.DotSettings @@ -76,6 +76,7 @@ PC PCE PCECD + PPU PSP PSX RAM