Debugger: Nametable Viewer - Added "Show attribute colors only" option

This commit is contained in:
Sour 2019-01-19 14:50:47 -05:00
parent 346c496004
commit f03b154686
9 changed files with 88 additions and 25 deletions

View file

@ -206,4 +206,11 @@ struct StackFrameInfo
uint16_t JumpSource;
uint16_t JumpTarget;
StackFrameFlags Flags;
};
enum class NametableDisplayMode
{
Normal = 0,
Grayscale = 1,
AttributeView = 2
};

View file

@ -265,7 +265,7 @@ uint8_t MemoryDumper::GetMemoryValue(DebugMemoryType memoryType, uint32_t addres
return 0;
}
void MemoryDumper::GetNametable(int nametableIndex, bool useGrayscalePalette, uint32_t* frameBuffer, uint8_t* tileData, uint8_t* paletteData)
void MemoryDumper::GetNametable(int nametableIndex, NametableDisplayMode mode, uint32_t* frameBuffer, uint8_t* tileData, uint8_t* paletteData)
{
shared_ptr<MMC5> mmc5 = std::dynamic_pointer_cast<MMC5>(_mapper);
uint32_t *rgbPalette = _debugger->GetConsole()->GetSettings()->GetRgbPalette();
@ -291,21 +291,30 @@ void MemoryDumper::GetNametable(int nametableIndex, bool useGrayscalePalette, ui
paletteBaseAddr = ((attribute >> shift) & 0x03) << 2;
}
uint16_t tileAddr = bgAddr + (tileIndex << 4);
for(uint8_t i = 0; i < 8; i++) {
uint8_t lowByte, highByte;
if(mmc5 && mmc5->IsExtendedAttributes()) {
lowByte = mmc5->GetExAttributeTileData(ntIndex, tileAddr + i);
highByte = mmc5->GetExAttributeTileData(ntIndex, tileAddr + i + 8);
} else {
lowByte = _mapper->DebugReadVRAM(tileAddr + i);
highByte = _mapper->DebugReadVRAM(tileAddr + i + 8);
if(mode == NametableDisplayMode::AttributeView) {
for(uint8_t i = 0; i < 8; i++) {
for(uint8_t j = 0; j < 8; j++) {
uint8_t color = ((j & 0x04) >> 2) + ((i & 0x04) >> 1);
frameBuffer[(y << 11) + (x << 3) + (i << 8) + j] = rgbPalette[_ppu->ReadPaletteRAM(color == 0 ? 0 : (paletteBaseAddr + color))];
}
}
for(uint8_t j = 0; j < 8; j++) {
uint8_t color = ((lowByte >> (7 - j)) & 0x01) | (((highByte >> (7 - j)) & 0x01) << 1);
if(useGrayscalePalette) {
frameBuffer[(y << 11) + (x << 3) + (i << 8) + j] = rgbPalette[grayscalePalette[color]];
} else {
for(uint8_t i = 0; i < 8; i++) {
uint8_t lowByte, highByte;
if(mmc5 && mmc5->IsExtendedAttributes()) {
lowByte = mmc5->GetExAttributeTileData(ntIndex, tileAddr + i);
highByte = mmc5->GetExAttributeTileData(ntIndex, tileAddr + i + 8);
} else {
frameBuffer[(y << 11) + (x << 3) + (i << 8) + j] = rgbPalette[(color == 0 ? _ppu->ReadPaletteRAM(0) : _ppu->ReadPaletteRAM(paletteBaseAddr + color)) & 0x3F];
lowByte = _mapper->DebugReadVRAM(tileAddr + i);
highByte = _mapper->DebugReadVRAM(tileAddr + i + 8);
}
for(uint8_t j = 0; j < 8; j++) {
uint8_t color = ((lowByte >> (7 - j)) & 0x01) | (((highByte >> (7 - j)) & 0x01) << 1);
if(mode == NametableDisplayMode::Grayscale) {
frameBuffer[(y << 11) + (x << 3) + (i << 8) + j] = rgbPalette[grayscalePalette[color]];
} else {
frameBuffer[(y << 11) + (x << 3) + (i << 8) + j] = rgbPalette[(color == 0 ? _ppu->ReadPaletteRAM(0) : _ppu->ReadPaletteRAM(paletteBaseAddr + color)) & 0x3F];
}
}
}
}

View file

@ -96,7 +96,7 @@ public:
uint32_t GetMemorySize(DebugMemoryType type);
uint32_t GetMemoryState(DebugMemoryType type, uint8_t *buffer);
void GetNametable(int nametableIndex, bool useGrayscalePalette, uint32_t* frameBuffer, uint8_t* tileData, uint8_t* paletteData);
void GetNametable(int nametableIndex, NametableDisplayMode mode, uint32_t* frameBuffer, uint8_t* tileData, uint8_t* paletteData);
void GetChrBank(int bankIndex, uint32_t* frameBuffer, uint8_t palette, bool largeSprites, CdlHighlightType highlightType, bool useAutoPalette, bool showSingleColorTilesInGrayscale, uint32_t* paletteBuffer);
void GetSprites(uint32_t* frameBuffer);
void GetPalette(uint32_t* frameBuffer);

View file

@ -190,6 +190,7 @@ namespace Mesen.GUI.Config
public bool PpuShowPreviousFrame = false;
public bool HidePauseIcon = false;
public bool ShowPpuScrollOverlay = true;
public bool ShowAttributeColorsOnly = false;
public bool ShowTileGrid = false;
public bool ShowAttributeGrid = false;
public bool HighlightChrTile = false;

View file

@ -76,6 +76,7 @@ namespace Mesen.GUI.Debugger.Controls
this.chkHighlightAttributeUpdates = new System.Windows.Forms.CheckBox();
this.lblHighlight = new System.Windows.Forms.Label();
this.chkIgnoreRedundantWrites = new System.Windows.Forms.CheckBox();
this.chkShowAttributeColorsOnly = new System.Windows.Forms.CheckBox();
this.tableLayoutPanel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.picNametable)).BeginInit();
this.ctxMenu.SuspendLayout();
@ -449,6 +450,7 @@ namespace Mesen.GUI.Debugger.Controls
this.flowLayoutPanel1.AutoSize = true;
this.flowLayoutPanel1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.flowLayoutPanel1.Controls.Add(this.chkShowPpuScrollOverlay);
this.flowLayoutPanel1.Controls.Add(this.chkShowAttributeColorsOnly);
this.flowLayoutPanel1.Controls.Add(this.chkShowTileGrid);
this.flowLayoutPanel1.Controls.Add(this.chkShowAttributeGrid);
this.flowLayoutPanel1.Controls.Add(this.chkUseGrayscalePalette);
@ -475,7 +477,7 @@ namespace Mesen.GUI.Debugger.Controls
// chkShowTileGrid
//
this.chkShowTileGrid.AutoSize = true;
this.chkShowTileGrid.Location = new System.Drawing.Point(3, 26);
this.chkShowTileGrid.Location = new System.Drawing.Point(3, 49);
this.chkShowTileGrid.Name = "chkShowTileGrid";
this.chkShowTileGrid.Size = new System.Drawing.Size(95, 17);
this.chkShowTileGrid.TabIndex = 2;
@ -486,7 +488,7 @@ namespace Mesen.GUI.Debugger.Controls
// chkShowAttributeGrid
//
this.chkShowAttributeGrid.AutoSize = true;
this.chkShowAttributeGrid.Location = new System.Drawing.Point(3, 49);
this.chkShowAttributeGrid.Location = new System.Drawing.Point(3, 72);
this.chkShowAttributeGrid.Name = "chkShowAttributeGrid";
this.chkShowAttributeGrid.Size = new System.Drawing.Size(117, 17);
this.chkShowAttributeGrid.TabIndex = 3;
@ -497,7 +499,7 @@ namespace Mesen.GUI.Debugger.Controls
// chkUseGrayscalePalette
//
this.chkUseGrayscalePalette.AutoSize = true;
this.chkUseGrayscalePalette.Location = new System.Drawing.Point(3, 72);
this.chkUseGrayscalePalette.Location = new System.Drawing.Point(3, 95);
this.chkUseGrayscalePalette.Name = "chkUseGrayscalePalette";
this.chkUseGrayscalePalette.Size = new System.Drawing.Size(131, 17);
this.chkUseGrayscalePalette.TabIndex = 5;
@ -508,7 +510,7 @@ namespace Mesen.GUI.Debugger.Controls
// chkHighlightChrTile
//
this.chkHighlightChrTile.CheckAlign = System.Drawing.ContentAlignment.TopLeft;
this.chkHighlightChrTile.Location = new System.Drawing.Point(3, 95);
this.chkHighlightChrTile.Location = new System.Drawing.Point(3, 118);
this.chkHighlightChrTile.Name = "chkHighlightChrTile";
this.chkHighlightChrTile.Size = new System.Drawing.Size(150, 31);
this.chkHighlightChrTile.TabIndex = 4;
@ -609,6 +611,17 @@ namespace Mesen.GUI.Debugger.Controls
this.chkIgnoreRedundantWrites.UseVisualStyleBackColor = true;
this.chkIgnoreRedundantWrites.Click += new System.EventHandler(this.chkIgnoreRedundantWrites_Click);
//
// chkShowAttributeColorsOnly
//
this.chkShowAttributeColorsOnly.AutoSize = true;
this.chkShowAttributeColorsOnly.Location = new System.Drawing.Point(3, 26);
this.chkShowAttributeColorsOnly.Name = "chkShowAttributeColorsOnly";
this.chkShowAttributeColorsOnly.Size = new System.Drawing.Size(147, 17);
this.chkShowAttributeColorsOnly.TabIndex = 6;
this.chkShowAttributeColorsOnly.Text = "Show attribute colors only";
this.chkShowAttributeColorsOnly.UseVisualStyleBackColor = true;
this.chkShowAttributeColorsOnly.Click += new System.EventHandler(this.chkShowAttributeColorsOnly_Click);
//
// ctrlNametableViewer
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -681,5 +694,6 @@ namespace Mesen.GUI.Debugger.Controls
private System.Windows.Forms.Label lblHighlight;
private System.Windows.Forms.CheckBox chkIgnoreRedundantWrites;
private System.Windows.Forms.ToolStripMenuItem mnuAddBreakpoint;
private System.Windows.Forms.CheckBox chkShowAttributeColorsOnly;
}
}

View file

@ -41,6 +41,7 @@ namespace Mesen.GUI.Debugger.Controls
private HdPackCopyHelper _hdCopyHelper = new HdPackCopyHelper();
private bool _firstDraw = true;
private bool[] _ntChanged = null;
private bool _showAttributeColorsOnly = false;
public ctrlNametableViewer()
{
@ -57,6 +58,10 @@ namespace Mesen.GUI.Debugger.Controls
chkHighlightAttributeUpdates.Checked = ConfigManager.Config.DebugInfo.NtViewerHighlightAttributeUpdates;
chkIgnoreRedundantWrites.Checked = ConfigManager.Config.DebugInfo.NtViewerIgnoreRedundantWrites;
chkShowAttributeColorsOnly.Checked = ConfigManager.Config.DebugInfo.ShowAttributeColorsOnly;
_showAttributeColorsOnly = ConfigManager.Config.DebugInfo.ShowAttributeColorsOnly;
chkUseGrayscalePalette.Enabled = !_showAttributeColorsOnly;
UpdateIgnoreWriteCheckbox();
}
}
@ -102,8 +107,17 @@ namespace Mesen.GUI.Debugger.Controls
_prevAttributeData[i] = _attributeData[i] != null ? (byte[])_attributeData[i].Clone() : null;
}
NametableDisplayMode mode;
if(_showAttributeColorsOnly) {
mode = NametableDisplayMode.AttributeView;
} else if(ConfigManager.Config.DebugInfo.NtViewerUseGrayscalePalette) {
mode = NametableDisplayMode.Grayscale;
} else {
mode = NametableDisplayMode.Normal;
}
for(int i = 0; i < 4; i++) {
InteropEmu.DebugGetNametable(i, ConfigManager.Config.DebugInfo.NtViewerUseGrayscalePalette, out _nametablePixelData[i], out _tileData[i], out _attributeData[i]);
InteropEmu.DebugGetNametable(i, mode, out _nametablePixelData[i], out _tileData[i], out _attributeData[i]);
}
_hdCopyHelper.RefreshData();
@ -396,6 +410,17 @@ namespace Mesen.GUI.Debugger.Controls
this.RefreshViewer();
}
private void chkShowAttributeColorsOnly_Click(object sender, EventArgs e)
{
ConfigManager.Config.DebugInfo.ShowAttributeColorsOnly = chkShowAttributeColorsOnly.Checked;
ConfigManager.ApplyChanges();
_showAttributeColorsOnly = chkShowAttributeColorsOnly.Checked;
chkUseGrayscalePalette.Enabled = !chkShowAttributeColorsOnly.Checked;
this.GetData();
this.RefreshViewer();
}
private void chkShowTileGrid_Click(object sender, EventArgs e)
{
ConfigManager.Config.DebugInfo.ShowTileGrid = chkShowTileGrid.Checked;

View file

@ -65,7 +65,7 @@ namespace Mesen.GUI.Debugger.Controls
InteropEmu.DebugGetState(ref _state);
for(int i = 0; i < 4; i++) {
InteropEmu.DebugGetNametable(i, ConfigManager.Config.DebugInfo.NtViewerUseGrayscalePalette, out _nametablePixelData[i], out _tileData[i], out _attributeData[i]);
InteropEmu.DebugGetNametable(i, NametableDisplayMode.Normal, out _nametablePixelData[i], out _tileData[i], out _attributeData[i]);
}
_ppuMemory = InteropEmu.DebugGetMemoryState(DebugMemoryType.PpuMemory);

View file

@ -415,8 +415,8 @@ namespace Mesen.GUI
return buffer;
}
[DllImport(DLLPath, EntryPoint = "DebugGetNametable")] private static extern void DebugGetNametableWrapper(UInt32 nametableIndex, [MarshalAs(UnmanagedType.I1)]bool useGrayscalePalette, IntPtr frameBuffer, IntPtr tileData, IntPtr attributeData);
public static void DebugGetNametable(int nametableIndex, bool useGrayscalePalette, out byte[] frameData, out byte[] tileData, out byte[] attributeData)
[DllImport(DLLPath, EntryPoint = "DebugGetNametable")] private static extern void DebugGetNametableWrapper(UInt32 nametableIndex, NametableDisplayMode mode, IntPtr frameBuffer, IntPtr tileData, IntPtr attributeData);
public static void DebugGetNametable(int nametableIndex, NametableDisplayMode mode, out byte[] frameData, out byte[] tileData, out byte[] attributeData)
{
frameData = new byte[256*240*4];
tileData = new byte[32*30];
@ -426,7 +426,7 @@ namespace Mesen.GUI
GCHandle hTileData = GCHandle.Alloc(tileData, GCHandleType.Pinned);
GCHandle hAttributeData = GCHandle.Alloc(attributeData, GCHandleType.Pinned);
try {
InteropEmu.DebugGetNametableWrapper((UInt32)nametableIndex, useGrayscalePalette, hFrameData.AddrOfPinnedObject(), hTileData.AddrOfPinnedObject(), hAttributeData.AddrOfPinnedObject());
InteropEmu.DebugGetNametableWrapper((UInt32)nametableIndex, mode, hFrameData.AddrOfPinnedObject(), hTileData.AddrOfPinnedObject(), hAttributeData.AddrOfPinnedObject());
} finally {
hFrameData.Free();
hTileData.Free();
@ -2307,6 +2307,13 @@ namespace Mesen.GUI
_270Degrees = 270
}
public enum NametableDisplayMode
{
Normal = 0,
Grayscale = 1,
AttributeView = 2
}
public enum DebugMemoryType
{
CpuMemory = 0,

View file

@ -75,7 +75,7 @@ extern "C"
DllExport uint32_t __stdcall DebugGetMemorySize(DebugMemoryType type) { return GetDebugger()->GetMemoryDumper()->GetMemorySize(type); }
DllExport uint32_t __stdcall DebugGetMemoryState(DebugMemoryType type, uint8_t *buffer) { return GetDebugger()->GetMemoryDumper()->GetMemoryState(type, buffer); }
DllExport void __stdcall DebugGetNametable(uint32_t nametableIndex, bool useGrayscalePalette, uint32_t *frameBuffer, uint8_t *tileData, uint8_t *attributeData) { GetDebugger()->GetMemoryDumper()->GetNametable(nametableIndex, useGrayscalePalette, frameBuffer, tileData, attributeData); }
DllExport void __stdcall DebugGetNametable(uint32_t nametableIndex, NametableDisplayMode mode, uint32_t *frameBuffer, uint8_t *tileData, uint8_t *attributeData) { GetDebugger()->GetMemoryDumper()->GetNametable(nametableIndex, mode, frameBuffer, tileData, attributeData); }
DllExport void __stdcall DebugGetChrBank(uint32_t bankIndex, uint32_t *frameBuffer, uint8_t palette, bool largeSprites, CdlHighlightType highlightType, bool useAutoPalette, bool showSingleColorTilesInGrayscale, uint32_t *paletteBuffer) { GetDebugger()->GetMemoryDumper()->GetChrBank(bankIndex, frameBuffer, palette, largeSprites, highlightType, useAutoPalette, showSingleColorTilesInGrayscale, paletteBuffer); }
DllExport void __stdcall DebugGetSprites(uint32_t *frameBuffer) { GetDebugger()->GetMemoryDumper()->GetSprites(frameBuffer); }
DllExport void __stdcall DebugGetPalette(uint32_t *frameBuffer) { GetDebugger()->GetMemoryDumper()->GetPalette(frameBuffer); }