Debugger: Added palette display to nametable/sprite viewers

This commit is contained in:
Souryo 2017-08-15 22:01:54 -04:00
parent b469bc5308
commit 6ca49dd4af
12 changed files with 472 additions and 144 deletions

View file

@ -50,16 +50,16 @@
this.label6 = new System.Windows.Forms.Label();
this.txtTileIndex = new System.Windows.Forms.TextBox();
this.picTile = new System.Windows.Forms.PictureBox();
this.picPaletteSelection = new System.Windows.Forms.PictureBox();
this.label3 = new System.Windows.Forms.Label();
this.picColorTooltip = new System.Windows.Forms.PictureBox();
this.picTileTooltip = new System.Windows.Forms.PictureBox();
this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel();
this.picChrBank1 = new System.Windows.Forms.PictureBox();
this.picChrBank2 = new System.Windows.Forms.PictureBox();
this.toolTip = new System.Windows.Forms.ToolTip(this.components);
this.ctxMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
this.mnuCopyHdPack = new System.Windows.Forms.ToolStripMenuItem();
this.picChrBank2 = new System.Windows.Forms.PictureBox();
this.toolTip = new System.Windows.Forms.ToolTip(this.components);
this.ctrlTilePalette = new Mesen.GUI.Debugger.Controls.ctrlTilePalette();
this.tableLayoutPanel3.SuspendLayout();
this.grpDisplayOptions.SuspendLayout();
this.tableLayoutPanel1.SuspendLayout();
@ -70,13 +70,12 @@
this.grpTileInfo.SuspendLayout();
this.tableLayoutPanel4.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.picTile)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.picPaletteSelection)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.picColorTooltip)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.picTileTooltip)).BeginInit();
this.tableLayoutPanel2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.picChrBank1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.picChrBank2)).BeginInit();
this.ctxMenu.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.picChrBank2)).BeginInit();
this.SuspendLayout();
//
// tableLayoutPanel3
@ -282,10 +281,10 @@
this.tableLayoutPanel4.Controls.Add(this.label6, 0, 2);
this.tableLayoutPanel4.Controls.Add(this.txtTileIndex, 1, 0);
this.tableLayoutPanel4.Controls.Add(this.picTile, 1, 2);
this.tableLayoutPanel4.Controls.Add(this.picPaletteSelection, 1, 3);
this.tableLayoutPanel4.Controls.Add(this.label3, 0, 3);
this.tableLayoutPanel4.Controls.Add(this.picColorTooltip, 2, 3);
this.tableLayoutPanel4.Controls.Add(this.picTileTooltip, 2, 2);
this.tableLayoutPanel4.Controls.Add(this.ctrlTilePalette, 1, 3);
this.tableLayoutPanel4.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel4.Location = new System.Drawing.Point(3, 16);
this.tableLayoutPanel4.Name = "tableLayoutPanel4";
@ -359,18 +358,6 @@
this.picTile.MouseMove += new System.Windows.Forms.MouseEventHandler(this.picTile_MouseMove);
this.picTile.MouseUp += new System.Windows.Forms.MouseEventHandler(this.picTile_MouseUp);
//
// picPaletteSelection
//
this.picPaletteSelection.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.picPaletteSelection.Location = new System.Drawing.Point(77, 191);
this.picPaletteSelection.Name = "picPaletteSelection";
this.picPaletteSelection.Size = new System.Drawing.Size(130, 34);
this.picPaletteSelection.TabIndex = 13;
this.picPaletteSelection.TabStop = false;
this.picPaletteSelection.MouseDown += new System.Windows.Forms.MouseEventHandler(this.picPaletteSelection_MouseDown);
this.picPaletteSelection.MouseLeave += new System.EventHandler(this.picPaletteSelection_MouseLeave);
this.picPaletteSelection.MouseMove += new System.Windows.Forms.MouseEventHandler(this.picPaletteSelection_MouseMove);
//
// label3
//
this.label3.Anchor = System.Windows.Forms.AnchorStyles.Left;
@ -433,6 +420,21 @@
this.picChrBank1.MouseLeave += new System.EventHandler(this.picChrBank_MouseLeave);
this.picChrBank1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.picChrBank_MouseMove);
//
// ctxMenu
//
this.ctxMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuCopyHdPack});
this.ctxMenu.Name = "ctxMenu";
this.ctxMenu.Size = new System.Drawing.Size(222, 26);
this.ctxMenu.Opening += new System.ComponentModel.CancelEventHandler(this.ctxMenu_Opening);
//
// mnuCopyHdPack
//
this.mnuCopyHdPack.Name = "mnuCopyHdPack";
this.mnuCopyHdPack.Size = new System.Drawing.Size(221, 22);
this.mnuCopyHdPack.Text = "Copy Tile (HD Pack Format)";
this.mnuCopyHdPack.Click += new System.EventHandler(this.mnuCopyHdPack_Click);
//
// picChrBank2
//
this.picChrBank2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
@ -454,20 +456,14 @@
this.toolTip.InitialDelay = 10;
this.toolTip.ReshowDelay = 10;
//
// ctxMenu
// ctrlTilePalette
//
this.ctxMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuCopyHdPack});
this.ctxMenu.Name = "ctxMenu";
this.ctxMenu.Size = new System.Drawing.Size(222, 48);
this.ctxMenu.Opening += new System.ComponentModel.CancelEventHandler(this.ctxMenu_Opening);
//
// mnuCopyHdPack
//
this.mnuCopyHdPack.Name = "mnuCopyHdPack";
this.mnuCopyHdPack.Size = new System.Drawing.Size(221, 22);
this.mnuCopyHdPack.Text = "Copy Tile (HD Pack Format)";
this.mnuCopyHdPack.Click += new System.EventHandler(this.mnuCopyHdPack_Click);
this.ctrlTilePalette.DisplayIndexes = false;
this.ctrlTilePalette.HighlightMouseOver = false;
this.ctrlTilePalette.Location = new System.Drawing.Point(77, 191);
this.ctrlTilePalette.Name = "ctrlTilePalette";
this.ctrlTilePalette.Size = new System.Drawing.Size(130, 34);
this.ctrlTilePalette.TabIndex = 17;
//
// ctrlChrViewer
//
@ -491,13 +487,12 @@
this.tableLayoutPanel4.ResumeLayout(false);
this.tableLayoutPanel4.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.picTile)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.picPaletteSelection)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.picColorTooltip)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.picTileTooltip)).EndInit();
this.tableLayoutPanel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.picChrBank1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.picChrBank2)).EndInit();
this.ctxMenu.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.picChrBank2)).EndInit();
this.ResumeLayout(false);
}
@ -528,7 +523,6 @@
private System.Windows.Forms.PictureBox picChrBank2;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2;
private System.Windows.Forms.GroupBox grpDisplayOptions;
private System.Windows.Forms.PictureBox picPaletteSelection;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.PictureBox picColorTooltip;
private System.Windows.Forms.PictureBox picTileTooltip;
@ -536,5 +530,6 @@
private System.Windows.Forms.PictureBox picPaletteTooltip;
private System.Windows.Forms.ContextMenuStrip ctxMenu;
private System.Windows.Forms.ToolStripMenuItem mnuCopyHdPack;
private ctrlTilePalette ctrlTilePalette;
}
}

View file

@ -28,8 +28,6 @@ namespace Mesen.GUI.Debugger.Controls
private bool _hoverBottomBank = false;
private int _hoverTileIndex = -1;
private int _selectedColor = 1;
private int _hoverColor = -1;
private int _tilePosX = -1;
private int _tilePosY = -1;
@ -45,11 +43,14 @@ namespace Mesen.GUI.Debugger.Controls
this.cboHighlightType.SelectedIndex = 0;
this.picTile.Cursor = new Cursor(Properties.Resources.Pencil.GetHicon());
this.picPaletteSelection.Cursor = new Cursor(Properties.Resources.Pipette.GetHicon());
this.toolTip.SetToolTip(this.picTileTooltip, "Click on the tile to draw with the selected color." + Environment.NewLine + "Right button draws the background color.");
this.toolTip.SetToolTip(this.picColorTooltip, "Click on a color (or press 1-4) to select it.");
this.toolTip.SetToolTip(this.picPaletteTooltip, "Press Shift-1 to Shift-8 to select the palette.");
this.ctrlTilePalette.AllowSelection = true;
this.ctrlTilePalette.HighlightMouseOver = true;
this.ctrlTilePalette.DisplayIndexes = true;
}
}
@ -116,7 +117,7 @@ namespace Mesen.GUI.Debugger.Controls
}
this.RefreshPreview(_hoverTileIndex >= 0 ? _hoverTileIndex : _tileIndex, _hoverTileIndex >= 0 ? _hoverBottomBank : _bottomBank);
this.RefreshPalettePicker();
ctrlTilePalette.RefreshPalette();
}
private UInt32 _chrSize;
@ -157,6 +158,7 @@ namespace Mesen.GUI.Debugger.Controls
private void cboPalette_SelectedIndexChanged(object sender, EventArgs e)
{
this._selectedPalette = this.cboPalette.SelectedIndex;
this.ctrlTilePalette.SelectedPalette = this._selectedPalette;
this.GetData();
this.RefreshViewer();
}
@ -306,7 +308,7 @@ namespace Mesen.GUI.Debugger.Controls
byte value = 0;
if(leftButton) {
value = (byte)_selectedColor;
value = (byte)ctrlTilePalette.SelectedColor;
byte1 |= (byte)(((value << 7) & 0x80) >> x);
byte2 |= (byte)(((value << 6) & 0x80) >> x);
}
@ -335,77 +337,6 @@ namespace Mesen.GUI.Debugger.Controls
_drawing = false;
}
private void RefreshPalettePicker()
{
byte[] palette = InteropEmu.DebugGetPalette();
byte[] currentPalette = new byte[16];
Array.Copy(palette, cboPalette.SelectedIndex * 16, currentPalette, 0, 16);
GCHandle handle = GCHandle.Alloc(currentPalette, GCHandleType.Pinned);
try {
Bitmap source = new Bitmap(4, 1, 4*4, System.Drawing.Imaging.PixelFormat.Format32bppArgb, handle.AddrOfPinnedObject());
Bitmap target = new Bitmap(128, 32);
using(Graphics g = Graphics.FromImage(target)) {
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
g.ScaleTransform(32, 32);
g.DrawImageUnscaled(source, 0, 0);
g.ResetTransform();
DrawString("1", 5, 2, g);
DrawString("2", 37, 2, g);
DrawString("3", 69, 2, g);
DrawString("4", 101, 2, g);
using(Pen pen = new Pen(Color.LightBlue, 3)) {
g.DrawRectangle(pen, _selectedColor * 32 + 2, 2, 29, 29);
}
if(_hoverColor >= 0) {
using(Pen pen = new Pen(Color.DarkGray, 3)) {
g.DrawRectangle(pen, _hoverColor * 32 + 2, 2, 29, 29);
}
}
}
this.picPaletteSelection.Image = target;
} finally {
handle.Free();
}
}
private void DrawString(string number, int x, int y, Graphics g)
{
using(Font font = new Font(BaseControl.MonospaceFontFamily, 10)) {
for(int i = -1; i < 2; i++) {
for(int j = -1; j < 2; j++) {
if(i != 0 || j != 0) {
g.DrawString(number, font, Brushes.Black, j+x, i+y);
}
}
}
g.DrawString(number, font, Brushes.White, x, y);
}
}
private void picPaletteSelection_MouseMove(object sender, MouseEventArgs e)
{
_hoverColor = e.X / 32;
RefreshPalettePicker();
}
private void picPaletteSelection_MouseDown(object sender, MouseEventArgs e)
{
_selectedColor = e.X / 32;
RefreshPalettePicker();
}
private void picPaletteSelection_MouseLeave(object sender, EventArgs e)
{
_hoverColor = -1;
RefreshPalettePicker();
}
public void SelectPalette(int palette)
{
cboPalette.SelectedIndex = palette;
@ -413,8 +344,7 @@ namespace Mesen.GUI.Debugger.Controls
public void SelectColor(int color)
{
_selectedColor = color;
RefreshPalettePicker();
ctrlTilePalette.SelectedColor = color;
}
string _copyData;

View file

@ -30,6 +30,8 @@
this.components = new System.ComponentModel.Container();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.picNametable = new System.Windows.Forms.PictureBox();
this.ctxMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
this.mnuCopyHdPack = new System.Windows.Forms.ToolStripMenuItem();
this.grpTileInfo = new System.Windows.Forms.GroupBox();
this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel();
this.txtPpuAddress = new System.Windows.Forms.TextBox();
@ -54,15 +56,14 @@
this.chkShowPpuScrollOverlay = new System.Windows.Forms.CheckBox();
this.chkShowTileGrid = new System.Windows.Forms.CheckBox();
this.chkShowAttributeGrid = new System.Windows.Forms.CheckBox();
this.ctxMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
this.mnuCopyHdPack = new System.Windows.Forms.ToolStripMenuItem();
this.ctrlTilePalette = new Mesen.GUI.Debugger.Controls.ctrlTilePalette();
this.tableLayoutPanel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.picNametable)).BeginInit();
this.ctxMenu.SuspendLayout();
this.grpTileInfo.SuspendLayout();
this.tableLayoutPanel2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.picTile)).BeginInit();
this.flowLayoutPanel1.SuspendLayout();
this.ctxMenu.SuspendLayout();
this.SuspendLayout();
//
// tableLayoutPanel1
@ -96,12 +97,27 @@
this.picNametable.TabStop = false;
this.picNametable.MouseMove += new System.Windows.Forms.MouseEventHandler(this.picNametable_MouseMove);
//
// ctxMenu
//
this.ctxMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuCopyHdPack});
this.ctxMenu.Name = "ctxMenu";
this.ctxMenu.Size = new System.Drawing.Size(222, 26);
this.ctxMenu.Opening += new System.ComponentModel.CancelEventHandler(this.ctxMenu_Opening);
//
// mnuCopyHdPack
//
this.mnuCopyHdPack.Name = "mnuCopyHdPack";
this.mnuCopyHdPack.Size = new System.Drawing.Size(221, 22);
this.mnuCopyHdPack.Text = "Copy Tile (HD Pack Format)";
this.mnuCopyHdPack.Click += new System.EventHandler(this.mnuCopyHdPack_Click);
//
// grpTileInfo
//
this.grpTileInfo.Controls.Add(this.tableLayoutPanel2);
this.grpTileInfo.Location = new System.Drawing.Point(519, 3);
this.grpTileInfo.Name = "grpTileInfo";
this.grpTileInfo.Size = new System.Drawing.Size(175, 330);
this.grpTileInfo.Size = new System.Drawing.Size(175, 353);
this.grpTileInfo.TabIndex = 4;
this.grpTileInfo.TabStop = false;
this.grpTileInfo.Text = "Tile Info";
@ -129,10 +145,12 @@
this.tableLayoutPanel2.Controls.Add(this.lblNametableIndex, 0, 1);
this.tableLayoutPanel2.Controls.Add(this.lblLocation, 0, 2);
this.tableLayoutPanel2.Controls.Add(this.lblPpuAddress, 0, 0);
this.tableLayoutPanel2.Controls.Add(this.ctrlTilePalette, 0, 9);
this.tableLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel2.Location = new System.Drawing.Point(3, 16);
this.tableLayoutPanel2.Name = "tableLayoutPanel2";
this.tableLayoutPanel2.RowCount = 10;
this.tableLayoutPanel2.RowCount = 11;
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());
@ -143,11 +161,12 @@
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(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel2.Size = new System.Drawing.Size(169, 311);
this.tableLayoutPanel2.Size = new System.Drawing.Size(169, 334);
this.tableLayoutPanel2.TabIndex = 0;
//
// txtPpuAddress
//
this.txtPpuAddress.BackColor = System.Drawing.SystemColors.Window;
this.txtPpuAddress.Location = new System.Drawing.Point(84, 3);
this.txtPpuAddress.Name = "txtPpuAddress";
this.txtPpuAddress.ReadOnly = true;
@ -156,6 +175,7 @@
//
// txtLocation
//
this.txtLocation.BackColor = System.Drawing.SystemColors.Window;
this.txtLocation.Location = new System.Drawing.Point(84, 55);
this.txtLocation.Name = "txtLocation";
this.txtLocation.ReadOnly = true;
@ -164,6 +184,7 @@
//
// txtNametable
//
this.txtNametable.BackColor = System.Drawing.SystemColors.Window;
this.txtNametable.Location = new System.Drawing.Point(84, 29);
this.txtNametable.Name = "txtNametable";
this.txtNametable.ReadOnly = true;
@ -172,6 +193,7 @@
//
// txtPaletteAddress
//
this.txtPaletteAddress.BackColor = System.Drawing.SystemColors.Window;
this.txtPaletteAddress.Location = new System.Drawing.Point(84, 185);
this.txtPaletteAddress.Name = "txtPaletteAddress";
this.txtPaletteAddress.ReadOnly = true;
@ -180,6 +202,7 @@
//
// txtAttributeAddress
//
this.txtAttributeAddress.BackColor = System.Drawing.SystemColors.Window;
this.txtAttributeAddress.Location = new System.Drawing.Point(84, 159);
this.txtAttributeAddress.Name = "txtAttributeAddress";
this.txtAttributeAddress.ReadOnly = true;
@ -188,6 +211,7 @@
//
// txtAttributeData
//
this.txtAttributeData.BackColor = System.Drawing.SystemColors.Window;
this.txtAttributeData.Location = new System.Drawing.Point(84, 133);
this.txtAttributeData.Name = "txtAttributeData";
this.txtAttributeData.ReadOnly = true;
@ -196,6 +220,7 @@
//
// txtTileAddress
//
this.txtTileAddress.BackColor = System.Drawing.SystemColors.Window;
this.txtTileAddress.Location = new System.Drawing.Point(84, 107);
this.txtTileAddress.Name = "txtTileAddress";
this.txtTileAddress.ReadOnly = true;
@ -264,6 +289,7 @@
//
// txtTileIndex
//
this.txtTileIndex.BackColor = System.Drawing.SystemColors.Window;
this.txtTileIndex.Location = new System.Drawing.Point(84, 81);
this.txtTileIndex.Name = "txtTileIndex";
this.txtTileIndex.ReadOnly = true;
@ -314,7 +340,7 @@
this.flowLayoutPanel1.Controls.Add(this.chkShowPpuScrollOverlay);
this.flowLayoutPanel1.Controls.Add(this.chkShowTileGrid);
this.flowLayoutPanel1.Controls.Add(this.chkShowAttributeGrid);
this.flowLayoutPanel1.Location = new System.Drawing.Point(516, 336);
this.flowLayoutPanel1.Location = new System.Drawing.Point(516, 359);
this.flowLayoutPanel1.Margin = new System.Windows.Forms.Padding(0);
this.flowLayoutPanel1.Name = "flowLayoutPanel1";
this.flowLayoutPanel1.Size = new System.Drawing.Size(181, 100);
@ -353,20 +379,16 @@
this.chkShowAttributeGrid.UseVisualStyleBackColor = true;
this.chkShowAttributeGrid.Click += new System.EventHandler(this.chkShowAttributeGrid_Click);
//
// ctxMenu
// ctrlTilePalette
//
this.ctxMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuCopyHdPack});
this.ctxMenu.Name = "ctxMenu";
this.ctxMenu.Size = new System.Drawing.Size(222, 48);
this.ctxMenu.Opening += new System.ComponentModel.CancelEventHandler(this.ctxMenu_Opening);
//
// mnuCopyHdPack
//
this.mnuCopyHdPack.Name = "mnuCopyHdPack";
this.mnuCopyHdPack.Size = new System.Drawing.Size(221, 22);
this.mnuCopyHdPack.Text = "Copy Tile (HD Pack Format)";
this.mnuCopyHdPack.Click += new System.EventHandler(this.mnuCopyHdPack_Click);
this.ctrlTilePalette.Anchor = System.Windows.Forms.AnchorStyles.None;
this.tableLayoutPanel2.SetColumnSpan(this.ctrlTilePalette, 2);
this.ctrlTilePalette.DisplayIndexes = false;
this.ctrlTilePalette.HighlightMouseOver = false;
this.ctrlTilePalette.Location = new System.Drawing.Point(19, 283);
this.ctrlTilePalette.Name = "ctrlTilePalette";
this.ctrlTilePalette.Size = new System.Drawing.Size(130, 34);
this.ctrlTilePalette.TabIndex = 19;
//
// ctrlNametableViewer
//
@ -377,13 +399,13 @@
this.Size = new System.Drawing.Size(697, 486);
this.tableLayoutPanel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.picNametable)).EndInit();
this.ctxMenu.ResumeLayout(false);
this.grpTileInfo.ResumeLayout(false);
this.tableLayoutPanel2.ResumeLayout(false);
this.tableLayoutPanel2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.picTile)).EndInit();
this.flowLayoutPanel1.ResumeLayout(false);
this.flowLayoutPanel1.PerformLayout();
this.ctxMenu.ResumeLayout(false);
this.ResumeLayout(false);
}
@ -418,5 +440,6 @@
private System.Windows.Forms.Label lblPpuAddress;
private System.Windows.Forms.ContextMenuStrip ctxMenu;
private System.Windows.Forms.ToolStripMenuItem mnuCopyHdPack;
private ctrlTilePalette ctrlTilePalette;
}
}

View file

@ -178,6 +178,8 @@ namespace Mesen.GUI.Debugger.Controls
int attributeAddr = baseAddress + 960 + ((_tileY & 0xFC) << 1) + (_tileX >> 2);
int paletteBaseAddr = ((attributeData >> shift) & 0x03) << 2;
this.ctrlTilePalette.SelectedPalette = (paletteBaseAddr >> 2);
this.txtPpuAddress.Text = _currentPpuAddress.ToString("X4");
this.txtNametable.Text = _nametableIndex.ToString();
this.txtLocation.Text = _tileX.ToString() + ", " + _tileY.ToString();

View file

@ -16,7 +16,7 @@ namespace Mesen.GUI.Debugger.Controls
public partial class ctrlPaletteViewer : BaseControl
{
private byte[] _paletteRam;
private byte[] _palettePixelData;
private int[] _palettePixelData;
private int _paletteIndex = -1;
public ctrlPaletteViewer()

View file

@ -52,6 +52,8 @@
this.picSprites = new System.Windows.Forms.PictureBox();
this.ctxMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
this.mnuCopyHdPack = new System.Windows.Forms.ToolStripMenuItem();
this.ctrlTilePalette = new Mesen.GUI.Debugger.Controls.ctrlTilePalette();
this.lblPalette = new System.Windows.Forms.Label();
this.tableLayoutPanel3.SuspendLayout();
this.grpSpriteInfo.SuspendLayout();
this.tableLayoutPanel4.SuspendLayout();
@ -95,10 +97,11 @@
this.tableLayoutPanel4.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 36.25F));
this.tableLayoutPanel4.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 38.75F));
this.tableLayoutPanel4.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25F));
this.tableLayoutPanel4.Controls.Add(this.lblPalette, 0, 4);
this.tableLayoutPanel4.Controls.Add(this.txtSpriteIndex, 1, 0);
this.tableLayoutPanel4.Controls.Add(this.lblSpriteIndex, 0, 0);
this.tableLayoutPanel4.Controls.Add(this.picPreview, 1, 4);
this.tableLayoutPanel4.Controls.Add(this.lblScreenPreview, 0, 4);
this.tableLayoutPanel4.Controls.Add(this.picPreview, 1, 5);
this.tableLayoutPanel4.Controls.Add(this.lblScreenPreview, 0, 5);
this.tableLayoutPanel4.Controls.Add(this.lblTile, 0, 3);
this.tableLayoutPanel4.Controls.Add(this.picTile, 1, 3);
this.tableLayoutPanel4.Controls.Add(this.lblPosition, 0, 2);
@ -110,10 +113,12 @@
this.tableLayoutPanel4.Controls.Add(this.txtPaletteAddress, 3, 0);
this.tableLayoutPanel4.Controls.Add(this.txtTileAddress, 3, 1);
this.tableLayoutPanel4.Controls.Add(this.tableLayoutPanel1, 2, 2);
this.tableLayoutPanel4.Controls.Add(this.ctrlTilePalette, 1, 4);
this.tableLayoutPanel4.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel4.Location = new System.Drawing.Point(3, 16);
this.tableLayoutPanel4.Name = "tableLayoutPanel4";
this.tableLayoutPanel4.RowCount = 5;
this.tableLayoutPanel4.RowCount = 6;
this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle());
@ -125,6 +130,7 @@
//
// txtSpriteIndex
//
this.txtSpriteIndex.BackColor = System.Drawing.SystemColors.Window;
this.txtSpriteIndex.Location = new System.Drawing.Point(94, 3);
this.txtSpriteIndex.Name = "txtSpriteIndex";
this.txtSpriteIndex.ReadOnly = true;
@ -146,16 +152,16 @@
this.picPreview.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.picPreview.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.tableLayoutPanel4.SetColumnSpan(this.picPreview, 3);
this.picPreview.Location = new System.Drawing.Point(94, 217);
this.picPreview.Location = new System.Drawing.Point(94, 257);
this.picPreview.Name = "picPreview";
this.picPreview.Size = new System.Drawing.Size(258, 242);
this.picPreview.Size = new System.Drawing.Size(258, 231);
this.picPreview.TabIndex = 21;
this.picPreview.TabStop = false;
//
// lblScreenPreview
//
this.lblScreenPreview.AutoSize = true;
this.lblScreenPreview.Location = new System.Drawing.Point(3, 219);
this.lblScreenPreview.Location = new System.Drawing.Point(3, 259);
this.lblScreenPreview.Margin = new System.Windows.Forms.Padding(3, 5, 3, 0);
this.lblScreenPreview.Name = "lblScreenPreview";
this.lblScreenPreview.Size = new System.Drawing.Size(85, 13);
@ -188,12 +194,13 @@
this.lblPosition.AutoSize = true;
this.lblPosition.Location = new System.Drawing.Point(3, 58);
this.lblPosition.Name = "lblPosition";
this.lblPosition.Size = new System.Drawing.Size(70, 13);
this.lblPosition.Size = new System.Drawing.Size(73, 13);
this.lblPosition.TabIndex = 16;
this.lblPosition.Text = "Position (X,Y)";
this.lblPosition.Text = "Position (X,Y):";
//
// txtPosition
//
this.txtPosition.BackColor = System.Drawing.SystemColors.Window;
this.txtPosition.Location = new System.Drawing.Point(94, 55);
this.txtPosition.Name = "txtPosition";
this.txtPosition.ReadOnly = true;
@ -212,6 +219,7 @@
//
// txtTileIndex
//
this.txtTileIndex.BackColor = System.Drawing.SystemColors.Window;
this.txtTileIndex.Location = new System.Drawing.Point(94, 29);
this.txtTileIndex.Name = "txtTileIndex";
this.txtTileIndex.ReadOnly = true;
@ -240,6 +248,7 @@
//
// txtPaletteAddress
//
this.txtPaletteAddress.BackColor = System.Drawing.SystemColors.Window;
this.txtPaletteAddress.Location = new System.Drawing.Point(332, 3);
this.txtPaletteAddress.Name = "txtPaletteAddress";
this.txtPaletteAddress.ReadOnly = true;
@ -248,6 +257,7 @@
//
// txtTileAddress
//
this.txtTileAddress.BackColor = System.Drawing.SystemColors.Window;
this.txtTileAddress.Location = new System.Drawing.Point(332, 29);
this.txtTileAddress.Name = "txtTileAddress";
this.txtTileAddress.ReadOnly = true;
@ -335,6 +345,28 @@
this.mnuCopyHdPack.Text = "Copy Tile (HD Pack Format)";
this.mnuCopyHdPack.Click += new System.EventHandler(this.mnuCopyHdPack_Click);
//
// ctrlTilePalette
//
this.ctrlTilePalette.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.tableLayoutPanel4.SetColumnSpan(this.ctrlTilePalette, 2);
this.ctrlTilePalette.DisplayIndexes = false;
this.ctrlTilePalette.HighlightMouseOver = false;
this.ctrlTilePalette.Location = new System.Drawing.Point(94, 217);
this.ctrlTilePalette.Name = "ctrlTilePalette";
this.ctrlTilePalette.Size = new System.Drawing.Size(130, 34);
this.ctrlTilePalette.TabIndex = 25;
//
// lblPalette
//
this.lblPalette.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.lblPalette.AutoSize = true;
this.lblPalette.Location = new System.Drawing.Point(3, 230);
this.lblPalette.Margin = new System.Windows.Forms.Padding(3, 5, 3, 0);
this.lblPalette.Name = "lblPalette";
this.lblPalette.Size = new System.Drawing.Size(43, 13);
this.lblPalette.TabIndex = 26;
this.lblPalette.Text = "Palette:";
//
// ctrlSpriteViewer
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -382,5 +414,7 @@
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.ContextMenuStrip ctxMenu;
private System.Windows.Forms.ToolStripMenuItem mnuCopyHdPack;
private System.Windows.Forms.Label lblPalette;
private ctrlTilePalette ctrlTilePalette;
}
}

View file

@ -138,6 +138,8 @@ namespace Mesen.GUI.Debugger.Controls
tileAddr = _spritePatternAddr + (tileIndex << 4);
}
this.ctrlTilePalette.SelectedPalette = (attributes & 0x03) + 4;
int paletteAddr = 0x3F10 + ((attributes & 0x03) << 2);
bool verticalMirror = (attributes & 0x80) == 0x80;
bool horizontalMirror = (attributes & 0x40) == 0x40;

View file

@ -0,0 +1,63 @@
namespace Mesen.GUI.Debugger.Controls
{
partial class ctrlTilePalette
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if(disposing && (components != null)) {
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.picPaletteSelection = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.picPaletteSelection)).BeginInit();
this.SuspendLayout();
//
// picPaletteSelection
//
this.picPaletteSelection.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.picPaletteSelection.Dock = System.Windows.Forms.DockStyle.Fill;
this.picPaletteSelection.Location = new System.Drawing.Point(0, 0);
this.picPaletteSelection.Name = "picPaletteSelection";
this.picPaletteSelection.Size = new System.Drawing.Size(130, 34);
this.picPaletteSelection.TabIndex = 14;
this.picPaletteSelection.TabStop = false;
this.picPaletteSelection.MouseDown += new System.Windows.Forms.MouseEventHandler(this.picPaletteSelection_MouseDown);
this.picPaletteSelection.MouseLeave += new System.EventHandler(this.picPaletteSelection_MouseLeave);
this.picPaletteSelection.MouseMove += new System.Windows.Forms.MouseEventHandler(this.picPaletteSelection_MouseMove);
//
// ctrlTilePalette
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.picPaletteSelection);
this.Name = "ctrlTilePalette";
this.Size = new System.Drawing.Size(130, 34);
((System.ComponentModel.ISupportInitialize)(this.picPaletteSelection)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.PictureBox picPaletteSelection;
}
}

View file

@ -0,0 +1,150 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using Mesen.GUI.Forms;
using Mesen.GUI.Controls;
namespace Mesen.GUI.Debugger.Controls
{
public partial class ctrlTilePalette : UserControl
{
private int _selectedPalette = -1;
private bool _allowSelection = false;
private int _hoverColor = -1;
private int _selectedColor = 0;
public bool HighlightMouseOver { get; set; }
public bool DisplayIndexes { get; set; }
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public int SelectedColor {
get
{
return _selectedColor;
}
set
{
_selectedColor = value;
this.RefreshPalette();
}
}
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool AllowSelection
{
get
{
return _allowSelection;
}
set
{
if(value) {
this.picPaletteSelection.Cursor = new Cursor(Properties.Resources.Pipette.GetHicon());
} else {
this.picPaletteSelection.Cursor = Cursors.Default;
}
_allowSelection = value;
}
}
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public int SelectedPalette
{
get
{
return _selectedPalette;
}
set
{
_selectedPalette = value;
this.RefreshPalette();
}
}
public ctrlTilePalette()
{
InitializeComponent();
}
public void RefreshPalette()
{
if(_selectedPalette < 0) {
return;
}
byte[] paletteRam = InteropEmu.DebugGetMemoryState(DebugMemoryType.PaletteMemory);
int[] palette = InteropEmu.DebugGetPalette();
int[] currentPalette = new int[16];
Array.Copy(palette, _selectedPalette * 4, currentPalette, 0, 4);
GCHandle handle = GCHandle.Alloc(currentPalette, GCHandleType.Pinned);
try {
Bitmap source = new Bitmap(4, 1, 4*4, System.Drawing.Imaging.PixelFormat.Format32bppArgb, handle.AddrOfPinnedObject());
Bitmap target = new Bitmap(128, 32);
using(Graphics g = Graphics.FromImage(target)) {
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
g.ScaleTransform(32, 32);
g.DrawImageUnscaled(source, 0, 0);
g.ResetTransform();
using(Font font = new Font(BaseControl.MonospaceFontFamily, 10)) {
using(Brush bg = new SolidBrush(Color.FromArgb(150, Color.LightGray))) {
for(int i = 0; i < 4; i++) {
if(this.DisplayIndexes) {
g.DrawOutlinedString(i.ToString(), font, Brushes.Black, bg, 5+i*32, 2);
} else {
g.DrawOutlinedString(paletteRam[_selectedPalette*4 + i].ToString("X2"), font, Brushes.Black, bg, 14+i*32, 18);
}
}
}
}
if(this.AllowSelection) {
using(Pen pen = new Pen(Color.LightBlue, 3)) {
g.DrawRectangle(pen, this.SelectedColor * 32 + 2, 2, 29, 29);
}
}
if(this.HighlightMouseOver && _hoverColor >= 0) {
using(Pen pen = new Pen(Color.DarkGray, 3)) {
g.DrawRectangle(pen, _hoverColor * 32 + 2, 2, 29, 29);
}
}
}
this.picPaletteSelection.Image = target;
} finally {
handle.Free();
}
}
private void picPaletteSelection_MouseMove(object sender, MouseEventArgs e)
{
_hoverColor = e.X / 32;
RefreshPalette();
}
private void picPaletteSelection_MouseDown(object sender, MouseEventArgs e)
{
this.SelectedColor = e.X / 32;
RefreshPalette();
}
private void picPaletteSelection_MouseLeave(object sender, EventArgs e)
{
_hoverColor = -1;
RefreshPalette();
}
}
}

View file

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View file

@ -382,6 +382,12 @@
<Compile Include="Debugger\Controls\ctrlTextbox.Designer.cs">
<DependentUpon>ctrlTextbox.cs</DependentUpon>
</Compile>
<Compile Include="Debugger\Controls\ctrlTilePalette.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Debugger\Controls\ctrlTilePalette.Designer.cs">
<DependentUpon>ctrlTilePalette.cs</DependentUpon>
</Compile>
<Compile Include="Debugger\Controls\ctrlWatch.cs">
<SubType>UserControl</SubType>
</Compile>
@ -831,6 +837,9 @@
<EmbeddedResource Include="Debugger\Controls\ctrlScrollableTextbox.resx">
<DependentUpon>ctrlScrollableTextbox.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Debugger\Controls\ctrlTilePalette.resx">
<DependentUpon>ctrlTilePalette.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Debugger\Controls\ctrlWatch.resx">
<DependentUpon>ctrlWatch.cs</DependentUpon>
</EmbeddedResource>

View file

@ -394,9 +394,9 @@ namespace Mesen.GUI
}
[DllImport(DLLPath, EntryPoint = "DebugGetPalette")] private static extern void DebugGetPaletteWrapper(IntPtr frameBuffer);
public static byte[] DebugGetPalette()
public static int[] DebugGetPalette()
{
byte[] frameData = new byte[4*8*4];
int[] frameData = new int[4*8];
GCHandle hFrameData = GCHandle.Alloc(frameData, GCHandleType.Pinned);
try {