From 247cef6835e2966e320f62e6c8234f20970142c8 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 30 Sep 2012 13:38:37 +0000 Subject: [PATCH] Trace Logger - log to the window only up to the maximum number of lines, ability to set max lines, save window position option, show status and instruction count on window, don't autoload trace logger if core doesn't have it available, close trace logger if switching to a non-traceable core --- BizHawk.MultiClient/MainForm.cs | 8 +- BizHawk.MultiClient/tools/InputPrompt.cs | 6 +- .../tools/TraceLogger.Designer.cs | 60 +++++++++---- BizHawk.MultiClient/tools/TraceLogger.cs | 84 ++++++++++++++++++- 4 files changed, 134 insertions(+), 24 deletions(-) diff --git a/BizHawk.MultiClient/MainForm.cs b/BizHawk.MultiClient/MainForm.cs index 5c6a4d5606..6df958769b 100644 --- a/BizHawk.MultiClient/MainForm.cs +++ b/BizHawk.MultiClient/MainForm.cs @@ -287,7 +287,12 @@ namespace BizHawk.MultiClient if (Global.Config.AutoLoadSNESGraphicsDebugger && Global.Emulator is LibsnesCore) LoadSNESGraphicsDebugger(); if (Global.Config.TraceLoggerAutoLoad) - LoadTraceLogger(); + { + if (Global.Emulator.CoreOutputComm.CpuTraceAvailable) + { + LoadTraceLogger(); + } + } if (Global.Config.MainWndx >= 0 && Global.Config.MainWndy >= 0 && Global.Config.SaveWindowPosition) this.Location = new Point(Global.Config.MainWndx, Global.Config.MainWndy); @@ -1572,6 +1577,7 @@ namespace BizHawk.MultiClient TAStudio1.Restart(); Cheats1.Restart(); ToolBox1.Restart(); + TraceLogger1.Restart(); if (Global.Config.LoadCheatFileByGame) { diff --git a/BizHawk.MultiClient/tools/InputPrompt.cs b/BizHawk.MultiClient/tools/InputPrompt.cs index 90fc91a5bf..ee4bb99596 100644 --- a/BizHawk.MultiClient/tools/InputPrompt.cs +++ b/BizHawk.MultiClient/tools/InputPrompt.cs @@ -77,7 +77,7 @@ namespace BizHawk.MultiClient case InputType.TEXT: break; case InputType.HEX: - if (e.KeyChar == '\b') + if (e.KeyChar == '\b' || e.KeyChar == 22 || e.KeyChar == 1 || e.KeyChar == 3) { return; } @@ -87,7 +87,7 @@ namespace BizHawk.MultiClient } break; case InputType.SIGNED: - if (e.KeyChar == '\b') + if (e.KeyChar == '\b' || e.KeyChar == 22 || e.KeyChar == 1 || e.KeyChar == 3) { return; } @@ -97,7 +97,7 @@ namespace BizHawk.MultiClient } break; case InputType.UNSIGNED: - if (e.KeyChar == '\b') + if (e.KeyChar == '\b' || e.KeyChar == 22 || e.KeyChar == 1 || e.KeyChar == 3) { return; } diff --git a/BizHawk.MultiClient/tools/TraceLogger.Designer.cs b/BizHawk.MultiClient/tools/TraceLogger.Designer.cs index d32d791ac1..841b424096 100644 --- a/BizHawk.MultiClient/tools/TraceLogger.Designer.cs +++ b/BizHawk.MultiClient/tools/TraceLogger.Designer.cs @@ -29,7 +29,7 @@ private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TraceLogger)); - this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.TracerBox = new System.Windows.Forms.GroupBox(); this.TraceView = new BizHawk.VirtualListView(); this.Script = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.menuStrip1 = new System.Windows.Forms.MenuStrip(); @@ -44,23 +44,26 @@ this.ClearButton = new System.Windows.Forms.Button(); this.LoggingEnabled = new System.Windows.Forms.CheckBox(); this.CloseButton = new System.Windows.Forms.Button(); - this.groupBox1.SuspendLayout(); + this.saveWindowPositionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.setMaxWindowLinesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); + this.TracerBox.SuspendLayout(); this.menuStrip1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.SuspendLayout(); // - // groupBox1 + // TracerBox // - this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + 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.groupBox1.Controls.Add(this.TraceView); - this.groupBox1.Location = new System.Drawing.Point(12, 27); - this.groupBox1.Name = "groupBox1"; - this.groupBox1.Size = new System.Drawing.Size(620, 444); - this.groupBox1.TabIndex = 1; - this.groupBox1.TabStop = false; - this.groupBox1.Text = "Trace log"; + this.TracerBox.Controls.Add(this.TraceView); + this.TracerBox.Location = new System.Drawing.Point(12, 27); + this.TracerBox.Name = "TracerBox"; + this.TracerBox.Size = new System.Drawing.Size(620, 444); + this.TracerBox.TabIndex = 1; + this.TracerBox.TabStop = false; + this.TracerBox.Text = "Trace log"; // // TraceView // @@ -138,7 +141,10 @@ // optionsToolStripMenuItem // this.optionsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.autoloadToolStripMenuItem}); + this.setMaxWindowLinesToolStripMenuItem, + this.toolStripSeparator2, + this.autoloadToolStripMenuItem, + this.saveWindowPositionToolStripMenuItem}); this.optionsToolStripMenuItem.Name = "optionsToolStripMenuItem"; this.optionsToolStripMenuItem.Size = new System.Drawing.Size(61, 20); this.optionsToolStripMenuItem.Text = "&Options"; @@ -147,7 +153,7 @@ // autoloadToolStripMenuItem // this.autoloadToolStripMenuItem.Name = "autoloadToolStripMenuItem"; - this.autoloadToolStripMenuItem.Size = new System.Drawing.Size(123, 22); + this.autoloadToolStripMenuItem.Size = new System.Drawing.Size(201, 22); this.autoloadToolStripMenuItem.Text = "&Autoload"; this.autoloadToolStripMenuItem.Click += new System.EventHandler(this.autoloadToolStripMenuItem_Click); // @@ -198,6 +204,25 @@ this.CloseButton.UseVisualStyleBackColor = true; this.CloseButton.Click += new System.EventHandler(this.CloseButton_Click); // + // saveWindowPositionToolStripMenuItem + // + this.saveWindowPositionToolStripMenuItem.Name = "saveWindowPositionToolStripMenuItem"; + this.saveWindowPositionToolStripMenuItem.Size = new System.Drawing.Size(201, 22); + this.saveWindowPositionToolStripMenuItem.Text = "&Save Window Position"; + this.saveWindowPositionToolStripMenuItem.Click += new System.EventHandler(this.saveWindowPositionToolStripMenuItem_Click); + // + // setMaxWindowLinesToolStripMenuItem + // + this.setMaxWindowLinesToolStripMenuItem.Name = "setMaxWindowLinesToolStripMenuItem"; + this.setMaxWindowLinesToolStripMenuItem.Size = new System.Drawing.Size(201, 22); + this.setMaxWindowLinesToolStripMenuItem.Text = "&Set Max Window Lines..."; + this.setMaxWindowLinesToolStripMenuItem.Click += new System.EventHandler(this.setMaxWindowLinesToolStripMenuItem_Click); + // + // toolStripSeparator2 + // + this.toolStripSeparator2.Name = "toolStripSeparator2"; + this.toolStripSeparator2.Size = new System.Drawing.Size(198, 6); + // // TraceLogger // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -206,14 +231,14 @@ this.ClientSize = new System.Drawing.Size(644, 539); this.Controls.Add(this.CloseButton); this.Controls.Add(this.groupBox2); - this.Controls.Add(this.groupBox1); + this.Controls.Add(this.TracerBox); this.Controls.Add(this.menuStrip1); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MainMenuStrip = this.menuStrip1; this.Name = "TraceLogger"; this.Text = "TraceLogger"; this.Load += new System.EventHandler(this.TraceLogger_Load); - this.groupBox1.ResumeLayout(false); + this.TracerBox.ResumeLayout(false); this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); this.groupBox2.ResumeLayout(false); @@ -225,7 +250,7 @@ #endregion - private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.GroupBox TracerBox; private System.Windows.Forms.MenuStrip menuStrip1; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1; private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem; @@ -240,5 +265,8 @@ private VirtualListView TraceView; public System.Windows.Forms.ColumnHeader Script; private System.Windows.Forms.Button CloseButton; + private System.Windows.Forms.ToolStripMenuItem setMaxWindowLinesToolStripMenuItem; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator2; + private System.Windows.Forms.ToolStripMenuItem saveWindowPositionToolStripMenuItem; } } \ No newline at end of file diff --git a/BizHawk.MultiClient/tools/TraceLogger.cs b/BizHawk.MultiClient/tools/TraceLogger.cs index 3ff3964e7a..e3500c1aa5 100644 --- a/BizHawk.MultiClient/tools/TraceLogger.cs +++ b/BizHawk.MultiClient/tools/TraceLogger.cs @@ -27,6 +27,8 @@ namespace BizHawk.MultiClient public void SaveConfigSettings() { Global.CoreInputComm.Tracer.Enabled = false; + Global.Config.TraceLoggerWndx = this.Location.X; + Global.Config.TraceLoggerWndy = this.Location.Y; } private void TraceView_QueryItemBkColor(int index, int column, ref Color color) @@ -48,14 +50,21 @@ namespace BizHawk.MultiClient private void TraceLogger_Load(object sender, EventArgs e) { + if (Global.Config.TraceLoggerSaveWindowPosition && Global.Config.TraceLoggerWndx >= 0 && Global.Config.TraceLoggerWndy >= 0) + { + this.Location = new Point(Global.Config.TraceLoggerWndx, Global.Config.TraceLoggerWndy); + } + ClearList(); LoggingEnabled.Checked = true; Global.CoreInputComm.Tracer.Enabled = true; + SetTracerBoxTitle(); } public void UpdateValues() { DoInstructions(); + SetTracerBoxTitle(); } public void Restart() @@ -66,7 +75,14 @@ namespace BizHawk.MultiClient } else { - ClearList(); + if (Global.Emulator.CoreOutputComm.CpuTraceAvailable) + { + ClearList(); + } + else + { + this.Close(); + } } } @@ -84,6 +100,7 @@ namespace BizHawk.MultiClient private void LoggingEnabled_CheckedChanged(object sender, EventArgs e) { Global.CoreInputComm.Tracer.Enabled = LoggingEnabled.Checked; + SetTracerBoxTitle(); } private void ClearButton_Click(object sender, EventArgs e) @@ -94,11 +111,21 @@ namespace BizHawk.MultiClient private void DoInstructions() { string[] instructions = Global.CoreInputComm.Tracer.TakeContents().Split('\n'); - foreach (string s in instructions) + if (!String.IsNullOrWhiteSpace(instructions[0])) { - Instructions.Add(s); + foreach (string s in instructions) + { + Instructions.Add(s); + } + + if (Instructions.Count >= Global.Config.TraceLoggerMaxLines) + { + int x = Instructions.Count - Global.Config.TraceLoggerMaxLines; + Instructions.RemoveRange(0, x); + } + + TraceView.ItemCount = Instructions.Count; } - TraceView.ItemCount = Instructions.Count; } private void autoloadToolStripMenuItem_Click(object sender, EventArgs e) @@ -109,11 +136,60 @@ namespace BizHawk.MultiClient private void optionsToolStripMenuItem_DropDownOpened(object sender, EventArgs e) { autoloadToolStripMenuItem.Checked = Global.Config.TraceLoggerAutoLoad; + saveWindowPositionToolStripMenuItem.Checked = Global.Config.TraceLoggerSaveWindowPosition; } private void CloseButton_Click(object sender, EventArgs e) { Close(); } + + private void saveWindowPositionToolStripMenuItem_Click(object sender, EventArgs e) + { + Global.Config.TraceLoggerSaveWindowPosition ^= true; + } + + private void setMaxWindowLinesToolStripMenuItem_Click(object sender, EventArgs e) + { + InputPrompt p = new InputPrompt(); + p.SetMessage("Max lines to display in the window"); + p.SetInitialValue(Global.Config.TraceLoggerMaxLines.ToString()); + p.TextInputType = InputPrompt.InputType.UNSIGNED; + DialogResult result = p.ShowDialog(); + if (p.UserOK) + { + int x = int.Parse(p.UserText); + if (x > 0) + { + Global.Config.TraceLoggerMaxLines = x; + } + } + } + + private void SetTracerBoxTitle() + { + if (Global.CoreInputComm.Tracer.Enabled) + { + if (Instructions.Count > 0) + { + TracerBox.Text = "Trace log - logging - " + Instructions.Count.ToString() + " instructions"; + } + else + { + TracerBox.Text = "Trace log - logging..."; + } + } + else + { + if (Instructions.Count > 0) + { + TracerBox.Text = "Trace log - " + Instructions.Count.ToString() + " instructions"; + } + else + { + TracerBox.Text = "Trace log"; + } + } + } } }