diff options
| author | 2016-06-27 20:42:42 +0300 | |
|---|---|---|
| committer | 2016-08-27 21:38:06 +0800 | |
| commit | b2df959733ee65cbf705dbfbd05761a06929a6b6 (patch) | |
| tree | 90327dc0e58493de455fa4a4fdd4599ee8c6477a /src | |
| parent | Merge pull request #2022 from MerryMage/issue-tpl (diff) | |
| download | yuzu-b2df959733ee65cbf705dbfbd05761a06929a6b6.tar.gz yuzu-b2df959733ee65cbf705dbfbd05761a06929a6b6.tar.xz yuzu-b2df959733ee65cbf705dbfbd05761a06929a6b6.zip | |
Memory: add ReadCString function
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/memory.cpp | 14 | ||||
| -rw-r--r-- | src/core/memory.h | 3 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 8c9e5d46d..9aa8c4e5a 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp | |||
| @@ -280,6 +280,20 @@ u8* GetPointer(const VAddr vaddr) { | |||
| 280 | return nullptr; | 280 | return nullptr; |
| 281 | } | 281 | } |
| 282 | 282 | ||
| 283 | std::string ReadCString(VAddr vaddr, std::size_t max_length) { | ||
| 284 | std::string string; | ||
| 285 | string.reserve(max_length); | ||
| 286 | for (std::size_t i = 0; i < max_length; ++i) { | ||
| 287 | char c = Read8(vaddr); | ||
| 288 | if (c == '\0') | ||
| 289 | break; | ||
| 290 | string.push_back(c); | ||
| 291 | ++vaddr; | ||
| 292 | } | ||
| 293 | string.shrink_to_fit(); | ||
| 294 | return string; | ||
| 295 | } | ||
| 296 | |||
| 283 | u8* GetPhysicalPointer(PAddr address) { | 297 | u8* GetPhysicalPointer(PAddr address) { |
| 284 | // TODO(Subv): This call should not go through the application's memory mapping. | 298 | // TODO(Subv): This call should not go through the application's memory mapping. |
| 285 | return GetPointer(PhysicalToVirtualAddress(address)); | 299 | return GetPointer(PhysicalToVirtualAddress(address)); |
diff --git a/src/core/memory.h b/src/core/memory.h index ae5588dee..cad845385 100644 --- a/src/core/memory.h +++ b/src/core/memory.h | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <cstddef> | 7 | #include <cstddef> |
| 8 | #include <string> | ||
| 8 | 9 | ||
| 9 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| 10 | 11 | ||
| @@ -130,6 +131,8 @@ void CopyBlock(VAddr dest_addr, VAddr src_addr, size_t size); | |||
| 130 | 131 | ||
| 131 | u8* GetPointer(VAddr virtual_address); | 132 | u8* GetPointer(VAddr virtual_address); |
| 132 | 133 | ||
| 134 | std::string ReadCString(VAddr virtual_address, std::size_t max_length); | ||
| 135 | |||
| 133 | /** | 136 | /** |
| 134 | * Converts a virtual address inside a region with 1:1 mapping to physical memory to a physical | 137 | * Converts a virtual address inside a region with 1:1 mapping to physical memory to a physical |
| 135 | * address. This should be used by services to translate addresses for use by the hardware. | 138 | * address. This should be used by services to translate addresses for use by the hardware. |