2014-12-20 15:56:01 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2014-12-20 16:01:11 +00:00
|
|
|
|
using System.Drawing;
|
2014-12-20 15:56:01 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2014-12-20 20:33:54 +00:00
|
|
|
|
using System.Windows.Forms;
|
2014-12-20 15:56:01 +00:00
|
|
|
|
|
|
|
|
|
namespace BizHawk.Client.EmuHawk
|
|
|
|
|
{
|
|
|
|
|
public partial class GenericDebugger
|
|
|
|
|
{
|
2014-12-23 02:34:08 +00:00
|
|
|
|
private readonly List<DisasmOp> DisassemblyLines = new List<DisasmOp>();
|
|
|
|
|
|
2014-12-20 15:56:01 +00:00
|
|
|
|
private class DisasmOp
|
|
|
|
|
{
|
2014-12-23 02:34:08 +00:00
|
|
|
|
public DisasmOp(uint address, int s, string m)
|
2014-12-20 15:56:01 +00:00
|
|
|
|
{
|
2014-12-23 02:34:08 +00:00
|
|
|
|
Address = address;
|
2014-12-20 15:56:01 +00:00
|
|
|
|
Size = s;
|
|
|
|
|
Mnemonic = m;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-23 02:34:08 +00:00
|
|
|
|
public uint Address { get; private set; }
|
2014-12-20 15:56:01 +00:00
|
|
|
|
public int Size { get; private set; }
|
|
|
|
|
public string Mnemonic { get; private set; }
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-20 18:11:42 +00:00
|
|
|
|
private int BusMaxValue
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return MemoryDomains.SystemBus.Size;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-20 15:56:01 +00:00
|
|
|
|
private void UpdateDisassembler()
|
|
|
|
|
{
|
|
|
|
|
if (CanDisassemble)
|
|
|
|
|
{
|
|
|
|
|
DisassemblerView.BlazingFast = true;
|
2014-12-20 20:33:54 +00:00
|
|
|
|
currentDisassemblerAddress = PC;
|
2014-12-23 02:34:08 +00:00
|
|
|
|
Disassemble();
|
2014-12-20 15:56:01 +00:00
|
|
|
|
DisassemblerView.Refresh();
|
|
|
|
|
DisassemblerView.BlazingFast = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-20 20:33:54 +00:00
|
|
|
|
uint currentDisassemblerAddress = 0;
|
|
|
|
|
|
2014-12-23 02:34:08 +00:00
|
|
|
|
private void Disassemble()
|
2014-12-20 15:56:01 +00:00
|
|
|
|
{
|
2014-12-23 02:34:08 +00:00
|
|
|
|
int line_count = DisassemblerView.NumberOfVisibleRows;
|
|
|
|
|
|
2014-12-20 15:56:01 +00:00
|
|
|
|
DisassemblyLines.Clear();
|
2014-12-20 20:33:54 +00:00
|
|
|
|
uint a = currentDisassemblerAddress;
|
2014-12-20 15:56:01 +00:00
|
|
|
|
for (int i = 0; i < line_count; ++i)
|
|
|
|
|
{
|
|
|
|
|
int advance;
|
|
|
|
|
string line = Disassembler.Disassemble(MemoryDomains.SystemBus, (ushort)a, out advance);
|
2014-12-23 02:34:08 +00:00
|
|
|
|
DisassemblyLines.Add(new DisasmOp(a, advance, line));
|
2014-12-20 20:33:54 +00:00
|
|
|
|
a += (uint)advance;
|
2014-12-20 18:11:42 +00:00
|
|
|
|
if (a > BusMaxValue)
|
2014-12-20 15:56:01 +00:00
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-12-20 16:01:11 +00:00
|
|
|
|
|
|
|
|
|
private void DisassemblerView_QueryItemText(int index, int column, out string text)
|
|
|
|
|
{
|
|
|
|
|
text = "";
|
2014-12-23 02:34:08 +00:00
|
|
|
|
|
|
|
|
|
if (index < DisassemblyLines.Count)
|
2014-12-20 16:01:11 +00:00
|
|
|
|
{
|
2014-12-23 02:34:08 +00:00
|
|
|
|
if (column == 0)
|
2014-12-20 16:01:11 +00:00
|
|
|
|
{
|
2014-12-23 02:34:08 +00:00
|
|
|
|
text = string.Format("{0:X4}", DisassemblyLines[index].Address);
|
2014-12-20 16:01:11 +00:00
|
|
|
|
}
|
2014-12-23 02:34:08 +00:00
|
|
|
|
else if (column == 1)
|
2014-12-20 16:01:11 +00:00
|
|
|
|
{
|
2014-12-23 02:34:08 +00:00
|
|
|
|
text = DisassemblyLines[index].Mnemonic;
|
2014-12-20 16:01:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DisassemblerView_QueryItemBkColor(int index, int column, ref Color color)
|
|
|
|
|
{
|
2014-12-23 03:13:13 +00:00
|
|
|
|
if (DisassemblyLines.Any() && index < DisassemblyLines.Count)
|
2014-12-20 16:01:11 +00:00
|
|
|
|
{
|
2014-12-23 03:13:13 +00:00
|
|
|
|
if (DisassemblyLines[index].Address == PC)
|
|
|
|
|
{
|
|
|
|
|
color = Color.LightCyan;
|
|
|
|
|
}
|
2014-12-20 16:01:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-12-20 20:33:54 +00:00
|
|
|
|
|
|
|
|
|
private void DecrementCurrentAddress()
|
|
|
|
|
{
|
|
|
|
|
uint newaddress = currentDisassemblerAddress;
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
int bytestoadvance;
|
|
|
|
|
Disassembler.Disassemble(MemoryDomains.SystemBus, newaddress, out bytestoadvance);
|
|
|
|
|
if (newaddress + bytestoadvance == currentDisassemblerAddress)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
newaddress--;
|
|
|
|
|
|
2014-12-23 02:34:08 +00:00
|
|
|
|
if (newaddress < 0)
|
|
|
|
|
{
|
|
|
|
|
newaddress = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-20 20:33:54 +00:00
|
|
|
|
// Just in case
|
|
|
|
|
if (currentDisassemblerAddress - newaddress > 5)
|
|
|
|
|
{
|
|
|
|
|
newaddress = currentDisassemblerAddress - 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
currentDisassemblerAddress = newaddress;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void IncrementCurrentAddress()
|
|
|
|
|
{
|
2014-12-23 02:13:26 +00:00
|
|
|
|
currentDisassemblerAddress += (uint)DisassemblyLines.First().Size;
|
2014-12-23 02:34:08 +00:00
|
|
|
|
if (currentDisassemblerAddress >= BusMaxValue)
|
|
|
|
|
{
|
|
|
|
|
currentDisassemblerAddress = (uint)(BusMaxValue - 1);
|
|
|
|
|
}
|
2014-12-20 20:33:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DisassemblerView_Scroll(object sender, ScrollEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Type == ScrollEventType.SmallIncrement)
|
|
|
|
|
{
|
|
|
|
|
IncrementCurrentAddress();
|
2014-12-23 02:34:08 +00:00
|
|
|
|
Disassemble();
|
2014-12-23 02:13:26 +00:00
|
|
|
|
DisassemblerView.Refresh();
|
2014-12-20 20:33:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (e.Type == ScrollEventType.SmallDecrement)
|
|
|
|
|
{
|
|
|
|
|
DecrementCurrentAddress();
|
2014-12-23 02:34:08 +00:00
|
|
|
|
Disassemble();
|
2014-12-23 02:13:26 +00:00
|
|
|
|
DisassemblerView.Refresh();
|
2014-12-20 20:33:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-12-23 02:34:08 +00:00
|
|
|
|
|
|
|
|
|
private void SetDisassemblerItemCount()
|
|
|
|
|
{
|
|
|
|
|
DisassemblerView.ItemCount = DisassemblerView.NumberOfVisibleRows + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DisassemblerView_SizeChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
SetDisassemblerItemCount();
|
|
|
|
|
Disassemble();
|
|
|
|
|
}
|
2014-12-20 15:56:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|