diff --git a/Core/HDRemaster.cpp b/Core/HDRemaster.cpp index 5bf731b87f..8b62719e00 100644 --- a/Core/HDRemaster.cpp +++ b/Core/HDRemaster.cpp @@ -17,4 +17,4 @@ #include "HDRemaster.h" -bool g_RemasterMode = false; \ No newline at end of file +bool g_RemasterMode = false; diff --git a/Core/HDRemaster.h b/Core/HDRemaster.h index 0e89c33ce1..4fced19876 100644 --- a/Core/HDRemaster.h +++ b/Core/HDRemaster.h @@ -18,24 +18,31 @@ #pragma once #include - -const int REMASTER_COUNT = 9; +#include "CommonTypes.h" // This bool is the key to having the HD remasters work. // We keep it set to false by default in PSPLoaders.cpp // in order to keep the 99% of other PSP games working happily. extern bool g_RemasterMode; -// TODO: Are those BLJM* IDs really valid? I haven't seen any -// HD Remasters with them, but they're included for safety. -const std::string g_RemastersGameIDs[REMASTER_COUNT] = { - "NPJB40001", // MONSTER HUNTER PORTABLE 3rd HD Ver. - "BLJM85002", // K-ON Houkago Live HD Ver - "NPJB40002", // K-ON Houkago Live HD Ver - "BLJM85003", // Shin Sangoku Musou Multi Raid 2 HD Ver - "NPJB40003", // Shin Sangoku Musou Multi Raid 2 HD Ver - "BLJM85004", // Eiyuu Densetsu Sora no Kiseki FC Kai HD Edition - "NPJB40004", // Eiyuu Densetsu Sora no Kiseki FC Kai HD Edition - "BLJM85005", // Eiyuu Densetsu: Sora no Kiseki SC Kai HD Edition - "NPJB40005", // Eiyuu Densetsu: Sora no Kiseki SC Kai HD Edition +struct HDRemaster { + std::string gameID; + u64 MemorySize; + u64 MemoryEnd; //Seems to be different for each game as well +}; + +// TODO: Are those BLJM* IDs really valid? They seem to be the physical PS3 disk IDs, +// but they're included for safety. +const u32 REMASTER_COUNT = 9; + +const struct HDRemaster g_HDRemasters[REMASTER_COUNT] = { + { "NPJB40001", 0x2800000, 0x0B8FFFFF }, // MONSTER HUNTER PORTABLE 3rd HD Ver. + { "BLJM85002", 0x2800000, 0x0B8FFFFF }, // K-ON Houkago Live HD Ver + { "NPJB40002", 0x2800000, 0x0B8FFFFF }, // K-ON Houkago Live HD Ver + { "BLJM85003", 0x2800000, 0x0B8FFFFF }, // Shin Sangoku Musou Multi Raid 2 HD Ver + { "NPJB40003", 0x2800000, 0x0B8FFFFF }, // Shin Sangoku Musou Multi Raid 2 HD Ver + { "BLJM85004", 0x3000000, 0x0B8FFFFF }, // Eiyuu Densetsu Sora no Kiseki FC Kai HD Edition + { "NPJB40004", 0x3000000, 0x0B8FFFFF }, // Eiyuu Densetsu Sora no Kiseki FC Kai HD Edition + { "BLJM85005", 0x4000000, 0x0B8FFFFF }, // Eiyuu Densetsu: Sora no Kiseki SC Kai HD Edition + { "NPJB40005", 0x4000000, 0x0B8FFFFF }, // Eiyuu Densetsu: Sora no Kiseki SC Kai HD Edition }; diff --git a/Core/MemMap.cpp b/Core/MemMap.cpp index ba79340e02..ce20352bd1 100644 --- a/Core/MemMap.cpp +++ b/Core/MemMap.cpp @@ -55,17 +55,22 @@ u8 *m_pKernelRAM; // RAM mirrored up to "kernel space". Fully accessible at all u8 *m_pPhysicalVRAM; u8 *m_pUncachedVRAM; +// Holds the ending address of the PSP's user space. +// Required for HD Remasters to work properly. +u32 g_MemoryEnd; +u32 g_MemoryMask; +u32 g_MemorySize; // We don't declare the IO region in here since its handled by other means. -static const MemoryView views[] = +static MemoryView views[] = { {&m_pScratchPad, &m_pPhysicalScratchPad, 0x00010000, SCRATCHPAD_SIZE, 0}, {NULL, &m_pUncachedScratchPad, 0x40010000, SCRATCHPAD_SIZE, MV_MIRROR_PREVIOUS}, {&m_pVRAM, &m_pPhysicalVRAM, 0x04000000, 0x00800000, 0}, {NULL, &m_pUncachedVRAM, 0x44000000, 0x00800000, MV_MIRROR_PREVIOUS}, - {&m_pRAM, &m_pPhysicalRAM, 0x08000000, RAM_SIZE, 0}, // only from 0x08800000 is it usable (last 24 megs) - {NULL, &m_pUncachedRAM, 0x48000000, RAM_SIZE, MV_MIRROR_PREVIOUS}, - {NULL, &m_pKernelRAM, 0x88000000, RAM_SIZE, MV_MIRROR_PREVIOUS}, + {&m_pRAM, &m_pPhysicalRAM, 0x08000000, g_MemorySize, 0}, // only from 0x08800000 is it usable (last 24 megs) + {NULL, &m_pUncachedRAM, 0x48000000, g_MemorySize, MV_MIRROR_PREVIOUS}, + {NULL, &m_pKernelRAM, 0x88000000, g_MemorySize, MV_MIRROR_PREVIOUS}, // TODO: There are a few swizzled mirrors of VRAM, not sure about the best way to // implement those. @@ -76,6 +81,11 @@ static const int num_views = sizeof(views) / sizeof(MemoryView); void Init() { int flags = 0; + + g_MemoryMask = g_MemorySize - 1; + for(int i = 4; i < 7; i++) + views[i].size = g_MemorySize; + base = MemoryMap_Setup(views, num_views, flags, &g_arena); INFO_LOG(MEMMAP, "Memory system initialized. RAM at %p (mirror at 0 @ %p, uncached @ %p)", @@ -84,7 +94,7 @@ void Init() void DoState(PointerWrap &p) { - p.DoArray(m_pRAM, RAM_SIZE); + p.DoArray(m_pRAM, g_MemorySize); p.DoMarker("RAM"); p.DoArray(m_pVRAM, VRAM_SIZE); p.DoMarker("VRAM"); @@ -106,7 +116,7 @@ void Shutdown() void Clear() { if (m_pRAM) - memset(m_pRAM, 0, RAM_SIZE); + memset(m_pRAM, 0, g_MemorySize); if (m_pScratchPad) memset(m_pScratchPad, 0, SCRATCHPAD_SIZE); if (m_pVRAM) diff --git a/Core/MemMap.h b/Core/MemMap.h index 6e857cdd86..9cf4f26ab7 100644 --- a/Core/MemMap.h +++ b/Core/MemMap.h @@ -66,7 +66,7 @@ inline u32 PSP_GetKernelMemoryEnd() { return 0x08400000;} // game through sceKernelVolatileMemTryLock. inline u32 PSP_GetUserMemoryBase() { return 0x08800000;} -inline u32 PSP_GetUserMemoryEnd() { return g_RemasterMode? 0x0B8FFFFF : 0x0A000000;} +inline u32 PSP_GetKernelMemoryEnd(); inline u32 PSP_GetDefaultLoadAddress() { return 0x08804000;} //inline u32 PSP_GetDefaultLoadAddress() { return 0x0898dab0;} @@ -99,14 +99,12 @@ extern u8 *m_pUncachedRAM; extern u8 *m_pPhysicalVRAM; extern u8 *m_pUncachedVRAM; -// TODO: Later PSP models got more RAM. -// Done, but we still need an emulator-wide rewrite for more RAM support/larger allocations -// to remove the remaster hack.. +extern u32 g_MemoryEnd; // End of PSP Userspace +extern u32 g_MemorySize; // Replaces RAM_SIZE +extern u32 g_MemoryMask; // Replaces RAM_MASK + enum { - RAM_SIZE = 0x4000000, // 64 MB - although only the upper 24 are available for the user. - RAM_MASK = RAM_SIZE - 1, - VRAM_SIZE = 0x200000, VRAM_MASK = VRAM_SIZE - 1, @@ -359,6 +357,8 @@ struct PSPPointer } }; +inline u32 PSP_GetUserMemoryEnd() { return Memory::g_MemoryEnd;} + template inline bool operator==(const PSPPointer &lhs, const PSPPointer &rhs) { diff --git a/Core/MemMapFunctions.cpp b/Core/MemMapFunctions.cpp index e8d7575464..e29c0e9760 100644 --- a/Core/MemMapFunctions.cpp +++ b/Core/MemMapFunctions.cpp @@ -44,10 +44,10 @@ namespace Memory u8 *GetPointer(const u32 address) { if ((address & 0x3E000000) == 0x08000000) { - return m_pRAM + (address & RAM_MASK); + return m_pRAM + (address & g_MemoryMask); } else if (g_RemasterMode && (address & 0x3E000000) != 0x08000000) { - return m_pRAM + (address & RAM_MASK); + return m_pRAM + (address & g_MemoryMask); } else if ((address & 0x3F800000) == 0x04000000) { return m_pVRAM + (address & VRAM_MASK); @@ -74,10 +74,10 @@ inline void ReadFromHardware(T &var, const u32 address) // Could just do a base-relative read, too.... TODO if ((address & 0x3E000000) == 0x08000000) { - var = *((const T*)&m_pRAM[address & RAM_MASK]); + var = *((const T*)&m_pRAM[address & g_MemoryMask]); } else if (g_RemasterMode && (address & 0x3E000000) != 0x08000000) { - var = *((const T*)&m_pRAM[address & RAM_MASK]); + var = *((const T*)&m_pRAM[address & g_MemoryMask]); } else if ((address & 0x3F800000) == 0x04000000) { var = *((const T*)&m_pVRAM[address & VRAM_MASK]); @@ -107,10 +107,10 @@ inline void WriteToHardware(u32 address, const T data) // Could just do a base-relative write, too.... TODO if ((address & 0x3E000000) == 0x08000000) { - *(T*)&m_pRAM[address & RAM_MASK] = data; + *(T*)&m_pRAM[address & g_MemoryMask] = data; } else if (g_RemasterMode && (address & 0x3E000000) != 0x08000000) { - *(T*)&m_pRAM[address & RAM_MASK] = data; + *(T*)&m_pRAM[address & g_MemoryMask] = data; } else if ((address & 0x3F800000) == 0x04000000) { *(T*)&m_pVRAM[address & VRAM_MASK] = data; diff --git a/Core/PSPLoaders.cpp b/Core/PSPLoaders.cpp index 79466850b5..0e670e84c5 100644 --- a/Core/PSPLoaders.cpp +++ b/Core/PSPLoaders.cpp @@ -40,6 +40,8 @@ #include "HLE/sceKernelMemory.h" #include "ELF/ParamSFO.h" +#include "Core/MemMap.h" + bool Load_PSP_ISO(const char *filename, std::string *error_string) { ISOFileSystem *umd2 = new ISOFileSystem(&pspFileSystem, constructBlockDevice(filename)); @@ -68,9 +70,13 @@ bool Load_PSP_ISO(const char *filename, std::string *error_string) INFO_LOG(LOADER, "%s", title); host->SetWindowTitle(title); g_RemasterMode = false; + Memory::g_MemoryEnd = 0x0A000000; + Memory::g_MemorySize = 0x2000000; for(int i = 0; i < REMASTER_COUNT; i++) { - if(g_RemastersGameIDs[i] == gameID) { + if(g_HDRemasters[i].gameID == gameID) { g_RemasterMode = true; + Memory::g_MemoryEnd = g_HDRemasters[i].MemoryEnd; + Memory::g_MemorySize = g_HDRemasters[i].MemorySize; break; } } diff --git a/GPU/GLES/DisplayListInterpreter.cpp b/GPU/GLES/DisplayListInterpreter.cpp index 54a4e256e8..7e8fc508c2 100644 --- a/GPU/GLES/DisplayListInterpreter.cpp +++ b/GPU/GLES/DisplayListInterpreter.cpp @@ -320,11 +320,7 @@ u32 GLES_GPU::DrawSync(int mode) // TODO: Fix this so it doesn't crash void GLES_GPU::FastRunLoop(DisplayList &list) { for (; downcount > 0; --downcount) { - u32 op; - if(g_RemasterMode) - op = Memory::Read_U32(list.pc); - else - op = Memory::ReadUnchecked_U32(list.pc); + u32 op = Memory::ReadUnchecked_U32(list.pc); u32 cmd = op >> 24; u32 diff = op ^ gstate.cmdmem[cmd]; diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index a53cb18eb8..ed5cd7f1eb 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -399,7 +399,7 @@ bool GPUCommon::InterpretList(DisplayList &list) const bool dumpThisFrame = dumpThisFrame_; // TODO: Add check for displaylist debugger. - const bool useFastRunLoop = !dumpThisFrame; + const bool useFastRunLoop = !dumpThisFrame && !g_RemasterMode; while (gpuState == GPUSTATE_RUNNING) { if (list.pc == list.stall)