From 49ea0515d814366b65f91c6230bb39e0a7b2dd52 Mon Sep 17 00:00:00 2001 From: "andres.delikat" Date: Wed, 19 Jan 2011 02:49:47 +0000 Subject: [PATCH] Ram Watch - more progress on Open Watch function, reads .wch files in the format of other emulators. Currently the results are garbled, need to fix bugs --- BizHawk.MultiClient/RamWatch.Designer.cs | 34 +++++++++++----------- BizHawk.MultiClient/RamWatch.cs | 33 ++++++++++++++++++++-- BizHawk.MultiClient/Watch.cs | 36 ++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 20 deletions(-) diff --git a/BizHawk.MultiClient/RamWatch.Designer.cs b/BizHawk.MultiClient/RamWatch.Designer.cs index f1ccc20d4c..37ee7fc9c0 100644 --- a/BizHawk.MultiClient/RamWatch.Designer.cs +++ b/BizHawk.MultiClient/RamWatch.Designer.cs @@ -51,13 +51,13 @@ this.moveUpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.moveDownToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.WatchListView = new System.Windows.Forms.ListView(); + this.Address = new System.Windows.Forms.ColumnHeader(); + this.Value = new System.Windows.Forms.ColumnHeader(); + this.Notes = new System.Windows.Forms.ColumnHeader(); this.toolStrip1 = new System.Windows.Forms.ToolStrip(); this.toolStripButton1 = new System.Windows.Forms.ToolStripButton(); this.toolStripButton2 = new System.Windows.Forms.ToolStripButton(); this.toolStripButton3 = new System.Windows.Forms.ToolStripButton(); - this.Address = new System.Windows.Forms.ColumnHeader(); - this.Value = new System.Windows.Forms.ColumnHeader(); - this.Notes = new System.Windows.Forms.ColumnHeader(); this.listBox1 = new System.Windows.Forms.ListBox(); this.menuStrip1.SuspendLayout(); this.toolStrip1.SuspendLayout(); @@ -246,6 +246,19 @@ this.WatchListView.TabIndex = 1; this.WatchListView.UseCompatibleStateImageBehavior = false; // + // Address + // + this.Address.Text = "Address"; + // + // Value + // + this.Value.Text = "Value"; + this.Value.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + // + // Notes + // + this.Notes.Text = "Notes"; + // // toolStrip1 // this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -285,25 +298,12 @@ this.toolStripButton3.Size = new System.Drawing.Size(23, 22); this.toolStripButton3.Text = "toolStripButton3"; // - // Address - // - this.Address.Text = "Address"; - // - // Value - // - this.Value.Text = "Value"; - this.Value.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; - // - // Notes - // - this.Notes.Text = "Notes"; - // // listBox1 // this.listBox1.FormattingEnabled = true; this.listBox1.Location = new System.Drawing.Point(311, 88); this.listBox1.Name = "listBox1"; - this.listBox1.Size = new System.Drawing.Size(120, 95); + this.listBox1.Size = new System.Drawing.Size(120, 355); this.listBox1.TabIndex = 3; // // RamWatch diff --git a/BizHawk.MultiClient/RamWatch.cs b/BizHawk.MultiClient/RamWatch.cs index f2beeae407..bfe67301c3 100644 --- a/BizHawk.MultiClient/RamWatch.cs +++ b/BizHawk.MultiClient/RamWatch.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; +using System.Globalization; namespace BizHawk.MultiClient { @@ -14,6 +15,7 @@ namespace BizHawk.MultiClient { //TODO: Recent files & autoload //Keep track of changes to watch list in order to prompt the user to save changes + //TODO: implement separator feature List watchList = new List(); @@ -22,6 +24,7 @@ namespace BizHawk.MultiClient InitializeComponent(); } + //Debug void TempDisplayWatchInTempList(Watch watch) { string temp = watch.address + " " + watch.value + " " + watch.notes; @@ -41,6 +44,7 @@ namespace BizHawk.MultiClient bool LoadWatchFile(string path) { + int y, z; var file = new FileInfo(path); if (file.Exists == false) return false; @@ -57,11 +61,11 @@ namespace BizHawk.MultiClient //Any properly formatted line couldn't possibly be this short anyway, this also takes care of any garbage lines that might be in a file if (s.Length < 5) continue; - int z = HowMany(s, '\t'); + z = HowMany(s, '\t'); if (z == 5) { //If 5, then this is a .wch file format made from another emulator, the first column (watch position) is not needed here - int y = s.IndexOf('\t') + 1; + y = s.IndexOf('\t') + 1; s = s.Substring(y, s.Length - y - 1); //5 digit value representing the watch position number } else if (z != 4) @@ -70,9 +74,31 @@ namespace BizHawk.MultiClient Watch w = new Watch(); temp = s.Substring(0, s.IndexOf('\t')); + w.address = int.Parse(temp, NumberStyles.HexNumber); - //w.address = int.Parse(temp); + y = s.IndexOf('\t') + 1; + s = s.Substring(y, s.Length - y - 1); //Type + w.SetTypeByChar(s[0]); + y = s.IndexOf('\t') + 1; + s = s.Substring(y, s.Length - y - 1); //Signed + w.SetSignedByChar(s[0]); + + y = s.IndexOf('\t') + 1; + s = s.Substring(y, s.Length - y - 1); //Endian + y = Int16.Parse(s[0].ToString()); + if (y == 0) + w.bigendian = false; + else + w.bigendian = true; + + w.notes = s.Substring(2, s.Length - 2); //User notes + + watchList.Add(w); + + //Debug + for (int x = 0; x < watchList.Count; x++) + TempDisplayWatchInTempList(watchList[x]); } } @@ -207,6 +233,7 @@ namespace BizHawk.MultiClient item1 = new ListViewItem(watch1.notes, 0); WatchListView.Items.Add(item1); + //Debug for (int x = 0; x < watchList.Count; x++) TempDisplayWatchInTempList(watchList[x]); } diff --git a/BizHawk.MultiClient/Watch.cs b/BizHawk.MultiClient/Watch.cs index 216e4f838b..1d861a6253 100644 --- a/BizHawk.MultiClient/Watch.cs +++ b/BizHawk.MultiClient/Watch.cs @@ -34,5 +34,41 @@ namespace BizHawk.MultiClient public asigned signed { get; set; } //Signed/Unsigned? public bool bigendian { get; set; } public string notes { get; set; } //User notes + + public bool SetTypeByChar(char c) //b = byte, w = word, d = dword + { + switch (c) + { + case 'b': + type = atype.BYTE; + return true; + case 'w': + type = atype.WORD; + return true; + case 'd': + type = atype.DWORD; + return true; + default: + return false; + } + } + + public bool SetSignedByChar(char c) //s = signed, u = unsigned, h = hex + { + switch (c) + { + case 's': + signed = asigned.SIGNED; + return true; + case 'u': + signed = asigned.UNSIGNED; + return true; + case 'h': + signed = asigned.HEX; + return true; + default: + return false; + } + } } }