2011-03-06 21:41:41 +00:00
|
|
|
|
using System;
|
2011-03-07 02:47:13 +00:00
|
|
|
|
using System.Drawing;
|
2011-03-06 21:41:41 +00:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace BizHawk.MultiClient
|
|
|
|
|
{
|
|
|
|
|
public class MemoryViewer : GroupBox
|
|
|
|
|
{
|
2011-03-07 03:15:16 +00:00
|
|
|
|
//data size variable, and adjust drawing based on it, and a method for parent to set it
|
|
|
|
|
|
2011-03-07 02:47:13 +00:00
|
|
|
|
public VScrollBar vScrollBar1;
|
|
|
|
|
MemoryDomain Domain = new MemoryDomain("NULL", 1, Endian.Little, addr => 0, (a, v) => { });
|
|
|
|
|
Font font = new Font("Courier New", 10);
|
|
|
|
|
Brush regBrush = Brushes.Black;
|
|
|
|
|
int RowsVisible = 0;
|
2011-03-07 03:33:25 +00:00
|
|
|
|
int DataSize = 1;
|
|
|
|
|
string Header = "";
|
2011-03-07 02:47:13 +00:00
|
|
|
|
|
2011-03-06 21:41:41 +00:00
|
|
|
|
public MemoryViewer()
|
|
|
|
|
{
|
|
|
|
|
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
|
|
|
|
SetStyle(ControlStyles.UserPaint, true);
|
|
|
|
|
SetStyle(ControlStyles.DoubleBuffer, true);
|
2011-03-07 03:04:50 +00:00
|
|
|
|
this.Paint += new System.Windows.Forms.PaintEventHandler(this.MemoryViewer_Paint);
|
2011-03-07 02:47:13 +00:00
|
|
|
|
this.vScrollBar1 = new VScrollBar();
|
|
|
|
|
|
|
|
|
|
Point n = new Point(this.Size);
|
2011-03-07 03:04:50 +00:00
|
|
|
|
this.vScrollBar1.Location = new System.Drawing.Point(n.X-18, n.Y-this.Height+7);
|
|
|
|
|
this.vScrollBar1.Height = this.Height-8;
|
2011-03-07 02:47:13 +00:00
|
|
|
|
this.vScrollBar1.Width = 16;
|
|
|
|
|
this.vScrollBar1.Visible = true;
|
|
|
|
|
this.vScrollBar1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
|
|
|
|
| System.Windows.Forms.AnchorStyles.Right)));
|
|
|
|
|
this.vScrollBar1.LargeChange = 16;
|
|
|
|
|
this.vScrollBar1.Name = "vScrollBar1";
|
|
|
|
|
this.vScrollBar1.TabIndex = 0;
|
|
|
|
|
this.vScrollBar1.Scroll += new System.Windows.Forms.ScrollEventHandler(this.vScrollBar1_Scroll);
|
|
|
|
|
|
|
|
|
|
this.Controls.Add(this.vScrollBar1);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 03:04:50 +00:00
|
|
|
|
//protected unsafe override void OnPaint(PaintEventArgs e)
|
|
|
|
|
private void Display(Graphics g)
|
2011-03-07 02:47:13 +00:00
|
|
|
|
{
|
|
|
|
|
unchecked
|
|
|
|
|
{
|
|
|
|
|
int row = 0;
|
|
|
|
|
int rowX = 8;
|
|
|
|
|
int rowY = 16;
|
|
|
|
|
int rowYoffset = 20;
|
2011-03-07 03:15:16 +00:00
|
|
|
|
string rowStr = "";
|
|
|
|
|
int addr = 0;
|
2011-03-07 02:47:13 +00:00
|
|
|
|
|
2011-03-07 03:33:25 +00:00
|
|
|
|
|
2011-03-07 03:04:50 +00:00
|
|
|
|
g.DrawLine(new Pen(regBrush), this.Left + 38, this.Top, this.Left + 38, this.Bottom - 40);
|
|
|
|
|
g.DrawLine(new Pen(regBrush), this.Left, 34, this.Right - 16, 34);
|
2011-03-07 02:47:13 +00:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < RowsVisible; i++)
|
|
|
|
|
{
|
|
|
|
|
row = i + vScrollBar1.Value;
|
|
|
|
|
rowStr = String.Format("{0:X4}", row * 16) + " "; //TODO: num digits based on size of domain
|
2011-03-07 03:33:25 +00:00
|
|
|
|
|
|
|
|
|
switch (DataSize)
|
2011-03-07 02:47:13 +00:00
|
|
|
|
{
|
2011-03-07 03:33:25 +00:00
|
|
|
|
default:
|
|
|
|
|
case 1:
|
|
|
|
|
Header = " 0 1 2 3 4 5 6 7 8 9 A B C D E F"; //TODO: not constant, must deal with bite size
|
|
|
|
|
for (int j = 0; j < 16; j++)
|
|
|
|
|
{
|
|
|
|
|
addr = (row * 16) + j;
|
|
|
|
|
if (addr < Domain.Size)
|
|
|
|
|
rowStr += String.Format("{0:X2}", Domain.PeekByte(addr)) + " "; //TODO: format based on data size
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
break;
|
|
|
|
|
|
2011-03-07 02:47:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 03:33:25 +00:00
|
|
|
|
g.DrawString(Header, font, regBrush, new Point(rowX, rowY));
|
2011-03-07 03:15:16 +00:00
|
|
|
|
if (row * 16 < Domain.Size)
|
|
|
|
|
g.DrawString(rowStr, font, regBrush, new Point(rowX, (rowY * (i + 1)) + rowYoffset));
|
2011-03-07 02:47:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ResetScrollBar()
|
|
|
|
|
{
|
|
|
|
|
vScrollBar1.Value = 0;
|
2011-03-07 03:23:05 +00:00
|
|
|
|
SetUpScrollBar();
|
2011-03-07 02:47:13 +00:00
|
|
|
|
Refresh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetUpScrollBar()
|
|
|
|
|
{
|
|
|
|
|
RowsVisible = this.Height / 16;
|
|
|
|
|
int totalRows = Domain.Size / 16;
|
|
|
|
|
int MaxRows = (totalRows - RowsVisible) + 17;
|
|
|
|
|
|
|
|
|
|
if (MaxRows > 0)
|
|
|
|
|
{
|
|
|
|
|
vScrollBar1.Visible = true;
|
|
|
|
|
if (vScrollBar1.Value > MaxRows)
|
|
|
|
|
vScrollBar1.Value = MaxRows;
|
|
|
|
|
vScrollBar1.Maximum = MaxRows;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
vScrollBar1.Visible = false;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetMemoryDomain(MemoryDomain d)
|
|
|
|
|
{
|
|
|
|
|
Domain = d;
|
|
|
|
|
SetUpScrollBar();
|
|
|
|
|
vScrollBar1.Value = 0;
|
|
|
|
|
Refresh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetMemoryDomainStr()
|
|
|
|
|
{
|
|
|
|
|
return Domain.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.SetUpScrollBar();
|
|
|
|
|
this.Refresh();
|
2011-03-06 21:41:41 +00:00
|
|
|
|
}
|
2011-03-07 03:04:50 +00:00
|
|
|
|
|
|
|
|
|
private void MemoryViewer_Paint(object sender, PaintEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Display(e.Graphics);
|
|
|
|
|
}
|
2011-03-06 21:41:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|