BizHawk/BizHawk.MultiClient/PCEtools/PCEBGViewer.cs

120 lines
3.0 KiB
C#
Raw Normal View History

2012-03-12 05:26:48 +00:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using BizHawk.Emulation.Consoles.TurboGrafx;
namespace BizHawk.MultiClient
{
public partial class PCEBGViewer : Form
{
PCEngine pce;
public PCEBGViewer()
{
InitializeComponent();
vdcComboBox.Items.Add("VDC1");
vdcComboBox.Items.Add("VDC2");
vdcComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
vdcComboBox.SelectedIndex = 0;
2012-03-12 05:26:48 +00:00
Activated += (o, e) => Generate();
}
public unsafe void Generate()
2012-03-12 05:26:48 +00:00
{
if (!this.IsHandleCreated || this.IsDisposed) return;
if (pce == null) return;
if (Global.Emulator.Frame % 20 != 0) return; // TODO: just a makeshift. hard-coded 3fps
VDC vdc = vdcComboBox.SelectedIndex == 0 ? pce.VDC1 : pce.VDC2;
int width = 8 * vdc.BatWidth;
int height = 8 * vdc.BatHeight;
2012-03-12 05:26:48 +00:00
BitmapData buf = canvas.bat.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, canvas.bat.PixelFormat);
int pitch = buf.Stride / 4;
int* begin = (int*)buf.Scan0.ToPointer();
int* p = begin;
// TODO: this does not clear background, why?
//for (int i = 0; i < pitch * buf.Height; ++i, ++p)
// *p = canvas.BackColor.ToArgb();
2012-03-12 05:26:48 +00:00
p = begin;
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;
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;
byte c = vdc.PatternBuffer[(tileNo * 64) + (yOfs * 8) + xOfs];
2012-03-12 05:26:48 +00:00
if (c == 0)
*p = pce.VCE.Palette[0];
else
{
*p = pce.VCE.Palette[paletteBase + c];
}
}
p += pitch - width;
}
canvas.bat.UnlockBits(buf);
canvas.Refresh();
}
public void Restart()
{
if (!this.IsHandleCreated || this.IsDisposed) return;
2012-03-12 05:26:48 +00:00
if (!(Global.Emulator is PCEngine))
{
this.Close();
return;
}
pce = Global.Emulator as PCEngine;
vdcComboBox.SelectedIndex = 0;
vdcComboBox.Enabled = pce.SystemId == "SGX";
2012-03-12 05:26:48 +00:00
}
public void UpdateValues()
{
if (!this.IsHandleCreated || this.IsDisposed) return;
if (!(Global.Emulator is PCEngine)) return;
}
private void PCEBGViewer_Load(object sender, EventArgs e)
{
pce = Global.Emulator as PCEngine;
vdcComboBox.SelectedIndex = 0;
vdcComboBox.Enabled = pce.SystemId == "SGX";
2012-03-12 05:26:48 +00:00
}
private void PCEBGViewer_FormClosed(object sender, FormClosedEventArgs e)
{
}
private void vdcComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
Generate();
}
2012-03-12 22:05:53 +00:00
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
2012-03-12 05:26:48 +00:00
}
}