diff --git a/BizHawk.Client.Common/tools/Watch.cs b/BizHawk.Client.Common/tools/Watch.cs index a3f10405b1..425d45d724 100644 --- a/BizHawk.Client.Common/tools/Watch.cs +++ b/BizHawk.Client.Common/tools/Watch.cs @@ -13,7 +13,7 @@ namespace BizHawk.Client.Common public abstract class Watch { public enum WatchSize { Byte = 1, Word = 2, DWord = 4, Separator = 0 } - public enum DisplayType { Separator, Signed, Unsigned, Hex, Binary, FixedPoint_12_4, FixedPoint_20_12, Float } + public enum DisplayType { Separator, Signed, Unsigned, Hex, Binary, FixedPoint_12_4, FixedPoint_20_12, FixedPoint_16_16, Float } public enum PreviousType { Original = 0, LastSearch = 1, LastFrame = 2, LastChange = 3 } public static string DisplayTypeToString(DisplayType type) @@ -26,6 +26,8 @@ namespace BizHawk.Client.Common return "Fixed Point 12.4"; case DisplayType.FixedPoint_20_12: return "Fixed Point 20.12"; + case DisplayType.FixedPoint_16_16: + return "Fixed Point 16.16"; } } @@ -39,6 +41,8 @@ namespace BizHawk.Client.Common return DisplayType.FixedPoint_12_4; case "Fixed Point 20.12": return DisplayType.FixedPoint_20_12; + case "Fixed Point 16.16": + return DisplayType.FixedPoint_16_16; } } @@ -130,6 +134,8 @@ namespace BizHawk.Client.Common return '1'; case DisplayType.FixedPoint_20_12: return '2'; + case DisplayType.FixedPoint_16_16: + return '3'; case DisplayType.Float: return 'f'; } @@ -155,6 +161,8 @@ namespace BizHawk.Client.Common return DisplayType.FixedPoint_12_4; case '2': return DisplayType.FixedPoint_20_12; + case '3': + return DisplayType.FixedPoint_16_16; case 'f': return DisplayType.Float; } @@ -970,7 +978,7 @@ namespace BizHawk.Client.Common { return new List { - DisplayType.Unsigned, DisplayType.Signed, DisplayType.Hex, DisplayType.FixedPoint_20_12, DisplayType.Float + DisplayType.Unsigned, DisplayType.Signed, DisplayType.Hex, DisplayType.FixedPoint_20_12, DisplayType.FixedPoint_16_16, DisplayType.Float }; } } @@ -1003,6 +1011,8 @@ namespace BizHawk.Client.Common return val.ToHexString(8); case DisplayType.FixedPoint_20_12: return string.Format("{0:0.######}", val / 4096.0); + case DisplayType.FixedPoint_16_16: + return string.Format("{0:0.######}", val / 65536.0); case DisplayType.Float: var bytes = BitConverter.GetBytes(val); var _float = BitConverter.ToSingle(bytes, 0); @@ -1061,6 +1071,17 @@ namespace BizHawk.Client.Common return false; } + break; + case DisplayType.FixedPoint_16_16: + if (value.IsFixedPoint()) + { + val = (uint)(int)(double.Parse(value) * 65536.0); + } + else + { + return false; + } + break; case DisplayType.Float: if (value.IsFloat()) diff --git a/BizHawk.Client.EmuHawk/tools/Watch/WatchValueBox.cs b/BizHawk.Client.EmuHawk/tools/Watch/WatchValueBox.cs index d4758485be..bf23acfbc3 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/WatchValueBox.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/WatchValueBox.cs @@ -123,6 +123,11 @@ namespace BizHawk.Client.EmuHawk get { return MaxUnsignedInt / 4096.0; } } + private double Max16_16 + { + get { return MaxUnsignedInt / 65536.0; } + } + private static double _12_4_Unit { get { return 1 / 16.0; } @@ -133,6 +138,11 @@ namespace BizHawk.Client.EmuHawk get { return 1 / 4096.0; } } + private static double _16_16_Unit + { + get { return 1 / 65536.0; } + } + public override void ResetText() { if (_nullable) @@ -153,6 +163,7 @@ namespace BizHawk.Client.EmuHawk break; case Watch.DisplayType.FixedPoint_12_4: case Watch.DisplayType.FixedPoint_20_12: + case Watch.DisplayType.FixedPoint_16_16: case Watch.DisplayType.Float: Text = "0.0"; break; @@ -238,6 +249,7 @@ namespace BizHawk.Client.EmuHawk MaxLength = 21; break; case Watch.DisplayType.FixedPoint_20_12: + case Watch.DisplayType.FixedPoint_16_16: MaxLength = 64; break; } @@ -279,6 +291,7 @@ namespace BizHawk.Client.EmuHawk break; case Watch.DisplayType.FixedPoint_12_4: case Watch.DisplayType.FixedPoint_20_12: + case Watch.DisplayType.FixedPoint_16_16: if (!e.KeyChar.IsFixedPoint()) { e.Handled = true; @@ -403,6 +416,19 @@ namespace BizHawk.Client.EmuHawk Text = f24val.ToString(); break; + case Watch.DisplayType.FixedPoint_16_16: + var f16val = double.Parse(text); + if (f16val >= Max16_16 - _16_16_Unit) + { + f16val = 0; + } + else + { + f16val += _16_16_Unit; + } + + Text = f16val.ToString(); + break; case Watch.DisplayType.Float: var dval = double.Parse(text); if (dval > double.MaxValue - 1) @@ -506,6 +532,19 @@ namespace BizHawk.Client.EmuHawk Text = f24val.ToString(); break; + case Watch.DisplayType.FixedPoint_16_16: + var f16val = double.Parse(text); + if (f16val < 0 + _16_16_Unit) + { + f16val = Max16_16; + } + else + { + f16val -= _16_16_Unit; + } + + Text = f16val.ToString(); + break; case Watch.DisplayType.Float: var dval = double.Parse(text); if (dval > double.MaxValue - 1) @@ -550,6 +589,7 @@ namespace BizHawk.Client.EmuHawk break; case Watch.DisplayType.FixedPoint_12_4: case Watch.DisplayType.FixedPoint_20_12: + case Watch.DisplayType.FixedPoint_16_16: Text = Text.OnlyFixedPoint(); break; case Watch.DisplayType.Float: @@ -615,6 +655,13 @@ namespace BizHawk.Client.EmuHawk return (int)(double.Parse(Text) * 4096.0); } + break; + case Watch.DisplayType.FixedPoint_16_16: + if (Text.IsFixedPoint()) + { + return (int)(double.Parse(Text) * 65536.0); + } + break; case Watch.DisplayType.Float: if (Text.IsFloat()) @@ -658,6 +705,9 @@ namespace BizHawk.Client.EmuHawk case Watch.DisplayType.FixedPoint_20_12: Text = string.Format("{0:F5}", val.Value / 4096.0); break; + case Watch.DisplayType.FixedPoint_16_16: + Text = string.Format("{0:F5}", val.Value / 65536.0); + break; case Watch.DisplayType.Float: var bytes = BitConverter.GetBytes(val.Value); float _float = BitConverter.ToSingle(bytes, 0);