diff --git a/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj b/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj index 9bc0e25a96..a986e9fcda 100644 --- a/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj +++ b/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj @@ -649,6 +649,12 @@ GenericDebugger.cs Form + + UserControl + + + RegisterBoxControl.cs + Form @@ -1224,6 +1230,9 @@ GenericDebugger.cs + + RegisterBoxControl.cs + GBAGPUView.cs diff --git a/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Designer.cs b/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Designer.cs index 7fe4f35ddb..de9df40be4 100644 --- a/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Designer.cs @@ -42,8 +42,11 @@ this.TracerBox = new System.Windows.Forms.GroupBox(); this.TraceView = new BizHawk.Client.EmuHawk.VirtualListView(); this.Script = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.RegistersGroupBox = new System.Windows.Forms.GroupBox(); + this.RegisterPanel = new BizHawk.Client.EmuHawk.RegisterBoxControl(); this.menuStrip1.SuspendLayout(); this.TracerBox.SuspendLayout(); + this.RegistersGroupBox.SuspendLayout(); this.SuspendLayout(); // // menuStrip1 @@ -54,7 +57,7 @@ this.OptionsSubMenu}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(685, 24); + this.menuStrip1.Size = new System.Drawing.Size(746, 24); this.menuStrip1.TabIndex = 1; this.menuStrip1.Text = "menuStrip1"; // @@ -170,11 +173,37 @@ this.Script.Text = "Instructions"; this.Script.Width = 599; // + // RegistersGroupBox + // + this.RegistersGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.RegistersGroupBox.Controls.Add(this.RegisterPanel); + this.RegistersGroupBox.Location = new System.Drawing.Point(425, 27); + this.RegistersGroupBox.Name = "RegistersGroupBox"; + this.RegistersGroupBox.Size = new System.Drawing.Size(309, 234); + this.RegistersGroupBox.TabIndex = 8; + this.RegistersGroupBox.TabStop = false; + this.RegistersGroupBox.Text = "Registers"; + // + // RegisterPanel + // + this.RegisterPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.RegisterPanel.AutoScroll = true; + this.RegisterPanel.Core = null; + this.RegisterPanel.Location = new System.Drawing.Point(8, 19); + this.RegisterPanel.Name = "RegisterPanel"; + this.RegisterPanel.ParentDebugger = null; + this.RegisterPanel.Size = new System.Drawing.Size(295, 209); + this.RegisterPanel.TabIndex = 0; + // // GenericDebugger // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(685, 560); + this.ClientSize = new System.Drawing.Size(746, 560); + this.Controls.Add(this.RegistersGroupBox); this.Controls.Add(this.TracerBox); this.Controls.Add(this.menuStrip1); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); @@ -186,6 +215,7 @@ this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); this.TracerBox.ResumeLayout(false); + this.RegistersGroupBox.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); @@ -206,5 +236,7 @@ private System.Windows.Forms.GroupBox TracerBox; private VirtualListView TraceView; public System.Windows.Forms.ColumnHeader Script; + private System.Windows.Forms.GroupBox RegistersGroupBox; + private RegisterBoxControl RegisterPanel; } } \ No newline at end of file diff --git a/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.cs b/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.cs index ca1243e98c..c4bb0ec167 100644 --- a/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.cs +++ b/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.cs @@ -58,12 +58,20 @@ namespace BizHawk.Client.EmuHawk EngageDebugger(); } + public void DisableRegisterBox() + { + RegistersGroupBox.Enabled = false; + } + private void EngageDebugger() { try { Core.Tracer.Enabled = true; TraceView.Columns[0].Text = Core.Tracer.Header; + RegisterPanel.Core = Core; + RegisterPanel.ParentDebugger = this; + RegisterPanel.GenerateUI(); } catch (NotImplementedException) { diff --git a/BizHawk.Client.EmuHawk/tools/Debugger/RegisterBoxControl.Designer.cs b/BizHawk.Client.EmuHawk/tools/Debugger/RegisterBoxControl.Designer.cs new file mode 100644 index 0000000000..6dbf927af1 --- /dev/null +++ b/BizHawk.Client.EmuHawk/tools/Debugger/RegisterBoxControl.Designer.cs @@ -0,0 +1,47 @@ +namespace BizHawk.Client.EmuHawk +{ + partial class RegisterBoxControl + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.SuspendLayout(); + // + // RegisterBoxControl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Name = "RegisterBoxControl"; + this.Size = new System.Drawing.Size(240, 217); + this.Load += new System.EventHandler(this.RegisterBoxControl_Load); + this.ResumeLayout(false); + + } + + #endregion + + } +} diff --git a/BizHawk.Client.EmuHawk/tools/Debugger/RegisterBoxControl.cs b/BizHawk.Client.EmuHawk/tools/Debugger/RegisterBoxControl.cs new file mode 100644 index 0000000000..89a36111b1 --- /dev/null +++ b/BizHawk.Client.EmuHawk/tools/Debugger/RegisterBoxControl.cs @@ -0,0 +1,157 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +using BizHawk.Common.NumberExtensions; +using BizHawk.Emulation.Common; + +namespace BizHawk.Client.EmuHawk +{ + public partial class RegisterBoxControl : UserControl + { + public IDebuggable Core { get; set; } + public GenericDebugger ParentDebugger { get; set; } + + private bool _supressChangeEvents = false; + + public RegisterBoxControl() + { + InitializeComponent(); + AutoScroll = true; + } + + private void RegisterBoxControl_Load(object sender, EventArgs e) + { + + } + + private bool CanGetCpuRegisters + { + get + { + try + { + var registers = Core.GetCpuFlagsAndRegisters(); + return true; + } + catch (NotImplementedException) + { + return false; + } + } + } + + private bool CanSetCpuRegisters + { + get + { + try + { + Core.SetCpuRegister("", 0); + return true; + } + catch (NotImplementedException) + { + return false; + } + catch (Exception) + { + return true; + } + } + } + + public void GenerateUI() + { + var canget = CanGetCpuRegisters; + var canset = CanSetCpuRegisters; + + if (!canget && !canset) + { + ParentDebugger.DisableRegisterBox(); + this.Enabled = false; + } + + var registers = Core.GetCpuFlagsAndRegisters(); + + int y = 0; + foreach (var register in registers) + { + this.Controls.Add(new Label + { + Text = register.Key + (canset ? ": " : ""), + Location = new Point(5, y + 2), + Width = 50 + }); + + if (canset) + { + if (register.Key.Contains("Flag")) // TODO: this depends on naming conventions! + { + var c = new CheckBox + { + Name = register.Key, + Text = "", + Checked = register.Value == 1 ? true : false, + Location = new Point(55, y) + }; + + c.CheckedChanged += (o, e) => + { + if (!_supressChangeEvents) + { + try + { + Core.SetCpuRegister(c.Name, c.Checked ? 1 : 0); + } + catch (InvalidOperationException) // TODO: This is hacky stuff because NES doesn't support setting flags! Need to know when a core supports this or not, and enable/disable the box accordingly + { + _supressChangeEvents = true; + c.Checked = !c.Checked; + _supressChangeEvents = false; + c.Enabled = false; + } + } + }; + + this.Controls.Add(c); + } + else + { + var t = new TextBox + { + Name = register.Key, + Text = register.Value.ToString(), + Width = 75, + Location = new Point(55, y), + }; + + t.TextChanged += (o, e) => + { + Core.SetCpuRegister(t.Name, int.Parse(t.Text)); + }; + + this.Controls.Add(t); + } + } + else + { + this.Controls.Add(new Label + { + Name = register.Key, + Text = register.Value.ToString(), + Width = 75, + Location = new Point(55, y) + }); + } + + y += 25; + } + } + } +} diff --git a/BizHawk.Client.EmuHawk/tools/Debugger/RegisterBoxControl.resx b/BizHawk.Client.EmuHawk/tools/Debugger/RegisterBoxControl.resx new file mode 100644 index 0000000000..29dcb1b3a3 --- /dev/null +++ b/BizHawk.Client.EmuHawk/tools/Debugger/RegisterBoxControl.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file