From 051382450ec59d1a80c3f2cef6425b44d6beef4a Mon Sep 17 00:00:00 2001 From: nattthebear Date: Wed, 31 May 2017 17:29:45 -0400 Subject: [PATCH] ngp: settings that theoretically work --- BizHawk.Client.EmuHawk/MainForm.Designer.cs | 26 +++++- BizHawk.Client.EmuHawk/MainForm.cs | 9 ++ .../Consoles/SNK/LibNeoGeoPort.cs | 7 +- .../Consoles/SNK/NeoGeoPort.cs | 92 +++++++++++++++++-- 4 files changed, 124 insertions(+), 10 deletions(-) diff --git a/BizHawk.Client.EmuHawk/MainForm.Designer.cs b/BizHawk.Client.EmuHawk/MainForm.Designer.cs index 8624674699..8acd080695 100644 --- a/BizHawk.Client.EmuHawk/MainForm.Designer.cs +++ b/BizHawk.Client.EmuHawk/MainForm.Designer.cs @@ -441,6 +441,8 @@ this.ShowMenuContextMenuSeparator = new System.Windows.Forms.ToolStripSeparator(); this.ShowMenuContextMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.timerMouseIdle = new System.Windows.Forms.Timer(this.components); + this.neoGeoPocketToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.preferencesToolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem(); this.MainformMenu.SuspendLayout(); this.MainStatusBar.SuspendLayout(); this.MainFormContextMenu.SuspendLayout(); @@ -475,11 +477,12 @@ this.IntvSubMenu, this.sNESToolStripMenuItem, this.virtualBoyToolStripMenuItem, + this.neoGeoPocketToolStripMenuItem, this.HelpSubMenu}); this.MainformMenu.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.Flow; this.MainformMenu.Location = new System.Drawing.Point(0, 0); this.MainformMenu.Name = "MainformMenu"; - this.MainformMenu.Size = new System.Drawing.Size(470, 57); + this.MainformMenu.Size = new System.Drawing.Size(470, 74); this.MainformMenu.TabIndex = 0; this.MainformMenu.Text = "menuStrip1"; this.MainformMenu.MenuActivate += new System.EventHandler(this.MainformMenu_MenuActivate); @@ -3198,7 +3201,7 @@ // preferencesToolStripMenuItem // this.preferencesToolStripMenuItem.Name = "preferencesToolStripMenuItem"; - this.preferencesToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.preferencesToolStripMenuItem.Size = new System.Drawing.Size(144, 22); this.preferencesToolStripMenuItem.Text = "Preferences..."; this.preferencesToolStripMenuItem.Click += new System.EventHandler(this.preferencesToolStripMenuItem_Click); // @@ -3213,7 +3216,7 @@ // preferencesToolStripMenuItem1 // this.preferencesToolStripMenuItem1.Name = "preferencesToolStripMenuItem1"; - this.preferencesToolStripMenuItem1.Size = new System.Drawing.Size(144, 22); + this.preferencesToolStripMenuItem1.Size = new System.Drawing.Size(152, 22); this.preferencesToolStripMenuItem1.Text = "Preferences..."; this.preferencesToolStripMenuItem1.Click += new System.EventHandler(this.preferencesToolStripMenuItem1_Click); // @@ -3906,6 +3909,21 @@ this.timerMouseIdle.Interval = 2000; this.timerMouseIdle.Tick += new System.EventHandler(this.TimerMouseIdle_Tick); // + // neoGeoPocketToolStripMenuItem + // + this.neoGeoPocketToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.preferencesToolStripMenuItem2}); + this.neoGeoPocketToolStripMenuItem.Name = "neoGeoPocketToolStripMenuItem"; + this.neoGeoPocketToolStripMenuItem.Size = new System.Drawing.Size(92, 17); + this.neoGeoPocketToolStripMenuItem.Text = "&NeoGeo Pocket"; + // + // preferencesToolStripMenuItem2 + // + this.preferencesToolStripMenuItem2.Name = "preferencesToolStripMenuItem2"; + this.preferencesToolStripMenuItem2.Size = new System.Drawing.Size(152, 22); + this.preferencesToolStripMenuItem2.Text = "Preferences..."; + this.preferencesToolStripMenuItem2.Click += new System.EventHandler(this.preferencesToolStripMenuItem2_Click); + // // MainForm // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; @@ -4358,5 +4376,7 @@ private System.Windows.Forms.ToolStripMenuItem preferencesToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem virtualBoyToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem preferencesToolStripMenuItem1; + private System.Windows.Forms.ToolStripMenuItem neoGeoPocketToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem preferencesToolStripMenuItem2; } } diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index 77928bec88..1961e2d2ae 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -1799,6 +1799,7 @@ namespace BizHawk.Client.EmuHawk IntvSubMenu.Visible = false; virtualBoyToolStripMenuItem.Visible = false; sNESToolStripMenuItem.Visible = false; + neoGeoPocketToolStripMenuItem.Visible = false; switch (system) { @@ -1880,6 +1881,9 @@ namespace BizHawk.Client.EmuHawk case "VB": virtualBoyToolStripMenuItem.Visible = true; break; + case "NGP": + neoGeoPocketToolStripMenuItem.Visible = true; + break; } } @@ -4304,6 +4308,11 @@ namespace BizHawk.Client.EmuHawk GenericCoreConfig.DoDialog(this, "Snes9x Settings"); } + private void preferencesToolStripMenuItem2_Click(object sender, EventArgs e) + { + GenericCoreConfig.DoDialog(this, "NeoPop Settings"); + } + private bool Rewind(ref bool runFrame, long currentTimestamp, out bool returnToRecording) { var isRewinding = false; diff --git a/BizHawk.Emulation.Cores/Consoles/SNK/LibNeoGeoPort.cs b/BizHawk.Emulation.Cores/Consoles/SNK/LibNeoGeoPort.cs index 952364d6db..93b5767d1a 100644 --- a/BizHawk.Emulation.Cores/Consoles/SNK/LibNeoGeoPort.cs +++ b/BizHawk.Emulation.Cores/Consoles/SNK/LibNeoGeoPort.cs @@ -27,8 +27,13 @@ namespace BizHawk.Emulation.Cores.Consoles.SNK public int Buttons; public int Lagged; } + public enum Language + { + Japanese, English + } + [BizImport(CC)] - public abstract bool LoadSystem(byte[] rom, int romlength, int language); + public abstract bool LoadSystem(byte[] rom, int romlength, Language language); [BizImport(CC)] public abstract void SetLayers(int enable); // 1, 2, 4 bg,fg,sprites [BizImport(CC)] diff --git a/BizHawk.Emulation.Cores/Consoles/SNK/NeoGeoPort.cs b/BizHawk.Emulation.Cores/Consoles/SNK/NeoGeoPort.cs index 5f750ad572..957e547718 100644 --- a/BizHawk.Emulation.Cores/Consoles/SNK/NeoGeoPort.cs +++ b/BizHawk.Emulation.Cores/Consoles/SNK/NeoGeoPort.cs @@ -1,9 +1,11 @@ -using BizHawk.Common.BizInvoke; +using BizHawk.Common; +using BizHawk.Common.BizInvoke; using BizHawk.Common.BufferExtensions; using BizHawk.Emulation.Common; using BizHawk.Emulation.Cores.Waterbox; using System; using System.Collections.Generic; +using System.ComponentModel; using System.IO; using System.Linq; using System.Text; @@ -13,16 +15,20 @@ namespace BizHawk.Emulation.Cores.Consoles.SNK { [CoreAttributes("NeoPop", "Thomas Klausner", true, false, "0.9.44.1", "https://mednafen.github.io/releases/", false)] - public class NeoGeoPort : IEmulator, IVideoProvider, ISoundProvider, IStatable, IInputPollable + public class NeoGeoPort : IEmulator, IVideoProvider, ISoundProvider, IStatable, IInputPollable, + ISettable { private PeRunner _exe; private LibNeoGeoPort _neopop; + private long _clockTime; + private int _clockDen; [CoreConstructor("NGP")] - public NeoGeoPort(CoreComm comm, byte[] rom) + public NeoGeoPort(CoreComm comm, byte[] rom, SyncSettings syncSettings, bool deterministic) { ServiceProvider = new BasicServiceProvider(this); CoreComm = comm; + _syncSettings = syncSettings ?? new SyncSettings(); _exe = new PeRunner(new PeRunnerOptions { @@ -36,7 +42,7 @@ namespace BizHawk.Emulation.Cores.Consoles.SNK _neopop = BizInvoker.GetInvoker(_exe, _exe); - if (!_neopop.LoadSystem(rom, rom.Length, 1)) + if (!_neopop.LoadSystem(rom, rom.Length, _syncSettings.Language)) { throw new InvalidOperationException("Core rejected the rom"); } @@ -45,10 +51,22 @@ namespace BizHawk.Emulation.Cores.Consoles.SNK _inputCallback = InputCallbacks.Call; InitMemoryDomains(); + + DeterministicEmulation = deterministic || !_syncSettings.UseRealTime; + _clockTime = (long)((_syncSettings.InitialTime - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds); } public unsafe void FrameAdvance(IController controller, bool render, bool rendersound = true) { + _clockDen += VsyncDenominator; + if (_clockDen >= VsyncNumerator) + { + _clockDen -= VsyncNumerator; + _clockTime++; + } + + long clockTime = DeterministicEmulation ? _clockTime : (long)((_syncSettings.InitialTime - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds); + _neopop.SetInputCallback(InputCallbacks.Count > 0 ? _inputCallback : null); if (controller.IsPressed("Power")) @@ -63,7 +81,8 @@ namespace BizHawk.Emulation.Cores.Consoles.SNK SoundBuff = (IntPtr)sp, SoundBufMaxSize = _soundBuffer.Length / 2, Buttons = GetButtons(controller), - SkipRendering = render ? 0 : 1 + SkipRendering = render ? 0 : 1, + FrontendTime = clockTime }; _neopop.FrameAdvance(spec); @@ -102,7 +121,7 @@ namespace BizHawk.Emulation.Cores.Consoles.SNK public IEmulatorServiceProvider ServiceProvider { get; private set; } public string SystemId { get { return "NGP"; } } - public bool DeterministicEmulation { get { return true; } } + public bool DeterministicEmulation { get; private set; } public CoreComm CoreComm { get; } #region IStatable @@ -259,6 +278,67 @@ namespace BizHawk.Emulation.Cores.Consoles.SNK #endregion + #region ISettable + + private SyncSettings _syncSettings; + + public class SyncSettings + { + [DisplayName("Language")] + [Description("Language of the system. Only affects some games.")] + [DefaultValue(LibNeoGeoPort.Language.Japanese)] + public LibNeoGeoPort.Language Language { get; set; } + + [DisplayName("Initial Time")] + [Description("Initial time of emulation. Only relevant when UseRealTime is false.")] + [DefaultValue(typeof(DateTime), "2010-01-01")] + public DateTime InitialTime { get; set; } + + [DisplayName("Use RealTime")] + [Description("If true, RTC clock will be based off of real time instead of emulated time. Ignored (set to false) when recording a movie.")] + [DefaultValue(false)] + public bool UseRealTime { get; set; } + + public SyncSettings Clone() + { + return (SyncSettings)MemberwiseClone(); + } + + public static bool NeedsReboot(SyncSettings x, SyncSettings y) + { + return !DeepEquality.DeepEquals(x, y); + } + + public SyncSettings() + { + SettingsUtil.SetDefaultValues(this); + } + } + + public object GetSettings() + { + return null; + } + + public SyncSettings GetSyncSettings() + { + return _syncSettings.Clone(); + } + + public bool PutSettings(object o) + { + return false; + } + + public bool PutSyncSettings(SyncSettings o) + { + var ret = SyncSettings.NeedsReboot(_syncSettings, o); + _syncSettings = o; + return ret; + } + + #endregion + #region Memory Domains private unsafe void InitMemoryDomains()