Some progress on the new Ram Watch dialog
This commit is contained in:
parent
1e8569be97
commit
089ce7f48a
File diff suppressed because it is too large
Load Diff
|
@ -654,6 +654,8 @@ namespace BizHawk.MultiClient
|
|||
traceLoggerToolStripMenuItem.ShortcutKeyDisplayString = Global.Config.HotkeyBindings["Trace Logger"].Bindings;
|
||||
toolBoxToolStripMenuItem.Enabled = !ToolBox1.IsHandleCreated || ToolBox1.IsDisposed;
|
||||
traceLoggerToolStripMenuItem.Enabled = Global.Emulator.CoreComm.CpuTraceAvailable;
|
||||
|
||||
newRamWatchToolStripMenuItem.Visible = MainForm.INTERIM;
|
||||
}
|
||||
|
||||
private void saveSlotToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
|
||||
|
|
|
@ -4179,5 +4179,10 @@ namespace BizHawk.MultiClient
|
|||
{
|
||||
Global.DisplayManager.NeedsToPaint = true;
|
||||
}
|
||||
|
||||
private void newRamWatchToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
new NewRamWatch().Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -6,19 +6,119 @@ using System.Drawing;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.IO;
|
||||
|
||||
namespace BizHawk.MultiClient
|
||||
{
|
||||
public partial class NewRamWatch : Form
|
||||
{
|
||||
public NewRamWatch()
|
||||
private WatchList Watches = new WatchList();
|
||||
private string systemID = "NULL";
|
||||
|
||||
public NewRamWatch()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void NewRamWatch_Load(object sender, EventArgs e)
|
||||
{
|
||||
public bool AskSave()
|
||||
{
|
||||
if (Global.Config.SupressAskSave) //User has elected to not be nagged
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (Watches.Changes)
|
||||
{
|
||||
Global.Sound.StopSound();
|
||||
DialogResult result = MessageBox.Show("Save Changes?", "Ram Watch", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3);
|
||||
Global.Sound.StartSound();
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
Watches.Save();
|
||||
}
|
||||
else if (result == DialogResult.No)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (result == DialogResult.Cancel)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void DisplayWatches()
|
||||
{
|
||||
WatchListView.ItemCount = Watches.ItemCount;
|
||||
}
|
||||
|
||||
private void UpdateWatchCount()
|
||||
{
|
||||
int count = Watches.WatchCount;
|
||||
WatchCountLabel.Text = count.ToString() + (count == 1 ? " watch" : " watches");
|
||||
}
|
||||
|
||||
private void SetMemoryDomain(int pos)
|
||||
{
|
||||
if (pos < Global.Emulator.MemoryDomains.Count) //Sanity check
|
||||
{
|
||||
Watches.Domain = Global.Emulator.MemoryDomains[pos];
|
||||
}
|
||||
SetPlatformAndMemoryDomainLabel();
|
||||
Update();
|
||||
}
|
||||
|
||||
private void SetPlatformAndMemoryDomainLabel()
|
||||
{
|
||||
string memoryDomain = Watches.Domain.ToString();
|
||||
systemID = Global.Emulator.SystemId;
|
||||
MemDomainLabel.Text = systemID + " " + memoryDomain;
|
||||
}
|
||||
|
||||
#region Winform Events
|
||||
|
||||
private void NewRamWatch_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!AskSave())
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
private void openToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var file = WatchCommon.GetFileFromUser(Watches.CurrentFileName);
|
||||
if (file != null)
|
||||
{
|
||||
bool result = true;
|
||||
if (Watches.Changes)
|
||||
{
|
||||
result = AskSave();
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
Watches.Load(file.FullName, false);
|
||||
DisplayWatches();
|
||||
MessageLabel.Text = Path.GetFileNameWithoutExtension(Watches.CurrentFileName);
|
||||
UpdateWatchCount();
|
||||
Global.Config.RecentWatches.Add(Watches.CurrentFileName);
|
||||
SetMemoryDomain(WatchCommon.GetDomainPos(Watches.Domain.ToString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,9 +117,6 @@
|
|||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>231, 17</value>
|
||||
</metadata>
|
||||
|
@ -209,6 +206,9 @@
|
|||
FF7bIVJVZ0N/soPK421UHGstlFvYd/hWecF/Qqf7CR0A5wwgSQA2AAAAAElFTkSuQmCC
|
||||
</value>
|
||||
</data>
|
||||
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
AAABAAEAEBAAAAEACABoBQAAFgAAACgAAAAQAAAAIAAAAAEACAAAAAAAAAAAABMLAAATCwAAAAEAAAAA
|
||||
|
|
|
@ -4,6 +4,7 @@ using System.Globalization;
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
|
||||
namespace BizHawk.MultiClient
|
||||
{
|
||||
|
@ -898,16 +899,19 @@ namespace BizHawk.MultiClient
|
|||
{
|
||||
protected MemoryDomain _domain;
|
||||
|
||||
public abstract int Address { get; }
|
||||
public abstract int Value { get; }
|
||||
public abstract int? Address { get; }
|
||||
public abstract int? Value { get; }
|
||||
|
||||
public abstract string AddressString { get; }
|
||||
public abstract string ValueString { get; }
|
||||
|
||||
public abstract string ToString();
|
||||
|
||||
public enum WatchSize { Byte = 1, Word = 2, DWord = 4 };
|
||||
public enum DisplayType { BYTE, BYTEHEX, WORD, WORDHEX, _12_4_FixedPoint, DWORD, DWORDHEX, _20_12_FixedPoint, _32bit_Float };
|
||||
|
||||
public readonly WatchSize Size;
|
||||
public readonly DisplayType Type;
|
||||
|
||||
public abstract bool IsSeparator();
|
||||
}
|
||||
|
||||
public interface iWatchEntryDetails
|
||||
|
@ -915,29 +919,21 @@ namespace BizHawk.MultiClient
|
|||
int ChangeCount { get; }
|
||||
void ClearChangeCount();
|
||||
|
||||
int Previous { get; }
|
||||
int? Previous { get; }
|
||||
void ResetPrevious();
|
||||
}
|
||||
|
||||
public class ByteWatch : WatchEntryBase
|
||||
{
|
||||
protected int _address;
|
||||
protected int? _address;
|
||||
|
||||
public ByteWatch(MemoryDomain domain, int address)
|
||||
{
|
||||
_address = address;
|
||||
_domain = domain;
|
||||
}
|
||||
|
||||
public override int Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return _domain.PeekByte(_address);
|
||||
}
|
||||
}
|
||||
|
||||
public override int Address
|
||||
|
||||
public override int? Address
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -945,6 +941,37 @@ namespace BizHawk.MultiClient
|
|||
}
|
||||
}
|
||||
|
||||
public override int? Value
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_address.HasValue)
|
||||
{
|
||||
return _domain.PeekByte(_address.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string AddressString
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public override string ValueString
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
switch(Type)
|
||||
|
@ -953,18 +980,23 @@ namespace BizHawk.MultiClient
|
|||
return Value.ToString(); //TODO
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsSeparator()
|
||||
{
|
||||
return !_address.HasValue;
|
||||
}
|
||||
}
|
||||
|
||||
public class DetailedByteWatch : ByteWatch, iWatchEntryDetails
|
||||
{
|
||||
private int _previous;
|
||||
private int? _previous;
|
||||
|
||||
public DetailedByteWatch(MemoryDomain domain, int address) : base(domain, address) { }
|
||||
|
||||
public int ChangeCount { get; private set; }
|
||||
public void ClearChangeCount() { ChangeCount = 0; }
|
||||
|
||||
public int Previous { get { return _previous; } }
|
||||
public int? Previous { get { return _previous; } }
|
||||
public void ResetPrevious()
|
||||
{
|
||||
_previous = Value;
|
||||
|
@ -976,6 +1008,7 @@ namespace BizHawk.MultiClient
|
|||
public enum WatchPrevDef { LastSearch, Original, LastFrame, LastChange };
|
||||
|
||||
private List<WatchEntryBase> _watchList = new List<WatchEntryBase>();
|
||||
private MemoryDomain _domain = null;
|
||||
|
||||
public WatchList() { }
|
||||
|
||||
|
@ -996,5 +1029,225 @@ namespace BizHawk.MultiClient
|
|||
return _watchList[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int WatchCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return _watchList.Count(w => !w.IsSeparator());
|
||||
}
|
||||
}
|
||||
|
||||
public int ItemCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return _watchList.Count;
|
||||
}
|
||||
}
|
||||
|
||||
public string AddressFormatStr
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_domain != null)
|
||||
{
|
||||
return "X" + IntHelpers.GetNumDigits(_domain.Size - 1).ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_watchList.Clear();
|
||||
}
|
||||
|
||||
public MemoryDomain Domain { get { return _domain; } set { _domain = value; } }
|
||||
|
||||
#region File handling logic - probably needs to be its own class
|
||||
|
||||
public string CurrentFileName { get; set; }
|
||||
public bool Changes { get; set; }
|
||||
|
||||
public void Save()
|
||||
{
|
||||
if (!String.IsNullOrWhiteSpace(CurrentFileName))
|
||||
{
|
||||
SaveFile();
|
||||
}
|
||||
else
|
||||
{
|
||||
SaveFileAs();
|
||||
}
|
||||
}
|
||||
|
||||
public void Load(string path, bool append)
|
||||
{
|
||||
bool result = LoadFile(path, append);
|
||||
|
||||
if (result)
|
||||
{
|
||||
if (!append)
|
||||
{
|
||||
CurrentFileName = path;
|
||||
}
|
||||
else
|
||||
{
|
||||
Changes = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveFile()
|
||||
{
|
||||
//TODO
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private void SaveFileAs()
|
||||
{
|
||||
//TODO
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private bool LoadFile(string path, bool append)
|
||||
{
|
||||
string domain = "";
|
||||
var file = new FileInfo(path);
|
||||
if (file.Exists == false) return false;
|
||||
bool isBizHawkWatch = true; //Hack to support .wch files from other emulators
|
||||
bool isOldBizHawkWatch = false;
|
||||
using (StreamReader sr = file.OpenText())
|
||||
{
|
||||
string s;
|
||||
|
||||
if (append == false)
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
while ((s = sr.ReadLine()) != null)
|
||||
{
|
||||
//.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)
|
||||
{
|
||||
isBizHawkWatch = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (s.Length >= 6 && s.Substring(0, 6) == "Domain")
|
||||
{
|
||||
domain = s.Substring(7, s.Length - 7);
|
||||
isBizHawkWatch = true;
|
||||
}
|
||||
|
||||
if (s.Length >= 8 && s.Substring(0, 8) == "SystemID")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int z = StringHelpers.HowMany(s, '\t');
|
||||
int y;
|
||||
if (z == 5)
|
||||
{
|
||||
//If 5, then this is a post 1.0.5 .wch file
|
||||
if (isBizHawkWatch)
|
||||
{
|
||||
//Do nothing here
|
||||
}
|
||||
else
|
||||
{
|
||||
y = s.IndexOf('\t') + 1;
|
||||
s = s.Substring(y, s.Length - y); //5 digit value representing the watch position number
|
||||
}
|
||||
}
|
||||
else if (z == 4)
|
||||
{
|
||||
isOldBizHawkWatch = true;
|
||||
}
|
||||
else //4 is 1.0.5 and earlier
|
||||
{
|
||||
continue; //If not 4, something is wrong with this line, ignore it
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Watch w = new Watch();
|
||||
|
||||
string temp = s.Substring(0, s.IndexOf('\t'));
|
||||
try
|
||||
{
|
||||
w.Address = int.Parse(temp, NumberStyles.HexNumber);
|
||||
}
|
||||
catch
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
y = s.IndexOf('\t') + 1;
|
||||
s = s.Substring(y, s.Length - y); //Type
|
||||
if (!w.SetTypeByChar(s[0]))
|
||||
continue;
|
||||
|
||||
y = s.IndexOf('\t') + 1;
|
||||
s = s.Substring(y, s.Length - y); //Signed
|
||||
if (!w.SetSignedByChar(s[0]))
|
||||
continue;
|
||||
|
||||
y = s.IndexOf('\t') + 1;
|
||||
s = s.Substring(y, s.Length - y); //Endian
|
||||
try
|
||||
{
|
||||
y = Int16.Parse(s[0].ToString());
|
||||
}
|
||||
catch
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (y == 0)
|
||||
{
|
||||
w.BigEndian = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
w.BigEndian = true;
|
||||
}
|
||||
|
||||
if (isBizHawkWatch && !isOldBizHawkWatch)
|
||||
{
|
||||
y = s.IndexOf('\t') + 1;
|
||||
s = s.Substring(y, s.Length - y); //Domain
|
||||
temp = s.Substring(0, s.IndexOf('\t'));
|
||||
w.Domain = Global.Emulator.MemoryDomains[GetDomainPos(temp)];
|
||||
}
|
||||
|
||||
y = s.IndexOf('\t') + 1;
|
||||
w.Notes = s.Substring(y, s.Length - y); //User notes
|
||||
|
||||
//_watchList.Add(w); //TODO: we need a widget factor or something, to manage the logic of what object to use!
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static int GetDomainPos(string name)
|
||||
{
|
||||
//Attempts to find the memory domain by name, if it fails, it defaults to index 0
|
||||
for (int x = 0; x < Global.Emulator.MemoryDomains.Count; x++)
|
||||
{
|
||||
if (Global.Emulator.MemoryDomains[x].Name == name)
|
||||
return x;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,25 @@ namespace BizHawk.MultiClient
|
|||
{
|
||||
public static class WatchCommon
|
||||
{
|
||||
public static bool SaveWchFile(string path, string domain_name, List<Watch> watchList)
|
||||
public static FileInfo GetFileFromUser(string currentFile)
|
||||
{
|
||||
var ofd = new OpenFileDialog();
|
||||
if (currentFile.Length > 0)
|
||||
ofd.FileName = Path.GetFileNameWithoutExtension(currentFile);
|
||||
ofd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.WatchPath, null);
|
||||
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 null;
|
||||
var file = new FileInfo(ofd.FileName);
|
||||
return file;
|
||||
}
|
||||
|
||||
public static bool SaveWchFile(string path, string domain_name, List<Watch> watchList)
|
||||
{
|
||||
using (StreamWriter sw = new StreamWriter(path))
|
||||
{
|
||||
|
|
|
@ -28,4 +28,19 @@ namespace BizHawk
|
|||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: put it in its own file
|
||||
public static class IntHelpers //TODO: a less lame name
|
||||
{
|
||||
public static int GetNumDigits(Int32 i)
|
||||
{
|
||||
//if (i == 0) return 0;
|
||||
//if (i < 0x10) return 1;
|
||||
//if (i < 0x100) return 2;
|
||||
//if (i < 0x1000) return 3; //adelikat: commenting these out because I decided that regardless of domain, 4 digits should be the minimum
|
||||
if (i < 0x10000) return 4;
|
||||
if (i < 0x1000000) return 6;
|
||||
else return 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue