From 9d83249ebad818e9d1c2da29102ef450580ba2de Mon Sep 17 00:00:00 2001 From: goyuken Date: Mon, 5 Nov 2012 13:48:19 +0000 Subject: [PATCH] gb gpu view: more stuff --- BizHawk.MultiClient/GBtools/BmpView.cs | 9 ++- .../GBtools/GBGPUView.Designer.cs | 58 +++++++++++++++++-- BizHawk.MultiClient/GBtools/GBGPUView.cs | 49 +++++++++++++++- BizHawk.Util/Win32.cs | 3 + 4 files changed, 110 insertions(+), 9 deletions(-) diff --git a/BizHawk.MultiClient/GBtools/BmpView.cs b/BizHawk.MultiClient/GBtools/BmpView.cs index 5390ff5aba..0b28c777a4 100644 --- a/BizHawk.MultiClient/GBtools/BmpView.cs +++ b/BizHawk.MultiClient/GBtools/BmpView.cs @@ -46,6 +46,13 @@ namespace BizHawk.MultiClient.GBtools return; bmp = new Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); } - + + 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)); + bmp.UnlockBits(lockdata); + Refresh(); + } } } diff --git a/BizHawk.MultiClient/GBtools/GBGPUView.Designer.cs b/BizHawk.MultiClient/GBtools/GBGPUView.Designer.cs index 2f4c4c4a2f..b6bfa0b67e 100644 --- a/BizHawk.MultiClient/GBtools/GBGPUView.Designer.cs +++ b/BizHawk.MultiClient/GBtools/GBGPUView.Designer.cs @@ -32,12 +32,16 @@ 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.SuspendLayout(); // // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(17, 21); + this.label1.Location = new System.Drawing.Point(9, 9); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(22, 13); this.label1.TabIndex = 2; @@ -46,7 +50,7 @@ // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(275, 24); + this.label2.Location = new System.Drawing.Point(271, 9); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(26, 13); this.label2.TabIndex = 3; @@ -55,7 +59,7 @@ // bmpViewWin // this.bmpViewWin.BackColor = System.Drawing.Color.Transparent; - this.bmpViewWin.Location = new System.Drawing.Point(278, 37); + 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; @@ -64,17 +68,57 @@ // bmpViewBG // this.bmpViewBG.BackColor = System.Drawing.Color.Transparent; - this.bmpViewBG.Location = new System.Drawing.Point(12, 37); + 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; + this.label3.Location = new System.Drawing.Point(533, 9); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(38, 13); + this.label3.TabIndex = 8; + this.label3.Text = "Tiles 1"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(667, 9); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(69, 13); + this.label4.TabIndex = 9; + this.label4.Text = "Tiles 2 (CGB)"; + // // GBGPUView // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(564, 404); + this.ClientSize = new System.Drawing.Size(951, 414); + this.Controls.Add(this.label4); + this.Controls.Add(this.label3); + this.Controls.Add(this.bmpViewTiles2); + this.Controls.Add(this.bmpViewTiles1); this.Controls.Add(this.bmpViewWin); this.Controls.Add(this.bmpViewBG); this.Controls.Add(this.label2); @@ -94,5 +138,9 @@ private System.Windows.Forms.Label label2; private BmpView bmpViewBG; private BmpView bmpViewWin; + private BmpView bmpViewTiles1; + private BmpView bmpViewTiles2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label4; } } \ No newline at end of file diff --git a/BizHawk.MultiClient/GBtools/GBGPUView.cs b/BizHawk.MultiClient/GBtools/GBGPUView.cs index b71250a429..955b3ff604 100644 --- a/BizHawk.MultiClient/GBtools/GBGPUView.cs +++ b/BizHawk.MultiClient/GBtools/GBGPUView.cs @@ -16,7 +16,6 @@ namespace BizHawk.MultiClient.GBtools public GBGPUView() { InitializeComponent(); - } public void Restart() @@ -24,10 +23,20 @@ namespace BizHawk.MultiClient.GBtools if (Global.Emulator is Emulation.Consoles.GB.Gameboy) { gb = Global.Emulator as Emulation.Consoles.GB.Gameboy; + if (gb.IsCGBMode()) + label4.Enabled = true; + else + label4.Enabled = false; + bmpViewBG.Clear(); + bmpViewWin.Clear(); + bmpViewTiles1.Clear(); + bmpViewTiles2.Clear(); } else { - this.Close(); + gb = null; + if (Visible) + Close(); } } @@ -162,6 +171,28 @@ namespace BizHawk.MultiClient.GBtools b.UnlockBits(lockdata); } + static unsafe void DrawTiles(Bitmap b, IntPtr _tiles, IntPtr _pal) + { + var lockdata = b.LockBits(new Rectangle(0, 0, 128, 192), 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; + byte* tile = (byte*)_tiles; + + for (int ty = 0; ty < 24; ty++) + { + for (int tx = 0; tx < 16; tx++) + { + DrawTileDMG(tile, dest, pitch, pal); + tile += 16; + dest += 8; + } + dest -= 128; + dest += pitch * 8; + } + b.UnlockBits(lockdata); + } + void ScanlineCallback(IntPtr vram, bool cgb, int lcdc, IntPtr bgpal, IntPtr sppal) { // set alpha on all pixels @@ -176,6 +207,7 @@ namespace BizHawk.MultiClient.GBtools p[i] |= unchecked((int)0xff000000); } + // bg maps if (!cgb) { DrawBGDMG( @@ -210,6 +242,17 @@ namespace BizHawk.MultiClient.GBtools } bmpViewBG.Refresh(); bmpViewWin.Refresh(); + + // tile display + // TODO: user selects palette to use, instead of fixed palette 0 + // or possibly "smart" where, if a tile is in use, it's drawn with one of the palettes actually being used with it? + DrawTiles(bmpViewTiles1.bmp, vram, bgpal); + bmpViewTiles1.Refresh(); + if (cgb) + { + DrawTiles(bmpViewTiles2.bmp, vram + 0x2000, bgpal); + bmpViewTiles2.Refresh(); + } } private void GBGPUView_FormClosed(object sender, FormClosedEventArgs e) @@ -223,7 +266,7 @@ namespace BizHawk.MultiClient.GBtools private void GBGPUView_Load(object sender, EventArgs e) { - gb = Global.Emulator as Emulation.Consoles.GB.Gameboy; + Restart(); } } } diff --git a/BizHawk.Util/Win32.cs b/BizHawk.Util/Win32.cs index 3d8027554d..958b90f388 100644 --- a/BizHawk.Util/Win32.cs +++ b/BizHawk.Util/Win32.cs @@ -439,6 +439,9 @@ namespace BizHawk [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam); + + [DllImport("Kernel32.dll", EntryPoint = "RtlZeroMemory", SetLastError = false)] + public static extern void ZeroMemory(IntPtr dest, uint size); } } \ No newline at end of file