diff --git a/Assets/Plugins/Essgee/Emulation/Machines/ColecoVision.cs b/Assets/Plugins/Essgee/Emulation/Machines/ColecoVision.cs index 6f4d42e..d5d08af 100644 --- a/Assets/Plugins/Essgee/Emulation/Machines/ColecoVision.cs +++ b/Assets/Plugins/Essgee/Emulation/Machines/ColecoVision.cs @@ -218,19 +218,20 @@ namespace Essgee.Emulation.Machines psg?.Shutdown(); } - public void SetState(Dictionary state) - { - SaveStateHandler.PerformSetState(cartridge, state[nameof(cartridge)]); - wram = state[nameof(wram)]; - SaveStateHandler.PerformSetState(cpu, state[nameof(cpu)]); - SaveStateHandler.PerformSetState(vdp, state[nameof(vdp)]); - SaveStateHandler.PerformSetState(psg, state[nameof(psg)]); + //public void SetState(Dictionary state) + public void SetState(Dictionary state) + { + SaveStateHandler.PerformSetState(cartridge, (Dictionary)state[nameof(cartridge)]); + wram = (byte[])state[nameof(wram)]; + SaveStateHandler.PerformSetState(cpu, (Dictionary)state[nameof(cpu)]); + SaveStateHandler.PerformSetState(vdp, (Dictionary)state[nameof(vdp)]); + SaveStateHandler.PerformSetState(psg, (Dictionary)state[nameof(psg)]); - portControls1 = state[nameof(portControls1)]; - portControls2 = state[nameof(portControls2)]; - controlsReadMode = state[nameof(controlsReadMode)]; - isNmi = state[nameof(isNmi)]; - isNmiPending = state[nameof(isNmiPending)]; + portControls1 = (ushort)state[nameof(portControls1)]; + portControls2 = (ushort)state[nameof(portControls2)]; + controlsReadMode = (byte)state[nameof(controlsReadMode)]; + isNmi = (bool)state[nameof(isNmi)]; + isNmiPending = (bool)state[nameof(isNmiPending)]; ReconfigureSystem(); } diff --git a/Assets/Plugins/Essgee/Emulation/Machines/GameGear.cs b/Assets/Plugins/Essgee/Emulation/Machines/GameGear.cs index d50a7c2..0b514bf 100644 --- a/Assets/Plugins/Essgee/Emulation/Machines/GameGear.cs +++ b/Assets/Plugins/Essgee/Emulation/Machines/GameGear.cs @@ -242,29 +242,30 @@ namespace Essgee.Emulation.Machines psg?.Shutdown(); } - public void SetState(Dictionary state) - { - configuration.Region = state[nameof(configuration.Region)]; + //public void SetState(Dictionary state) + public void SetState(Dictionary state) + { + configuration.Region = (Region)state[nameof(configuration.Region)]; - SaveStateHandler.PerformSetState(bootstrap, state[nameof(bootstrap)]); - SaveStateHandler.PerformSetState(cartridge, state[nameof(cartridge)]); - wram = state[nameof(wram)]; - SaveStateHandler.PerformSetState(cpu, state[nameof(cpu)]); - SaveStateHandler.PerformSetState(vdp, state[nameof(vdp)]); - SaveStateHandler.PerformSetState(psg, state[nameof(psg)]); + SaveStateHandler.PerformSetState(bootstrap, (Dictionary)state[nameof(bootstrap)]); + SaveStateHandler.PerformSetState(cartridge, (Dictionary)state[nameof(cartridge)]); + wram = (byte[])state[nameof(wram)]; + SaveStateHandler.PerformSetState(cpu, (Dictionary)state[nameof(cpu)]); + SaveStateHandler.PerformSetState(vdp, (Dictionary)state[nameof(vdp)]); + SaveStateHandler.PerformSetState(psg, (Dictionary)state[nameof(psg)]); - portMemoryControl = state[nameof(portMemoryControl)]; - portIoControl = state[nameof(portIoControl)]; - hCounterLatched = state[nameof(hCounterLatched)]; - portIoAB = state[nameof(portIoAB)]; - portIoBMisc = state[nameof(portIoBMisc)]; + portMemoryControl = (byte)state[nameof(portMemoryControl)]; + portIoControl = (byte)state[nameof(portIoControl)]; + hCounterLatched = (byte)state[nameof(hCounterLatched)]; + portIoAB = (byte)state[nameof(portIoAB)]; + portIoBMisc = (byte)state[nameof(portIoBMisc)]; - portIoC = state[nameof(portIoC)]; - portParallelData = state[nameof(portParallelData)]; - portDataDirNMI = state[nameof(portDataDirNMI)]; - portTxBuffer = state[nameof(portTxBuffer)]; - portRxBuffer = state[nameof(portRxBuffer)]; - portSerialControl = state[nameof(portSerialControl)]; + portIoC = (byte)state[nameof(portIoC)]; + portParallelData = (byte)state[nameof(portParallelData)]; + portDataDirNMI = (byte)state[nameof(portDataDirNMI)]; + portTxBuffer = (byte)state[nameof(portTxBuffer)]; + portRxBuffer = (byte)state[nameof(portRxBuffer)]; + portSerialControl = (byte)state[nameof(portSerialControl)]; ReconfigureSystem(); } diff --git a/Assets/Plugins/Essgee/Emulation/Machines/MasterSystem.cs b/Assets/Plugins/Essgee/Emulation/Machines/MasterSystem.cs index 22d676c..2f3e6d5 100644 --- a/Assets/Plugins/Essgee/Emulation/Machines/MasterSystem.cs +++ b/Assets/Plugins/Essgee/Emulation/Machines/MasterSystem.cs @@ -263,24 +263,25 @@ namespace Essgee.Emulation.Machines psg?.Shutdown(); } - public void SetState(Dictionary state) - { - configuration.TVStandard = state[nameof(configuration.TVStandard)]; - configuration.Region = state[nameof(configuration.Region)]; + //public void SetState(Dictionary state) + public void SetState(Dictionary state) + { + configuration.TVStandard = (TVStandard)state[nameof(configuration.TVStandard)]; + configuration.Region = (Region)state[nameof(configuration.Region)]; - SaveStateHandler.PerformSetState(bootstrap, state[nameof(bootstrap)]); - SaveStateHandler.PerformSetState(cartridge, state[nameof(cartridge)]); - wram = state[nameof(wram)]; - SaveStateHandler.PerformSetState(cpu, state[nameof(cpu)]); - SaveStateHandler.PerformSetState(vdp, state[nameof(vdp)]); - SaveStateHandler.PerformSetState(psg, state[nameof(psg)]); + SaveStateHandler.PerformSetState(bootstrap, (Dictionary)state[nameof(bootstrap)]); + SaveStateHandler.PerformSetState(cartridge, (Dictionary)state[nameof(cartridge)]); + wram = (byte[])state[nameof(wram)]; + SaveStateHandler.PerformSetState(cpu, (Dictionary)state[nameof(cpu)]); + SaveStateHandler.PerformSetState(vdp, (Dictionary)state[nameof(vdp)]); + SaveStateHandler.PerformSetState(psg, (Dictionary)state[nameof(psg)]); - inputDevices = state[nameof(inputDevices)]; - lightgunLatched = state[nameof(lightgunLatched)]; + inputDevices = (InputDevice[])state[nameof(inputDevices)]; + lightgunLatched = (bool)state[nameof(lightgunLatched)]; - portMemoryControl = state[nameof(portMemoryControl)]; - portIoControl = state[nameof(portIoControl)]; - hCounterLatched = state[nameof(hCounterLatched)]; + portMemoryControl = (byte)state[nameof(portMemoryControl)]; + portIoControl = (byte)state[nameof(portIoControl)]; + hCounterLatched = (byte)state[nameof(hCounterLatched)]; ReconfigureSystem(); } diff --git a/Assets/Plugins/Essgee/Emulation/Machines/SC3000.cs b/Assets/Plugins/Essgee/Emulation/Machines/SC3000.cs index 53917b2..a5f22e9 100644 --- a/Assets/Plugins/Essgee/Emulation/Machines/SC3000.cs +++ b/Assets/Plugins/Essgee/Emulation/Machines/SC3000.cs @@ -246,18 +246,18 @@ namespace Essgee.Emulation.Machines psg?.Shutdown(); } - public void SetState(Dictionary state) - { - configuration.TVStandard = state[nameof(configuration.TVStandard)]; - - SaveStateHandler.PerformSetState(cartridge, state[nameof(cartridge)]); - wram = state[nameof(wram)]; - SaveStateHandler.PerformSetState(cpu, state[nameof(cpu)]); - SaveStateHandler.PerformSetState(vdp, state[nameof(vdp)]); - SaveStateHandler.PerformSetState(psg, state[nameof(psg)]); - SaveStateHandler.PerformSetState(ppi, state[nameof(ppi)]); - keyboard = state[nameof(keyboard)]; + //public void SetState(Dictionary state) + public void SetState(Dictionary state) + { + configuration.TVStandard = (TVStandard)state[nameof(configuration.TVStandard)]; + SaveStateHandler.PerformSetState(cartridge, (Dictionary)state[nameof(cartridge)]); + wram = (byte[])state[nameof(wram)]; + SaveStateHandler.PerformSetState(cpu, (Dictionary)state[nameof(cpu)]); + SaveStateHandler.PerformSetState(vdp, (Dictionary)state[nameof(vdp)]); + SaveStateHandler.PerformSetState(psg, (Dictionary)state[nameof(psg)]); + SaveStateHandler.PerformSetState(ppi, (Dictionary)state[nameof(ppi)]); + keyboard = (bool[,])(state[nameof(keyboard)]); ReconfigureSystem(); } diff --git a/Assets/Plugins/Essgee/Emulation/Machines/SG1000.cs b/Assets/Plugins/Essgee/Emulation/Machines/SG1000.cs index 5e83208..27ab860 100644 --- a/Assets/Plugins/Essgee/Emulation/Machines/SG1000.cs +++ b/Assets/Plugins/Essgee/Emulation/Machines/SG1000.cs @@ -221,15 +221,16 @@ namespace Essgee.Emulation.Machines psg?.Shutdown(); } - public void SetState(Dictionary state) - { - configuration.TVStandard = state[nameof(configuration.TVStandard)]; + //public void SetState(Dictionary state) + public void SetState(Dictionary state) + { + configuration.TVStandard = (TVStandard)state[nameof(configuration.TVStandard)]; - SaveStateHandler.PerformSetState(cartridge, state[nameof(cartridge)]); - wram = state[nameof(wram)]; - SaveStateHandler.PerformSetState(cpu, state[nameof(cpu)]); - SaveStateHandler.PerformSetState(vdp, state[nameof(vdp)]); - SaveStateHandler.PerformSetState(psg, state[nameof(psg)]); + SaveStateHandler.PerformSetState(cartridge, (Dictionary)state[nameof(cartridge)]); + wram = (byte[])state[nameof(wram)]; + SaveStateHandler.PerformSetState(cpu, (Dictionary)state[nameof(cpu)]); + SaveStateHandler.PerformSetState(vdp, (Dictionary)state[nameof(vdp)]); + SaveStateHandler.PerformSetState(psg, (Dictionary)state[nameof(psg)]); ReconfigureSystem(); } diff --git a/Assets/Plugins/Essgee/Emulation/SaveStateHandler.cs b/Assets/Plugins/Essgee/Emulation/SaveStateHandler.cs index 88444be..839c807 100644 --- a/Assets/Plugins/Essgee/Emulation/SaveStateHandler.cs +++ b/Assets/Plugins/Essgee/Emulation/SaveStateHandler.cs @@ -102,8 +102,10 @@ namespace Essgee.Emulation return machineId.Substring(0, Math.Min(machineId.Length, 16)).PadRight(16); } - public static void PerformSetState(object obj, Dictionary state) - { + //public static void PerformSetState(object obj, Dictionary state) + + public static void PerformSetState(object obj, Dictionary state) + { if (obj != null) { /* Restore property values from state */ @@ -120,11 +122,13 @@ namespace Essgee.Emulation } } - public static Dictionary PerformGetState(object obj) - { - var state = new Dictionary(); + //public static Dictionary PerformGetState(object obj) + public static Dictionary PerformGetState(object obj) + { + //var state = new Dictionary(); + var state = new Dictionary(); - if (obj != null) + if (obj != null) { /* Copy property values to state */ foreach (var prop in obj.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).Where(x => x.GetCustomAttributes(typeof(StateRequiredAttribute), false).Length != 0)) diff --git a/Assets/Plugins/Essgee/Graphics/FastMethodInvoker.cs b/Assets/Plugins/Essgee/Graphics/FastMethodInvoker.cs index 29cc4cb..121124b 100644 --- a/Assets/Plugins/Essgee/Graphics/FastMethodInvoker.cs +++ b/Assets/Plugins/Essgee/Graphics/FastMethodInvoker.cs @@ -1,140 +1,140 @@ -using System; -using System.Reflection; -using System.Reflection.Emit; +//using System; +//using System.Reflection; +//using System.Reflection.Emit; -namespace Essgee.Graphics -{ - /* http://www.codeproject.com/Articles/14593/A-General-Fast-Method-Invoker */ +//namespace Essgee.Graphics +//{ +// /* http://www.codeproject.com/Articles/14593/A-General-Fast-Method-Invoker */ - internal delegate object FastInvokeHandler(object target, object[] paramters); +// internal delegate object FastInvokeHandler(object target, object[] paramters); - internal class FastMethodInvoker - { - public static FastInvokeHandler GetMethodInvoker(MethodInfo methodInfo) - { - DynamicMethod dynamicMethod = new DynamicMethod(string.Empty, typeof(object), new Type[] { typeof(object), typeof(object[]) }, methodInfo.DeclaringType.Module); +// internal class FastMethodInvoker +// { +// public static FastInvokeHandler GetMethodInvoker(MethodInfo methodInfo) +// { +// DynamicMethod dynamicMethod = new DynamicMethod(string.Empty, typeof(object), new Type[] { typeof(object), typeof(object[]) }, methodInfo.DeclaringType.Module); - ILGenerator il = dynamicMethod.GetILGenerator(); - ParameterInfo[] ps = methodInfo.GetParameters(); +// ILGenerator il = dynamicMethod.GetILGenerator(); +// ParameterInfo[] ps = methodInfo.GetParameters(); - Type[] paramTypes = new Type[ps.Length]; - for (int i = 0; i < paramTypes.Length; i++) - { - if (ps[i].ParameterType.IsByRef) - paramTypes[i] = ps[i].ParameterType.GetElementType(); - else - paramTypes[i] = ps[i].ParameterType; - } +// Type[] paramTypes = new Type[ps.Length]; +// for (int i = 0; i < paramTypes.Length; i++) +// { +// if (ps[i].ParameterType.IsByRef) +// paramTypes[i] = ps[i].ParameterType.GetElementType(); +// else +// paramTypes[i] = ps[i].ParameterType; +// } - LocalBuilder[] locals = new LocalBuilder[paramTypes.Length]; - for (int i = 0; i < paramTypes.Length; i++) - locals[i] = il.DeclareLocal(paramTypes[i], true); +// LocalBuilder[] locals = new LocalBuilder[paramTypes.Length]; +// for (int i = 0; i < paramTypes.Length; i++) +// locals[i] = il.DeclareLocal(paramTypes[i], true); - for (int i = 0; i < paramTypes.Length; i++) - { - il.Emit(OpCodes.Ldarg_1); - EmitFastInt(il, i); - il.Emit(OpCodes.Ldelem_Ref); - EmitCastToReference(il, paramTypes[i]); - il.Emit(OpCodes.Stloc, locals[i]); - } +// for (int i = 0; i < paramTypes.Length; i++) +// { +// il.Emit(OpCodes.Ldarg_1); +// EmitFastInt(il, i); +// il.Emit(OpCodes.Ldelem_Ref); +// EmitCastToReference(il, paramTypes[i]); +// il.Emit(OpCodes.Stloc, locals[i]); +// } - if (!methodInfo.IsStatic) - il.Emit(OpCodes.Ldarg_0); +// if (!methodInfo.IsStatic) +// il.Emit(OpCodes.Ldarg_0); - for (int i = 0; i < paramTypes.Length; i++) - { - if (ps[i].ParameterType.IsByRef) - il.Emit(OpCodes.Ldloca_S, locals[i]); - else - il.Emit(OpCodes.Ldloc, locals[i]); - } +// for (int i = 0; i < paramTypes.Length; i++) +// { +// if (ps[i].ParameterType.IsByRef) +// il.Emit(OpCodes.Ldloca_S, locals[i]); +// else +// il.Emit(OpCodes.Ldloc, locals[i]); +// } - if (methodInfo.IsStatic) - il.EmitCall(OpCodes.Call, methodInfo, null); - else - il.EmitCall(OpCodes.Callvirt, methodInfo, null); +// if (methodInfo.IsStatic) +// il.EmitCall(OpCodes.Call, methodInfo, null); +// else +// il.EmitCall(OpCodes.Callvirt, methodInfo, null); - if (methodInfo.ReturnType == typeof(void)) - il.Emit(OpCodes.Ldnull); - else - EmitBoxIfNeeded(il, methodInfo.ReturnType); +// if (methodInfo.ReturnType == typeof(void)) +// il.Emit(OpCodes.Ldnull); +// else +// EmitBoxIfNeeded(il, methodInfo.ReturnType); - for (int i = 0; i < paramTypes.Length; i++) - { - if (ps[i].ParameterType.IsByRef) - { - il.Emit(OpCodes.Ldarg_1); - EmitFastInt(il, i); - il.Emit(OpCodes.Ldloc, locals[i]); +// for (int i = 0; i < paramTypes.Length; i++) +// { +// if (ps[i].ParameterType.IsByRef) +// { +// il.Emit(OpCodes.Ldarg_1); +// EmitFastInt(il, i); +// il.Emit(OpCodes.Ldloc, locals[i]); - if (locals[i].LocalType.IsValueType) - il.Emit(OpCodes.Box, locals[i].LocalType); +// if (locals[i].LocalType.IsValueType) +// il.Emit(OpCodes.Box, locals[i].LocalType); - il.Emit(OpCodes.Stelem_Ref); - } - } +// il.Emit(OpCodes.Stelem_Ref); +// } +// } - il.Emit(OpCodes.Ret); +// il.Emit(OpCodes.Ret); - FastInvokeHandler invoder = (FastInvokeHandler)dynamicMethod.CreateDelegate(typeof(FastInvokeHandler)); - return invoder; - } +// FastInvokeHandler invoder = (FastInvokeHandler)dynamicMethod.CreateDelegate(typeof(FastInvokeHandler)); +// return invoder; +// } - private static void EmitCastToReference(ILGenerator il, Type type) - { - if (type.IsValueType) - il.Emit(OpCodes.Unbox_Any, type); - else - il.Emit(OpCodes.Castclass, type); - } +// private static void EmitCastToReference(ILGenerator il, Type type) +// { +// if (type.IsValueType) +// il.Emit(OpCodes.Unbox_Any, type); +// else +// il.Emit(OpCodes.Castclass, type); +// } - private static void EmitBoxIfNeeded(ILGenerator il, Type type) - { - if (type.IsValueType) - il.Emit(OpCodes.Box, type); - } +// private static void EmitBoxIfNeeded(ILGenerator il, Type type) +// { +// if (type.IsValueType) +// il.Emit(OpCodes.Box, type); +// } - private static void EmitFastInt(ILGenerator il, int value) - { - switch (value) - { - case -1: - il.Emit(OpCodes.Ldc_I4_M1); - return; - case 0: - il.Emit(OpCodes.Ldc_I4_0); - return; - case 1: - il.Emit(OpCodes.Ldc_I4_1); - return; - case 2: - il.Emit(OpCodes.Ldc_I4_2); - return; - case 3: - il.Emit(OpCodes.Ldc_I4_3); - return; - case 4: - il.Emit(OpCodes.Ldc_I4_4); - return; - case 5: - il.Emit(OpCodes.Ldc_I4_5); - return; - case 6: - il.Emit(OpCodes.Ldc_I4_6); - return; - case 7: - il.Emit(OpCodes.Ldc_I4_7); - return; - case 8: - il.Emit(OpCodes.Ldc_I4_8); - return; - } +// private static void EmitFastInt(ILGenerator il, int value) +// { +// switch (value) +// { +// case -1: +// il.Emit(OpCodes.Ldc_I4_M1); +// return; +// case 0: +// il.Emit(OpCodes.Ldc_I4_0); +// return; +// case 1: +// il.Emit(OpCodes.Ldc_I4_1); +// return; +// case 2: +// il.Emit(OpCodes.Ldc_I4_2); +// return; +// case 3: +// il.Emit(OpCodes.Ldc_I4_3); +// return; +// case 4: +// il.Emit(OpCodes.Ldc_I4_4); +// return; +// case 5: +// il.Emit(OpCodes.Ldc_I4_5); +// return; +// case 6: +// il.Emit(OpCodes.Ldc_I4_6); +// return; +// case 7: +// il.Emit(OpCodes.Ldc_I4_7); +// return; +// case 8: +// il.Emit(OpCodes.Ldc_I4_8); +// return; +// } - if (value > -129 && value < 128) - il.Emit(OpCodes.Ldc_I4_S, (sbyte)value); - else - il.Emit(OpCodes.Ldc_I4, value); - } - } -} +// if (value > -129 && value < 128) +// il.Emit(OpCodes.Ldc_I4_S, (sbyte)value); +// else +// il.Emit(OpCodes.Ldc_I4, value); +// } +// } +//}