2015-07-01 23:17:14 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2016-05-22 14:43:07 -04:00
|
|
|
|
using System.ComponentModel;
|
2016-01-01 10:21:41 -05:00
|
|
|
|
using System.Diagnostics;
|
2015-07-01 23:17:14 -04:00
|
|
|
|
using System.Drawing;
|
2017-05-06 15:27:48 -04:00
|
|
|
|
using System.Drawing.Text;
|
2015-12-27 18:41:38 -05:00
|
|
|
|
using System.IO;
|
2016-12-09 12:49:17 -05:00
|
|
|
|
using System.Linq;
|
2016-02-08 23:23:31 -05:00
|
|
|
|
using System.Net;
|
2015-07-01 23:17:14 -04:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
2016-02-08 23:23:31 -05:00
|
|
|
|
using System.Xml;
|
2015-07-03 00:12:02 -04:00
|
|
|
|
using Mesen.GUI.Config;
|
2015-07-01 23:17:14 -04:00
|
|
|
|
using Mesen.GUI.Debugger;
|
2015-07-03 00:12:02 -04:00
|
|
|
|
using Mesen.GUI.Forms.Cheats;
|
2015-07-10 21:07:24 -04:00
|
|
|
|
using Mesen.GUI.Forms.Config;
|
2017-06-28 19:00:08 -04:00
|
|
|
|
using Mesen.GUI.Forms.HdPackEditor;
|
2015-07-01 23:17:14 -04:00
|
|
|
|
using Mesen.GUI.Forms.NetPlay;
|
2016-05-22 14:43:07 -04:00
|
|
|
|
using Mesen.GUI.GoogleDriveIntegration;
|
2015-07-01 23:17:14 -04:00
|
|
|
|
|
|
|
|
|
namespace Mesen.GUI.Forms
|
|
|
|
|
{
|
2016-07-28 17:45:18 -04:00
|
|
|
|
public partial class frmMain : BaseForm, IMessageFilter
|
2015-07-01 23:17:14 -04:00
|
|
|
|
{
|
2017-08-08 19:32:50 -04:00
|
|
|
|
private const int WM_KEYDOWN = 0x100;
|
|
|
|
|
private const int WM_KEYUP = 0x101;
|
|
|
|
|
|
2015-07-01 23:17:14 -04:00
|
|
|
|
private InteropEmu.NotificationListener _notifListener;
|
|
|
|
|
private Thread _emuThread;
|
2015-08-05 20:40:10 -04:00
|
|
|
|
private frmDebugger _debugger;
|
2016-06-19 16:54:34 -04:00
|
|
|
|
private frmLogWindow _logWindow;
|
2016-08-25 19:02:33 -04:00
|
|
|
|
private frmCheatList _cheatListWindow;
|
2017-06-28 19:00:08 -04:00
|
|
|
|
private frmHdPackEditor _hdPackEditorWindow;
|
2017-07-30 09:03:54 -04:00
|
|
|
|
private ResourcePath? _currentRomPath = null;
|
2017-08-08 19:32:50 -04:00
|
|
|
|
private Image _pauseButton = Mesen.GUI.Properties.Resources.Pause;
|
|
|
|
|
private Image _playButton = Mesen.GUI.Properties.Resources.Play;
|
2016-01-28 22:34:23 -05:00
|
|
|
|
private string _currentGame = null;
|
2016-02-07 13:05:32 -05:00
|
|
|
|
private bool _customSize = false;
|
2016-05-23 21:35:32 -04:00
|
|
|
|
private FormWindowState _originalWindowState;
|
2016-02-07 13:05:32 -05:00
|
|
|
|
private bool _fullscreenMode = false;
|
2017-08-08 16:10:54 -04:00
|
|
|
|
private Size? _nonNsfSize = null;
|
2016-06-25 20:46:54 -04:00
|
|
|
|
private bool _isNsfPlayerMode = false;
|
2016-06-26 10:43:52 -04:00
|
|
|
|
private object _loadRomLock = new object();
|
|
|
|
|
private int _romLoadCounter = 0;
|
2016-12-21 23:41:39 -05:00
|
|
|
|
private bool _removeFocus = false;
|
2017-08-01 19:47:19 -04:00
|
|
|
|
private bool _showUpgradeMessage = false;
|
2016-02-07 13:05:32 -05:00
|
|
|
|
|
2016-07-29 19:05:15 -04:00
|
|
|
|
private string[] _commandLineArgs;
|
2016-07-23 15:28:52 -04:00
|
|
|
|
private bool _noAudio = false;
|
|
|
|
|
private bool _noVideo = false;
|
|
|
|
|
private bool _noInput = false;
|
|
|
|
|
|
2017-05-06 15:27:48 -04:00
|
|
|
|
private PrivateFontCollection _fonts = new PrivateFontCollection();
|
|
|
|
|
|
2015-12-27 22:05:45 -05:00
|
|
|
|
public frmMain(string[] args)
|
2015-07-01 23:17:14 -04:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2016-07-28 17:45:18 -04:00
|
|
|
|
|
2017-05-01 23:17:51 -04:00
|
|
|
|
if(ConfigManager.Config.WindowLocation.HasValue) {
|
|
|
|
|
this.StartPosition = FormStartPosition.Manual;
|
|
|
|
|
this.Location = ConfigManager.Config.WindowLocation.Value;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-02 00:00:27 -04:00
|
|
|
|
Version currentVersion = new Version(InteropEmu.GetMesenVersion());
|
|
|
|
|
lblVersion.Text = currentVersion.ToString();
|
|
|
|
|
|
2017-05-06 15:27:48 -04:00
|
|
|
|
_fonts.AddFontFile(Path.Combine(ConfigManager.HomeFolder, "Resources", "PixelFont.ttf"));
|
|
|
|
|
lblVersion.Font = new Font(_fonts.Families[0], 11);
|
|
|
|
|
|
2016-07-29 19:05:15 -04:00
|
|
|
|
_commandLineArgs = args;
|
2017-07-30 09:03:54 -04:00
|
|
|
|
|
2016-07-28 17:45:18 -04:00
|
|
|
|
Application.AddMessageFilter(this);
|
2017-05-06 20:01:48 -04:00
|
|
|
|
this.Resize += ResizeRecentGames;
|
2016-07-28 17:45:18 -04:00
|
|
|
|
this.FormClosed += (s, e) => Application.RemoveMessageFilter(this);
|
2015-07-14 21:53:01 -04:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-29 19:05:15 -04:00
|
|
|
|
public void ProcessCommandLineArguments(string[] args, bool forStartup)
|
2015-12-27 22:05:45 -05:00
|
|
|
|
{
|
2017-03-19 13:05:33 -04:00
|
|
|
|
var switches = new List<string>();
|
|
|
|
|
for(int i = 0; i < args.Length; i++) {
|
2017-04-04 07:48:48 -04:00
|
|
|
|
if(args[i] != null) {
|
|
|
|
|
switches.Add(args[i].ToLowerInvariant().Replace("--", "/").Replace("-", "/").Replace("=/", "=-"));
|
|
|
|
|
}
|
2017-03-19 13:05:33 -04:00
|
|
|
|
}
|
2016-07-29 19:05:15 -04:00
|
|
|
|
|
2017-03-19 13:05:33 -04:00
|
|
|
|
if(forStartup) {
|
2016-07-29 19:05:15 -04:00
|
|
|
|
_noVideo = switches.Contains("/novideo");
|
|
|
|
|
_noAudio = switches.Contains("/noaudio");
|
|
|
|
|
_noInput = switches.Contains("/noinput");
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-19 13:05:33 -04:00
|
|
|
|
if(switches.Contains("/fullscreen")) {
|
|
|
|
|
this.SetFullscreenState(true);
|
|
|
|
|
}
|
|
|
|
|
if(switches.Contains("/donotsavesettings")) {
|
|
|
|
|
ConfigManager.DoNotSaveSettings = true;
|
|
|
|
|
}
|
|
|
|
|
ConfigManager.ProcessSwitches(switches);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LoadGameFromCommandLine(string[] args)
|
|
|
|
|
{
|
2016-07-29 19:05:15 -04:00
|
|
|
|
if(args.Length > 0) {
|
|
|
|
|
foreach(string arg in args) {
|
2017-04-09 08:33:24 -04:00
|
|
|
|
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 { }
|
|
|
|
|
}
|
2016-07-29 19:05:15 -04:00
|
|
|
|
}
|
2015-12-27 22:05:45 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-14 21:53:01 -04:00
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnLoad(e);
|
2015-07-01 23:17:14 -04:00
|
|
|
|
|
2017-08-08 19:32:50 -04:00
|
|
|
|
#if HIDETESTMENU
|
2016-02-11 20:35:40 -05:00
|
|
|
|
mnuTests.Visible = false;
|
2017-08-08 19:32:50 -04:00
|
|
|
|
#endif
|
2016-02-11 20:35:40 -05:00
|
|
|
|
|
2017-08-01 19:47:19 -04:00
|
|
|
|
PerformUpgrade();
|
|
|
|
|
|
2015-07-01 23:17:14 -04:00
|
|
|
|
_notifListener = new InteropEmu.NotificationListener();
|
|
|
|
|
_notifListener.OnNotification += _notifListener_OnNotification;
|
|
|
|
|
|
2015-08-30 21:04:21 -04:00
|
|
|
|
menuTimer.Start();
|
2017-07-30 09:03:54 -04:00
|
|
|
|
|
2017-03-19 13:05:33 -04:00
|
|
|
|
this.ProcessCommandLineArguments(_commandLineArgs, true);
|
2015-08-30 21:04:21 -04:00
|
|
|
|
|
2016-02-06 18:33:24 -05:00
|
|
|
|
VideoInfo.ApplyConfig();
|
2016-04-30 20:08:53 -04:00
|
|
|
|
InitializeVsSystemMenu();
|
2016-01-28 20:47:16 -05:00
|
|
|
|
InitializeFdsDiskMenu();
|
2015-08-24 20:27:07 -04:00
|
|
|
|
InitializeEmulationSpeedMenu();
|
2017-07-30 09:03:54 -04:00
|
|
|
|
|
2015-07-23 23:16:31 -04:00
|
|
|
|
UpdateVideoSettings();
|
2015-12-27 18:41:38 -05:00
|
|
|
|
|
2015-07-05 22:23:44 -04:00
|
|
|
|
InitializeEmu();
|
2015-07-05 19:05:33 -04:00
|
|
|
|
|
2015-07-01 23:17:14 -04:00
|
|
|
|
UpdateMenus();
|
|
|
|
|
UpdateRecentFiles();
|
2015-07-03 00:12:02 -04:00
|
|
|
|
|
2016-02-07 13:05:32 -05:00
|
|
|
|
UpdateViewerSize();
|
|
|
|
|
|
2016-05-22 14:43:07 -04:00
|
|
|
|
if(ConfigManager.Config.PreferenceInfo.CloudSaveIntegration) {
|
|
|
|
|
Task.Run(() => CloudSyncHelper.Sync());
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-19 13:05:33 -04:00
|
|
|
|
this.LoadGameFromCommandLine(_commandLineArgs);
|
2016-02-08 23:23:31 -05:00
|
|
|
|
|
|
|
|
|
if(ConfigManager.Config.PreferenceInfo.AutomaticallyCheckForUpdates) {
|
|
|
|
|
CheckForUpdates(false);
|
|
|
|
|
}
|
2017-08-08 16:10:54 -04:00
|
|
|
|
|
|
|
|
|
if(ConfigManager.Config.WindowSize.HasValue) {
|
|
|
|
|
this.ClientSize = ConfigManager.Config.WindowSize.Value;
|
|
|
|
|
}
|
2015-07-01 23:17:14 -04:00
|
|
|
|
}
|
2017-07-30 09:03:54 -04:00
|
|
|
|
|
2016-07-28 17:45:18 -04:00
|
|
|
|
protected override void OnDeactivate(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnDeactivate(e);
|
2016-12-21 23:41:39 -05:00
|
|
|
|
_removeFocus = true;
|
2016-07-28 17:45:18 -04:00
|
|
|
|
InteropEmu.ResetKeyState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnActivated(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnActivated(e);
|
2016-12-21 23:41:39 -05:00
|
|
|
|
_removeFocus = false;
|
2016-07-28 17:45:18 -04:00
|
|
|
|
InteropEmu.ResetKeyState();
|
|
|
|
|
}
|
2016-02-08 23:23:31 -05:00
|
|
|
|
|
|
|
|
|
protected override void OnShown(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnShown(e);
|
|
|
|
|
|
2017-08-01 19:47:19 -04:00
|
|
|
|
if(_showUpgradeMessage) {
|
|
|
|
|
MesenMsgBox.Show("UpgradeSuccess", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
_showUpgradeMessage = false;
|
|
|
|
|
}
|
2017-08-08 16:10:54 -04:00
|
|
|
|
|
|
|
|
|
if(ConfigManager.Config.WindowSize.HasValue) {
|
|
|
|
|
this.Size = ConfigManager.Config.WindowSize.Value;
|
|
|
|
|
}
|
2016-02-08 23:23:31 -05:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-22 14:43:07 -04:00
|
|
|
|
protected override void OnClosing(CancelEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(_notifListener != null) {
|
|
|
|
|
_notifListener.Dispose();
|
|
|
|
|
_notifListener = null;
|
|
|
|
|
}
|
|
|
|
|
if(_debugger != null) {
|
|
|
|
|
_debugger.Close();
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-11 08:29:34 -04:00
|
|
|
|
ConfigManager.Config.EmulationInfo.EmulationSpeed = InteropEmu.GetEmulationSpeed();
|
2017-05-01 23:17:51 -04:00
|
|
|
|
if(this.WindowState == FormWindowState.Normal) {
|
|
|
|
|
ConfigManager.Config.WindowLocation = this.Location;
|
2017-08-08 16:10:54 -04:00
|
|
|
|
ConfigManager.Config.WindowSize = this.Size;
|
2017-05-01 23:17:51 -04:00
|
|
|
|
} else {
|
|
|
|
|
ConfigManager.Config.WindowLocation = this.RestoreBounds.Location;
|
2017-08-08 16:10:54 -04:00
|
|
|
|
ConfigManager.Config.WindowSize = this.RestoreBounds.Size;
|
|
|
|
|
}
|
|
|
|
|
if(this._nonNsfSize.HasValue) {
|
|
|
|
|
ConfigManager.Config.WindowSize = this._nonNsfSize.Value;
|
2017-05-01 23:17:51 -04:00
|
|
|
|
}
|
2017-08-08 16:10:54 -04:00
|
|
|
|
|
2016-05-22 14:43:07 -04:00
|
|
|
|
ConfigManager.ApplyChanges();
|
|
|
|
|
|
|
|
|
|
StopEmu();
|
|
|
|
|
|
|
|
|
|
if(ConfigManager.Config.PreferenceInfo.CloudSaveIntegration) {
|
|
|
|
|
CloudSyncHelper.Sync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InteropEmu.Release();
|
|
|
|
|
|
2016-09-07 19:55:57 -04:00
|
|
|
|
ConfigManager.SaveConfig();
|
|
|
|
|
|
2016-05-22 14:43:07 -04:00
|
|
|
|
base.OnClosing(e);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-30 21:04:21 -04:00
|
|
|
|
private void menuTimer_Tick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.UpdateMenus();
|
|
|
|
|
}
|
2015-07-01 23:17:14 -04:00
|
|
|
|
|
2015-07-05 22:23:44 -04:00
|
|
|
|
void InitializeEmu()
|
|
|
|
|
{
|
2016-07-23 15:28:52 -04:00
|
|
|
|
InteropEmu.InitializeEmu(ConfigManager.HomeFolder, this.Handle, this.ctrlRenderer.Handle, _noAudio, _noVideo, _noInput);
|
2016-06-26 10:43:52 -04:00
|
|
|
|
foreach(RecentItem recentItem in ConfigManager.Config.RecentFiles) {
|
2017-07-30 09:03:54 -04:00
|
|
|
|
InteropEmu.AddKnownGameFolder(recentItem.RomFile.Folder);
|
2015-07-05 22:23:44 -04:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-28 17:45:18 -04:00
|
|
|
|
ConfigManager.Config.InitializeDefaults();
|
|
|
|
|
ConfigManager.ApplyChanges();
|
|
|
|
|
|
2015-07-21 23:05:27 -04:00
|
|
|
|
ConfigManager.Config.ApplyConfig();
|
2017-07-30 09:03:54 -04:00
|
|
|
|
|
2015-07-17 21:18:57 -04:00
|
|
|
|
UpdateEmulationFlags();
|
|
|
|
|
}
|
2015-08-23 20:24:24 -04:00
|
|
|
|
|
2016-01-06 20:34:45 -05:00
|
|
|
|
private void UpdateViewerSize()
|
|
|
|
|
{
|
2017-08-08 16:10:54 -04:00
|
|
|
|
this.Resize -= frmMain_Resize;
|
|
|
|
|
|
2016-02-07 13:05:32 -05:00
|
|
|
|
InteropEmu.ScreenSize size = InteropEmu.GetScreenSize(false);
|
|
|
|
|
|
2016-12-30 16:43:49 -05:00
|
|
|
|
if(!_customSize && this.WindowState != FormWindowState.Maximized) {
|
|
|
|
|
Size sizeGap = this.Size - this.ClientSize;
|
2016-12-22 23:08:34 -05:00
|
|
|
|
|
2016-12-30 16:43:49 -05:00
|
|
|
|
UpdateScaleMenu(size.Scale);
|
2017-04-22 16:54:45 -04:00
|
|
|
|
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)));
|
2016-12-09 12:01:44 -05:00
|
|
|
|
}
|
2016-12-30 16:43:49 -05:00
|
|
|
|
|
|
|
|
|
ctrlRenderer.Size = new Size(size.Width, size.Height);
|
|
|
|
|
ctrlRenderer.Left = (panelRenderer.Width - ctrlRenderer.Width) / 2;
|
|
|
|
|
ctrlRenderer.Top = (panelRenderer.Height - ctrlRenderer.Height) / 2;
|
2017-04-22 16:54:45 -04:00
|
|
|
|
|
|
|
|
|
if(this.HideMenuStrip) {
|
|
|
|
|
this.menuStrip.Visible = false;
|
|
|
|
|
}
|
2017-08-08 16:10:54 -04:00
|
|
|
|
|
|
|
|
|
this.Resize += frmMain_Resize;
|
2016-02-07 13:05:32 -05:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-06 20:01:48 -04:00
|
|
|
|
private void ResizeRecentGames(object sender, EventArgs e)
|
2017-05-06 15:27:48 -04:00
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
2017-05-28 10:33:09 -04:00
|
|
|
|
ctrlRecentGames.Width = this.ClientSize.Width;
|
|
|
|
|
ctrlRecentGames.Top = (this.HideMenuStrip && this.menuStrip.Visible) ? -menuStrip.Height : 0;
|
2017-05-06 15:27:48 -04:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-07 13:05:32 -05:00
|
|
|
|
private void frmMain_Resize(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(this.WindowState != FormWindowState.Minimized) {
|
|
|
|
|
SetScaleBasedOnWindowSize();
|
2016-06-25 20:46:54 -04:00
|
|
|
|
ctrlRenderer.Left = (panelRenderer.Width - ctrlRenderer.Width) / 2;
|
|
|
|
|
ctrlRenderer.Top = (panelRenderer.Height - ctrlRenderer.Height) / 2;
|
2016-02-07 13:05:32 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-30 09:03:54 -04:00
|
|
|
|
|
2016-02-07 13:05:32 -05:00
|
|
|
|
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);
|
2017-08-03 21:55:31 -04:00
|
|
|
|
if(_fullscreenMode && ConfigManager.Config.VideoInfo.FullscreenForceIntegerScale) {
|
|
|
|
|
scale = Math.Floor(scale);
|
|
|
|
|
}
|
2016-02-07 13:05:32 -05:00
|
|
|
|
UpdateScaleMenu(scale);
|
|
|
|
|
VideoInfo.ApplyConfig();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetFullscreenState(bool enabled)
|
|
|
|
|
{
|
|
|
|
|
this.Resize -= frmMain_Resize;
|
2017-05-01 19:03:54 -04:00
|
|
|
|
_fullscreenMode = enabled;
|
2016-02-07 13:05:32 -05:00
|
|
|
|
if(enabled) {
|
|
|
|
|
this.menuStrip.Visible = false;
|
2016-05-23 21:35:32 -04:00
|
|
|
|
_originalWindowState = this.WindowState;
|
2016-02-07 13:05:32 -05:00
|
|
|
|
this.WindowState = FormWindowState.Normal;
|
|
|
|
|
this.FormBorderStyle = FormBorderStyle.None;
|
|
|
|
|
this.WindowState = FormWindowState.Maximized;
|
|
|
|
|
SetScaleBasedOnWindowSize();
|
|
|
|
|
} else {
|
|
|
|
|
this.menuStrip.Visible = true;
|
2016-05-23 21:35:32 -04:00
|
|
|
|
this.WindowState = _originalWindowState;
|
2016-02-07 13:05:32 -05:00
|
|
|
|
this.FormBorderStyle = FormBorderStyle.Sizable;
|
2017-08-08 16:10:54 -04:00
|
|
|
|
this.frmMain_Resize(null, EventArgs.Empty);
|
2016-02-07 13:05:32 -05:00
|
|
|
|
}
|
|
|
|
|
this.Resize += frmMain_Resize;
|
2016-07-29 19:05:15 -04:00
|
|
|
|
mnuFullscreen.Checked = enabled;
|
2015-07-23 23:16:31 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-22 16:54:45 -04:00
|
|
|
|
private bool HideMenuStrip
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _fullscreenMode || ConfigManager.Config.PreferenceInfo.AutoHideMenu;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-23 21:35:32 -04:00
|
|
|
|
private void ctrlRenderer_MouseMove(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
2017-06-08 20:38:48 -04:00
|
|
|
|
if(sender != this.ctrlRecentGames) {
|
|
|
|
|
CursorManager.OnMouseMove((Control)sender);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-22 16:54:45 -04:00
|
|
|
|
if(this.HideMenuStrip && !this.menuStrip.ContainsFocus) {
|
|
|
|
|
if(sender == ctrlRenderer) {
|
|
|
|
|
this.menuStrip.Visible = ctrlRenderer.Top + e.Y < 30;
|
|
|
|
|
} else {
|
|
|
|
|
this.menuStrip.Visible = e.Y < 30;
|
|
|
|
|
}
|
2016-05-23 21:35:32 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ctrlRenderer_MouseClick(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
2017-04-22 16:54:45 -04:00
|
|
|
|
if(this.HideMenuStrip) {
|
2016-05-23 21:35:32 -04:00
|
|
|
|
this.menuStrip.Visible = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-27 18:41:38 -05:00
|
|
|
|
private void _notifListener_OnNotification(InteropEmu.NotificationEventArgs e)
|
2015-07-01 23:17:14 -04:00
|
|
|
|
{
|
2016-01-28 20:47:16 -05:00
|
|
|
|
switch(e.NotificationType) {
|
|
|
|
|
case InteropEmu.ConsoleNotificationType.GameLoaded:
|
2016-06-17 20:53:05 -04:00
|
|
|
|
_currentGame = InteropEmu.GetRomInfo().GetRomName();
|
2017-05-22 11:50:21 -04:00
|
|
|
|
InteropEmu.SetNesModel(ConfigManager.Config.Region);
|
2016-06-26 17:13:10 -04:00
|
|
|
|
InitializeNsfMode(false, true);
|
2016-01-28 20:47:16 -05:00
|
|
|
|
InitializeFdsDiskMenu();
|
2016-04-30 20:08:53 -04:00
|
|
|
|
InitializeVsSystemMenu();
|
2016-01-28 20:47:16 -05:00
|
|
|
|
CheatInfo.ApplyCheats();
|
2016-04-30 20:08:53 -04:00
|
|
|
|
VsConfigInfo.ApplyConfig();
|
2016-01-28 20:47:16 -05:00
|
|
|
|
InitializeStateMenu(mnuSaveState, true);
|
|
|
|
|
InitializeStateMenu(mnuLoadState, false);
|
2017-05-22 20:14:02 -04:00
|
|
|
|
if(ConfigManager.Config.PreferenceInfo.ShowVsConfigOnLoad && InteropEmu.IsVsSystem()) {
|
|
|
|
|
this.Invoke((MethodInvoker)(() => {
|
|
|
|
|
this.ShowVsGameConfig();
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-28 20:47:16 -05:00
|
|
|
|
this.StartEmuThread();
|
2016-12-30 18:31:50 -05:00
|
|
|
|
this.BeginInvoke((MethodInvoker)(() => {
|
|
|
|
|
UpdateViewerSize();
|
|
|
|
|
}));
|
2016-01-28 20:47:16 -05:00
|
|
|
|
break;
|
|
|
|
|
|
2016-06-25 20:46:54 -04:00
|
|
|
|
case InteropEmu.ConsoleNotificationType.PpuFrameDone:
|
|
|
|
|
if(InteropEmu.IsNsf()) {
|
|
|
|
|
this.ctrlNsfPlayer.CountFrame();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case InteropEmu.ConsoleNotificationType.GameReset:
|
|
|
|
|
InitializeNsfMode();
|
|
|
|
|
break;
|
|
|
|
|
|
2016-02-05 23:14:27 -05:00
|
|
|
|
case InteropEmu.ConsoleNotificationType.DisconnectedFromServer:
|
|
|
|
|
ConfigManager.Config.ApplyConfig();
|
|
|
|
|
break;
|
|
|
|
|
|
2016-01-28 20:47:16 -05:00
|
|
|
|
case InteropEmu.ConsoleNotificationType.GameStopped:
|
2017-05-06 15:27:48 -04:00
|
|
|
|
this._currentGame = null;
|
2017-08-08 23:09:53 -04:00
|
|
|
|
InitializeNsfMode();
|
2016-01-28 20:47:16 -05:00
|
|
|
|
CheatInfo.ClearCheats();
|
2017-05-06 15:27:48 -04:00
|
|
|
|
this.BeginInvoke((MethodInvoker)(() => {
|
2017-06-28 19:00:08 -04:00
|
|
|
|
if(_hdPackEditorWindow != null) {
|
|
|
|
|
_hdPackEditorWindow.Close();
|
|
|
|
|
}
|
2017-05-06 15:27:48 -04:00
|
|
|
|
ctrlRecentGames.Initialize();
|
|
|
|
|
}));
|
2016-01-28 20:47:16 -05:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case InteropEmu.ConsoleNotificationType.ResolutionChanged:
|
|
|
|
|
this.BeginInvoke((MethodInvoker)(() => {
|
2016-12-22 23:08:34 -05:00
|
|
|
|
UpdateViewerSize();
|
2016-01-28 20:47:16 -05:00
|
|
|
|
}));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case InteropEmu.ConsoleNotificationType.FdsBiosNotFound:
|
|
|
|
|
this.BeginInvoke((MethodInvoker)(() => {
|
|
|
|
|
SelectFdsBiosPrompt();
|
|
|
|
|
}));
|
|
|
|
|
break;
|
2017-02-18 13:59:58 -05:00
|
|
|
|
|
|
|
|
|
case InteropEmu.ConsoleNotificationType.RequestExit:
|
|
|
|
|
this.BeginInvoke((MethodInvoker)(() => this.Close()));
|
|
|
|
|
break;
|
2017-03-19 14:21:53 -04:00
|
|
|
|
|
|
|
|
|
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;
|
2017-05-25 20:31:20 -04:00
|
|
|
|
|
|
|
|
|
case InteropEmu.ConsoleNotificationType.ToggleAudio:
|
|
|
|
|
this.BeginInvoke((MethodInvoker)(() => {
|
|
|
|
|
ConfigManager.Config.AudioInfo.EnableAudio = !ConfigManager.Config.AudioInfo.EnableAudio;
|
|
|
|
|
AudioInfo.ApplyConfig();
|
|
|
|
|
ConfigManager.ApplyChanges();
|
|
|
|
|
}));
|
|
|
|
|
break;
|
2015-07-01 23:17:14 -04:00
|
|
|
|
}
|
2016-06-25 20:46:54 -04:00
|
|
|
|
|
|
|
|
|
if(e.NotificationType != InteropEmu.ConsoleNotificationType.PpuFrameDone) {
|
|
|
|
|
UpdateMenus();
|
|
|
|
|
}
|
2015-07-01 23:17:14 -04:00
|
|
|
|
}
|
2017-08-08 19:32:50 -04:00
|
|
|
|
|
2016-01-31 13:53:17 -05:00
|
|
|
|
private void UpdateFocusFlag()
|
|
|
|
|
{
|
|
|
|
|
bool hasFocus = false;
|
2016-02-14 12:58:35 -05:00
|
|
|
|
if(Application.OpenForms.Count > 0) {
|
|
|
|
|
if(Application.OpenForms[0].ContainsFocus) {
|
2016-01-31 13:53:17 -05:00
|
|
|
|
hasFocus = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-21 23:41:39 -05:00
|
|
|
|
if(_removeFocus) {
|
|
|
|
|
hasFocus = false;
|
2016-02-14 12:58:35 -05:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-31 13:53:17 -05:00
|
|
|
|
InteropEmu.SetFlag(EmulationFlags.InBackground, !hasFocus);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-01 23:17:14 -04:00
|
|
|
|
private void UpdateMenus()
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
if(this.InvokeRequired) {
|
|
|
|
|
this.BeginInvoke((MethodInvoker)(() => this.UpdateMenus()));
|
|
|
|
|
} else {
|
2017-05-06 15:27:48 -04:00
|
|
|
|
panelInfo.Visible = _emuThread == null;
|
2017-07-25 22:43:39 -04:00
|
|
|
|
ctrlRecentGames.Visible = _emuThread == null;
|
2017-05-02 00:00:27 -04:00
|
|
|
|
|
2016-06-26 10:43:52 -04:00
|
|
|
|
ctrlLoading.Visible = (_romLoadCounter > 0);
|
|
|
|
|
|
2016-01-31 13:53:17 -05:00
|
|
|
|
UpdateFocusFlag();
|
2017-04-22 16:54:45 -04:00
|
|
|
|
UpdateWindowTitle();
|
2015-08-23 20:24:24 -04:00
|
|
|
|
|
2016-02-05 23:14:27 -05:00
|
|
|
|
bool isNetPlayClient = InteropEmu.IsConnected();
|
|
|
|
|
|
2017-07-30 09:03:54 -04:00
|
|
|
|
mnuPause.Enabled = mnuPowerCycle.Enabled = mnuReset.Enabled = mnuPowerOff.Enabled = (_emuThread != null && !isNetPlayClient);
|
2016-07-19 16:36:07 -04:00
|
|
|
|
mnuSaveState.Enabled = (_emuThread != null && !isNetPlayClient && !InteropEmu.IsNsf());
|
|
|
|
|
mnuLoadState.Enabled = (_emuThread != null && !isNetPlayClient && !InteropEmu.IsNsf() && !InteropEmu.MoviePlaying() && !InteropEmu.MovieRecording());
|
|
|
|
|
|
2016-02-19 13:05:04 -05:00
|
|
|
|
mnuPause.Text = InteropEmu.IsPaused() ? ResourceHelper.GetMessage("Resume") : ResourceHelper.GetMessage("Pause");
|
2017-03-09 23:50:20 -05:00
|
|
|
|
mnuPause.Image = InteropEmu.IsPaused() ? _playButton : _pauseButton;
|
2015-07-01 23:17:14 -04:00
|
|
|
|
|
2016-02-05 23:14:27 -05:00
|
|
|
|
bool netPlay = InteropEmu.IsServerRunning() || isNetPlayClient;
|
2015-07-01 23:17:14 -04:00
|
|
|
|
|
2016-02-05 23:14:27 -05:00
|
|
|
|
mnuStartServer.Enabled = !isNetPlayClient;
|
|
|
|
|
mnuConnect.Enabled = !InteropEmu.IsServerRunning();
|
2016-02-06 15:33:45 -05:00
|
|
|
|
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;
|
2016-02-19 13:05:04 -05:00
|
|
|
|
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)) + ")";
|
2016-02-06 15:33:45 -05:00
|
|
|
|
|
|
|
|
|
mnuNetPlayPlayer1.Checked = (currentControllerPort == 0);
|
|
|
|
|
mnuNetPlayPlayer2.Checked = (currentControllerPort == 1);
|
|
|
|
|
mnuNetPlayPlayer3.Checked = (currentControllerPort == 2);
|
|
|
|
|
mnuNetPlayPlayer4.Checked = (currentControllerPort == 3);
|
|
|
|
|
mnuNetPlaySpectator.Checked = (currentControllerPort == 0xFF);
|
|
|
|
|
|
|
|
|
|
mnuNetPlaySpectator.Enabled = true;
|
|
|
|
|
}
|
2015-07-01 23:17:14 -04:00
|
|
|
|
|
2016-02-19 13:05:04 -05:00
|
|
|
|
mnuStartServer.Text = InteropEmu.IsServerRunning() ? ResourceHelper.GetMessage("StopServer") : ResourceHelper.GetMessage("StartServer");
|
|
|
|
|
mnuConnect.Text = isNetPlayClient ? ResourceHelper.GetMessage("Disconnect") : ResourceHelper.GetMessage("ConnectToServer");
|
2015-07-01 23:17:14 -04:00
|
|
|
|
|
2016-02-05 23:14:27 -05:00
|
|
|
|
mnuCheats.Enabled = !isNetPlayClient;
|
|
|
|
|
mnuEmulationSpeed.Enabled = !isNetPlayClient;
|
|
|
|
|
mnuIncreaseSpeed.Enabled = !isNetPlayClient;
|
|
|
|
|
mnuDecreaseSpeed.Enabled = !isNetPlayClient;
|
|
|
|
|
mnuEmuSpeedMaximumSpeed.Enabled = !isNetPlayClient;
|
|
|
|
|
mnuInput.Enabled = !isNetPlayClient;
|
|
|
|
|
mnuRegion.Enabled = !isNetPlayClient;
|
2015-08-23 20:24:24 -04:00
|
|
|
|
|
2015-07-01 23:17:14 -04:00
|
|
|
|
bool moviePlaying = InteropEmu.MoviePlaying();
|
|
|
|
|
bool movieRecording = InteropEmu.MovieRecording();
|
2015-07-05 22:23:44 -04:00
|
|
|
|
mnuPlayMovie.Enabled = !netPlay && !moviePlaying && !movieRecording;
|
2015-07-01 23:17:14 -04:00
|
|
|
|
mnuStopMovie.Enabled = _emuThread != null && !netPlay && (moviePlaying || movieRecording);
|
|
|
|
|
mnuRecordFrom.Enabled = _emuThread != null && !moviePlaying && !movieRecording;
|
2016-02-05 23:14:27 -05:00
|
|
|
|
mnuRecordFromStart.Enabled = _emuThread != null && !isNetPlayClient && !moviePlaying && !movieRecording;
|
2015-07-01 23:17:14 -04:00
|
|
|
|
mnuRecordFromNow.Enabled = _emuThread != null && !moviePlaying && !movieRecording;
|
|
|
|
|
|
2016-06-05 14:36:20 -04:00
|
|
|
|
bool waveRecording = InteropEmu.WaveIsRecording();
|
|
|
|
|
mnuWaveRecord.Enabled = _emuThread != null && !waveRecording;
|
|
|
|
|
mnuWaveStop.Enabled = _emuThread != null && waveRecording;
|
|
|
|
|
|
2016-12-29 21:19:13 -05:00
|
|
|
|
bool aviRecording = InteropEmu.AviIsRecording();
|
|
|
|
|
mnuAviRecord.Enabled = _emuThread != null && !aviRecording;
|
|
|
|
|
mnuAviStop.Enabled = _emuThread != null && aviRecording;
|
2017-04-30 01:16:33 -04:00
|
|
|
|
mnuVideoRecorder.Enabled = !_isNsfPlayerMode;
|
2016-12-29 21:19:13 -05:00
|
|
|
|
|
2015-12-26 17:11:00 -05:00
|
|
|
|
bool testRecording = InteropEmu.RomTestRecording();
|
|
|
|
|
mnuTestRun.Enabled = !netPlay && !moviePlaying && !movieRecording;
|
|
|
|
|
mnuTestStopRecording.Enabled = _emuThread != null && testRecording;
|
2016-02-05 23:14:27 -05:00
|
|
|
|
mnuTestRecordStart.Enabled = _emuThread != null && !isNetPlayClient && !moviePlaying && !movieRecording;
|
2015-12-26 17:11:00 -05:00
|
|
|
|
mnuTestRecordNow.Enabled = _emuThread != null && !moviePlaying && !movieRecording;
|
2015-12-27 09:13:52 -05:00
|
|
|
|
mnuTestRecordMovie.Enabled = !netPlay && !moviePlaying && !movieRecording;
|
|
|
|
|
mnuTestRecordTest.Enabled = !netPlay && !moviePlaying && !movieRecording;
|
|
|
|
|
mnuTestRecordFrom.Enabled = (mnuTestRecordStart.Enabled || mnuTestRecordNow.Enabled || mnuTestRecordMovie.Enabled || mnuTestRecordTest.Enabled);
|
2015-12-26 17:11:00 -05:00
|
|
|
|
|
2015-07-01 23:17:14 -04:00
|
|
|
|
mnuDebugger.Enabled = !netPlay && _emuThread != null;
|
2017-06-28 19:00:08 -04:00
|
|
|
|
mnuHdPackEditor.Enabled = !netPlay && _emuThread != null;
|
2015-07-01 23:17:14 -04:00
|
|
|
|
|
2016-07-18 17:28:33 -04:00
|
|
|
|
mnuTakeScreenshot.Enabled = _emuThread != null && !InteropEmu.IsNsf();
|
2016-08-26 17:52:30 -04:00
|
|
|
|
mnuNetPlay.Enabled = !InteropEmu.IsNsf();
|
|
|
|
|
if(_emuThread != null && InteropEmu.IsNsf()) {
|
2016-12-06 18:22:50 -05:00
|
|
|
|
mnuPowerCycle.Enabled = false;
|
2016-08-26 17:52:30 -04:00
|
|
|
|
mnuMovies.Enabled = mnuPlayMovie.Enabled = mnuStopMovie.Enabled = mnuRecordFrom.Enabled = mnuRecordFromStart.Enabled = mnuRecordFromNow.Enabled = false;
|
|
|
|
|
}
|
2015-07-21 23:05:27 -04:00
|
|
|
|
|
|
|
|
|
mnuRegionAuto.Checked = ConfigManager.Config.Region == NesModel.Auto;
|
|
|
|
|
mnuRegionNtsc.Checked = ConfigManager.Config.Region == NesModel.NTSC;
|
|
|
|
|
mnuRegionPal.Checked = ConfigManager.Config.Region == NesModel.PAL;
|
2016-01-30 19:33:32 -05:00
|
|
|
|
mnuRegionDendy.Checked = ConfigManager.Config.Region == NesModel.Dendy;
|
2017-05-19 20:28:00 -04:00
|
|
|
|
|
2017-07-30 09:03:54 -04:00
|
|
|
|
bool autoInsertDisabled = !InteropEmu.FdsIsAutoInsertDiskEnabled();
|
2017-05-19 20:28:00 -04:00
|
|
|
|
mnuSelectDisk.Enabled = autoInsertDisabled;
|
|
|
|
|
mnuEjectDisk.Enabled = autoInsertDisabled;
|
|
|
|
|
mnuSwitchDiskSide.Enabled = autoInsertDisabled;
|
2015-07-01 23:17:14 -04:00
|
|
|
|
}
|
|
|
|
|
} catch { }
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-22 16:54:45 -04:00
|
|
|
|
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;
|
|
|
|
|
}
|
2017-08-08 19:32:50 -04:00
|
|
|
|
|
2015-07-01 23:17:14 -04:00
|
|
|
|
private void StartEmuThread()
|
|
|
|
|
{
|
|
|
|
|
if(_emuThread == null) {
|
|
|
|
|
_emuThread = new Thread(() => {
|
|
|
|
|
try {
|
|
|
|
|
InteropEmu.Run();
|
|
|
|
|
_emuThread = null;
|
|
|
|
|
} catch(Exception ex) {
|
2016-02-19 13:05:04 -05:00
|
|
|
|
MesenMsgBox.Show("UnexpectedError", MessageBoxButtons.OK, MessageBoxIcon.Error, ex.ToString());
|
2017-05-26 07:27:38 -04:00
|
|
|
|
_emuThread = null;
|
2015-07-01 23:17:14 -04:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
_emuThread.Start();
|
|
|
|
|
}
|
|
|
|
|
UpdateMenus();
|
|
|
|
|
}
|
2017-07-30 09:03:54 -04:00
|
|
|
|
|
2015-07-01 23:17:14 -04:00
|
|
|
|
private void StopEmu()
|
|
|
|
|
{
|
|
|
|
|
InteropEmu.Stop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void PauseEmu()
|
|
|
|
|
{
|
2017-06-28 23:18:51 -04:00
|
|
|
|
if(InteropEmu.DebugIsDebuggerRunning()) {
|
|
|
|
|
InteropEmu.DebugStep(1);
|
2015-07-01 23:17:14 -04:00
|
|
|
|
} else {
|
2017-06-28 23:18:51 -04:00
|
|
|
|
if(InteropEmu.IsPaused()) {
|
|
|
|
|
InteropEmu.Resume();
|
|
|
|
|
} else {
|
|
|
|
|
InteropEmu.Pause();
|
|
|
|
|
}
|
2016-06-25 20:46:54 -04:00
|
|
|
|
|
2017-06-28 23:18:51 -04:00
|
|
|
|
ctrlNsfPlayer.UpdateText();
|
|
|
|
|
}
|
2015-07-01 23:17:14 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ResetEmu()
|
|
|
|
|
{
|
|
|
|
|
InteropEmu.Reset();
|
|
|
|
|
}
|
2016-02-07 13:05:32 -05:00
|
|
|
|
|
2016-07-28 17:45:18 -04:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-01 23:17:14 -04:00
|
|
|
|
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
|
|
|
|
|
{
|
2016-07-28 17:45:18 -04:00
|
|
|
|
if(msg.Msg == WM_KEYDOWN) {
|
|
|
|
|
int scanCode = (Int32)(((Int64)msg.LParam & 0x1FF0000) >> 16);
|
|
|
|
|
InteropEmu.SetKeyState(scanCode, true);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-27 09:13:52 -05:00
|
|
|
|
if(!this.menuStrip.Enabled) {
|
|
|
|
|
//Make sure we disable all shortcut keys while the bar is disabled (i.e when running tests)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-22 16:54:45 -04:00
|
|
|
|
if(this.HideMenuStrip && (keyData & Keys.Alt) == Keys.Alt) {
|
2016-02-07 13:05:32 -05:00
|
|
|
|
if(this.menuStrip.Visible && !this.menuStrip.ContainsFocus) {
|
|
|
|
|
this.menuStrip.Visible = false;
|
|
|
|
|
} else {
|
|
|
|
|
this.menuStrip.Visible = true;
|
|
|
|
|
this.menuStrip.Focus();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-08 19:32:50 -04:00
|
|
|
|
#if !HIDETESTMENU
|
2016-08-27 13:25:38 -04:00
|
|
|
|
if(keyData == Keys.Pause) {
|
|
|
|
|
if(InteropEmu.RomTestRecording()) {
|
|
|
|
|
InteropEmu.RomTestStop();
|
|
|
|
|
} else {
|
|
|
|
|
InteropEmu.RomTestRecord(ConfigManager.TestFolder + "\\" + InteropEmu.GetRomInfo().GetRomName() + ".mtp", true);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-08 19:32:50 -04:00
|
|
|
|
#endif
|
2016-08-27 13:25:38 -04:00
|
|
|
|
|
2015-07-01 23:17:14 -04:00
|
|
|
|
if(keyData == Keys.Escape && _emuThread != null && mnuPause.Enabled) {
|
|
|
|
|
PauseEmu();
|
|
|
|
|
return true;
|
2015-08-24 20:27:07 -04:00
|
|
|
|
} else if(keyData == Keys.Oemplus) {
|
|
|
|
|
mnuIncreaseSpeed.PerformClick();
|
|
|
|
|
return true;
|
|
|
|
|
} else if(keyData == Keys.OemMinus) {
|
|
|
|
|
mnuDecreaseSpeed.PerformClick();
|
|
|
|
|
return true;
|
2015-07-01 23:17:14 -04:00
|
|
|
|
}
|
|
|
|
|
return base.ProcessCmdKey(ref msg, keyData);
|
|
|
|
|
}
|
2017-08-08 19:32:50 -04:00
|
|
|
|
|
2016-01-28 20:47:16 -05:00
|
|
|
|
private void SelectFdsBiosPrompt()
|
|
|
|
|
{
|
2016-02-19 13:05:04 -05:00
|
|
|
|
if(MesenMsgBox.Show("FdsBiosNotFound", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) {
|
2017-06-28 19:00:08 -04:00
|
|
|
|
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"));
|
2017-07-30 09:03:54 -04:00
|
|
|
|
LoadROM(_currentRomPath.Value, ConfigManager.Config.PreferenceInfo.AutoLoadIpsPatches);
|
2017-06-28 19:00:08 -04:00
|
|
|
|
} else {
|
|
|
|
|
MesenMsgBox.Show("InvalidFdsBios", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
2016-01-28 20:47:16 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-01-28 23:01:01 -05:00
|
|
|
|
|
|
|
|
|
private void frmMain_DragDrop(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
|
|
|
|
if(File.Exists(files[0])) {
|
|
|
|
|
LoadFile(files[0]);
|
2016-12-11 16:39:11 -05:00
|
|
|
|
this.Activate();
|
2016-01-28 23:01:01 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void frmMain_DragEnter(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(e.Data.GetDataPresent(DataFormats.FileDrop)) {
|
|
|
|
|
e.Effect = DragDropEffects.Copy;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-06 15:33:45 -05:00
|
|
|
|
|
2016-05-23 21:35:32 -04:00
|
|
|
|
private void ctrlRenderer_DoubleClick(object sender, EventArgs e)
|
|
|
|
|
{
|
2017-06-08 20:38:48 -04:00
|
|
|
|
if(!CursorManager.NeedMouseIcon && !InteropEmu.HasArkanoidPaddle()) {
|
2016-09-10 09:29:02 -04:00
|
|
|
|
//Disable double clicking (used to switch to fullscreen mode) when using zapper/arkanoid controller
|
|
|
|
|
SetFullscreenState(!_fullscreenMode);
|
|
|
|
|
}
|
2016-05-23 21:35:32 -04:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-07 13:05:32 -05:00
|
|
|
|
private void panelRenderer_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2017-04-22 16:54:45 -04:00
|
|
|
|
if(this.HideMenuStrip) {
|
2016-05-23 21:35:32 -04:00
|
|
|
|
this.menuStrip.Visible = false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-07 13:05:32 -05:00
|
|
|
|
ctrlRenderer.Focus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ctrlRenderer_Enter(object sender, EventArgs e)
|
|
|
|
|
{
|
2017-04-22 16:54:45 -04:00
|
|
|
|
if(this.HideMenuStrip) {
|
2016-02-07 13:05:32 -05:00
|
|
|
|
this.menuStrip.Visible = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void menuStrip_VisibleChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2017-04-22 16:54:45 -04:00
|
|
|
|
if(this.HideMenuStrip) {
|
2016-12-22 23:08:34 -05:00
|
|
|
|
IntPtr handle = this.Handle;
|
|
|
|
|
this.BeginInvoke((MethodInvoker)(() => {
|
2016-12-30 16:43:49 -05:00
|
|
|
|
int rendererTop = (panelRenderer.Height + (this.menuStrip.Visible ? menuStrip.Height : 0) - ctrlRenderer.Height) / 2;
|
|
|
|
|
this.ctrlRenderer.Top = rendererTop + (this.menuStrip.Visible ? -menuStrip.Height : 0);
|
2017-05-28 10:33:09 -04:00
|
|
|
|
this.ctrlRecentGames.Top = this.menuStrip.Visible ? -menuStrip.Height : 0;
|
2016-12-22 23:08:34 -05:00
|
|
|
|
}));
|
|
|
|
|
}
|
2016-02-07 13:05:32 -05:00
|
|
|
|
}
|
2016-02-07 16:13:48 -05:00
|
|
|
|
|
2016-06-26 17:13:10 -04:00
|
|
|
|
private void InitializeNsfMode(bool updateTextOnly = false, bool gameLoaded = false)
|
2016-06-25 20:46:54 -04:00
|
|
|
|
{
|
|
|
|
|
if(this.InvokeRequired) {
|
2016-08-29 22:34:13 -04:00
|
|
|
|
if(InteropEmu.IsNsf()) {
|
|
|
|
|
if(InteropEmu.IsConnected()) {
|
|
|
|
|
InteropEmu.Disconnect();
|
|
|
|
|
}
|
|
|
|
|
if(InteropEmu.IsServerRunning()) {
|
|
|
|
|
InteropEmu.StopServer();
|
|
|
|
|
}
|
2016-08-26 17:52:30 -04:00
|
|
|
|
}
|
2016-06-26 17:13:10 -04:00
|
|
|
|
this.BeginInvoke((MethodInvoker)(() => this.InitializeNsfMode(updateTextOnly, gameLoaded)));
|
2016-06-25 20:46:54 -04:00
|
|
|
|
} else {
|
|
|
|
|
if(InteropEmu.IsNsf()) {
|
2016-06-26 17:13:10 -04:00
|
|
|
|
if(gameLoaded) {
|
|
|
|
|
//Force emulation speed to 100 when loading a NSF
|
|
|
|
|
SetEmulationSpeed(100);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-25 20:46:54 -04:00
|
|
|
|
if(!this._isNsfPlayerMode) {
|
2017-08-08 16:10:54 -04:00
|
|
|
|
this._nonNsfSize = this.WindowState == FormWindowState.Maximized ? this.RestoreBounds.Size : this.Size;
|
2016-06-25 20:46:54 -04:00
|
|
|
|
this.Size = new Size(380, 320);
|
|
|
|
|
this.MinimumSize = new Size(380, 320);
|
|
|
|
|
}
|
|
|
|
|
this._isNsfPlayerMode = true;
|
|
|
|
|
this.ctrlNsfPlayer.UpdateText();
|
2016-06-26 15:51:50 -04:00
|
|
|
|
if(!updateTextOnly) {
|
|
|
|
|
this.ctrlNsfPlayer.ResetCount();
|
|
|
|
|
}
|
2016-06-25 20:46:54 -04:00
|
|
|
|
this.ctrlNsfPlayer.Visible = true;
|
|
|
|
|
this.ctrlNsfPlayer.Focus();
|
2017-07-30 09:03:54 -04:00
|
|
|
|
|
2016-06-25 20:46:54 -04:00
|
|
|
|
_currentGame = InteropEmu.NsfGetHeader().GetSongName();
|
2016-07-29 18:24:24 -04:00
|
|
|
|
} else if(this._isNsfPlayerMode) {
|
2017-08-08 16:10:54 -04:00
|
|
|
|
this.MinimumSize = new Size(340, 280);
|
|
|
|
|
this.Size = this._nonNsfSize.Value;
|
|
|
|
|
this._nonNsfSize = null;
|
2016-06-25 20:46:54 -04:00
|
|
|
|
this._isNsfPlayerMode = false;
|
|
|
|
|
this.ctrlNsfPlayer.Visible = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-09 12:49:17 -05:00
|
|
|
|
|
2017-06-08 20:38:48 -04:00
|
|
|
|
private void panelRenderer_MouseLeave(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
CursorManager.OnMouseLeave();
|
|
|
|
|
}
|
2015-07-01 23:17:14 -04:00
|
|
|
|
}
|
|
|
|
|
}
|