2015-07-01 23:17:14 -04:00
using System ;
using System.Collections.Generic ;
2016-01-01 10:21:41 -05:00
using System.Diagnostics ;
2015-07-01 23:17:14 -04:00
using System.Drawing ;
2015-12-27 18:41:38 -05:00
using System.IO ;
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 ;
2015-07-01 23:17:14 -04:00
using Mesen.GUI.Forms.NetPlay ;
namespace Mesen.GUI.Forms
{
2016-01-16 22:40:41 -05:00
public partial class frmMain : BaseForm
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 ;
2015-12-27 22:05:45 -05:00
private string _romToLoad = null ;
2016-01-28 22:34:23 -05:00
private string _currentGame = null ;
2016-02-07 13:05:32 -05:00
private bool _customSize = false ;
private bool _fullscreenMode = false ;
private double _regularScale = ConfigManager . Config . VideoInfo . VideoScale ;
2015-12-27 22:05:45 -05:00
public frmMain ( string [ ] args )
2015-07-01 23:17:14 -04:00
{
2015-12-27 22:05:45 -05:00
if ( args . Length > 0 & & File . Exists ( args [ 0 ] ) ) {
_romToLoad = args [ 0 ] ;
}
2015-07-01 23:17:14 -04:00
InitializeComponent ( ) ;
2015-07-14 21:53:01 -04:00
}
2015-12-27 22:05:45 -05:00
public void ProcessCommandLineArguments ( string [ ] args )
{
if ( args . Length > 0 & & File . Exists ( args [ 0 ] ) ) {
2016-01-31 14:03:12 -05:00
this . LoadFile ( args [ 0 ] ) ;
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
_notifListener = new InteropEmu . NotificationListener ( ) ;
_notifListener . OnNotification + = _notifListener_OnNotification ;
2015-08-30 21:04:21 -04:00
menuTimer . Start ( ) ;
2016-02-06 18:33:24 -05:00
VideoInfo . ApplyConfig ( ) ;
2016-01-28 20:47:16 -05:00
InitializeFdsDiskMenu ( ) ;
2015-08-24 20:27:07 -04:00
InitializeEmulationSpeedMenu ( ) ;
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 ( ) ;
2015-12-27 22:05:45 -05:00
if ( _romToLoad ! = null ) {
2016-01-31 14:07:40 -05:00
LoadFile ( this . _romToLoad ) ;
2015-12-27 22:05:45 -05:00
}
2016-02-08 23:23:31 -05:00
if ( ConfigManager . Config . PreferenceInfo . AutomaticallyCheckForUpdates ) {
CheckForUpdates ( false ) ;
}
2015-07-01 23:17:14 -04:00
}
2016-02-08 23:23:31 -05:00
protected override void OnShown ( EventArgs e )
{
base . OnShown ( e ) ;
PerformUpgrade ( ) ;
}
void PerformUpgrade ( )
{
if ( new Version ( ConfigManager . Config . MesenVersion ) < new Version ( InteropEmu . GetMesenVersion ( ) ) ) {
//Upgrade
ConfigManager . Config . MesenVersion = InteropEmu . GetMesenVersion ( ) ;
ConfigManager . ApplyChanges ( ) ;
MessageBox . Show ( "Upgrade completed successfully." , "Mesen" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
}
}
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-02-05 23:14:27 -05:00
InteropEmu . InitializeEmu ( ConfigManager . HomeFolder , this . Handle , this . ctrlRenderer . Handle ) ;
2015-07-05 22:23:44 -04:00
foreach ( string romPath in ConfigManager . Config . RecentFiles ) {
2015-12-27 18:41:38 -05:00
InteropEmu . AddKnowGameFolder ( Path . GetDirectoryName ( romPath ) . ToLowerInvariant ( ) ) ;
2015-07-05 22:23:44 -04:00
}
2015-07-21 23:05:27 -04:00
ConfigManager . Config . ApplyConfig ( ) ;
2015-07-17 21:18:57 -04:00
UpdateEmulationFlags ( ) ;
}
2015-08-23 20:24:24 -04:00
2015-08-24 20:27:07 -04:00
private void InitializeEmulationSpeedMenu ( )
{
mnuEmuSpeedNormal . Tag = 100 ;
mnuEmuSpeedTriple . Tag = 300 ;
mnuEmuSpeedDouble . Tag = 200 ;
mnuEmuSpeedHalf . Tag = 50 ;
mnuEmuSpeedQuarter . Tag = 25 ;
mnuEmuSpeedMaximumSpeed . Tag = 0 ;
UpdateEmulationSpeedMenu ( ) ;
}
private void UpdateEmulationSpeedMenu ( )
2015-08-23 20:24:24 -04:00
{
2015-08-24 20:27:07 -04:00
foreach ( ToolStripMenuItem item in new ToolStripMenuItem [ ] { mnuEmuSpeedDouble , mnuEmuSpeedHalf , mnuEmuSpeedNormal , mnuEmuSpeedQuarter , mnuEmuSpeedTriple , mnuEmuSpeedMaximumSpeed } ) {
item . Checked = ( ( int ) item . Tag = = ConfigManager . Config . VideoInfo . EmulationSpeed ) ;
2015-08-23 20:24:24 -04:00
}
2015-08-24 20:27:07 -04:00
}
2015-08-23 20:24:24 -04:00
2015-08-24 20:27:07 -04:00
private void SetEmulationSpeed ( uint emulationSpeed )
{
if ( emulationSpeed = = 0 ) {
InteropEmu . DisplayMessage ( "Emulation Speed" , "Maximum speed" ) ;
} else {
InteropEmu . DisplayMessage ( "Emulation Speed" , emulationSpeed + "%" ) ;
2015-08-23 20:24:24 -04:00
}
2015-08-24 20:27:07 -04:00
ConfigManager . Config . VideoInfo . EmulationSpeed = emulationSpeed ;
ConfigManager . ApplyChanges ( ) ;
UpdateEmulationSpeedMenu ( ) ;
VideoInfo . ApplyConfig ( ) ;
}
2015-08-23 20:24:24 -04:00
2015-08-24 20:27:07 -04:00
private void mnuIncreaseSpeed_Click ( object sender , EventArgs e )
{
if ( ConfigManager . Config . VideoInfo . EmulationSpeed > 0 ) {
if ( ConfigManager . Config . VideoInfo . EmulationSpeed < 100 ) {
SetEmulationSpeed ( ConfigManager . Config . VideoInfo . EmulationSpeed + 25 ) ;
} else if ( ConfigManager . Config . VideoInfo . EmulationSpeed < 450 ) {
SetEmulationSpeed ( ConfigManager . Config . VideoInfo . EmulationSpeed + 50 ) ;
} else {
SetEmulationSpeed ( 0 ) ;
}
}
2015-08-23 20:24:24 -04:00
}
2015-08-24 20:27:07 -04:00
private void mnuDecreaseSpeed_Click ( object sender , EventArgs e )
2015-08-23 20:24:24 -04:00
{
2015-08-24 20:27:07 -04:00
if ( ConfigManager . Config . VideoInfo . EmulationSpeed = = 0 ) {
SetEmulationSpeed ( 450 ) ;
} else if ( ConfigManager . Config . VideoInfo . EmulationSpeed < = 100 ) {
if ( ConfigManager . Config . VideoInfo . EmulationSpeed > 25 ) {
SetEmulationSpeed ( ConfigManager . Config . VideoInfo . EmulationSpeed - 25 ) ;
}
} else {
SetEmulationSpeed ( ConfigManager . Config . VideoInfo . EmulationSpeed - 50 ) ;
2015-08-23 20:24:24 -04:00
}
}
2015-08-24 20:27:07 -04:00
private void mnuEmuSpeedMaximumSpeed_Click ( object sender , EventArgs e )
2015-08-23 20:24:24 -04:00
{
2015-08-24 20:27:07 -04:00
if ( ConfigManager . Config . VideoInfo . EmulationSpeed = = 0 ) {
SetEmulationSpeed ( 100 ) ;
2015-08-23 20:24:24 -04:00
} else {
2015-08-24 20:27:07 -04:00
SetEmulationSpeed ( 0 ) ;
2015-08-23 20:24:24 -04:00
}
2015-08-24 20:27:07 -04:00
}
2015-08-23 20:24:24 -04:00
2015-08-24 20:27:07 -04:00
private void mnuEmulationSpeedOption_Click ( object sender , EventArgs e )
{
2015-08-30 21:04:21 -04:00
SetEmulationSpeed ( ( uint ) ( int ) ( ( ToolStripItem ) sender ) . Tag ) ;
2015-08-23 20:24:24 -04:00
}
2015-12-27 18:41:38 -05:00
private void UpdateEmulationFlags ( )
2015-07-17 21:18:57 -04:00
{
ConfigManager . Config . VideoInfo . ShowFPS = mnuShowFPS . Checked ;
ConfigManager . ApplyChanges ( ) ;
VideoInfo . ApplyConfig ( ) ;
2015-07-05 22:23:44 -04:00
}
2015-12-27 18:41:38 -05:00
private void UpdateVideoSettings ( )
2015-07-23 23:16:31 -04:00
{
mnuShowFPS . Checked = ConfigManager . Config . VideoInfo . ShowFPS ;
2015-08-24 20:27:07 -04:00
UpdateEmulationSpeedMenu ( ) ;
2016-01-05 21:28:38 -05:00
UpdateScaleMenu ( ConfigManager . Config . VideoInfo . VideoScale ) ;
UpdateFilterMenu ( ConfigManager . Config . VideoInfo . VideoFilter ) ;
2016-01-06 20:34:45 -05:00
2016-02-07 13:05:32 -05:00
UpdateViewerSize ( ) ;
2016-01-06 20:34:45 -05:00
}
private void UpdateViewerSize ( )
{
2016-02-07 13:05:32 -05:00
InteropEmu . ScreenSize size = InteropEmu . GetScreenSize ( false ) ;
if ( ! _customSize & & this . WindowState ! = FormWindowState . Maximized ) {
this . Resize - = frmMain_Resize ;
this . ClientSize = new Size ( size . Width , size . Height + menuStrip . Height ) ;
this . Resize + = frmMain_Resize ;
2016-01-06 20:34:45 -05:00
}
2016-02-07 13:05:32 -05:00
2016-02-05 23:14:27 -05:00
ctrlRenderer . Size = new Size ( size . Width , size . Height ) ;
2016-02-07 13:05:32 -05:00
ctrlRenderer . Left = ( panelRenderer . Width - ctrlRenderer . Width ) / 2 ;
ctrlRenderer . Top = ( panelRenderer . Height - ctrlRenderer . Height ) / 2 ;
}
private void frmMain_Resize ( object sender , EventArgs e )
{
if ( this . WindowState ! = FormWindowState . Minimized ) {
SetScaleBasedOnWindowSize ( ) ;
}
}
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 ) ;
UpdateScaleMenu ( scale ) ;
VideoInfo . ApplyConfig ( ) ;
}
private void SetFullscreenState ( bool enabled )
{
this . Resize - = frmMain_Resize ;
if ( enabled ) {
this . menuStrip . Visible = false ;
this . WindowState = FormWindowState . Normal ;
this . FormBorderStyle = FormBorderStyle . None ;
this . WindowState = FormWindowState . Maximized ;
SetScaleBasedOnWindowSize ( ) ;
} else {
this . menuStrip . Visible = true ;
this . WindowState = FormWindowState . Normal ;
this . FormBorderStyle = FormBorderStyle . Sizable ;
this . UpdateScaleMenu ( _regularScale ) ;
VideoInfo . ApplyConfig ( ) ;
}
this . Resize + = frmMain_Resize ;
_fullscreenMode = enabled ;
2015-07-23 23:16:31 -04:00
}
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-01-28 22:34:23 -05:00
_currentGame = Path . GetFileNameWithoutExtension ( InteropEmu . GetROMPath ( ) ) ;
2016-01-28 20:47:16 -05:00
InitializeFdsDiskMenu ( ) ;
CheatInfo . ApplyCheats ( ) ;
InitializeStateMenu ( mnuSaveState , true ) ;
InitializeStateMenu ( mnuLoadState , false ) ;
this . StartEmuThread ( ) ;
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 :
CheatInfo . ClearCheats ( ) ;
break ;
case InteropEmu . ConsoleNotificationType . ResolutionChanged :
this . BeginInvoke ( ( MethodInvoker ) ( ( ) = > {
UpdateVideoSettings ( ) ;
} ) ) ;
break ;
case InteropEmu . ConsoleNotificationType . FdsBiosNotFound :
this . BeginInvoke ( ( MethodInvoker ) ( ( ) = > {
SelectFdsBiosPrompt ( ) ;
} ) ) ;
break ;
2015-07-01 23:17:14 -04:00
}
UpdateMenus ( ) ;
}
private void mnuOpen_Click ( object sender , EventArgs e )
{
OpenFileDialog ofd = new OpenFileDialog ( ) ;
2016-01-28 20:47:16 -05:00
ofd . Filter = "All supported formats (*.nes, *.zip, *.fds, *.ips)|*.NES;*.ZIP;*.IPS;*.FDS|NES Roms (*.nes)|*.NES|Famicom Disk System Roms (*.fds)|*.FDS|ZIP Archives (*.zip)|*.ZIP|IPS Patches (*.ips)|*.IPS|All (*.*)|*.*" ;
2015-12-27 18:41:38 -05:00
if ( ConfigManager . Config . RecentFiles . Count > 0 ) {
ofd . InitialDirectory = Path . GetDirectoryName ( ConfigManager . Config . RecentFiles [ 0 ] ) ;
}
2015-07-01 23:17:14 -04:00
if ( ofd . ShowDialog ( ) = = System . Windows . Forms . DialogResult . OK ) {
2016-01-28 23:01:01 -05:00
LoadFile ( ofd . FileName ) ;
}
}
private void LoadFile ( string filename )
{
2016-01-31 14:03:12 -05:00
if ( File . Exists ( filename ) ) {
if ( Path . GetExtension ( filename ) . ToLowerInvariant ( ) = = ".ips" ) {
LoadIpsFile ( filename ) ;
} else if ( Path . GetExtension ( filename ) . ToLowerInvariant ( ) = = ".mmo" ) {
InteropEmu . MoviePlay ( filename ) ;
} else {
LoadROM ( filename , ConfigManager . Config . PreferenceInfo . AutoLoadIpsPatches ) ;
}
2016-01-28 23:01:01 -05:00
}
}
private void LoadIpsFile ( string filename )
{
string ipsFile = filename ;
string romFile = Path . Combine ( Path . GetDirectoryName ( filename ) , Path . GetFileNameWithoutExtension ( filename ) ) ;
if ( File . Exists ( romFile + ".nes" ) | | File . Exists ( romFile + ".zip" ) | | File . Exists ( romFile + ".fds" ) ) {
string ext = string . Empty ;
if ( File . Exists ( romFile + ".nes" ) )
ext = ".nes" ;
if ( File . Exists ( romFile + ".zip" ) )
ext = ".zip" ;
if ( File . Exists ( romFile + ".fds" ) )
ext = ".fds" ;
LoadROM ( romFile + ext ) ;
InteropEmu . ApplyIpsPatch ( ipsFile ) ;
} else {
if ( _emuThread = = null ) {
if ( MessageBox . Show ( "Please select a ROM matching the IPS patch file." , string . Empty , MessageBoxButtons . OKCancel , MessageBoxIcon . Question ) = = System . Windows . Forms . DialogResult . OK ) {
OpenFileDialog ofd = new OpenFileDialog ( ) ;
ofd . Filter = "All supported formats (*.nes, *.zip, *.fds)|*.NES;*.ZIP;*.FDS|NES Roms (*.nes)|*.NES|Famicom Disk System Roms (*.fds)|*.FDS|ZIP Archives (*.zip)|*.ZIP|All (*.*)|*.*" ;
if ( ConfigManager . Config . RecentFiles . Count > 0 ) {
ofd . InitialDirectory = Path . GetDirectoryName ( ConfigManager . Config . RecentFiles [ 0 ] ) ;
}
if ( ofd . ShowDialog ( ) = = System . Windows . Forms . DialogResult . OK ) {
LoadROM ( ofd . FileName ) ;
2015-12-27 18:41:38 -05:00
}
2016-01-28 23:01:01 -05:00
InteropEmu . ApplyIpsPatch ( ipsFile ) ;
2015-12-27 18:41:38 -05:00
}
2016-01-28 23:01:01 -05:00
} else if ( MessageBox . Show ( "Patch and reset the current game?" , string . Empty , MessageBoxButtons . OKCancel , MessageBoxIcon . Question ) = = System . Windows . Forms . DialogResult . OK ) {
InteropEmu . ApplyIpsPatch ( ipsFile ) ;
2015-12-27 18:41:38 -05:00
}
2015-07-01 23:17:14 -04:00
}
}
2016-01-28 20:47:16 -05:00
private void LoadROM ( string filename , bool autoLoadIps = false )
2015-07-01 23:17:14 -04:00
{
2016-01-28 20:47:16 -05:00
_romToLoad = filename ;
2016-01-01 10:21:41 -05:00
if ( File . Exists ( filename ) ) {
ConfigManager . Config . AddRecentFile ( filename ) ;
InteropEmu . LoadROM ( filename ) ;
UpdateRecentFiles ( ) ;
2016-01-28 20:47:16 -05:00
string ipsFile = Path . Combine ( Path . GetDirectoryName ( filename ) , Path . GetFileNameWithoutExtension ( filename ) ) + ".ips" ;
if ( File . Exists ( ipsFile ) ) {
InteropEmu . ApplyIpsPatch ( ipsFile ) ;
}
2016-01-01 10:21:41 -05:00
} else {
MessageBox . Show ( "File not found." , "Mesen" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
}
2015-07-01 23:17:14 -04:00
}
2016-01-31 13:53:17 -05:00
private void UpdateFocusFlag ( )
{
bool hasFocus = false ;
foreach ( Form form in Application . OpenForms ) {
if ( form . ContainsFocus ) {
hasFocus = true ;
break ;
}
}
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 {
2016-01-31 13:53:17 -05:00
UpdateFocusFlag ( ) ;
2016-01-28 22:34:23 -05:00
if ( string . IsNullOrWhiteSpace ( _currentGame ) ) {
2015-08-23 20:24:24 -04:00
this . Text = "Mesen" ;
} else {
2016-01-28 22:34:23 -05:00
this . Text = "Mesen - " + _currentGame ;
2015-08-23 20:24:24 -04:00
}
2016-02-05 23:14:27 -05:00
bool isNetPlayClient = InteropEmu . IsConnected ( ) ;
mnuSaveState . Enabled = mnuLoadState . Enabled = mnuPause . Enabled = mnuStop . Enabled = mnuReset . Enabled = ( _emuThread ! = null & & ! isNetPlayClient ) ;
2015-07-01 23:17:14 -04:00
mnuPause . Text = InteropEmu . IsPaused ( ) ? "Resume" : "Pause" ;
2016-02-11 18:34:55 -05:00
mnuPause . Image = InteropEmu . IsPaused ( ) ? Mesen . GUI . Properties . Resources . Play : Mesen . GUI . Properties . Resources . Pause ;
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 ;
mnuNetPlayPlayer1 . Text = "Player 1 (" + InteropEmu . NetPlayGetControllerType ( 0 ) . ToString ( ) + ")" ;
mnuNetPlayPlayer2 . Text = "Player 2 (" + InteropEmu . NetPlayGetControllerType ( 1 ) . ToString ( ) + ")" ;
mnuNetPlayPlayer3 . Text = "Player 3 (" + InteropEmu . NetPlayGetControllerType ( 2 ) . ToString ( ) + ")" ;
mnuNetPlayPlayer4 . Text = "Player 4 (" + InteropEmu . NetPlayGetControllerType ( 3 ) . ToString ( ) + ")" ;
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-05 23:14:27 -05:00
mnuStartServer . Text = InteropEmu . IsServerRunning ( ) ? "Stop Server" : "Start Server" ;
mnuConnect . Text = isNetPlayClient ? "Disconnect" : "Connect to Server" ;
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 ;
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 ;
mnuTakeScreenshot . Enabled = _emuThread ! = null ;
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 ;
2015-07-01 23:17:14 -04:00
}
} catch { }
}
private void UpdateRecentFiles ( )
{
mnuRecentFiles . DropDownItems . Clear ( ) ;
foreach ( string filepath in ConfigManager . Config . RecentFiles ) {
ToolStripMenuItem tsmi = new ToolStripMenuItem ( ) ;
2015-12-27 18:41:38 -05:00
tsmi . Text = Path . GetFileName ( filepath ) ;
2015-07-01 23:17:14 -04:00
tsmi . Click + = ( object sender , EventArgs args ) = > {
LoadROM ( filepath ) ;
} ;
mnuRecentFiles . DropDownItems . Add ( tsmi ) ;
}
2016-01-16 22:51:44 -05:00
mnuRecentFiles . Enabled = mnuRecentFiles . DropDownItems . Count > 0 ;
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-01-28 21:40:30 -05:00
MessageBox . Show ( ex . ToString ( ) , "Unexpected Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
2015-07-01 23:17:14 -04:00
}
} ) ;
_emuThread . Start ( ) ;
}
UpdateMenus ( ) ;
}
2015-08-30 21:04:21 -04:00
2015-07-01 23:17:14 -04:00
private void StopEmu ( )
{
InteropEmu . Stop ( ) ;
}
private void PauseEmu ( )
{
if ( InteropEmu . IsPaused ( ) ) {
InteropEmu . Resume ( ) ;
} else {
InteropEmu . Pause ( ) ;
}
}
private void ResetEmu ( )
{
InteropEmu . Reset ( ) ;
}
2016-02-07 13:05:32 -05:00
2015-07-01 23:17:14 -04:00
protected override bool ProcessCmdKey ( ref Message msg , Keys keyData )
{
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 ;
}
2016-02-07 13:05:32 -05:00
if ( _fullscreenMode & & ( keyData & Keys . Alt ) = = Keys . Alt ) {
if ( this . menuStrip . Visible & & ! this . menuStrip . ContainsFocus ) {
this . menuStrip . Visible = false ;
} else {
this . menuStrip . Visible = true ;
this . menuStrip . Focus ( ) ;
}
}
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 ) ;
}
const int NumberOfSaveSlots = 5 ;
private void InitializeStateMenu ( ToolStripMenuItem menu , bool forSave )
{
2015-08-23 20:24:24 -04:00
if ( this . InvokeRequired ) {
this . BeginInvoke ( ( MethodInvoker ) ( ( ) = > this . InitializeStateMenu ( menu , forSave ) ) ) ;
} else {
menu . DropDownItems . Clear ( ) ;
for ( uint i = 1 ; i < = frmMain . NumberOfSaveSlots ; i + + ) {
Int64 fileTime = InteropEmu . GetStateInfo ( i ) ;
string label ;
if ( fileTime = = 0 ) {
label = i . ToString ( ) + ". <empty>" ;
} else {
DateTime dateTime = DateTime . FromFileTime ( fileTime ) ;
label = i . ToString ( ) + ". " + dateTime . ToShortDateString ( ) + " " + dateTime . ToShortTimeString ( ) ;
}
2015-07-01 23:17:14 -04:00
2015-08-23 20:24:24 -04:00
ToolStripMenuItem item = ( ToolStripMenuItem ) menu . DropDownItems . Add ( label ) ;
uint stateIndex = i ;
item . Click + = ( object sender , EventArgs e ) = > {
2016-01-31 00:41:33 -05:00
if ( _emuThread ! = null ) {
if ( forSave ) {
InteropEmu . SaveState ( stateIndex ) ;
} else {
InteropEmu . LoadState ( stateIndex ) ;
}
2015-08-23 20:24:24 -04:00
}
} ;
item . ShortcutKeys = ( Keys ) ( ( int ) Keys . F1 + i - 1 ) ;
2015-07-01 23:17:14 -04:00
if ( forSave ) {
2015-08-23 20:24:24 -04:00
item . ShortcutKeys | = Keys . Shift ;
2015-07-01 23:17:14 -04:00
}
}
}
}
#region Events
private void mnuPause_Click ( object sender , EventArgs e )
{
PauseEmu ( ) ;
}
private void mnuReset_Click ( object sender , EventArgs e )
{
ResetEmu ( ) ;
}
private void mnuStop_Click ( object sender , EventArgs e )
{
InteropEmu . Stop ( ) ;
}
private void mnuShowFPS_Click ( object sender , EventArgs e )
{
2015-07-17 21:18:57 -04:00
UpdateEmulationFlags ( ) ;
2015-07-01 23:17:14 -04:00
}
private void mnuStartServer_Click ( object sender , EventArgs e )
{
2016-02-05 23:14:27 -05:00
if ( InteropEmu . IsServerRunning ( ) ) {
Task . Run ( ( ) = > InteropEmu . StopServer ( ) ) ;
} else {
frmServerConfig frm = new frmServerConfig ( ) ;
if ( frm . ShowDialog ( sender ) = = System . Windows . Forms . DialogResult . OK ) {
2016-02-06 15:33:45 -05:00
InteropEmu . StartServer ( ConfigManager . Config . ServerInfo . Port , ConfigManager . Config . Profile . PlayerName ) ;
2016-02-05 23:14:27 -05:00
}
2015-07-01 23:17:14 -04:00
}
}
private void mnuConnect_Click ( object sender , EventArgs e )
{
2016-02-05 23:14:27 -05:00
if ( InteropEmu . IsConnected ( ) ) {
Task . Run ( ( ) = > InteropEmu . Disconnect ( ) ) ;
} else {
frmClientConfig frm = new frmClientConfig ( ) ;
if ( frm . ShowDialog ( sender ) = = System . Windows . Forms . DialogResult . OK ) {
2016-02-10 20:19:06 -05:00
Task . Run ( ( ) = > {
InteropEmu . Connect ( ConfigManager . Config . ClientConnectionInfo . Host , ConfigManager . Config . ClientConnectionInfo . Port , ConfigManager . Config . Profile . PlayerName , ConfigManager . Config . Profile . PlayerAvatar , ( UInt16 ) ConfigManager . Config . Profile . PlayerAvatar . Length , ConfigManager . Config . ClientConnectionInfo . Spectator ) ;
} ) ;
2016-02-05 23:14:27 -05:00
}
2015-07-01 23:17:14 -04:00
}
}
private void mnuProfile_Click ( object sender , EventArgs e )
{
2016-01-31 11:58:41 -05:00
new frmPlayerProfile ( ) . ShowDialog ( sender ) ;
2015-07-01 23:17:14 -04:00
}
private void mnuExit_Click ( object sender , EventArgs e )
{
this . Close ( ) ;
}
private void mnuVideoConfig_Click ( object sender , EventArgs e )
{
2016-01-31 11:58:41 -05:00
new frmVideoConfig ( ) . ShowDialog ( sender ) ;
2015-07-23 23:16:31 -04:00
UpdateVideoSettings ( ) ;
2015-07-01 23:17:14 -04:00
}
private void mnuDebugger_Click ( object sender , EventArgs e )
{
2015-08-05 20:40:10 -04:00
if ( _debugger = = null ) {
_debugger = new frmDebugger ( ) ;
_debugger . FormClosed + = ( obj , args ) = > {
_debugger = null ;
} ;
2016-01-31 11:58:41 -05:00
_debugger . Show ( sender ) ;
2015-08-05 20:40:10 -04:00
} else {
_debugger . Focus ( ) ;
}
2015-07-01 23:17:14 -04:00
}
2015-12-26 17:11:00 -05:00
2015-07-01 23:17:14 -04:00
private void mnuSaveState_DropDownOpening ( object sender , EventArgs e )
{
InitializeStateMenu ( mnuSaveState , true ) ;
}
private void mnuLoadState_DropDownOpening ( object sender , EventArgs e )
{
InitializeStateMenu ( mnuLoadState , false ) ;
}
private void mnuTakeScreenshot_Click ( object sender , EventArgs e )
{
InteropEmu . TakeScreenshot ( ) ;
}
#endregion
private void RecordMovie ( bool resetEmu )
{
SaveFileDialog sfd = new SaveFileDialog ( ) ;
sfd . Filter = "Movie files (*.mmo)|*.mmo|All (*.*)|*.*" ;
2015-12-26 17:11:00 -05:00
sfd . InitialDirectory = ConfigManager . MovieFolder ;
2015-12-27 18:41:38 -05:00
sfd . FileName = Path . GetFileNameWithoutExtension ( InteropEmu . GetROMPath ( ) ) + ".mmo" ;
2015-07-01 23:17:14 -04:00
if ( sfd . ShowDialog ( ) = = System . Windows . Forms . DialogResult . OK ) {
InteropEmu . MovieRecord ( sfd . FileName , resetEmu ) ;
}
}
private void mnuPlayMovie_Click ( object sender , EventArgs e )
{
OpenFileDialog ofd = new OpenFileDialog ( ) ;
ofd . Filter = "Movie files (*.mmo)|*.mmo|All (*.*)|*.*" ;
2015-12-26 17:11:00 -05:00
ofd . InitialDirectory = ConfigManager . MovieFolder ;
2015-07-01 23:17:14 -04:00
if ( ofd . ShowDialog ( ) = = System . Windows . Forms . DialogResult . OK ) {
InteropEmu . MoviePlay ( ofd . FileName ) ;
}
}
private void mnuStopMovie_Click ( object sender , EventArgs e )
{
InteropEmu . MovieStop ( ) ;
}
private void mnuRecordFromStart_Click ( object sender , EventArgs e )
{
RecordMovie ( true ) ;
}
private void mnuRecordFromNow_Click ( object sender , EventArgs e )
{
RecordMovie ( false ) ;
}
2015-07-03 00:12:02 -04:00
2015-12-26 17:11:00 -05:00
private void mnuTestRun_Click ( object sender , EventArgs e )
{
OpenFileDialog ofd = new OpenFileDialog ( ) ;
ofd . Filter = "Test files (*.mtp)|*.mtp|All (*.*)|*.*" ;
ofd . InitialDirectory = ConfigManager . TestFolder ;
ofd . Multiselect = true ;
if ( ofd . ShowDialog ( ) = = System . Windows . Forms . DialogResult . OK ) {
List < string > passedTests = new List < string > ( ) ;
List < string > failedTests = new List < string > ( ) ;
2015-12-29 20:54:55 -05:00
List < int > failedFrameCount = new List < int > ( ) ;
2015-12-26 17:11:00 -05:00
this . menuStrip . Enabled = false ;
2015-12-27 09:13:52 -05:00
Task . Run ( ( ) = > {
foreach ( string filename in ofd . FileNames ) {
2015-12-29 20:54:55 -05:00
int result = InteropEmu . RomTestRun ( filename ) ;
2015-12-26 17:11:00 -05:00
2015-12-29 20:54:55 -05:00
if ( result = = 0 ) {
2015-12-27 18:41:38 -05:00
passedTests . Add ( Path . GetFileNameWithoutExtension ( filename ) ) ;
2015-12-27 09:13:52 -05:00
} else {
2015-12-27 18:41:38 -05:00
failedTests . Add ( Path . GetFileNameWithoutExtension ( filename ) ) ;
2015-12-29 20:54:55 -05:00
failedFrameCount . Add ( result ) ;
2015-12-27 09:13:52 -05:00
}
2015-12-26 17:11:00 -05:00
}
2015-12-27 09:13:52 -05:00
this . BeginInvoke ( ( MethodInvoker ) ( ( ) = > {
if ( failedTests . Count = = 0 ) {
MessageBox . Show ( "All tests passed." , "" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
} else {
StringBuilder message = new StringBuilder ( ) ;
2015-12-29 20:54:55 -05:00
if ( passedTests . Count > 0 ) {
message . AppendLine ( "Passed tests:" ) ;
foreach ( string test in passedTests ) {
message . AppendLine ( " -" + test ) ;
}
message . AppendLine ( "" ) ;
2015-12-27 09:13:52 -05:00
}
message . AppendLine ( "Failed tests:" ) ;
2015-12-29 20:54:55 -05:00
for ( int i = 0 , len = failedTests . Count ; i < len ; i + + ) {
message . AppendLine ( " -" + failedTests [ i ] + " (" + failedFrameCount [ i ] + ")" ) ;
2015-12-27 09:13:52 -05:00
}
MessageBox . Show ( message . ToString ( ) , "" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
}
2015-12-26 17:11:00 -05:00
2015-12-27 09:13:52 -05:00
this . menuStrip . Enabled = true ;
} ) ) ;
} ) ;
2015-12-26 17:11:00 -05:00
}
}
private void mnuTestRecordStart_Click ( object sender , EventArgs e )
{
RecordTest ( true ) ;
}
private void mnuTestRecordNow_Click ( object sender , EventArgs e )
{
RecordTest ( false ) ;
}
2015-12-27 09:13:52 -05:00
private void RecordTest ( bool resetEmu )
{
SaveFileDialog sfd = new SaveFileDialog ( ) ;
sfd . Filter = "Test files (*.mtp)|*.mtp|All (*.*)|*.*" ;
sfd . InitialDirectory = ConfigManager . TestFolder ;
2015-12-27 18:41:38 -05:00
sfd . FileName = Path . GetFileNameWithoutExtension ( InteropEmu . GetROMPath ( ) ) + ".mtp" ;
2015-12-27 09:13:52 -05:00
if ( sfd . ShowDialog ( ) = = System . Windows . Forms . DialogResult . OK ) {
InteropEmu . RomTestRecord ( sfd . FileName , resetEmu ) ;
}
}
private void mnuTestRecordMovie_Click ( object sender , EventArgs e )
{
OpenFileDialog ofd = new OpenFileDialog ( ) ;
ofd . Filter = "Movie files (*.mmo)|*.mmo|All (*.*)|*.*" ;
ofd . InitialDirectory = ConfigManager . MovieFolder ;
if ( ofd . ShowDialog ( ) = = System . Windows . Forms . DialogResult . OK ) {
SaveFileDialog sfd = new SaveFileDialog ( ) ;
sfd . Filter = "Test files (*.mtp)|*.mtp|All (*.*)|*.*" ;
sfd . InitialDirectory = ConfigManager . TestFolder ;
2015-12-27 18:41:38 -05:00
sfd . FileName = Path . GetFileNameWithoutExtension ( ofd . FileName ) + ".mtp" ;
2015-12-27 09:13:52 -05:00
if ( sfd . ShowDialog ( ) = = System . Windows . Forms . DialogResult . OK ) {
InteropEmu . RomTestRecordFromMovie ( sfd . FileName , ofd . FileName ) ;
}
}
}
private void mnuTestRecordTest_Click ( object sender , EventArgs e )
{
OpenFileDialog ofd = new OpenFileDialog ( ) ;
ofd . Filter = "Test files (*.mtp)|*.mtp|All (*.*)|*.*" ;
ofd . InitialDirectory = ConfigManager . TestFolder ;
if ( ofd . ShowDialog ( ) = = System . Windows . Forms . DialogResult . OK ) {
SaveFileDialog sfd = new SaveFileDialog ( ) ;
sfd . Filter = "Test files (*.mtp)|*.mtp|All (*.*)|*.*" ;
sfd . InitialDirectory = ConfigManager . TestFolder ;
2015-12-27 18:41:38 -05:00
sfd . FileName = Path . GetFileNameWithoutExtension ( ofd . FileName ) + ".mtp" ;
2015-12-27 09:13:52 -05:00
if ( sfd . ShowDialog ( ) = = System . Windows . Forms . DialogResult . OK ) {
InteropEmu . RomTestRecordFromTest ( sfd . FileName , ofd . FileName ) ;
}
}
}
2015-12-26 17:11:00 -05:00
private void mnuTestStopRecording_Click ( object sender , EventArgs e )
{
InteropEmu . RomTestStop ( ) ;
}
2015-07-03 00:12:02 -04:00
private void mnuCheats_Click ( object sender , EventArgs e )
{
2015-07-05 19:05:33 -04:00
frmCheatList frm = new frmCheatList ( ) ;
2016-02-05 23:14:27 -05:00
frm . Show ( sender , this ) ;
2015-07-05 19:05:33 -04:00
frm . FormClosed + = ( object a , FormClosedEventArgs b ) = > {
frm = null ;
CheatInfo . ApplyCheats ( ) ;
} ;
2015-07-03 00:12:02 -04:00
}
2015-07-10 21:07:24 -04:00
private void mnuInput_Click ( object sender , EventArgs e )
{
2016-01-31 11:58:41 -05:00
new frmInputConfig ( ) . ShowDialog ( sender ) ;
2015-07-10 21:07:24 -04:00
}
2015-07-17 20:58:57 -04:00
private void mnuAudioConfig_Click ( object sender , EventArgs e )
{
2016-01-31 11:58:41 -05:00
new frmAudioConfig ( ) . ShowDialog ( sender ) ;
2015-07-17 20:58:57 -04:00
}
2015-07-21 23:05:27 -04:00
2015-12-27 22:05:45 -05:00
private void mnuPreferences_Click ( object sender , EventArgs e )
{
2016-01-31 11:58:41 -05:00
new frmPreferences ( ) . ShowDialog ( sender ) ;
2015-12-27 22:05:45 -05:00
}
2015-07-21 23:05:27 -04:00
private void mnuRegion_Click ( object sender , EventArgs e )
{
if ( sender = = mnuRegionAuto ) {
ConfigManager . Config . Region = NesModel . Auto ;
} else if ( sender = = mnuRegionNtsc ) {
ConfigManager . Config . Region = NesModel . NTSC ;
} else if ( sender = = mnuRegionPal ) {
ConfigManager . Config . Region = NesModel . PAL ;
2016-01-30 19:33:32 -05:00
} else if ( sender = = mnuRegionDendy ) {
ConfigManager . Config . Region = NesModel . Dendy ;
2015-07-21 23:05:27 -04:00
}
ConfigManager . Config . ApplyConfig ( ) ;
}
2016-01-01 10:21:41 -05:00
private void mnuRunAllTests_Click ( object sender , EventArgs e )
{
2016-01-17 11:42:35 -05:00
string workingDirectory = Path . Combine ( Path . GetDirectoryName ( System . Reflection . Assembly . GetExecutingAssembly ( ) . Location ) ) ;
ProcessStartInfo startInfo = new ProcessStartInfo ( ) ;
startInfo . FileName = "TestHelper.exe" ;
startInfo . WorkingDirectory = workingDirectory ;
Process . Start ( startInfo ) ;
2016-01-01 10:21:41 -05:00
}
2016-01-05 21:28:38 -05:00
2016-02-07 13:05:32 -05:00
private void UpdateScaleMenu ( double scale )
2016-01-05 21:28:38 -05:00
{
2016-02-07 13:05:32 -05:00
mnuScale1x . Checked = ( scale = = 1.0 ) & & ! _customSize ;
mnuScale2x . Checked = ( scale = = 2.0 ) & & ! _customSize ;
mnuScale3x . Checked = ( scale = = 3.0 ) & & ! _customSize ;
mnuScale4x . Checked = ( scale = = 4.0 ) & & ! _customSize ;
mnuScaleCustom . Checked = _customSize | | ! mnuScale1x . Checked & & ! mnuScale2x . Checked & & ! mnuScale3x . Checked & & ! mnuScale4x . Checked ;
2016-01-05 21:28:38 -05:00
ConfigManager . Config . VideoInfo . VideoScale = scale ;
ConfigManager . ApplyChanges ( ) ;
}
private void UpdateFilterMenu ( VideoFilterType filterType )
{
mnuNoneFilter . Checked = ( filterType = = VideoFilterType . None ) ;
mnuNtscFilter . Checked = ( filterType = = VideoFilterType . NTSC ) ;
ConfigManager . Config . VideoInfo . VideoFilter = filterType ;
ConfigManager . ApplyChanges ( ) ;
}
private void mnuScale_Click ( object sender , EventArgs e )
{
UInt32 scale = UInt32 . Parse ( ( string ) ( ( ToolStripMenuItem ) sender ) . Tag ) ;
2016-02-07 13:05:32 -05:00
_customSize = false ;
_regularScale = scale ;
2016-01-05 21:28:38 -05:00
InteropEmu . SetVideoScale ( scale ) ;
UpdateScaleMenu ( scale ) ;
}
private void mnuNoneFilter_Click ( object sender , EventArgs e )
{
InteropEmu . SetVideoFilter ( VideoFilterType . None ) ;
UpdateFilterMenu ( VideoFilterType . None ) ;
2016-02-07 13:05:32 -05:00
_customSize = false ;
2016-01-05 21:28:38 -05:00
}
private void mnuNtscFilter_Click ( object sender , EventArgs e )
{
InteropEmu . SetVideoFilter ( VideoFilterType . NTSC ) ;
UpdateFilterMenu ( VideoFilterType . NTSC ) ;
2016-02-07 13:05:32 -05:00
_customSize = false ;
2016-01-05 21:28:38 -05:00
}
2016-01-28 20:47:16 -05:00
private void InitializeFdsDiskMenu ( )
{
if ( this . InvokeRequired ) {
this . BeginInvoke ( ( MethodInvoker ) ( ( ) = > this . InitializeFdsDiskMenu ( ) ) ) ;
} else {
UInt32 sideCount = InteropEmu . FdsGetSideCount ( ) ;
mnuSelectDisk . DropDownItems . Clear ( ) ;
if ( sideCount > 0 ) {
for ( UInt32 i = 0 ; i < sideCount ; i + + ) {
UInt32 diskNumber = i ;
ToolStripItem item = mnuSelectDisk . DropDownItems . Add ( "Disk " + ( diskNumber / 2 + 1 ) + " Side " + ( diskNumber % 2 = = 0 ? "A" : "B" ) ) ;
item . Click + = ( object sender , EventArgs args ) = > {
InteropEmu . FdsInsertDisk ( diskNumber ) ;
} ;
}
sepFdsDisk . Visible = true ;
mnuSelectDisk . Visible = true ;
mnuEjectDisk . Visible = true ;
mnuSwitchDiskSide . Visible = sideCount > 1 ;
} else {
sepFdsDisk . Visible = false ;
mnuSelectDisk . Visible = false ;
mnuEjectDisk . Visible = false ;
mnuSwitchDiskSide . Visible = false ;
}
}
}
private void mnuEjectDisk_Click ( object sender , EventArgs e )
{
InteropEmu . FdsEjectDisk ( ) ;
}
private void mnuSwitchDiskSide_Click ( object sender , EventArgs e )
{
InteropEmu . FdsSwitchDiskSide ( ) ;
}
private void SelectFdsBiosPrompt ( )
{
if ( MessageBox . Show ( "FDS bios not found. The bios is required to run FDS games." + Environment . NewLine + Environment . NewLine + "Select bios file now?" , "Mesen" , MessageBoxButtons . OKCancel , MessageBoxIcon . Question ) = = DialogResult . OK ) {
OpenFileDialog ofd = new OpenFileDialog ( ) ;
ofd . Filter = "All Files (*.*)|*.*" ;
if ( ofd . ShowDialog ( ) = = DialogResult . OK ) {
if ( MD5Helper . GetMD5Hash ( ofd . FileName ) . ToLowerInvariant ( ) = = "ca30b50f880eb660a320674ed365ef7a" ) {
File . Copy ( ofd . FileName , Path . Combine ( ConfigManager . HomeFolder , "FdsBios.bin" ) ) ;
LoadROM ( _romToLoad ) ;
} else {
MessageBox . Show ( "The selected bios file is invalid." , "Mesen" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
}
}
}
}
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 ] ) ;
}
}
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
private void mnuNetPlayPlayer1_Click ( object sender , EventArgs e )
{
InteropEmu . NetPlaySelectController ( 0 ) ;
}
private void mnuNetPlayPlayer2_Click ( object sender , EventArgs e )
{
InteropEmu . NetPlaySelectController ( 1 ) ;
}
private void mnuNetPlayPlayer3_Click ( object sender , EventArgs e )
{
InteropEmu . NetPlaySelectController ( 2 ) ;
}
private void mnuNetPlayPlayer4_Click ( object sender , EventArgs e )
{
InteropEmu . NetPlaySelectController ( 3 ) ;
}
private void mnuNetPlaySpectator_Click ( object sender , EventArgs e )
{
InteropEmu . NetPlaySelectController ( 0xFF ) ;
}
2016-02-07 13:05:32 -05:00
private void mnuFullscreen_Click ( object sender , EventArgs e )
{
SetFullscreenState ( ! _fullscreenMode ) ;
mnuFullscreen . Checked = _fullscreenMode ;
}
private void mnuScaleCustom_Click ( object sender , EventArgs e )
{
SetScaleBasedOnWindowSize ( ) ;
}
private void panelRenderer_Click ( object sender , EventArgs e )
{
ctrlRenderer . Focus ( ) ;
}
private void ctrlRenderer_Enter ( object sender , EventArgs e )
{
if ( _fullscreenMode ) {
this . menuStrip . Visible = false ;
}
}
private void menuStrip_VisibleChanged ( object sender , EventArgs e )
{
IntPtr handle = this . Handle ;
this . BeginInvoke ( ( MethodInvoker ) ( ( ) = > {
if ( _fullscreenMode & & _customSize ) {
SetScaleBasedOnWindowSize ( ) ;
}
} ) ) ;
}
2016-02-07 16:13:48 -05:00
private void mnuAbout_Click ( object sender , EventArgs e )
{
new frmAbout ( ) . ShowDialog ( ) ;
}
2016-02-08 23:23:31 -05:00
private void CheckForUpdates ( bool displayResult )
{
Task . Run ( ( ) = > {
try {
using ( var client = new WebClient ( ) ) {
XmlDocument xmlDoc = new XmlDocument ( ) ;
xmlDoc . LoadXml ( client . DownloadString ( "http://www.mesen.ca/Services/GetLatestVersion.php?v=" + InteropEmu . GetMesenVersion ( ) + "&p=win" ) ) ;
Version currentVersion = new Version ( InteropEmu . GetMesenVersion ( ) ) ;
Version latestVersion = new Version ( xmlDoc . SelectSingleNode ( "VersionInfo/LatestVersion" ) . InnerText ) ;
string changeLog = xmlDoc . SelectSingleNode ( "VersionInfo/ChangeLog" ) . InnerText ;
2016-02-10 18:58:13 -05:00
string fileHash = xmlDoc . SelectSingleNode ( "VersionInfo/Sha1Hash" ) . InnerText ;
2016-02-08 23:23:31 -05:00
if ( latestVersion > currentVersion ) {
this . BeginInvoke ( ( MethodInvoker ) ( ( ) = > {
2016-02-10 18:58:13 -05:00
frmUpdatePrompt frmUpdate = new frmUpdatePrompt ( currentVersion , latestVersion , changeLog , fileHash ) ;
if ( frmUpdate . ShowDialog ( null , this ) = = DialogResult . OK ) {
Application . Exit ( ) ;
}
2016-02-08 23:23:31 -05:00
} ) ) ;
} else if ( displayResult ) {
MessageBox . Show ( "You are running the latest version of Mesen." , "Mesen" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
}
}
} catch ( Exception ex ) {
if ( displayResult ) {
MessageBox . Show ( "An error has occurred while trying to check for updates." + Environment . NewLine + Environment . NewLine + "Error details:" + Environment . NewLine + ex . ToString ( ) , "Mesen" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
}
}
} ) ;
}
private void mnuCheckForUpdates_Click ( object sender , EventArgs e )
{
CheckForUpdates ( true ) ;
}
2015-07-01 23:17:14 -04:00
}
}