diff --git a/BizHawk.MultiClient/RamWatch.Designer.cs b/BizHawk.MultiClient/RamWatch.Designer.cs index ec57176ba2..f1ccc20d4c 100644 --- a/BizHawk.MultiClient/RamWatch.Designer.cs +++ b/BizHawk.MultiClient/RamWatch.Designer.cs @@ -58,6 +58,7 @@ 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(); this.SuspendLayout(); @@ -69,7 +70,7 @@ this.watchesToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(375, 24); + this.menuStrip1.Size = new System.Drawing.Size(485, 24); this.menuStrip1.TabIndex = 0; this.menuStrip1.Text = "menuStrip1"; // @@ -241,7 +242,7 @@ this.Notes}); this.WatchListView.Location = new System.Drawing.Point(34, 52); this.WatchListView.Name = "WatchListView"; - this.WatchListView.Size = new System.Drawing.Size(307, 403); + this.WatchListView.Size = new System.Drawing.Size(232, 403); this.WatchListView.TabIndex = 1; this.WatchListView.UseCompatibleStateImageBehavior = false; // @@ -253,7 +254,7 @@ this.toolStripButton3}); this.toolStrip1.Location = new System.Drawing.Point(0, 24); this.toolStrip1.Name = "toolStrip1"; - this.toolStrip1.Size = new System.Drawing.Size(375, 25); + this.toolStrip1.Size = new System.Drawing.Size(485, 25); this.toolStrip1.TabIndex = 2; this.toolStrip1.Text = "toolStrip1"; // @@ -297,11 +298,20 @@ // 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.TabIndex = 3; + // // RamWatch // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(375, 467); + this.ClientSize = new System.Drawing.Size(485, 467); + this.Controls.Add(this.listBox1); this.Controls.Add(this.toolStrip1); this.Controls.Add(this.WatchListView); this.Controls.Add(this.menuStrip1); @@ -349,5 +359,6 @@ private System.Windows.Forms.ColumnHeader Address; private System.Windows.Forms.ColumnHeader Value; private System.Windows.Forms.ColumnHeader Notes; + private System.Windows.Forms.ListBox listBox1; } } \ No newline at end of file diff --git a/BizHawk.MultiClient/RamWatch.cs b/BizHawk.MultiClient/RamWatch.cs index a4b804160f..f2beeae407 100644 --- a/BizHawk.MultiClient/RamWatch.cs +++ b/BizHawk.MultiClient/RamWatch.cs @@ -6,11 +6,15 @@ using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; +using System.IO; namespace BizHawk.MultiClient { public partial class RamWatch : Form { + //TODO: Recent files & autoload + //Keep track of changes to watch list in order to prompt the user to save changes + List watchList = new List(); public RamWatch() @@ -18,6 +22,63 @@ namespace BizHawk.MultiClient InitializeComponent(); } + void TempDisplayWatchInTempList(Watch watch) + { + string temp = watch.address + " " + watch.value + " " + watch.notes; + listBox1.Items.Add(temp); + } + + public int HowMany(string str, char c) //Shouldn't something like this exist already? Counts how many times c in in str + { + int count = 0; + for (int x = 0; x < str.Length; x++) + { + if (str[x] == c) + count++; + } + return count; + } + + bool LoadWatchFile(string path) + { + var file = new FileInfo(path); + if (file.Exists == false) return false; + + using (StreamReader sr = file.OpenText()) + { + string s = ""; + string temp = ""; + watchList.Clear(); //Wipe existing list and read from file + while ((s = sr.ReadLine()) != null) + { + //parse each line and add to watchList + + //.wch files from other emulators start with a number representing the number of watch, that line can be discarded here + //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'); + 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; + s = s.Substring(y, s.Length - y - 1); //5 digit value representing the watch position number + } + else if (z != 4) + continue; //If not 4, something is wrong with this line, ignore it + + Watch w = new Watch(); + + temp = s.Substring(0, s.IndexOf('\t')); + + //w.address = int.Parse(temp); + + } + } + + return true; + } + void AddNewWatch() { } @@ -54,7 +115,19 @@ namespace BizHawk.MultiClient private void openToolStripMenuItem_Click(object sender, EventArgs e) { + var ofd = new OpenFileDialog(); + ofd.InitialDirectory = Global.Config.LastRomPath; + ofd.Filter = "Watch Files (*.wch)|*.wch|All Files|*.*"; + ofd.RestoreDirectory = true; + Global.Sound.StopSound(); + var result = ofd.ShowDialog(); + Global.Sound.StartSound(); + if (result != DialogResult.OK) + return; + var file = new FileInfo(ofd.FileName); + Global.Config.LastRomPath = file.DirectoryName; + LoadWatchFile(file.FullName); } private void saveToolStripMenuItem_Click(object sender, EventArgs e) @@ -115,11 +188,27 @@ namespace BizHawk.MultiClient private void RamWatch_Load(object sender, EventArgs e) { Watch watch1 = new Watch(); - watch1.notes = "Test"; + watch1.notes = "Test1"; + watchList.Add(watch1); + Watch watch2 = new Watch(0x00FF, 256, atype.BYTE, asigned.SIGNED, true, "This is a test"); + Watch watch3 = new Watch(0x00FE, 256, atype.BYTE, asigned.SIGNED, true, "This is a test too"); + Watch watch4 = new Watch(0x00FD, 256, atype.BYTE, asigned.SIGNED, true, "Stuff"); + watchList.Add(watch2); + watchList.Add(watch3); + watchList.Add(watch4); + ListViewItem item1 = new ListViewItem(watch1.address.ToString(), 0); WatchListView.Items.Add(item1); - + + item1 = new ListViewItem(watch1.value.ToString(), 0); + WatchListView.Items.Add(item1); + + item1 = new ListViewItem(watch1.notes, 0); + WatchListView.Items.Add(item1); + + for (int x = 0; x < watchList.Count; x++) + TempDisplayWatchInTempList(watchList[x]); } } } diff --git a/BizHawk.MultiClient/Watch.cs b/BizHawk.MultiClient/Watch.cs index e46be7e311..216e4f838b 100644 --- a/BizHawk.MultiClient/Watch.cs +++ b/BizHawk.MultiClient/Watch.cs @@ -16,23 +16,23 @@ namespace BizHawk.MultiClient value = 0; type = atype.BYTE; signed = asigned.SIGNED; - endian = false; + bigendian = false; notes = ""; } - public Watch(int Address, int Value, atype Type, asigned Signed, bool Endian, string Notes) + public Watch(int Address, int Value, atype Type, asigned Signed, bool BigEndian, string Notes) { address = Address; value = Value; type = Type; signed = Signed; - endian = Endian; + bigendian = BigEndian; notes = Notes; } public int address { get; set; } public int value { get; set; } //Current value public atype type { get; set; } //Address type (byte, word, dword, etc public asigned signed { get; set; } //Signed/Unsigned? - public bool endian { get; set; } + public bool bigendian { get; set; } public string notes { get; set; } //User notes } }