From 25e7355fe460dc5f6a9107dad64c84f2c6355b9f Mon Sep 17 00:00:00 2001 From: goyuken Date: Thu, 6 Feb 2014 02:06:17 +0000 Subject: [PATCH] NES: region override. now you can add Subor Style to all of your favourite games --- .../NES/NESSyncSettingsForm.Designer.cs | 36 +++++++++-- .../config/NES/NESSyncSettingsForm.cs | 12 +++- .../Consoles/Nintendo/NES/Core.cs | 17 ++--- .../Consoles/Nintendo/NES/NES.cs | 62 ++++++++++++++++++- 4 files changed, 108 insertions(+), 19 deletions(-) diff --git a/BizHawk.Client.EmuHawk/config/NES/NESSyncSettingsForm.Designer.cs b/BizHawk.Client.EmuHawk/config/NES/NESSyncSettingsForm.Designer.cs index c57af90b7d..4619eb6eab 100644 --- a/BizHawk.Client.EmuHawk/config/NES/NESSyncSettingsForm.Designer.cs +++ b/BizHawk.Client.EmuHawk/config/NES/NESSyncSettingsForm.Designer.cs @@ -33,13 +33,15 @@ this.label1 = new System.Windows.Forms.Label(); this.dataGridView1 = new System.Windows.Forms.DataGridView(); this.HelpBtn = new System.Windows.Forms.Button(); + this.label2 = new System.Windows.Forms.Label(); + this.comboBox1 = new System.Windows.Forms.ComboBox(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); this.SuspendLayout(); // // 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(140, 238); + this.OkBtn.Location = new System.Drawing.Point(140, 402); this.OkBtn.Name = "OkBtn"; this.OkBtn.Size = new System.Drawing.Size(67, 23); this.OkBtn.TabIndex = 0; @@ -51,7 +53,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(213, 238); + this.CancelBtn.Location = new System.Drawing.Point(213, 402); this.CancelBtn.Name = "CancelBtn"; this.CancelBtn.Size = new System.Drawing.Size(67, 23); this.CancelBtn.TabIndex = 1; @@ -77,13 +79,13 @@ this.dataGridView1.Location = new System.Drawing.Point(12, 25); this.dataGridView1.MultiSelect = false; this.dataGridView1.Name = "dataGridView1"; - this.dataGridView1.Size = new System.Drawing.Size(268, 207); + this.dataGridView1.Size = new System.Drawing.Size(268, 307); this.dataGridView1.TabIndex = 3; // // HelpBtn // this.HelpBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.HelpBtn.Location = new System.Drawing.Point(12, 238); + this.HelpBtn.Location = new System.Drawing.Point(12, 338); this.HelpBtn.Name = "HelpBtn"; this.HelpBtn.Size = new System.Drawing.Size(23, 23); this.HelpBtn.TabIndex = 4; @@ -91,12 +93,34 @@ this.HelpBtn.UseVisualStyleBackColor = true; this.HelpBtn.Click += new System.EventHandler(this.HelpBtn_Click); // + // label2 + // + this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 378); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(44, 13); + this.label2.TabIndex = 5; + this.label2.Text = "Region:"; + // + // comboBox1 + // + this.comboBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.comboBox1.FormattingEnabled = true; + this.comboBox1.Location = new System.Drawing.Point(62, 375); + this.comboBox1.Name = "comboBox1"; + this.comboBox1.Size = new System.Drawing.Size(218, 21); + this.comboBox1.TabIndex = 6; + // // NESSyncSettingsForm // this.AcceptButton = this.OkBtn; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(292, 273); + this.ClientSize = new System.Drawing.Size(292, 437); + this.Controls.Add(this.comboBox1); + this.Controls.Add(this.label2); this.Controls.Add(this.HelpBtn); this.Controls.Add(this.dataGridView1); this.Controls.Add(this.label1); @@ -119,5 +143,7 @@ private System.Windows.Forms.Label label1; private System.Windows.Forms.DataGridView dataGridView1; private System.Windows.Forms.Button HelpBtn; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.ComboBox comboBox1; } } \ 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 b637b81ef3..ea62f8f00d 100644 --- a/BizHawk.Client.EmuHawk/config/NES/NESSyncSettingsForm.cs +++ b/BizHawk.Client.EmuHawk/config/NES/NESSyncSettingsForm.cs @@ -21,6 +21,10 @@ namespace BizHawk.Client.EmuHawk SyncSettings = (BizHawk.Emulation.Cores.Nintendo.NES.NES.NESSyncSettings)Global.Emulator.GetSyncSettings(); DTDB = new DataTableDictionaryBind(SyncSettings.BoardProperties); dataGridView1.DataSource = DTDB.Table; + + comboBox1.DropDownStyle = ComboBoxStyle.DropDownList; + comboBox1.Items.AddRange(Enum.GetNames(typeof(BizHawk.Emulation.Cores.Nintendo.NES.NES.NESSyncSettings.Region))); + comboBox1.SelectedItem = Enum.GetName(typeof(BizHawk.Emulation.Cores.Nintendo.NES.NES.NESSyncSettings.Region), SyncSettings.RegionOverride); } private void CancelBtn_Click(object sender, EventArgs e) @@ -31,8 +35,14 @@ namespace BizHawk.Client.EmuHawk private void OkBtn_Click(object sender, EventArgs e) { + var old = SyncSettings.RegionOverride; + SyncSettings.RegionOverride = (BizHawk.Emulation.Cores.Nintendo.NES.NES.NESSyncSettings.Region) + Enum.Parse( + typeof(BizHawk.Emulation.Cores.Nintendo.NES.NES.NESSyncSettings.Region), + (string)comboBox1.SelectedItem); + DialogResult = DialogResult.OK; - if (DTDB.WasModified) + if (DTDB.WasModified || old != SyncSettings.RegionOverride) { GlobalWin.MainForm.PutCoreSyncSettings(SyncSettings); } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Core.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Core.cs index 473780f23a..9cdda96b17 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Core.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Core.cs @@ -171,11 +171,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES // if (magicSoundProvider != null) magicSoundProvider.Dispose(); // set up region - switch (cart.system) + switch (_display_type) { - case "NES-PAL": - case "NES-PAL-A": - case "NES-PAL-B": + case Common.DisplayType.PAL: apu = new APU(this, apu, true); ppu.region = PPU.Region.PAL; CoreComm.VsyncNum = 50; @@ -184,8 +182,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES cpu_sequence = cpu_sequence_PAL; _display_type = DisplayType.PAL; break; - case "NES-NTSC": - case "Famicom": + case Common.DisplayType.NTSC: apu = new APU(this, apu, false); ppu.region = PPU.Region.NTSC; CoreComm.VsyncNum = 39375000; @@ -194,7 +191,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES cpu_sequence = cpu_sequence_NTSC; break; // this is in bootgod, but not used at all - case "Dendy": + case Common.DisplayType.DENDY: apu = new APU(this, apu, false); ppu.region = PPU.Region.Dendy; CoreComm.VsyncNum = 50; @@ -203,12 +200,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES cpu_sequence = cpu_sequence_NTSC; _display_type = DisplayType.DENDY; break; - case null: - Console.WriteLine("Unknown NES system! Defaulting to NTSC."); - goto case "NES-NTSC"; default: - Console.WriteLine("Unrecognized NES system \"{0}\"! Defaulting to NTSC.", cart.system); - goto case "NES-NTSC"; + throw new Exception("Unknown displaytype!"); } if (magicSoundProvider == null) magicSoundProvider = new MagicSoundProvider(this, (uint)cpuclockrate); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs index 15f951c81d..42c26e5dbc 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs @@ -768,9 +768,59 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES board.PostConfigure(); + // set up display type + + NESSyncSettings.Region fromrom = DetectRegion(cart.system); + NESSyncSettings.Region fromsettings = SyncSettings.RegionOverride; + + if (fromsettings != NESSyncSettings.Region.Default) + { + Console.WriteLine("Using system region override"); + fromrom = fromsettings; + } + switch (fromrom) + { + case NESSyncSettings.Region.Dendy: + _display_type = Common.DisplayType.DENDY; + break; + case NESSyncSettings.Region.NTSC: + _display_type = Common.DisplayType.NTSC; + break; + case NESSyncSettings.Region.PAL: + _display_type = Common.DisplayType.PAL; + break; + default: + _display_type = Common.DisplayType.NTSC; + break; + } + Console.WriteLine("Using NES system region of {0}", _display_type); + HardReset(); } + NESSyncSettings.Region DetectRegion(string system) + { + switch (system) + { + case "NES-PAL": + case "NES-PAL-A": + case "NES-PAL-B": + return NESSyncSettings.Region.PAL; + case "NES-NTSC": + case "Famicom": + return NESSyncSettings.Region.NTSC; + // this is in bootgod, but not used at all + case "Dendy": + return NESSyncSettings.Region.Dendy; + case null: + Console.WriteLine("Rom is of unknown NES region!"); + return NESSyncSettings.Region.Default; + default: + Console.WriteLine("Unrecognized region {0}", system); + return NESSyncSettings.Region.Default; + } + } + void SyncState(Serializer ser) { int version = 2; @@ -926,6 +976,16 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES { public Dictionary BoardProperties = new Dictionary(); + public enum Region + { + Default, + NTSC, + PAL, + Dendy + }; + + public Region RegionOverride = Region.Default; + public NESSyncSettings Clone() { var ret = (NESSyncSettings)MemberwiseClone(); @@ -935,7 +995,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES public static bool NeedsReboot(NESSyncSettings x, NESSyncSettings y) { - return !Util.DictionaryEqual(x.BoardProperties, y.BoardProperties); + return !(Util.DictionaryEqual(x.BoardProperties, y.BoardProperties) && x.RegionOverride == y.RegionOverride); } }