using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Drawing.Text; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using System.Xml; using Mesen.GUI.Config; using Mesen.GUI.Debugger; using Mesen.GUI.Forms.Cheats; using Mesen.GUI.Forms.Config; using Mesen.GUI.Forms.HdPackEditor; using Mesen.GUI.Forms.NetPlay; using Mesen.GUI.GoogleDriveIntegration; namespace Mesen.GUI.Forms { public partial class frmMain : BaseForm, IMessageFilter { private const int WM_KEYDOWN = 0x100; private const int WM_KEYUP = 0x101; private InteropEmu.NotificationListener _notifListener; private Thread _emuThread; private frmDebugger _debugger; private frmLogWindow _logWindow; private frmCheatList _cheatListWindow; private frmHdPackEditor _hdPackEditorWindow; private ResourcePath? _currentRomPath = null; private Image _pauseButton = Mesen.GUI.Properties.Resources.Pause; private Image _playButton = Mesen.GUI.Properties.Resources.Play; private string _currentGame = null; private bool _customSize = false; private FormWindowState _originalWindowState; private bool _fullscreenMode = false; private Size? _nonNsfSize = null; private bool _isNsfPlayerMode = false; private object _loadRomLock = new object(); private int _romLoadCounter = 0; private bool _removeFocus = false; private bool _showUpgradeMessage = false; private string[] _commandLineArgs; private bool _noAudio = false; private bool _noVideo = false; private bool _noInput = false; private PrivateFontCollection _fonts = new PrivateFontCollection(); public frmMain(string[] args) { InitializeComponent(); Version currentVersion = new Version(InteropEmu.GetMesenVersion()); lblVersion.Text = currentVersion.ToString(); _fonts.AddFontFile(Path.Combine(ConfigManager.HomeFolder, "Resources", "PixelFont.ttf")); lblVersion.Font = new Font(_fonts.Families[0], 11); _commandLineArgs = args; Application.AddMessageFilter(this); this.Resize += ResizeRecentGames; this.FormClosed += (s, e) => Application.RemoveMessageFilter(this); } public void ProcessCommandLineArguments(string[] args, bool forStartup) { var switches = new List(); for(int i = 0; i < args.Length; i++) { if(args[i] != null) { switches.Add(args[i].ToLowerInvariant().Replace("--", "/").Replace("-", "/").Replace("=/", "=-")); } } if(forStartup) { _noVideo = switches.Contains("/novideo"); _noAudio = switches.Contains("/noaudio"); _noInput = switches.Contains("/noinput"); } if(switches.Contains("/fullscreen")) { this.SetFullscreenState(true); } if(switches.Contains("/donotsavesettings")) { ConfigManager.DoNotSaveSettings = true; } ConfigManager.ProcessSwitches(switches); } public void LoadGameFromCommandLine(string[] args) { if(args.Length > 0) { foreach(string arg in args) { if(arg != null) { string path = arg; try { if(File.Exists(path)) { this.LoadFile(path); break; } //Try loading file as a relative path to the folder Mesen was started from path = Path.Combine(Program.OriginalFolder, path); if(File.Exists(path)) { this.LoadFile(path); break; } } catch { } } } } } protected override void OnLoad(EventArgs e) { ResourceHelper.LoadResources(ConfigManager.Config.PreferenceInfo.DisplayLanguage); ResourceHelper.UpdateEmuLanguage(); base.OnLoad(e); #if HIDETESTMENU mnuTests.Visible = false; #endif PerformUpgrade(); _notifListener = new InteropEmu.NotificationListener(); _notifListener.OnNotification += _notifListener_OnNotification; menuTimer.Start(); this.ProcessCommandLineArguments(_commandLineArgs, true); VideoInfo.ApplyConfig(); InitializeVsSystemMenu(); InitializeFdsDiskMenu(); InitializeEmulationSpeedMenu(); UpdateVideoSettings(); InitializeEmu(); UpdateMenus(); UpdateRecentFiles(); UpdateViewerSize(); if(ConfigManager.Config.WindowLocation.HasValue) { this.StartPosition = FormStartPosition.Manual; this.Location = ConfigManager.Config.WindowLocation.Value; } else { //First launch this.StartPosition = FormStartPosition.CenterScreen; } if(ConfigManager.Config.PreferenceInfo.CloudSaveIntegration) { Task.Run(() => CloudSyncHelper.Sync()); } if(ConfigManager.Config.PreferenceInfo.AutomaticallyCheckForUpdates) { CheckForUpdates(false); } if(ConfigManager.Config.WindowSize.HasValue) { this.ClientSize = ConfigManager.Config.WindowSize.Value; } } protected override void OnDeactivate(EventArgs e) { base.OnDeactivate(e); _removeFocus = true; InteropEmu.ResetKeyState(); } protected override void OnActivated(EventArgs e) { base.OnActivated(e); _removeFocus = false; InteropEmu.ResetKeyState(); } protected override void OnShown(EventArgs e) { base.OnShown(e); if(_showUpgradeMessage) { MesenMsgBox.Show("UpgradeSuccess", MessageBoxButtons.OK, MessageBoxIcon.Information); _showUpgradeMessage = false; } if(ConfigManager.Config.WindowSize.HasValue) { this.Size = ConfigManager.Config.WindowSize.Value; } this.LoadGameFromCommandLine(_commandLineArgs); this.menuStrip.VisibleChanged += new System.EventHandler(this.menuStrip_VisibleChanged); this.UpdateRendererLocation(); } protected override void OnClosing(CancelEventArgs e) { if(ConfigManager.Config.PreferenceInfo.ConfirmExitResetPower && MesenMsgBox.Show("ConfirmExit", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK) { e.Cancel = true; return; } if(_notifListener != null) { _notifListener.Dispose(); _notifListener = null; } if(_debugger != null) { _debugger.Close(); } ConfigManager.Config.EmulationInfo.EmulationSpeed = InteropEmu.GetEmulationSpeed(); if(this.WindowState == FormWindowState.Normal) { ConfigManager.Config.WindowLocation = this.Location; ConfigManager.Config.WindowSize = this.Size; } else { ConfigManager.Config.WindowLocation = this.RestoreBounds.Location; ConfigManager.Config.WindowSize = this.RestoreBounds.Size; } if(this._nonNsfSize.HasValue) { ConfigManager.Config.WindowSize = this._nonNsfSize.Value; } ConfigManager.ApplyChanges(); StopEmu(); if(ConfigManager.Config.PreferenceInfo.CloudSaveIntegration) { CloudSyncHelper.Sync(); } InteropEmu.Release(); ConfigManager.SaveConfig(); base.OnClosing(e); } private void menuTimer_Tick(object sender, EventArgs e) { this.UpdateMenus(); } void InitializeEmu() { InteropEmu.InitializeEmu(ConfigManager.HomeFolder, this.Handle, this.ctrlRenderer.Handle, _noAudio, _noVideo, _noInput); foreach(RecentItem recentItem in ConfigManager.Config.RecentFiles) { InteropEmu.AddKnownGameFolder(recentItem.RomFile.Folder); } ConfigManager.Config.InitializeDefaults(); ConfigManager.ApplyChanges(); ConfigManager.Config.ApplyConfig(); UpdateEmulationFlags(); } private void UpdateViewerSize() { this.Resize -= frmMain_Resize; InteropEmu.ScreenSize size = InteropEmu.GetScreenSize(false); if(!_customSize && this.WindowState != FormWindowState.Maximized) { Size sizeGap = this.Size - this.ClientSize; UpdateScaleMenu(size.Scale); this.ClientSize = new Size(Math.Max(this.MinimumSize.Width - sizeGap.Width, size.Width), Math.Max(this.MinimumSize.Height - sizeGap.Height, size.Height + (this.HideMenuStrip ? 0 : menuStrip.Height))); } ctrlRenderer.Size = new Size(size.Width, size.Height); ctrlRenderer.Left = (panelRenderer.Width - ctrlRenderer.Width) / 2; ctrlRenderer.Top = (panelRenderer.Height - ctrlRenderer.Height) / 2; if(this.HideMenuStrip) { this.menuStrip.Visible = false; } this.Resize += frmMain_Resize; } private void ResizeRecentGames(object sender, EventArgs e) { if(this.ClientSize.Height < 400) { ctrlRecentGames.Height = this.ClientSize.Height - 125 + Math.Min(50, (400 - this.ClientSize.Height)); } else { ctrlRecentGames.Height = this.ClientSize.Height - 125; } ctrlRecentGames.Width = this.ClientSize.Width; ctrlRecentGames.Top = (this.HideMenuStrip && this.menuStrip.Visible) ? -menuStrip.Height : 0; } private void frmMain_Resize(object sender, EventArgs e) { if(this.WindowState != FormWindowState.Minimized) { SetScaleBasedOnWindowSize(); ctrlRenderer.Left = (panelRenderer.Width - ctrlRenderer.Width) / 2; ctrlRenderer.Top = (panelRenderer.Height - ctrlRenderer.Height) / 2; } } private void SetScaleBasedOnWindowSize() { _customSize = true; InteropEmu.ScreenSize size = InteropEmu.GetScreenSize(true); double verticalScale = (double)panelRenderer.ClientSize.Height / size.Height; double horizontalScale = (double)panelRenderer.ClientSize.Width / size.Width; double scale = Math.Min(verticalScale, horizontalScale); if(_fullscreenMode && ConfigManager.Config.VideoInfo.FullscreenForceIntegerScale) { scale = Math.Floor(scale); } UpdateScaleMenu(scale); VideoInfo.ApplyConfig(); } private void SetFullscreenState(bool enabled) { this.Resize -= frmMain_Resize; _fullscreenMode = enabled; if(enabled) { this.menuStrip.Visible = false; _originalWindowState = this.WindowState; this.WindowState = FormWindowState.Normal; this.FormBorderStyle = FormBorderStyle.None; this.WindowState = FormWindowState.Maximized; SetScaleBasedOnWindowSize(); } else { this.menuStrip.Visible = true; this.WindowState = _originalWindowState; this.FormBorderStyle = FormBorderStyle.Sizable; this.frmMain_Resize(null, EventArgs.Empty); } this.Resize += frmMain_Resize; mnuFullscreen.Checked = enabled; } private bool HideMenuStrip { get { return _fullscreenMode || ConfigManager.Config.PreferenceInfo.AutoHideMenu; } } private void ctrlRenderer_MouseMove(object sender, MouseEventArgs e) { if(sender != this.ctrlRecentGames) { CursorManager.OnMouseMove((Control)sender); } if(this.HideMenuStrip && !this.menuStrip.ContainsFocus) { if(sender == ctrlRenderer) { this.menuStrip.Visible = ctrlRenderer.Top + e.Y < 30; } else { this.menuStrip.Visible = e.Y < 30; } } } private void ctrlRenderer_MouseClick(object sender, MouseEventArgs e) { if(this.HideMenuStrip) { this.menuStrip.Visible = false; } } private void _notifListener_OnNotification(InteropEmu.NotificationEventArgs e) { switch(e.NotificationType) { case InteropEmu.ConsoleNotificationType.GameLoaded: _currentGame = InteropEmu.GetRomInfo().GetRomName(); InteropEmu.SetNesModel(ConfigManager.Config.Region); InitializeNsfMode(false, true); InitializeFdsDiskMenu(); InitializeVsSystemMenu(); CheatInfo.ApplyCheats(); VsConfigInfo.ApplyConfig(); InitializeStateMenu(mnuSaveState, true); InitializeStateMenu(mnuLoadState, false); if(ConfigManager.Config.PreferenceInfo.ShowVsConfigOnLoad && InteropEmu.IsVsSystem()) { this.Invoke((MethodInvoker)(() => { this.ShowVsGameConfig(); })); } this.StartEmuThread(); this.BeginInvoke((MethodInvoker)(() => { UpdateViewerSize(); })); break; case InteropEmu.ConsoleNotificationType.PpuFrameDone: if(InteropEmu.IsNsf()) { this.ctrlNsfPlayer.CountFrame(); } break; case InteropEmu.ConsoleNotificationType.GameReset: InitializeNsfMode(); break; case InteropEmu.ConsoleNotificationType.DisconnectedFromServer: ConfigManager.Config.ApplyConfig(); break; case InteropEmu.ConsoleNotificationType.GameStopped: this._currentGame = null; InitializeNsfMode(); CheatInfo.ClearCheats(); this.BeginInvoke((MethodInvoker)(() => { if(_hdPackEditorWindow != null) { _hdPackEditorWindow.Close(); } ctrlRecentGames.Initialize(); })); break; case InteropEmu.ConsoleNotificationType.ResolutionChanged: this.BeginInvoke((MethodInvoker)(() => { UpdateViewerSize(); })); break; case InteropEmu.ConsoleNotificationType.FdsBiosNotFound: this.BeginInvoke((MethodInvoker)(() => { SelectFdsBiosPrompt(); })); break; case InteropEmu.ConsoleNotificationType.RequestReset: this.BeginInvoke((MethodInvoker)(() => this.ResetEmu())); break; case InteropEmu.ConsoleNotificationType.RequestPowerCycle: this.BeginInvoke((MethodInvoker)(() => this.PowerCycleEmu())); break; case InteropEmu.ConsoleNotificationType.RequestExit: this.BeginInvoke((MethodInvoker)(() => this.Close())); break; case InteropEmu.ConsoleNotificationType.ToggleCheats: this.BeginInvoke((MethodInvoker)(() => { ConfigManager.Config.DisableAllCheats = !ConfigManager.Config.DisableAllCheats; if(ConfigManager.Config.DisableAllCheats) { InteropEmu.DisplayMessage("Cheats", "CheatsDisabled"); } CheatInfo.ApplyCheats(); ConfigManager.ApplyChanges(); })); break; case InteropEmu.ConsoleNotificationType.ToggleAudio: this.BeginInvoke((MethodInvoker)(() => { ConfigManager.Config.AudioInfo.EnableAudio = !ConfigManager.Config.AudioInfo.EnableAudio; AudioInfo.ApplyConfig(); ConfigManager.ApplyChanges(); })); break; } if(e.NotificationType != InteropEmu.ConsoleNotificationType.PpuFrameDone) { UpdateMenus(); } } private void UpdateFocusFlag() { bool hasFocus = false; if(Application.OpenForms.Count > 0) { if(Application.OpenForms[0].ContainsFocus) { hasFocus = true; } } if(_removeFocus) { hasFocus = false; } InteropEmu.SetFlag(EmulationFlags.InBackground, !hasFocus); } private void UpdateMenus() { try { if(this.InvokeRequired) { this.BeginInvoke((MethodInvoker)(() => this.UpdateMenus())); } else { panelInfo.Visible = _emuThread == null; ctrlRecentGames.Visible = _emuThread == null; ctrlLoading.Visible = (_romLoadCounter > 0); UpdateFocusFlag(); UpdateWindowTitle(); bool isNetPlayClient = InteropEmu.IsConnected(); mnuPause.Enabled = mnuPowerCycle.Enabled = mnuReset.Enabled = mnuPowerOff.Enabled = (_emuThread != null && !isNetPlayClient); mnuSaveState.Enabled = (_emuThread != null && !isNetPlayClient && !InteropEmu.IsNsf()); mnuLoadState.Enabled = (_emuThread != null && !isNetPlayClient && !InteropEmu.IsNsf() && !InteropEmu.MoviePlaying() && !InteropEmu.MovieRecording()); mnuPause.Text = InteropEmu.IsPaused() ? ResourceHelper.GetMessage("Resume") : ResourceHelper.GetMessage("Pause"); mnuPause.Image = InteropEmu.IsPaused() ? _playButton : _pauseButton; bool netPlay = InteropEmu.IsServerRunning() || isNetPlayClient; mnuStartServer.Enabled = !isNetPlayClient; mnuConnect.Enabled = !InteropEmu.IsServerRunning(); mnuNetPlaySelectController.Enabled = isNetPlayClient || InteropEmu.IsServerRunning(); if(mnuNetPlaySelectController.Enabled) { int availableControllers = InteropEmu.NetPlayGetAvailableControllers(); int currentControllerPort = InteropEmu.NetPlayGetControllerPort(); mnuNetPlayPlayer1.Enabled = (availableControllers & 0x01) == 0x01; mnuNetPlayPlayer2.Enabled = (availableControllers & 0x02) == 0x02; mnuNetPlayPlayer3.Enabled = (availableControllers & 0x04) == 0x04; mnuNetPlayPlayer4.Enabled = (availableControllers & 0x08) == 0x08; mnuNetPlayPlayer1.Text = ResourceHelper.GetMessage("PlayerNumber", "1") + " (" + ResourceHelper.GetEnumText(InteropEmu.NetPlayGetControllerType(0)) + ")"; mnuNetPlayPlayer2.Text = ResourceHelper.GetMessage("PlayerNumber", "2") + " (" + ResourceHelper.GetEnumText(InteropEmu.NetPlayGetControllerType(1)) + ")"; mnuNetPlayPlayer3.Text = ResourceHelper.GetMessage("PlayerNumber", "3") + " (" + ResourceHelper.GetEnumText(InteropEmu.NetPlayGetControllerType(2)) + ")"; mnuNetPlayPlayer4.Text = ResourceHelper.GetMessage("PlayerNumber", "4") + " (" + ResourceHelper.GetEnumText(InteropEmu.NetPlayGetControllerType(3)) + ")"; mnuNetPlayPlayer1.Checked = (currentControllerPort == 0); mnuNetPlayPlayer2.Checked = (currentControllerPort == 1); mnuNetPlayPlayer3.Checked = (currentControllerPort == 2); mnuNetPlayPlayer4.Checked = (currentControllerPort == 3); mnuNetPlaySpectator.Checked = (currentControllerPort == 0xFF); mnuNetPlaySpectator.Enabled = true; } mnuStartServer.Text = InteropEmu.IsServerRunning() ? ResourceHelper.GetMessage("StopServer") : ResourceHelper.GetMessage("StartServer"); mnuConnect.Text = isNetPlayClient ? ResourceHelper.GetMessage("Disconnect") : ResourceHelper.GetMessage("ConnectToServer"); mnuCheats.Enabled = !isNetPlayClient; mnuEmulationSpeed.Enabled = !isNetPlayClient; mnuIncreaseSpeed.Enabled = !isNetPlayClient; mnuDecreaseSpeed.Enabled = !isNetPlayClient; mnuEmuSpeedMaximumSpeed.Enabled = !isNetPlayClient; mnuInput.Enabled = !isNetPlayClient; mnuRegion.Enabled = !isNetPlayClient; bool moviePlaying = InteropEmu.MoviePlaying(); bool movieRecording = InteropEmu.MovieRecording(); mnuPlayMovie.Enabled = !netPlay && !moviePlaying && !movieRecording; mnuStopMovie.Enabled = _emuThread != null && !netPlay && (moviePlaying || movieRecording); mnuRecordFrom.Enabled = _emuThread != null && !moviePlaying && !movieRecording; mnuRecordFromStart.Enabled = _emuThread != null && !isNetPlayClient && !moviePlaying && !movieRecording; mnuRecordFromNow.Enabled = _emuThread != null && !moviePlaying && !movieRecording; bool waveRecording = InteropEmu.WaveIsRecording(); mnuWaveRecord.Enabled = _emuThread != null && !waveRecording; mnuWaveStop.Enabled = _emuThread != null && waveRecording; bool aviRecording = InteropEmu.AviIsRecording(); mnuAviRecord.Enabled = _emuThread != null && !aviRecording; mnuAviStop.Enabled = _emuThread != null && aviRecording; mnuVideoRecorder.Enabled = !_isNsfPlayerMode; bool testRecording = InteropEmu.RomTestRecording(); mnuTestRun.Enabled = !netPlay && !moviePlaying && !movieRecording; mnuTestStopRecording.Enabled = _emuThread != null && testRecording; mnuTestRecordStart.Enabled = _emuThread != null && !isNetPlayClient && !moviePlaying && !movieRecording; mnuTestRecordNow.Enabled = _emuThread != null && !moviePlaying && !movieRecording; mnuTestRecordMovie.Enabled = !netPlay && !moviePlaying && !movieRecording; mnuTestRecordTest.Enabled = !netPlay && !moviePlaying && !movieRecording; mnuTestRecordFrom.Enabled = (mnuTestRecordStart.Enabled || mnuTestRecordNow.Enabled || mnuTestRecordMovie.Enabled || mnuTestRecordTest.Enabled); mnuDebugger.Enabled = !netPlay && _emuThread != null; mnuHdPackEditor.Enabled = !netPlay && _emuThread != null; mnuTakeScreenshot.Enabled = _emuThread != null && !InteropEmu.IsNsf(); mnuNetPlay.Enabled = !InteropEmu.IsNsf(); if(_emuThread != null && InteropEmu.IsNsf()) { mnuPowerCycle.Enabled = false; mnuMovies.Enabled = mnuPlayMovie.Enabled = mnuStopMovie.Enabled = mnuRecordFrom.Enabled = mnuRecordFromStart.Enabled = mnuRecordFromNow.Enabled = false; } mnuRegionAuto.Checked = ConfigManager.Config.Region == NesModel.Auto; mnuRegionNtsc.Checked = ConfigManager.Config.Region == NesModel.NTSC; mnuRegionPal.Checked = ConfigManager.Config.Region == NesModel.PAL; mnuRegionDendy.Checked = ConfigManager.Config.Region == NesModel.Dendy; bool autoInsertDisabled = !InteropEmu.FdsIsAutoInsertDiskEnabled(); mnuSelectDisk.Enabled = autoInsertDisabled; mnuEjectDisk.Enabled = autoInsertDisabled; mnuSwitchDiskSide.Enabled = autoInsertDisabled; } } catch { } } private void UpdateWindowTitle() { string title = "Mesen"; if(!string.IsNullOrWhiteSpace(_currentGame)) { title += " - " + _currentGame; } if(ConfigManager.Config.PreferenceInfo.DisplayTitleBarInfo) { title += string.Format(" - {0}x{1} ({2:0.##}x, {3}) - {4}", ctrlRenderer.Width, ctrlRenderer.Height, ConfigManager.Config.VideoInfo.VideoScale, ResourceHelper.GetEnumText(ConfigManager.Config.VideoInfo.AspectRatio), ResourceHelper.GetEnumText(ConfigManager.Config.VideoInfo.VideoFilter)); } this.Text = title; } private void StartEmuThread() { if(_emuThread == null) { _emuThread = new Thread(() => { try { InteropEmu.Run(); _emuThread = null; } catch(Exception ex) { MesenMsgBox.Show("UnexpectedError", MessageBoxButtons.OK, MessageBoxIcon.Error, ex.ToString()); _emuThread = null; } }); _emuThread.Start(); } UpdateMenus(); } private void StopEmu() { InteropEmu.Stop(); } private void PauseEmu() { if(InteropEmu.DebugIsDebuggerRunning()) { InteropEmu.DebugStep(1); } else { if(InteropEmu.IsPaused()) { InteropEmu.Resume(); } else { InteropEmu.Pause(); } ctrlNsfPlayer.UpdateText(); } } private void ResetEmu() { if(!ConfigManager.Config.PreferenceInfo.ConfirmExitResetPower || MesenMsgBox.Show("ConfirmReset", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK) { InteropEmu.Reset(); } } private void PowerCycleEmu() { if(!ConfigManager.Config.PreferenceInfo.ConfirmExitResetPower || MesenMsgBox.Show("ConfirmPowerCycle", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK) { InteropEmu.PowerCycle(); } } bool IMessageFilter.PreFilterMessage(ref Message m) { if(m.Msg == WM_KEYUP) { int scanCode = (Int32)(((Int64)m.LParam & 0x1FF0000) >> 16); InteropEmu.SetKeyState(scanCode, false); } return false; } protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if(msg.Msg == WM_KEYDOWN) { int scanCode = (Int32)(((Int64)msg.LParam & 0x1FF0000) >> 16); InteropEmu.SetKeyState(scanCode, true); } if(!this.menuStrip.Enabled) { //Make sure we disable all shortcut keys while the bar is disabled (i.e when running tests) return false; } if(this.HideMenuStrip && (keyData & Keys.Alt) == Keys.Alt) { if(this.menuStrip.Visible && !this.menuStrip.ContainsFocus) { this.menuStrip.Visible = false; } else { this.menuStrip.Visible = true; this.menuStrip.Focus(); } } #if !HIDETESTMENU if(keyData == Keys.Pause) { if(InteropEmu.RomTestRecording()) { InteropEmu.RomTestStop(); } else { InteropEmu.RomTestRecord(ConfigManager.TestFolder + "\\" + InteropEmu.GetRomInfo().GetRomName() + ".mtp", true); } } #endif if(keyData == Keys.Escape && _emuThread != null && mnuPause.Enabled) { PauseEmu(); return true; } else if(keyData == Keys.Oemplus) { mnuIncreaseSpeed.PerformClick(); return true; } else if(keyData == Keys.OemMinus) { mnuDecreaseSpeed.PerformClick(); return true; } return base.ProcessCmdKey(ref msg, keyData); } private void SelectFdsBiosPrompt() { if(MesenMsgBox.Show("FdsBiosNotFound", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { using(OpenFileDialog ofd = new OpenFileDialog()) { ofd.SetFilter(ResourceHelper.GetMessage("FilterAll")); if(ofd.ShowDialog() == DialogResult.OK) { string hash = MD5Helper.GetMD5Hash(ofd.FileName).ToLowerInvariant(); if(hash == "ca30b50f880eb660a320674ed365ef7a" || hash == "c1a9e9415a6adde3c8563c622d4c9fce") { File.Copy(ofd.FileName, Path.Combine(ConfigManager.HomeFolder, "FdsBios.bin")); LoadROM(_currentRomPath.Value, ConfigManager.Config.PreferenceInfo.AutoLoadIpsPatches); } else { MesenMsgBox.Show("InvalidFdsBios", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } } private void frmMain_DragDrop(object sender, DragEventArgs e) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); if(File.Exists(files[0])) { LoadFile(files[0]); this.Activate(); } } private void frmMain_DragEnter(object sender, DragEventArgs e) { if(e.Data.GetDataPresent(DataFormats.FileDrop)) { e.Effect = DragDropEffects.Copy; } } private void ctrlRenderer_DoubleClick(object sender, EventArgs e) { if(!CursorManager.NeedMouseIcon && !InteropEmu.HasArkanoidPaddle()) { //Disable double clicking (used to switch to fullscreen mode) when using zapper/arkanoid controller SetFullscreenState(!_fullscreenMode); } } private void panelRenderer_Click(object sender, EventArgs e) { if(this.HideMenuStrip) { this.menuStrip.Visible = false; } ctrlRenderer.Focus(); } private void ctrlRenderer_Enter(object sender, EventArgs e) { if(this.HideMenuStrip) { this.menuStrip.Visible = false; } } private void menuStrip_VisibleChanged(object sender, EventArgs e) { this.UpdateRendererLocation(); } private void UpdateRendererLocation() { if(this.HideMenuStrip) { IntPtr handle = this.Handle; this.BeginInvoke((MethodInvoker)(() => { int rendererTop = (panelRenderer.Height + (this.menuStrip.Visible ? menuStrip.Height : 0) - ctrlRenderer.Height) / 2; this.ctrlRenderer.Top = rendererTop + (this.menuStrip.Visible ? -menuStrip.Height : 0); this.ctrlRecentGames.Top = this.menuStrip.Visible ? -menuStrip.Height : 0; })); } } private void InitializeNsfMode(bool updateTextOnly = false, bool gameLoaded = false) { if(this.InvokeRequired) { if(InteropEmu.IsNsf()) { if(InteropEmu.IsConnected()) { InteropEmu.Disconnect(); } if(InteropEmu.IsServerRunning()) { InteropEmu.StopServer(); } } this.BeginInvoke((MethodInvoker)(() => this.InitializeNsfMode(updateTextOnly, gameLoaded))); } else { if(InteropEmu.IsNsf()) { if(gameLoaded) { //Force emulation speed to 100 when loading a NSF SetEmulationSpeed(100); } if(!this._isNsfPlayerMode) { this._nonNsfSize = this.WindowState == FormWindowState.Maximized ? this.RestoreBounds.Size : this.Size; this.Size = new Size(380, 320); this.MinimumSize = new Size(380, 320); } this._isNsfPlayerMode = true; this.ctrlNsfPlayer.UpdateText(); if(!updateTextOnly) { this.ctrlNsfPlayer.ResetCount(); } this.ctrlNsfPlayer.Visible = true; this.ctrlNsfPlayer.Focus(); NsfHeader header = InteropEmu.NsfGetHeader(); if(header.HasSongName) { _currentGame = header.GetSongName(); } } else if(this._isNsfPlayerMode) { this.MinimumSize = new Size(340, 280); this.Size = this._nonNsfSize.Value; this._nonNsfSize = null; this._isNsfPlayerMode = false; this.ctrlNsfPlayer.Visible = false; } } } private void panelRenderer_MouseLeave(object sender, EventArgs e) { CursorManager.OnMouseLeave(); } } }