Expose `MemoryDomain.ReadByteRange`'s `Span` overload via `IMemoryApi`

This commit is contained in:
YoshiRulz 2022-12-04 09:42:35 +10:00 committed by YoshiRulz
parent 0b651b90c4
commit 531aebb54f
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
2 changed files with 29 additions and 0 deletions

View File

@ -260,6 +260,26 @@ namespace BizHawk.Client.Common
return newBytes;
}
public bool ReadByteRange(ulong srcStartOffset, Span<byte> dstBuffer, string domain = null)
{
var d = NamedDomainOrCurrent(domain);
if (srcStartOffset >= (ulong) d.Size)
{
LogCallback($"Warning: attempted read of {srcStartOffset} outside the memory size of {d.Size}");
return false;
}
try
{
d.BulkPeekByte(srcStartOffset, dstBuffer);
return true;
}
catch (Exception e)
{
LogCallback($"bulk-peek threw {e.GetType().Name}: {e.Message}");
return false;
}
}
public void WriteByteRange(long addr, IReadOnlyList<byte> memoryblock, string domain = null)
{
var d = NamedDomainOrCurrent(domain);

View File

@ -17,6 +17,15 @@ namespace BizHawk.Client.Common
uint ReadByte(long addr, string domain = null);
IReadOnlyList<byte> ReadByteRange(long addr, int length, string domain = null);
/// <summary>copies a region of memory into <paramref name="dstBuffer"/>, starting at <paramref name="srcStartOffset"/> and taking as many bytes as will fit in the buffer</summary>
/// <returns>
/// <see langword="false"/> iff the internal API call threw an exception (for example, if you request bytes beyond the end of the domain).<br/>
/// If this happens, the state of <paramref name="dstBuffer"/> is undefined. Anywhere from <c>0</c> bytes to all of them could have been copied.
/// The exception is when <paramref name="srcStartOffset"/> falls outside the domain, as that is checked first and results in a no-op.
/// </returns>
bool ReadByteRange(ulong srcStartOffset, Span<byte> dstBuffer, string domain = null);
float ReadFloat(long addr, string domain = null);
int ReadS8(long addr, string domain = null);