Debugger: Added RW text markers for WRAM/SRAM/CHR RAM in memory mappings

This commit is contained in:
Sour 2019-01-08 18:06:52 -05:00
parent 945b043c98
commit 46b7ca1d43

View file

@ -13,10 +13,15 @@ namespace Mesen.GUI.Debugger.Controls
public string Name { get; set; }
public int Size { get; set; }
public Color Color { get; set; }
public MemoryAccessType AccessType { get; set; } = MemoryAccessType.Unspecified;
}
class ctrlMemoryMapping : Control
{
Font _largeFont = new Font("Arial", 9);
Font _mediumFont = new Font("Arial", 8);
Font _smallFont = new Font("Arial", 7);
List<MemoryRegionInfo> _regions = new List<MemoryRegionInfo>();
public ctrlMemoryMapping()
@ -49,17 +54,18 @@ namespace Mesen.GUI.Debugger.Controls
regions.Add(new MemoryRegionInfo() { Name = "CPU Registers", Size = 0x2020, Color = Color.FromArgb(222, 222, 222) });
Action<int> addEmpty = (int size) => { regions.Add(new MemoryRegionInfo() { Name = "N/A", Size = size, Color = Color.FromArgb(222, 222, 222) }); };
Action<int, int> addWorkRam = (int page, int size) => {
Action<int, int, MemoryAccessType> addWorkRam = (int page, int size, MemoryAccessType type) => {
string name = size >= 0x2000 ? ("Work RAM ($" + page.ToString("X2") + ")") : (size >= 0x800 ? ("$" + page.ToString("X2")) : "");
regions.Add(new MemoryRegionInfo() { Name = name, Size = size, Color = Color.FromArgb(0xCD, 0xDC, 0xFA) });
regions.Add(new MemoryRegionInfo() { Name = name, Size = size, Color = Color.FromArgb(0xCD, 0xDC, 0xFA), AccessType = type });
};
Action<int, int> addSaveRam = (int page, int size) => {
Action<int, int, MemoryAccessType> addSaveRam = (int page, int size, MemoryAccessType type) => {
string name = size >= 0x2000 ? ("Save RAM ($" + page.ToString("X2") + ")") : (size >= 0x800 ? ("$" + page.ToString("X2")) : "");
regions.Add(new MemoryRegionInfo() { Name = name, Size = size, Color = Color.FromArgb(0xFA, 0xDC, 0xCD) });
regions.Add(new MemoryRegionInfo() { Name = name, Size = size, Color = Color.FromArgb(0xFA, 0xDC, 0xCD), AccessType = type });
};
Action<int, int, Color> addPrgRom = (int page, int size, Color color) => { regions.Add(new MemoryRegionInfo() { Name = "$" + page.ToString("X2"), Size = size, Color = color }); };
PrgMemoryType? memoryType = null;
MemoryAccessType accessType = MemoryAccessType.Unspecified;
int currentSize = 0;
int sizeOffset = -0x20;
int startIndex = 0x40;
@ -77,12 +83,12 @@ namespace Mesen.GUI.Debugger.Controls
addPrgRom((int)(state.PrgMemoryOffset[startIndex] / state.PrgPageSize), size, alternateColor ? Color.FromArgb(0xC4, 0xE7, 0xD4) : Color.FromArgb(0xA4, 0xD7, 0xB4));
alternateColor = !alternateColor;
} else if(memoryType == PrgMemoryType.WorkRam) {
addWorkRam((int)(state.PrgMemoryOffset[startIndex] / state.WorkRamPageSize), size);
addWorkRam((int)(state.PrgMemoryOffset[startIndex] / state.WorkRamPageSize), size, accessType);
} else if(memoryType == PrgMemoryType.SaveRam) {
if(state.HasBattery) {
addSaveRam((int)(state.PrgMemoryOffset[startIndex] / state.SaveRamPageSize), size);
addSaveRam((int)(state.PrgMemoryOffset[startIndex] / state.SaveRamPageSize), size, accessType);
} else {
addWorkRam((int)(state.PrgMemoryOffset[startIndex] / state.SaveRamPageSize), size);
addWorkRam((int)(state.PrgMemoryOffset[startIndex] / state.SaveRamPageSize), size, accessType);
}
}
sizeOffset = 0;
@ -97,11 +103,13 @@ namespace Mesen.GUI.Debugger.Controls
addSection(i);
}
memoryType = state.PrgMemoryType[i];
accessType = state.PrgMemoryAccess[i];
} else {
if(memoryType != null) {
addSection(i);
}
memoryType = null;
accessType = MemoryAccessType.Unspecified;
}
currentSize += 0x100;
}
@ -114,6 +122,7 @@ namespace Mesen.GUI.Debugger.Controls
{
List<MemoryRegionInfo> regions = new List<MemoryRegionInfo>();
MemoryAccessType accessType = MemoryAccessType.Unspecified;
ChrMemoryType? memoryType = null;
int currentSize = 0;
int startIndex = 0;
@ -135,7 +144,7 @@ namespace Mesen.GUI.Debugger.Controls
int page = (int)(state.ChrMemoryOffset[startIndex] / state.ChrPageSize);
Color color = alternateColor ? Color.FromArgb(0xC4, 0xE0, 0xF4) : Color.FromArgb(0xB4, 0xD0, 0xE4);
alternateColor = !alternateColor;
regions.Add(new MemoryRegionInfo() { Name = "$" + page.ToString("X2"), Size = currentSize, Color = color });
regions.Add(new MemoryRegionInfo() { Name = "$" + page.ToString("X2"), Size = currentSize, Color = color, AccessType = accessType });
}
currentSize = 0;
startIndex = i;
@ -147,11 +156,13 @@ namespace Mesen.GUI.Debugger.Controls
if(forceNewBlock || memoryType != state.ChrMemoryType[i] || state.ChrMemoryOffset[i] - state.ChrMemoryOffset[i - 1] != 0x100) {
addSection(i);
}
accessType = state.ChrMemoryAccess[i];
memoryType = state.ChrMemoryType[i];
} else {
if(memoryType != null) {
addSection(i);
}
accessType = MemoryAccessType.Unspecified;
memoryType = null;
}
currentSize += 0x100;
@ -190,12 +201,29 @@ namespace Mesen.GUI.Debugger.Controls
}
e.Graphics.DrawRectangle(Pens.Black, currentPosition, 0, length, rect.Height);
e.Graphics.RotateTransform(-90);
SizeF textSize = e.Graphics.MeasureString(byteOffset.ToString("X4"), new Font("Arial", 8));
e.Graphics.DrawString(byteOffset.ToString("X4"), new Font("Arial", 8), Brushes.Black, -rect.Height + (rect.Height - textSize.Width) / 2, currentPosition + 3);
SizeF textSize = e.Graphics.MeasureString(byteOffset.ToString("X4"), _mediumFont);
e.Graphics.DrawString(byteOffset.ToString("X4"), _mediumFont, Brushes.Black, -rect.Height + (rect.Height - textSize.Width) / 2, currentPosition + 3);
e.Graphics.ResetTransform();
textSize = e.Graphics.MeasureString(region.Name, new Font("Arial", 9));
e.Graphics.DrawString(region.Name, new Font("Arial", 9), Brushes.Black, currentPosition + 12 + ((length - 12) / 2 - textSize.Width / 2), rect.Height / 2 - 7);
textSize = e.Graphics.MeasureString(region.Name, _largeFont);
e.Graphics.DrawString(region.Name, _largeFont, Brushes.Black, currentPosition + 12 + ((length - 12) / 2 - textSize.Width / 2), rect.Height / 2 - 7);
if(region.AccessType != MemoryAccessType.Unspecified) {
string accessTypeString = "";
if(((int)region.AccessType & (int)MemoryAccessType.Read) != 0) {
accessTypeString += "R";
}
if(((int)region.AccessType & (int)MemoryAccessType.Write) != 0) {
accessTypeString += "W";
}
if(string.IsNullOrWhiteSpace(accessTypeString)) {
//Mark it as "open bus" if it cannot be written/read
accessTypeString = "OB";
}
SizeF size = e.Graphics.MeasureString(accessTypeString, _smallFont);
e.Graphics.DrawString(accessTypeString, _smallFont, Brushes.Black, currentPosition + length - size.Width - 1, rect.Height - size.Height + 2);
}
currentPosition += length;
byteOffset += region.Size;