public void LoadCartridge(string baseDir, string cartridgeFile) { SnesApi.LoadRom(cartridgeFile, string.Empty); InitDebugger(); EnableDebugger(); RunGame(); }
private void StartEmulatorProcess(string baseDir) { var test = SnesApi.TestDll(); SnesApi.InitDll(); //EmuApi.InitDll(); var version = SnesApi.GetMesenVersion(); //InteropEmu.SetDisplayLanguage(Brewmaster.Emulation.Language.English); //SnesApi.SetDisplayLanguage(Mesen.GUI.Forms.Language.English); ApplyVideoConfig(); SnesApi.InitializeEmu(baseDir, _mainWindow.Handle, _renderControl.Handle, false, false, false); ApplyVideoConfig(); ApplyAudioConfig(); ApplyInputConfig(); ApplyEmulationConfig(); ApplyPreferenceConfig(); ApplyDebuggerConfig(); Mesen.GUI.ScreenSize size = SnesApi.GetScreenSize(false); _renderControl.Size = new Size(size.Width, size.Height); //SnesApi.AddKnownGameFolder(@"C:\Users\dkmrs\Documents\NesDev\sc"); _notifListener = new NotificationListener(); _notifListener.OnNotification += HandleNotification; //SnesApi.SetNesModel(NesModel.Auto); //SnesApi.DebugSetDebuggerConsole(SnesApi.ConsoleId.Master); }
private void HandleNotification(NotificationEventArgs e) { switch (e.NotificationType) { case ConsoleNotificationType.GameLoaded: if (!SnesApi.IsPaused()) { RefreshBreakpoints(); } GameLoaded(); if (OnRun != null) { OnRun(); } if (OnStatusChange != null) { OnStatusChange(EmulatorStatus.Playing); } EmitDebugData(); break; case ConsoleNotificationType.CodeBreak: var source = (SnesBreakSource)(byte)e.Parameter.ToInt64(); //if (source == SnesBreakSource.Breakpoint && OnBreak != null) if (OnBreak != null) { var state = SnesDebugApi.GetState(); var address = SnesDebugApi.GetAbsoluteAddress(new AddressInfo { Address = (state.Cpu.K << 16) | state.Cpu.PC, Type = SnesMemoryType.CpuMemory }); OnBreak(address.Address); } if (OnStatusChange != null) { OnStatusChange(EmulatorStatus.Paused); } EmitDebugData(); break; case ConsoleNotificationType.PpuFrameDone: CountFrame(); break; } if (e.NotificationType == ConsoleNotificationType.PpuFrameDone) { return; } if (e.NotificationType == ConsoleNotificationType.EventViewerRefresh) { return; } var status = string.Format("Emulator: {0}", e.NotificationType.ToString()); _logHandler(new LogData(status, LogType.Normal)); }
public void Dispose() { if (IsRunning()) { SnesApi.Pause(); Stop(); } }
public void SetScale(double scale) { VideoConfig.VideoScale = scale; ApplyVideoConfig(); ScreenSize size = SnesApi.GetScreenSize(false); _renderControl.Size = new Size(size.Width, size.Height); }
public void Resume() { if (!IsRunning()) { return; } SnesApi.Resume(); if (OnStatusChange != null) { OnStatusChange(EmulatorStatus.Playing); } }
public void Restart() { if (!IsRunning()) { return; } SnesApi.Reset(); //SnesApi.PowerCycle(); TODO: Would love to make powercycle possible, but causes a weird crash if you stop emulation after a powercycle before running the emulator for a while if (OnStatusChange != null) { OnStatusChange(EmulatorStatus.Playing); } }
public static Image GetSaveStatePreview(string saveStatePath) { if (File.Exists(saveStatePath)) { byte[] buffer = new byte[512 * 478 * 4]; Int32 size = EmuApi.GetSaveStatePreviewWrapper(saveStatePath, buffer); if (size > 0) { Array.Resize(ref buffer, size); using (MemoryStream stream = new MemoryStream(buffer)) { return(Image.FromStream(stream)); } } } return(null); }
public void Stop() { if (!IsRunning()) { return; } Task.Run(() => { try { SnesApi.Stop(); } catch (Exception ex) { Program.Error("An error occurred while trying to stop the SNES emulator!", ex); } }); _isRunning = false; if (OnStatusChange != null) { OnStatusChange(EmulatorStatus.Stopped); } }
public void LoadState(string file) { SnesApi.LoadStateFile(file); }
public void SaveState(string file) { SnesApi.SaveStateFile(file); }
public static string GetLog() { return(Utf8Marshaler.PtrToStringUtf8(EmuApi.GetLogWrapper()).Replace("\n", Environment.NewLine)); }