From 1d0b623d887f3a83978bbeb5a9b1c2f790b9a395 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 20 Dec 2014 20:33:54 +0000 Subject: [PATCH] Debugger - diassembler - an attempt to implement scrolling up (only works on small increment for now), but busted, arg --- .../Debugger/GenericDebugger.Designer.cs | 1 + .../Debugger/GenericDebugger.Disassembler.cs | 80 +++++++++++++++++-- .../Debugger/GenericDebugger.IToolForm.cs | 4 +- 3 files changed, 75 insertions(+), 10 deletions(-) diff --git a/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Designer.cs b/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Designer.cs index f1f29a8195..ee239eb7d1 100644 --- a/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Designer.cs @@ -277,6 +277,7 @@ this.DisassemblerView.UseCompatibleStateImageBehavior = false; this.DisassemblerView.UseCustomBackground = true; this.DisassemblerView.View = System.Windows.Forms.View.Details; + this.DisassemblerView.Scroll += new System.Windows.Forms.ScrollEventHandler(this.DisassemblerView_Scroll); // // Address // diff --git a/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Disassembler.cs b/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Disassembler.cs index 5e518c72a8..d659128157 100644 --- a/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Disassembler.cs +++ b/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Disassembler.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; +using System.Windows.Forms; namespace BizHawk.Client.EmuHawk { @@ -40,24 +41,27 @@ namespace BizHawk.Client.EmuHawk if (CanDisassemble) { DisassemblerView.BlazingFast = true; + currentDisassemblerAddress = PC; Disassemble(DISASM_LINE_COUNT); DisassemblerView.ensureVisible(BusMaxValue); - DisassemblerView.ensureVisible(PC); + DisassemblerView.ensureVisible((int)PC); DisassemblerView.Refresh(); DisassemblerView.BlazingFast = false; } } + uint currentDisassemblerAddress = 0; + private void Disassemble(int line_count) { DisassemblyLines.Clear(); - int a = PC; + 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)); - a += advance; + a += (uint)advance; if (a > BusMaxValue) { break; @@ -70,10 +74,11 @@ namespace BizHawk.Client.EmuHawk text = ""; if (column == 0) { - if (PC <= index && index < PC + DisassemblyLines.Count) + //if (PC <= index && index < PC + DisassemblyLines.Count) + if (currentDisassemblerAddress <= index && index < currentDisassemblerAddress + DisassemblyLines.Count) { - int a = PC; - for (int i = 0; i < index - PC; ++i) + int a = (int)currentDisassemblerAddress; + for (int i = 0; i < index - currentDisassemblerAddress; ++i) { a += DisassemblyLines[i].Size; } @@ -83,9 +88,10 @@ namespace BizHawk.Client.EmuHawk } else if (column == 1) { - if (PC <= index && index < PC + DisassemblyLines.Count) + //if (PC <= index && index < PC + DisassemblyLines.Count) + if (currentDisassemblerAddress <= index && index < currentDisassemblerAddress + DisassemblyLines.Count) { - text = DisassemblyLines[index - PC].Mnemonic; + text = DisassemblyLines[index - (int)currentDisassemblerAddress].Mnemonic; } } } @@ -97,5 +103,63 @@ namespace BizHawk.Client.EmuHawk color = Color.LightCyan; } } + + private void DecrementCurrentAddress() + { + uint newaddress = currentDisassemblerAddress; + while (true) + { + int bytestoadvance; + Disassembler.Disassemble(MemoryDomains.SystemBus, newaddress, out bytestoadvance); + if (newaddress + bytestoadvance == currentDisassemblerAddress) + { + break; + } + newaddress--; + + // Just in case + if (currentDisassemblerAddress - newaddress > 5) + { + newaddress = currentDisassemblerAddress - 1; + break; + } + } + + currentDisassemblerAddress = newaddress; + } + + private void IncrementCurrentAddress() + { + currentDisassemblerAddress++; + } + + private void DisassemblerView_Scroll(object sender, ScrollEventArgs e) + { + if (e.Type == ScrollEventType.SmallIncrement) + { + IncrementCurrentAddress(); + Disassemble(DISASM_LINE_COUNT); + } + + if (e.Type == ScrollEventType.SmallDecrement) + { + DecrementCurrentAddress(); + Disassemble(DISASM_LINE_COUNT); + } + + //int oldv = e.OldValue; + //int newv = e.NewValue; + //int diff = oldv - newv; + + //if (e.OldValue > e.NewValue) // Scrolled Up + //{ + // Disassemble(DISASM_LINE_COUNT, PC - (e.OldValue - e.NewValue)); + //} + //else if (e.OldValue < e.NewValue) // Scrolled Down + //{ + // Disassemble(DISASM_LINE_COUNT, PC - (e.OldValue - e.NewValue)); + //} + //} + } } } diff --git a/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.IToolForm.cs b/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.IToolForm.cs index ba74866c1d..58921774f2 100644 --- a/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.IToolForm.cs +++ b/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.IToolForm.cs @@ -20,10 +20,10 @@ namespace BizHawk.Client.EmuHawk private MemoryDomainList MemoryDomains { get { return MemoryDomainSource.MemoryDomains; } } - private int PC + private uint PC { // TODO: is this okay for N64? - get { return (int)Debuggable.GetCpuFlagsAndRegisters()[Disassembler.PCRegisterName].Value; } + get { return (uint)Debuggable.GetCpuFlagsAndRegisters()[Disassembler.PCRegisterName].Value; } } #region Implementation checking