From 287c5c61f8c1793e782c87ce5d45cd2f87959178 Mon Sep 17 00:00:00 2001 From: taotao54321 Date: Mon, 12 Mar 2012 06:27:34 +0000 Subject: [PATCH] PCE BG Viewer: Added a dropdown box to select VDC1/VDC2. Now it is automatically updated in 3fps. (this is just a makeshift. PCE core should provide callbacks) --- BizHawk.MultiClient/MainForm.cs | 1 + .../PCEtools/PCEBGViewer.Designer.cs | 16 +++++++- BizHawk.MultiClient/PCEtools/PCEBGViewer.cs | 37 ++++++++++++++----- 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/BizHawk.MultiClient/MainForm.cs b/BizHawk.MultiClient/MainForm.cs index c75d2ac22f..1ab911e8a9 100644 --- a/BizHawk.MultiClient/MainForm.cs +++ b/BizHawk.MultiClient/MainForm.cs @@ -1802,6 +1802,7 @@ namespace BizHawk.MultiClient NESNameTableViewer1.UpdateValues(); NESPPU1.UpdateValues(); PCEBGViewer1.UpdateValues(); + PCEBGViewer1.Generate(); // TODO: just a makeshift. PCE core should provide callbacks. TAStudio1.UpdateValues(); } diff --git a/BizHawk.MultiClient/PCEtools/PCEBGViewer.Designer.cs b/BizHawk.MultiClient/PCEtools/PCEBGViewer.Designer.cs index a16cb4e407..af8167a953 100644 --- a/BizHawk.MultiClient/PCEtools/PCEBGViewer.Designer.cs +++ b/BizHawk.MultiClient/PCEtools/PCEBGViewer.Designer.cs @@ -28,12 +28,22 @@ /// private void InitializeComponent() { + this.vdcComboBox = new System.Windows.Forms.ComboBox(); this.canvas = new BizHawk.MultiClient.PCEBGCanvas(); this.SuspendLayout(); // + // vdcComboBox + // + this.vdcComboBox.FormattingEnabled = true; + this.vdcComboBox.Location = new System.Drawing.Point(13, 13); + this.vdcComboBox.Name = "vdcComboBox"; + this.vdcComboBox.Size = new System.Drawing.Size(121, 20); + this.vdcComboBox.TabIndex = 1; + this.vdcComboBox.SelectedIndexChanged += new System.EventHandler(this.vdcComboBox_SelectedIndexChanged); + // // canvas // - this.canvas.Location = new System.Drawing.Point(12, 12); + this.canvas.Location = new System.Drawing.Point(12, 49); this.canvas.Name = "canvas"; this.canvas.Size = new System.Drawing.Size(1024, 512); this.canvas.TabIndex = 0; @@ -42,7 +52,8 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1056, 549); + this.ClientSize = new System.Drawing.Size(1056, 573); + this.Controls.Add(this.vdcComboBox); this.Controls.Add(this.canvas); this.Name = "PCEBGViewer"; this.ShowIcon = false; @@ -56,5 +67,6 @@ #endregion private PCEBGCanvas canvas; + private System.Windows.Forms.ComboBox vdcComboBox; } } \ No newline at end of file diff --git a/BizHawk.MultiClient/PCEtools/PCEBGViewer.cs b/BizHawk.MultiClient/PCEtools/PCEBGViewer.cs index b473769794..75748377ea 100644 --- a/BizHawk.MultiClient/PCEtools/PCEBGViewer.cs +++ b/BizHawk.MultiClient/PCEtools/PCEBGViewer.cs @@ -18,24 +18,32 @@ namespace BizHawk.MultiClient public PCEBGViewer() { InitializeComponent(); + vdcComboBox.Items.Add("VDC1"); + vdcComboBox.Items.Add("VDC2"); + vdcComboBox.DropDownStyle = ComboBoxStyle.DropDownList; + vdcComboBox.SelectedIndex = 0; Activated += (o, e) => Generate(); } - private unsafe void Generate() + public unsafe void Generate() { if (!this.IsHandleCreated || this.IsDisposed) return; if (pce == null) return; - int width = 8 * pce.VDC1.BatWidth; - int height = 8 * pce.VDC1.BatHeight; + 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; 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(); + //for (int i = 0; i < pitch * buf.Height; ++i, ++p) + // *p = canvas.BackColor.ToArgb(); p = begin; for (int y = 0; y < height; ++y) @@ -46,11 +54,11 @@ namespace BizHawk.MultiClient { int xTile = x / 8; int xOfs = x % 8; - int tileNo = pce.VDC1.VRAM[(ushort)(((yTile * pce.VDC1.BatWidth) + xTile))] & 0x07FF; - int paletteNo = pce.VDC1.VRAM[(ushort)(((yTile * pce.VDC1.BatWidth) + xTile))] >> 12; + int tileNo = vdc.VRAM[(ushort)(((yTile * vdc.BatWidth) + xTile))] & 0x07FF; + int paletteNo = vdc.VRAM[(ushort)(((yTile * vdc.BatWidth) + xTile))] >> 12; int paletteBase = paletteNo * 16; - byte c = pce.VDC1.PatternBuffer[(tileNo * 64) + (yOfs * 8) + xOfs]; + byte c = vdc.PatternBuffer[(tileNo * 64) + (yOfs * 8) + xOfs]; if (c == 0) *p = pce.VCE.Palette[0]; else @@ -67,13 +75,15 @@ namespace BizHawk.MultiClient public void Restart() { + if (!this.IsHandleCreated || this.IsDisposed) return; if (!(Global.Emulator is PCEngine)) { this.Close(); return; } - else - pce = Global.Emulator as PCEngine; + pce = Global.Emulator as PCEngine; + vdcComboBox.SelectedIndex = 0; + vdcComboBox.Enabled = pce.SystemId == "SGX"; } public void UpdateValues() @@ -87,11 +97,18 @@ namespace BizHawk.MultiClient private void PCEBGViewer_Load(object sender, EventArgs e) { pce = Global.Emulator as PCEngine; + vdcComboBox.SelectedIndex = 0; + vdcComboBox.Enabled = pce.SystemId == "SGX"; } private void PCEBGViewer_FormClosed(object sender, FormClosedEventArgs e) { } + + private void vdcComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + Generate(); + } } }