Example #1
0
        private void OnNotificationReceived(NotificationEventArgs e)
        {
            switch (e.NotificationType)
            {
            case ConsoleNotificationType.GameLoaded:
                this.BeginInvoke((Action)(() => {
                    UpdateDebuggerMenu();
                    ctrlRecentGames.Visible = false;
                    SaveStateManager.UpdateStateMenu(mnuLoadState, false);
                    SaveStateManager.UpdateStateMenu(mnuSaveState, true);

                    RomInfo romInfo = EmuApi.GetRomInfo();
                    this.Text = "Mesen-S - " + romInfo.GetRomName();

                    if (DebugWindowManager.HasOpenedWindow)
                    {
                        DebugWorkspaceManager.GetWorkspace();
                    }
                }));
                break;

            case ConsoleNotificationType.BeforeEmulationStop:
                this.Invoke((Action)(() => {
                    DebugWindowManager.CloseAll();
                }));
                break;

            case ConsoleNotificationType.EmulationStopped:
                this.BeginInvoke((Action)(() => {
                    this.Text = "Mesen-S";
                    UpdateDebuggerMenu();
                    ctrlRecentGames.Initialize();
                    ctrlRecentGames.Visible = true;
                    ResizeRecentGames();
                    if (_displayManager.ExclusiveFullscreen)
                    {
                        _displayManager.SetFullscreenState(false);
                    }
                }));
                break;

            case ConsoleNotificationType.ResolutionChanged:
                this.BeginInvoke((Action)(() => {
                    _displayManager.UpdateViewerSize();
                }));
                break;

            case ConsoleNotificationType.ExecuteShortcut:
                this.BeginInvoke((Action)(() => {
                    _shortcuts.ExecuteShortcut((EmulatorShortcut)e.Parameter);
                }));
                break;
            }
        }
Example #2
0
        private void OnNotificationReceived(NotificationEventArgs e)
        {
            switch (e.NotificationType)
            {
            case ConsoleNotificationType.GameLoaded:
                CheatCodes.ApplyCheats();

                this.BeginInvoke((Action)(() => {
                    UpdateDebuggerMenu();
                    ctrlRecentGames.Visible = false;
                    SaveStateManager.UpdateStateMenu(mnuLoadState, false);
                    SaveStateManager.UpdateStateMenu(mnuSaveState, true);

                    RomInfo romInfo = EmuApi.GetRomInfo();
                    this.Text = "Mesen-S - " + romInfo.GetRomName();

                    if (DebugWindowManager.HasOpenedWindow)
                    {
                        DebugWorkspaceManager.GetWorkspace();
                    }
                }));
                break;

            case ConsoleNotificationType.BeforeEmulationStop:
                this.Invoke((Action)(() => {
                    DebugWindowManager.CloseAll();
                }));
                break;

            case ConsoleNotificationType.GameResumed:
                this.BeginInvoke((Action)(() => {
                    //Ensure mouse is hidden when game is resumed
                    CursorManager.OnMouseMove(ctrlRenderer);
                }));
                break;

            case ConsoleNotificationType.EmulationStopped:
                this.BeginInvoke((Action)(() => {
                    this.Text = "Mesen-S";
                    UpdateDebuggerMenu();
                    ShowGameScreen(GameScreenMode.RecentGames);
                    ResizeRecentGames();
                    if (_displayManager.ExclusiveFullscreen)
                    {
                        _displayManager.SetFullscreenState(false);
                    }
                }));
                break;

            case ConsoleNotificationType.ResolutionChanged:
                this.BeginInvoke((Action)(() => {
                    _displayManager.UpdateViewerSize();
                }));
                break;

            case ConsoleNotificationType.ExecuteShortcut:
                this.BeginInvoke((Action)(() => {
                    _shortcuts.ExecuteShortcut((EmulatorShortcut)e.Parameter);
                }));
                break;

            case ConsoleNotificationType.MissingFirmware:
                this.Invoke((Action)(() => {
                    MissingFirmwareMessage msg = (MissingFirmwareMessage)Marshal.PtrToStructure(e.Parameter, typeof(MissingFirmwareMessage));
                    FirmwareHelper.RequestFirmwareFile(msg);
                }));
                break;
            }
        }
Example #3
0
        internal static int Run(string[] args)
        {
            ConfigManager.DoNotSaveSettings = true;
            string        romPath;
            List <string> luaScriptsToLoad;

            CommandLineHelper.GetRomPathFromCommandLine(CommandLineHelper.PreprocessCommandLineArguments(args, false), out romPath, out luaScriptsToLoad);
            if (romPath == null)
            {
                //No rom specified
                return(-1);
            }

            List <string> lcArgs = CommandLineHelper.PreprocessCommandLineArguments(args, true);

            int    timeout    = 100;       //100 seconds
            string timeoutArg = lcArgs.Find(arg => arg.StartsWith("/timeout="));

            if (timeoutArg != null)
            {
                int timeoutValue;
                if (Int32.TryParse(timeoutArg.Substring(timeoutArg.IndexOf("=") + 1), out timeoutValue))
                {
                    timeout = timeoutValue;
                }
            }

            InteropEmu.InitDll();
            ConfigManager.ProcessSwitches(lcArgs);
            ConfigManager.Config.ApplyConfig();
            InteropEmu.SetFlag(EmulationFlags.ConsoleMode, true);

            InteropEmu.InitializeEmu(ConfigManager.HomeFolder, IntPtr.Zero, IntPtr.Zero, true, true, true);

            InteropEmu.LoadROM(romPath, string.Empty);

            DebugWorkspaceManager.GetWorkspace();

            foreach (string luaScript in luaScriptsToLoad)
            {
                try {
                    string script = File.ReadAllText(luaScript);
                    InteropEmu.DebugLoadScript(luaScript, script);
                } catch { }
            }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            Task.Run(() => {
                InteropEmu.Run();
            });

            InteropEmu.SetFlag(EmulationFlags.ForceMaxSpeed, true);

            sw.Start();
            int result = -1;

            while (sw.ElapsedMilliseconds < timeout * 1000)
            {
                System.Threading.Thread.Sleep(100);

                if (!InteropEmu.IsRunning())
                {
                    result = InteropEmu.GetStopCode();
                    break;
                }
            }

            InteropEmu.Stop();
            InteropEmu.Release();
            return(result);
        }