2017-12-26 17:33:46 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
2019-01-03 14:27:10 -05:00
|
|
|
|
using System.Linq;
|
2017-12-26 17:33:46 -05:00
|
|
|
|
using Be.Windows.Forms;
|
2017-12-26 17:55:08 -05:00
|
|
|
|
using Mesen.GUI.Config;
|
2017-12-26 17:33:46 -05:00
|
|
|
|
|
|
|
|
|
namespace Mesen.GUI.Debugger
|
|
|
|
|
{
|
|
|
|
|
public class ChrByteColorProvider : IByteColorProvider
|
|
|
|
|
{
|
|
|
|
|
DebugMemoryType _memoryType;
|
2020-02-14 21:40:50 -05:00
|
|
|
|
AddressCounters[] _counts;
|
2019-01-13 18:32:27 -05:00
|
|
|
|
DebugState _state = new DebugState();
|
|
|
|
|
bool _showWrite;
|
|
|
|
|
bool _showRead;
|
|
|
|
|
int _framesToFade;
|
|
|
|
|
bool _hideUnusedBytes;
|
|
|
|
|
bool _hideReadBytes;
|
|
|
|
|
bool _hideWrittenBytes;
|
2017-12-26 17:33:46 -05:00
|
|
|
|
bool _highlightDrawnBytes;
|
|
|
|
|
bool _highlightReadBytes;
|
2019-01-03 14:27:10 -05:00
|
|
|
|
bool _highlightBreakpoints;
|
2017-12-26 17:33:46 -05:00
|
|
|
|
byte[] _cdlData;
|
2019-01-03 14:27:10 -05:00
|
|
|
|
ByteColors _colors = new ByteColors();
|
|
|
|
|
BreakpointType[] _breakpointTypes;
|
2017-12-26 17:33:46 -05:00
|
|
|
|
|
2019-01-13 18:32:27 -05:00
|
|
|
|
public ChrByteColorProvider(DebugMemoryType memoryType, bool showWrite, bool showRead, int framesToFade, bool hideUnusedBytes, bool hideReadBytes, bool hideWrittenBytes, bool highlightDrawnBytes, bool highlightReadBytes, bool highlightBreakpoints)
|
2017-12-26 17:33:46 -05:00
|
|
|
|
{
|
|
|
|
|
_memoryType = memoryType;
|
2019-01-13 18:32:27 -05:00
|
|
|
|
_showWrite = showWrite;
|
|
|
|
|
_showRead = showRead;
|
|
|
|
|
_framesToFade = framesToFade;
|
|
|
|
|
_hideUnusedBytes = hideUnusedBytes;
|
|
|
|
|
_hideReadBytes = hideReadBytes;
|
|
|
|
|
_hideWrittenBytes = hideWrittenBytes;
|
2017-12-26 17:33:46 -05:00
|
|
|
|
_highlightDrawnBytes = highlightDrawnBytes;
|
|
|
|
|
_highlightReadBytes = highlightReadBytes;
|
2019-01-03 14:27:10 -05:00
|
|
|
|
_highlightBreakpoints = highlightBreakpoints;
|
|
|
|
|
|
|
|
|
|
_colors.ForeColor = Color.Black;
|
2017-12-26 17:33:46 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Prepare(long firstByteIndex, long lastByteIndex)
|
|
|
|
|
{
|
2019-01-03 14:27:10 -05:00
|
|
|
|
int visibleByteCount = (int)(lastByteIndex - firstByteIndex + 1);
|
|
|
|
|
if(_highlightBreakpoints) {
|
|
|
|
|
Breakpoint[] breakpoints = BreakpointManager.Breakpoints.ToArray();
|
|
|
|
|
_breakpointTypes = new BreakpointType[visibleByteCount];
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < visibleByteCount; i++) {
|
|
|
|
|
int byteIndex = i + (int)firstByteIndex;
|
|
|
|
|
foreach(Breakpoint bp in breakpoints) {
|
|
|
|
|
if(bp.Enabled && !bp.IsCpuBreakpoint && bp.Matches(byteIndex, _memoryType)) {
|
|
|
|
|
_breakpointTypes[i] = bp.BreakOnWrite ? BreakpointType.WriteVram : BreakpointType.ReadVram;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
_breakpointTypes = null;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-13 18:32:27 -05:00
|
|
|
|
InteropEmu.DebugGetState(ref _state);
|
|
|
|
|
|
2020-02-14 21:40:50 -05:00
|
|
|
|
_counts = InteropEmu.DebugGetMemoryAccessCounts((UInt32)firstByteIndex, (UInt32)visibleByteCount, _memoryType);
|
2019-01-13 18:32:27 -05:00
|
|
|
|
|
|
|
|
|
if(_memoryType == DebugMemoryType.ChrRom && (_highlightDrawnBytes || _highlightReadBytes)) {
|
2019-01-03 14:27:10 -05:00
|
|
|
|
_cdlData = InteropEmu.DebugGetCdlData((UInt32)firstByteIndex, (UInt32)visibleByteCount, _memoryType);
|
2017-12-26 17:33:46 -05:00
|
|
|
|
} else {
|
|
|
|
|
_cdlData = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-03 14:27:10 -05:00
|
|
|
|
public ByteColors GetByteColor(long firstByteIndex, long byteIndex)
|
2017-12-26 17:33:46 -05:00
|
|
|
|
{
|
2019-01-13 18:32:27 -05:00
|
|
|
|
const int CyclesPerFrame = 29780;
|
2017-12-26 17:33:46 -05:00
|
|
|
|
long index = byteIndex - firstByteIndex;
|
2020-02-14 21:40:50 -05:00
|
|
|
|
double framesSinceWrite = (double)(_state.CPU.CycleCount - _counts[index].WriteStamp) / CyclesPerFrame;
|
|
|
|
|
double framesSinceRead = (double)(_state.CPU.CycleCount - _counts[index].ReadStamp) / CyclesPerFrame;
|
2019-01-13 18:32:27 -05:00
|
|
|
|
|
2020-02-14 21:40:50 -05:00
|
|
|
|
bool isRead = _counts[index].ReadCount > 0;
|
|
|
|
|
bool isWritten = _counts[index].WriteCount > 0;
|
2019-01-13 18:32:27 -05:00
|
|
|
|
bool isUnused = !isRead && !isWritten;
|
|
|
|
|
|
|
|
|
|
int alpha = 0;
|
|
|
|
|
if(isRead && _hideReadBytes || isWritten && _hideWrittenBytes || isUnused && _hideUnusedBytes) {
|
|
|
|
|
alpha = 128;
|
|
|
|
|
}
|
|
|
|
|
if(isRead && !_hideReadBytes || isWritten && !_hideWrittenBytes || isUnused && !_hideUnusedBytes) {
|
|
|
|
|
alpha = 255;
|
|
|
|
|
}
|
2017-12-26 17:33:46 -05:00
|
|
|
|
|
2019-01-03 14:27:10 -05:00
|
|
|
|
_colors.BackColor = Color.Transparent;
|
2017-12-26 17:33:46 -05:00
|
|
|
|
if(_cdlData != null) {
|
|
|
|
|
if((_cdlData[index] & 0x01) != 0 && _highlightDrawnBytes) {
|
|
|
|
|
//Drawn (CHR ROM)
|
2019-01-03 14:27:10 -05:00
|
|
|
|
_colors.BackColor = ConfigManager.Config.DebugInfo.RamChrDrawnByteColor;
|
2017-12-26 17:33:46 -05:00
|
|
|
|
} else if((_cdlData[index] & 0x02) != 0 && _highlightReadBytes) {
|
|
|
|
|
//Read (CHR ROM)
|
2019-01-03 14:27:10 -05:00
|
|
|
|
_colors.BackColor = ConfigManager.Config.DebugInfo.RamChrReadByteColor;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_colors.BorderColor = Color.Empty;
|
|
|
|
|
if(_breakpointTypes != null) {
|
|
|
|
|
switch(_breakpointTypes[index]) {
|
|
|
|
|
case BreakpointType.WriteVram: _colors.BorderColor = ConfigManager.Config.DebugInfo.CodeWriteBreakpointColor; break;
|
|
|
|
|
case BreakpointType.ReadVram: _colors.BorderColor = ConfigManager.Config.DebugInfo.CodeReadBreakpointColor; break;
|
2017-12-26 17:33:46 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-14 21:40:50 -05:00
|
|
|
|
if(_showWrite && _counts[index].WriteStamp != 0 && framesSinceWrite >= 0 && (framesSinceWrite < _framesToFade || _framesToFade == 0)) {
|
2019-01-13 18:32:27 -05:00
|
|
|
|
_colors.ForeColor = Color.FromArgb(alpha, ByteColorProvider.DarkerColor(ConfigManager.Config.DebugInfo.RamWriteColor, (_framesToFade - framesSinceWrite) / _framesToFade));
|
2020-02-14 21:40:50 -05:00
|
|
|
|
} else if(_showRead && _counts[index].ReadStamp != 0 && framesSinceRead >= 0 && (framesSinceRead < _framesToFade || _framesToFade == 0)) {
|
2019-01-13 18:32:27 -05:00
|
|
|
|
_colors.ForeColor = Color.FromArgb(alpha, ByteColorProvider.DarkerColor(ConfigManager.Config.DebugInfo.RamReadColor, (_framesToFade - framesSinceRead) / _framesToFade));
|
|
|
|
|
} else {
|
|
|
|
|
_colors.ForeColor = Color.FromArgb(alpha, Color.Black);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-03 14:27:10 -05:00
|
|
|
|
return _colors;
|
2017-12-26 17:33:46 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|