From b9d35399b7b75b7dd7ce451488c0265080875097 Mon Sep 17 00:00:00 2001 From: upthorn Date: Sun, 23 Dec 2018 00:46:20 -0800 Subject: [PATCH] Created some working small integers to bypass C#'s hatred of 8bit and 16bit arithmetic. --- .../BizHawk.Emulation.Common.csproj | 4 + .../WorkingTypes/wbyte.cs | 112 ++++++++++++++++++ .../WorkingTypes/wsbyte.cs | 111 +++++++++++++++++ .../WorkingTypes/wshort.cs | 111 +++++++++++++++++ .../WorkingTypes/wushort.cs | 112 ++++++++++++++++++ 5 files changed, 450 insertions(+) create mode 100644 BizHawk.Emulation.Common/WorkingTypes/wbyte.cs create mode 100644 BizHawk.Emulation.Common/WorkingTypes/wsbyte.cs create mode 100644 BizHawk.Emulation.Common/WorkingTypes/wshort.cs create mode 100644 BizHawk.Emulation.Common/WorkingTypes/wushort.cs diff --git a/BizHawk.Emulation.Common/BizHawk.Emulation.Common.csproj b/BizHawk.Emulation.Common/BizHawk.Emulation.Common.csproj index 0a8aa6ec09..7287faab8b 100644 --- a/BizHawk.Emulation.Common/BizHawk.Emulation.Common.csproj +++ b/BizHawk.Emulation.Common/BizHawk.Emulation.Common.csproj @@ -121,6 +121,10 @@ + + + + diff --git a/BizHawk.Emulation.Common/WorkingTypes/wbyte.cs b/BizHawk.Emulation.Common/WorkingTypes/wbyte.cs new file mode 100644 index 0000000000..f09a152bd6 --- /dev/null +++ b/BizHawk.Emulation.Common/WorkingTypes/wbyte.cs @@ -0,0 +1,112 @@ +using System; +using System.Globalization; +using System.Security; + + +namespace BizHawk.Emulation.Common.WorkingTypes +{ + // + // Summary: + // Represents an 8-bit unsigned integer, that is capable of arithmetic without making you weep. + // Also provides all the base functionality of the standard C# Byte by calling its methods where relevant. + public unsafe class wbyte : IComparable, IFormattable, IComparable, IEquatable + { + private Byte val; + public const Byte MaxValue = Byte.MaxValue; + public const Byte MinValue = Byte.MinValue; + public static implicit operator wbyte(uint value) + { + return value; + } + public static implicit operator byte(wbyte value) + { + return value.val; + } + public wbyte() + { + + } + public wbyte(uint value) + { + val = (Byte)(value & 0xFF); + } + public wbyte(int value) + { + val = (Byte)(value & 0xFF); + } + public wbyte(double value) + { + val = (Byte)(((int)value) & 0xFF); + } + public static wbyte Parse(string s, NumberStyles style, IFormatProvider provider) + { + return (uint)Byte.Parse(s, style, provider); + } + public static wbyte Parse(string s, IFormatProvider provider) + { + return (uint)Byte.Parse(s, provider); + } + public static wbyte Parse(string s) + { + return (uint)Byte.Parse(s); + } + public static wbyte Parse(string s, NumberStyles style) + { + return (uint)Byte.Parse(s, style); + } + public static bool TryParse(string s, out wbyte result) + { + result = new wbyte(); + return byte.TryParse(s, out result.val); + } + public static bool TryParse(string s, NumberStyles style, IFormatProvider provider, out wbyte result) + { + result = new wbyte(); + return byte.TryParse(s, style, provider, out result.val); + } + public int CompareTo(wbyte value) + { + return val.CompareTo(value.val); + } + public int CompareTo(object value) + { + return val.CompareTo(value); + } + public override bool Equals(object obj) + { + return val.Equals(obj); + } + public bool Equals(wbyte obj) + { + return val.Equals(obj); + } + public override int GetHashCode() + { + return val.GetHashCode(); + } + public TypeCode GetTypeCode() + { + return val.GetTypeCode(); + } + [SecuritySafeCritical] + public string ToString(string format, IFormatProvider provider) + { + return val.ToString(format, provider); + } + [SecuritySafeCritical] + public override string ToString() + { + return val.ToString(); + } + [SecuritySafeCritical] + public string ToString(string format) + { + return val.ToString(format); + } + [SecuritySafeCritical] + public string ToString(IFormatProvider provider) + { + return val.ToString(provider); + } + } +} \ No newline at end of file diff --git a/BizHawk.Emulation.Common/WorkingTypes/wsbyte.cs b/BizHawk.Emulation.Common/WorkingTypes/wsbyte.cs new file mode 100644 index 0000000000..859b0a563c --- /dev/null +++ b/BizHawk.Emulation.Common/WorkingTypes/wsbyte.cs @@ -0,0 +1,111 @@ +using System; +using System.Globalization; +using System.Security; + +namespace BizHawk.Emulation.Common.WorkingTypes +{ + // + // Summary: + // Represents an 8-bit unsigned integer, that is capable of arithmetic without making you weep. + // Also provides all the base functionality of the standard C# SByte by calling its methods where relevant. + public unsafe class wsbyte : IComparable, IFormattable, IComparable, IEquatable + { + private SByte val; + public const SByte MaxValue = SByte.MaxValue; + public const SByte MinValue = SByte.MinValue; + public static implicit operator wsbyte(int value) + { + return value; + } + public static implicit operator SByte(wsbyte value) + { + return value.val; + } + public wsbyte() + { + + } + public wsbyte(int value) + { + val = (SByte)(value & 0xFF); + } + public wsbyte(uint value) + { + val = (SByte)(value & 0xFF); + } + public wsbyte(double value) + { + val = (SByte)(((uint)value) & 0xFF); + } + public static wsbyte Parse(string s, NumberStyles style, IFormatProvider provider) + { + return (int)SByte.Parse(s, style, provider); + } + public static wsbyte Parse(string s, IFormatProvider provider) + { + return (int)SByte.Parse(s, provider); + } + public static wsbyte Parse(string s) + { + return (int)SByte.Parse(s); + } + public static wsbyte Parse(string s, NumberStyles style) + { + return (int)SByte.Parse(s, style); + } + public static bool TryParse(string s, out wsbyte result) + { + result = new wsbyte(); + return SByte.TryParse(s, out result.val); + } + public static bool TryParse(string s, NumberStyles style, IFormatProvider provider, out wsbyte result) + { + result = new wsbyte(); + return SByte.TryParse(s, style, provider, out result.val); + } + public int CompareTo(wsbyte value) + { + return val.CompareTo(value.val); + } + public int CompareTo(object value) + { + return val.CompareTo(value); + } + public override bool Equals(object obj) + { + return val.Equals(obj); + } + public bool Equals(wsbyte obj) + { + return val.Equals(obj); + } + public override int GetHashCode() + { + return val.GetHashCode(); + } + public TypeCode GetTypeCode() + { + return val.GetTypeCode(); + } + [SecuritySafeCritical] + public string ToString(string format, IFormatProvider provider) + { + return val.ToString(format, provider); + } + [SecuritySafeCritical] + public override string ToString() + { + return val.ToString(); + } + [SecuritySafeCritical] + public string ToString(string format) + { + return val.ToString(format); + } + [SecuritySafeCritical] + public string ToString(IFormatProvider provider) + { + return val.ToString(provider); + } + } +} \ No newline at end of file diff --git a/BizHawk.Emulation.Common/WorkingTypes/wshort.cs b/BizHawk.Emulation.Common/WorkingTypes/wshort.cs new file mode 100644 index 0000000000..04040691b9 --- /dev/null +++ b/BizHawk.Emulation.Common/WorkingTypes/wshort.cs @@ -0,0 +1,111 @@ +using System; +using System.Globalization; +using System.Security; + +namespace BizHawk.Emulation.Common.WorkingTypes +{ + // + // Summary: + // Represents an 16-bit unsigned integer, that is capable of arithmetic without making you weep. + // Also provides all the base functionality of the standard C# Int16 by calling its methods where relevant. + public unsafe class wshort : IComparable, IFormattable, IComparable, IEquatable + { + private Int16 val; + public const Int16 MaxValue = Int16.MaxValue; + public const Int16 MinValue = Int16.MinValue; + public static implicit operator wshort(int value) + { + return value; + } + public static implicit operator Int16(wshort value) + { + return value.val; + } + public wshort() + { + + } + public wshort(int value) + { + val = (Int16)(value & 0xFFFF); + } + public wshort(uint value) + { + val = (Int16)(value & 0xFFFF); + } + public wshort(double value) + { + val = (Int16)(((uint)value) & 0xFFFF); + } + public static wshort Parse(string s, NumberStyles style, IFormatProvider provider) + { + return (int)Int16.Parse(s, style, provider); + } + public static wshort Parse(string s, IFormatProvider provider) + { + return (int)Int16.Parse(s, provider); + } + public static wshort Parse(string s) + { + return (int)Int16.Parse(s); + } + public static wshort Parse(string s, NumberStyles style) + { + return (int)Int16.Parse(s, style); + } + public static bool TryParse(string s, out wshort result) + { + result = new wshort(); + return Int16.TryParse(s, out result.val); + } + public static bool TryParse(string s, NumberStyles style, IFormatProvider provider, out wshort result) + { + result = new wshort(); + return Int16.TryParse(s, style, provider, out result.val); + } + public int CompareTo(wshort value) + { + return val.CompareTo(value.val); + } + public int CompareTo(object value) + { + return val.CompareTo(value); + } + public override bool Equals(object obj) + { + return val.Equals(obj); + } + public bool Equals(wshort obj) + { + return val.Equals(obj); + } + public override int GetHashCode() + { + return val.GetHashCode(); + } + public TypeCode GetTypeCode() + { + return val.GetTypeCode(); + } + [SecuritySafeCritical] + public string ToString(string format, IFormatProvider provider) + { + return val.ToString(format, provider); + } + [SecuritySafeCritical] + public override string ToString() + { + return val.ToString(); + } + [SecuritySafeCritical] + public string ToString(string format) + { + return val.ToString(format); + } + [SecuritySafeCritical] + public string ToString(IFormatProvider provider) + { + return val.ToString(provider); + } + } +} \ No newline at end of file diff --git a/BizHawk.Emulation.Common/WorkingTypes/wushort.cs b/BizHawk.Emulation.Common/WorkingTypes/wushort.cs new file mode 100644 index 0000000000..3e5a84abe3 --- /dev/null +++ b/BizHawk.Emulation.Common/WorkingTypes/wushort.cs @@ -0,0 +1,112 @@ +using System; +using System.Globalization; +using System.Security; + + +namespace BizHawk.Emulation.Common.WorkingTypes +{ + // + // Summary: + // Represents an 16-bit unsigned integer, that is capable of arithmetic without making you weep. + // Also provides all the base functionality of the standard C# UInt16 by calling its methods where relevant. + public unsafe class wushort : IComparable, IFormattable, IComparable, IEquatable + { + private UInt16 val; + public const UInt16 MaxValue = UInt16.MaxValue; + public const UInt16 MinValue = UInt16.MinValue; + public static implicit operator wushort(uint value) + { + return value; + } + public static implicit operator ushort(wushort value) + { + return value.val; + } + public wushort() + { + + } + public wushort(uint value) + { + val = (UInt16)(value & 0xFFFF); + } + public wushort(int value) + { + val = (UInt16)(value & 0xFFFF); + } + public wushort(double value) + { + val = (UInt16)(((int)value) & 0xFFFF); + } + public static wushort Parse(string s, NumberStyles style, IFormatProvider provider) + { + return (uint)UInt16.Parse(s, style, provider); + } + public static wushort Parse(string s, IFormatProvider provider) + { + return (uint)UInt16.Parse(s, provider); + } + public static wushort Parse(string s) + { + return (uint)UInt16.Parse(s); + } + public static wushort Parse(string s, NumberStyles style) + { + return (uint)UInt16.Parse(s, style); + } + public static bool TryParse(string s, out wushort result) + { + result = new wushort(); + return ushort.TryParse(s, out result.val); + } + public static bool TryParse(string s, NumberStyles style, IFormatProvider provider, out wushort result) + { + result = new wushort(); + return ushort.TryParse(s, style, provider, out result.val); + } + public int CompareTo(wushort value) + { + return val.CompareTo(value.val); + } + public int CompareTo(object value) + { + return val.CompareTo(value); + } + public override bool Equals(object obj) + { + return val.Equals(obj); + } + public bool Equals(wushort obj) + { + return val.Equals(obj); + } + public override int GetHashCode() + { + return val.GetHashCode(); + } + public TypeCode GetTypeCode() + { + return val.GetTypeCode(); + } + [SecuritySafeCritical] + public string ToString(string format, IFormatProvider provider) + { + return val.ToString(format, provider); + } + [SecuritySafeCritical] + public override string ToString() + { + return val.ToString(); + } + [SecuritySafeCritical] + public string ToString(string format) + { + return val.ToString(format); + } + [SecuritySafeCritical] + public string ToString(IFormatProvider provider) + { + return val.ToString(provider); + } + } +} \ No newline at end of file