Change ToRawInt to ToRawUInt

This commit is contained in:
YoshiRulz 2024-08-16 23:14:39 +10:00
parent 97adf1a87d
commit 72fb3061a3
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
11 changed files with 89 additions and 90 deletions

View File

@ -8,8 +8,8 @@ namespace BizHawk.Client.Common.RamSearchEngine
internal interface IMiniWatch internal interface IMiniWatch
{ {
long Address { get; } long Address { get; }
long Previous { get; } // do not store sign extended variables in here. uint Previous { get; }
long Current { get; } uint Current { get; }
int ChangeCount { get; } int ChangeCount { get; }
void ClearChangeCount(); void ClearChangeCount();
void SetPreviousToCurrent(); void SetPreviousToCurrent();
@ -35,8 +35,8 @@ namespace BizHawk.Client.Common.RamSearchEngine
_previous = _current; _previous = _current;
} }
public long Previous => _previous; public uint Previous => _previous;
public long Current => _current; public uint Current => _current;
public int ChangeCount { get; private set; } public int ChangeCount { get; private set; }
@ -87,8 +87,8 @@ namespace BizHawk.Client.Common.RamSearchEngine
_previous = _current; _previous = _current;
} }
public long Previous => _previous; public uint Previous => _previous;
public long Current => _current; public uint Current => _current;
public int ChangeCount { get; private set; } public int ChangeCount { get; private set; }
@ -139,8 +139,8 @@ namespace BizHawk.Client.Common.RamSearchEngine
_previous = _current; _previous = _current;
} }
public long Previous => _previous; public uint Previous => _previous;
public long Current => _current; public uint Current => _current;
public int ChangeCount { get; private set; } public int ChangeCount { get; private set; }

View File

@ -7,7 +7,6 @@ using BizHawk.Common.CollectionExtensions;
using BizHawk.Common.NumberExtensions; using BizHawk.Common.NumberExtensions;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
// ReSharper disable PossibleInvalidCastExceptionInForeachLoop
namespace BizHawk.Client.Common.RamSearchEngine namespace BizHawk.Client.Common.RamSearchEngine
{ {
public class RamSearchEngine public class RamSearchEngine
@ -38,7 +37,7 @@ namespace BizHawk.Client.Common.RamSearchEngine
}; };
} }
public RamSearchEngine(SearchEngineSettings settings, IMemoryDomains memoryDomains, Compare compareTo, long? compareValue, int? differentBy) public RamSearchEngine(SearchEngineSettings settings, IMemoryDomains memoryDomains, Compare compareTo, uint? compareValue, uint? differentBy)
: this(settings, memoryDomains) : this(settings, memoryDomains)
{ {
_compareTo = compareTo; _compareTo = compareTo;
@ -156,7 +155,7 @@ namespace BizHawk.Client.Common.RamSearchEngine
} }
} }
public long? CompareValue { get; set; } public uint? CompareValue { get; set; }
public ComparisonOperator Operator { get; set; } public ComparisonOperator Operator { get; set; }
@ -164,7 +163,7 @@ namespace BizHawk.Client.Common.RamSearchEngine
/// zero 07-sep-2014 - this isn't ideal. but don't bother changing it (to a long, for instance) until it can support floats. maybe store it as a double here.<br/> /// zero 07-sep-2014 - this isn't ideal. but don't bother changing it (to a long, for instance) until it can support floats. maybe store it as a double here.<br/>
/// it already supported floats by way of reinterpret-cast, it just wasn't implemented correctly on this side --yoshi /// it already supported floats by way of reinterpret-cast, it just wasn't implemented correctly on this side --yoshi
/// </remarks> /// </remarks>
public int? DifferentBy { get; set; } public uint? DifferentBy { get; set; }
public void Update(bool updatePrevious) public void Update(bool updatePrevious)
{ {
@ -318,7 +317,7 @@ namespace BizHawk.Client.Common.RamSearchEngine
case ComparisonOperator.LessThanEqual: case ComparisonOperator.LessThanEqual:
return watchList.Where(w => SignExtendAsNeeded(w.Current) <= SignExtendAsNeeded(w.Previous)); return watchList.Where(w => SignExtendAsNeeded(w.Current) <= SignExtendAsNeeded(w.Previous));
case ComparisonOperator.DifferentBy: case ComparisonOperator.DifferentBy:
if (DifferentBy is not int differentBy) throw new InvalidOperationException(); if (DifferentBy is not uint differentBy) throw new InvalidOperationException();
return watchList.Where(w => return watchList.Where(w =>
differentBy == Math.Abs(SignExtendAsNeeded(w.Current) - SignExtendAsNeeded(w.Previous))); differentBy == Math.Abs(SignExtendAsNeeded(w.Current) - SignExtendAsNeeded(w.Previous)));
} }
@ -349,7 +348,7 @@ namespace BizHawk.Client.Common.RamSearchEngine
return val < prev || val.HawkFloatEquality(prev); return val < prev || val.HawkFloatEquality(prev);
}); });
case ComparisonOperator.DifferentBy: case ComparisonOperator.DifferentBy:
if (DifferentBy is not int differentBy) throw new InvalidOperationException(); if (DifferentBy is not uint differentBy) throw new InvalidOperationException();
var differentByF = ReinterpretAsF32(differentBy); var differentByF = ReinterpretAsF32(differentBy);
return watchList.Where(w => Math.Abs(ReinterpretAsF32(w.Current) - ReinterpretAsF32(w.Previous)) return watchList.Where(w => Math.Abs(ReinterpretAsF32(w.Current) - ReinterpretAsF32(w.Previous))
.HawkFloatEquality(differentByF)); .HawkFloatEquality(differentByF));
@ -358,7 +357,7 @@ namespace BizHawk.Client.Common.RamSearchEngine
private IEnumerable<IMiniWatch> CompareSpecificValue(IEnumerable<IMiniWatch> watchList) private IEnumerable<IMiniWatch> CompareSpecificValue(IEnumerable<IMiniWatch> watchList)
{ {
if (CompareValue is not long compareValue) throw new InvalidOperationException(); if (CompareValue is not uint compareValue) throw new InvalidOperationException();
if (_settings.Type is not WatchDisplayType.Float) if (_settings.Type is not WatchDisplayType.Float)
{ {
switch (Operator) switch (Operator)
@ -377,7 +376,7 @@ namespace BizHawk.Client.Common.RamSearchEngine
case ComparisonOperator.LessThanEqual: case ComparisonOperator.LessThanEqual:
return watchList.Where(w => SignExtendAsNeeded(w.Current) <= SignExtendAsNeeded(compareValue)); return watchList.Where(w => SignExtendAsNeeded(w.Current) <= SignExtendAsNeeded(compareValue));
case ComparisonOperator.DifferentBy: case ComparisonOperator.DifferentBy:
if (DifferentBy is not int differentBy) throw new InvalidOperationException(); if (DifferentBy is not uint differentBy) throw new InvalidOperationException();
return watchList.Where(w => return watchList.Where(w =>
differentBy == Math.Abs(SignExtendAsNeeded(w.Current) - SignExtendAsNeeded(compareValue))); differentBy == Math.Abs(SignExtendAsNeeded(w.Current) - SignExtendAsNeeded(compareValue)));
} }
@ -407,7 +406,7 @@ namespace BizHawk.Client.Common.RamSearchEngine
return val < compareValueF || val.HawkFloatEquality(compareValueF); return val < compareValueF || val.HawkFloatEquality(compareValueF);
}); });
case ComparisonOperator.DifferentBy: case ComparisonOperator.DifferentBy:
if (DifferentBy is not int differentBy) throw new InvalidOperationException(); if (DifferentBy is not uint differentBy) throw new InvalidOperationException();
var differentByF = ReinterpretAsF32(differentBy); var differentByF = ReinterpretAsF32(differentBy);
return watchList.Where(w => Math.Abs(ReinterpretAsF32(w.Current) - compareValueF) return watchList.Where(w => Math.Abs(ReinterpretAsF32(w.Current) - compareValueF)
.HawkFloatEquality(differentByF)); .HawkFloatEquality(differentByF));
@ -416,7 +415,7 @@ namespace BizHawk.Client.Common.RamSearchEngine
private IEnumerable<IMiniWatch> CompareSpecificAddress(IEnumerable<IMiniWatch> watchList) private IEnumerable<IMiniWatch> CompareSpecificAddress(IEnumerable<IMiniWatch> watchList)
{ {
if (CompareValue is not long compareValue) throw new InvalidOperationException(); if (CompareValue is not uint compareValue) throw new InvalidOperationException();
switch (Operator) switch (Operator)
{ {
default: default:
@ -433,14 +432,14 @@ namespace BizHawk.Client.Common.RamSearchEngine
case ComparisonOperator.LessThanEqual: case ComparisonOperator.LessThanEqual:
return watchList.Where(w => w.Address <= compareValue); return watchList.Where(w => w.Address <= compareValue);
case ComparisonOperator.DifferentBy: case ComparisonOperator.DifferentBy:
if (DifferentBy is not int differentBy) throw new InvalidOperationException(); if (DifferentBy is not uint differentBy) throw new InvalidOperationException();
return watchList.Where(w => Math.Abs(w.Address - compareValue) == differentBy); return watchList.Where(w => Math.Abs(w.Address - compareValue) == differentBy);
} }
} }
private IEnumerable<IMiniWatch> CompareChanges(IEnumerable<IMiniWatch> watchList) private IEnumerable<IMiniWatch> CompareChanges(IEnumerable<IMiniWatch> watchList)
{ {
if (CompareValue is not long compareValue) throw new InvalidOperationException(); if (CompareValue is not uint compareValue) throw new InvalidOperationException();
switch (Operator) switch (Operator)
{ {
default: default:
@ -457,14 +456,14 @@ namespace BizHawk.Client.Common.RamSearchEngine
case ComparisonOperator.LessThanEqual: case ComparisonOperator.LessThanEqual:
return watchList.Where(w => w.ChangeCount <= compareValue); return watchList.Where(w => w.ChangeCount <= compareValue);
case ComparisonOperator.DifferentBy: case ComparisonOperator.DifferentBy:
if (DifferentBy is not int differentBy) throw new InvalidOperationException(); if (DifferentBy is not uint differentBy) throw new InvalidOperationException();
return watchList.Where(w => Math.Abs(w.ChangeCount - compareValue) == differentBy); return watchList.Where(w => Math.Abs(w.ChangeCount - compareValue) == differentBy);
} }
} }
private IEnumerable<IMiniWatch> CompareDifference(IEnumerable<IMiniWatch> watchList) private IEnumerable<IMiniWatch> CompareDifference(IEnumerable<IMiniWatch> watchList)
{ {
if (CompareValue is not long compareValue) throw new InvalidCastException(); //TODO typo for IOE? if (CompareValue is not uint compareValue) throw new InvalidCastException(); //TODO typo for IOE?
if (_settings.Type is not WatchDisplayType.Float) if (_settings.Type is not WatchDisplayType.Float)
{ {
switch (Operator) switch (Operator)
@ -483,9 +482,9 @@ namespace BizHawk.Client.Common.RamSearchEngine
case ComparisonOperator.LessThanEqual: case ComparisonOperator.LessThanEqual:
return watchList.Where(w => SignExtendAsNeeded(w.Current) - SignExtendAsNeeded(w.Previous) <= compareValue); return watchList.Where(w => SignExtendAsNeeded(w.Current) - SignExtendAsNeeded(w.Previous) <= compareValue);
case ComparisonOperator.DifferentBy: case ComparisonOperator.DifferentBy:
if (DifferentBy is not int differentBy) throw new InvalidOperationException(); if (DifferentBy is not uint differentBy) throw new InvalidOperationException();
return watchList.Where(w => return watchList.Where(w =>
differentBy == Math.Abs(SignExtendAsNeeded(w.Current) - SignExtendAsNeeded(w.Previous) - compareValue)); differentBy == Math.Abs(Math.Abs(SignExtendAsNeeded(w.Current) - SignExtendAsNeeded(w.Previous)) - compareValue));
} }
} }
var compareValueF = ReinterpretAsF32(compareValue); var compareValueF = ReinterpretAsF32(compareValue);
@ -513,7 +512,7 @@ namespace BizHawk.Client.Common.RamSearchEngine
return diff < compareValueF || diff.HawkFloatEquality(compareValueF); return diff < compareValueF || diff.HawkFloatEquality(compareValueF);
}); });
case ComparisonOperator.DifferentBy: case ComparisonOperator.DifferentBy:
if (DifferentBy is not int differentBy) throw new InvalidOperationException(); if (DifferentBy is not uint differentBy) throw new InvalidOperationException();
var differentByF = ReinterpretAsF32(differentBy); var differentByF = ReinterpretAsF32(differentBy);
return watchList.Where(w => Math.Abs(ReinterpretAsF32(w.Current) - ReinterpretAsF32(w.Previous) - compareValueF) return watchList.Where(w => Math.Abs(ReinterpretAsF32(w.Current) - ReinterpretAsF32(w.Previous) - compareValueF)
.HawkFloatEquality(differentByF)); .HawkFloatEquality(differentByF));

View File

@ -10,8 +10,8 @@ namespace BizHawk.Client.EmuHawk
public interface INumberBox public interface INumberBox
{ {
bool Nullable { get; } bool Nullable { get; }
int? ToRawInt(); uint? ToRawUInt();
void SetFromRawInt(int? rawInt); void SetFromRawUInt(uint? rawUInt);
} }
public class HexTextBox : ClipboardEventTextBox, INumberBox public class HexTextBox : ClipboardEventTextBox, INumberBox
@ -85,7 +85,7 @@ namespace BizHawk.Client.EmuHawk
{ {
if (Text.IsHex() && !string.IsNullOrEmpty(_addressFormatStr)) if (Text.IsHex() && !string.IsNullOrEmpty(_addressFormatStr))
{ {
var val = (uint)ToRawInt(); var val = ToRawUInt();
if (val == GetMax()) if (val == GetMax())
{ {
@ -103,7 +103,7 @@ namespace BizHawk.Client.EmuHawk
{ {
if (Text.IsHex() && !string.IsNullOrEmpty(_addressFormatStr)) if (Text.IsHex() && !string.IsNullOrEmpty(_addressFormatStr))
{ {
var val = (uint)ToRawInt(); var val = ToRawUInt();
if (val == 0) if (val == 0)
{ {
val = (uint)GetMax(); // int to long todo val = (uint)GetMax(); // int to long todo
@ -146,7 +146,7 @@ namespace BizHawk.Client.EmuHawk
base.OnPaste(e); base.OnPaste(e);
} }
public int? ToRawInt() public uint? ToRawUInt()
{ {
if (string.IsNullOrWhiteSpace(Text)) if (string.IsNullOrWhiteSpace(Text))
{ {
@ -158,10 +158,10 @@ namespace BizHawk.Client.EmuHawk
return 0; return 0;
} }
return int.Parse(Text, NumberStyles.HexNumber); return uint.Parse(Text, NumberStyles.HexNumber);
} }
public void SetFromRawInt(int? val) public void SetFromRawUInt(uint? val)
{ {
Text = val.HasValue ? string.Format(_addressFormatStr, val) : ""; Text = val.HasValue ? string.Format(_addressFormatStr, val) : "";
} }
@ -230,7 +230,7 @@ namespace BizHawk.Client.EmuHawk
{ {
if (Text.IsHex()) if (Text.IsHex())
{ {
var val = (uint)ToRawInt(); var val = ToRawUInt().Value;
if (val == uint.MaxValue) if (val == uint.MaxValue)
{ {
val = 0; val = 0;
@ -247,7 +247,7 @@ namespace BizHawk.Client.EmuHawk
{ {
if (Text.IsHex()) if (Text.IsHex())
{ {
var val = (uint)ToRawInt(); var val = ToRawUInt().Value;
if (val == 0) if (val == 0)
{ {
@ -279,7 +279,7 @@ namespace BizHawk.Client.EmuHawk
base.OnTextChanged(e); base.OnTextChanged(e);
} }
public int? ToRawInt() public uint? ToRawUInt()
{ {
if (string.IsNullOrWhiteSpace(Text) || !Text.IsHex()) if (string.IsNullOrWhiteSpace(Text) || !Text.IsHex())
{ {
@ -291,10 +291,10 @@ namespace BizHawk.Client.EmuHawk
return 0; return 0;
} }
return (int)uint.Parse(Text); return uint.Parse(Text);
} }
public void SetFromRawInt(int? val) public void SetFromRawUInt(uint? val)
{ {
Text = val?.ToString() ?? ""; Text = val?.ToString() ?? "";
} }

View File

@ -593,7 +593,7 @@ namespace BizHawk.Client.EmuHawk
if (StopOnFrameCheckbox.Checked) if (StopOnFrameCheckbox.Checked)
{ {
if (LastFrameCheckbox.Checked) _mainForm.PauseOnFrame = _movieSession.Movie.InputLogLength; if (LastFrameCheckbox.Checked) _mainForm.PauseOnFrame = _movieSession.Movie.InputLogLength;
else if (StopOnFrameTextBox.ToRawInt() is int i) _mainForm.PauseOnFrame = i; else if (StopOnFrameTextBox.ToRawUInt() is uint i) _mainForm.PauseOnFrame = (int)i;
} }
Close(); Close();
} }

View File

@ -93,7 +93,7 @@ namespace BizHawk.Client.EmuHawk
CheckFormState(); CheckFormState();
if (!_cheat.Compare.HasValue) if (!_cheat.Compare.HasValue)
{ {
CompareBox.Text = ""; // Necessary hack until WatchValueBox.ToRawInt() becomes nullable CompareBox.Text = ""; // Necessary hack until WatchValueBox.ToRawUInt() becomes nullable
} }
_loading = false; _loading = false;
@ -132,7 +132,7 @@ namespace BizHawk.Client.EmuHawk
SetTypeSelected(WatchDisplayType.Hex); SetTypeSelected(WatchDisplayType.Hex);
CheckFormState(); CheckFormState();
CompareBox.Text = ""; // TODO: A needed hack until WatchValueBox.ToRawInt() becomes nullable CompareBox.Text = ""; // TODO: A needed hack until WatchValueBox.ToRawUInt() becomes nullable
_loading = false; _loading = false;
} }
@ -310,7 +310,7 @@ namespace BizHawk.Client.EmuHawk
public Cheat GetCheat() public Cheat GetCheat()
{ {
var domain = MemoryDomains[DomainDropDown.SelectedItem.ToString()]!; var domain = MemoryDomains[DomainDropDown.SelectedItem.ToString()]!;
var address = AddressBox.ToRawInt().Value; var address = AddressBox.ToRawUInt().Value;
if (address < domain.Size) if (address < domain.Size)
{ {
var watch = Watch.GenerateWatch( var watch = Watch.GenerateWatch(
@ -333,11 +333,11 @@ namespace BizHawk.Client.EmuHawk
_ => Cheat.CompareType.None _ => Cheat.CompareType.None
}; };
var compare = CompareBox.ToRawInt(); var compare = CompareBox.ToRawUInt();
return new Cheat( return new Cheat(
watch, watch,
value: ValueBox.ToRawInt().Value, value: (int)ValueBox.ToRawUInt().Value,
compare: compare, compare: (int?)compare,
enabled: true, enabled: true,
comparisonType); comparisonType);
} }

View File

@ -100,13 +100,13 @@ namespace BizHawk.Client.EmuHawk
public uint Address public uint Address
{ {
get => (uint)AddressBox.ToRawInt().Value & AddressMask; get => AddressBox.ToRawUInt().Value & AddressMask;
set => AddressBox.SetFromLong(value & AddressMask); set => AddressBox.SetFromLong(value & AddressMask);
} }
public uint AddressMask public uint AddressMask
{ {
get => (uint)AddressMaskBox.ToRawInt().Value; get => AddressMaskBox.ToRawUInt().Value;
set => AddressMaskBox.SetFromLong(value); set => AddressMaskBox.SetFromLong(value);
} }

View File

@ -118,7 +118,7 @@ namespace BizHawk.Client.EmuHawk
var pc = PCRegister; var pc = PCRegister;
SeekToBox.Nullable = false; SeekToBox.Nullable = false;
SeekToBox.SetHexProperties((long)Math.Pow(2, pc.BitSize)); SeekToBox.SetHexProperties((long)Math.Pow(2, pc.BitSize));
SeekToBox.SetFromRawInt(0); SeekToBox.SetFromRawUInt(0);
} }
else else
{ {
@ -263,7 +263,7 @@ namespace BizHawk.Client.EmuHawk
private void SeekToBtn_Click(object sender, EventArgs e) private void SeekToBtn_Click(object sender, EventArgs e)
{ {
CancelSeekBtn.Enabled = true; CancelSeekBtn.Enabled = true;
var pcVal = (uint)(SeekToBox.ToRawInt() ?? 0); var pcVal = SeekToBox.ToRawUInt() ?? 0;
var pcBitSize = PCRegister.BitSize; var pcBitSize = PCRegister.BitSize;
BreakPointControl1.RemoveCurrentSeek(); BreakPointControl1.RemoveCurrentSeek();

View File

@ -17,7 +17,7 @@ namespace BizHawk.Client.EmuHawk
this.label1.Text = bodyMessage; this.label1.Text = bodyMessage;
} }
public int Frames => NumFramesBox.ToRawInt() ?? 0; public int Frames => (int)(NumFramesBox.ToRawUInt() ?? 0);
private void FramesPrompt_Load(object sender, EventArgs e) private void FramesPrompt_Load(object sender, EventArgs e)
{ {

View File

@ -421,7 +421,7 @@ namespace BizHawk.Client.EmuHawk
WatchListView.AnyRowsSelected && _searches.Domain.Writable; WatchListView.AnyRowsSelected && _searches.Domain.Writable;
} }
private long? CompareToValue private uint? CompareToValue
{ {
get get
{ {
@ -432,29 +432,29 @@ namespace BizHawk.Client.EmuHawk
if (SpecificValueRadio.Checked) if (SpecificValueRadio.Checked)
{ {
return (long)SpecificValueBox.ToRawInt() & 0x00000000FFFFFFFF; return SpecificValueBox.ToRawUInt();
} }
if (SpecificAddressRadio.Checked) if (SpecificAddressRadio.Checked)
{ {
return SpecificAddressBox.ToRawInt(); return SpecificAddressBox.ToRawUInt();
} }
if (NumberOfChangesRadio.Checked) if (NumberOfChangesRadio.Checked)
{ {
return NumberOfChangesBox.ToRawInt(); return NumberOfChangesBox.ToRawUInt();
} }
if (DifferenceRadio.Checked) if (DifferenceRadio.Checked)
{ {
return DifferenceBox.ToRawInt(); return DifferenceBox.ToRawUInt();
} }
return null; return null;
} }
} }
private int? DifferentByValue => DifferentByRadio.Checked ? DifferentByBox.ToRawInt() : null; private uint? DifferentByValue => DifferentByRadio.Checked ? DifferentByBox.ToRawUInt() : null;
private ComparisonOperator Operator private ComparisonOperator Operator
{ {
@ -737,7 +737,7 @@ namespace BizHawk.Client.EmuHawk
WatchListView.Refresh(); WatchListView.Refresh();
} }
private void SetCompareValue(int? value) private void SetCompareValue(uint? value)
{ {
_searches.CompareValue = value; _searches.CompareValue = value;
WatchListView.Refresh(); WatchListView.Refresh();
@ -1441,7 +1441,7 @@ namespace BizHawk.Client.EmuHawk
SpecificAddressBox.ResetText(); SpecificAddressBox.ResetText();
} }
_searches.CompareValue = SpecificValueBox.ToRawInt(); _searches.CompareValue = SpecificValueBox.ToRawUInt();
if (Focused) if (Focused)
{ {
@ -1463,7 +1463,7 @@ namespace BizHawk.Client.EmuHawk
SpecificAddressBox.ResetText(); SpecificAddressBox.ResetText();
} }
_searches.CompareValue = SpecificAddressBox.ToRawInt(); _searches.CompareValue = SpecificAddressBox.ToRawUInt();
if (Focused) if (Focused)
{ {
@ -1485,7 +1485,7 @@ namespace BizHawk.Client.EmuHawk
NumberOfChangesBox.ResetText(); NumberOfChangesBox.ResetText();
} }
_searches.CompareValue = NumberOfChangesBox.ToRawInt(); _searches.CompareValue = NumberOfChangesBox.ToRawUInt();
if (Focused) if (Focused)
{ {
@ -1507,7 +1507,7 @@ namespace BizHawk.Client.EmuHawk
DifferenceBox.ResetText(); DifferenceBox.ResetText();
} }
_searches.CompareValue = DifferenceBox.ToRawInt(); _searches.CompareValue = DifferenceBox.ToRawUInt();
if (Focused) if (Focused)
{ {
@ -1519,7 +1519,7 @@ namespace BizHawk.Client.EmuHawk
private void CompareToValue_TextChanged(object sender, EventArgs e) private void CompareToValue_TextChanged(object sender, EventArgs e)
{ {
SetCompareValue(((INumberBox)sender).ToRawInt()); SetCompareValue(((INumberBox)sender).ToRawUInt());
} }
private void EqualToRadio_Click(object sender, EventArgs e) private void EqualToRadio_Click(object sender, EventArgs e)
@ -1567,7 +1567,7 @@ namespace BizHawk.Client.EmuHawk
DifferentByBox.ResetText(); DifferentByBox.ResetText();
} }
_searches.DifferentBy = DifferenceBox.ToRawInt(); _searches.DifferentBy = DifferenceBox.ToRawUInt();
if (Focused) if (Focused)
{ {
@ -1579,7 +1579,7 @@ namespace BizHawk.Client.EmuHawk
private void DifferentByBox_TextChanged(object sender, EventArgs e) private void DifferentByBox_TextChanged(object sender, EventArgs e)
{ {
_searches.DifferentBy = !string.IsNullOrWhiteSpace(DifferentByBox.Text) ? DifferentByBox.ToRawInt() : null; _searches.DifferentBy = !string.IsNullOrWhiteSpace(DifferentByBox.Text) ? DifferentByBox.ToRawUInt() : null;
WatchListView.Refresh(); WatchListView.Refresh();
} }

View File

@ -275,7 +275,7 @@ namespace BizHawk.Client.EmuHawk
Watches[i] = Watch.GenerateWatch( Watches[i] = Watch.GenerateWatch(
Watches[i].Domain, Watches[i].Domain,
Watches.Count == 1 ? AddressBox.ToRawInt() ?? 0 : Watches[i].Address, Watches.Count == 1 ? AddressBox.ToRawUInt() ?? 0 : Watches[i].Address,
size, size,
_changedDisplayType ? displayType : Watches[i].Type, _changedDisplayType ? displayType : Watches[i].Type,
Watches[i].BigEndian, Watches[i].BigEndian,

View File

@ -56,10 +56,10 @@ namespace BizHawk.Client.EmuHawk
get => _type; get => _type;
set set
{ {
var val = ToRawInt(); var val = ToRawUInt();
_type = value; _type = value;
SetMaxLength(); SetMaxLength();
SetFromRawInt(val); SetFromRawUInt(val);
} }
} }
@ -197,7 +197,7 @@ namespace BizHawk.Client.EmuHawk
{ {
default: default:
case WatchDisplayType.Signed: case WatchDisplayType.Signed:
int val = ToRawInt() ?? 0; int val = (int)(ToRawUInt() ?? 0);
if (val == MaxSignedInt) if (val == MaxSignedInt)
{ {
val = MinSignedInt; val = MinSignedInt;
@ -210,7 +210,7 @@ namespace BizHawk.Client.EmuHawk
Text = val.ToString(); Text = val.ToString();
break; break;
case WatchDisplayType.Unsigned: case WatchDisplayType.Unsigned:
var uval = (uint)(ToRawInt() ?? 0); var uval = ToRawUInt() ?? 0;
if (uval == MaxUnsignedInt) if (uval == MaxUnsignedInt)
{ {
uval = 0; uval = 0;
@ -223,7 +223,7 @@ namespace BizHawk.Client.EmuHawk
Text = uval.ToString(); Text = uval.ToString();
break; break;
case WatchDisplayType.Binary: case WatchDisplayType.Binary:
var bVal = (uint)(ToRawInt() ?? 0); var bVal = ToRawUInt() ?? 0;
if (bVal == MaxUnsignedInt) if (bVal == MaxUnsignedInt)
{ {
bVal = 0; bVal = 0;
@ -237,7 +237,7 @@ namespace BizHawk.Client.EmuHawk
Text = Convert.ToString(bVal, 2).PadLeft(numBits, '0'); Text = Convert.ToString(bVal, 2).PadLeft(numBits, '0');
break; break;
case WatchDisplayType.Hex: case WatchDisplayType.Hex:
var hexVal = (uint)(ToRawInt() ?? 0); var hexVal = ToRawUInt() ?? 0;
if (hexVal == MaxUnsignedInt) if (hexVal == MaxUnsignedInt)
{ {
hexVal = 0; hexVal = 0;
@ -309,7 +309,7 @@ namespace BizHawk.Client.EmuHawk
{ {
default: default:
case WatchDisplayType.Signed: case WatchDisplayType.Signed:
int val = ToRawInt() ?? 0; int val = (int)(ToRawUInt() ?? 0);
if (val == MinSignedInt) if (val == MinSignedInt)
{ {
val = MaxSignedInt; val = MaxSignedInt;
@ -322,7 +322,7 @@ namespace BizHawk.Client.EmuHawk
Text = val.ToString(); Text = val.ToString();
break; break;
case WatchDisplayType.Unsigned: case WatchDisplayType.Unsigned:
var uval = (uint)(ToRawInt() ?? 0); var uval = ToRawUInt() ?? 0;
if (uval == 0) if (uval == 0)
{ {
uval = MaxUnsignedInt; uval = MaxUnsignedInt;
@ -335,7 +335,7 @@ namespace BizHawk.Client.EmuHawk
Text = uval.ToString(); Text = uval.ToString();
break; break;
case WatchDisplayType.Binary: case WatchDisplayType.Binary:
var bVal = (uint)(ToRawInt() ?? 0); var bVal = ToRawUInt() ?? 0;
if (bVal == 0) if (bVal == 0)
{ {
bVal = MaxUnsignedInt; bVal = MaxUnsignedInt;
@ -349,7 +349,7 @@ namespace BizHawk.Client.EmuHawk
Text = Convert.ToString(bVal, 2).PadLeft(numBits, '0'); Text = Convert.ToString(bVal, 2).PadLeft(numBits, '0');
break; break;
case WatchDisplayType.Hex: case WatchDisplayType.Hex:
var hexVal = (uint)(ToRawInt() ?? 0); var hexVal = ToRawUInt() ?? 0;
if (hexVal == 0) if (hexVal == 0)
{ {
hexVal = MaxUnsignedInt; hexVal = MaxUnsignedInt;
@ -445,23 +445,23 @@ namespace BizHawk.Client.EmuHawk
base.OnPaste(e); base.OnPaste(e);
} }
public int? ToRawInt() public uint? ToRawUInt()
{ {
static int ReinterpretAsS32(float f) static uint ReinterpretAsU32(float f)
=> Unsafe.As<float, int>(ref f); => Unsafe.As<float, uint>(ref f);
try try
{ {
return _type switch return _type switch
{ {
WatchDisplayType.Signed => int.Parse(Text), WatchDisplayType.Signed => (uint)int.Parse(Text),
WatchDisplayType.Unsigned => (int)uint.Parse(Text), WatchDisplayType.Unsigned => uint.Parse(Text),
WatchDisplayType.Binary => Convert.ToInt32(Text, 2), WatchDisplayType.Binary => Convert.ToUInt32(Text, 2),
WatchDisplayType.Hex => int.Parse(Text, NumberStyles.HexNumber), WatchDisplayType.Hex => uint.Parse(Text, NumberStyles.HexNumber),
WatchDisplayType.FixedPoint_12_4 => (int)(double.Parse(Text, NumberFormatInfo.InvariantInfo) * 16.0), WatchDisplayType.FixedPoint_12_4 => (uint)(double.Parse(Text, NumberFormatInfo.InvariantInfo) * 16.0),
WatchDisplayType.FixedPoint_20_12 => (int)(double.Parse(Text, NumberFormatInfo.InvariantInfo) * 4096.0), WatchDisplayType.FixedPoint_20_12 => (uint)(double.Parse(Text, NumberFormatInfo.InvariantInfo) * 4096.0),
WatchDisplayType.FixedPoint_16_16 => (int)(double.Parse(Text, NumberFormatInfo.InvariantInfo) * 65536.0), WatchDisplayType.FixedPoint_16_16 => (uint)(double.Parse(Text, NumberFormatInfo.InvariantInfo) * 65536.0),
WatchDisplayType.Float => ReinterpretAsS32(float.Parse(Text, NumberFormatInfo.InvariantInfo)), WatchDisplayType.Float => ReinterpretAsU32(float.Parse(Text, NumberFormatInfo.InvariantInfo)),
_ => int.Parse(Text) _ => uint.Parse(Text)
}; };
} }
catch catch
@ -472,9 +472,9 @@ namespace BizHawk.Client.EmuHawk
return Nullable ? null : 0; return Nullable ? null : 0;
} }
public void SetFromRawInt(int? val) public void SetFromRawUInt(uint? val)
{ {
if (val is not int i) if (val is not uint i)
{ {
Text = string.Empty; Text = string.Empty;
return; return;
@ -482,13 +482,13 @@ namespace BizHawk.Client.EmuHawk
Text = _type switch Text = _type switch
{ {
WatchDisplayType.Signed => i.ToString(), WatchDisplayType.Signed => i.ToString(),
WatchDisplayType.Unsigned => ((uint) i).ToString(), WatchDisplayType.Unsigned => i.ToString(),
WatchDisplayType.Binary => Convert.ToString(i, toBase: 2).PadLeft(8 * (int) ByteSize, '0'), WatchDisplayType.Binary => Convert.ToString(i, toBase: 2).PadLeft(8 * (int) ByteSize, '0'),
WatchDisplayType.Hex => i.ToHexString(MaxLength), WatchDisplayType.Hex => i.ToHexString(MaxLength),
WatchDisplayType.FixedPoint_12_4 => (i / 16.0).ToString("F5", NumberFormatInfo.InvariantInfo), WatchDisplayType.FixedPoint_12_4 => (i / 16.0).ToString("F5", NumberFormatInfo.InvariantInfo),
WatchDisplayType.FixedPoint_20_12 => (i / 4096.0).ToString("F5", NumberFormatInfo.InvariantInfo), WatchDisplayType.FixedPoint_20_12 => (i / 4096.0).ToString("F5", NumberFormatInfo.InvariantInfo),
WatchDisplayType.FixedPoint_16_16 => (i / 65536.0).ToString("F5", NumberFormatInfo.InvariantInfo), WatchDisplayType.FixedPoint_16_16 => (i / 65536.0).ToString("F5", NumberFormatInfo.InvariantInfo),
WatchDisplayType.Float => Unsafe.As<int, float>(ref i).ToString("F6", NumberFormatInfo.InvariantInfo), WatchDisplayType.Float => Unsafe.As<uint, float>(ref i).ToString("F6", NumberFormatInfo.InvariantInfo),
_ => i.ToString() _ => i.ToString()
}; };
} }