MMU: Add a HostGetU16String() function for wide strings used by emulated software.

This commit is contained in:
Admiral H. Curtiss 2023-07-17 22:31:22 +02:00
parent 163c97e242
commit 7f29f0398c
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
2 changed files with 18 additions and 0 deletions

View File

@ -867,6 +867,22 @@ std::string MMU::HostGetString(const Core::CPUThreadGuard& guard, u32 address, s
return s; return s;
} }
std::u16string MMU::HostGetU16String(const Core::CPUThreadGuard& guard, u32 address, size_t size)
{
std::u16string s;
do
{
if (!HostIsRAMAddress(guard, address) || !HostIsRAMAddress(guard, address + 1))
break;
const u16 res = HostRead_U16(guard, address);
if (!res)
break;
s += static_cast<char16_t>(res);
address += 2;
} while (size == 0 || s.length() < size);
return s;
}
std::optional<ReadResult<std::string>> MMU::HostTryReadString(const Core::CPUThreadGuard& guard, std::optional<ReadResult<std::string>> MMU::HostTryReadString(const Core::CPUThreadGuard& guard,
u32 address, size_t size, u32 address, size_t size,
RequestedAddressSpace space) RequestedAddressSpace space)

View File

@ -132,6 +132,8 @@ public:
static double HostRead_F64(const Core::CPUThreadGuard& guard, u32 address); static double HostRead_F64(const Core::CPUThreadGuard& guard, u32 address);
static u32 HostRead_Instruction(const Core::CPUThreadGuard& guard, u32 address); static u32 HostRead_Instruction(const Core::CPUThreadGuard& guard, u32 address);
static std::string HostGetString(const Core::CPUThreadGuard& guard, u32 address, size_t size = 0); static std::string HostGetString(const Core::CPUThreadGuard& guard, u32 address, size_t size = 0);
static std::u16string HostGetU16String(const Core::CPUThreadGuard& guard, u32 address,
size_t size = 0);
// Try to read a value from emulated memory at the given address in the given memory space. // Try to read a value from emulated memory at the given address in the given memory space.
// If the read succeeds, the returned value will be present and the ReadResult contains the read // If the read succeeds, the returned value will be present and the ReadResult contains the read