Created some working small integers to bypass C#'s hatred of 8bit and 16bit arithmetic.

This commit is contained in:
upthorn 2018-12-23 00:46:20 -08:00
parent 3b1fd8fec6
commit b9d35399b7
5 changed files with 450 additions and 0 deletions

View File

@ -121,6 +121,10 @@
<Compile Include="Sound\Utilities\Waves.cs" />
<Compile Include="SystemLookup.cs" />
<Compile Include="TextState.cs" />
<Compile Include="WorkingTypes\wshort.cs" />
<Compile Include="WorkingTypes\wushort.cs" />
<Compile Include="WorkingTypes\wsbyte.cs" />
<Compile Include="WorkingTypes\wbyte.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BizHawk.Common\BizHawk.Common.csproj">

View File

@ -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<wbyte>, IEquatable<wbyte>
{
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);
}
}
}

View File

@ -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<wsbyte>, IEquatable<wsbyte>
{
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);
}
}
}

View File

@ -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<wshort>, IEquatable<wshort>
{
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);
}
}
}

View File

@ -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<wushort>, IEquatable<wushort>
{
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);
}
}
}