Skip to content

Commit e4468f8

Browse files
committed
Add 64-bit-wide peeks and pokes
1 parent 6ef58bd commit e4468f8

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/BizHawk.Emulation.Common/Base Implementations/MemoryDomain.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,24 @@ public virtual uint PeekUint(long addr, bool bigEndian)
6060
: BinaryPrimitives.ReadUInt32LittleEndian(scratch);
6161
}
6262

63+
public virtual ulong PeekUlong(long addr, bool bigEndian)
64+
{
65+
ReadOnlySpan<byte> scratch = stackalloc byte[]
66+
{
67+
PeekByte(addr),
68+
PeekByte(addr + 1),
69+
PeekByte(addr + 2),
70+
PeekByte(addr + 3),
71+
PeekByte(addr + 4),
72+
PeekByte(addr + 5),
73+
PeekByte(addr + 6),
74+
PeekByte(addr + 7),
75+
};
76+
return bigEndian
77+
? BinaryPrimitives.ReadUInt64BigEndian(scratch)
78+
: BinaryPrimitives.ReadUInt64LittleEndian(scratch);
79+
}
80+
6381
public virtual void PokeUshort(long addr, ushort val, bool bigEndian)
6482
{
6583
if (bigEndian)
@@ -85,6 +103,14 @@ public virtual void PokeUint(long addr, uint val, bool bigEndian)
85103
PokeByte(addr + 3, scratch[3]);
86104
}
87105

106+
public virtual void PokeUlong(long addr, ulong val, bool bigEndian)
107+
{
108+
Span<byte> scratch = stackalloc byte[8];
109+
if (bigEndian) BinaryPrimitives.WriteUInt64BigEndian(scratch, val);
110+
else BinaryPrimitives.WriteUInt64LittleEndian(scratch, val);
111+
for (var i = 0; i < scratch.Length; i++) PokeByte(addr + i, scratch[i]);
112+
}
113+
88114
public virtual void BulkPeekByte(Range<long> addresses, byte[] values)
89115
{
90116
if (addresses is null) throw new ArgumentNullException(paramName: nameof(addresses));
@@ -152,6 +178,8 @@ public virtual void BulkPeekUint(Range<long> addresses, bool bigEndian, uint[] v
152178
}
153179
}
154180

181+
//TODO BulkPeekUlong?
182+
155183
public virtual void SendCheatToCore(int addr, byte value, int compare, int compare_type) { }
156184

157185
/// <summary>

0 commit comments

Comments
 (0)