This commit is contained in:
nattthebear 2016-02-21 14:00:11 -05:00
parent 61c50e1d7c
commit c77de0e8af
2 changed files with 88 additions and 48 deletions

View File

@ -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);
}
}
}

View File

@ -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;