diff --git a/src/BizHawk.Client.Common/Api/Classes/MemoryApi.cs b/src/BizHawk.Client.Common/Api/Classes/MemoryApi.cs index 3c6725d42d..d8d0ebe100 100644 --- a/src/BizHawk.Client.Common/Api/Classes/MemoryApi.cs +++ b/src/BizHawk.Client.Common/Api/Classes/MemoryApi.cs @@ -260,6 +260,26 @@ namespace BizHawk.Client.Common return newBytes; } + public bool ReadByteRange(ulong srcStartOffset, Span 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 memoryblock, string domain = null) { var d = NamedDomainOrCurrent(domain); diff --git a/src/BizHawk.Client.Common/Api/Interfaces/IMemoryApi.cs b/src/BizHawk.Client.Common/Api/Interfaces/IMemoryApi.cs index ae644937a0..08a082c3c3 100644 --- a/src/BizHawk.Client.Common/Api/Interfaces/IMemoryApi.cs +++ b/src/BizHawk.Client.Common/Api/Interfaces/IMemoryApi.cs @@ -17,6 +17,15 @@ namespace BizHawk.Client.Common uint ReadByte(long addr, string domain = null); IReadOnlyList ReadByteRange(long addr, int length, string domain = null); + + /// copies a region of memory into , starting at and taking as many bytes as will fit in the buffer + /// + /// iff the internal API call threw an exception (for example, if you request bytes beyond the end of the domain).
+ /// If this happens, the state of is undefined. Anywhere from 0 bytes to all of them could have been copied. + /// The exception is when falls outside the domain, as that is checked first and results in a no-op. + ///
+ bool ReadByteRange(ulong srcStartOffset, Span dstBuffer, string domain = null); + float ReadFloat(long addr, string domain = null); int ReadS8(long addr, string domain = null);