From 73add14d2833a121e950ac18cc26e83db7e3d4a3 Mon Sep 17 00:00:00 2001 From: "andres.delikat" Date: Mon, 12 Sep 2011 00:17:17 +0000 Subject: [PATCH] Watch object - add ValueToString() and PrevToString() methods and make Ram Watch use these methods and thus simplify the UpdateValues logic. Added an override for ToString() that displays notes + value in preparation for a on screen ram watch option. --- BizHawk.MultiClient/tools/RamWatch.cs | 55 ++-------------------- BizHawk.MultiClient/tools/Watch.cs | 67 +++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 52 deletions(-) diff --git a/BizHawk.MultiClient/tools/RamWatch.cs b/BizHawk.MultiClient/tools/RamWatch.cs index 7d62c5dd4e..b8e81c2f44 100644 --- a/BizHawk.MultiClient/tools/RamWatch.cs +++ b/BizHawk.MultiClient/tools/RamWatch.cs @@ -153,7 +153,7 @@ namespace BizHawk.MultiClient e.Cancel = true; base.OnClosing(e); } - + private void WatchListView_QueryItemBkColor(int index, int column, ref Color color) { if (column == 0) @@ -177,34 +177,7 @@ namespace BizHawk.MultiClient } if (column == 1) //Value { - if (watchList[index].type == atype.SEPARATOR) - text = ""; - else - { - switch (watchList[index].signed) - { - case asigned.HEX: - switch (watchList[index].type) - { - case atype.BYTE: - text = String.Format("{0:X2}", watchList[index].value); - break; - case atype.WORD: - text = String.Format("{0:X4}", watchList[index].value); - break; - case atype.DWORD: - text = String.Format("{0:X8}", watchList[index].value); - break; - } - break; - case asigned.SIGNED: - text = ((sbyte)watchList[index].value).ToString(); - break; - case asigned.UNSIGNED: - text = watchList[index].value.ToString(); - break; - } - } + text = watchList[index].ValueToString(); } if (column == 2) //Prev { @@ -222,29 +195,7 @@ namespace BizHawk.MultiClient } else { - switch (watchList[index].signed) - { - case asigned.HEX: - switch (watchList[index].type) - { - case atype.BYTE: - text = String.Format("{0:X2}", watchList[index].prev); - break; - case atype.WORD: - text = String.Format("{0:X4}", watchList[index].prev); - break; - case atype.DWORD: - text = String.Format("{0:X8}", watchList[index].prev); - break; - } - break; - case asigned.SIGNED: - text = ((sbyte)watchList[index].prev).ToString(); - break; - case asigned.UNSIGNED: - text = watchList[index].prev.ToString(); - break; - } + text = watchList[index].PrevToString(); } } } diff --git a/BizHawk.MultiClient/tools/Watch.cs b/BizHawk.MultiClient/tools/Watch.cs index d36b1c0973..22de490400 100644 --- a/BizHawk.MultiClient/tools/Watch.cs +++ b/BizHawk.MultiClient/tools/Watch.cs @@ -231,6 +231,73 @@ namespace BizHawk.MultiClient } } + public override string ToString() + { + if (type == atype.SEPARATOR) + return ""; + + StringBuilder str = new StringBuilder(notes); + str.Append(": "); + str.Append(ValueToString()); + return str.ToString(); + } + + public string ValueToString() + { + if (type == atype.SEPARATOR) + return ""; + else + { + switch (signed) + { + case asigned.HEX: + switch (type) + { + default: + case atype.BYTE: + return String.Format("{0:X2}", value); + case atype.WORD: + return String.Format("{0:X4}", value); + case atype.DWORD: + return String.Format("{0:X8}", value); + } + case asigned.SIGNED: + return ((sbyte)value).ToString(); + default: + case asigned.UNSIGNED: + return value.ToString(); + } + } + } + + public string PrevToString() + { + if (type == atype.SEPARATOR) + return ""; + else + { + switch (signed) + { + case asigned.HEX: + switch (type) + { + default: + case atype.BYTE: + return String.Format("{0:X2}", prev); + case atype.WORD: + return String.Format("{0:X4}", prev); + case atype.DWORD: + return String.Format("{0:X8}", prev); + } + case asigned.SIGNED: + return ((sbyte)prev).ToString(); + default: + case asigned.UNSIGNED: + return prev.ToString(); + } + } + } + private int CompareAddress(Watch Other) { if (this.address < Other.address)