Skip to content

Commit

Permalink
Merge pull request libretro#33 from RetroSven/master
Browse files Browse the repository at this point in the history
add memory hooks for libretro in order to use cheat code searching an…
  • Loading branch information
inactive123 authored Aug 2, 2018
2 parents 0197fbb + 6f4a361 commit d61e5d3
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,15 @@ CMakeLists.txt.user
*.kdev4
# Ignore IDEA/Clion files/dirs
/.idea/
**/*.cmake
**/CMakeFiles
**/*.a
**/Makefile
.cproject
.project
.settings/
Binaries/
CMakeCache.txt
exports/
dolphin_libretro.so

6 changes: 6 additions & 0 deletions Source/Core/Common/MemArena.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ u8* MemArena::FindMemoryBase()
const size_t memory_size = 0x400000000;
#endif

return GetMemoryBase(memory_size) ;
}

u8* MemArena::GetMemoryBase(size_t memory_size)
{

#ifdef _WIN32
u8* base = static_cast<u8*>(VirtualAlloc(nullptr, memory_size, MEM_RESERVE, PAGE_READWRITE));
if (!base)
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/Common/MemArena.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class MemArena

// This finds 1 GB in 32-bit, 16 GB in 64-bit.
static u8* FindMemoryBase();
// Finds virtual memory location in the specified size
static u8* GetMemoryBase(size_t size);

private:
#ifdef _WIN32
Expand Down
26 changes: 26 additions & 0 deletions Source/Core/Core/HW/Memmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ namespace Memory
// Store the MemArena here
u8* physical_base = nullptr;
u8* logical_base = nullptr;
#ifdef __LIBRETRO__
u8* single_physical_base = nullptr;
#endif

// The MemArena class
static Common::MemArena g_arena;
Expand All @@ -55,6 +58,10 @@ u8* m_pRAM;
u8* m_pL1Cache;
u8* m_pEXRAM;
u8* m_pFakeVMEM;
#ifdef __LIBRETRO__
u8* m_pContiguousRAM;
u32 m_TotalMemorySize ;
#endif

// MMIO mapping object.
std::unique_ptr<MMIO::Mapping> mmio_mapping;
Expand Down Expand Up @@ -207,6 +214,18 @@ void Init()
}
}

#ifdef __LIBRETRO__
m_TotalMemorySize = mem_size ;
single_physical_base = Common::MemArena::GetMemoryBase(m_TotalMemorySize);
m_pContiguousRAM = (u8*)g_arena.CreateView(0, m_TotalMemorySize, single_physical_base);

if (!m_pContiguousRAM)
{
PanicAlert("MemoryMap_Setup: Failed finding a single memory base.");
exit(0);
}
#endif

#ifndef _ARCH_32
logical_base = physical_base + 0x200000000;
#endif
Expand Down Expand Up @@ -292,6 +311,10 @@ void Shutdown()
g_arena.ReleaseView(*region.out_pointer, region.size);
*region.out_pointer = nullptr;
}
#ifdef __LIBRETRO__
g_arena.ReleaseView(m_pContiguousRAM, m_TotalMemorySize);
m_pContiguousRAM = nullptr;
#endif
for (auto& entry : logical_mapped_entries)
{
g_arena.ReleaseView(entry.mapped_pointer, entry.mapped_size);
Expand All @@ -300,6 +323,9 @@ void Shutdown()
g_arena.ReleaseSHMSegment();
physical_base = nullptr;
logical_base = nullptr;
#ifdef __LIBRETRO__
single_physical_base = nullptr;
#endif
mmio_mapping.reset();
INFO_LOG(MEMMAP, "Memory system shut down.");
}
Expand Down
4 changes: 4 additions & 0 deletions Source/Core/Core/HW/Memmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ extern u8* m_pRAM;
extern u8* m_pEXRAM;
extern u8* m_pL1Cache;
extern u8* m_pFakeVMEM;
#ifdef __LIBRETRO__
extern u8* m_pContiguousRAM;
extern u32 m_TotalMemorySize ;
#endif

enum
{
Expand Down
7 changes: 7 additions & 0 deletions Source/Core/DolphinLibretro/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "Core/Config/SYSCONFSettings.h"
#include "Core/Core.h"
#include "Core/HW/CPU.h"
#include "Core/HW/Memmap.h"
#include "Core/HW/ProcessorInterface.h"
#include "Core/HW/VideoInterface.h"
#include "Core/State.h"
Expand Down Expand Up @@ -286,11 +287,17 @@ unsigned retro_api_version()

size_t retro_get_memory_size(unsigned id)
{
if ( id == RETRO_MEMORY_SYSTEM_RAM ) {
return Memory::m_TotalMemorySize;
}
return 0;
}

void* retro_get_memory_data(unsigned id)
{
if ( id == RETRO_MEMORY_SYSTEM_RAM ) {
return Memory::m_pContiguousRAM;
}
return NULL;
}

Expand Down

0 comments on commit d61e5d3

Please sign in to comment.