Debugger: Memory Viewer - Fixed "Highlight labels" option for work/save ram memory types (+ some refactoring)

This commit is contained in:
Sour 2019-01-03 12:06:37 -05:00
parent 925b64481b
commit a18a3b7e95
3 changed files with 41 additions and 25 deletions

View file

@ -184,26 +184,16 @@ void CodeDataLogger::SetCdlData(uint8_t *cdlData, uint32_t length)
}
}
void CodeDataLogger::GetCdlData(uint32_t offset, uint32_t length, DebugMemoryType memoryType, uint8_t * cdlData)
void CodeDataLogger::GetCdlData(uint32_t offset, uint32_t length, DebugMemoryType memoryType, uint8_t *cdlData)
{
if(memoryType == DebugMemoryType::PrgRom) {
for(uint32_t i = 0; i < length; i++) {
cdlData[i] = _cdlData[offset + i];
if(_debugger->GetLabelManager()->HasLabelOrComment(offset + i, AddressType::PrgRom)) {
cdlData[i] |= 0x04; //Has label or comment
}
}
memcpy(cdlData, _cdlData + offset, length);
} else if(memoryType == DebugMemoryType::ChrRom) {
for(uint32_t i = 0; i < length; i++) {
cdlData[i] = _cdlData[_prgSize + offset + i];
}
memcpy(cdlData, _cdlData + _prgSize + offset, length);
} else if(memoryType == DebugMemoryType::CpuMemory) {
for(uint32_t i = 0; i < length; i++) {
int32_t absoluteAddress = _debugger->GetAbsoluteAddress(offset + i);
cdlData[i] = absoluteAddress >= 0 ? _cdlData[absoluteAddress] : 0;
if(_debugger->GetLabelManager()->HasLabelOrComment(offset + i)) {
cdlData[i] |= 0x04; //Has label or comment
}
}
} else if(memoryType == DebugMemoryType::PpuMemory) {
for(uint32_t i = 0; i < length; i++) {

View file

@ -16,6 +16,7 @@ namespace Mesen.GUI.Debugger
Int32[] _execCounts;
bool[] _freezeState;
byte[] _cdlData;
bool[] _hasLabel;
DebugState _state = new DebugState();
bool _showExec;
bool _showWrite;
@ -61,7 +62,7 @@ namespace Mesen.GUI.Debugger
_execCounts = InteropEmu.DebugGetMemoryAccessCountsEx((UInt32)firstByteIndex, (UInt32)(lastByteIndex - firstByteIndex + 1), _memoryType, MemoryOperationType.Exec);
_cdlData = null;
if(_highlightDmcDataBytes || _highlightDataBytes || _highlightCodeBytes || _highlightLabelledBytes) {
if(_highlightDmcDataBytes || _highlightDataBytes || _highlightCodeBytes) {
switch(_memoryType) {
case DebugMemoryType.ChrRom:
case DebugMemoryType.PpuMemory:
@ -72,6 +73,22 @@ namespace Mesen.GUI.Debugger
}
}
_hasLabel = new bool[lastByteIndex - firstByteIndex + 1];
if(_highlightLabelledBytes) {
if(_memoryType == DebugMemoryType.CpuMemory) {
for(long i = 0; i < _hasLabel.Length; i++) {
_hasLabel[i] = (
!string.IsNullOrWhiteSpace(LabelManager.GetLabel((UInt16)(i + firstByteIndex))?.Label) ||
!string.IsNullOrWhiteSpace(LabelManager.GetLabel((uint)(i + firstByteIndex), AddressType.Register)?.Label)
);
}
} else if(_memoryType == DebugMemoryType.PrgRom || _memoryType == DebugMemoryType.WorkRam || _memoryType == DebugMemoryType.SaveRam) {
for(long i = 0; i < _hasLabel.Length; i++) {
_hasLabel[i] = !string.IsNullOrWhiteSpace(LabelManager.GetLabel((uint)(firstByteIndex + i), _memoryType.ToAddressType())?.Label);
}
}
}
InteropEmu.DebugGetState(ref _state);
}
@ -111,21 +128,23 @@ namespace Mesen.GUI.Debugger
bgColor = Color.Transparent;
if(_cdlData != null) {
if((_cdlData[index] & 0x04) != 0 && _highlightLabelledBytes) {
//Labels/comments
bgColor = ConfigManager.Config.DebugInfo.RamLabelledByteColor;
} else if((_cdlData[index] & 0x01) != 0 && _highlightCodeBytes) {
if((_cdlData[index] & (byte)CdlPrgFlags.Code) != 0 && _highlightCodeBytes) {
//Code
bgColor = ConfigManager.Config.DebugInfo.RamCodeByteColor;
} else if((_cdlData[index] & 0x40) != 0 && _highlightDmcDataBytes) {
} else if((_cdlData[index] & (byte)CdlPrgFlags.PcmData) != 0 && _highlightDmcDataBytes) {
//DMC channel Data
bgColor = ConfigManager.Config.DebugInfo.RamDmcDataByteColor;
} else if((_cdlData[index] & 0x02) != 0 && _highlightDataBytes) {
} else if((_cdlData[index] & (byte)CdlPrgFlags.Data) != 0 && _highlightDataBytes) {
//Data
bgColor = ConfigManager.Config.DebugInfo.RamDataByteColor;
}
}
if(_hasLabel[index]) {
//Labels/comments
bgColor = ConfigManager.Config.DebugInfo.RamLabelledByteColor;
}
if(_freezeState != null && _freezeState[index]) {
return Color.Magenta;
} else if(_showExec && _execStamps[index] != 0 && framesSinceExec >= 0 && (framesSinceExec < _framesToFade || _framesToFade == 0)) {

View file

@ -49,7 +49,7 @@ namespace Mesen.GUI.Debugger
public class LabelManager
{
private static Dictionary<string, CodeLabel> _labels = new Dictionary<string, CodeLabel>();
private static Dictionary<UInt32, CodeLabel> _labels = new Dictionary<UInt32, CodeLabel>();
private static Dictionary<string, CodeLabel> _reverseLookup = new Dictionary<string, CodeLabel>();
public static event EventHandler OnLabelUpdated;
@ -98,9 +98,16 @@ namespace Mesen.GUI.Debugger
return _labels.Values.ToList<CodeLabel>();
}
private static string GetKey(UInt32 address, AddressType addressType)
private static UInt32 GetKey(UInt32 address, AddressType addressType)
{
return address.ToString() + addressType.ToString();
switch(addressType) {
case AddressType.InternalRam: return address | 0x80000000;
case AddressType.PrgRom: return address | 0xE0000000;
case AddressType.WorkRam: return address | 0xC0000000;
case AddressType.SaveRam: return address | 0xA0000000;
case AddressType.Register: return address | 0x60000000;
}
throw new Exception("Invalid type");
}
public static bool SetLabel(UInt32 address, AddressType type, string label, string comment, bool raiseEvent = true, CodeLabelFlags flags = CodeLabelFlags.None)
@ -111,7 +118,7 @@ namespace Mesen.GUI.Debugger
DeleteLabel(existingLabel.Address, existingLabel.AddressType, false);
}
string key = GetKey(address, type);
UInt32 key = GetKey(address, type);
if(_labels.ContainsKey(key)) {
_reverseLookup.Remove(_labels[key].Label);
}
@ -131,7 +138,7 @@ namespace Mesen.GUI.Debugger
public static void DeleteLabel(UInt32 address, AddressType type, bool raiseEvent)
{
string key = GetKey(address, type);
UInt32 key = GetKey(address, type);
if(_labels.ContainsKey(key)) {
_reverseLookup.Remove(_labels[key].Label);
}