Column sorting (and reverse sorting) for Ram Search & Ram Watch
This commit is contained in:
parent
fc48e0e4f7
commit
5e27953db0
|
@ -10,203 +10,203 @@ using System.IO;
|
|||
|
||||
namespace BizHawk.MultiClient
|
||||
{
|
||||
public partial class PlayMovie : Form
|
||||
{
|
||||
//TODO: after browse & update, focus on the movie just added, and show stats
|
||||
//This is a modal dialog, implement it as modeless
|
||||
// Option to include subdirectories
|
||||
// Option to include savestate files (that have an input log)
|
||||
//Clicking column headers should sort info
|
||||
//AddMovieToList should check for duplicates and not add them
|
||||
public partial class PlayMovie : Form
|
||||
{
|
||||
//TODO: after browse & update, focus on the movie just added, and show stats
|
||||
//This is a modal dialog, implement it as modeless
|
||||
// Option to include subdirectories
|
||||
// Option to include savestate files (that have an input log)
|
||||
//Clicking column headers should sort info
|
||||
//AddMovieToList should check for duplicates and not add them
|
||||
|
||||
List<Movie> MovieList = new List<Movie>();
|
||||
bool sortReverse;
|
||||
string sortedCol;
|
||||
List<Movie> MovieList = new List<Movie>();
|
||||
bool sortReverse;
|
||||
string sortedCol;
|
||||
|
||||
public PlayMovie()
|
||||
{
|
||||
InitializeComponent();
|
||||
MovieView.QueryItemText += new QueryItemTextHandler(MovieView_QueryItemText);
|
||||
MovieView.QueryItemBkColor += new QueryItemBkColorHandler(MovieView_QueryItemBkColor);
|
||||
MovieView.VirtualMode = true;
|
||||
sortReverse = false;
|
||||
sortedCol = "";
|
||||
}
|
||||
public PlayMovie()
|
||||
{
|
||||
InitializeComponent();
|
||||
MovieView.QueryItemText += new QueryItemTextHandler(MovieView_QueryItemText);
|
||||
MovieView.QueryItemBkColor += new QueryItemBkColorHandler(MovieView_QueryItemBkColor);
|
||||
MovieView.VirtualMode = true;
|
||||
sortReverse = false;
|
||||
sortedCol = "";
|
||||
}
|
||||
|
||||
void MovieView_QueryItemText(int index, int column, out string text)
|
||||
{
|
||||
text = "";
|
||||
if (column == 0) //File
|
||||
text = Path.GetFileName(MovieList[index].GetFilePath());
|
||||
if (column == 1) //System
|
||||
text = MovieList[index].GetSysID();
|
||||
if (column == 2) //Game
|
||||
text = MovieList[index].GetGameName();
|
||||
if (column == 3) //Time
|
||||
text = MovieList[index].GetTime(true);
|
||||
}
|
||||
void MovieView_QueryItemText(int index, int column, out string text)
|
||||
{
|
||||
text = "";
|
||||
if (column == 0) //File
|
||||
text = Path.GetFileName(MovieList[index].GetFilePath());
|
||||
if (column == 1) //System
|
||||
text = MovieList[index].GetSysID();
|
||||
if (column == 2) //Game
|
||||
text = MovieList[index].GetGameName();
|
||||
if (column == 3) //Time
|
||||
text = MovieList[index].GetTime(true);
|
||||
}
|
||||
|
||||
private void MovieView_QueryItemBkColor(int index, int column, ref Color color)
|
||||
{
|
||||
|
||||
}
|
||||
private void MovieView_QueryItemBkColor(int index, int column, ref Color color)
|
||||
{
|
||||
|
||||
private void Cancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
|
||||
private void Run()
|
||||
{
|
||||
Global.MainForm.StartNewMovie(MovieList[MovieView.SelectedIndices[0]], false);
|
||||
}
|
||||
private void Cancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private void OK_Click(object sender, EventArgs e)
|
||||
{
|
||||
Global.MainForm.ReadOnly = ReadOnlyCheckBox.Checked;
|
||||
Run();
|
||||
this.Close();
|
||||
}
|
||||
private void Run()
|
||||
{
|
||||
Global.MainForm.StartNewMovie(MovieList[MovieView.SelectedIndices[0]], false);
|
||||
}
|
||||
|
||||
private void BrowseMovies_Click(object sender, EventArgs e)
|
||||
{
|
||||
OpenFileDialog ofd = new OpenFileDialog();
|
||||
ofd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.MoviesPath, "");
|
||||
ofd.Filter = "Movie files (*.tas)|*.TAS;*.ZIP;*.7z|FCEUX Movies|*.FM2|PCEjin Movies|*.PCE|Archive Files|*.zip;*.7z|All Files|*.*";
|
||||
|
||||
Global.Sound.StopSound();
|
||||
var result = ofd.ShowDialog();
|
||||
Global.Sound.StartSound();
|
||||
if (result == DialogResult.OK)
|
||||
{
|
||||
var file = new FileInfo(ofd.FileName);
|
||||
if (!file.Exists)
|
||||
return;
|
||||
else
|
||||
{
|
||||
AddMovieToList(ofd.FileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void OK_Click(object sender, EventArgs e)
|
||||
{
|
||||
Global.MainForm.ReadOnly = ReadOnlyCheckBox.Checked;
|
||||
Run();
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private void AddMovieToList(string filename)
|
||||
{
|
||||
var file = new HawkFile(filename);
|
||||
if (!file.Exists)
|
||||
return;
|
||||
else
|
||||
{
|
||||
PreLoadMovieFile(file);
|
||||
MovieView.ItemCount = MovieList.Count;
|
||||
UpdateList();
|
||||
MovieView.SelectedIndices.Clear();
|
||||
MovieView.setSelection(MovieList.Count - 1);
|
||||
sortReverse = false;
|
||||
sortedCol = "";
|
||||
}
|
||||
}
|
||||
private void BrowseMovies_Click(object sender, EventArgs e)
|
||||
{
|
||||
OpenFileDialog ofd = new OpenFileDialog();
|
||||
ofd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.MoviesPath, "");
|
||||
ofd.Filter = "Movie files (*.tas)|*.TAS;*.ZIP;*.7z|FCEUX Movies|*.FM2|PCEjin Movies|*.PCE|Archive Files|*.zip;*.7z|All Files|*.*";
|
||||
|
||||
private void PreLoadMovieFile(HawkFile path)
|
||||
{
|
||||
Movie m = new Movie(path.CanonicalFullPath, MOVIEMODE.INACTIVE);
|
||||
m.PreLoadText();
|
||||
//m.LoadMovie();
|
||||
if (path.Extension.ToUpper() == ".FM2")
|
||||
m.SetHeaderLine(MovieHeader.PLATFORM, "NES");
|
||||
else if (path.Extension.ToUpper() == ".MC2")
|
||||
m.SetHeaderLine(MovieHeader.PLATFORM, "PCE");
|
||||
MovieList.Add(m);
|
||||
}
|
||||
Global.Sound.StopSound();
|
||||
var result = ofd.ShowDialog();
|
||||
Global.Sound.StartSound();
|
||||
if (result == DialogResult.OK)
|
||||
{
|
||||
var file = new FileInfo(ofd.FileName);
|
||||
if (!file.Exists)
|
||||
return;
|
||||
else
|
||||
{
|
||||
AddMovieToList(ofd.FileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateList()
|
||||
{
|
||||
MovieView.Refresh();
|
||||
UpdateMovieCount();
|
||||
}
|
||||
private void AddMovieToList(string filename)
|
||||
{
|
||||
var file = new HawkFile(filename);
|
||||
if (!file.Exists)
|
||||
return;
|
||||
else
|
||||
{
|
||||
PreLoadMovieFile(file);
|
||||
MovieView.ItemCount = MovieList.Count;
|
||||
UpdateList();
|
||||
MovieView.SelectedIndices.Clear();
|
||||
MovieView.setSelection(MovieList.Count - 1);
|
||||
sortReverse = false;
|
||||
sortedCol = "";
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateMovieCount()
|
||||
{
|
||||
int x = MovieList.Count;
|
||||
if (x == 1)
|
||||
MovieCount.Text = x.ToString() + " movie";
|
||||
else
|
||||
MovieCount.Text = x.ToString() + " movies";
|
||||
}
|
||||
private void PreLoadMovieFile(HawkFile path)
|
||||
{
|
||||
Movie m = new Movie(path.CanonicalFullPath, MOVIEMODE.INACTIVE);
|
||||
m.PreLoadText();
|
||||
//m.LoadMovie();
|
||||
if (path.Extension.ToUpper() == ".FM2")
|
||||
m.SetHeaderLine(MovieHeader.PLATFORM, "NES");
|
||||
else if (path.Extension.ToUpper() == ".MC2")
|
||||
m.SetHeaderLine(MovieHeader.PLATFORM, "PCE");
|
||||
MovieList.Add(m);
|
||||
}
|
||||
|
||||
private void PlayMovie_Load(object sender, EventArgs e)
|
||||
{
|
||||
string d = PathManager.MakeAbsolutePath(Global.Config.MoviesPath, "");
|
||||
if (!Directory.Exists(d))
|
||||
Directory.CreateDirectory(d);
|
||||
foreach (string f in Directory.GetFiles(d, "*.tas"))
|
||||
AddMovieToList(f);
|
||||
foreach (string f in Directory.GetFiles(d, "*.fm2"))
|
||||
AddMovieToList(f);
|
||||
foreach (string f in Directory.GetFiles(d, "*.mc2"))
|
||||
AddMovieToList(f);
|
||||
}
|
||||
private void UpdateList()
|
||||
{
|
||||
MovieView.Refresh();
|
||||
UpdateMovieCount();
|
||||
}
|
||||
|
||||
private void MovieView_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
DetailsView.Items.Clear();
|
||||
int x = MovieView.SelectedIndices[0];
|
||||
Dictionary<string, string> h = MovieList[x].GetHeaderInfo();
|
||||
|
||||
foreach (var kvp in h)
|
||||
{
|
||||
ListViewItem item = new ListViewItem(kvp.Key);
|
||||
item.SubItems.Add(kvp.Value);
|
||||
DetailsView.Items.Add(item);
|
||||
}
|
||||
}
|
||||
private void UpdateMovieCount()
|
||||
{
|
||||
int x = MovieList.Count;
|
||||
if (x == 1)
|
||||
MovieCount.Text = x.ToString() + " movie";
|
||||
else
|
||||
MovieCount.Text = x.ToString() + " movies";
|
||||
}
|
||||
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
//TODO: a comments viewer/editor
|
||||
}
|
||||
private void PlayMovie_Load(object sender, EventArgs e)
|
||||
{
|
||||
string d = PathManager.MakeAbsolutePath(Global.Config.MoviesPath, "");
|
||||
if (!Directory.Exists(d))
|
||||
Directory.CreateDirectory(d);
|
||||
foreach (string f in Directory.GetFiles(d, "*.tas"))
|
||||
AddMovieToList(f);
|
||||
foreach (string f in Directory.GetFiles(d, "*.fm2"))
|
||||
AddMovieToList(f);
|
||||
foreach (string f in Directory.GetFiles(d, "*.mc2"))
|
||||
AddMovieToList(f);
|
||||
}
|
||||
|
||||
private void button2_Click(object sender, EventArgs e)
|
||||
{
|
||||
//TODO: a subtitle viewer/editor
|
||||
}
|
||||
private void MovieView_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
DetailsView.Items.Clear();
|
||||
int x = MovieView.SelectedIndices[0];
|
||||
Dictionary<string, string> h = MovieList[x].GetHeaderInfo();
|
||||
|
||||
private void MovieView_DoubleClick(object sender, EventArgs e)
|
||||
{
|
||||
Run();
|
||||
this.Close();
|
||||
}
|
||||
foreach (var kvp in h)
|
||||
{
|
||||
ListViewItem item = new ListViewItem(kvp.Key);
|
||||
item.SubItems.Add(kvp.Value);
|
||||
DetailsView.Items.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void MovieView_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop) ? DragDropEffects.Copy : DragDropEffects.None; string[] filePaths = (string[])e.Data.GetData(DataFormats.FileDrop);
|
||||
}
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
//TODO: a comments viewer/editor
|
||||
}
|
||||
|
||||
private void MovieView_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
string[] filePaths = (string[])e.Data.GetData(DataFormats.FileDrop);
|
||||
foreach (string path in filePaths)
|
||||
{
|
||||
if (Path.GetExtension(path) == ".tas" || Path.GetExtension(path) == ".fm2" ||
|
||||
Path.GetExtension(path) == ".mc2")
|
||||
AddMovieToList(path);
|
||||
}
|
||||
}
|
||||
private void button2_Click(object sender, EventArgs e)
|
||||
{
|
||||
//TODO: a subtitle viewer/editor
|
||||
}
|
||||
|
||||
private void MovieView_ColumnClick(object sender, ColumnClickEventArgs e)
|
||||
{
|
||||
OrderColumn(e.Column);
|
||||
}
|
||||
private void MovieView_DoubleClick(object sender, EventArgs e)
|
||||
{
|
||||
Run();
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private void OrderColumn(int columnToOrder)
|
||||
{
|
||||
string columnName = MovieView.Columns[columnToOrder].Text;
|
||||
if (sortedCol.CompareTo(columnName) != 0)
|
||||
sortReverse = false;
|
||||
MovieList.Sort((x, y) => x.CompareTo(y, columnName) * (sortReverse ? -1 : 1));
|
||||
sortedCol = columnName;
|
||||
sortReverse = !(sortReverse);
|
||||
MovieView.Refresh();
|
||||
}
|
||||
private void MovieView_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop) ? DragDropEffects.Copy : DragDropEffects.None; string[] filePaths = (string[])e.Data.GetData(DataFormats.FileDrop);
|
||||
}
|
||||
|
||||
}
|
||||
private void MovieView_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
string[] filePaths = (string[])e.Data.GetData(DataFormats.FileDrop);
|
||||
foreach (string path in filePaths)
|
||||
{
|
||||
if (Path.GetExtension(path) == ".tas" || Path.GetExtension(path) == ".fm2" ||
|
||||
Path.GetExtension(path) == ".mc2")
|
||||
AddMovieToList(path);
|
||||
}
|
||||
}
|
||||
|
||||
private void MovieView_ColumnClick(object sender, ColumnClickEventArgs e)
|
||||
{
|
||||
OrderColumn(e.Column);
|
||||
}
|
||||
|
||||
private void OrderColumn(int columnToOrder)
|
||||
{
|
||||
string columnName = MovieView.Columns[columnToOrder].Text;
|
||||
if (sortedCol.CompareTo(columnName) != 0)
|
||||
sortReverse = false;
|
||||
MovieList.Sort((x, y) => x.CompareTo(y, columnName) * (sortReverse ? -1 : 1));
|
||||
sortedCol = columnName;
|
||||
sortReverse = !(sortReverse);
|
||||
MovieView.Refresh();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -361,28 +361,28 @@
|
|||
this.showChangeCountsToolStripMenuItem.Checked = true;
|
||||
this.showChangeCountsToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
|
||||
this.showChangeCountsToolStripMenuItem.Name = "showChangeCountsToolStripMenuItem";
|
||||
this.showChangeCountsToolStripMenuItem.Size = new System.Drawing.Size(206, 22);
|
||||
this.showChangeCountsToolStripMenuItem.Size = new System.Drawing.Size(203, 22);
|
||||
this.showChangeCountsToolStripMenuItem.Text = "Change Counts";
|
||||
this.showChangeCountsToolStripMenuItem.Click += new System.EventHandler(this.showChangeCountsToolStripMenuItem_Click);
|
||||
//
|
||||
// showPreviousValueToolStripMenuItem
|
||||
//
|
||||
this.showPreviousValueToolStripMenuItem.Name = "showPreviousValueToolStripMenuItem";
|
||||
this.showPreviousValueToolStripMenuItem.Size = new System.Drawing.Size(206, 22);
|
||||
this.showPreviousValueToolStripMenuItem.Size = new System.Drawing.Size(203, 22);
|
||||
this.showPreviousValueToolStripMenuItem.Text = "Previous Value";
|
||||
this.showPreviousValueToolStripMenuItem.Click += new System.EventHandler(this.showPreviousValueToolStripMenuItem_Click);
|
||||
//
|
||||
// prevValueShowsChangeAmountToolStripMenuItem
|
||||
//
|
||||
this.prevValueShowsChangeAmountToolStripMenuItem.Name = "prevValueShowsChangeAmountToolStripMenuItem";
|
||||
this.prevValueShowsChangeAmountToolStripMenuItem.Size = new System.Drawing.Size(206, 22);
|
||||
this.prevValueShowsChangeAmountToolStripMenuItem.Size = new System.Drawing.Size(203, 22);
|
||||
this.prevValueShowsChangeAmountToolStripMenuItem.Text = "Prev Value as change";
|
||||
this.prevValueShowsChangeAmountToolStripMenuItem.Click += new System.EventHandler(this.prevValueShowsChangeAmountToolStripMenuItem_Click);
|
||||
//
|
||||
// toolStripSeparator7
|
||||
//
|
||||
this.toolStripSeparator7.Name = "toolStripSeparator7";
|
||||
this.toolStripSeparator7.Size = new System.Drawing.Size(203, 6);
|
||||
this.toolStripSeparator7.Size = new System.Drawing.Size(200, 6);
|
||||
//
|
||||
// restoreWindowSizeToolStripMenuItem
|
||||
//
|
||||
|
@ -416,6 +416,7 @@
|
|||
this.WatchListView.TabIndex = 1;
|
||||
this.WatchListView.UseCompatibleStateImageBehavior = false;
|
||||
this.WatchListView.View = System.Windows.Forms.View.Details;
|
||||
this.WatchListView.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.WatchListView_ColumnClick);
|
||||
this.WatchListView.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.WatchListView_MouseDoubleClick);
|
||||
this.WatchListView.ColumnReordered += new System.Windows.Forms.ColumnReorderedEventHandler(this.ColumnReorder);
|
||||
this.WatchListView.AfterLabelEdit += new System.Windows.Forms.LabelEditEventHandler(this.WatchListView_AfterLabelEdit);
|
||||
|
|
|
@ -17,8 +17,8 @@ namespace BizHawk.MultiClient
|
|||
public partial class RamWatch : Form
|
||||
{
|
||||
//TODO:
|
||||
//Restore window size should restore column order as well
|
||||
//When receiving a watch from a different domain, should something be done?
|
||||
//when sorting, "Prev as Change" option not taken into account
|
||||
|
||||
int defaultWidth; //For saving the default size of the dialog, so the user can restore if desired
|
||||
int defaultHeight;
|
||||
|
@ -35,6 +35,9 @@ namespace BizHawk.MultiClient
|
|||
bool changes = false;
|
||||
List<ToolStripMenuItem> domainMenuItems = new List<ToolStripMenuItem>();
|
||||
|
||||
string sortedCol;
|
||||
bool sortReverse;
|
||||
|
||||
public void Restart()
|
||||
{
|
||||
if (!this.IsHandleCreated || this.IsDisposed) return;
|
||||
|
@ -132,6 +135,8 @@ namespace BizHawk.MultiClient
|
|||
WatchListView.QueryItemBkColor += new QueryItemBkColorHandler(WatchListView_QueryItemBkColor);
|
||||
WatchListView.VirtualMode = true;
|
||||
Closing += (o, e) => SaveConfigSettings();
|
||||
sortReverse = false;
|
||||
sortedCol = "";
|
||||
}
|
||||
|
||||
protected override void OnClosing(CancelEventArgs e)
|
||||
|
@ -312,6 +317,8 @@ namespace BizHawk.MultiClient
|
|||
currentWatchFile = "";
|
||||
changes = false;
|
||||
MessageLabel.Text = "";
|
||||
sortReverse = false;
|
||||
sortedCol = "";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1376,5 +1383,21 @@ namespace BizHawk.MultiClient
|
|||
i++;
|
||||
} while (columnHeaders.Count() > 0);
|
||||
}
|
||||
|
||||
private void OrderColumn(int columnToOrder)
|
||||
{
|
||||
string columnName = WatchListView.Columns[columnToOrder].Text;
|
||||
if (sortedCol.CompareTo(columnName) != 0)
|
||||
sortReverse = false;
|
||||
watchList.Sort((x, y) => x.CompareTo(y, columnName));//* (sortReverse ? -1 : 1));
|
||||
//sortedCol = columnName;
|
||||
//sortReverse = !(sortReverse);
|
||||
WatchListView.Refresh();
|
||||
}
|
||||
|
||||
private void WatchListView_ColumnClick(object sender, ColumnClickEventArgs e)
|
||||
{
|
||||
OrderColumn(e.Column);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,230 +5,383 @@ using System.Text;
|
|||
|
||||
namespace BizHawk.MultiClient
|
||||
{
|
||||
public enum atype { BYTE, WORD, DWORD, SEPARATOR }; //TODO: more custom types too like 12.4 and 24.12 fixed point
|
||||
public enum asigned { SIGNED, UNSIGNED, HEX };
|
||||
public enum atype { BYTE, WORD, DWORD, SEPARATOR }; //TODO: more custom types too like 12.4 and 24.12 fixed point
|
||||
public enum asigned { SIGNED, UNSIGNED, HEX };
|
||||
|
||||
/// <summary>
|
||||
/// An object that represent a ram address and related properties
|
||||
/// </summary>
|
||||
public class Watch
|
||||
{
|
||||
public Watch()
|
||||
{
|
||||
address = 0;
|
||||
value = 0;
|
||||
type = atype.BYTE;
|
||||
signed = asigned.UNSIGNED;
|
||||
bigendian = true;
|
||||
notes = "";
|
||||
changecount = 0;
|
||||
prev = 0;
|
||||
}
|
||||
/// <summary>
|
||||
/// An object that represent a ram address and related properties
|
||||
/// </summary>
|
||||
public class Watch
|
||||
{
|
||||
public Watch()
|
||||
{
|
||||
address = 0;
|
||||
value = 0;
|
||||
type = atype.BYTE;
|
||||
signed = asigned.UNSIGNED;
|
||||
bigendian = true;
|
||||
notes = "";
|
||||
changecount = 0;
|
||||
prev = 0;
|
||||
}
|
||||
|
||||
public Watch(Watch w)
|
||||
{
|
||||
address = w.address;
|
||||
value = w.value;
|
||||
type = w.type;
|
||||
signed = w.signed;
|
||||
bigendian = w.bigendian;
|
||||
notes = w.notes;
|
||||
changecount = w.changecount;
|
||||
prev = w.prev;
|
||||
}
|
||||
public Watch(Watch w)
|
||||
{
|
||||
address = w.address;
|
||||
value = w.value;
|
||||
type = w.type;
|
||||
signed = w.signed;
|
||||
bigendian = w.bigendian;
|
||||
notes = w.notes;
|
||||
changecount = w.changecount;
|
||||
prev = w.prev;
|
||||
}
|
||||
|
||||
public Watch(int Address, int Value, atype Type, asigned Signed, bool BigEndian, string Notes)
|
||||
{
|
||||
address = Address;
|
||||
value = Value;
|
||||
type = Type;
|
||||
signed = Signed;
|
||||
bigendian = BigEndian;
|
||||
notes = Notes;
|
||||
changecount = 0;
|
||||
prev = 0;
|
||||
}
|
||||
public int address { get; set; }
|
||||
public int value { get; set; } //Current value
|
||||
public int prev { get; set; }
|
||||
public atype type { get; set; } //Address type (byte, word, dword, etc
|
||||
public asigned signed { get; set; } //Signed/Unsigned?
|
||||
public bool bigendian { get; set; }
|
||||
public string notes { get; set; } //User notes
|
||||
public int changecount { get; set; }
|
||||
|
||||
public Watch(int Address, int Value, atype Type, asigned Signed, bool BigEndian, string Notes)
|
||||
{
|
||||
address = Address;
|
||||
value = Value;
|
||||
type = Type;
|
||||
signed = Signed;
|
||||
bigendian = BigEndian;
|
||||
notes = Notes;
|
||||
changecount = 0;
|
||||
prev = 0;
|
||||
}
|
||||
public int address { get; set; }
|
||||
public int value { get; set; } //Current value
|
||||
public int prev { get; set; }
|
||||
public atype type { get; set; } //Address type (byte, word, dword, etc
|
||||
public asigned signed { get; set; } //Signed/Unsigned?
|
||||
public bool bigendian { get; set; }
|
||||
public string notes { get; set; } //User notes
|
||||
public int changecount { get; set; }
|
||||
|
||||
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;
|
||||
case 'S':
|
||||
type = atype.SEPARATOR;
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public char GetTypeByChar()
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case atype.BYTE:
|
||||
return 'b';
|
||||
case atype.WORD:
|
||||
return 'w';
|
||||
case atype.DWORD:
|
||||
return 'd';
|
||||
case atype.SEPARATOR:
|
||||
return 'S';
|
||||
default:
|
||||
return 'b'; //Just in case
|
||||
}
|
||||
}
|
||||
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;
|
||||
case 'S':
|
||||
type = atype.SEPARATOR;
|
||||
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;
|
||||
}
|
||||
}
|
||||
public char GetTypeByChar()
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case atype.BYTE:
|
||||
return 'b';
|
||||
case atype.WORD:
|
||||
return 'w';
|
||||
case atype.DWORD:
|
||||
return 'd';
|
||||
case atype.SEPARATOR:
|
||||
return 'S';
|
||||
default:
|
||||
return 'b'; //Just in case
|
||||
}
|
||||
}
|
||||
|
||||
public char GetSignedByChar()
|
||||
{
|
||||
switch (signed)
|
||||
{
|
||||
case asigned.SIGNED:
|
||||
return 's';
|
||||
case asigned.UNSIGNED:
|
||||
return 'u';
|
||||
case asigned.HEX:
|
||||
return 'h';
|
||||
default:
|
||||
return 's'; //Just in case
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
private void PeekByte(MemoryDomain domain)
|
||||
{
|
||||
value = domain.PeekByte(address);
|
||||
}
|
||||
public char GetSignedByChar()
|
||||
{
|
||||
switch (signed)
|
||||
{
|
||||
case asigned.SIGNED:
|
||||
return 's';
|
||||
case asigned.UNSIGNED:
|
||||
return 'u';
|
||||
case asigned.HEX:
|
||||
return 'h';
|
||||
default:
|
||||
return 's'; //Just in case
|
||||
}
|
||||
}
|
||||
|
||||
private int PeekWord(MemoryDomain domain, int addr)
|
||||
{
|
||||
int temp = 0;
|
||||
if (bigendian)
|
||||
{
|
||||
temp = ((domain.PeekByte(addr) * 256) +
|
||||
domain.PeekByte(addr + 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
temp = ((domain.PeekByte(addr) +
|
||||
domain.PeekByte(addr + 1) * 256));
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
private void PeekByte(MemoryDomain domain)
|
||||
{
|
||||
value = domain.PeekByte(address);
|
||||
}
|
||||
|
||||
private void PeekDWord(MemoryDomain domain)
|
||||
{
|
||||
value = ((PeekWord(domain, address) * 65536) +
|
||||
PeekWord(domain, address + 2));
|
||||
}
|
||||
private int PeekWord(MemoryDomain domain, int addr)
|
||||
{
|
||||
int temp = 0;
|
||||
if (bigendian)
|
||||
{
|
||||
temp = ((domain.PeekByte(addr) * 256) +
|
||||
domain.PeekByte(addr + 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
temp = ((domain.PeekByte(addr) +
|
||||
domain.PeekByte(addr + 1) * 256));
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
public void PeekAddress(MemoryDomain domain)
|
||||
{
|
||||
if (type == atype.SEPARATOR)
|
||||
return;
|
||||
private void PeekDWord(MemoryDomain domain)
|
||||
{
|
||||
value = ((PeekWord(domain, address) * 65536) +
|
||||
PeekWord(domain, address + 2));
|
||||
}
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case atype.BYTE:
|
||||
PeekByte(domain);
|
||||
break;
|
||||
case atype.WORD:
|
||||
value = PeekWord(domain, address);
|
||||
break;
|
||||
case atype.DWORD:
|
||||
PeekDWord(domain);
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void PeekAddress(MemoryDomain domain)
|
||||
{
|
||||
if (type == atype.SEPARATOR)
|
||||
return;
|
||||
|
||||
private void PokeByte(MemoryDomain domain)
|
||||
{
|
||||
domain.PokeByte(address, (byte)value);
|
||||
}
|
||||
switch (type)
|
||||
{
|
||||
case atype.BYTE:
|
||||
PeekByte(domain);
|
||||
break;
|
||||
case atype.WORD:
|
||||
value = PeekWord(domain, address);
|
||||
break;
|
||||
case atype.DWORD:
|
||||
PeekDWord(domain);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void PokeWord(MemoryDomain domain)
|
||||
{
|
||||
if (bigendian)
|
||||
{
|
||||
domain.PokeByte(address, (byte)(value / 256));
|
||||
domain.PokeByte(address + 1, (byte)(value % 256));
|
||||
}
|
||||
else
|
||||
{
|
||||
domain.PokeByte(address + 1, (byte)(value / 256));
|
||||
domain.PokeByte(address, (byte)(value % 256));
|
||||
}
|
||||
}
|
||||
private void PokeByte(MemoryDomain domain)
|
||||
{
|
||||
domain.PokeByte(address, (byte)value);
|
||||
}
|
||||
|
||||
private void PokeDWord(MemoryDomain domain)
|
||||
{
|
||||
if (bigendian)
|
||||
{
|
||||
domain.PokeByte(address, (byte)(value << 6));
|
||||
domain.PokeByte(address + 1, (byte)(value << 4));
|
||||
domain.PokeByte(address + 2, (byte)(value << 2));
|
||||
domain.PokeByte(address + 3, (byte)(value));
|
||||
}
|
||||
else
|
||||
{
|
||||
domain.PokeByte(address + 1, (byte)(value << 6));
|
||||
domain.PokeByte(address, (byte)(value << 4));
|
||||
domain.PokeByte(address + 3, (byte)(value << 2));
|
||||
domain.PokeByte(address + 2, (byte)(value));
|
||||
}
|
||||
}
|
||||
private void PokeWord(MemoryDomain domain)
|
||||
{
|
||||
if (bigendian)
|
||||
{
|
||||
domain.PokeByte(address, (byte)(value / 256));
|
||||
domain.PokeByte(address + 1, (byte)(value % 256));
|
||||
}
|
||||
else
|
||||
{
|
||||
domain.PokeByte(address + 1, (byte)(value / 256));
|
||||
domain.PokeByte(address, (byte)(value % 256));
|
||||
}
|
||||
}
|
||||
|
||||
public void PokeAddress(MemoryDomain domain)
|
||||
{
|
||||
if (type == atype.SEPARATOR)
|
||||
return;
|
||||
private void PokeDWord(MemoryDomain domain)
|
||||
{
|
||||
if (bigendian)
|
||||
{
|
||||
domain.PokeByte(address, (byte)(value << 6));
|
||||
domain.PokeByte(address + 1, (byte)(value << 4));
|
||||
domain.PokeByte(address + 2, (byte)(value << 2));
|
||||
domain.PokeByte(address + 3, (byte)(value));
|
||||
}
|
||||
else
|
||||
{
|
||||
domain.PokeByte(address + 1, (byte)(value << 6));
|
||||
domain.PokeByte(address, (byte)(value << 4));
|
||||
domain.PokeByte(address + 3, (byte)(value << 2));
|
||||
domain.PokeByte(address + 2, (byte)(value));
|
||||
}
|
||||
}
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case atype.BYTE:
|
||||
PokeByte(domain);
|
||||
break;
|
||||
case atype.WORD:
|
||||
PokeWord(domain);
|
||||
break;
|
||||
case atype.DWORD:
|
||||
PokeDWord(domain);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void PokeAddress(MemoryDomain domain)
|
||||
{
|
||||
if (type == atype.SEPARATOR)
|
||||
return;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case atype.BYTE:
|
||||
PokeByte(domain);
|
||||
break;
|
||||
case atype.WORD:
|
||||
PokeWord(domain);
|
||||
break;
|
||||
case atype.DWORD:
|
||||
PokeDWord(domain);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private int CompareAddress(Watch Other)
|
||||
{
|
||||
if (this.address < Other.address)
|
||||
return -1;
|
||||
else if (this.address > Other.address)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int CompareValue(Watch Other)
|
||||
{
|
||||
if (this.value < Other.value)
|
||||
return -1;
|
||||
else if (this.value > Other.value)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int ComparePrev(Watch Other)
|
||||
{
|
||||
if (this.prev < Other.prev)
|
||||
return -1;
|
||||
else if (this.prev > Other.prev)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int CompareChanges(Watch Other)
|
||||
{
|
||||
if (this.changecount < Other.changecount)
|
||||
return -1;
|
||||
else if (this.changecount > Other.changecount)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int CompareNotes(Watch Other)
|
||||
{
|
||||
if (this.notes == null & Other.notes == null)
|
||||
return 0;
|
||||
else if (this.notes == null)
|
||||
return -1;
|
||||
else if (Other.notes == null)
|
||||
return 1;
|
||||
else
|
||||
return this.notes.CompareTo(Other.notes);
|
||||
}
|
||||
|
||||
public int CompareTo(Watch Other, string parameter)
|
||||
{
|
||||
int compare = 0;
|
||||
if (parameter == "Address")
|
||||
{
|
||||
compare = CompareAddress(Other);
|
||||
if (compare == 0)
|
||||
{
|
||||
compare = CompareValue(Other);
|
||||
if (compare == 0)
|
||||
{
|
||||
compare = CompareChanges(Other);
|
||||
if (compare == 0)
|
||||
{
|
||||
compare = ComparePrev(Other);
|
||||
if (compare == 0)
|
||||
compare = CompareNotes(Other);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if (parameter == "Value")
|
||||
{
|
||||
compare = CompareValue(Other);
|
||||
if (compare == 0)
|
||||
{
|
||||
compare = CompareAddress(Other);
|
||||
if (compare == 0)
|
||||
{
|
||||
compare = CompareChanges(Other);
|
||||
if (compare == 0)
|
||||
{
|
||||
compare = ComparePrev(Other);
|
||||
if (compare == 0)
|
||||
compare = CompareNotes(Other);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if (parameter == "Prev")
|
||||
{
|
||||
compare = ComparePrev(Other);
|
||||
if (compare == 0)
|
||||
{
|
||||
compare = CompareAddress(Other);
|
||||
if (compare == 0)
|
||||
{
|
||||
compare = CompareValue(Other);
|
||||
if (compare == 0)
|
||||
{
|
||||
compare = CompareChanges(Other);
|
||||
if (compare == 0)
|
||||
compare = CompareNotes(Other);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if (parameter == "Changes")
|
||||
{
|
||||
compare = CompareChanges(Other);
|
||||
if (compare == 0)
|
||||
{
|
||||
compare = CompareAddress(Other);
|
||||
if (compare == 0)
|
||||
{
|
||||
compare = CompareValue(Other);
|
||||
if (compare == 0)
|
||||
{
|
||||
compare = ComparePrev(Other);
|
||||
if (compare == 0)
|
||||
compare = CompareNotes(Other);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if (parameter == "Notes")
|
||||
{
|
||||
compare = CompareNotes(Other);
|
||||
if (compare == 0)
|
||||
{
|
||||
compare = CompareAddress(Other);
|
||||
if (compare == 0)
|
||||
{
|
||||
compare = CompareValue(Other);
|
||||
if (compare == 0)
|
||||
{
|
||||
compare = CompareChanges(Other);
|
||||
if (compare == 0)
|
||||
compare = ComparePrev(Other);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return compare;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue