gb gpu view: palettes
This commit is contained in:
parent
821553cda8
commit
1118fded53
|
@ -11,7 +11,8 @@ namespace BizHawk.MultiClient.GBtools
|
|||
{
|
||||
public partial class BmpView : Control
|
||||
{
|
||||
public Bitmap bmp;
|
||||
public Bitmap bmp { get; private set; }
|
||||
bool scaled;
|
||||
|
||||
public BmpView()
|
||||
{
|
||||
|
@ -22,37 +23,49 @@ namespace BizHawk.MultiClient.GBtools
|
|||
SetStyle(ControlStyles.Opaque, true);
|
||||
this.BackColor = Color.Transparent;
|
||||
this.Paint += new PaintEventHandler(BmpView_Paint);
|
||||
this.SizeChanged += new EventHandler(BmpView_SizeChanged);
|
||||
ChangeBitmapSize(1, 1);
|
||||
}
|
||||
|
||||
void BmpView_Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
if (bmp != null)
|
||||
if (scaled)
|
||||
{
|
||||
e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
|
||||
e.Graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
|
||||
e.Graphics.DrawImage(bmp, 0, 0, Width, Height);
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Graphics.DrawImageUnscaled(bmp, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void BmpView_SizeChanged(object sender, EventArgs e)
|
||||
public void ChangeBitmapSize(Size s)
|
||||
{
|
||||
ChangeBitmapSize(s.Width, s.Height);
|
||||
}
|
||||
|
||||
public void ChangeBitmapSize(int w, int h)
|
||||
{
|
||||
if (bmp != null)
|
||||
{
|
||||
bmp.Dispose();
|
||||
bmp = null;
|
||||
}
|
||||
if (Width == 0 || Height == 0)
|
||||
return;
|
||||
bmp = new Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
||||
bmp = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
||||
scaled = !(w == Width && h == Height);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
var lockdata = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
||||
Win32.ZeroMemory(lockdata.Scan0, (uint)(lockdata.Height * lockdata.Stride));
|
||||
//Win32.ZeroMemory(lockdata.Scan0, (uint)(lockdata.Height * lockdata.Stride));
|
||||
Win32.MemSet(lockdata.Scan0, 0xff, (uint)(lockdata.Height * lockdata.Stride));
|
||||
bmp.UnlockBits(lockdata);
|
||||
Refresh();
|
||||
}
|
||||
|
||||
// kill unused props
|
||||
[Browsable(false)]
|
||||
public override Color BackColor { get { return base.BackColor; } set { base.BackColor = value; } }
|
||||
[Browsable(false)]
|
||||
public override string Text { get { return base.Text; } set { base.Text = value; } }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,12 +30,16 @@
|
|||
{
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.bmpViewWin = new BizHawk.MultiClient.GBtools.BmpView();
|
||||
this.bmpViewBG = new BizHawk.MultiClient.GBtools.BmpView();
|
||||
this.bmpViewTiles1 = new BizHawk.MultiClient.GBtools.BmpView();
|
||||
this.bmpViewTiles2 = new BizHawk.MultiClient.GBtools.BmpView();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.label4 = new System.Windows.Forms.Label();
|
||||
this.label5 = new System.Windows.Forms.Label();
|
||||
this.label6 = new System.Windows.Forms.Label();
|
||||
this.bmpViewSPPal = new BizHawk.MultiClient.GBtools.BmpView();
|
||||
this.bmpViewBGPal = new BizHawk.MultiClient.GBtools.BmpView();
|
||||
this.bmpViewTiles2 = new BizHawk.MultiClient.GBtools.BmpView();
|
||||
this.bmpViewTiles1 = new BizHawk.MultiClient.GBtools.BmpView();
|
||||
this.bmpViewWin = new BizHawk.MultiClient.GBtools.BmpView();
|
||||
this.bmpViewBG = new BizHawk.MultiClient.GBtools.BmpView();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// label1
|
||||
|
@ -56,42 +60,6 @@
|
|||
this.label2.TabIndex = 3;
|
||||
this.label2.Text = "Win";
|
||||
//
|
||||
// bmpViewWin
|
||||
//
|
||||
this.bmpViewWin.BackColor = System.Drawing.Color.Transparent;
|
||||
this.bmpViewWin.Location = new System.Drawing.Point(274, 25);
|
||||
this.bmpViewWin.Name = "bmpViewWin";
|
||||
this.bmpViewWin.Size = new System.Drawing.Size(256, 256);
|
||||
this.bmpViewWin.TabIndex = 5;
|
||||
this.bmpViewWin.Text = "bmpView2";
|
||||
//
|
||||
// bmpViewBG
|
||||
//
|
||||
this.bmpViewBG.BackColor = System.Drawing.Color.Transparent;
|
||||
this.bmpViewBG.Location = new System.Drawing.Point(12, 25);
|
||||
this.bmpViewBG.Name = "bmpViewBG";
|
||||
this.bmpViewBG.Size = new System.Drawing.Size(256, 256);
|
||||
this.bmpViewBG.TabIndex = 4;
|
||||
this.bmpViewBG.Text = "bmpView1";
|
||||
//
|
||||
// bmpViewTiles1
|
||||
//
|
||||
this.bmpViewTiles1.BackColor = System.Drawing.Color.Transparent;
|
||||
this.bmpViewTiles1.Location = new System.Drawing.Point(536, 25);
|
||||
this.bmpViewTiles1.Name = "bmpViewTiles1";
|
||||
this.bmpViewTiles1.Size = new System.Drawing.Size(128, 192);
|
||||
this.bmpViewTiles1.TabIndex = 6;
|
||||
this.bmpViewTiles1.Text = "bmpView1";
|
||||
//
|
||||
// bmpViewTiles2
|
||||
//
|
||||
this.bmpViewTiles2.BackColor = System.Drawing.Color.Transparent;
|
||||
this.bmpViewTiles2.Location = new System.Drawing.Point(670, 25);
|
||||
this.bmpViewTiles2.Name = "bmpViewTiles2";
|
||||
this.bmpViewTiles2.Size = new System.Drawing.Size(128, 192);
|
||||
this.bmpViewTiles2.TabIndex = 7;
|
||||
this.bmpViewTiles2.Text = "bmpView2";
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.AutoSize = true;
|
||||
|
@ -110,11 +78,87 @@
|
|||
this.label4.TabIndex = 9;
|
||||
this.label4.Text = "Tiles 2 (CGB)";
|
||||
//
|
||||
// label5
|
||||
//
|
||||
this.label5.AutoSize = true;
|
||||
this.label5.Location = new System.Drawing.Point(533, 220);
|
||||
this.label5.Name = "label5";
|
||||
this.label5.Size = new System.Drawing.Size(63, 13);
|
||||
this.label5.TabIndex = 12;
|
||||
this.label5.Text = "BG Palettes";
|
||||
//
|
||||
// label6
|
||||
//
|
||||
this.label6.AutoSize = true;
|
||||
this.label6.Location = new System.Drawing.Point(667, 220);
|
||||
this.label6.Name = "label6";
|
||||
this.label6.Size = new System.Drawing.Size(72, 13);
|
||||
this.label6.TabIndex = 13;
|
||||
this.label6.Text = "OAM Palettes";
|
||||
//
|
||||
// bmpViewSPPal
|
||||
//
|
||||
this.bmpViewSPPal.BackColor = System.Drawing.Color.Transparent;
|
||||
this.bmpViewSPPal.Location = new System.Drawing.Point(670, 236);
|
||||
this.bmpViewSPPal.Name = "bmpViewSPPal";
|
||||
this.bmpViewSPPal.Size = new System.Drawing.Size(128, 64);
|
||||
this.bmpViewSPPal.TabIndex = 11;
|
||||
this.bmpViewSPPal.Text = "bmpView2";
|
||||
//
|
||||
// bmpViewBGPal
|
||||
//
|
||||
this.bmpViewBGPal.BackColor = System.Drawing.Color.Transparent;
|
||||
this.bmpViewBGPal.Location = new System.Drawing.Point(536, 236);
|
||||
this.bmpViewBGPal.Name = "bmpViewBGPal";
|
||||
this.bmpViewBGPal.Size = new System.Drawing.Size(128, 64);
|
||||
this.bmpViewBGPal.TabIndex = 10;
|
||||
this.bmpViewBGPal.Text = "bmpView1";
|
||||
//
|
||||
// bmpViewTiles2
|
||||
//
|
||||
this.bmpViewTiles2.BackColor = System.Drawing.Color.Transparent;
|
||||
this.bmpViewTiles2.Location = new System.Drawing.Point(670, 25);
|
||||
this.bmpViewTiles2.Name = "bmpViewTiles2";
|
||||
this.bmpViewTiles2.Size = new System.Drawing.Size(128, 192);
|
||||
this.bmpViewTiles2.TabIndex = 7;
|
||||
this.bmpViewTiles2.Text = "bmpView2";
|
||||
//
|
||||
// bmpViewTiles1
|
||||
//
|
||||
this.bmpViewTiles1.BackColor = System.Drawing.Color.Transparent;
|
||||
this.bmpViewTiles1.Location = new System.Drawing.Point(536, 25);
|
||||
this.bmpViewTiles1.Name = "bmpViewTiles1";
|
||||
this.bmpViewTiles1.Size = new System.Drawing.Size(128, 192);
|
||||
this.bmpViewTiles1.TabIndex = 6;
|
||||
this.bmpViewTiles1.Text = "bmpView1";
|
||||
//
|
||||
// bmpViewWin
|
||||
//
|
||||
this.bmpViewWin.BackColor = System.Drawing.Color.Transparent;
|
||||
this.bmpViewWin.Location = new System.Drawing.Point(274, 25);
|
||||
this.bmpViewWin.Name = "bmpViewWin";
|
||||
this.bmpViewWin.Size = new System.Drawing.Size(256, 256);
|
||||
this.bmpViewWin.TabIndex = 5;
|
||||
this.bmpViewWin.Text = "bmpView2";
|
||||
//
|
||||
// bmpViewBG
|
||||
//
|
||||
this.bmpViewBG.BackColor = System.Drawing.Color.Transparent;
|
||||
this.bmpViewBG.Location = new System.Drawing.Point(12, 25);
|
||||
this.bmpViewBG.Name = "bmpViewBG";
|
||||
this.bmpViewBG.Size = new System.Drawing.Size(256, 256);
|
||||
this.bmpViewBG.TabIndex = 4;
|
||||
this.bmpViewBG.Text = "bmpView1";
|
||||
//
|
||||
// GBGPUView
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(951, 414);
|
||||
this.Controls.Add(this.label6);
|
||||
this.Controls.Add(this.label5);
|
||||
this.Controls.Add(this.bmpViewSPPal);
|
||||
this.Controls.Add(this.bmpViewBGPal);
|
||||
this.Controls.Add(this.label4);
|
||||
this.Controls.Add(this.label3);
|
||||
this.Controls.Add(this.bmpViewTiles2);
|
||||
|
@ -142,5 +186,9 @@
|
|||
private BmpView bmpViewTiles2;
|
||||
private System.Windows.Forms.Label label3;
|
||||
private System.Windows.Forms.Label label4;
|
||||
private BmpView bmpViewBGPal;
|
||||
private BmpView bmpViewSPPal;
|
||||
private System.Windows.Forms.Label label5;
|
||||
private System.Windows.Forms.Label label6;
|
||||
}
|
||||
}
|
|
@ -16,6 +16,12 @@ namespace BizHawk.MultiClient.GBtools
|
|||
public GBGPUView()
|
||||
{
|
||||
InitializeComponent();
|
||||
bmpViewBG.ChangeBitmapSize(256, 256);
|
||||
bmpViewWin.ChangeBitmapSize(256, 256);
|
||||
bmpViewTiles1.ChangeBitmapSize(128, 192);
|
||||
bmpViewTiles2.ChangeBitmapSize(128, 192);
|
||||
bmpViewBGPal.ChangeBitmapSize(8, 4);
|
||||
bmpViewSPPal.ChangeBitmapSize(8, 4);
|
||||
}
|
||||
|
||||
public void Restart()
|
||||
|
@ -31,6 +37,8 @@ namespace BizHawk.MultiClient.GBtools
|
|||
bmpViewWin.Clear();
|
||||
bmpViewTiles1.Clear();
|
||||
bmpViewTiles2.Clear();
|
||||
bmpViewBGPal.Clear();
|
||||
bmpViewSPPal.Clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -109,9 +117,6 @@ namespace BizHawk.MultiClient.GBtools
|
|||
|
||||
static unsafe void DrawBGCGB(Bitmap b, IntPtr _map, IntPtr _tiles, bool wrap, IntPtr _pal)
|
||||
{
|
||||
if (b.Width != 256 || b.Height != 256)
|
||||
throw new Exception("GPUView screwed up.");
|
||||
|
||||
var lockdata = b.LockBits(new Rectangle(0, 0, 256, 256), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
||||
byte* map = (byte*)_map;
|
||||
int* dest = (int*)lockdata.Scan0;
|
||||
|
@ -144,9 +149,6 @@ namespace BizHawk.MultiClient.GBtools
|
|||
|
||||
static unsafe void DrawBGDMG(Bitmap b, IntPtr _map, IntPtr _tiles, bool wrap, IntPtr _pal)
|
||||
{
|
||||
if (b.Width != 256 || b.Height != 256)
|
||||
throw new Exception("GPUView screwed up.");
|
||||
|
||||
var lockdata = b.LockBits(new Rectangle(0, 0, 256, 256), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
||||
byte* map = (byte*)_map;
|
||||
int* dest = (int*)lockdata.Scan0;
|
||||
|
@ -193,6 +195,26 @@ namespace BizHawk.MultiClient.GBtools
|
|||
b.UnlockBits(lockdata);
|
||||
}
|
||||
|
||||
static unsafe void DrawPal(Bitmap b, IntPtr _pal)
|
||||
{
|
||||
var lockdata = b.LockBits(new Rectangle(0, 0, 8, 4), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
||||
int* dest = (int*)lockdata.Scan0;
|
||||
int pitch = lockdata.Stride / sizeof(int);
|
||||
int* pal = (int*)_pal;
|
||||
|
||||
for (int px = 0; px < 8; px++)
|
||||
{
|
||||
for (int py = 0; py < 4; py++)
|
||||
{
|
||||
*dest = *pal++;
|
||||
dest += pitch;
|
||||
}
|
||||
dest -= pitch * 4;
|
||||
dest++;
|
||||
}
|
||||
b.UnlockBits(lockdata);
|
||||
}
|
||||
|
||||
void ScanlineCallback(IntPtr vram, bool cgb, int lcdc, IntPtr bgpal, IntPtr sppal)
|
||||
{
|
||||
// set alpha on all pixels
|
||||
|
@ -253,6 +275,11 @@ namespace BizHawk.MultiClient.GBtools
|
|||
DrawTiles(bmpViewTiles2.bmp, vram + 0x2000, bgpal);
|
||||
bmpViewTiles2.Refresh();
|
||||
}
|
||||
|
||||
DrawPal(bmpViewBGPal.bmp, bgpal);
|
||||
DrawPal(bmpViewSPPal.bmp, sppal);
|
||||
bmpViewBGPal.Refresh();
|
||||
bmpViewSPPal.Refresh();
|
||||
}
|
||||
|
||||
private void GBGPUView_FormClosed(object sender, FormClosedEventArgs e)
|
||||
|
|
|
@ -442,6 +442,9 @@ namespace BizHawk
|
|||
|
||||
[DllImport("Kernel32.dll", EntryPoint = "RtlZeroMemory", SetLastError = false)]
|
||||
public static extern void ZeroMemory(IntPtr dest, uint size);
|
||||
|
||||
[DllImport("msvcrt.dll", EntryPoint = "memset", CallingConvention = CallingConvention.Cdecl, SetLastError = false)]
|
||||
public static extern IntPtr MemSet(IntPtr dest, int c, uint count);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue