From 2152c7996522cd26565d11b877fff23525eab8dc Mon Sep 17 00:00:00 2001 From: Triang3l Date: Wed, 14 Aug 2019 00:07:27 +0300 Subject: [PATCH] =?UTF-8?q?[Memory]=200xE=E2=80=A6=20adjustment=20in=20Tra?= =?UTF-8?q?nslateVirtual?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/xenia/memory.cc | 2 +- src/xenia/memory.h | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/xenia/memory.cc b/src/xenia/memory.cc index 19a80de53..77f62d9d8 100644 --- a/src/xenia/memory.cc +++ b/src/xenia/memory.cc @@ -306,7 +306,7 @@ void Memory::Reset() { heaps_.physical.Reset(); } -BaseHeap* Memory::LookupHeap(uint32_t address) { +const BaseHeap* Memory::LookupHeap(uint32_t address) const { if (address < 0x40000000) { return &heaps_.v00000000; } else if (address < 0x7F000000) { diff --git a/src/xenia/memory.h b/src/xenia/memory.h index 7e9202ca1..cfbace0cb 100644 --- a/src/xenia/memory.h +++ b/src/xenia/memory.h @@ -286,7 +286,12 @@ class Memory { // Note that the contents at the specified host address are big-endian. template inline T TranslateVirtual(uint32_t guest_address) const { - return reinterpret_cast(virtual_membase_ + guest_address); + uint8_t* host_address = virtual_membase_ + guest_address; + const auto heap = LookupHeap(guest_address); + if (heap) { + host_address += heap->host_address_offset(); + } + return reinterpret_cast(host_address); } // Base address of physical memory in the host address space. @@ -399,7 +404,12 @@ class Memory { void SystemHeapFree(uint32_t address); // Gets the heap for the address space containing the given address. - BaseHeap* LookupHeap(uint32_t address); + const BaseHeap* LookupHeap(uint32_t address) const; + + inline BaseHeap* LookupHeap(uint32_t address) { + return const_cast( + const_cast(this)->LookupHeap(address)); + } // Gets the heap with the given properties. BaseHeap* LookupHeapByType(bool physical, uint32_t page_size);