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);