Refactoring of Watch object and related tools, add domain into Watch object. No functionality changes in this commit

This commit is contained in:
adelikat 2012-09-03 23:42:00 +00:00
parent 0a60a37705
commit 1f454af2c3
7 changed files with 1003 additions and 829 deletions

View File

@ -593,21 +593,21 @@ namespace BizHawk.MultiClient
private Watch MakeWatch(int address) private Watch MakeWatch(int address)
{ {
Watch w = new Watch(); Watch w = new Watch();
w.address = address; w.Address = address;
w.bigendian = BigEndian; w.BigEndian = BigEndian;
w.signed = asigned.HEX; w.Signed = Watch.DISPTYPE.HEX;
switch (DataSize) switch (DataSize)
{ {
default: default:
case 1: case 1:
w.type = atype.BYTE; w.Type = Watch.TYPE.BYTE;
break; break;
case 2: case 2:
w.type = atype.WORD; w.Type = Watch.TYPE.WORD;
break; break;
case 4: case 4:
w.type = atype.DWORD; w.Type = Watch.TYPE.DWORD;
break; break;
} }
return w; return w;
@ -649,22 +649,22 @@ namespace BizHawk.MultiClient
if (p >= 0) if (p >= 0)
{ {
Watch w = new Watch(); Watch w = new Watch();
w.address = p; w.Address = p;
w.value = MakeValue(p); w.Value = MakeValue(p);
w.bigendian = BigEndian; w.BigEndian = BigEndian;
w.signed = asigned.HEX; w.Signed = Watch.DISPTYPE.HEX;
switch (DataSize) switch (DataSize)
{ {
default: default:
case 1: case 1:
w.type = atype.BYTE; w.Type = Watch.TYPE.BYTE;
break; break;
case 2: case 2:
w.type = atype.WORD; w.Type = Watch.TYPE.WORD;
break; break;
case 4: case 4:
w.type = atype.DWORD; w.Type = Watch.TYPE.DWORD;
break; break;
} }

View File

@ -32,19 +32,27 @@ namespace BizHawk.MultiClient
private void RamPoke_Load(object sender, EventArgs e) private void RamPoke_Load(object sender, EventArgs e)
{ {
if (watch.address == 0) if (watch.Address == 0)
PopulateMemoryDomainComboBox(); PopulateMemoryDomainComboBox();
SetTypeRadio(watch.type); SetTypeRadio(watch.Type);
SetSignedRadio(watch.signed); SetSignedRadio(watch.Signed);
if (watch.signed == asigned.HEX) if (watch.Signed == Watch.DISPTYPE.HEX)
{
ValueHexLabel.Text = "0x"; ValueHexLabel.Text = "0x";
}
else else
{
ValueHexLabel.Text = ""; ValueHexLabel.Text = "";
}
if (watch.bigendian == true) if (watch.BigEndian == true)
{
BigEndianRadio.Checked = true; BigEndianRadio.Checked = true;
}
else else
{
LittleEndianRadio.Checked = true; LittleEndianRadio.Checked = true;
}
SetValueBox(); SetValueBox();
SetAddressBox(); SetAddressBox();
@ -63,15 +71,15 @@ namespace BizHawk.MultiClient
{ {
if (HexRadio.Checked) if (HexRadio.Checked)
ValueBox.Text = String.Format("{0:X" + ValueBox.Text = String.Format("{0:X" +
GetValueNumDigits() + "}", watch.value); GetValueNumDigits() + "}", watch.Value);
else else
ValueBox.Text = watch.value.ToString(); ValueBox.Text = watch.Value.ToString();
} }
private void SetAddressBox() private void SetAddressBox()
{ {
AddressBox.Text = String.Format("{0:X" + AddressBox.Text = String.Format("{0:X" +
GetNumDigits(watch.address) + "}", watch.address); GetNumDigits(watch.Address) + "}", watch.Address);
} }
private void UpdateTitleText() private void UpdateTitleText()
@ -79,17 +87,17 @@ namespace BizHawk.MultiClient
Text = "Ram Poke - " + domain.ToString(); Text = "Ram Poke - " + domain.ToString();
} }
private void SetTypeRadio(atype a) private void SetTypeRadio(Watch.TYPE a)
{ {
switch (a) switch (a)
{ {
case atype.BYTE: case Watch.TYPE.BYTE:
Byte1Radio.Checked = true; Byte1Radio.Checked = true;
break; break;
case atype.WORD: case Watch.TYPE.WORD:
Byte2Radio.Checked = true; Byte2Radio.Checked = true;
break; break;
case atype.DWORD: case Watch.TYPE.DWORD:
Byte4Radio.Checked = true; Byte4Radio.Checked = true;
break; break;
default: default:
@ -97,17 +105,17 @@ namespace BizHawk.MultiClient
} }
} }
private void SetSignedRadio(asigned a) private void SetSignedRadio(Watch.DISPTYPE a)
{ {
switch (a) switch (a)
{ {
case asigned.SIGNED: case Watch.DISPTYPE.SIGNED:
SignedRadio.Checked = true; SignedRadio.Checked = true;
break; break;
case asigned.UNSIGNED: case Watch.DISPTYPE.UNSIGNED:
UnsignedRadio.Checked = true; UnsignedRadio.Checked = true;
break; break;
case asigned.HEX: case Watch.DISPTYPE.HEX:
HexRadio.Checked = true; HexRadio.Checked = true;
break; break;
default: default:
@ -125,7 +133,7 @@ namespace BizHawk.MultiClient
//Put user settings in the watch file //Put user settings in the watch file
if (InputValidate.IsValidHexNumber(AddressBox.Text)) if (InputValidate.IsValidHexNumber(AddressBox.Text))
watch.address = int.Parse(AddressBox.Text, NumberStyles.HexNumber); watch.Address = int.Parse(AddressBox.Text, NumberStyles.HexNumber);
else else
{ {
MessageBox.Show("Invalid Address, must be a valid hex number", "Invalid Address", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Invalid Address, must be a valid hex number", "Invalid Address", MessageBoxButtons.OK, MessageBoxIcon.Error);
@ -135,25 +143,41 @@ namespace BizHawk.MultiClient
} }
if (SignedRadio.Checked) if (SignedRadio.Checked)
watch.signed = asigned.SIGNED; {
watch.Signed = Watch.DISPTYPE.SIGNED;
}
else if (UnsignedRadio.Checked) else if (UnsignedRadio.Checked)
watch.signed = asigned.UNSIGNED; {
watch.Signed = Watch.DISPTYPE.UNSIGNED;
}
else if (HexRadio.Checked) else if (HexRadio.Checked)
watch.signed = asigned.HEX; {
watch.Signed = Watch.DISPTYPE.HEX;
}
if (Byte1Radio.Checked) if (Byte1Radio.Checked)
watch.type = atype.BYTE; {
watch.Type = Watch.TYPE.BYTE;
}
else if (Byte2Radio.Checked) else if (Byte2Radio.Checked)
watch.type = atype.WORD; {
watch.Type = Watch.TYPE.WORD;
}
else if (Byte4Radio.Checked) else if (Byte4Radio.Checked)
watch.type = atype.DWORD; {
watch.Type = Watch.TYPE.DWORD;
}
if (BigEndianRadio.Checked) if (BigEndianRadio.Checked)
watch.bigendian = true; {
watch.BigEndian = true;
}
else if (LittleEndianRadio.Checked) else if (LittleEndianRadio.Checked)
watch.bigendian = false; {
watch.BigEndian = false;
}
int x = GetSpecificValue(); int x = GetSpecificValue(); //TODO: use a nullable int instead of this crap
if (x == -99999999) if (x == -99999999)
{ {
MessageBox.Show("Missing or invalid value", "Invalid Value", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Missing or invalid value", "Invalid Value", MessageBoxButtons.OK, MessageBoxIcon.Error);
@ -162,17 +186,19 @@ namespace BizHawk.MultiClient
return; return;
} }
else else
watch.value = int.Parse(ValueBox.Text); {
watch.Value = int.Parse(ValueBox.Text);
}
watch.PokeAddress(domain); watch.PokeAddress(domain);
string value; string value;
if (HexRadio.Checked) if (HexRadio.Checked)
value = "0x" + String.Format("{0:X" + GetValueNumDigits() + "}", watch.value); value = "0x" + String.Format("{0:X" + GetValueNumDigits() + "}", watch.Value);
else else
value = watch.value.ToString(); value = watch.Value.ToString();
string address = String.Format("{0:X" + GetNumDigits(domain.Size).ToString() string address = String.Format("{0:X" + GetNumDigits(domain.Size).ToString()
+ "}", watch.address); + "}", watch.Address);
OutputLabel.Text = value + " written to " + address; OutputLabel.Text = value + " written to " + address;
@ -202,16 +228,24 @@ namespace BizHawk.MultiClient
} }
} }
private asigned GetDataType() private Watch.DISPTYPE GetDataType()
{ {
if (SignedRadio.Checked) if (SignedRadio.Checked)
return asigned.SIGNED; {
return Watch.DISPTYPE.SIGNED;
}
if (UnsignedRadio.Checked) if (UnsignedRadio.Checked)
return asigned.UNSIGNED; {
return Watch.DISPTYPE.UNSIGNED;
}
if (HexRadio.Checked) if (HexRadio.Checked)
return asigned.HEX; {
return Watch.DISPTYPE.HEX;
return asigned.UNSIGNED; //Just in case }
else
{
return Watch.DISPTYPE.UNSIGNED; //Just in case
}
} }
private void AddressBox_KeyPress(object sender, KeyPressEventArgs e) private void AddressBox_KeyPress(object sender, KeyPressEventArgs e)
@ -228,48 +262,62 @@ namespace BizHawk.MultiClient
switch (GetDataType()) switch (GetDataType())
{ {
case asigned.UNSIGNED: case Watch.DISPTYPE.UNSIGNED:
if (!InputValidate.IsValidUnsignedNumber(e.KeyChar)) if (!InputValidate.IsValidUnsignedNumber(e.KeyChar))
{
e.Handled = true; e.Handled = true;
}
break; break;
case asigned.SIGNED: case Watch.DISPTYPE.SIGNED:
if (!InputValidate.IsValidSignedNumber(e.KeyChar)) if (!InputValidate.IsValidSignedNumber(e.KeyChar))
{
e.Handled = true; e.Handled = true;
}
break; break;
case asigned.HEX: case Watch.DISPTYPE.HEX:
if (!InputValidate.IsValidHexNumber(e.KeyChar)) if (!InputValidate.IsValidHexNumber(e.KeyChar))
{
e.Handled = true; e.Handled = true;
}
break; break;
} }
} }
private atype GetDataSize() private Watch.TYPE GetDataSize()
{ {
if (Byte1Radio.Checked) if (Byte1Radio.Checked)
return atype.BYTE; {
if (Byte2Radio.Checked) return Watch.TYPE.BYTE;
return atype.WORD; }
if (Byte4Radio.Checked) else if (Byte2Radio.Checked)
return atype.DWORD; {
return Watch.TYPE.WORD;
return atype.BYTE; }
else if (Byte4Radio.Checked)
{
return Watch.TYPE.DWORD;
}
else
{
return Watch.TYPE.BYTE;
}
} }
private int GetSpecificValue() private int GetSpecificValue() //TODO: don't use -99999999 use nullable int instead
{ {
if (ValueBox.Text == "" || ValueBox.Text == "-") return 0; if (ValueBox.Text == "" || ValueBox.Text == "-") return 0;
bool i = false; bool i = false;
switch (GetDataType()) switch (GetDataType())
{ {
case asigned.UNSIGNED: case Watch.DISPTYPE.UNSIGNED:
i = InputValidate.IsValidUnsignedNumber(ValueBox.Text); i = InputValidate.IsValidUnsignedNumber(ValueBox.Text);
if (!i) return -99999999; if (!i) return -99999999;
return (int)Int64.Parse(ValueBox.Text); //Note: 64 to be safe return (int)Int64.Parse(ValueBox.Text); //Note: 64 to be safe
case asigned.SIGNED: case Watch.DISPTYPE.SIGNED:
i = InputValidate.IsValidSignedNumber(ValueBox.Text); i = InputValidate.IsValidSignedNumber(ValueBox.Text);
if (!i) return -99999999; if (!i) return -99999999;
return (int)Int64.Parse(ValueBox.Text); return (int)Int64.Parse(ValueBox.Text);
case asigned.HEX: case Watch.DISPTYPE.HEX:
i = InputValidate.IsValidHexNumber(ValueBox.Text); i = InputValidate.IsValidHexNumber(ValueBox.Text);
if (!i) return -99999999; if (!i) return -99999999;
return (int)Int64.Parse(ValueBox.Text, NumberStyles.HexNumber); return (int)Int64.Parse(ValueBox.Text, NumberStyles.HexNumber);
@ -300,15 +348,15 @@ namespace BizHawk.MultiClient
switch (GetDataSize()) switch (GetDataSize())
{ {
default: default:
case atype.BYTE: case Watch.TYPE.BYTE:
if (HexRadio.Checked) return 2; if (HexRadio.Checked) return 2;
else if (UnsignedRadio.Checked) return 3; else if (UnsignedRadio.Checked) return 3;
else return 4; else return 4;
case atype.WORD: case Watch.TYPE.WORD:
if (HexRadio.Checked) return 4; if (HexRadio.Checked) return 4;
else if (UnsignedRadio.Checked) return 5; else if (UnsignedRadio.Checked) return 5;
else return 6; else return 6;
case atype.DWORD: case Watch.TYPE.DWORD:
if (HexRadio.Checked) return 8; if (HexRadio.Checked) return 8;
else if (UnsignedRadio.Checked) return 10; else if (UnsignedRadio.Checked) return 10;
else return 11; else return 11;
@ -343,8 +391,8 @@ namespace BizHawk.MultiClient
domain = Global.Emulator.MemoryDomains[DomainComboBox.SelectedIndex]; domain = Global.Emulator.MemoryDomains[DomainComboBox.SelectedIndex];
UpdateTitleText(); UpdateTitleText();
int x = GetNumDigits(domain.Size); int x = GetNumDigits(domain.Size);
watch.address = 0; watch.Address = 0;
watch.value = 0; watch.Value = 0;
SetAddressBox(); SetAddressBox();
SetValueBox(); SetValueBox();
AddressBox.MaxLength = GetNumDigits(domain.Size); AddressBox.MaxLength = GetNumDigits(domain.Size);

File diff suppressed because it is too large Load Diff

View File

@ -33,7 +33,7 @@ namespace BizHawk.MultiClient
string systemID = "NULL"; string systemID = "NULL";
MemoryDomain Domain = new MemoryDomain("NULL", 1, Endian.Little, addr => 0, (a, v) => { }); MemoryDomain Domain = new MemoryDomain("NULL", 1, Endian.Little, addr => 0, (a, v) => { });
List<Watch> watchList = new List<Watch>(); List<Watch> Watches = new List<Watch>();
string currentFile = ""; string currentFile = "";
bool changes = false; bool changes = false;
List<ToolStripMenuItem> domainMenuItems = new List<ToolStripMenuItem>(); List<ToolStripMenuItem> domainMenuItems = new List<ToolStripMenuItem>();
@ -62,15 +62,15 @@ namespace BizHawk.MultiClient
public List<Watch> GetRamWatchList() public List<Watch> GetRamWatchList()
{ {
List<Watch> w = new List<Watch>(); List<Watch> w = new List<Watch>();
for (int x = 0; x < watchList.Count; x++) for (int x = 0; x < Watches.Count; x++)
w.Add(new Watch(watchList[x])); w.Add(new Watch(Watches[x]));
return w; return w;
} }
public void DisplayWatchList() public void DisplayWatchList()
{ {
WatchListView.ItemCount = watchList.Count; WatchListView.ItemCount = Watches.Count;
} }
public void UpdateValues() public void UpdateValues()
@ -80,17 +80,17 @@ namespace BizHawk.MultiClient
return; return;
} }
for (int x = 0; x < watchList.Count; x++) for (int x = 0; x < Watches.Count; x++)
{ {
watchList[x].PeekAddress(Domain); Watches[x].PeekAddress(Domain);
} }
if (Global.Config.DisplayRamWatch) if (Global.Config.DisplayRamWatch)
{ {
for (int x = 0; x < watchList.Count; x++) for (int x = 0; x < Watches.Count; x++)
{ {
bool alert = Global.CheatList.IsActiveCheat(Domain, watchList[x].address); bool alert = Global.CheatList.IsActiveCheat(Domain, Watches[x].Address);
Global.OSD.AddGUIText(watchList[x].ToString(), Global.OSD.AddGUIText(Watches[x].ToString(),
Global.Config.DispRamWatchx, (Global.Config.DispRamWatchy + (x * 14)), alert, Color.Black, Color.White, 0); Global.Config.DispRamWatchx, (Global.Config.DispRamWatchy + (x * 14)), alert, Color.Black, Color.White, 0);
} }
} }
@ -106,7 +106,7 @@ namespace BizHawk.MultiClient
public void AddWatch(Watch w) public void AddWatch(Watch w)
{ {
watchList.Add(w); Watches.Add(w);
Changes(); Changes();
UpdateValues(); UpdateValues();
DisplayWatchList(); DisplayWatchList();
@ -186,80 +186,72 @@ namespace BizHawk.MultiClient
private void WatchListView_QueryItemBkColor(int index, int column, ref Color color) private void WatchListView_QueryItemBkColor(int index, int column, ref Color color)
{ {
if (index >= watchList.Count) if (index >= Watches.Count)
{ {
return; return;
} }
if (column == 0) if (column == 0)
{ {
if (watchList[index].type == atype.SEPARATOR) if (Watches[index].Type == Watch.TYPE.SEPARATOR)
{
color = this.BackColor; color = this.BackColor;
if (Global.CheatList.IsActiveCheat(Domain, watchList[index].address)) }
if (Global.CheatList.IsActiveCheat(Domain, Watches[index].Address))
{
color = Color.LightCyan; color = Color.LightCyan;
}
} }
} }
void WatchListView_QueryItemText(int index, int column, out string text) void WatchListView_QueryItemText(int index, int column, out string text)
{ {
text = ""; text = "";
if (index >= watchList.Count)
if (Watches[index].Type == Watch.TYPE.SEPARATOR || index >= Watches.Count)
{ {
return; return;
} }
if (column == 0) //Address if (column == 0) //Address
{ {
if (watchList[index].type != atype.SEPARATOR) text = Watches[index].Address.ToString(addressFormatStr);
{
text = watchList[index].address.ToString(addressFormatStr);
}
} }
if (column == 1) //Value if (column == 1) //Value
{ {
text = watchList[index].ValueToString(); text = Watches[index].ValueString;
} }
if (column == 2) //Prev if (column == 2) //Prev
{ {
if (watchList[index].type != atype.SEPARATOR) switch(Global.Config.RamWatchPrev_Type)
{ {
switch(Global.Config.RamWatchPrev_Type) case 1:
{ text = Watches[index].PrevString;
case 1: break;
text = watchList[index].PrevToString(); case 2:
break; text = Watches[index].LastChangeString;
case 2: break;
text = watchList[index].LastChangeToString();
break;
}
} }
} }
if (column == 3) //Change Counts if (column == 3) //Change Counts
{ {
if (watchList[index].type != atype.SEPARATOR) text = Watches[index].Changecount.ToString();
text = watchList[index].changecount.ToString();
} }
if (column == 4) //Diff if (column == 4) //Diff
{ {
if (watchList[index].type != atype.SEPARATOR) switch(Global.Config.RamWatchPrev_Type)
{ {
switch(Global.Config.RamWatchPrev_Type) case 1:
{ text = Watches[index].DiffToString(Watches[index].DiffPrev);
case 1: break;
text = watchList[index].DiffToString(watchList[index].diffPrev); case 2:
break; text = Watches[index].DiffToString(Watches[index].DiffLastChange);
case 2: break;
text = watchList[index].DiffToString(watchList[index].diffLastChange);
break;
}
} }
} }
if (column == 5) //Notes if (column == 5) //Notes
{ {
if (watchList[index].type == atype.SEPARATOR) text = Watches[index].Notes;
text = "";
else
text = watchList[index].notes;
} }
} }
@ -319,7 +311,7 @@ namespace BizHawk.MultiClient
if (result == true || suppressAsk) if (result == true || suppressAsk)
{ {
watchList.Clear(); Watches.Clear();
DisplayWatchList(); DisplayWatchList();
UpdateWatchCount(); UpdateWatchCount();
currentFile = ""; currentFile = "";
@ -332,15 +324,15 @@ namespace BizHawk.MultiClient
private bool SaveWatchFile(string path) private bool SaveWatchFile(string path)
{ {
return WatchCommon.SaveWchFile(path, Domain.Name, watchList); return WatchCommon.SaveWchFile(path, Domain.Name, Watches);
} }
private void UpdateWatchCount() private void UpdateWatchCount()
{ {
int count = 0; int count = 0;
foreach (Watch w in watchList) foreach (Watch w in Watches)
{ {
if (!(w.type == atype.SEPARATOR)) if (!(w.Type == Watch.TYPE.SEPARATOR))
{ {
count++; count++;
} }
@ -352,11 +344,11 @@ namespace BizHawk.MultiClient
public bool LoadWatchFile(string path, bool append) public bool LoadWatchFile(string path, bool append)
{ {
string domain = ""; string domain = "";
bool result = WatchCommon.LoadWatchFile(path, append, watchList, out domain); bool result = WatchCommon.LoadWatchFile(path, append, Watches, out domain);
if (result) if (result)
{ {
foreach (Watch w in watchList) foreach (Watch w in Watches)
{ {
InitializeAddress(w); InitializeAddress(w);
} }
@ -396,7 +388,7 @@ namespace BizHawk.MultiClient
if (r.userSelected == true) if (r.userSelected == true)
{ {
InitializeAddress(r.watch); InitializeAddress(r.watch);
watchList.Add(r.watch); Watches.Add(r.watch);
Changes(); Changes();
UpdateWatchCount(); UpdateWatchCount();
DisplayWatchList(); DisplayWatchList();
@ -406,11 +398,11 @@ namespace BizHawk.MultiClient
private void InitializeAddress(Watch w) private void InitializeAddress(Watch w)
{ {
w.PeekAddress(Domain); w.PeekAddress(Domain);
w.prev = w.value; w.Prev = w.Value;
w.original = w.value; w.Original = w.Value;
w.lastchange = w.value; w.LastChange = w.Value;
w.lastsearch = w.value; w.LastSearch = w.Value;
w.changecount = 0; w.Changecount = 0;
} }
void Changes() void Changes()
@ -423,7 +415,7 @@ namespace BizHawk.MultiClient
{ {
RamWatchNewWatch r = new RamWatchNewWatch(); RamWatchNewWatch r = new RamWatchNewWatch();
r.location = GetPromptPoint(); r.location = GetPromptPoint();
r.SetToEditWatch(watchList[pos], "Edit Watch"); r.SetToEditWatch(Watches[pos], "Edit Watch");
Global.Sound.StopSound(); Global.Sound.StopSound();
r.ShowDialog(); r.ShowDialog();
Global.Sound.StartSound(); Global.Sound.StartSound();
@ -431,7 +423,7 @@ namespace BizHawk.MultiClient
if (r.userSelected == true) if (r.userSelected == true)
{ {
Changes(); Changes();
watchList[pos] = r.watch; Watches[pos] = r.watch;
DisplayWatchList(); DisplayWatchList();
} }
} }
@ -452,7 +444,7 @@ namespace BizHawk.MultiClient
{ {
foreach (int index in indexes) foreach (int index in indexes)
{ {
watchList.Remove(watchList[indexes[0]]); //index[0] used since each iteration will make this the correct list index Watches.Remove(Watches[indexes[0]]); //index[0] used since each iteration will make this the correct list index
} }
indexes.Clear(); indexes.Clear();
DisplayWatchList(); DisplayWatchList();
@ -469,7 +461,7 @@ namespace BizHawk.MultiClient
RamWatchNewWatch r = new RamWatchNewWatch(); RamWatchNewWatch r = new RamWatchNewWatch();
r.location = GetPromptPoint(); r.location = GetPromptPoint();
int x = indexes[0]; int x = indexes[0];
r.SetToEditWatch(watchList[x], "Duplicate Watch"); r.SetToEditWatch(Watches[x], "Duplicate Watch");
Global.Sound.StopSound(); Global.Sound.StopSound();
r.ShowDialog(); r.ShowDialog();
@ -479,7 +471,7 @@ namespace BizHawk.MultiClient
{ {
InitializeAddress(r.watch); InitializeAddress(r.watch);
Changes(); Changes();
watchList.Add(r.watch); Watches.Add(r.watch);
DisplayWatchList(); DisplayWatchList();
} }
} }
@ -498,9 +490,9 @@ namespace BizHawk.MultiClient
if (indexes.Count == 0) return; if (indexes.Count == 0) return;
foreach (int index in indexes) foreach (int index in indexes)
{ {
temp = watchList[index]; temp = Watches[index];
watchList.Remove(watchList[index]); Watches.Remove(Watches[index]);
watchList.Insert(index - 1, temp); Watches.Insert(index - 1, temp);
//Note: here it will get flagged many times redundantly potentially, //Note: here it will get flagged many times redundantly potentially,
//but this avoids it being flagged falsely when the user did not select an index //but this avoids it being flagged falsely when the user did not select an index
@ -525,13 +517,13 @@ namespace BizHawk.MultiClient
if (indexes.Count == 0) return; if (indexes.Count == 0) return;
foreach (int index in indexes) foreach (int index in indexes)
{ {
temp = watchList[index]; temp = Watches[index];
if (index < watchList.Count - 1) if (index < Watches.Count - 1)
{ {
watchList.Remove(watchList[index]); Watches.Remove(Watches[index]);
watchList.Insert(index + 1, temp); Watches.Insert(index + 1, temp);
} }
@ -754,13 +746,13 @@ namespace BizHawk.MultiClient
if (InputValidate.IsValidHexNumber(Str)) if (InputValidate.IsValidHexNumber(Str))
{ {
watchList[e.Item].address = int.Parse(Str, NumberStyles.HexNumber); Watches[e.Item].Address = int.Parse(Str, NumberStyles.HexNumber);
EditWatchObject(index); EditWatchObject(index);
} }
else else
{ {
MessageBox.Show("Invalid number!"); //TODO: More parameters and better message MessageBox.Show("Invalid number!"); //TODO: More parameters and better message
WatchListView.Items[index].Text = watchList[index].address.ToString(); //TODO: Why doesn't the list view update to the new value? It won't until something else changes WatchListView.Items[index].Text = Watches[index].Address.ToString(); //TODO: Why doesn't the list view update to the new value? It won't until something else changes
} }
} }
@ -817,7 +809,7 @@ namespace BizHawk.MultiClient
{ {
Changes(); Changes();
Watch w = new Watch(); Watch w = new Watch();
w.type = atype.SEPARATOR; w.Type = Watch.TYPE.SEPARATOR;
ListView.SelectedIndexCollection indexes = WatchListView.SelectedIndices; ListView.SelectedIndexCollection indexes = WatchListView.SelectedIndices;
int x; int x;
@ -825,10 +817,10 @@ namespace BizHawk.MultiClient
{ {
x = indexes[0]; x = indexes[0];
if (indexes[0] > 0) if (indexes[0] > 0)
watchList.Insert(indexes[0], w); Watches.Insert(indexes[0], w);
} }
else else
watchList.Add(w); Watches.Add(w);
DisplayWatchList(); DisplayWatchList();
} }
@ -884,7 +876,7 @@ namespace BizHawk.MultiClient
RamPoke p = new RamPoke(); RamPoke p = new RamPoke();
Global.Sound.StartSound(); Global.Sound.StartSound();
if (indexes.Count > 0) if (indexes.Count > 0)
p.SetWatchObject(watchList[indexes[0]], Domain); p.SetWatchObject(Watches[indexes[0]], Domain);
p.location = GetPromptPoint(); p.location = GetPromptPoint();
p.ShowDialog(); p.ShowDialog();
UpdateValues(); UpdateValues();
@ -979,7 +971,7 @@ namespace BizHawk.MultiClient
if (indexes.Count == 1) if (indexes.Count == 1)
{ {
if (Global.CheatList.IsActiveCheat(Domain, watchList[indexes[0]].address)) if (Global.CheatList.IsActiveCheat(Domain, Watches[indexes[0]].Address))
{ {
contextMenuStrip1.Items[4].Text = "&Unfreeze address"; contextMenuStrip1.Items[4].Text = "&Unfreeze address";
contextMenuStrip1.Items[4].Image = contextMenuStrip1.Items[4].Image =
@ -1036,8 +1028,8 @@ namespace BizHawk.MultiClient
private void ClearChangeCounts() private void ClearChangeCounts()
{ {
for (int x = 0; x < watchList.Count; x++) for (int x = 0; x < Watches.Count; x++)
watchList[x].changecount = 0; Watches[x].Changecount = 0;
DisplayWatchList(); DisplayWatchList();
MessageLabel.Text = "Change counts cleared"; MessageLabel.Text = "Change counts cleared";
} }
@ -1108,7 +1100,7 @@ namespace BizHawk.MultiClient
if (indexes.Count > 0) if (indexes.Count > 0)
{ {
Global.MainForm.LoadHexEditor(); Global.MainForm.LoadHexEditor();
Global.MainForm.HexEditor1.GoToAddress(watchList[indexes[0]].address); Global.MainForm.HexEditor1.GoToAddress(Watches[indexes[0]].Address);
} }
} }
@ -1148,20 +1140,20 @@ namespace BizHawk.MultiClient
{ {
for (int i = 0; i < indexes.Count; i++) for (int i = 0; i < indexes.Count; i++)
{ {
switch (watchList[indexes[i]].type) switch (Watches[indexes[i]].Type)
{ {
case atype.BYTE: case Watch.TYPE.BYTE:
Cheat c = new Cheat("", watchList[indexes[i]].address, (byte)watchList[indexes[i]].value, Cheat c = new Cheat("", Watches[indexes[i]].Address, (byte)Watches[indexes[i]].Value,
true, Domain); true, Domain);
Global.MainForm.Cheats1.AddCheat(c); Global.MainForm.Cheats1.AddCheat(c);
break; break;
case atype.WORD: case Watch.TYPE.WORD:
{ {
byte low = (byte)(watchList[indexes[i]].value / 256); byte low = (byte)(Watches[indexes[i]].Value / 256);
byte high = (byte)(watchList[indexes[i]].value); byte high = (byte)(Watches[indexes[i]].Value);
int a1 = watchList[indexes[i]].address; int a1 = Watches[indexes[i]].Address;
int a2 = watchList[indexes[i]].address + 1; int a2 = Watches[indexes[i]].Address + 1;
if (watchList[indexes[i]].bigendian) if (Watches[indexes[i]].BigEndian)
{ {
Cheat c1 = new Cheat("", a1, low, true, Domain); Cheat c1 = new Cheat("", a1, low, true, Domain);
Cheat c2 = new Cheat("", a2, high, true, Domain); Cheat c2 = new Cheat("", a2, high, true, Domain);
@ -1177,17 +1169,17 @@ namespace BizHawk.MultiClient
} }
} }
break; break;
case atype.DWORD: case Watch.TYPE.DWORD:
{ {
byte HIWORDhigh = (byte)(watchList[indexes[i]].value / 0x1000000); byte HIWORDhigh = (byte)(Watches[indexes[i]].Value / 0x1000000);
byte HIWORDlow = (byte)(watchList[indexes[i]].value / 0x10000); byte HIWORDlow = (byte)(Watches[indexes[i]].Value / 0x10000);
byte LOWORDhigh = (byte)(watchList[indexes[i]].value / 0x100); byte LOWORDhigh = (byte)(Watches[indexes[i]].Value / 0x100);
byte LOWORDlow = (byte)(watchList[indexes[i]].value); byte LOWORDlow = (byte)(Watches[indexes[i]].Value);
int a1 = watchList[indexes[i]].address; int a1 = Watches[indexes[i]].Address;
int a2 = watchList[indexes[i]].address + 1; int a2 = Watches[indexes[i]].Address + 1;
int a3 = watchList[indexes[i]].address + 2; int a3 = Watches[indexes[i]].Address + 2;
int a4 = watchList[indexes[i]].address + 3; int a4 = Watches[indexes[i]].Address + 3;
if (watchList[indexes[i]].bigendian) if (Watches[indexes[i]].BigEndian)
{ {
Cheat c1 = new Cheat("", a1, HIWORDhigh, true, Domain); Cheat c1 = new Cheat("", a1, HIWORDhigh, true, Domain);
Cheat c2 = new Cheat("", a2, HIWORDlow, true, Domain); Cheat c2 = new Cheat("", a2, HIWORDlow, true, Domain);
@ -1223,20 +1215,20 @@ namespace BizHawk.MultiClient
{ {
for (int i = 0; i < indexes.Count; i++) for (int i = 0; i < indexes.Count; i++)
{ {
switch (watchList[indexes[i]].type) switch (Watches[indexes[i]].Type)
{ {
case atype.BYTE: case Watch.TYPE.BYTE:
Global.CheatList.Remove(Domain, watchList[indexes[i]].address); Global.CheatList.Remove(Domain, Watches[indexes[i]].Address);
break; break;
case atype.WORD: case Watch.TYPE.WORD:
Global.CheatList.Remove(Domain, watchList[indexes[i]].address); Global.CheatList.Remove(Domain, Watches[indexes[i]].Address);
Global.CheatList.Remove(Domain, watchList[indexes[i]].address + 1); Global.CheatList.Remove(Domain, Watches[indexes[i]].Address + 1);
break; break;
case atype.DWORD: case Watch.TYPE.DWORD:
Global.CheatList.Remove(Domain, watchList[indexes[i]].address); Global.CheatList.Remove(Domain, Watches[indexes[i]].Address);
Global.CheatList.Remove(Domain, watchList[indexes[i]].address + 1); Global.CheatList.Remove(Domain, Watches[indexes[i]].Address + 1);
Global.CheatList.Remove(Domain, watchList[indexes[i]].address + 2); Global.CheatList.Remove(Domain, Watches[indexes[i]].Address + 2);
Global.CheatList.Remove(Domain, watchList[indexes[i]].address + 3); Global.CheatList.Remove(Domain, Watches[indexes[i]].Address + 3);
break; break;
} }
} }
@ -1398,7 +1390,7 @@ namespace BizHawk.MultiClient
string columnName = WatchListView.Columns[columnToOrder].Text; string columnName = WatchListView.Columns[columnToOrder].Text;
if (sortedCol.CompareTo(columnName) != 0) if (sortedCol.CompareTo(columnName) != 0)
sortReverse = false; sortReverse = false;
watchList.Sort((x, y) => x.CompareTo(y, columnName, Global.Config.RamWatchPrev_Type == 1 ? prevDef.LASTFRAME : prevDef.LASTCHANGE) * (sortReverse ? -1 : 1)); Watches.Sort((x, y) => x.CompareTo(y, columnName, Global.Config.RamWatchPrev_Type == 1 ? Watch.PREVDEF.LASTFRAME : Watch.PREVDEF.LASTCHANGE) * (sortReverse ? -1 : 1));
sortedCol = columnName; sortedCol = columnName;
sortReverse = !(sortReverse); sortReverse = !(sortReverse);
WatchListView.Refresh(); WatchListView.Refresh();
@ -1426,7 +1418,7 @@ namespace BizHawk.MultiClient
private void SelectAll() private void SelectAll()
{ {
for (int x = 0; x < watchList.Count; x++) for (int x = 0; x < Watches.Count; x++)
WatchListView.SelectItem(x, true); WatchListView.SelectItem(x, true);
} }
@ -1453,7 +1445,7 @@ namespace BizHawk.MultiClient
} }
else if (e.KeyCode == Keys.A && e.Control && !e.Alt && !e.Shift) //Select All else if (e.KeyCode == Keys.A && e.Control && !e.Alt && !e.Shift) //Select All
{ {
for (int x = 0; x < watchList.Count; x++) for (int x = 0; x < Watches.Count; x++)
{ {
WatchListView.SelectItem(x, true); WatchListView.SelectItem(x, true);
} }

View File

@ -22,17 +22,17 @@ namespace BizHawk.MultiClient
InitializeComponent(); InitializeComponent();
} }
private void SetTypeRadio(atype a) private void SetTypeRadio(Watch.TYPE a)
{ {
switch (a) switch (a)
{ {
case atype.BYTE: case Watch.TYPE.BYTE:
Byte1Radio.Checked = true; Byte1Radio.Checked = true;
break; break;
case atype.WORD: case Watch.TYPE.WORD:
Byte2Radio.Checked = true; Byte2Radio.Checked = true;
break; break;
case atype.DWORD: case Watch.TYPE.DWORD:
Byte4Radio.Checked = true; Byte4Radio.Checked = true;
break; break;
default: default:
@ -40,17 +40,17 @@ namespace BizHawk.MultiClient
} }
} }
private void SetSignedRadio(asigned a) private void SetSignedRadio(Watch.DISPTYPE a)
{ {
switch (a) switch (a)
{ {
case asigned.SIGNED: case Watch.DISPTYPE.SIGNED:
SignedRadio.Checked = true; SignedRadio.Checked = true;
break; break;
case asigned.UNSIGNED: case Watch.DISPTYPE.UNSIGNED:
UnsignedRadio.Checked = true; UnsignedRadio.Checked = true;
break; break;
case asigned.HEX: case Watch.DISPTYPE.HEX:
HexRadio.Checked = true; HexRadio.Checked = true;
break; break;
default: default:
@ -64,13 +64,13 @@ namespace BizHawk.MultiClient
this.Text = message; this.Text = message;
customSetup = true; customSetup = true;
AddressBox.Text = string.Format("{0:X4}", w.address); AddressBox.Text = string.Format("{0:X4}", w.Address);
NotesBox.Text = w.notes; NotesBox.Text = w.Notes;
SetTypeRadio(w.type); SetTypeRadio(w.Type);
SetSignedRadio(w.signed); SetSignedRadio(w.Signed);
if (w.bigendian == true) if (w.BigEndian == true)
BigEndianRadio.Checked = true; BigEndianRadio.Checked = true;
else else
LittleEndianRadio.Checked = true; LittleEndianRadio.Checked = true;
@ -93,8 +93,8 @@ namespace BizHawk.MultiClient
if (!customSetup) if (!customSetup)
{ {
Watch w = new Watch(); Watch w = new Watch();
SetTypeRadio(w.type); SetTypeRadio(w.Type);
SetSignedRadio(w.signed); SetSignedRadio(w.Signed);
AddressBox.Text = "0000"; AddressBox.Text = "0000";
} }
@ -113,7 +113,9 @@ namespace BizHawk.MultiClient
//Put user settings in the watch file //Put user settings in the watch file
userSelected = true; userSelected = true;
if (InputValidate.IsValidHexNumber(AddressBox.Text)) if (InputValidate.IsValidHexNumber(AddressBox.Text))
watch.address = int.Parse(AddressBox.Text, NumberStyles.HexNumber); {
watch.Address = int.Parse(AddressBox.Text, NumberStyles.HexNumber);
}
else else
{ {
MessageBox.Show("Not a valid address (enter a valid Hex number)", "Invalid Address", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Not a valid address (enter a valid Hex number)", "Invalid Address", MessageBoxButtons.OK, MessageBoxIcon.Error);
@ -124,25 +126,41 @@ namespace BizHawk.MultiClient
} }
if (SignedRadio.Checked) if (SignedRadio.Checked)
watch.signed = asigned.SIGNED; {
watch.Signed = Watch.DISPTYPE.SIGNED;
}
else if (UnsignedRadio.Checked) else if (UnsignedRadio.Checked)
watch.signed = asigned.UNSIGNED; {
watch.Signed = Watch.DISPTYPE.UNSIGNED;
}
else if (HexRadio.Checked) else if (HexRadio.Checked)
watch.signed = asigned.HEX; {
watch.Signed = Watch.DISPTYPE.HEX;
}
if (Byte1Radio.Checked) if (Byte1Radio.Checked)
watch.type = atype.BYTE; {
watch.Type = Watch.TYPE.BYTE;
}
else if (Byte2Radio.Checked) else if (Byte2Radio.Checked)
watch.type = atype.WORD; {
watch.Type = Watch.TYPE.WORD;
}
else if (Byte4Radio.Checked) else if (Byte4Radio.Checked)
watch.type = atype.DWORD; {
watch.Type = Watch.TYPE.DWORD;
}
if (BigEndianRadio.Checked) if (BigEndianRadio.Checked)
watch.bigendian = true; {
watch.BigEndian = true;
}
else if (LittleEndianRadio.Checked) else if (LittleEndianRadio.Checked)
watch.bigendian = false; {
watch.BigEndian = false;
}
watch.notes = NotesBox.Text; watch.Notes = NotesBox.Text;
this.Close(); this.Close();
} }

View File

@ -5,254 +5,338 @@ using System.Text;
namespace BizHawk.MultiClient 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 prevDef { LASTSEARCH, ORIGINAL, LASTFRAME, LASTCHANGE };
/// <summary> /// <summary>
/// An object that represent a ram address and related properties /// An object that represent a ram address and related properties
/// </summary> /// </summary>
public class Watch public class Watch
{ {
public enum TYPE { BYTE, WORD, DWORD, SEPARATOR };
public enum DISPTYPE { SIGNED, UNSIGNED, HEX };
public enum PREVDEF { LASTSEARCH, ORIGINAL, LASTFRAME, LASTCHANGE };
#region Constructors
public Watch() public Watch()
{ {
address = 0; Address = 0;
value = 0; Value = 0;
type = atype.BYTE; Type = TYPE.BYTE;
signed = asigned.UNSIGNED; Signed = DISPTYPE.UNSIGNED;
bigendian = true; BigEndian = true;
notes = ""; Notes = "";
changecount = 0; Changecount = 0;
prev = 0; Prev = 0;
original = 0; Original = 0;
lastchange = 0; LastChange = 0;
lastsearch = 0; LastSearch = 0;
deleted = false; Deleted = false;
Domain = Global.Emulator.MainMemory;
} }
public Watch(Watch w) public Watch(Watch w)
{ {
address = w.address; Address = w.Address;
value = w.value; Value = w.Value;
type = w.type; Type = w.Type;
signed = w.signed; Signed = w.Signed;
bigendian = w.bigendian; BigEndian = w.BigEndian;
notes = w.notes; Notes = w.Notes;
changecount = w.changecount; Changecount = w.Changecount;
prev = w.prev; Prev = w.Prev;
original = w.original; Original = w.Original;
lastchange = w.lastchange; LastChange = w.LastChange;
lastsearch = w.lastsearch; LastSearch = w.LastSearch;
deleted = w.deleted; Deleted = w.Deleted;
} }
public Watch(int Address, int Value, atype Type, asigned Signed, bool BigEndian, string Notes) public Watch(MemoryDomain _domain, int _address, int _value, TYPE _type, DISPTYPE _disptype, bool _bigendian, string _notes)
{ {
address = Address; Domain = _domain;
value = Value; Address = _address;
type = Type; Value = _value;
signed = Signed; Type = _type;
bigendian = BigEndian; Signed = _disptype;
notes = Notes; BigEndian = _bigendian;
changecount = 0; Notes = _notes;
prev = Value; Changecount = 0;
original = Value; Prev = _value;
lastchange = Value; Original = _value;
lastsearch = Value; LastChange = _value;
LastSearch = _value;
} }
public int address { get; set; }
public int value { get; set; } //Current value
public int prev { get; set; }
public int original { get; set; }
public int lastchange { get; set; }
public int lastsearch { get; set; }
public int diffPrev { get { return value - prev; } }
public int diffOriginal { get { return value - original; } }
public int diffLastChange { get { return value - lastchange; } }
public int diffLastSearch { get { return value - lastsearch; } }
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 deleted { get; set; } //For weeding out addresses in things like ram search, without actually removing them from the list (in order to preview, undo, etc)
#endregion
#region Properties
public MemoryDomain Domain;
public int Address;
public int Value;
public int Prev;
public int Original;
public int LastChange;
public int LastSearch;
public TYPE Type;
public DISPTYPE Signed;
public bool BigEndian;
public string Notes;
public int Changecount;
public bool Deleted;
public int DiffPrev
{
get
{
return Value - Prev;
}
}
public int DiffOriginal
{
get
{
return Value - Original;
}
}
public int DiffLastChange
{
get
{
return Value - LastChange;
}
}
public int DiffLastSearch
{
get
{
return Value - LastSearch;
}
}
public string ValueString
{
get
{
return ValToString(Value);
}
}
public string PrevString
{
get
{
return ValToString(Prev);
}
}
public string OriginalString
{
get
{
return ValToString(Original);
}
}
public string LastChangeString
{
get
{
return ValToString(LastChange);
}
}
public string LastSearchString
{
get
{
return ValToString(LastSearch);
}
}
public string DiffPrevString
{
get
{
return DiffToString(Prev);
}
}
public string DiffOriginalString
{
get
{
return DiffToString(Original);
}
}
public string DiffLastChangeString
{
get
{
return DiffToString(LastChange);
}
}
public string DiffLastSearchString
{
get
{
return DiffToString(LastSearch);
}
}
public char TypeChar
{
get
{
switch (Type)
{
case TYPE.BYTE:
return 'b';
case TYPE.WORD:
return 'w';
case TYPE.DWORD:
return 'd';
case TYPE.SEPARATOR:
return 'S';
default:
return 'b'; //Just in case
}
}
}
public char SignedChar
{
get
{
switch (Signed)
{
case DISPTYPE.SIGNED:
return 's';
case DISPTYPE.UNSIGNED:
return 'u';
case DISPTYPE.HEX:
return 'h';
default:
return 's'; //Just in case
}
}
}
#endregion
#region Public Methods
public bool SetTypeByChar(char c) //b = byte, w = word, d = dword public bool SetTypeByChar(char c) //b = byte, w = word, d = dword
{ {
switch (c) switch (c)
{ {
case 'b': case 'b':
type = atype.BYTE; Type = TYPE.BYTE;
return true; return true;
case 'w': case 'w':
type = atype.WORD; Type = TYPE.WORD;
return true; return true;
case 'd': case 'd':
type = atype.DWORD; Type = TYPE.DWORD;
return true; return true;
case 'S': case 'S':
type = atype.SEPARATOR; Type = TYPE.SEPARATOR;
return true; return true;
default: default:
return false; 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 SetSignedByChar(char c) //s = signed, u = unsigned, h = hex public bool SetSignedByChar(char c) //s = signed, u = unsigned, h = hex
{ {
switch (c) switch (c)
{ {
case 's': case 's':
signed = asigned.SIGNED; Signed = DISPTYPE.SIGNED;
return true; return true;
case 'u': case 'u':
signed = asigned.UNSIGNED; Signed = DISPTYPE.UNSIGNED;
return true; return true;
case 'h': case 'h':
signed = asigned.HEX; Signed = DISPTYPE.HEX;
return true; return true;
default: default:
return false; return false;
} }
} }
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 void PeekAddress(MemoryDomain domain) public void PeekAddress(MemoryDomain domain)
{ {
if (type == atype.SEPARATOR) if (Type == TYPE.SEPARATOR)
return; return;
prev = value; Prev = Value;
switch (type) switch (Type)
{ {
case atype.BYTE: case TYPE.BYTE:
value = domain.PeekByte(address); Value = domain.PeekByte(Address);
break; break;
case atype.WORD: case TYPE.WORD:
if (bigendian) if (BigEndian)
{ {
value = 0; Value = 0;
value |= domain.PeekByte(address) << 8; Value |= domain.PeekByte(Address) << 8;
value |= domain.PeekByte(address + 1); Value |= domain.PeekByte(Address + 1);
} }
else else
{ {
value = 0; Value = 0;
value |= domain.PeekByte(address); Value |= domain.PeekByte(Address);
value |= domain.PeekByte(address + 1) << 8; Value |= domain.PeekByte(Address + 1) << 8;
} }
break; break;
case atype.DWORD: case TYPE.DWORD:
if (bigendian) if (BigEndian)
{ {
value = 0; Value = 0;
value |= domain.PeekByte(address) << 24; Value |= domain.PeekByte(Address) << 24;
value |= domain.PeekByte(address + 1) << 16; Value |= domain.PeekByte(Address + 1) << 16;
value |= domain.PeekByte(address + 2) << 8; Value |= domain.PeekByte(Address + 2) << 8;
value |= domain.PeekByte(address + 3) << 0; Value |= domain.PeekByte(Address + 3) << 0;
} }
else else
{ {
value = 0; Value = 0;
value |= domain.PeekByte(address) << 0; Value |= domain.PeekByte(Address) << 0;
value |= domain.PeekByte(address + 1) << 8; Value |= domain.PeekByte(Address + 1) << 8;
value |= domain.PeekByte(address + 2) << 16; Value |= domain.PeekByte(Address + 2) << 16;
value |= domain.PeekByte(address + 3) << 24; Value |= domain.PeekByte(Address + 3) << 24;
} }
break; break;
} }
if (value != prev) if (Value != Prev)
{ {
lastchange = prev; LastChange = Prev;
changecount++; Changecount++;
}
}
private void PokeByte(MemoryDomain domain)
{
domain.PokeByte(address, (byte)value);
}
private void PokeWord(MemoryDomain domain)
{
if (bigendian)
{
domain.PokeByte(address + 0, (byte)(value >> 8));
domain.PokeByte(address + 1, (byte)(value));
}
else
{
domain.PokeByte(address + 0, (byte)(value));
domain.PokeByte(address + 1, (byte)(value >> 8));
}
}
private void PokeDWord(MemoryDomain domain)
{
if (bigendian)
{
domain.PokeByte(address + 0, (byte)(value << 24));
domain.PokeByte(address + 1, (byte)(value << 16));
domain.PokeByte(address + 2, (byte)(value << 8));
domain.PokeByte(address + 3, (byte)(value));
}
else
{
domain.PokeByte(address + 0, (byte)(value));
domain.PokeByte(address + 1, (byte)(value << 8));
domain.PokeByte(address + 2, (byte)(value << 16));
domain.PokeByte(address + 3, (byte)(value << 24));
} }
} }
public void PokeAddress(MemoryDomain domain) public void PokeAddress(MemoryDomain domain)
{ {
if (type == atype.SEPARATOR) if (Type == TYPE.SEPARATOR)
return; return;
switch (type) switch (Type)
{ {
case atype.BYTE: case TYPE.BYTE:
PokeByte(domain); PokeByte(domain);
break; break;
case atype.WORD: case TYPE.WORD:
PokeWord(domain); PokeWord(domain);
break; break;
case atype.DWORD: case TYPE.DWORD:
PokeDWord(domain); PokeDWord(domain);
break; break;
} }
@ -260,11 +344,11 @@ namespace BizHawk.MultiClient
public uint UnsignedVal(int val) public uint UnsignedVal(int val)
{ {
switch (type) switch (Type)
{ {
case atype.BYTE: case TYPE.BYTE:
return (uint)(byte)val; return (uint)(byte)val;
case atype.WORD: case TYPE.WORD:
return (uint)(ushort)val; return (uint)(ushort)val;
} }
return (uint)val; return (uint)val;
@ -272,11 +356,11 @@ namespace BizHawk.MultiClient
public int SignedVal(int val) public int SignedVal(int val)
{ {
switch (type) switch (Type)
{ {
case atype.BYTE: case TYPE.BYTE:
return (int)(sbyte)val; return (int)(sbyte)val;
case atype.WORD: case TYPE.WORD:
return (int)(short)val; return (int)(short)val;
} }
return val; return val;
@ -284,37 +368,41 @@ namespace BizHawk.MultiClient
public override string ToString() public override string ToString()
{ {
if (type == atype.SEPARATOR) if (Type == TYPE.SEPARATOR)
{
return "----"; return "----";
}
StringBuilder str = new StringBuilder(notes); StringBuilder str = new StringBuilder(Notes);
str.Append(": "); str.Append(": ");
str.Append(ValToString(value)); str.Append(ValToString(Value));
return str.ToString(); return str.ToString();
} }
public string ValToString(int val) public string ValToString(int val)
{ {
if (type == atype.SEPARATOR) if (Type == TYPE.SEPARATOR)
{
return ""; return "";
}
else else
{ {
switch (signed) switch (Signed)
{ {
default: default:
case asigned.UNSIGNED: case DISPTYPE.UNSIGNED:
return UnsignedVal(val).ToString(); return UnsignedVal(val).ToString();
case asigned.SIGNED: case DISPTYPE.SIGNED:
return SignedVal(val).ToString(); return SignedVal(val).ToString();
case asigned.HEX: case DISPTYPE.HEX:
switch (type) switch (Type)
{ {
default: default:
case atype.BYTE: case TYPE.BYTE:
return String.Format("{0:X2}", val); return String.Format("{0:X2}", val);
case atype.WORD: case TYPE.WORD:
return String.Format("{0:X4}", val); return String.Format("{0:X4}", val);
case atype.DWORD: case TYPE.DWORD:
return String.Format("{0:X8}", val); return String.Format("{0:X8}", val);
} }
} }
@ -329,88 +417,88 @@ namespace BizHawk.MultiClient
return converted; return converted;
} }
public string ValueToString() #endregion
#region Helpers
private void PokeByte(MemoryDomain domain)
{ {
return ValToString(value); domain.PokeByte(Address, (byte)Value);
} }
public string PrevToString() private void PokeWord(MemoryDomain domain)
{ {
return ValToString(prev); if (BigEndian)
{
domain.PokeByte(Address + 0, (byte)(Value >> 8));
domain.PokeByte(Address + 1, (byte)(Value));
}
else
{
domain.PokeByte(Address + 0, (byte)(Value));
domain.PokeByte(Address + 1, (byte)(Value >> 8));
}
} }
public string OriginalToString() private void PokeDWord(MemoryDomain domain)
{ {
return ValToString(original); if (BigEndian)
{
domain.PokeByte(Address + 0, (byte)(Value << 24));
domain.PokeByte(Address + 1, (byte)(Value << 16));
domain.PokeByte(Address + 2, (byte)(Value << 8));
domain.PokeByte(Address + 3, (byte)(Value));
}
else
{
domain.PokeByte(Address + 0, (byte)(Value));
domain.PokeByte(Address + 1, (byte)(Value << 8));
domain.PokeByte(Address + 2, (byte)(Value << 16));
domain.PokeByte(Address + 3, (byte)(Value << 24));
}
} }
public string LastChangeToString() #endregion
{
return ValToString(lastchange);
}
public string LastSearchToString() #region Compare Methods
{
return ValToString(lastsearch);
}
public string DiffPrevToString() private int ComparePrevious(Watch Other, PREVDEF previous)
{
return DiffToString(prev);
}
public string DiffOriginalToString()
{
return DiffToString(original);
}
public string DiffLastChangeToString()
{
return DiffToString(lastchange);
}
public string DiffLastSearchToString()
{
return DiffToString(lastsearch);
}
private int ComparePrevious(Watch Other, prevDef previous)
{ {
switch (previous) switch (previous)
{ {
case prevDef.LASTSEARCH: case PREVDEF.LASTSEARCH:
return CompareLastSearch(Other); return CompareLastSearch(Other);
case prevDef.ORIGINAL: case PREVDEF.ORIGINAL:
return CompareOriginal(Other); return CompareOriginal(Other);
default: default:
case prevDef.LASTFRAME: case PREVDEF.LASTFRAME:
return ComparePrev(Other); return ComparePrev(Other);
case prevDef.LASTCHANGE: case PREVDEF.LASTCHANGE:
return CompareLastChange(Other); return CompareLastChange(Other);
} }
} }
private int CompareDiff(Watch Other, prevDef previous) private int CompareDiff(Watch Other, PREVDEF previous)
{ {
switch (previous) switch (previous)
{ {
case prevDef.LASTSEARCH: case PREVDEF.LASTSEARCH:
return CompareDiffLastSearch(Other); return CompareDiffLastSearch(Other);
case prevDef.ORIGINAL: case PREVDEF.ORIGINAL:
return CompareDiffOriginal(Other); return CompareDiffOriginal(Other);
default: default:
case prevDef.LASTFRAME: case PREVDEF.LASTFRAME:
return CompareDiffPrev(Other); return CompareDiffPrev(Other);
case prevDef.LASTCHANGE: case PREVDEF.LASTCHANGE:
return CompareDiffLastChange(Other); return CompareDiffLastChange(Other);
} }
} }
private int CompareAddress(Watch Other) private int CompareAddress(Watch Other)
{ {
if (this.address < Other.address) if (this.Address < Other.Address)
return -1; return -1;
else if (this.address > Other.address) else if (this.Address > Other.Address)
return 1; return 1;
else else
return 0; return 0;
@ -418,18 +506,18 @@ namespace BizHawk.MultiClient
private int CompareValue(Watch Other) private int CompareValue(Watch Other)
{ {
if (signed == asigned.SIGNED) if (Signed == DISPTYPE.SIGNED)
{ {
if (SignedVal(this.value) < SignedVal(Other.value)) if (SignedVal(this.Value) < SignedVal(Other.Value))
return -1; return -1;
else if (SignedVal(this.value) > SignedVal(Other.value)) else if (SignedVal(this.Value) > SignedVal(Other.Value))
return 1; return 1;
else else
return 0; return 0;
} }
if (UnsignedVal(this.value) < UnsignedVal(Other.value)) if (UnsignedVal(this.Value) < UnsignedVal(Other.Value))
return -1; return -1;
else if (UnsignedVal(this.value) > UnsignedVal(Other.value)) else if (UnsignedVal(this.Value) > UnsignedVal(Other.Value))
return 1; return 1;
else else
return 0; return 0;
@ -437,18 +525,18 @@ namespace BizHawk.MultiClient
private int ComparePrev(Watch Other) private int ComparePrev(Watch Other)
{ {
if (signed == asigned.SIGNED) if (Signed == DISPTYPE.SIGNED)
{ {
if (SignedVal(this.prev) < SignedVal(Other.prev)) if (SignedVal(this.Prev) < SignedVal(Other.Prev))
return -1; return -1;
else if (SignedVal(this.prev) > SignedVal(Other.prev)) else if (SignedVal(this.Prev) > SignedVal(Other.Prev))
return 1; return 1;
else else
return 0; return 0;
} }
if (UnsignedVal(this.prev) < UnsignedVal(Other.prev)) if (UnsignedVal(this.Prev) < UnsignedVal(Other.Prev))
return -1; return -1;
else if (UnsignedVal(this.prev) > UnsignedVal(Other.prev)) else if (UnsignedVal(this.Prev) > UnsignedVal(Other.Prev))
return 1; return 1;
else else
return 0; return 0;
@ -456,18 +544,18 @@ namespace BizHawk.MultiClient
private int CompareOriginal(Watch Other) private int CompareOriginal(Watch Other)
{ {
if (signed == asigned.SIGNED) if (Signed == DISPTYPE.SIGNED)
{ {
if (SignedVal(this.original) < SignedVal(Other.original)) if (SignedVal(this.Original) < SignedVal(Other.Original))
return -1; return -1;
else if (SignedVal(this.original) > SignedVal(Other.original)) else if (SignedVal(this.Original) > SignedVal(Other.Original))
return 1; return 1;
else else
return 0; return 0;
} }
if (UnsignedVal(this.original) < UnsignedVal(Other.original)) if (UnsignedVal(this.Original) < UnsignedVal(Other.Original))
return -1; return -1;
else if (UnsignedVal(this.original) > UnsignedVal(Other.original)) else if (UnsignedVal(this.Original) > UnsignedVal(Other.Original))
return 1; return 1;
else else
return 0; return 0;
@ -475,18 +563,18 @@ namespace BizHawk.MultiClient
private int CompareLastChange(Watch Other) private int CompareLastChange(Watch Other)
{ {
if (signed == asigned.SIGNED) if (Signed == DISPTYPE.SIGNED)
{ {
if (SignedVal(this.lastchange) < SignedVal(Other.lastchange)) if (SignedVal(this.LastChange) < SignedVal(Other.LastChange))
return -1; return -1;
else if (SignedVal(this.lastchange) > SignedVal(Other.lastchange)) else if (SignedVal(this.LastChange) > SignedVal(Other.LastChange))
return 1; return 1;
else else
return 0; return 0;
} }
if (UnsignedVal(this.lastchange) < UnsignedVal(Other.lastchange)) if (UnsignedVal(this.LastChange) < UnsignedVal(Other.LastChange))
return -1; return -1;
else if (UnsignedVal(this.lastchange) > UnsignedVal(Other.lastchange)) else if (UnsignedVal(this.LastChange) > UnsignedVal(Other.LastChange))
return 1; return 1;
else else
return 0; return 0;
@ -494,18 +582,18 @@ namespace BizHawk.MultiClient
private int CompareLastSearch(Watch Other) private int CompareLastSearch(Watch Other)
{ {
if (signed == asigned.SIGNED) if (Signed == DISPTYPE.SIGNED)
{ {
if (SignedVal(this.lastsearch) < SignedVal(Other.lastsearch)) if (SignedVal(this.LastSearch) < SignedVal(Other.LastSearch))
return -1; return -1;
else if (SignedVal(this.lastsearch) > SignedVal(Other.lastsearch)) else if (SignedVal(this.LastSearch) > SignedVal(Other.LastSearch))
return 1; return 1;
else else
return 0; return 0;
} }
if (UnsignedVal(this.lastsearch) < UnsignedVal(Other.lastsearch)) if (UnsignedVal(this.LastSearch) < UnsignedVal(Other.LastSearch))
return -1; return -1;
else if (UnsignedVal(this.lastsearch) > UnsignedVal(Other.lastsearch)) else if (UnsignedVal(this.LastSearch) > UnsignedVal(Other.LastSearch))
return 1; return 1;
else else
return 0; return 0;
@ -513,9 +601,9 @@ namespace BizHawk.MultiClient
private int CompareDiffPrev(Watch Other) private int CompareDiffPrev(Watch Other)
{ {
if (this.diffPrev < Other.diffPrev) if (this.DiffPrev < Other.DiffPrev)
return -1; return -1;
else if (this.diffPrev > Other.diffPrev) else if (this.DiffPrev > Other.DiffPrev)
return 1; return 1;
else else
return 0; return 0;
@ -523,9 +611,9 @@ namespace BizHawk.MultiClient
private int CompareDiffOriginal(Watch Other) private int CompareDiffOriginal(Watch Other)
{ {
if (this.diffOriginal < Other.diffOriginal) if (this.DiffOriginal < Other.DiffOriginal)
return -1; return -1;
else if (this.diffOriginal > Other.diffOriginal) else if (this.DiffOriginal > Other.DiffOriginal)
return 1; return 1;
else else
return 0; return 0;
@ -533,9 +621,9 @@ namespace BizHawk.MultiClient
private int CompareDiffLastChange(Watch Other) private int CompareDiffLastChange(Watch Other)
{ {
if (this.diffLastChange < Other.diffLastChange) if (this.DiffLastChange < Other.DiffLastChange)
return -1; return -1;
else if (this.diffLastChange > Other.diffLastChange) else if (this.DiffLastChange > Other.DiffLastChange)
return 1; return 1;
else else
return 0; return 0;
@ -543,9 +631,9 @@ namespace BizHawk.MultiClient
private int CompareDiffLastSearch(Watch Other) private int CompareDiffLastSearch(Watch Other)
{ {
if (this.diffLastSearch < Other.diffLastSearch) if (this.DiffLastSearch < Other.DiffLastSearch)
return -1; return -1;
else if (this.diffLastSearch > Other.diffLastSearch) else if (this.DiffLastSearch > Other.DiffLastSearch)
return 1; return 1;
else else
return 0; return 0;
@ -553,9 +641,9 @@ namespace BizHawk.MultiClient
private int CompareChanges(Watch Other) private int CompareChanges(Watch Other)
{ {
if (this.changecount < Other.changecount) if (this.Changecount < Other.Changecount)
return -1; return -1;
else if (this.changecount > Other.changecount) else if (this.Changecount > Other.Changecount)
return 1; return 1;
else else
return 0; return 0;
@ -563,17 +651,17 @@ namespace BizHawk.MultiClient
private int CompareNotes(Watch Other) private int CompareNotes(Watch Other)
{ {
if (this.notes == null & Other.notes == null) if (this.Notes == null & Other.Notes == null)
return 0; return 0;
else if (this.notes == null) else if (this.Notes == null)
return -1; return -1;
else if (Other.notes == null) else if (Other.Notes == null)
return 1; return 1;
else else
return this.notes.CompareTo(Other.notes); return this.Notes.CompareTo(Other.Notes);
} }
public int CompareTo(Watch Other, string parameter, prevDef previous) public int CompareTo(Watch Other, string parameter, PREVDEF previous)
{ {
int compare = 0; int compare = 0;
if (parameter == "Address") if (parameter == "Address")
@ -716,5 +804,7 @@ namespace BizHawk.MultiClient
return compare; return compare;
} }
#endregion
} }
} }

View File

@ -25,16 +25,20 @@ namespace BizHawk.MultiClient
for (int x = 0; x < watchList.Count; x++) for (int x = 0; x < watchList.Count; x++)
{ {
str.Append(string.Format("{0:X4}", watchList[x].address) + "\t"); str.Append(string.Format("{0:X4}", watchList[x].Address) + "\t");
str.Append(watchList[x].GetTypeByChar().ToString() + "\t"); str.Append(watchList[x].TypeChar.ToString() + "\t");
str.Append(watchList[x].GetSignedByChar().ToString() + "\t"); str.Append(watchList[x].SignedChar.ToString() + "\t");
if (watchList[x].bigendian == true) if (watchList[x].BigEndian == true)
{
str.Append("1\t"); str.Append("1\t");
}
else else
{
str.Append("0\t"); str.Append("0\t");
}
str.Append(watchList[x].notes + "\n"); str.Append(watchList[x].Notes + "\n");
} }
sw.WriteLine(str.ToString()); sw.WriteLine(str.ToString());
@ -87,7 +91,7 @@ namespace BizHawk.MultiClient
temp = s.Substring(0, s.IndexOf('\t')); temp = s.Substring(0, s.IndexOf('\t'));
try try
{ {
w.address = int.Parse(temp, NumberStyles.HexNumber); w.Address = int.Parse(temp, NumberStyles.HexNumber);
} }
catch catch
{ {
@ -114,11 +118,11 @@ namespace BizHawk.MultiClient
continue; continue;
} }
if (y == 0) if (y == 0)
w.bigendian = false; w.BigEndian = false;
else else
w.bigendian = true; w.BigEndian = true;
w.notes = s.Substring(2, s.Length - 2); //User notes w.Notes = s.Substring(2, s.Length - 2); //User notes
watchList.Add(w); watchList.Add(w);
} }