2015-08-08 22:36:39 -04:00
|
|
|
|
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;
|
2016-12-11 14:25:29 -05:00
|
|
|
|
using Mesen.GUI.Controls;
|
2015-08-08 22:36:39 -04:00
|
|
|
|
|
|
|
|
|
namespace Mesen.GUI.Debugger.Controls
|
|
|
|
|
{
|
2016-12-11 14:25:29 -05:00
|
|
|
|
public partial class ctrlChrViewer : BaseControl
|
2015-08-08 22:36:39 -04:00
|
|
|
|
{
|
2016-11-26 20:44:23 -05:00
|
|
|
|
private byte[][] _chrPixelData = new byte[2][];
|
|
|
|
|
private int _selectedPalette = 0;
|
|
|
|
|
private int _chrSelection = 0;
|
|
|
|
|
private CdlHighlightType _highlightType = CdlHighlightType.None;
|
|
|
|
|
private bool _useLargeSprites = false;
|
|
|
|
|
|
2015-08-08 22:36:39 -04:00
|
|
|
|
public ctrlChrViewer()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2016-11-29 20:44:22 -05:00
|
|
|
|
|
|
|
|
|
bool designMode = (LicenseManager.UsageMode == LicenseUsageMode.Designtime);
|
|
|
|
|
if(!designMode) {
|
|
|
|
|
this.cboPalette.SelectedIndex = 0;
|
|
|
|
|
this.cboHighlightType.SelectedIndex = 0;
|
|
|
|
|
}
|
2015-08-08 22:36:39 -04:00
|
|
|
|
}
|
2016-11-26 20:44:23 -05:00
|
|
|
|
|
|
|
|
|
public void GetData()
|
2015-08-08 22:36:39 -04:00
|
|
|
|
{
|
2016-11-26 20:44:23 -05:00
|
|
|
|
for(int i = 0; i < 2; i++) {
|
|
|
|
|
_chrPixelData[i] = InteropEmu.DebugGetChrBank(i + _chrSelection * 2, _selectedPalette, _useLargeSprites, _highlightType);
|
2015-08-08 22:36:39 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RefreshViewer()
|
|
|
|
|
{
|
2016-09-05 12:09:14 -04:00
|
|
|
|
UpdateDropdown();
|
|
|
|
|
|
2016-11-26 20:44:23 -05:00
|
|
|
|
PictureBox[] chrBanks = new PictureBox[] { this.picChrBank1, this.picChrBank2 };
|
|
|
|
|
|
2015-08-08 22:36:39 -04:00
|
|
|
|
for(int i = 0; i < 2; i++) {
|
2016-11-26 20:44:23 -05:00
|
|
|
|
byte[] pixelData = _chrPixelData[i];
|
2015-08-08 22:36:39 -04:00
|
|
|
|
|
|
|
|
|
GCHandle handle = GCHandle.Alloc(pixelData, GCHandleType.Pinned);
|
|
|
|
|
try {
|
|
|
|
|
Bitmap source = new Bitmap(128, 128, 4*128, System.Drawing.Imaging.PixelFormat.Format32bppArgb, handle.AddrOfPinnedObject());
|
|
|
|
|
Bitmap target = new Bitmap(256, 256);
|
|
|
|
|
|
|
|
|
|
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;
|
2016-09-05 12:09:14 -04:00
|
|
|
|
g.Clear(Color.Black);
|
2015-08-08 22:36:39 -04:00
|
|
|
|
g.DrawImage(source, new Rectangle(0, 0, 256, 256), new Rectangle(0, 0, 128, 128), GraphicsUnit.Pixel);
|
|
|
|
|
}
|
|
|
|
|
chrBanks[i].Image = target;
|
|
|
|
|
} finally {
|
|
|
|
|
handle.Free();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-05 12:09:14 -04:00
|
|
|
|
private UInt32 _chrSize;
|
|
|
|
|
private void UpdateDropdown()
|
|
|
|
|
{
|
|
|
|
|
DebugState state = new DebugState();
|
|
|
|
|
InteropEmu.DebugGetState(ref state);
|
|
|
|
|
|
2016-09-05 16:34:01 -04:00
|
|
|
|
if(state.Cartridge.ChrRomSize == 0) {
|
|
|
|
|
this.flpHighlight.Visible = false;
|
|
|
|
|
this.cboHighlightType.SelectedIndex = 0;
|
|
|
|
|
} else {
|
|
|
|
|
this.flpHighlight.Visible = true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-05 12:09:14 -04:00
|
|
|
|
UInt32 chrSize = state.Cartridge.ChrRomSize == 0 ? state.Cartridge.ChrRamSize : state.Cartridge.ChrRomSize;
|
|
|
|
|
|
|
|
|
|
if(chrSize != _chrSize) {
|
|
|
|
|
_chrSize = chrSize;
|
|
|
|
|
|
|
|
|
|
int index = this.cboChrSelection.SelectedIndex;
|
|
|
|
|
this.cboChrSelection.Items.Clear();
|
|
|
|
|
this.cboChrSelection.Items.Add("PPU: $0000 - $1FFF");
|
|
|
|
|
for(int i = 0; i < _chrSize / 0x2000; i++) {
|
|
|
|
|
this.cboChrSelection.Items.Add("CHR: $" + (i * 0x2000).ToString("X4") + " - $" + (i * 0x2000 + 0x1FFF).ToString("X4"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.cboChrSelection.SelectedIndex = this.cboChrSelection.Items.Count > index && index >= 0 ? index : 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void cboChrSelection_DropDown(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
UpdateDropdown();
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-08 22:36:39 -04:00
|
|
|
|
private void cboPalette_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2016-11-26 20:44:23 -05:00
|
|
|
|
this._selectedPalette = this.cboPalette.SelectedIndex;
|
2015-08-08 22:36:39 -04:00
|
|
|
|
this.RefreshViewer();
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-29 18:10:55 -04:00
|
|
|
|
private void chkLargeSprites_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2016-11-26 20:44:23 -05:00
|
|
|
|
this._useLargeSprites = this.chkLargeSprites.Checked;
|
2016-08-29 18:10:55 -04:00
|
|
|
|
this.RefreshViewer();
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-05 12:09:14 -04:00
|
|
|
|
private void cboHighlightType_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2016-11-26 20:44:23 -05:00
|
|
|
|
this._highlightType = (CdlHighlightType)this.cboHighlightType.SelectedIndex;
|
2016-09-05 12:09:14 -04:00
|
|
|
|
this.RefreshViewer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void cboChrSelection_SelectionChangeCommitted(object sender, EventArgs e)
|
|
|
|
|
{
|
2016-11-26 20:44:23 -05:00
|
|
|
|
this._chrSelection = this.cboChrSelection.SelectedIndex;
|
2016-09-05 12:09:14 -04:00
|
|
|
|
this.RefreshViewer();
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-08 22:36:39 -04:00
|
|
|
|
private void picChrBank_MouseMove(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
List<PictureBox> chrBanks = new List<PictureBox>() { this.picChrBank1, this.picChrBank2 };
|
|
|
|
|
int bankIndex = chrBanks.IndexOf((PictureBox)sender);
|
|
|
|
|
int baseAddress = bankIndex == 0 ? 0x0000 : 0x1000;
|
2016-09-05 12:09:14 -04:00
|
|
|
|
if(this.cboChrSelection.SelectedIndex > 1) {
|
|
|
|
|
baseAddress += (this.cboChrSelection.SelectedIndex - 1) * 0x2000;
|
|
|
|
|
}
|
2015-08-08 22:36:39 -04:00
|
|
|
|
|
|
|
|
|
int tileX = Math.Min(e.X / 16, 15);
|
|
|
|
|
int tileY = Math.Min(e.Y / 16, 15);
|
|
|
|
|
|
|
|
|
|
int tileIndex = tileY * 16 + tileX;
|
|
|
|
|
|
|
|
|
|
this.txtTileIndex.Text = tileIndex.ToString("X2");
|
|
|
|
|
this.txtTileAddress.Text = (baseAddress + tileIndex * 16).ToString("X4");
|
|
|
|
|
|
|
|
|
|
Bitmap tile = new Bitmap(64, 64);
|
|
|
|
|
using(Graphics g = Graphics.FromImage(tile)) {
|
|
|
|
|
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
|
|
|
|
|
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
|
|
|
|
|
g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
|
|
|
|
|
g.DrawImage(((PictureBox)sender).Image, new Rectangle(0, 0, 64, 64), new Rectangle(tileX*16, tileY*16, 16, 16), GraphicsUnit.Pixel);
|
|
|
|
|
}
|
|
|
|
|
this.picTile.Image = tile;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|