Working types now allow implicit conversions from longs.

This commit is contained in:
upthorn 2019-01-03 05:52:31 -08:00
parent 01914552de
commit c76d850687
5 changed files with 45 additions and 89 deletions

View File

@ -1,52 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using BizHawk.Common.ReflectionExtensions;
using BizHawk.Emulation.Common;
using BizHawk.Client.ApiHawk;
namespace BizHawk.Client.EmuHawk
{
public static class ApiManager
{
private static ApiContainer container;
private static void Register(IEmulatorServiceProvider serviceProvider)
{
// Register external apis
var libs = Assembly
.Load("BizHawk.Client.ApiHawk")
.GetTypes()
.Where(t => typeof(IExternalApi).IsAssignableFrom(t))
.Where(t => t.IsSealed)
.Where(t => ServiceInjector.IsAvailable(serviceProvider, t))
.ToList();
libs.AddRange(
Assembly
.GetAssembly(typeof(ApiContainer))
.GetTypes()
.Where(t => typeof(IExternalApi).IsAssignableFrom(t))
.Where(t => t.IsSealed)
.Where(t => ServiceInjector.IsAvailable(serviceProvider, t)));
foreach (var lib in libs)
{
var instance = (IExternalApi)Activator.CreateInstance(lib);
ServiceInjector.UpdateServices(serviceProvider, instance);
Libraries.Add(lib, instance);
}
container = new ApiContainer(Libraries);
GlobalWin.ApiProvider = new BasicApiProvider(container);
}
private static readonly Dictionary<Type, IExternalApi> Libraries = new Dictionary<Type, IExternalApi>();
public static void Restart(IEmulatorServiceProvider newServiceProvider)
{
Libraries.Clear();
Register(newServiceProvider);
}
}
}

View File

@ -7,14 +7,18 @@ namespace BizHawk.Emulation.Common.WorkingTypes
{ {
// //
// Summary: // Summary:
// Represents an 8-bit unsigned integer, that is capable of arithmetic without making you weep. // 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. // 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> public unsafe class wbyte : IComparable, IFormattable, IComparable<wbyte>, IEquatable<wbyte>
{ {
private Byte val; private Byte val;
public const Byte MaxValue = Byte.MaxValue; public const Byte MaxValue = Byte.MaxValue;
public const Byte MinValue = Byte.MinValue; public const Byte MinValue = Byte.MinValue;
public static implicit operator wbyte(uint value) public static implicit operator wbyte(ulong value)
{
return new wbyte(value);
}
public static implicit operator wbyte(wushort value)
{ {
return new wbyte(value); return new wbyte(value);
} }
@ -26,33 +30,33 @@ namespace BizHawk.Emulation.Common.WorkingTypes
{ {
} }
public wbyte(uint value) public wbyte(ulong value)
{ {
val = (Byte)(value & 0xFF); val = (Byte)(value & 0xFF);
} }
public wbyte(int value) public wbyte(long value)
{ {
val = (Byte)(value & 0xFF); val = (Byte)(value & 0xFF);
} }
public wbyte(double value) public wbyte(double value)
{ {
val = (Byte)(((int)value) & 0xFF); val = (Byte)(((long)value) & 0xFF);
} }
public static wbyte Parse(string s, NumberStyles style, IFormatProvider provider) public static wbyte Parse(string s, NumberStyles style, IFormatProvider provider)
{ {
return (uint)Byte.Parse(s, style, provider); return (ulong)Byte.Parse(s, style, provider);
} }
public static wbyte Parse(string s, IFormatProvider provider) public static wbyte Parse(string s, IFormatProvider provider)
{ {
return (uint)Byte.Parse(s, provider); return (ulong)Byte.Parse(s, provider);
} }
public static wbyte Parse(string s) public static wbyte Parse(string s)
{ {
return (uint)Byte.Parse(s); return (ulong)Byte.Parse(s);
} }
public static wbyte Parse(string s, NumberStyles style) public static wbyte Parse(string s, NumberStyles style)
{ {
return (uint)Byte.Parse(s, style); return (ulong)Byte.Parse(s, style);
} }
public static bool TryParse(string s, out wbyte result) public static bool TryParse(string s, out wbyte result)
{ {

View File

@ -6,14 +6,14 @@ namespace BizHawk.Emulation.Common.WorkingTypes
{ {
// //
// Summary: // Summary:
// Represents an 8-bit unsigned integer, that is capable of arithmetic without making you weep. // 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. // 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> public unsafe class wsbyte : IComparable, IFormattable, IComparable<wsbyte>, IEquatable<wsbyte>
{ {
private SByte val; private SByte val;
public const SByte MaxValue = SByte.MaxValue; public const SByte MaxValue = SByte.MaxValue;
public const SByte MinValue = SByte.MinValue; public const SByte MinValue = SByte.MinValue;
public static implicit operator wsbyte(int value) public static implicit operator wsbyte(long value)
{ {
return new wsbyte(value); return new wsbyte(value);
} }
@ -25,33 +25,33 @@ namespace BizHawk.Emulation.Common.WorkingTypes
{ {
} }
public wsbyte(int value) public wsbyte(long value)
{ {
val = (SByte)(value & 0xFF); val = (SByte)(value & 0xFF);
} }
public wsbyte(uint value) public wsbyte(ulong value)
{ {
val = (SByte)(value & 0xFF); val = (SByte)(value & 0xFF);
} }
public wsbyte(double value) public wsbyte(double value)
{ {
val = (SByte)(((uint)value) & 0xFF); val = (SByte)(((ulong)value) & 0xFF);
} }
public static wsbyte Parse(string s, NumberStyles style, IFormatProvider provider) public static wsbyte Parse(string s, NumberStyles style, IFormatProvider provider)
{ {
return (int)SByte.Parse(s, style, provider); return (long)SByte.Parse(s, style, provider);
} }
public static wsbyte Parse(string s, IFormatProvider provider) public static wsbyte Parse(string s, IFormatProvider provider)
{ {
return (int)SByte.Parse(s, provider); return (long)SByte.Parse(s, provider);
} }
public static wsbyte Parse(string s) public static wsbyte Parse(string s)
{ {
return (int)SByte.Parse(s); return (long)SByte.Parse(s);
} }
public static wsbyte Parse(string s, NumberStyles style) public static wsbyte Parse(string s, NumberStyles style)
{ {
return (int)SByte.Parse(s, style); return (long)SByte.Parse(s, style);
} }
public static bool TryParse(string s, out wsbyte result) public static bool TryParse(string s, out wsbyte result)
{ {

View File

@ -6,14 +6,14 @@ namespace BizHawk.Emulation.Common.WorkingTypes
{ {
// //
// Summary: // Summary:
// Represents an 16-bit unsigned integer, that is capable of arithmetic without making you weep. // 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. // 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> public unsafe class wshort : IComparable, IFormattable, IComparable<wshort>, IEquatable<wshort>
{ {
private Int16 val; private Int16 val;
public const Int16 MaxValue = Int16.MaxValue; public const Int16 MaxValue = Int16.MaxValue;
public const Int16 MinValue = Int16.MinValue; public const Int16 MinValue = Int16.MinValue;
public static implicit operator wshort(int value) public static implicit operator wshort(long value)
{ {
return new wshort(value); return new wshort(value);
} }
@ -25,33 +25,33 @@ namespace BizHawk.Emulation.Common.WorkingTypes
{ {
} }
public wshort(int value) public wshort(long value)
{ {
val = (Int16)(value & 0xFFFF); val = (Int16)(value & 0xFFFF);
} }
public wshort(uint value) public wshort(ulong value)
{ {
val = (Int16)(value & 0xFFFF); val = (Int16)(value & 0xFFFF);
} }
public wshort(double value) public wshort(double value)
{ {
val = (Int16)(((uint)value) & 0xFFFF); val = (Int16)(((ulong)value) & 0xFFFF);
} }
public static wshort Parse(string s, NumberStyles style, IFormatProvider provider) public static wshort Parse(string s, NumberStyles style, IFormatProvider provider)
{ {
return (int)Int16.Parse(s, style, provider); return (long)Int16.Parse(s, style, provider);
} }
public static wshort Parse(string s, IFormatProvider provider) public static wshort Parse(string s, IFormatProvider provider)
{ {
return (int)Int16.Parse(s, provider); return (long)Int16.Parse(s, provider);
} }
public static wshort Parse(string s) public static wshort Parse(string s)
{ {
return (int)Int16.Parse(s); return (long)Int16.Parse(s);
} }
public static wshort Parse(string s, NumberStyles style) public static wshort Parse(string s, NumberStyles style)
{ {
return (int)Int16.Parse(s, style); return (long)Int16.Parse(s, style);
} }
public static bool TryParse(string s, out wshort result) public static bool TryParse(string s, out wshort result)
{ {

View File

@ -7,18 +7,22 @@ namespace BizHawk.Emulation.Common.WorkingTypes
{ {
// //
// Summary: // Summary:
// Represents an 16-bit unsigned integer, that is capable of arithmetic without making you weep. // 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. // 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> public unsafe class wushort : IComparable, IFormattable, IComparable<wushort>, IEquatable<wushort>
{ {
private UInt16 val; private UInt16 val;
public const UInt16 MaxValue = UInt16.MaxValue; public const UInt16 MaxValue = UInt16.MaxValue;
public const UInt16 MinValue = UInt16.MinValue; public const UInt16 MinValue = UInt16.MinValue;
public static implicit operator wushort(uint value) public static implicit operator wushort(ulong value)
{ {
return new wushort(value); return new wushort(value);
} }
public static implicit operator ushort(wushort value) public static implicit operator wushort(wbyte value)
{
return new wushort(value);
}
public static implicit operator UInt16(wushort value)
{ {
return value.val; return value.val;
} }
@ -26,17 +30,17 @@ namespace BizHawk.Emulation.Common.WorkingTypes
{ {
} }
public wushort(uint value) public wushort(ulong value)
{ {
val = (UInt16)(value & 0xFFFF); val = (UInt16)(value & 0xFFFF);
} }
public wushort(int value) public wushort(long value)
{ {
val = (UInt16)(value & 0xFFFF); val = (UInt16)(value & 0xFFFF);
} }
public wushort(double value) public wushort(double value)
{ {
val = (UInt16)(((int)value) & 0xFFFF); val = (UInt16)(((long)value) & 0xFFFF);
} }
public static wushort Parse(string s, NumberStyles style, IFormatProvider provider) public static wushort Parse(string s, NumberStyles style, IFormatProvider provider)
{ {