2012-03-12 05:26:48 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Drawing.Imaging;
|
2014-01-31 23:42:06 +00:00
|
|
|
|
using System.Windows.Forms;
|
2013-10-25 00:57:23 +00:00
|
|
|
|
|
|
|
|
|
using BizHawk.Client.Common;
|
2013-11-13 23:36:21 +00:00
|
|
|
|
using BizHawk.Emulation.Cores.PCEngine;
|
2012-03-12 05:26:48 +00:00
|
|
|
|
|
2013-11-03 03:54:37 +00:00
|
|
|
|
namespace BizHawk.Client.EmuHawk
|
2012-03-12 05:26:48 +00:00
|
|
|
|
{
|
2014-01-31 23:42:06 +00:00
|
|
|
|
public partial class PceBgViewer : Form, IToolForm
|
2012-03-12 05:26:48 +00:00
|
|
|
|
{
|
2013-11-20 01:37:54 +00:00
|
|
|
|
private PCEngine _pce;
|
2014-01-31 23:42:06 +00:00
|
|
|
|
private int _vdcType;
|
2013-11-02 22:39:23 +00:00
|
|
|
|
|
2014-01-31 23:42:06 +00:00
|
|
|
|
public PceBgViewer()
|
2012-03-12 05:26:48 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2014-01-31 23:42:06 +00:00
|
|
|
|
TopMost = Global.Config.PceBgViewerSettings.TopMost;
|
2012-03-12 05:26:48 +00:00
|
|
|
|
Activated += (o, e) => Generate();
|
2014-01-31 23:42:06 +00:00
|
|
|
|
Closing += (o, e) =>
|
|
|
|
|
{
|
|
|
|
|
Global.Config.PceBgViewerSettings.Wndx = Location.X;
|
|
|
|
|
Global.Config.PceBgViewerSettings.Wndy = Location.Y;
|
|
|
|
|
Global.Config.PCEBGViewerRefreshRate = RefreshRate.Value;
|
|
|
|
|
};
|
2012-03-12 05:26:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-31 23:42:06 +00:00
|
|
|
|
private void PceBgViewer_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_pce = Global.Emulator as PCEngine;
|
|
|
|
|
|
|
|
|
|
if (Global.Config.PceBgViewerSettings.UseWindowPosition)
|
|
|
|
|
{
|
|
|
|
|
Location = Global.Config.PceBgViewerSettings.WindowPosition;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Global.Config.PCEBGViewerRefreshRate >= RefreshRate.Minimum && Global.Config.PCEBGViewerRefreshRate <= RefreshRate.Maximum)
|
|
|
|
|
{
|
|
|
|
|
RefreshRate.Value = Global.Config.PCEBGViewerRefreshRate;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
RefreshRate.Value = RefreshRate.Maximum;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RefreshFloatingWindowControl()
|
2012-03-12 05:26:48 +00:00
|
|
|
|
{
|
2014-01-31 23:42:06 +00:00
|
|
|
|
Owner = Global.Config.PceBgViewerSettings.FloatingWindow ? null : GlobalWin.MainForm;
|
|
|
|
|
}
|
2012-03-12 06:27:34 +00:00
|
|
|
|
|
2014-01-31 23:42:06 +00:00
|
|
|
|
#region Public API
|
2012-03-12 06:27:34 +00:00
|
|
|
|
|
2014-01-31 23:42:06 +00:00
|
|
|
|
public bool AskSave() { return true; }
|
|
|
|
|
public bool UpdateBefore { get { return true; } }
|
2012-03-12 05:26:48 +00:00
|
|
|
|
|
2014-01-31 23:42:06 +00:00
|
|
|
|
public unsafe void Generate()
|
|
|
|
|
{
|
|
|
|
|
if (Global.Emulator.Frame % RefreshRate.Value != 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var vdc = _vdcType == 0 ? _pce.VDC1 : _pce.VDC2;
|
|
|
|
|
|
|
|
|
|
var width = 8 * vdc.BatWidth;
|
|
|
|
|
var height = 8 * vdc.BatHeight;
|
|
|
|
|
var buf = canvas.Bat.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, canvas.Bat.PixelFormat);
|
|
|
|
|
var pitch = buf.Stride / 4;
|
|
|
|
|
var begin = (int*)buf.Scan0.ToPointer();
|
2012-03-12 05:26:48 +00:00
|
|
|
|
|
2013-04-15 02:14:14 +00:00
|
|
|
|
int* p = begin;
|
2012-03-12 05:26:48 +00:00
|
|
|
|
for (int y = 0; y < height; ++y)
|
|
|
|
|
{
|
|
|
|
|
int yTile = y / 8;
|
|
|
|
|
int yOfs = y % 8;
|
|
|
|
|
for (int x = 0; x < width; ++x, ++p)
|
|
|
|
|
{
|
|
|
|
|
int xTile = x / 8;
|
|
|
|
|
int xOfs = x % 8;
|
2012-03-12 06:27:34 +00:00
|
|
|
|
int tileNo = vdc.VRAM[(ushort)(((yTile * vdc.BatWidth) + xTile))] & 0x07FF;
|
|
|
|
|
int paletteNo = vdc.VRAM[(ushort)(((yTile * vdc.BatWidth) + xTile))] >> 12;
|
2012-03-12 05:26:48 +00:00
|
|
|
|
int paletteBase = paletteNo * 16;
|
|
|
|
|
|
2012-03-12 06:27:34 +00:00
|
|
|
|
byte c = vdc.PatternBuffer[(tileNo * 64) + (yOfs * 8) + xOfs];
|
2012-03-12 05:26:48 +00:00
|
|
|
|
if (c == 0)
|
2014-01-31 23:42:06 +00:00
|
|
|
|
{
|
2013-11-20 01:37:54 +00:00
|
|
|
|
*p = _pce.VCE.Palette[0];
|
2014-01-31 23:42:06 +00:00
|
|
|
|
}
|
2012-03-12 05:26:48 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2013-11-20 01:37:54 +00:00
|
|
|
|
*p = _pce.VCE.Palette[paletteBase + c];
|
2012-03-12 05:26:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-31 23:42:06 +00:00
|
|
|
|
|
2012-03-12 05:26:48 +00:00
|
|
|
|
p += pitch - width;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-20 01:37:54 +00:00
|
|
|
|
canvas.Bat.UnlockBits(buf);
|
2012-03-12 05:26:48 +00:00
|
|
|
|
canvas.Refresh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Restart()
|
|
|
|
|
{
|
2013-11-02 22:39:23 +00:00
|
|
|
|
if (Global.Emulator is PCEngine)
|
|
|
|
|
{
|
2013-11-20 01:37:54 +00:00
|
|
|
|
_pce = Global.Emulator as PCEngine;
|
2013-11-02 22:39:23 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2012-03-12 05:26:48 +00:00
|
|
|
|
{
|
2013-04-15 02:14:14 +00:00
|
|
|
|
Close();
|
2012-03-12 05:26:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateValues()
|
|
|
|
|
{
|
2013-11-02 22:39:23 +00:00
|
|
|
|
if (Global.Emulator is PCEngine)
|
|
|
|
|
{
|
|
|
|
|
Generate();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
2012-03-12 05:26:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-31 23:42:06 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Events
|
|
|
|
|
|
|
|
|
|
#region Menu
|
|
|
|
|
|
|
|
|
|
private void FileSubMenu_DropDownOpened(object sender, EventArgs e)
|
2012-03-13 02:41:10 +00:00
|
|
|
|
{
|
2014-01-31 23:42:06 +00:00
|
|
|
|
VDC2MenuItem.Enabled = _pce.SystemId == "SGX";
|
|
|
|
|
|
|
|
|
|
VDC1MenuItem.Checked = _vdcType == 0;
|
|
|
|
|
VDC2MenuItem.Checked = _vdcType == 1;
|
2012-03-13 02:41:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-31 23:42:06 +00:00
|
|
|
|
private void VDC1MenuItem_Click(object sender, EventArgs e)
|
2012-03-13 02:41:10 +00:00
|
|
|
|
{
|
2014-01-31 23:42:06 +00:00
|
|
|
|
_vdcType = 0;
|
2012-03-13 02:41:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-31 23:42:06 +00:00
|
|
|
|
private void VDC2MenuItem_Click(object sender, EventArgs e)
|
2012-03-12 05:26:48 +00:00
|
|
|
|
{
|
2014-01-31 23:42:06 +00:00
|
|
|
|
_vdcType = 1;
|
2012-03-12 05:26:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-31 23:42:06 +00:00
|
|
|
|
private void ExitMenuItem_Click(object sender, EventArgs e)
|
2012-03-12 22:05:53 +00:00
|
|
|
|
{
|
2013-04-15 02:14:14 +00:00
|
|
|
|
Close();
|
2012-03-12 22:05:53 +00:00
|
|
|
|
}
|
2012-03-13 02:41:10 +00:00
|
|
|
|
|
2014-01-31 23:42:06 +00:00
|
|
|
|
private void OptionsSubMenu_DropDownOpened(object sender, EventArgs e)
|
2012-03-13 02:41:10 +00:00
|
|
|
|
{
|
2014-01-31 23:42:06 +00:00
|
|
|
|
SaveWindowPositionMenuItem.Checked = Global.Config.PceBgViewerSettings.SaveWindowPosition;
|
|
|
|
|
AutoloadMenuItem.Checked = Global.Config.PCEBGViewerAutoload;
|
|
|
|
|
AlwaysOnTopMenuItem.Checked = Global.Config.PceBgViewerSettings.TopMost;
|
|
|
|
|
FloatingWindowMenuItem.Checked = Global.Config.PceBgViewerSettings.FloatingWindow;
|
2012-03-13 02:41:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-31 23:42:06 +00:00
|
|
|
|
private void AutoloadMenuItem_Click(object sender, EventArgs e)
|
2012-03-13 02:41:10 +00:00
|
|
|
|
{
|
|
|
|
|
Global.Config.PCEBGViewerAutoload ^= true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-31 23:42:06 +00:00
|
|
|
|
private void SaveWindowPositionMenuItem_Click(object sender, EventArgs e)
|
2012-03-13 02:41:10 +00:00
|
|
|
|
{
|
2014-01-31 23:42:06 +00:00
|
|
|
|
Global.Config.PceBgViewerSettings.SaveWindowPosition ^= true;
|
2012-03-13 02:41:10 +00:00
|
|
|
|
}
|
2012-03-16 15:29:05 +00:00
|
|
|
|
|
2014-01-31 23:42:06 +00:00
|
|
|
|
private void AlwaysOnTopMenuItem_Click(object sender, EventArgs e)
|
2012-03-16 15:29:05 +00:00
|
|
|
|
{
|
2014-01-31 23:42:06 +00:00
|
|
|
|
Global.Config.PceBgViewerSettings.TopMost ^= true;
|
|
|
|
|
TopMost = Global.Config.PceBgViewerSettings.TopMost;
|
2012-03-16 15:29:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-31 23:42:06 +00:00
|
|
|
|
private void FloatingWindowMenuItem_Click(object sender, EventArgs e)
|
2012-03-16 15:29:05 +00:00
|
|
|
|
{
|
2014-01-31 23:42:06 +00:00
|
|
|
|
Global.Config.PceBgViewerSettings.FloatingWindow ^= true;
|
|
|
|
|
RefreshFloatingWindowControl();
|
2012-03-16 15:29:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-31 23:42:06 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Dialog and Controls
|
2012-07-13 02:25:45 +00:00
|
|
|
|
|
2014-01-31 23:42:06 +00:00
|
|
|
|
private void Canvas_MouseMove(object sender, MouseEventArgs e)
|
2012-07-13 02:25:45 +00:00
|
|
|
|
{
|
2014-01-31 23:42:06 +00:00
|
|
|
|
var vdc = _vdcType == 0 ? _pce.VDC1 : _pce.VDC2;
|
2012-07-13 02:25:45 +00:00
|
|
|
|
int xTile = e.X / 8;
|
|
|
|
|
int yTile = e.Y / 8;
|
2014-01-31 23:42:06 +00:00
|
|
|
|
int tileNo = vdc.VRAM[(ushort)((yTile * vdc.BatWidth) + xTile)] & 0x07FF;
|
|
|
|
|
int paletteNo = vdc.VRAM[(ushort)((yTile * vdc.BatWidth) + xTile)] >> 12;
|
2012-07-13 02:25:45 +00:00
|
|
|
|
TileIDLabel.Text = tileNo.ToString();
|
2014-01-31 23:42:06 +00:00
|
|
|
|
XYLabel.Text = xTile + ":" + yTile;
|
2012-07-13 02:25:45 +00:00
|
|
|
|
PaletteLabel.Text = paletteNo.ToString();
|
|
|
|
|
}
|
2014-01-31 23:42:06 +00:00
|
|
|
|
|
|
|
|
|
protected override void OnShown(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
RefreshFloatingWindowControl();
|
|
|
|
|
base.OnShown(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#endregion
|
2012-03-12 05:26:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|