2019-04-28 22:19:52 -04:00
|
|
|
|
using Mesen.GUI.Debugger.Labels;
|
|
|
|
|
using System;
|
2019-02-27 19:49:26 -05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Mesen.GUI.Debugger
|
|
|
|
|
{
|
|
|
|
|
public class CodeLineData
|
|
|
|
|
{
|
2019-04-28 22:19:52 -04:00
|
|
|
|
private CpuType _cpuType;
|
|
|
|
|
|
2019-02-27 19:49:26 -05:00
|
|
|
|
public string Text;
|
|
|
|
|
|
|
|
|
|
public Int32 Address;
|
|
|
|
|
public Int32 AbsoluteAddress;
|
|
|
|
|
|
|
|
|
|
public LineFlags Flags;
|
|
|
|
|
|
2019-05-04 09:33:28 -04:00
|
|
|
|
public int? CustomIndent = null;
|
|
|
|
|
|
2019-02-27 19:49:26 -05:00
|
|
|
|
public byte OpSize;
|
|
|
|
|
public string ByteCode;
|
|
|
|
|
public string Comment;
|
|
|
|
|
|
|
|
|
|
public Int32 EffectiveAddress;
|
2019-02-28 16:53:04 -05:00
|
|
|
|
public UInt16 Value;
|
|
|
|
|
public byte ValueSize;
|
2019-02-27 19:49:26 -05:00
|
|
|
|
|
2019-04-07 17:57:30 -04:00
|
|
|
|
public string GetEffectiveAddressString(string format)
|
2019-02-27 19:49:26 -05:00
|
|
|
|
{
|
2019-02-28 16:53:04 -05:00
|
|
|
|
if(EffectiveAddress >= 0) {
|
2019-07-18 08:31:41 -04:00
|
|
|
|
AddressInfo relAddress = new AddressInfo() { Address = EffectiveAddress, Type = _cpuType.ToMemoryType() };
|
2019-04-28 22:19:52 -04:00
|
|
|
|
CodeLabel label = LabelManager.GetLabel(relAddress);
|
|
|
|
|
if(label != null) {
|
|
|
|
|
if(label.Length > 1) {
|
|
|
|
|
int gap = DebugApi.GetAbsoluteAddress(relAddress).Address - label.GetAbsoluteAddress().Address;
|
|
|
|
|
if(gap > 0) {
|
|
|
|
|
return "[" + label.Label + "+" + gap.ToString() + "]";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return "[" + label.Label + "]";
|
|
|
|
|
} else {
|
2019-05-04 13:54:17 -04:00
|
|
|
|
return "[$" + EffectiveAddress.ToString(format) + "]";
|
2019-04-28 22:19:52 -04:00
|
|
|
|
}
|
2019-02-28 16:53:04 -05:00
|
|
|
|
} else {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetValueString()
|
|
|
|
|
{
|
|
|
|
|
if(ValueSize == 1) {
|
|
|
|
|
return " = $" + Value.ToString("X2");
|
|
|
|
|
} else if(ValueSize == 2) {
|
|
|
|
|
return " = $" + Value.ToString("X4");
|
|
|
|
|
} else {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
2019-02-27 19:49:26 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Indentation
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2019-05-04 09:33:28 -04:00
|
|
|
|
if(CustomIndent.HasValue) {
|
|
|
|
|
return CustomIndent.Value;
|
2019-05-24 21:47:06 -04:00
|
|
|
|
} else if(Flags.HasFlag(LineFlags.ShowAsData) || Flags.HasFlag(LineFlags.BlockStart) || Flags.HasFlag(LineFlags.BlockEnd) || Flags.HasFlag(LineFlags.Label) || (Flags.HasFlag(LineFlags.Comment) && Text.Length == 0)) {
|
2019-02-27 19:49:26 -05:00
|
|
|
|
return 0;
|
|
|
|
|
} else {
|
2019-04-28 22:19:52 -04:00
|
|
|
|
return 15;
|
2019-02-27 19:49:26 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-28 22:19:52 -04:00
|
|
|
|
public CodeLineData(CpuType cpuType)
|
2019-02-27 19:49:26 -05:00
|
|
|
|
{
|
2019-04-28 22:19:52 -04:00
|
|
|
|
_cpuType = cpuType;
|
2019-02-27 19:49:26 -05:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-28 22:19:52 -04:00
|
|
|
|
public CodeLineData(InteropCodeLineData data, CpuType cpuType)
|
2019-02-27 19:49:26 -05:00
|
|
|
|
{
|
2019-04-28 22:19:52 -04:00
|
|
|
|
_cpuType = cpuType;
|
|
|
|
|
|
2019-02-27 19:49:26 -05:00
|
|
|
|
this.Text = ConvertString(data.Text);
|
|
|
|
|
this.Comment = ConvertString(data.Comment);
|
|
|
|
|
this.OpSize = data.OpSize;
|
|
|
|
|
for(int i = 0; i < this.OpSize; i++) {
|
|
|
|
|
this.ByteCode += "$" + data.ByteCode[i].ToString("X2") + " ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.Address = data.Address;
|
|
|
|
|
this.AbsoluteAddress = data.AbsoluteAddress;
|
|
|
|
|
this.EffectiveAddress = data.EffectiveAddress;
|
|
|
|
|
this.Flags = (LineFlags)data.Flags;
|
|
|
|
|
this.Value = data.Value;
|
2019-02-28 16:53:04 -05:00
|
|
|
|
this.ValueSize = data.ValueSize;
|
2019-02-27 19:49:26 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string ConvertString(byte[] stringArray)
|
|
|
|
|
{
|
|
|
|
|
int length = 0;
|
|
|
|
|
for(int i = 0; i < 1000; i++) {
|
|
|
|
|
if(stringArray[i] == 0) {
|
|
|
|
|
length = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Encoding.UTF8.GetString(stringArray, 0, length);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public struct InteropCodeLineData
|
|
|
|
|
{
|
|
|
|
|
public Int32 Address;
|
|
|
|
|
public Int32 AbsoluteAddress;
|
|
|
|
|
public byte OpSize;
|
2019-04-28 22:19:52 -04:00
|
|
|
|
public UInt16 Flags;
|
2019-02-27 19:49:26 -05:00
|
|
|
|
|
|
|
|
|
public Int32 EffectiveAddress;
|
2019-02-28 16:53:04 -05:00
|
|
|
|
public UInt16 Value;
|
|
|
|
|
public byte ValueSize;
|
2019-02-27 19:49:26 -05:00
|
|
|
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
|
|
|
|
|
public byte[] ByteCode;
|
|
|
|
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1000)]
|
|
|
|
|
public byte[] Text;
|
|
|
|
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1000)]
|
|
|
|
|
public byte[] Comment;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-28 22:19:52 -04:00
|
|
|
|
public enum LineFlags : UInt16
|
2019-02-27 19:49:26 -05:00
|
|
|
|
{
|
2019-04-28 22:19:52 -04:00
|
|
|
|
None = 0,
|
|
|
|
|
PrgRom = 0x01,
|
|
|
|
|
WorkRam = 0x02,
|
|
|
|
|
SaveRam = 0x04,
|
|
|
|
|
VerifiedData = 0x08,
|
|
|
|
|
VerifiedCode = 0x10,
|
|
|
|
|
BlockStart = 0x20,
|
|
|
|
|
BlockEnd = 0x40,
|
|
|
|
|
SubStart = 0x80,
|
|
|
|
|
Label = 0x100,
|
|
|
|
|
Comment = 0x200,
|
2019-05-24 21:47:06 -04:00
|
|
|
|
ShowAsData = 0x400
|
2019-02-27 19:49:26 -05:00
|
|
|
|
}
|
|
|
|
|
}
|