public byte GetByte(uint address, bool absoluteAddress = false, uint?mask = null, int?shift = null) { object lockValue = Config.LockManager.GetMemoryLockValue(address, typeof(byte), mask, shift); byte? parsedValue = ParsingUtilities.ParseByteRoundingWrapping(lockValue); if (parsedValue.HasValue) { return(parsedValue.Value); } byte value = ReadRam((UIntPtr)address, 1, EndiannessType.Little, absoluteAddress)[0]; if (mask.HasValue) { value = (byte)(value & mask.Value); } if (shift.HasValue) { value = (byte)(value >> shift.Value); } return(value); }
public bool SetValueRoundingWrapping(Type type, object value, uint address, bool absoluteAddress = false, uint?mask = null) { if (value is string) { value = ParsingUtilities.ParseDoubleNullable((string)value); if (value == null) { return(false); } if (type == typeof(byte)) { value = ParsingUtilities.ParseByteRoundingWrapping((double)value); } if (type == typeof(sbyte)) { value = ParsingUtilities.ParseSByteRoundingWrapping((double)value); } if (type == typeof(short)) { value = ParsingUtilities.ParseShortRoundingWrapping((double)value); } if (type == typeof(ushort)) { value = ParsingUtilities.ParseUShortRoundingWrapping((double)value); } if (type == typeof(int)) { value = ParsingUtilities.ParseIntRoundingWrapping((double)value); } if (type == typeof(uint)) { value = ParsingUtilities.ParseUIntRoundingWrapping((double)value); } } return(SetValue(type, value.ToString(), address, absoluteAddress, mask)); }
public bool SetValueRoundingWrapping( Type type, object value, uint address, bool absoluteAddress = false, uint?mask = null, int?shift = null) { // Allow short circuiting if object is already of type if (type == typeof(byte) && value is byte byteValue) { return(SetValue(byteValue, address, absoluteAddress, mask, shift)); } if (type == typeof(sbyte) && value is sbyte sbyteValue) { return(SetValue(sbyteValue, address, absoluteAddress, mask, shift)); } if (type == typeof(short) && value is short shortValue) { return(SetValue(shortValue, address, absoluteAddress, mask, shift)); } if (type == typeof(ushort) && value is ushort ushortValue) { return(SetValue(ushortValue, address, absoluteAddress, mask, shift)); } if (type == typeof(int) && value is int intValue) { return(SetValue(intValue, address, absoluteAddress, mask, shift)); } if (type == typeof(uint) && value is uint uintValue) { return(SetValue(uintValue, address, absoluteAddress, mask, shift)); } if (type == typeof(float) && value is float floatValue) { return(SetValue(floatValue, address, absoluteAddress, mask, shift)); } if (type == typeof(double) && value is double doubleValue) { return(SetValue(doubleValue, address, absoluteAddress, mask, shift)); } value = ParsingUtilities.ParseDoubleNullable(value); if (value == null) { return(false); } if (type == typeof(byte)) { value = ParsingUtilities.ParseByteRoundingWrapping(value); } if (type == typeof(sbyte)) { value = ParsingUtilities.ParseSByteRoundingWrapping(value); } if (type == typeof(short)) { value = ParsingUtilities.ParseShortRoundingWrapping(value); } if (type == typeof(ushort)) { value = ParsingUtilities.ParseUShortRoundingWrapping(value); } if (type == typeof(int)) { value = ParsingUtilities.ParseIntRoundingWrapping(value); } if (type == typeof(uint)) { value = ParsingUtilities.ParseUIntRoundingWrapping(value); } return(SetValue(type, value.ToString(), address, absoluteAddress, mask, shift)); }