Skip to content

Commit

Permalink
Merge branch 'TASEmulators:master' into add-gameboy-memory-callback-v…
Browse files Browse the repository at this point in the history
…alues
  • Loading branch information
roydmerkel authored Jun 21, 2024
2 parents 170af1e + 542e043 commit f38aef5
Show file tree
Hide file tree
Showing 17 changed files with 123 additions and 135 deletions.
14 changes: 9 additions & 5 deletions Dist/git_hook_shim.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/bin/sh
set -e
kind="$(basename "$0")"
pwsh="$(command -v pwsh)"
if [ -z "$pwsh" ]; then pwsh="$(command -v dotnet) pwsh"; fi
if ! ("$pwsh" -v >/dev/null 2>/dev/null); then exit 0; fi
kind="$(basename "$0")"
"$pwsh" "./Dist/git_hooks/$kind.ps1" "$@"
if [ -e "./Dist/git_hooks/$kind.local.ps1" ]; then "$pwsh" "./Dist/git_hooks/$kind.local.ps1" "$@"; fi
if ! ("$pwsh" -v >/dev/null 2>/dev/null); then
printf "pwsh not found in PATH; skipping %s hook\n" "$kind"
exit 0
fi
if [ -e "./Dist/git_hooks/$kind.ps1" ]; then
"$pwsh" "./Dist/git_hooks/$kind.ps1" "$@" || exit $?
if [ -e "./Dist/git_hooks/$kind.local.ps1" ]; then "$pwsh" "./Dist/git_hooks/$kind.local.ps1" "$@" || exit $?; fi
fi
2 changes: 1 addition & 1 deletion Dist/install_git_hooks.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (Test-Path $targetDir -PathType Container) { # is Git repo
#TODO use symlinks on Linux
} elseif ((Get-FileHash $target).Hash -ne $shimChecksum) { # files differ
$head = Get-Content $target -TotalCount 3
echo "[$PSCommandFilename] found existing Git hook $hook, please resolve conflict manually"
echo "[$PSCommandFilename] found existing Git hook $hook, please resolve conflict manually (ignore if checking out older commits)"
exit 1
}
# else no-op
Expand Down
5 changes: 3 additions & 2 deletions src/BizHawk.Client.Common/Api/Classes/MemoryApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;

using BizHawk.Common;
using BizHawk.Common.NumberExtensions;
using BizHawk.Emulation.Common;

namespace BizHawk.Client.Common
Expand Down Expand Up @@ -287,7 +288,7 @@ public float ReadFloat(long addr, string domain = null)
LogCallback($"Warning: Attempted read {addr} outside memory size of {d.Size}");
return default;
}
return BitConverter.ToSingle(BitConverter.GetBytes(d.PeekUint(addr, _isBigEndian)), 0);
return NumberExtensions.ReinterpretAsF32(d.PeekUint(addr, _isBigEndian));
}

public void WriteFloat(long addr, double value, string domain = null)
Expand All @@ -303,7 +304,7 @@ public void WriteFloat(long addr, double value, string domain = null)
LogCallback($"Warning: Attempted write {addr} outside memory size of {d.Size}");
return;
}
d.PokeUint(addr, BitConverter.ToUInt32(BitConverter.GetBytes((float) value), 0), _isBigEndian);
d.PokeUint(addr, NumberExtensions.ReinterpretAsUInt32((float) value), _isBigEndian);
}

public int ReadS8(long addr, string domain = null) => (sbyte) ReadUnsigned(addr, 1, domain);
Expand Down
16 changes: 8 additions & 8 deletions src/BizHawk.Client.Common/tools/RamSearchEngine/IMiniWatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace BizHawk.Client.Common.RamSearchEngine
internal interface IMiniWatch
{
long Address { get; }
long Previous { get; } // do not store sign extended variables in here.
long Current { get; }
uint Previous { get; }
uint Current { get; }
int ChangeCount { get; }
void ClearChangeCount();
void SetPreviousToCurrent();
Expand All @@ -35,8 +35,8 @@ public void SetPreviousToCurrent()
_previous = _current;
}

public long Previous => _previous;
public long Current => _current;
public uint Previous => _previous;
public uint Current => _current;

public int ChangeCount { get; private set; }

Expand Down Expand Up @@ -87,8 +87,8 @@ public void SetPreviousToCurrent()
_previous = _current;
}

public long Previous => _previous;
public long Current => _current;
public uint Previous => _previous;
public uint Current => _current;

public int ChangeCount { get; private set; }

Expand Down Expand Up @@ -139,8 +139,8 @@ public void SetPreviousToCurrent()
_previous = _current;
}

public long Previous => _previous;
public long Current => _current;
public uint Previous => _previous;
public uint Current => _current;

public int ChangeCount { get; private set; }

Expand Down
41 changes: 17 additions & 24 deletions src/BizHawk.Client.Common/tools/RamSearchEngine/RamSearchEngine.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;

using BizHawk.Common;
using BizHawk.Common.CollectionExtensions;
using BizHawk.Common.NumberExtensions;
using BizHawk.Emulation.Common;
using static BizHawk.Common.NumberExtensions.NumberExtensions;

// ReSharper disable PossibleInvalidCastExceptionInForeachLoop
namespace BizHawk.Client.Common.RamSearchEngine
{
public class RamSearchEngine
{
/// <remarks>TODO move to BizHawk.Common</remarks>
private static float ReinterpretAsF32(long l)
{
return Unsafe.As<long, float>(ref l);
}

private Compare _compareTo = Compare.Previous;

private IMiniWatch[] _watchList = [ ];
Expand All @@ -39,7 +32,7 @@ public RamSearchEngine(SearchEngineSettings settings, IMemoryDomains memoryDomai
};
}

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)
{
_compareTo = compareTo;
Expand Down Expand Up @@ -157,15 +150,15 @@ public Compare CompareTo
}
}

public long? CompareValue { get; set; }
public uint? CompareValue { get; set; }

public ComparisonOperator Operator { get; set; }

/// <remarks>
/// 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
/// </remarks>
public int? DifferentBy { get; set; }
public uint? DifferentBy { get; set; }

public void Update(bool updatePrevious)
{
Expand Down Expand Up @@ -319,7 +312,7 @@ private IEnumerable<IMiniWatch> ComparePrevious(IEnumerable<IMiniWatch> watchLis
case ComparisonOperator.LessThanEqual:
return watchList.Where(w => SignExtendAsNeeded(w.Current) <= SignExtendAsNeeded(w.Previous));
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 =>
differentBy == Math.Abs(SignExtendAsNeeded(w.Current) - SignExtendAsNeeded(w.Previous)));
}
Expand Down Expand Up @@ -350,7 +343,7 @@ private IEnumerable<IMiniWatch> ComparePrevious(IEnumerable<IMiniWatch> watchLis
return val < prev || val.HawkFloatEquality(prev);
});
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);
return watchList.Where(w => Math.Abs(ReinterpretAsF32(w.Current) - ReinterpretAsF32(w.Previous))
.HawkFloatEquality(differentByF));
Expand All @@ -359,7 +352,7 @@ private IEnumerable<IMiniWatch> ComparePrevious(IEnumerable<IMiniWatch> watchLis

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)
{
switch (Operator)
Expand All @@ -378,7 +371,7 @@ private IEnumerable<IMiniWatch> CompareSpecificValue(IEnumerable<IMiniWatch> wat
case ComparisonOperator.LessThanEqual:
return watchList.Where(w => SignExtendAsNeeded(w.Current) <= SignExtendAsNeeded(compareValue));
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 =>
differentBy == Math.Abs(SignExtendAsNeeded(w.Current) - SignExtendAsNeeded(compareValue)));
}
Expand Down Expand Up @@ -408,7 +401,7 @@ private IEnumerable<IMiniWatch> CompareSpecificValue(IEnumerable<IMiniWatch> wat
return val < compareValueF || val.HawkFloatEquality(compareValueF);
});
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);
return watchList.Where(w => Math.Abs(ReinterpretAsF32(w.Current) - compareValueF)
.HawkFloatEquality(differentByF));
Expand All @@ -417,7 +410,7 @@ private IEnumerable<IMiniWatch> CompareSpecificValue(IEnumerable<IMiniWatch> wat

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)
{
default:
Expand All @@ -434,14 +427,14 @@ private IEnumerable<IMiniWatch> CompareSpecificAddress(IEnumerable<IMiniWatch> w
case ComparisonOperator.LessThanEqual:
return watchList.Where(w => w.Address <= compareValue);
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);
}
}

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)
{
default:
Expand All @@ -458,14 +451,14 @@ private IEnumerable<IMiniWatch> CompareChanges(IEnumerable<IMiniWatch> watchList
case ComparisonOperator.LessThanEqual:
return watchList.Where(w => w.ChangeCount <= compareValue);
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);
}
}

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)
{
switch (Operator)
Expand All @@ -484,9 +477,9 @@ private IEnumerable<IMiniWatch> CompareDifference(IEnumerable<IMiniWatch> watchL
case ComparisonOperator.LessThanEqual:
return watchList.Where(w => SignExtendAsNeeded(w.Current) - SignExtendAsNeeded(w.Previous) <= compareValue);
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 =>
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);
Expand Down Expand Up @@ -514,7 +507,7 @@ private IEnumerable<IMiniWatch> CompareDifference(IEnumerable<IMiniWatch> watchL
return diff < compareValueF || diff.HawkFloatEquality(compareValueF);
});
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);
return watchList.Where(w => Math.Abs(ReinterpretAsF32(w.Current) - ReinterpretAsF32(w.Previous) - compareValueF)
.HawkFloatEquality(differentByF));
Expand Down
6 changes: 3 additions & 3 deletions src/BizHawk.Client.Common/tools/Watch/DWordWatch.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using BizHawk.Common.NumberExtensions;
using BizHawk.Emulation.Common;

namespace BizHawk.Client.Common
Expand Down Expand Up @@ -84,7 +85,7 @@ public override bool Poke(string value)
WatchDisplayType.Hex => uint.Parse(value, NumberStyles.HexNumber),
WatchDisplayType.FixedPoint_20_12 => (uint)(double.Parse(value, NumberFormatInfo.InvariantInfo) * 4096.0),
WatchDisplayType.FixedPoint_16_16 => (uint)(double.Parse(value, NumberFormatInfo.InvariantInfo) * 65536.0),
WatchDisplayType.Float => BitConverter.ToUInt32(BitConverter.GetBytes(float.Parse(value, NumberFormatInfo.InvariantInfo)), 0),
WatchDisplayType.Float => NumberExtensions.ReinterpretAsUInt32(float.Parse(value, NumberFormatInfo.InvariantInfo)),
_ => 0
};

Expand Down Expand Up @@ -133,8 +134,7 @@ public string FormatValue(uint val)
{
string FormatFloat()
{
var bytes = BitConverter.GetBytes(val);
var _float = BitConverter.ToSingle(bytes, 0);
var _float = NumberExtensions.ReinterpretAsF32(val);
return _float.ToString(NumberFormatInfo.InvariantInfo);
}

Expand Down
24 changes: 12 additions & 12 deletions src/BizHawk.Client.EmuHawk/CustomControls/HexTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ namespace BizHawk.Client.EmuHawk
public interface INumberBox
{
bool Nullable { get; }
int? ToRawInt();
void SetFromRawInt(int? rawInt);
uint? ToRawUInt();
void SetFromRawUInt(uint? rawUInt);
}

public class HexTextBox : ClipboardEventTextBox, INumberBox
Expand Down Expand Up @@ -86,7 +86,7 @@ protected override void OnKeyDown(KeyEventArgs e)
{
if (Text.IsHex() && !string.IsNullOrEmpty(_addressFormatStr))
{
var val = (uint)ToRawInt();
var val = ToRawUInt();

if (val == GetMax())
{
Expand All @@ -104,7 +104,7 @@ protected override void OnKeyDown(KeyEventArgs e)
{
if (Text.IsHex() && !string.IsNullOrEmpty(_addressFormatStr))
{
var val = (uint)ToRawInt();
var val = ToRawUInt();
if (val == 0)
{
val = (uint)GetMax(); // int to long todo
Expand Down Expand Up @@ -147,7 +147,7 @@ protected override void OnPaste(PasteEventArgs e)
base.OnPaste(e);
}

public int? ToRawInt()
public uint? ToRawUInt()
{
if (string.IsNullOrWhiteSpace(Text))
{
Expand All @@ -159,10 +159,10 @@ protected override void OnPaste(PasteEventArgs e)
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) : "";
}
Expand Down Expand Up @@ -231,7 +231,7 @@ protected override void OnKeyDown(KeyEventArgs e)
{
if (Text.IsHex())
{
var val = (uint)ToRawInt();
var val = ToRawUInt().Value;
if (val == uint.MaxValue)
{
val = 0;
Expand All @@ -248,7 +248,7 @@ protected override void OnKeyDown(KeyEventArgs e)
{
if (Text.IsHex())
{
var val = (uint)ToRawInt();
var val = ToRawUInt().Value;

if (val == 0)
{
Expand Down Expand Up @@ -280,7 +280,7 @@ protected override void OnTextChanged(EventArgs e)
base.OnTextChanged(e);
}

public int? ToRawInt()
public uint? ToRawUInt()
{
if (string.IsNullOrWhiteSpace(Text) || !Text.IsHex())
{
Expand All @@ -292,10 +292,10 @@ protected override void OnTextChanged(EventArgs e)
return 0;
}

return (int)uint.Parse(Text);
return uint.Parse(Text);
}

public void SetFromRawInt(int? val)
public void SetFromRawUInt(uint? val)
{
Text = val?.ToString() ?? "";
}
Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Client.EmuHawk/movie/PlayMovie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ private void Ok_Click(object sender, EventArgs e)
if (StopOnFrameCheckbox.Checked)
{
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();
}
Expand Down
Loading

0 comments on commit f38aef5

Please sign in to comment.