diff --git a/BizHawk.Emulation.Common/Interfaces/IDebuggable.cs b/BizHawk.Emulation.Common/Interfaces/IDebuggable.cs index 2f680eaa62..15504e236e 100644 --- a/BizHawk.Emulation.Common/Interfaces/IDebuggable.cs +++ b/BizHawk.Emulation.Common/Interfaces/IDebuggable.cs @@ -33,70 +33,118 @@ namespace BizHawk.Emulation.Common public class RegisterValue { - public ulong Value { get; set; } - public byte BitSize { get; set; } + public ulong Value { get; private set; } + public byte BitSize { get; private set; } + + public RegisterValue(ulong val, byte bitSize) + { + if (bitSize == 64) + Value = val; + else if (bitSize > 64 || bitSize == 0) + throw new System.ArgumentOutOfRangeException("bitSize", "BitSize must be in 1..64"); + else + Value = val & (1UL << bitSize) - 1; + BitSize = bitSize; + } + + public RegisterValue(bool val) + { + Value = val ? 1UL : 0UL; + BitSize = 1; + } + + public RegisterValue(byte val) + { + Value = val; + BitSize = 8; + } + + public RegisterValue(sbyte val) + { + Value = (byte)val; + BitSize = 8; + } + + public RegisterValue(ushort val) + { + Value = val; + BitSize = 16; + } + + public RegisterValue(short val) + { + Value = (ushort)val; + BitSize = 16; + } + + public RegisterValue(uint val) + { + Value = val; + BitSize = 32; + } + + public RegisterValue(int val) + { + Value = (uint)val; + BitSize = 32; + } + + public RegisterValue(ulong val) + { + Value = val; + BitSize = 64; + } + + public RegisterValue(long val) + { + Value = (ulong)val; + BitSize = 64; + } + public static implicit operator RegisterValue(bool val) { - return new RegisterValue - { - Value = (ulong)(val ? 1 : 0), - BitSize = 1 - }; + return new RegisterValue(val); } public static implicit operator RegisterValue(byte val) { - return new RegisterValue - { - Value = val, - BitSize = 8 - }; + return new RegisterValue(val); + } + + public static implicit operator RegisterValue(sbyte val) + { + return new RegisterValue(val); } public static implicit operator RegisterValue(ushort val) { - return new RegisterValue - { - Value = val, - BitSize = 16 - }; + return new RegisterValue(val); } - public static implicit operator RegisterValue(int val) + public static implicit operator RegisterValue(short val) { - return new RegisterValue - { - Value = (ulong)val, - BitSize = 32 - }; + return new RegisterValue(val); } public static implicit operator RegisterValue(uint val) { - return new RegisterValue - { - Value = val, - BitSize = 32 - }; + return new RegisterValue(val); } - public static implicit operator RegisterValue(long val) + public static implicit operator RegisterValue(int val) { - return new RegisterValue - { - Value = (ulong)val, - BitSize = 64 - }; + return new RegisterValue(val); } public static implicit operator RegisterValue(ulong val) { - return new RegisterValue - { - Value = val, - BitSize = 64 - }; + return new RegisterValue(val); + } + + public static implicit operator RegisterValue(long val) + { + return new RegisterValue(val); } } } diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.IDebuggable.cs b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.IDebuggable.cs index 9f8ddf7341..671d2ff774 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.IDebuggable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.IDebuggable.cs @@ -24,15 +24,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx if (name.Contains("68K SR") || name.StartsWith("Z80")) size = 16; - // TODO: clean me up - if (size == 16) - { - ret[Marshal.PtrToStringAnsi(regs[i].Name)] = (ushort)regs[i].Value; - } - else - { - ret[Marshal.PtrToStringAnsi(regs[i].Name)] = (uint)regs[i].Value; - } + ret[name] = new RegisterValue((ulong)regs[i].Value, size); } return ret;