From 7a31121f203f26ac05a7f5f8a9aaa2774cb2f230 Mon Sep 17 00:00:00 2001 From: adelikat Date: Tue, 27 Sep 2016 09:52:21 -0400 Subject: [PATCH] NESHawk - Provide a UI for initial ram pattern override --- .../NES/NESSyncSettingsForm.Designer.cs | 54 +++++++++++++++---- .../config/NES/NESSyncSettingsForm.cs | 35 +++++++++--- .../Consoles/Nintendo/NES/NES.ISettable.cs | 8 ++- 3 files changed, 76 insertions(+), 21 deletions(-) diff --git a/BizHawk.Client.EmuHawk/config/NES/NESSyncSettingsForm.Designer.cs b/BizHawk.Client.EmuHawk/config/NES/NESSyncSettingsForm.Designer.cs index 3df9cfbbd9..10470a5099 100644 --- a/BizHawk.Client.EmuHawk/config/NES/NESSyncSettingsForm.Designer.cs +++ b/BizHawk.Client.EmuHawk/config/NES/NESSyncSettingsForm.Designer.cs @@ -37,6 +37,9 @@ this.BoardPropertiesGroupBox = new System.Windows.Forms.GroupBox(); this.label1 = new System.Windows.Forms.Label(); this.InfoLabel = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.RamPatternOverrideBox = new BizHawk.Client.EmuHawk.HexTextBox(); + this.label4 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); this.BoardPropertiesGroupBox.SuspendLayout(); this.SuspendLayout(); @@ -44,7 +47,7 @@ // OkBtn // this.OkBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.OkBtn.Location = new System.Drawing.Point(221, 354); + this.OkBtn.Location = new System.Drawing.Point(221, 423); this.OkBtn.Name = "OkBtn"; this.OkBtn.Size = new System.Drawing.Size(67, 23); this.OkBtn.TabIndex = 0; @@ -56,7 +59,7 @@ // this.CancelBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.CancelBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.CancelBtn.Location = new System.Drawing.Point(294, 354); + this.CancelBtn.Location = new System.Drawing.Point(294, 423); this.CancelBtn.Name = "CancelBtn"; this.CancelBtn.Size = new System.Drawing.Size(67, 23); this.CancelBtn.TabIndex = 1; @@ -73,7 +76,7 @@ this.dataGridView1.Location = new System.Drawing.Point(10, 19); this.dataGridView1.MultiSelect = false; this.dataGridView1.Name = "dataGridView1"; - this.dataGridView1.Size = new System.Drawing.Size(333, 203); + this.dataGridView1.Size = new System.Drawing.Size(333, 181); this.dataGridView1.TabIndex = 9; // // RegionComboBox @@ -89,7 +92,7 @@ // this.HelpBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.HelpBtn.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.Help; - this.HelpBtn.Location = new System.Drawing.Point(12, 87); + this.HelpBtn.Location = new System.Drawing.Point(12, 177); this.HelpBtn.Name = "HelpBtn"; this.HelpBtn.Size = new System.Drawing.Size(23, 23); this.HelpBtn.TabIndex = 10; @@ -111,9 +114,9 @@ | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.BoardPropertiesGroupBox.Controls.Add(this.dataGridView1); - this.BoardPropertiesGroupBox.Location = new System.Drawing.Point(12, 113); + this.BoardPropertiesGroupBox.Location = new System.Drawing.Point(12, 204); this.BoardPropertiesGroupBox.Name = "BoardPropertiesGroupBox"; - this.BoardPropertiesGroupBox.Size = new System.Drawing.Size(349, 228); + this.BoardPropertiesGroupBox.Size = new System.Drawing.Size(349, 206); this.BoardPropertiesGroupBox.TabIndex = 13; this.BoardPropertiesGroupBox.TabStop = false; this.BoardPropertiesGroupBox.Text = "Custom Board Properties"; @@ -129,20 +132,51 @@ // // InfoLabel // + this.InfoLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.InfoLabel.AutoSize = true; - this.InfoLabel.Location = new System.Drawing.Point(40, 92); + this.InfoLabel.Location = new System.Drawing.Point(41, 182); this.InfoLabel.Name = "InfoLabel"; this.InfoLabel.Size = new System.Drawing.Size(213, 13); this.InfoLabel.TabIndex = 15; this.InfoLabel.Text = "The current board has no custom properties"; // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(12, 92); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(133, 13); + this.label3.TabIndex = 16; + this.label3.Text = "Initial Ram pattern override"; + // + // RamPatternOverrideBox + // + this.RamPatternOverrideBox.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper; + this.RamPatternOverrideBox.Location = new System.Drawing.Point(12, 108); + this.RamPatternOverrideBox.Name = "RamPatternOverrideBox"; + this.RamPatternOverrideBox.Nullable = true; + this.RamPatternOverrideBox.Size = new System.Drawing.Size(165, 20); + this.RamPatternOverrideBox.TabIndex = 17; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(12, 131); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(269, 13); + this.label4.TabIndex = 18; + this.label4.Text = "Provides an override to the initial WRAM startup pattern"; + // // NESSyncSettingsForm // this.AcceptButton = this.OkBtn; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.CancelBtn; - this.ClientSize = new System.Drawing.Size(373, 389); + this.ClientSize = new System.Drawing.Size(373, 458); + this.Controls.Add(this.label4); + this.Controls.Add(this.RamPatternOverrideBox); + this.Controls.Add(this.label3); this.Controls.Add(this.InfoLabel); this.Controls.Add(this.label1); this.Controls.Add(this.BoardPropertiesGroupBox); @@ -156,7 +190,6 @@ this.ShowIcon = false; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "NES Advanced Settings"; - this.Load += new System.EventHandler(this.NESSyncSettingsForm_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); this.BoardPropertiesGroupBox.ResumeLayout(false); this.ResumeLayout(false); @@ -175,5 +208,8 @@ private System.Windows.Forms.Label label1; internal System.Windows.Forms.GroupBox BoardPropertiesGroupBox; private System.Windows.Forms.Label InfoLabel; + private System.Windows.Forms.Label label3; + private HexTextBox RamPatternOverrideBox; + private System.Windows.Forms.Label label4; } } \ No newline at end of file diff --git a/BizHawk.Client.EmuHawk/config/NES/NESSyncSettingsForm.cs b/BizHawk.Client.EmuHawk/config/NES/NESSyncSettingsForm.cs index d0d85e7318..ac890adbc3 100644 --- a/BizHawk.Client.EmuHawk/config/NES/NESSyncSettingsForm.cs +++ b/BizHawk.Client.EmuHawk/config/NES/NESSyncSettingsForm.cs @@ -8,7 +8,7 @@ using System.Text; using System.Windows.Forms; using BizHawk.Client.Common; using BizHawk.Emulation.Cores.Nintendo.NES; - +using BizHawk.Common.NumberExtensions; namespace BizHawk.Client.EmuHawk { public partial class NESSyncSettingsForm : Form @@ -39,6 +39,17 @@ namespace BizHawk.Client.EmuHawk RegionComboBox.Items.AddRange(Enum.GetNames(typeof(NES.NESSyncSettings.Region))); RegionComboBox.SelectedItem = Enum.GetName(typeof(NES.NESSyncSettings.Region), SyncSettings.RegionOverride); + + if (SyncSettings.InitialWRamStatePattern != null && SyncSettings.InitialWRamStatePattern.Any()) + { + var sb = new StringBuilder(); + foreach (var b in SyncSettings.InitialWRamStatePattern) + { + sb.Append(b.ToHexString(2)); + } + + RamPatternOverrideBox.Text = sb.ToString(); + } } private void CancelBtn_Click(object sender, EventArgs e) @@ -56,8 +67,23 @@ namespace BizHawk.Client.EmuHawk typeof(NES.NESSyncSettings.Region), (string)RegionComboBox.SelectedItem); + List oldRam = SyncSettings.InitialWRamStatePattern != null ? SyncSettings.InitialWRamStatePattern.ToList() : new List(); + + if (!string.IsNullOrWhiteSpace(RamPatternOverrideBox.Text)) + { + SyncSettings.InitialWRamStatePattern = Enumerable.Range(0, RamPatternOverrideBox.Text.Length) + .Where(x => x % 2 == 0) + .Select(x => Convert.ToByte(RamPatternOverrideBox.Text.Substring(x, 2), 16)) + .ToList(); + } + else + { + SyncSettings.InitialWRamStatePattern = null; + } + bool changed = (DTDB != null && DTDB.WasModified) || - old != SyncSettings.RegionOverride; + old != SyncSettings.RegionOverride || + !(oldRam.SequenceEqual(SyncSettings.InitialWRamStatePattern ?? new List())); DialogResult = DialogResult.OK; if (changed) @@ -75,10 +101,5 @@ namespace BizHawk.Client.EmuHawk MessageBoxButtons.OK, MessageBoxIcon.Information); } - - private void NESSyncSettingsForm_Load(object sender, EventArgs e) - { - - } } } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.ISettable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.ISettable.cs index ed511abec2..e428d9d5c7 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.ISettable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.ISettable.cs @@ -73,10 +73,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES public NESControlSettings Controls = new NESControlSettings(); - public List InitialWRamStatePattern = new List - { - 0, 0, 0, 0, 255, 255, 255, 255 - }; + public List InitialWRamStatePattern = null; public NESSyncSettings Clone() { @@ -90,7 +87,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES { return !(Util.DictionaryEqual(x.BoardProperties, y.BoardProperties) && x.RegionOverride == y.RegionOverride && - !NESControlSettings.NeedsReboot(x.Controls, y.Controls)); + !NESControlSettings.NeedsReboot(x.Controls, y.Controls) && + ((x.InitialWRamStatePattern ?? new List()).SequenceEqual(y.InitialWRamStatePattern ?? new List()))); } }