diff --git a/BizHawk.Client.EmuHawk/CustomControls/VirtualListView.cs b/BizHawk.Client.EmuHawk/CustomControls/VirtualListView.cs index fe7c122d6f..d303379126 100644 --- a/BizHawk.Client.EmuHawk/CustomControls/VirtualListView.cs +++ b/BizHawk.Client.EmuHawk/CustomControls/VirtualListView.cs @@ -422,8 +422,20 @@ namespace BizHawk.Client.EmuHawk #endregion + [Browsable(false)] + [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)] public int LineHeight { get; private set; } + [Browsable(false)] + [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)] + public int NumberOfVisibleRows + { + get + { + return Height / LineHeight; + } + } + #region Constructors /// diff --git a/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Designer.cs b/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Designer.cs index 7272a51114..0b45108400 100644 --- a/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Designer.cs @@ -80,7 +80,7 @@ // this.ExitMenuItem.Name = "ExitMenuItem"; this.ExitMenuItem.ShortcutKeyDisplayString = "Alt+F4"; - this.ExitMenuItem.Size = new System.Drawing.Size(152, 22); + this.ExitMenuItem.Size = new System.Drawing.Size(145, 22); this.ExitMenuItem.Text = "&Close"; this.ExitMenuItem.Click += new System.EventHandler(this.ExitMenuItem_Click); // @@ -217,6 +217,7 @@ this.DisassemblerView.UseCustomBackground = true; this.DisassemblerView.View = System.Windows.Forms.View.Details; this.DisassemblerView.Scroll += new System.Windows.Forms.ScrollEventHandler(this.DisassemblerView_Scroll); + this.DisassemblerView.SizeChanged += new System.EventHandler(this.DisassemblerView_SizeChanged); // // Address // diff --git a/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Disassembler.cs b/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Disassembler.cs index 15da9bbfb0..54e305b129 100644 --- a/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Disassembler.cs +++ b/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Disassembler.cs @@ -9,20 +9,22 @@ namespace BizHawk.Client.EmuHawk { public partial class GenericDebugger { + private readonly List DisassemblyLines = new List(); + private class DisasmOp { - public DisasmOp(int s, string m) + public DisasmOp(uint address, int s, string m) { + Address = address; Size = s; Mnemonic = m; } + public uint Address { get; private set; } public int Size { get; private set; } public string Mnemonic { get; private set; } } - //private const int ADDR_MAX = 0xFFFF; // TODO: this isn't a constant, calculate it off bus size - private int BusMaxValue { get @@ -31,20 +33,13 @@ namespace BizHawk.Client.EmuHawk } } - private const int DISASM_LINE_COUNT = 100; - - private readonly List DisassemblyLines = new List(); - private void UpdateDisassembler() { - // Always show a window's worth of instructions (if possible) if (CanDisassemble) { DisassemblerView.BlazingFast = true; currentDisassemblerAddress = PC; - Disassemble(DISASM_LINE_COUNT); - DisassemblerView.ensureVisible(BusMaxValue); - DisassemblerView.ensureVisible((int)PC); + Disassemble(); DisassemblerView.Refresh(); DisassemblerView.BlazingFast = false; } @@ -52,15 +47,17 @@ namespace BizHawk.Client.EmuHawk uint currentDisassemblerAddress = 0; - private void Disassemble(int line_count) + private void Disassemble() { + int line_count = DisassemblerView.NumberOfVisibleRows; + DisassemblyLines.Clear(); uint a = currentDisassemblerAddress; for (int i = 0; i < line_count; ++i) { int advance; string line = Disassembler.Disassemble(MemoryDomains.SystemBus, (ushort)a, out advance); - DisassemblyLines.Add(new DisasmOp(advance, line)); + DisassemblyLines.Add(new DisasmOp(a, advance, line)); a += (uint)advance; if (a > BusMaxValue) { @@ -72,33 +69,23 @@ namespace BizHawk.Client.EmuHawk private void DisassemblerView_QueryItemText(int index, int column, out string text) { text = ""; - if (column == 0) - { - //if (PC <= index && index < PC + DisassemblyLines.Count) - if (currentDisassemblerAddress <= index && index < currentDisassemblerAddress + DisassemblyLines.Count) - { - int a = (int)currentDisassemblerAddress; - for (int i = 0; i < index - currentDisassemblerAddress; ++i) - { - a += DisassemblyLines[i].Size; - } - text = string.Format("{0:X4}", a); - } - } - else if (column == 1) + if (index < DisassemblyLines.Count) { - //if (PC <= index && index < PC + DisassemblyLines.Count) - if (currentDisassemblerAddress <= index && index < currentDisassemblerAddress + DisassemblyLines.Count) + if (column == 0) { - text = DisassemblyLines[index - (int)currentDisassemblerAddress].Mnemonic; + text = string.Format("{0:X4}", DisassemblyLines[index].Address); + } + else if (column == 1) + { + text = DisassemblyLines[index].Mnemonic; } } } private void DisassemblerView_QueryItemBkColor(int index, int column, ref Color color) { - if (index == PC) + if (DisassemblyLines[index].Address == PC) { color = Color.LightCyan; } @@ -117,6 +104,12 @@ namespace BizHawk.Client.EmuHawk } newaddress--; + if (newaddress < 0) + { + newaddress = 0; + break; + } + // Just in case if (currentDisassemblerAddress - newaddress > 5) { @@ -131,6 +124,10 @@ namespace BizHawk.Client.EmuHawk private void IncrementCurrentAddress() { currentDisassemblerAddress += (uint)DisassemblyLines.First().Size; + if (currentDisassemblerAddress >= BusMaxValue) + { + currentDisassemblerAddress = (uint)(BusMaxValue - 1); + } } private void DisassemblerView_Scroll(object sender, ScrollEventArgs e) @@ -138,16 +135,27 @@ namespace BizHawk.Client.EmuHawk if (e.Type == ScrollEventType.SmallIncrement) { IncrementCurrentAddress(); - Disassemble(DISASM_LINE_COUNT); + Disassemble(); DisassemblerView.Refresh(); } if (e.Type == ScrollEventType.SmallDecrement) { DecrementCurrentAddress(); - Disassemble(DISASM_LINE_COUNT); + Disassemble(); DisassemblerView.Refresh(); } } + + private void SetDisassemblerItemCount() + { + DisassemblerView.ItemCount = DisassemblerView.NumberOfVisibleRows + 1; + } + + private void DisassemblerView_SizeChanged(object sender, EventArgs e) + { + SetDisassemblerItemCount(); + Disassemble(); + } } } diff --git a/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.cs b/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.cs index 879227b326..1512800422 100644 --- a/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.cs +++ b/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.cs @@ -28,8 +28,9 @@ namespace BizHawk.Client.EmuHawk private void GenericDebugger_Load(object sender, EventArgs e) { - DisassemblerView.ItemCount = BusMaxValue + 1; + SetDisassemblerItemCount(); EngageDebugger(); + UpdateDisassembler(); } public void DisableRegisterBox()