Debugger: Tile Viewer - Remember options/position/size

This commit is contained in:
Sour 2019-04-21 20:18:32 -04:00
parent 1847932b0a
commit f0cb8052d7
8 changed files with 179 additions and 216 deletions

View file

@ -22,6 +22,7 @@ namespace Mesen.GUI.Config
public EventViewerInfo EventViewer = new EventViewerInfo();
public DebuggerInfo Debugger = new DebuggerInfo();
public TilemapViewerConfig TilemapViewer = new TilemapViewerConfig();
public TileViewerConfig TileViewer = new TileViewerConfig();
public DebugInfo()
{

View file

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;
using Mesen.GUI.Debugger;
using Mesen.GUI.Controls;
using Mesen.GUI.Utilities;
namespace Mesen.GUI.Config
{
public class TileViewerConfig
{
public Size WindowSize = new Size(0, 0);
public Point WindowLocation;
public int ImageScale = 3;
public bool ShowTileGrid = false;
public SnesMemoryType Source = SnesMemoryType.VideoRam;
public TileFormat Format = TileFormat.Bpp4;
public int ColumnCount = 16;
public int Bank = 0;
public int Offset = 0;
public int SelectedPalette = 0;
public bool AutoRefresh = true;
public int RefreshScanline = 240;
public int RefreshCycle = 0;
public TileViewerConfig()
{
}
}
}

View file

@ -1,62 +0,0 @@
namespace Mesen.GUI.Debugger
{
partial class ctrlPaletteViewer
{
/// <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.picPalette = new Mesen.GUI.Controls.ctrlMesenPictureBox();
((System.ComponentModel.ISupportInitialize)(this.picPalette)).BeginInit();
this.SuspendLayout();
//
// picPalette
//
this.picPalette.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
this.picPalette.Location = new System.Drawing.Point(0, 0);
this.picPalette.MinimumSize = new System.Drawing.Size(256, 256);
this.picPalette.Name = "picPalette";
this.picPalette.Size = new System.Drawing.Size(256, 256);
this.picPalette.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.picPalette.TabIndex = 1;
this.picPalette.TabStop = false;
this.picPalette.MouseClick += new System.Windows.Forms.MouseEventHandler(this.picPalette_MouseClick);
//
// ctrlPaletteViewer
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.picPalette);
this.Name = "ctrlPaletteViewer";
this.Size = new System.Drawing.Size(256, 256);
((System.ComponentModel.ISupportInitialize)(this.picPalette)).EndInit();
this.ResumeLayout(false);
}
#endregion
private GUI.Controls.ctrlMesenPictureBox picPalette;
}
}

View file

@ -14,27 +14,90 @@ using System.Drawing.Drawing2D;
namespace Mesen.GUI.Debugger
{
public partial class ctrlPaletteViewer : BaseControl
public partial class ctrlPaletteViewer : PictureBox
{
public delegate void SelectionChangedHandler();
public event SelectionChangedHandler SelectionChanged;
private byte[] _cgRam;
private Bitmap _paletteImage;
private int _selectedPalette = 0;
private PaletteSelectionMode _selectionMode = PaletteSelectionMode.None;
public int PaletteScale { get; set; } = 16;
public int SelectedPalette { get; private set; } = 0;
public PaletteSelectionMode SelectionMode { get; set; } = PaletteSelectionMode.None;
public ctrlPaletteViewer()
{
InitializeComponent();
if(IsDesignMode) {
return;
}
this.SetStyle(ControlStyles.Selectable, true);
_paletteImage = new Bitmap(PaletteScale * 16, PaletteScale * 16, PixelFormat.Format32bppArgb);
picPalette.Image = _paletteImage;
this.Image = _paletteImage;
}
public int SelectedPalette
{
get { return _selectedPalette; }
set
{
int maxPalette = 0;
switch(this.SelectionMode) {
case PaletteSelectionMode.SingleColor: maxPalette = 255; break;
case PaletteSelectionMode.FourColors: maxPalette = 63; break;
case PaletteSelectionMode.SixteenColors: maxPalette = 15; break;
}
int newPalette = Math.Max(0, Math.Min(value, maxPalette));
if(newPalette != _selectedPalette) {
_selectedPalette = newPalette;
SelectionChanged?.Invoke();
}
}
}
public PaletteSelectionMode SelectionMode
{
get { return _selectionMode; }
set
{
_selectionMode = value;
this.SelectedPalette = _selectedPalette;
}
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
switch(keyData) {
case Keys.Left:
this.SelectedPalette--;
RefreshViewer();
return true;
case Keys.Right:
this.SelectedPalette++;
RefreshViewer();
return true;
case Keys.Down:
switch(this.SelectionMode) {
case PaletteSelectionMode.SingleColor: this.SelectedPalette+=16; break;
case PaletteSelectionMode.FourColors: this.SelectedPalette+=4; break;
case PaletteSelectionMode.SixteenColors: this.SelectedPalette++; break;
}
RefreshViewer();
return true;
case Keys.Up:
switch(this.SelectionMode) {
case PaletteSelectionMode.SingleColor: this.SelectedPalette-=16; break;
case PaletteSelectionMode.FourColors: this.SelectedPalette-=4; break;
case PaletteSelectionMode.SixteenColors: this.SelectedPalette--; break;
}
RefreshViewer();
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
public byte[] CgRam
@ -52,7 +115,8 @@ namespace Mesen.GUI.Debugger
return (uint)((color << 3) + (color >> 2));
}
public uint ToArgb(int rgb555) {
public uint ToArgb(int rgb555)
{
uint b = To8Bit(rgb555 >> 10);
uint g = To8Bit((rgb555 >> 5) & 0x1F);
uint r = To8Bit(rgb555 & 0x1F);
@ -94,12 +158,14 @@ namespace Mesen.GUI.Debugger
}
}
picPalette.Size = _paletteImage.Size;
picPalette.Invalidate();
this.Size = _paletteImage.Size;
this.Invalidate();
}
private void picPalette_MouseClick(object sender, MouseEventArgs e)
protected override void OnMouseClick(MouseEventArgs e)
{
base.OnMouseClick(e);
int paletteIndex = 0;
if(SelectionMode == PaletteSelectionMode.SingleColor) {
paletteIndex = (e.Y / PaletteScale) * 16 + (e.X / PaletteScale);
@ -111,9 +177,9 @@ namespace Mesen.GUI.Debugger
}
SelectedPalette = paletteIndex;
SelectionChanged?.Invoke();
RefreshViewer();
this.Focus();
}
}

View file

@ -1,120 +0,0 @@
<?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

@ -78,7 +78,7 @@
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 1;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 522F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(737, 522);
this.tableLayoutPanel1.TabIndex = 7;
//
@ -301,6 +301,7 @@
this.ctrlPaletteViewer.Location = new System.Drawing.Point(3, 161);
this.ctrlPaletteViewer.Name = "ctrlPaletteViewer";
this.ctrlPaletteViewer.PaletteScale = 11;
this.ctrlPaletteViewer.SelectedPalette = 0;
this.ctrlPaletteViewer.SelectionMode = Mesen.GUI.Debugger.PaletteSelectionMode.None;
this.ctrlPaletteViewer.Size = new System.Drawing.Size(176, 176);
this.ctrlPaletteViewer.TabIndex = 12;
@ -341,7 +342,7 @@
//
this.mnuClose.Image = global::Mesen.GUI.Properties.Resources.Exit;
this.mnuClose.Name = "mnuClose";
this.mnuClose.Size = new System.Drawing.Size(152, 22);
this.mnuClose.Size = new System.Drawing.Size(103, 22);
this.mnuClose.Text = "Close";
this.mnuClose.Click += new System.EventHandler(this.mnuClose_Click);
//
@ -366,6 +367,7 @@
this.mnuAutoRefresh.Name = "mnuAutoRefresh";
this.mnuAutoRefresh.Size = new System.Drawing.Size(152, 22);
this.mnuAutoRefresh.Text = "Auto-refresh";
this.mnuAutoRefresh.CheckedChanged += new System.EventHandler(this.mnuAutoRefresh_CheckedChanged);
//
// toolStripMenuItem2
//

View file

@ -25,6 +25,7 @@ namespace Mesen.GUI.Debugger
private SnesMemoryType _memoryType = SnesMemoryType.VideoRam;
private int _addressOffset = 0;
private DateTime _lastUpdate = DateTime.MinValue;
private bool _autoRefresh = true;
public frmTileViewer()
{
@ -42,25 +43,36 @@ namespace Mesen.GUI.Debugger
_notifListener.OnNotification += OnNotificationReceived;
BaseConfigForm.InitializeComboBox(cboFormat, typeof(TileFormat));
InitMemoryTypeDropdown();
_tileData = new byte[512 * 512 * 4];
_tileImage = new Bitmap(512, 512, PixelFormat.Format32bppArgb);
ctrlImagePanel.Image = _tileImage;
ctrlScanlineCycleSelect.Initialize(241, 0);
InitShortcuts();
_options.Format = TileFormat.Bpp4;
_options.Width = 32;
_options.Palette = ctrlPaletteViewer.SelectedPalette;
TileViewerConfig config = ConfigManager.Config.Debug.TileViewer;
if(!config.WindowSize.IsEmpty) {
this.StartPosition = FormStartPosition.Manual;
this.Size = config.WindowSize;
this.Location = config.WindowLocation;
}
cboMemoryType.SetEnumValue(config.Source);
cboFormat.SetEnumValue(config.Format);
nudColumns.Value = config.ColumnCount;
nudBank.Value = config.Bank;
nudOffset.Value = config.Offset;
mnuAutoRefresh.Checked = config.AutoRefresh;
chkShowTileGrid.Checked = config.ShowTileGrid;
ctrlImagePanel.ImageScale = config.ImageScale;
ctrlScanlineCycleSelect.Initialize(config.RefreshScanline, config.RefreshCycle);
ctrlPaletteViewer.SelectedPalette = config.SelectedPalette;
_options.ShowTileGrid = config.ShowTileGrid;
RefreshData();
RefreshViewer();
InitMemoryTypeDropdown();
cboFormat.SetEnumValue(TileFormat.Bpp4);
ctrlPaletteViewer.SelectionMode = PaletteSelectionMode.SixteenColors;
InitShortcuts();
}
private void InitShortcuts()
@ -74,6 +86,24 @@ namespace Mesen.GUI.Debugger
{
base.OnFormClosed(e);
_notifListener?.Dispose();
TileViewerConfig config = ConfigManager.Config.Debug.TileViewer;
config.WindowSize = this.WindowState != FormWindowState.Normal ? this.RestoreBounds.Size : this.Size;
config.WindowLocation = this.WindowState != FormWindowState.Normal ? this.RestoreBounds.Location : this.Location;
config.AutoRefresh = mnuAutoRefresh.Checked;
config.ShowTileGrid = chkShowTileGrid.Checked;
config.RefreshScanline = ctrlScanlineCycleSelect.Scanline;
config.RefreshCycle = ctrlScanlineCycleSelect.Cycle;
config.ImageScale = ctrlImagePanel.ImageScale;
config.Source = cboMemoryType.GetEnumValue<SnesMemoryType>();
config.Format = cboFormat.GetEnumValue<TileFormat>();
config.ColumnCount = (int)nudColumns.Value;
config.Bank = (int)nudBank.Value;
config.Offset = (int)nudOffset.Value;
config.SelectedPalette = ctrlPaletteViewer.SelectedPalette;
ConfigManager.ApplyChanges();
}
private void OnNotificationReceived(NotificationEventArgs e)
@ -81,7 +111,7 @@ namespace Mesen.GUI.Debugger
switch(e.NotificationType) {
case ConsoleNotificationType.CodeBreak:
case ConsoleNotificationType.ViewerRefresh:
if(e.Parameter.ToInt32() == ctrlScanlineCycleSelect.ViewerId) {
if(_autoRefresh && e.Parameter.ToInt32() == ctrlScanlineCycleSelect.ViewerId) {
if((DateTime.Now - _lastUpdate).Milliseconds > 10) {
_lastUpdate = DateTime.Now;
RefreshData();
@ -127,6 +157,10 @@ namespace Mesen.GUI.Debugger
private void RefreshViewer()
{
if(_tileSource == null) {
return;
}
DebugApi.GetTileView(_options, _tileSource, _tileSource.Length, _cgram, _tileData);
int tileCount = 0x10000 / GetBytesPerTile();
@ -226,12 +260,14 @@ namespace Mesen.GUI.Debugger
private void nudBank_ValueChanged(object sender, EventArgs e)
{
_addressOffset = (int)(nudBank.Value * 0x10000 + nudOffset.Value);
RefreshData();
RefreshViewer();
}
private void nudOffset_ValueChanged(object sender, EventArgs e)
{
_addressOffset = (int)(nudBank.Value * 0x10000 + nudOffset.Value);
RefreshData();
RefreshViewer();
}
@ -261,5 +297,10 @@ namespace Mesen.GUI.Debugger
{
Close();
}
private void mnuAutoRefresh_CheckedChanged(object sender, EventArgs e)
{
_autoRefresh = mnuAutoRefresh.Checked;
}
}
}

View file

@ -252,6 +252,7 @@
<Compile Include="Debugger\Code\IDisassemblyManager.cs" />
<Compile Include="Debugger\Config\DebuggerShortcutsConfig.cs" />
<Compile Include="Debugger\Config\DebuggerInfo.cs" />
<Compile Include="Debugger\Config\TileViewerConfig.cs" />
<Compile Include="Debugger\Config\TilemapViewerConfig.cs" />
<Compile Include="Debugger\Controls\ctrlPanel.cs">
<SubType>Component</SubType>
@ -475,10 +476,7 @@
</Compile>
<Compile Include="Debugger\MemoryTools\TblByteCharConverter.cs" />
<Compile Include="Debugger\PpuViewer\ctrlPaletteViewer.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Debugger\PpuViewer\ctrlPaletteViewer.Designer.cs">
<DependentUpon>ctrlPaletteViewer.cs</DependentUpon>
<SubType>Component</SubType>
</Compile>
<Compile Include="Debugger\PpuViewer\ctrlScanlineCycleSelect.cs">
<SubType>UserControl</SubType>
@ -806,9 +804,6 @@
<EmbeddedResource Include="Debugger\PpuViewer\ctrlImagePanel.resx">
<DependentUpon>ctrlImagePanel.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Debugger\PpuViewer\ctrlPaletteViewer.resx">
<DependentUpon>ctrlPaletteViewer.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Debugger\PpuViewer\ctrlScanlineCycleSelect.resx">
<DependentUpon>ctrlScanlineCycleSelect.cs</DependentUpon>
</EmbeddedResource>