ram watch - fix two minor bugs

fixes two minor bugs relating to ram watch display type

1.binary display was broken on 32 bit watches
2.changing a watch's size to one with an incompatible display type resulted in an exception (e.g. 32 bit float -> 8 bit unsigned)
This commit is contained in:
scrimpeh 2020-06-27 14:11:59 +02:00 committed by adelikat
parent f9e174fd2d
commit c8ca09724c
2 changed files with 14 additions and 6 deletions

View File

@ -201,6 +201,16 @@ namespace BizHawk.Client.Common
return _float.ToString();
};
string FormatBinary()
{
var str = Convert.ToString(val, 2).PadLeft(32, '0');
for (var i = 28; i > 0; i -= 4)
{
str = str.Insert(i, " ");
}
return str;
};
return Type switch
{
_ when !IsValid => "-",
@ -210,6 +220,7 @@ namespace BizHawk.Client.Common
DisplayType.FixedPoint_20_12 => $"{(int)val / 4096.0:0.######}",
DisplayType.FixedPoint_16_16 => $"{(int)val / 65536.0:0.######}",
DisplayType.Float => FormatFloat(),
DisplayType.Binary => FormatBinary(),
_ => val.ToString()
};
}

View File

@ -276,21 +276,18 @@ namespace BizHawk.Client.EmuHawk
_ => WatchSize.Byte
};
var displayType = Watch.StringToDisplayType(DisplayTypeDropDown.SelectedItem.ToString());
Watches[i] = Watch.GenerateWatch(
Watches[i].Domain,
Watches.Count == 1 ? AddressBox.ToRawInt() ?? 0 : Watches[i].Address,
size,
Watches[i].Type,
_changedDisplayType ? displayType : Watches[i].Type,
Watches[i].BigEndian,
Watches[i].Notes);
}
}
if (_changedDisplayType)
{
Watches.ForEach(x => x.Type = Watch.StringToDisplayType(DisplayTypeDropDown.SelectedItem.ToString()));
}
if (BigEndianCheckBox.CheckState != CheckState.Indeterminate)
{
Watches.ForEach(x => x.BigEndian = BigEndianCheckBox.Checked);