BizHawk/BizHawk.MultiClient/Program.cs

141 lines
3.7 KiB
C#
Raw Normal View History

2011-01-11 02:55:51 +00:00
using System;
using System.Windows.Forms;
#if WINDOWS
2011-01-11 02:55:51 +00:00
using SlimDX.Direct3D9;
using SlimDX.DirectSound;
using Microsoft.VisualBasic.ApplicationServices;
#endif
2011-01-11 02:55:51 +00:00
namespace BizHawk.MultiClient
{
static class Program
{
[STAThread]
unsafe static void Main(string[] args)
{
//string test = BizHawk.Emulation.Consoles.Nintendo.SNES.LibsnesDll.snes_library_revision_minor().ToString();
//BizHawk.Emulation.Consoles.Nintendo.SNES.LibsnesDll.snes_init();
//BizHawk.Emulation.Consoles.Nintendo.SNES.LibsnesDll.snes_video_refresh_t myvidproc =
// (ushort* data, int width, int height) =>
// {
// };
//System.Runtime.InteropServices.GCHandle handle = System.Runtime.InteropServices.GCHandle.Alloc(myvidproc);
////IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(myvidproc);
//BizHawk.Emulation.Consoles.Nintendo.SNES.LibsnesDll.snes_set_video_refresh(myvidproc);
//byte[] rom = System.IO.File.ReadAllBytes("d:\\Super Mario World (US).smc");
//BizHawk.Emulation.Consoles.Nintendo.SNES.LibsnesDll.snes_load_cartridge_normal(null, rom, rom.Length);
//BizHawk.Emulation.Consoles.Nintendo.SNES.LibsnesDll.snes_power();
//int framectr = 0;
//for (; ; )
//{
// framectr++;
// BizHawk.Emulation.Consoles.Nintendo.SNES.LibsnesDll.snes_run();
//}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
2011-01-11 02:55:51 +00:00
Global.Config = ConfigService.Load<Config>(PathManager.DefaultIniPath, new Config());
// this will look in subdirectory "dll" to load pinvoked stuff
Win32.SetDllDirectory("dll");
#if WINDOWS
try { Global.DSound = new DirectSound(); }
catch
{
2012-03-02 03:39:09 +00:00
MessageBox.Show("Couldn't initialize DirectSound! Things may go poorly for you. Try changing your sound driver to 41khz instead of 48khz in mmsys.cpl.", "Initialization Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
2011-01-11 02:55:51 +00:00
try { Global.Direct3D = new Direct3D(); }
catch
{
2011-08-21 01:07:58 +00:00
//fallback to GDI rendering
if (!Global.Config.DisplayGDI)
DisplayDirect3DError();
}
#endif
2011-01-11 02:55:51 +00:00
try
{
#if WINDOWS
if (Global.Config.SingleInstanceMode)
{
SingleInstanceController controller = new SingleInstanceController(args);
controller.Run(args);
}
else
{
#endif
using (var mf = new MainForm(args))
{
var title = mf.Text;
mf.Show();
mf.Text = title;
mf.ProgramRunLoop();
}
#if WINDOWS
}
#endif
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
#if WINDOWS
finally
{
if (Global.DSound != null && Global.DSound.Disposed == false)
Global.DSound.Dispose();
if (Global.Direct3D != null && Global.Direct3D.Disposed == false)
Global.Direct3D.Dispose();
}
#endif
}
#if WINDOWS
public class SingleInstanceController : WindowsFormsApplicationBase
{
MainForm mf;
string[] cmdArgs;
public SingleInstanceController(string[] args)
{
cmdArgs = args;
IsSingleInstance = true;
StartupNextInstance += this_StartupNextInstance;
}
void this_StartupNextInstance(object sender, StartupNextInstanceEventArgs e)
{
mf.LoadRom(e.CommandLine[0]);
}
protected override void OnCreateMainForm()
{
MainForm = new RamWatch();
mf = new MainForm(cmdArgs);
MainForm = mf;
mf.Show();
mf.ProgramRunLoop();
}
}
2011-08-21 01:07:58 +00:00
public static void DisplayDirect3DError()
{
MessageBox.Show("Failure to initialize Direct3D, reverting to GDI+ display method. Change the option in Config > GUI or install DirectX web update.", "Initialization Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
#endif
}
2011-01-11 02:55:51 +00:00
}