Skip to content

Commit

Permalink
Use MEMSIZE SFO param to detect 64MB homebrew.
Browse files Browse the repository at this point in the history
Now, use 32MB for normal games even in PSP-2000 mode, which is how real
firmware behaves.
  • Loading branch information
unknownbrackets committed Dec 23, 2015
1 parent d5219eb commit d273dee
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 11 deletions.
8 changes: 8 additions & 0 deletions Core/ELF/ParamSFO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ u8* ParamSFOData::GetValueData(std::string key, unsigned int *size)
return it->second.u_value;
}

std::vector<std::string> ParamSFOData::GetKeys() {
std::vector<std::string> result;
for (const auto &pair : values) {
result.push_back(pair.first);
}
return result;
}

// I'm so sorry Ced but this is highly endian unsafe :(
bool ParamSFOData::ReadSFO(const u8 *paramsfo, size_t size)
{
Expand Down
2 changes: 2 additions & 0 deletions Core/ELF/ParamSFO.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class ParamSFOData
std::string GetValueString(std::string key);
u8* GetValueData(std::string key, unsigned int *size);

std::vector<std::string> GetKeys();

bool ReadSFO(const u8 *paramsfo, size_t size);
bool WriteSFO(u8 **paramsfo, size_t *size);

Expand Down
16 changes: 14 additions & 2 deletions Core/MemMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,16 @@ void Init()

void DoState(PointerWrap &p)
{
auto s = p.Section("Memory", 1, 2);
auto s = p.Section("Memory", 1, 3);
if (!s)
return;

if (s < 2) {
if (!g_RemasterMode)
g_MemorySize = RAM_NORMAL_SIZE;
g_PSPModel = PSP_MODEL_FAT;
} else {
} else if (s == 2) {
// In version 2, we determine memory size based on PSP model.
u32 oldMemorySize = g_MemorySize;
p.Do(g_PSPModel);
p.DoMarker("PSPModel");
Expand All @@ -359,6 +360,17 @@ void DoState(PointerWrap &p)
Init();
}
}
} else {
// In version 3, we started just saving the memory size directly.
// It's no longer based strictly on the PSP model.
u32 oldMemorySize = g_MemorySize;
p.Do(g_PSPModel);
p.DoMarker("PSPModel");
p.Do(g_MemorySize);
if (oldMemorySize != g_MemorySize) {
Shutdown();
Init();
}
}

p.DoArray(GetPointer(PSP_GetKernelMemoryBase()), g_MemorySize);
Expand Down
43 changes: 38 additions & 5 deletions Core/PSPLoaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,53 @@ void InitMemoryForGameISO(FileLoader *fileLoader) {
{
std::vector<u8> paramsfo;
pspFileSystem.ReadEntireFile(sfoPath, paramsfo);
if (g_paramSFO.ReadSFO(paramsfo))
{
if (g_paramSFO.ReadSFO(paramsfo)) {
// TODO: Check the SFO for other parameters that might be useful for identifying?
gameID = g_paramSFO.GetValueString("DISC_ID");

for (size_t i = 0; i < ARRAY_SIZE(g_HDRemasters); i++) {
if(g_HDRemasters[i].gameID == gameID) {
if (g_HDRemasters[i].gameID == gameID) {
g_RemasterMode = true;
Memory::g_MemorySize = g_HDRemasters[i].MemorySize;
if(g_HDRemasters[i].DoubleTextureCoordinates)
if (g_HDRemasters[i].DoubleTextureCoordinates)
g_DoubleTextureCoordinates = true;
break;
}
}
DEBUG_LOG(LOADER, "HDRemaster mode is %s", g_RemasterMode? "true": "false");
if (g_RemasterMode) {
INFO_LOG(LOADER, "HDRemaster found, using increased memory");
}
}
}
}

void InitMemoryForGamePBP(FileLoader *fileLoader) {
bool useLargeMem = false;

// TODO: Change PBPReader to read FileLoader objects?
std::string filename = fileLoader->Path();
PBPReader pbp(filename.c_str());
if (pbp.IsValid() && !pbp.IsELF()) {
size_t sfoSize;
u8 *sfoData = pbp.GetSubFile(PBP_PARAM_SFO, &sfoSize);
if (sfoData) {
ParamSFOData paramSFO;
paramSFO.ReadSFO(sfoData, sfoSize);

// This is the parameter CFW uses to determine homebrew wants the full 64MB.
int memsize = paramSFO.GetValueInt("MEMSIZE");
useLargeMem = memsize == 1;

delete [] sfoData;
}
}

if (useLargeMem) {
if (Memory::g_PSPModel != PSP_MODEL_FAT) {
INFO_LOG(LOADER, "Homebrew requested full PSP-2000 memory access");
Memory::g_MemorySize = Memory::RAM_DOUBLE_SIZE;
} else {
WARN_LOG(LOADER, "Homebrew requested full PSP-2000 memory access, ignoring in PSP-1000 mode");
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Core/PSPLoaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ class FileLoader;
bool Load_PSP_ISO(FileLoader *fileLoader, std::string *error_string);
bool Load_PSP_ELF_PBP(FileLoader *fileLoader, std::string *error_string);
void InitMemoryForGameISO(FileLoader *fileLoader);
void InitMemoryForGamePBP(FileLoader *fileLoader);
16 changes: 12 additions & 4 deletions Core/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,7 @@ void CPU_Init() {

// Default memory settings
// Seems to be the safest place currently..
if (g_Config.iPSPModel == PSP_MODEL_FAT)
Memory::g_MemorySize = Memory::RAM_NORMAL_SIZE; // 32 MB of ram by default
else
Memory::g_MemorySize = Memory::RAM_DOUBLE_SIZE;
Memory::g_MemorySize = Memory::RAM_NORMAL_SIZE; // 32 MB of ram by default

g_RemasterMode = false;
g_DoubleTextureCoordinates = false;
Expand Down Expand Up @@ -209,6 +206,17 @@ void CPU_Init() {
case FILETYPE_PSP_DISC_DIRECTORY:
InitMemoryForGameISO(loadedFile);
break;
case FILETYPE_PSP_PBP_DIRECTORY: {
// TODO: Can we get this lower into LoadFile?
std::string ebootFilename = loadedFile->Path() + "/EBOOT.PBP";
FileLoader *tempLoader = ConstructFileLoader(ebootFilename);
InitMemoryForGamePBP(tempLoader);
delete tempLoader;
break;
}
case FILETYPE_PSP_PBP:
InitMemoryForGamePBP(loadedFile);
break;
default:
break;
}
Expand Down

0 comments on commit d273dee

Please sign in to comment.