From 20087cd80483f36dc6bad57f29285d48575ea577 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Sun, 3 Mar 2019 17:52:47 +1000 Subject: [PATCH 1/4] Use string interpolation with {0:P;M;Z} format string --- .../tools/Watch/ByteWatch.cs | 19 +------------------ .../tools/Watch/WordWatch.cs | 19 +------------------ 2 files changed, 2 insertions(+), 36 deletions(-) diff --git a/BizHawk.Client.Common/tools/Watch/ByteWatch.cs b/BizHawk.Client.Common/tools/Watch/ByteWatch.cs index 7d6c53738c..e576b01edd 100644 --- a/BizHawk.Client.Common/tools/Watch/ByteWatch.cs +++ b/BizHawk.Client.Common/tools/Watch/ByteWatch.cs @@ -200,24 +200,7 @@ namespace BizHawk.Client.Common /// Get a string representation of difference /// between current value and the previous one /// - public override string Diff - { - get - { - string diff = ""; - int diffVal = _value - _previous; - if (diffVal > 0) - { - diff = "+"; - } - else if (diffVal < 0) - { - diff = "-"; - } - - return $"{diff}{((byte)Math.Abs(diffVal))}"; - } - } + public override string Diff => $"{(byte)Math.Abs(_value - _previous):+G;-G;G}"; /// /// Get the maximum possible value diff --git a/BizHawk.Client.Common/tools/Watch/WordWatch.cs b/BizHawk.Client.Common/tools/Watch/WordWatch.cs index 968e81e0f8..1fb49b7823 100644 --- a/BizHawk.Client.Common/tools/Watch/WordWatch.cs +++ b/BizHawk.Client.Common/tools/Watch/WordWatch.cs @@ -214,24 +214,7 @@ namespace BizHawk.Client.Common /// Get a string representation of difference /// between current value and the previous one /// - public override string Diff - { - get - { - string diff = ""; - int diffVal = _value - _previous; - if (diffVal > 0) - { - diff = "+"; - } - else if (diffVal < 0) - { - diff = "-"; - } - - return $"{diff}{((ushort)Math.Abs(diffVal))}"; - } - } + public override string Diff => $"{(ushort)Math.Abs(_value - _previous):+G;-G;G}"; /// /// Get the maximum possible value From 2f3ac59c7a71750d263cd64248348e451dc4acf2 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Sun, 3 Mar 2019 17:55:25 +1000 Subject: [PATCH 2/4] Inline local vars, use interpolated strings, and use {0:P;M} format string --- .../CPUs/Z80A/NewDisassembler.cs | 23 +++---------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/BizHawk.Emulation.Cores/CPUs/Z80A/NewDisassembler.cs b/BizHawk.Emulation.Cores/CPUs/Z80A/NewDisassembler.cs index 8bc3938c7d..89fe556df5 100644 --- a/BizHawk.Emulation.Cores/CPUs/Z80A/NewDisassembler.cs +++ b/BizHawk.Emulation.Cores/CPUs/Z80A/NewDisassembler.cs @@ -12,29 +12,12 @@ namespace BizHawk.Emulation.Cores.Components.Z80A //d immediately succeeds the opcode //n immediate succeeds the opcode and the displacement (if present) //nn immediately succeeds the opcode and the displacement (if present) - if (format.IndexOf("nn") != -1) - { - byte B = read(addr++); - byte C = read(addr++); - format = format.Replace("nn", string.Format("{0:X4}h", B + C * 256)); - } - if (format.IndexOf("n") != -1) - { - byte B = read(addr++); - format = format.Replace("n", string.Format("{0:X2}h", B)); - } + if (format.IndexOf("nn") != -1) format = format.Replace("nn", $"{read(addr++) + (read(addr++) << 8):X4}h"); // LSB is read first + if (format.IndexOf("n") != -1) format = format.Replace("n", $"{read(addr++):X2}h"); if (format.IndexOf("+d") != -1) format = format.Replace("+d", "d"); - - if (format.IndexOf("d") != -1) - { - byte B = read(addr++); - bool neg = ((B & 0x80) != 0); - char sign = neg ? '-' : '+'; - int val = neg ? 256 - B : B; - format = format.Replace("d", string.Format("{0}{1:X2}h", sign, val)); - } + if (format.IndexOf("d") != -1) format = format.Replace("d", $"{(sbyte)read(addr++):+X2;-X2}h"); return format; } From 5412a7489070d5a75967271c69739f606a895c8a Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Tue, 5 Mar 2019 19:16:20 +1000 Subject: [PATCH 3/4] Use the *correct* formatting string, skip calls to Math.Abs --- BizHawk.Client.Common/tools/Watch/ByteWatch.cs | 2 +- BizHawk.Client.Common/tools/Watch/DWordWatch.cs | 2 +- BizHawk.Client.Common/tools/Watch/WordWatch.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/BizHawk.Client.Common/tools/Watch/ByteWatch.cs b/BizHawk.Client.Common/tools/Watch/ByteWatch.cs index e576b01edd..50531248ba 100644 --- a/BizHawk.Client.Common/tools/Watch/ByteWatch.cs +++ b/BizHawk.Client.Common/tools/Watch/ByteWatch.cs @@ -200,7 +200,7 @@ namespace BizHawk.Client.Common /// Get a string representation of difference /// between current value and the previous one /// - public override string Diff => $"{(byte)Math.Abs(_value - _previous):+G;-G;G}"; + public override string Diff => $"{_value - (short)_previous:+#;-#;0}"; /// /// Get the maximum possible value diff --git a/BizHawk.Client.Common/tools/Watch/DWordWatch.cs b/BizHawk.Client.Common/tools/Watch/DWordWatch.cs index 79a9ef03aa..360966dac0 100644 --- a/BizHawk.Client.Common/tools/Watch/DWordWatch.cs +++ b/BizHawk.Client.Common/tools/Watch/DWordWatch.cs @@ -231,7 +231,7 @@ namespace BizHawk.Client.Common /// Get a string representation of difference /// between current value and the previous one /// - public override string Diff => (_previous - _value).ToString(); + public override string Diff => $"{_value - (long)_previous:+#;-#;0}"; /// /// Get the maximum possible value diff --git a/BizHawk.Client.Common/tools/Watch/WordWatch.cs b/BizHawk.Client.Common/tools/Watch/WordWatch.cs index 1fb49b7823..be6d461bf4 100644 --- a/BizHawk.Client.Common/tools/Watch/WordWatch.cs +++ b/BizHawk.Client.Common/tools/Watch/WordWatch.cs @@ -214,7 +214,7 @@ namespace BizHawk.Client.Common /// Get a string representation of difference /// between current value and the previous one /// - public override string Diff => $"{(ushort)Math.Abs(_value - _previous):+G;-G;G}"; + public override string Diff => $"{_value - (int)_previous:+#;-#;0}"; /// /// Get the maximum possible value From 0b5a61dcd3b558659b70088fa467867688cd4398 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Tue, 5 Mar 2019 19:37:59 +1000 Subject: [PATCH 4/4] Rewrite "d" replacement again but more like the previous algorithm --- BizHawk.Emulation.Cores/CPUs/Z80A/NewDisassembler.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/BizHawk.Emulation.Cores/CPUs/Z80A/NewDisassembler.cs b/BizHawk.Emulation.Cores/CPUs/Z80A/NewDisassembler.cs index 89fe556df5..aef7dc8ec5 100644 --- a/BizHawk.Emulation.Cores/CPUs/Z80A/NewDisassembler.cs +++ b/BizHawk.Emulation.Cores/CPUs/Z80A/NewDisassembler.cs @@ -17,7 +17,11 @@ namespace BizHawk.Emulation.Cores.Components.Z80A if (format.IndexOf("n") != -1) format = format.Replace("n", $"{read(addr++):X2}h"); if (format.IndexOf("+d") != -1) format = format.Replace("+d", "d"); - if (format.IndexOf("d") != -1) format = format.Replace("d", $"{(sbyte)read(addr++):+X2;-X2}h"); + if (format.IndexOf("d") != -1) + { + var b = unchecked ((sbyte) read(addr++)); + format = format.Replace("d", $"{(b < 0 ? '-' : '+')}{(b < 0 ? -b : b):X2}h"); + } return format; }