Use read-only collection types in `IMemoryApi`
This commit is contained in:
parent
cba206efec
commit
1bdff05442
|
@ -185,10 +185,8 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public void SetBigEndian(bool enabled = true) => _isBigEndian = enabled;
|
||||
|
||||
public List<string> GetMemoryDomainList() =>
|
||||
DomainList
|
||||
.Select(domain => domain.Name)
|
||||
.ToList();
|
||||
public IReadOnlyCollection<string> GetMemoryDomainList()
|
||||
=> DomainList.Select(static domain => domain.Name).ToList();
|
||||
|
||||
public uint GetMemoryDomainSize(string name = null) => (uint) NamedDomainOrCurrent(name).Size;
|
||||
|
||||
|
@ -243,7 +241,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public void WriteByte(long addr, uint value, string domain = null) => WriteUnsigned(addr, value, 1, domain);
|
||||
|
||||
public List<byte> ReadByteRange(long addr, int length, string domain = null)
|
||||
public IReadOnlyList<byte> ReadByteRange(long addr, int length, string domain = null)
|
||||
{
|
||||
var d = NamedDomainOrCurrent(domain);
|
||||
if (addr < 0) LogCallback($"Warning: Attempted reads on addresses {addr}..-1 outside range of domain {d.Name} in {nameof(ReadByteRange)}()");
|
||||
|
@ -255,10 +253,10 @@ namespace BizHawk.Client.Common
|
|||
for (var i = addr < 0 ? -addr : 0; i != indexAfterLast; i++) bytes[i] = d.PeekByte(addr + i);
|
||||
}
|
||||
if (lastReqAddr >= d.Size) LogCallback($"Warning: Attempted reads on addresses {d.Size}..{lastReqAddr} outside range of domain {d.Name} in {nameof(ReadByteRange)}()");
|
||||
return bytes.ToList();
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public void WriteByteRange(long addr, List<byte> memoryblock, string domain = null)
|
||||
public void WriteByteRange(long addr, IReadOnlyList<byte> memoryblock, string domain = null)
|
||||
{
|
||||
var d = NamedDomainOrCurrent(domain);
|
||||
if (!d.Writable)
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
void SetBigEndian(bool enabled = true);
|
||||
|
||||
List<string> GetMemoryDomainList();
|
||||
IReadOnlyCollection<string> GetMemoryDomainList();
|
||||
uint GetMemoryDomainSize(string name = "");
|
||||
string GetCurrentMemoryDomain();
|
||||
uint GetCurrentMemoryDomainSize();
|
||||
|
@ -16,7 +16,7 @@ namespace BizHawk.Client.Common
|
|||
string HashRegion(long addr, int count, string domain = null);
|
||||
|
||||
uint ReadByte(long addr, string domain = null);
|
||||
List<byte> ReadByteRange(long addr, int length, string domain = null);
|
||||
IReadOnlyList<byte> ReadByteRange(long addr, int length, string domain = null);
|
||||
float ReadFloat(long addr, string domain = null);
|
||||
|
||||
int ReadS8(long addr, string domain = null);
|
||||
|
@ -30,7 +30,7 @@ namespace BizHawk.Client.Common
|
|||
uint ReadU32(long addr, string domain = null);
|
||||
|
||||
void WriteByte(long addr, uint value, string domain = null);
|
||||
void WriteByteRange(long addr, List<byte> memoryblock, string domain = null);
|
||||
void WriteByteRange(long addr, IReadOnlyList<byte> memoryblock, string domain = null);
|
||||
void WriteFloat(long addr, double value, string domain = null);
|
||||
|
||||
void WriteS8(long addr, int value, string domain = null);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
|
||||
|
@ -19,7 +20,7 @@ namespace BizHawk.Client.Common
|
|||
[LuaMethod("getmemorydomainlist", "Returns a string of the memory domains for the loaded platform core. List will be a single string delimited by line feeds")]
|
||||
[return: LuaASCIIStringParam]
|
||||
public LuaTable GetMemoryDomainList()
|
||||
=> _th.ListToTable(APIs.Memory.GetMemoryDomainList(), indexFrom: 0);
|
||||
=> _th.ListToTable((List<string>) APIs.Memory.GetMemoryDomainList(), indexFrom: 0); //HACK cast will succeed as long as impl. returns .Select<T, string>().ToList() as IROC<string>
|
||||
|
||||
[LuaMethodExample("local uimemget = memory.getmemorydomainsize( mainmemory.getname( ) );")]
|
||||
[LuaMethod("getmemorydomainsize", "Returns the number of bytes of the specified memory domain. If no domain is specified, or the specified domain doesn't exist, returns the current domain size")]
|
||||
|
|
Loading…
Reference in New Issue