Atari 2600 - Debugger - add trace logging, and show some stats: scanline, vsync, vblank

This commit is contained in:
adelikat 2014-04-20 01:19:33 +00:00
parent 7d5db039c0
commit 54203c00b9
4 changed files with 164 additions and 28 deletions

View File

@ -68,9 +68,15 @@
this.label8 = new System.Windows.Forms.Label();
this.FrameCountBox = new System.Windows.Forms.TextBox();
this.label7 = new System.Windows.Forms.Label();
this.TracerBox = new System.Windows.Forms.GroupBox();
this.TraceView = new BizHawk.Client.EmuHawk.VirtualListView();
this.Script = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.VSyncChexkbox = new System.Windows.Forms.CheckBox();
this.VBlankCheckbox = new System.Windows.Forms.CheckBox();
this.DebuggerMenu.SuspendLayout();
this.RegistersBox.SuspendLayout();
this.CoreInfoBox.SuspendLayout();
this.TracerBox.SuspendLayout();
this.SuspendLayout();
//
// DebuggerMenu
@ -79,7 +85,7 @@
this.FileSubMenu});
this.DebuggerMenu.Location = new System.Drawing.Point(0, 0);
this.DebuggerMenu.Name = "DebuggerMenu";
this.DebuggerMenu.Size = new System.Drawing.Size(534, 24);
this.DebuggerMenu.Size = new System.Drawing.Size(732, 24);
this.DebuggerMenu.TabIndex = 0;
this.DebuggerMenu.Text = "menuStrip1";
//
@ -102,7 +108,7 @@
// StepBtn
//
this.StepBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.StepBtn.Location = new System.Drawing.Point(447, 27);
this.StepBtn.Location = new System.Drawing.Point(645, 27);
this.StepBtn.Name = "StepBtn";
this.StepBtn.Size = new System.Drawing.Size(75, 23);
this.StepBtn.TabIndex = 1;
@ -113,7 +119,7 @@
// ScanlineAdvanceBtn
//
this.ScanlineAdvanceBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.ScanlineAdvanceBtn.Location = new System.Drawing.Point(447, 56);
this.ScanlineAdvanceBtn.Location = new System.Drawing.Point(645, 56);
this.ScanlineAdvanceBtn.Name = "ScanlineAdvanceBtn";
this.ScanlineAdvanceBtn.Size = new System.Drawing.Size(75, 23);
this.ScanlineAdvanceBtn.TabIndex = 2;
@ -124,7 +130,7 @@
// FrameAdvButton
//
this.FrameAdvButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.FrameAdvButton.Location = new System.Drawing.Point(447, 85);
this.FrameAdvButton.Location = new System.Drawing.Point(645, 85);
this.FrameAdvButton.Name = "FrameAdvButton";
this.FrameAdvButton.Size = new System.Drawing.Size(75, 23);
this.FrameAdvButton.TabIndex = 3;
@ -420,6 +426,8 @@
//
// CoreInfoBox
//
this.CoreInfoBox.Controls.Add(this.VBlankCheckbox);
this.CoreInfoBox.Controls.Add(this.VSyncChexkbox);
this.CoreInfoBox.Controls.Add(this.ScanlineBox);
this.CoreInfoBox.Controls.Add(this.label8);
this.CoreInfoBox.Controls.Add(this.FrameCountBox);
@ -465,11 +473,74 @@
this.label7.TabIndex = 0;
this.label7.Text = "Frame:";
//
// TracerBox
//
this.TracerBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.TracerBox.Controls.Add(this.TraceView);
this.TracerBox.Location = new System.Drawing.Point(12, 188);
this.TracerBox.Name = "TracerBox";
this.TracerBox.Size = new System.Drawing.Size(511, 444);
this.TracerBox.TabIndex = 6;
this.TracerBox.TabStop = false;
this.TracerBox.Text = "Trace log";
//
// TraceView
//
this.TraceView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.TraceView.BlazingFast = false;
this.TraceView.CheckBoxes = true;
this.TraceView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.Script});
this.TraceView.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.TraceView.FullRowSelect = true;
this.TraceView.GridLines = true;
this.TraceView.HideSelection = false;
this.TraceView.ItemCount = 0;
this.TraceView.Location = new System.Drawing.Point(8, 18);
this.TraceView.Name = "TraceView";
this.TraceView.SelectAllInProgress = false;
this.TraceView.selectedItem = -1;
this.TraceView.Size = new System.Drawing.Size(497, 414);
this.TraceView.TabIndex = 4;
this.TraceView.TabStop = false;
this.TraceView.UseCompatibleStateImageBehavior = false;
this.TraceView.View = System.Windows.Forms.View.Details;
//
// Script
//
this.Script.Text = "Instructions";
this.Script.Width = 599;
//
// VSyncChexkbox
//
this.VSyncChexkbox.AutoSize = true;
this.VSyncChexkbox.Location = new System.Drawing.Point(9, 63);
this.VSyncChexkbox.Name = "VSyncChexkbox";
this.VSyncChexkbox.Size = new System.Drawing.Size(57, 17);
this.VSyncChexkbox.TabIndex = 4;
this.VSyncChexkbox.Text = "VSync";
this.VSyncChexkbox.UseVisualStyleBackColor = true;
//
// VBlankCheckbox
//
this.VBlankCheckbox.AutoSize = true;
this.VBlankCheckbox.Location = new System.Drawing.Point(9, 80);
this.VBlankCheckbox.Name = "VBlankCheckbox";
this.VBlankCheckbox.Size = new System.Drawing.Size(60, 17);
this.VBlankCheckbox.TabIndex = 5;
this.VBlankCheckbox.Text = "VBlank";
this.VBlankCheckbox.UseVisualStyleBackColor = true;
//
// Atari2600Debugger
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(534, 498);
this.ClientSize = new System.Drawing.Size(732, 702);
this.Controls.Add(this.TracerBox);
this.Controls.Add(this.CoreInfoBox);
this.Controls.Add(this.RegistersBox);
this.Controls.Add(this.FrameAdvButton);
@ -487,6 +558,7 @@
this.RegistersBox.PerformLayout();
this.CoreInfoBox.ResumeLayout(false);
this.CoreInfoBox.PerformLayout();
this.TracerBox.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
@ -533,5 +605,10 @@
private System.Windows.Forms.Label label7;
private System.Windows.Forms.TextBox ScanlineBox;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.GroupBox TracerBox;
private VirtualListView TraceView;
public System.Windows.Forms.ColumnHeader Script;
private System.Windows.Forms.CheckBox VBlankCheckbox;
private System.Windows.Forms.CheckBox VSyncChexkbox;
}
}

View File

@ -15,11 +15,15 @@ namespace BizHawk.Client.EmuHawk
public partial class Atari2600Debugger : Form, IToolForm
{
private Atari2600 _core = Global.Emulator as Atari2600;
private readonly List<string> _instructions = new List<string>();
public Atari2600Debugger()
{
InitializeComponent();
TraceView.QueryItemText += TraceView_QueryItemText;
TraceView.VirtualMode = true;
//TODO: add to Closing a Mainform.ResumeControl() call
}
@ -27,7 +31,7 @@ namespace BizHawk.Client.EmuHawk
{
// TODO: some kind of method like PauseAndRelinquishControl() which will set a flag preventing unpausing by the user, and then a ResumeControl() method that is done on close
GlobalWin.MainForm.PauseEmulator();
Global.CoreComm.Tracer.Enabled = true;
}
public void Restart()
@ -47,36 +51,56 @@ namespace BizHawk.Client.EmuHawk
public void UpdateValues()
{
//var flags = _core.GetCpuFlagsAndRegisters();
//PCRegisterBox.Text = flags["PC"].ToString();
var flags = _core.GetCpuFlagsAndRegisters();
PCRegisterBox.Text = flags["PC"].ToString();
//SPRegisterBox.Text = flags["S"].ToString();
//SPRegisterHexBox.Text = string.Format("{0:X2}", flags["S"]);
//SPRegisterBinaryBox.Text = ToBinStr(flags["S"]);
SPRegisterBox.Text = flags["S"].ToString();
SPRegisterHexBox.Text = string.Format("{0:X2}", flags["S"]);
SPRegisterBinaryBox.Text = ToBinStr(flags["S"]);
//ARegisterBox.Text = flags["A"].ToString();
//ARegisterHexBox.Text = string.Format("{0:X2}", flags["A"]);
//ARegisterBinaryBox.Text = ToBinStr(flags["A"]);
ARegisterBox.Text = flags["A"].ToString();
ARegisterHexBox.Text = string.Format("{0:X2}", flags["A"]);
ARegisterBinaryBox.Text = ToBinStr(flags["A"]);
//XRegisterBox.Text = flags["X"].ToString();
//XRegisterHexBox.Text = string.Format("{0:X2}", flags["X"]);
//XRegisterBinaryBox.Text = ToBinStr(flags["X"]);
XRegisterBox.Text = flags["X"].ToString();
XRegisterHexBox.Text = string.Format("{0:X2}", flags["X"]);
XRegisterBinaryBox.Text = ToBinStr(flags["X"]);
//YRegisterBox.Text = flags["Y"].ToString();
//YRegisterHexBox.Text = string.Format("{0:X2}", flags["Y"]);
//YRegisterBinaryBox.Text = ToBinStr(flags["Y"]);
YRegisterBox.Text = flags["Y"].ToString();
YRegisterHexBox.Text = string.Format("{0:X2}", flags["Y"]);
YRegisterBinaryBox.Text = ToBinStr(flags["Y"]);
//NFlagCheckbox.Checked = flags["Flag N"] == 1;
//VFlagCheckbox.Checked = flags["Flag V"] == 1;
//TFlagCheckbox.Checked = flags["Flag T"] == 1;
//BFlagCheckbox.Checked = flags["Flag B"] == 1;
NFlagCheckbox.Checked = flags["Flag N"] == 1;
VFlagCheckbox.Checked = flags["Flag V"] == 1;
TFlagCheckbox.Checked = flags["Flag T"] == 1;
BFlagCheckbox.Checked = flags["Flag B"] == 1;
//DFlagCheckbox.Checked = flags["Flag D"] == 1;
//IFlagCheckbox.Checked = flags["Flag I"] == 1;
//ZFlagCheckbox.Checked = flags["Flag Z"] == 1;
//CFlagCheckbox.Checked = flags["Flag C"] == 1;
DFlagCheckbox.Checked = flags["Flag D"] == 1;
IFlagCheckbox.Checked = flags["Flag I"] == 1;
ZFlagCheckbox.Checked = flags["Flag Z"] == 1;
CFlagCheckbox.Checked = flags["Flag C"] == 1;
FrameCountBox.Text = _core.Frame.ToString();
ScanlineBox.Text = _core.CurrentScanLine.ToString();
VSyncChexkbox.Checked = _core.IsVsync;
VBlankCheckbox.Checked = _core.IsVBlank;
UpdateTraceLog();
}
private void UpdateTraceLog()
{
var instructions = Global.CoreComm.Tracer.TakeContents().Split('\n');
if (!string.IsNullOrWhiteSpace(instructions[0]))
{
_instructions.AddRange(instructions.Where(str => !string.IsNullOrEmpty(str)));
}
if (_instructions.Count >= Global.Config.TraceLoggerMaxLines)
{
_instructions.RemoveRange(0, _instructions.Count - Global.Config.TraceLoggerMaxLines);
}
TraceView.ItemCount = _instructions.Count;
}
private string ToBinStr(int val)
@ -84,6 +108,11 @@ namespace BizHawk.Client.EmuHawk
return Convert.ToString((uint)val, 2).PadLeft(8, '0');
}
private void TraceView_QueryItemText(int index, int column, out string text)
{
text = index < _instructions.Count ? _instructions[index] : string.Empty;
}
#region Events
private void ExitMenuItem_Click(object sender, EventArgs e)

View File

@ -131,6 +131,21 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
}
};
public int CurrentScanLine
{
get { return _tia.CurrentScanLine; }
}
public bool IsVsync
{
get { return _tia.IsVSync; }
}
public bool IsVBlank
{
get { return _tia.IsVBlank; }
}
public CompactGameInfo GenerateGameDbEntry()
{
return new CompactGameInfo

View File

@ -76,6 +76,21 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
_player1.ScanCnt = 8;
}
public int CurrentScanLine
{
get { return _scanlinesBuffer.Count; }
}
public bool IsVBlank
{
get { return _vblankEnabled; }
}
public bool IsVSync
{
get { return _vsyncEnabled; }
}
public void Reset()
{
_hsyncCnt = 0;