From ff1848857cfb78a6158a540c05ee11b00bedb146 Mon Sep 17 00:00:00 2001 From: Sour Date: Fri, 3 Jul 2020 11:06:22 -0400 Subject: [PATCH] Debugger: Tile Viewer - Added background color option --- Core/DebugTypes.h | 10 +++ Core/PpuTools.cpp | 18 ++-- UI/Debugger/Config/TileViewerConfig.cs | 1 + .../PpuViewer/frmTileViewer.Designer.cs | 90 +++++++++++++------ UI/Debugger/PpuViewer/frmTileViewer.cs | 11 +++ UI/Dependencies/resources.en.xml | 7 ++ UI/Interop/DebugApi.cs | 10 +++ 7 files changed, 114 insertions(+), 33 deletions(-) diff --git a/Core/DebugTypes.h b/Core/DebugTypes.h index 5666ae6..db0b474 100644 --- a/Core/DebugTypes.h +++ b/Core/DebugTypes.h @@ -182,10 +182,20 @@ enum class TileLayout SingleLine16x16 }; +enum class TileBackground +{ + Default = 0, + PaletteColor = 1, + Black = 2, + White = 3, + Magenta = 4 +}; + struct GetTileViewOptions { TileFormat Format; TileLayout Layout; + TileBackground Background; int32_t Width; int32_t Palette; int32_t PageSize; diff --git a/Core/PpuTools.cpp b/Core/PpuTools.cpp index 77ead0d..ec20c0c 100644 --- a/Core/PpuTools.cpp +++ b/Core/PpuTools.cpp @@ -88,10 +88,18 @@ void PpuTools::GetTileView(GetTileViewOptions options, uint8_t *source, uint32_t int bytesPerTile = 64 * bpp / 8; int tileCount = options.PageSize / bytesPerTile; - - uint16_t bgColor = (cgram[1] << 8) | cgram[0]; + + uint32_t bgColor = 0; + switch(options.Background) { + case TileBackground::Default: bgColor = DefaultVideoFilter::ToArgb((cgram[1] << 8) | cgram[0]); break; + case TileBackground::PaletteColor: bgColor = DefaultVideoFilter::ToArgb(0); break; + case TileBackground::Black: bgColor = DefaultVideoFilter::ToArgb(0); break; + case TileBackground::White: bgColor = DefaultVideoFilter::ToArgb(0x7FFF); break; + case TileBackground::Magenta: bgColor = DefaultVideoFilter::ToArgb(0x7C1F); break; + } + for(uint32_t i = 0; i < outputSize / sizeof(uint32_t); i++) { - outBuffer[i] = DefaultVideoFilter::ToArgb(bgColor); + outBuffer[i] = bgColor; } int rowCount = (int)std::ceil((double)tileCount / options.Width); @@ -122,7 +130,7 @@ void PpuTools::GetTileView(GetTileViewOptions options, uint8_t *source, uint32_t for(int x = 0; x < 8; x++) { uint8_t color = ram[(pixelStart + x * 2 + 1) & ramMask]; - if(color != 0) { + if(color != 0 || options.Background == TileBackground::PaletteColor) { uint32_t rgbColor; if(directColor) { rgbColor = DefaultVideoFilter::ToArgb(((color & 0x07) << 2) | ((color & 0x38) << 4) | ((color & 0xC0) << 7)); @@ -138,7 +146,7 @@ void PpuTools::GetTileView(GetTileViewOptions options, uint8_t *source, uint32_t uint32_t pixelStart = addr + y * 2; for(int x = 0; x < 8; x++) { uint8_t color = GetTilePixelColor(ram, ramMask, bpp, pixelStart, 7 - x); - if(color != 0) { + if(color != 0 || options.Background == TileBackground::PaletteColor) { outBuffer[baseOutputOffset + (y*options.Width*8) + x] = GetRgbPixelColor(cgram, color, options.Palette, bpp, directColor, 0); } } diff --git a/UI/Debugger/Config/TileViewerConfig.cs b/UI/Debugger/Config/TileViewerConfig.cs index 260153d..e9e330e 100644 --- a/UI/Debugger/Config/TileViewerConfig.cs +++ b/UI/Debugger/Config/TileViewerConfig.cs @@ -25,6 +25,7 @@ namespace Mesen.GUI.Config public SnesMemoryType Source = SnesMemoryType.VideoRam; public TileFormat Format = TileFormat.Bpp4; public TileLayout Layout = TileLayout.Normal; + public TileBackground Background = TileBackground.Default; public int ColumnCount = 16; public int Address = 0; public int PageSize = 0x10000; diff --git a/UI/Debugger/PpuViewer/frmTileViewer.Designer.cs b/UI/Debugger/PpuViewer/frmTileViewer.Designer.cs index a033425..0702a49 100644 --- a/UI/Debugger/PpuViewer/frmTileViewer.Designer.cs +++ b/UI/Debugger/PpuViewer/frmTileViewer.Designer.cs @@ -73,6 +73,8 @@ this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator(); this.mnuZoomIn = new System.Windows.Forms.ToolStripMenuItem(); this.mnuZoomOut = new System.Windows.Forms.ToolStripMenuItem(); + this.cboBackgroundColor = new System.Windows.Forms.ComboBox(); + this.lblBgColor = new System.Windows.Forms.Label(); this.tableLayoutPanel1.SuspendLayout(); this.tableLayoutPanel2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.ctrlPaletteViewer)).BeginInit(); @@ -112,27 +114,30 @@ this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); this.tableLayoutPanel2.Controls.Add(this.cboMemoryType, 1, 0); this.tableLayoutPanel2.Controls.Add(this.lblSource, 0, 0); - this.tableLayoutPanel2.Controls.Add(this.chkShowTileGrid, 0, 6); + this.tableLayoutPanel2.Controls.Add(this.chkShowTileGrid, 0, 7); this.tableLayoutPanel2.Controls.Add(this.lblBpp, 0, 1); this.tableLayoutPanel2.Controls.Add(this.cboFormat, 1, 1); - this.tableLayoutPanel2.Controls.Add(this.ctrlPaletteViewer, 0, 9); - this.tableLayoutPanel2.Controls.Add(this.lblPresets, 0, 7); - this.tableLayoutPanel2.Controls.Add(this.tlpPresets1, 1, 7); - this.tableLayoutPanel2.Controls.Add(this.tlpPresets2, 1, 8); - this.tableLayoutPanel2.Controls.Add(this.lblTileAddress, 0, 10); - this.tableLayoutPanel2.Controls.Add(this.txtTileAddress, 1, 10); + this.tableLayoutPanel2.Controls.Add(this.ctrlPaletteViewer, 0, 10); + this.tableLayoutPanel2.Controls.Add(this.lblPresets, 0, 8); + this.tableLayoutPanel2.Controls.Add(this.tlpPresets1, 1, 8); + this.tableLayoutPanel2.Controls.Add(this.tlpPresets2, 1, 9); + this.tableLayoutPanel2.Controls.Add(this.lblTileAddress, 0, 11); + this.tableLayoutPanel2.Controls.Add(this.txtTileAddress, 1, 11); this.tableLayoutPanel2.Controls.Add(this.lblTileLayout, 0, 2); this.tableLayoutPanel2.Controls.Add(this.cboLayout, 1, 2); - this.tableLayoutPanel2.Controls.Add(this.lblAddress, 0, 3); - this.tableLayoutPanel2.Controls.Add(this.nudAddress, 1, 3); - this.tableLayoutPanel2.Controls.Add(this.lblColumns, 0, 5); - this.tableLayoutPanel2.Controls.Add(this.lblSize, 0, 4); - this.tableLayoutPanel2.Controls.Add(this.nudColumns, 1, 5); - this.tableLayoutPanel2.Controls.Add(this.nudSize, 1, 4); + this.tableLayoutPanel2.Controls.Add(this.lblAddress, 0, 4); + this.tableLayoutPanel2.Controls.Add(this.nudAddress, 1, 4); + this.tableLayoutPanel2.Controls.Add(this.lblColumns, 0, 6); + this.tableLayoutPanel2.Controls.Add(this.lblSize, 0, 5); + this.tableLayoutPanel2.Controls.Add(this.nudColumns, 1, 6); + this.tableLayoutPanel2.Controls.Add(this.nudSize, 1, 5); + this.tableLayoutPanel2.Controls.Add(this.cboBackgroundColor, 1, 3); + this.tableLayoutPanel2.Controls.Add(this.lblBgColor, 0, 3); this.tableLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill; this.tableLayoutPanel2.Location = new System.Drawing.Point(534, 3); this.tableLayoutPanel2.Name = "tableLayoutPanel2"; - this.tableLayoutPanel2.RowCount = 12; + this.tableLayoutPanel2.RowCount = 13; + this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle()); @@ -173,7 +178,7 @@ // this.chkShowTileGrid.AutoSize = true; this.tableLayoutPanel2.SetColumnSpan(this.chkShowTileGrid, 2); - this.chkShowTileGrid.Location = new System.Drawing.Point(3, 165); + this.chkShowTileGrid.Location = new System.Drawing.Point(3, 192); this.chkShowTileGrid.Name = "chkShowTileGrid"; this.chkShowTileGrid.Size = new System.Drawing.Size(89, 17); this.chkShowTileGrid.TabIndex = 0; @@ -210,7 +215,8 @@ // ctrlPaletteViewer // this.tableLayoutPanel2.SetColumnSpan(this.ctrlPaletteViewer, 2); - this.ctrlPaletteViewer.Location = new System.Drawing.Point(3, 244); + this.ctrlPaletteViewer.CpuType = Mesen.GUI.CpuType.Cpu; + this.ctrlPaletteViewer.Location = new System.Drawing.Point(3, 271); this.ctrlPaletteViewer.Name = "ctrlPaletteViewer"; this.ctrlPaletteViewer.PaletteScale = 11; this.ctrlPaletteViewer.SelectedPalette = 0; @@ -223,7 +229,7 @@ // this.lblPresets.Anchor = System.Windows.Forms.AnchorStyles.Left; this.lblPresets.AutoSize = true; - this.lblPresets.Location = new System.Drawing.Point(3, 192); + this.lblPresets.Location = new System.Drawing.Point(3, 219); this.lblPresets.Name = "lblPresets"; this.lblPresets.Size = new System.Drawing.Size(45, 13); this.lblPresets.TabIndex = 13; @@ -241,7 +247,7 @@ this.tlpPresets1.Controls.Add(this.btnPresetBg3, 2, 0); this.tlpPresets1.Controls.Add(this.btnPresetBg4, 3, 0); this.tlpPresets1.Dock = System.Windows.Forms.DockStyle.Fill; - this.tlpPresets1.Location = new System.Drawing.Point(74, 185); + this.tlpPresets1.Location = new System.Drawing.Point(74, 212); this.tlpPresets1.Margin = new System.Windows.Forms.Padding(0); this.tlpPresets1.Name = "tlpPresets1"; this.tlpPresets1.RowCount = 1; @@ -293,7 +299,7 @@ this.tlpPresets2.Controls.Add(this.btnPresetOam1, 0, 0); this.tlpPresets2.Controls.Add(this.btnPresetOam2, 1, 0); this.tlpPresets2.Dock = System.Windows.Forms.DockStyle.Fill; - this.tlpPresets2.Location = new System.Drawing.Point(74, 213); + this.tlpPresets2.Location = new System.Drawing.Point(74, 240); this.tlpPresets2.Margin = new System.Windows.Forms.Padding(0); this.tlpPresets2.Name = "tlpPresets2"; this.tlpPresets2.RowCount = 1; @@ -323,7 +329,7 @@ // this.lblTileAddress.Anchor = System.Windows.Forms.AnchorStyles.Left; this.lblTileAddress.AutoSize = true; - this.lblTileAddress.Location = new System.Drawing.Point(3, 429); + this.lblTileAddress.Location = new System.Drawing.Point(3, 456); this.lblTileAddress.Name = "lblTileAddress"; this.lblTileAddress.Size = new System.Drawing.Size(68, 13); this.lblTileAddress.TabIndex = 16; @@ -331,7 +337,7 @@ // // txtTileAddress // - this.txtTileAddress.Location = new System.Drawing.Point(77, 426); + this.txtTileAddress.Location = new System.Drawing.Point(77, 453); this.txtTileAddress.Name = "txtTileAddress"; this.txtTileAddress.ReadOnly = true; this.txtTileAddress.Size = new System.Drawing.Size(60, 20); @@ -368,7 +374,7 @@ // this.lblAddress.Anchor = System.Windows.Forms.AnchorStyles.Left; this.lblAddress.AutoSize = true; - this.lblAddress.Location = new System.Drawing.Point(3, 88); + this.lblAddress.Location = new System.Drawing.Point(3, 115); this.lblAddress.Name = "lblAddress"; this.lblAddress.Size = new System.Drawing.Size(48, 13); this.lblAddress.TabIndex = 9; @@ -383,7 +389,7 @@ 0, 0}); this.nudAddress.IsHex = true; - this.nudAddress.Location = new System.Drawing.Point(77, 84); + this.nudAddress.Location = new System.Drawing.Point(77, 111); this.nudAddress.Maximum = new decimal(new int[] { 65536, 0, @@ -409,7 +415,7 @@ // this.lblColumns.Anchor = System.Windows.Forms.AnchorStyles.Left; this.lblColumns.AutoSize = true; - this.lblColumns.Location = new System.Drawing.Point(3, 142); + this.lblColumns.Location = new System.Drawing.Point(3, 169); this.lblColumns.Name = "lblColumns"; this.lblColumns.Size = new System.Drawing.Size(50, 13); this.lblColumns.TabIndex = 3; @@ -419,7 +425,7 @@ // this.lblSize.Anchor = System.Windows.Forms.AnchorStyles.Left; this.lblSize.AutoSize = true; - this.lblSize.Location = new System.Drawing.Point(3, 115); + this.lblSize.Location = new System.Drawing.Point(3, 142); this.lblSize.Name = "lblSize"; this.lblSize.Size = new System.Drawing.Size(64, 13); this.lblSize.TabIndex = 5; @@ -434,7 +440,7 @@ 0, 0}); this.nudColumns.IsHex = false; - this.nudColumns.Location = new System.Drawing.Point(77, 138); + this.nudColumns.Location = new System.Drawing.Point(77, 165); this.nudColumns.Maximum = new decimal(new int[] { 64, 0, @@ -465,7 +471,7 @@ 0, 0}); this.nudSize.IsHex = true; - this.nudSize.Location = new System.Drawing.Point(77, 111); + this.nudSize.Location = new System.Drawing.Point(77, 138); this.nudSize.Maximum = new decimal(new int[] { 0, 0, @@ -637,6 +643,32 @@ this.mnuZoomOut.Text = "Zoom Out"; this.mnuZoomOut.Click += new System.EventHandler(this.mnuZoomOut_Click); // + // cboBackgroundColor + // + this.cboBackgroundColor.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cboBackgroundColor.FormattingEnabled = true; + this.cboBackgroundColor.Items.AddRange(new object[] { + "2 BPP", + "4 BPP", + "8 BPP", + "8 BPP - Direct Color Mode", + "Mode 7", + "Mode 7 - Direct Color Mode"}); + this.cboBackgroundColor.Location = new System.Drawing.Point(77, 84); + this.cboBackgroundColor.Name = "cboBackgroundColor"; + this.cboBackgroundColor.Size = new System.Drawing.Size(120, 21); + this.cboBackgroundColor.TabIndex = 20; + // + // lblBgColor + // + this.lblBgColor.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.lblBgColor.AutoSize = true; + this.lblBgColor.Location = new System.Drawing.Point(3, 88); + this.lblBgColor.Name = "lblBgColor"; + this.lblBgColor.Size = new System.Drawing.Size(68, 13); + this.lblBgColor.TabIndex = 21; + this.lblBgColor.Text = "Background:"; + // // frmTileViewer // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -710,5 +742,7 @@ private System.Windows.Forms.ToolStripMenuItem mnuAutoRefreshLow; private System.Windows.Forms.ToolStripMenuItem mnuAutoRefreshNormal; private System.Windows.Forms.ToolStripMenuItem mnuAutoRefreshHigh; - } + private System.Windows.Forms.ComboBox cboBackgroundColor; + private System.Windows.Forms.Label lblBgColor; + } } \ No newline at end of file diff --git a/UI/Debugger/PpuViewer/frmTileViewer.cs b/UI/Debugger/PpuViewer/frmTileViewer.cs index cb91c1f..345dd29 100644 --- a/UI/Debugger/PpuViewer/frmTileViewer.cs +++ b/UI/Debugger/PpuViewer/frmTileViewer.cs @@ -57,6 +57,7 @@ namespace Mesen.GUI.Debugger BaseConfigForm.InitializeComboBox(cboFormat, typeof(TileFormat)); BaseConfigForm.InitializeComboBox(cboLayout, typeof(TileLayout)); + BaseConfigForm.InitializeComboBox(cboBackgroundColor, typeof(TileBackground)); InitMemoryTypeDropdown(); InitShortcuts(); @@ -67,6 +68,7 @@ namespace Mesen.GUI.Debugger cboMemoryType.SetEnumValue(config.Source); cboFormat.SetEnumValue(config.Format); cboLayout.SetEnumValue(config.Layout); + cboBackgroundColor.SetEnumValue(config.Background); nudColumns.Value = config.ColumnCount; UpdateMemoryType(config.Source); @@ -94,6 +96,7 @@ namespace Mesen.GUI.Debugger _address = config.Address; _options.Format = config.Format; _options.Layout = config.Layout; + _options.Background = config.Background; _options.Palette = config.SelectedPalette; _options.Width = config.ColumnCount; _options.PageSize = config.PageSize; @@ -116,6 +119,7 @@ namespace Mesen.GUI.Debugger chkShowTileGrid.Click += chkShowTileGrid_Click; cboFormat.SelectedIndexChanged += cboFormat_SelectedIndexChanged; cboLayout.SelectedIndexChanged += cboLayout_SelectedIndexChanged; + cboBackgroundColor.SelectedIndexChanged += cboBackgroundColor_SelectedIndexChanged; nudColumns.ValueChanged += nudColumns_ValueChanged; nudSize.ValueChanged += nudSize_ValueChanged; ctrlPaletteViewer.SelectionChanged += ctrlPaletteViewer_SelectionChanged; @@ -165,6 +169,7 @@ namespace Mesen.GUI.Debugger config.Source = cboMemoryType.GetEnumValue(); config.Format = cboFormat.GetEnumValue(); config.Layout = cboLayout.GetEnumValue(); + config.Background = cboBackgroundColor.GetEnumValue(); config.ColumnCount = (int)nudColumns.Value; config.Address = (int)nudAddress.Value; config.PageSize = (int)nudSize.Value; @@ -376,6 +381,12 @@ namespace Mesen.GUI.Debugger UpdatePaletteControl(); RefreshViewer(); } + + private void cboBackgroundColor_SelectedIndexChanged(object sender, EventArgs e) + { + _options.Background = cboBackgroundColor.GetEnumValue(); + RefreshViewer(); + } private void cboLayout_SelectedIndexChanged(object sender, EventArgs e) { diff --git a/UI/Dependencies/resources.en.xml b/UI/Dependencies/resources.en.xml index 029dffb..f17226c 100644 --- a/UI/Dependencies/resources.en.xml +++ b/UI/Dependencies/resources.en.xml @@ -1011,6 +1011,13 @@ 8x16 (same line) 16x16 (same line) + + Default (Color 0) + Palette Color 0 + Black + White + Magenta + Hexadecimal Text diff --git a/UI/Interop/DebugApi.cs b/UI/Interop/DebugApi.cs index 160e804..1773d26 100644 --- a/UI/Interop/DebugApi.cs +++ b/UI/Interop/DebugApi.cs @@ -472,10 +472,20 @@ namespace Mesen.GUI public byte Layer; } + public enum TileBackground + { + Default = 0, + PaletteColor = 1, + Black = 2, + White = 3, + Magenta = 4 + } + public struct GetTileViewOptions { public TileFormat Format; public TileLayout Layout; + public TileBackground Background; public Int32 Width; public Int32 Palette; public Int32 PageSize;