Parse PARAM.SFO to get the disc ID, show in title bar on Windows

This commit is contained in:
Henrik Rydgard 2012-11-30 21:49:59 +01:00
parent 6102e0f143
commit a5e35ad6d9
13 changed files with 171 additions and 6 deletions

View File

@ -588,6 +588,8 @@ add_library(${CoreLibName} ${CoreLinkType}
Core/ELF/ElfTypes.h Core/ELF/ElfTypes.h
Core/ELF/PrxDecrypter.cpp Core/ELF/PrxDecrypter.cpp
Core/ELF/PrxDecrypter.h Core/ELF/PrxDecrypter.h
Core/ELF/ParamSFO.cpp
Core/ELF/ParamSFO.h
Core/FileSystems/BlockDevices.cpp Core/FileSystems/BlockDevices.cpp
Core/FileSystems/BlockDevices.h Core/FileSystems/BlockDevices.h
Core/FileSystems/DirectoryFileSystem.cpp Core/FileSystems/DirectoryFileSystem.cpp

View File

@ -13,6 +13,7 @@ set(SRCS
MIPS/MIPSVFPUUtils.cpp MIPS/MIPSVFPUUtils.cpp
MIPS/JitCommon/JitCommon.cpp MIPS/JitCommon/JitCommon.cpp
ELF/ElfReader.cpp ELF/ElfReader.cpp
ELF/ParamSFO.cpp
ELF/PrxDecrypter.cpp ELF/PrxDecrypter.cpp
HLE/HLE.cpp HLE/HLE.cpp
HLE/HLETables.cpp HLE/HLETables.cpp

View File

@ -120,6 +120,7 @@
<ClCompile Include="Debugger\Breakpoints.cpp" /> <ClCompile Include="Debugger\Breakpoints.cpp" />
<ClCompile Include="Debugger\SymbolMap.cpp" /> <ClCompile Include="Debugger\SymbolMap.cpp" />
<ClCompile Include="ELF\ElfReader.cpp" /> <ClCompile Include="ELF\ElfReader.cpp" />
<ClCompile Include="ELF\ParamSFO.cpp" />
<ClCompile Include="ELF\PrxDecrypter.cpp" /> <ClCompile Include="ELF\PrxDecrypter.cpp" />
<ClCompile Include="FileSystems\BlockDevices.cpp" /> <ClCompile Include="FileSystems\BlockDevices.cpp" />
<ClCompile Include="FileSystems\DirectoryFileSystem.cpp" /> <ClCompile Include="FileSystems\DirectoryFileSystem.cpp" />
@ -251,6 +252,7 @@
<ClInclude Include="Debugger\SymbolMap.h" /> <ClInclude Include="Debugger\SymbolMap.h" />
<ClInclude Include="ELF\ElfReader.h" /> <ClInclude Include="ELF\ElfReader.h" />
<ClInclude Include="ELF\ElfTypes.h" /> <ClInclude Include="ELF\ElfTypes.h" />
<ClInclude Include="ELF\ParamSFO.h" />
<ClInclude Include="ELF\PrxDecrypter.h" /> <ClInclude Include="ELF\PrxDecrypter.h" />
<ClInclude Include="FileSystems\BlockDevices.h" /> <ClInclude Include="FileSystems\BlockDevices.h" />
<ClInclude Include="FileSystems\DirectoryFileSystem.h" /> <ClInclude Include="FileSystems\DirectoryFileSystem.h" />

View File

@ -300,6 +300,9 @@
<ClCompile Include="HLE\sceFont.cpp"> <ClCompile Include="HLE\sceFont.cpp">
<Filter>HLE\Libraries</Filter> <Filter>HLE\Libraries</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="ELF\ParamSFO.cpp">
<Filter>ELF</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="ELF\ElfReader.h"> <ClInclude Include="ELF\ElfReader.h">
@ -548,6 +551,9 @@
<ClInclude Include="HLE\sceFont.h"> <ClInclude Include="HLE\sceFont.h">
<Filter>HLE\Libraries</Filter> <Filter>HLE\Libraries</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="ELF\ParamSFO.h">
<Filter>ELF</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="CMakeLists.txt" /> <None Include="CMakeLists.txt" />

93
Core/ELF/ParamSFO.cpp Normal file
View File

@ -0,0 +1,93 @@
// Copyright (c) 2012- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include "../Globals.h"
#include "ParamSFO.h"
struct Header
{
u32 magic; /* Always PSF */
u32 version; /* Usually 1.1 */
u32 key_table_start; /* Start position of key_table */
u32 data_table_start; /* Start position of data_table */
u32 index_table_entries; /* Number of entries in index_table*/
};
struct IndexTable
{
u16 key_table_offset; /* Offset of the param_key from start of key_table */
u16 param_fmt; /* Type of data of param_data in the data_table */
u32 param_len; /* Used Bytes by param_data in the data_table */
u32 param_max_len; /* Total bytes reserved for param_data in the data_table */
u32 data_table_offset; /* Offset of the param_data from start of data_table */
};
void ParseDataString(const char *key, const char *utfdata, ParamSFOData *sfodata)
{
if (!strcmp(key, "DISC_ID"))
{
sfodata->discID = utfdata;
}
}
// I'm so sorry Ced but this is highly endian unsafe :(
bool ParseParamSFO(const u8 *paramsfo, size_t size, ParamSFOData *data)
{
const Header *header = (const Header *)paramsfo;
if (header->magic != 0x46535000)
return false;
if (header->version != 0x00000101)
WARN_LOG(LOADER, "Unexpected SFO header version: %08x", header->version);
const IndexTable *indexTables = (const IndexTable *)(paramsfo + sizeof(Header));
const u8 *key_start = paramsfo + header->key_table_start;
const u8 *data_start = paramsfo + header->data_table_start;
for (int i = 0; i < header->index_table_entries; i++)
{
const char *key = (const char *)(key_start + indexTables[i].key_table_offset);
switch (indexTables[i].param_fmt) {
case 0x0404:
{
// Unsigned int
const u32 *data = (const u32 *)(data_start + indexTables[i].data_table_offset);
DEBUG_LOG(LOADER, "%s %08x", key, *data);
}
break;
case 0x0004:
// Special format UTF-8
{
const char *utfdata = (const char *)(data_start + indexTables[i].data_table_offset);
DEBUG_LOG(LOADER, "%s %s", key, utfdata);
ParseDataString(key, utfdata, data);
}
break;
case 0x0204:
// Regular UTF-8
{
const char *utfdata = (const char *)(data_start + indexTables[i].data_table_offset);
DEBUG_LOG(LOADER, "%s %s", key, utfdata);
ParseDataString(key, utfdata, data);
}
break;
}
}
return true;
}

27
Core/ELF/ParamSFO.h Normal file
View File

@ -0,0 +1,27 @@
// Copyright (c) 2012- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#pragma once
struct ParamSFOData
{
std::string discID;
};
bool ParseParamSFO(const u8 *paramsfo, size_t size, ParamSFOData *data);

View File

@ -58,6 +58,7 @@ public:
virtual bool IsDebuggingEnabled() {return true;} virtual bool IsDebuggingEnabled() {return true;}
virtual bool AttemptLoadSymbolMap() {return false;} virtual bool AttemptLoadSymbolMap() {return false;}
virtual void SetWindowTitle(const char *message) {}
}; };
extern Host *host; extern Host *host;

View File

@ -950,7 +950,7 @@ int MIPSInterpret_RunUntil(u64 globalTicks)
// int cycles = 0; // int cycles = 0;
{ {
again: again:
u32 op = Memory::ReadUnchecked_U32(curMips->pc); u32 op = Memory::Read_U32(curMips->pc);
//u32 op = Memory::Read_Opcode_JIT(mipsr4k.pc); //u32 op = Memory::Read_Opcode_JIT(mipsr4k.pc);
/* /*
// Choke on VFPU // Choke on VFPU

View File

@ -37,7 +37,7 @@
#include "HLE/sceKernelThread.h" #include "HLE/sceKernelThread.h"
#include "HLE/sceKernelModule.h" #include "HLE/sceKernelModule.h"
#include "HLE/sceKernelMemory.h" #include "HLE/sceKernelMemory.h"
#include "ELF/ParamSFO.h"
BlockDevice *constructBlockDevice(const char *filename) BlockDevice *constructBlockDevice(const char *filename)
{ {
@ -52,10 +52,13 @@ BlockDevice *constructBlockDevice(const char *filename)
} }
} }
bool Load_PSP_ISO(const char *filename, std::string *error_string) bool Load_PSP_ISO(const char *filename, std::string *error_string)
{ {
ISOFileSystem *umd2 = new ISOFileSystem(&pspFileSystem, constructBlockDevice(filename)); ISOFileSystem *umd2 = new ISOFileSystem(&pspFileSystem, constructBlockDevice(filename));
// Parse PARAM.SFO
//pspFileSystem.Mount("host0:",umd2); //pspFileSystem.Mount("host0:",umd2);
pspFileSystem.Mount("umd0:", umd2); pspFileSystem.Mount("umd0:", umd2);
pspFileSystem.Mount("umd1:", umd2); pspFileSystem.Mount("umd1:", umd2);
@ -66,6 +69,24 @@ bool Load_PSP_ISO(const char *filename, std::string *error_string)
pspFileSystem.Mount("DISC0:", umd2); pspFileSystem.Mount("DISC0:", umd2);
pspFileSystem.Mount("UMD:", umd2); pspFileSystem.Mount("UMD:", umd2);
std::string sfoPath("disc0:/PSP_GAME/PARAM.SFO");
PSPFileInfo fileInfo = pspFileSystem.GetFileInfo(sfoPath.c_str());
if (fileInfo.exists)
{
u8 *paramsfo = new u8[fileInfo.size];
u32 fd = pspFileSystem.OpenFile(sfoPath, FILEACCESS_READ);
pspFileSystem.ReadFile(fd, paramsfo, fileInfo.size);
pspFileSystem.CloseFile(fd);
ParamSFOData data;
if (ParseParamSFO(paramsfo, fileInfo.size, &data))
{
INFO_LOG(LOADER, "Disc ID: %s", data.discID.c_str());
host->SetWindowTitle(data.discID.c_str());
}
delete [] paramsfo;
}
std::string bootpath("disc0:/PSP_GAME/SYSDIR/EBOOT.BIN"); std::string bootpath("disc0:/PSP_GAME/SYSDIR/EBOOT.BIN");
// bypass patchers // bypass patchers
if (pspFileSystem.GetFileInfo("disc0:/PSP_GAME/SYSDIR/EBOOT.OLD").exists) { if (pspFileSystem.GetFileInfo("disc0:/PSP_GAME/SYSDIR/EBOOT.OLD").exists) {
@ -80,6 +101,7 @@ bool Load_PSP_ISO(const char *filename, std::string *error_string)
if (memcmp(head, "~PSP", 4) == 0 || memcmp(head, "\x7F""ELF", 4) == 0) { if (memcmp(head, "~PSP", 4) == 0 || memcmp(head, "\x7F""ELF", 4) == 0) {
hasEncrypted = true; hasEncrypted = true;
} }
pspFileSystem.CloseFile(fd);
} }
if (!hasEncrypted) if (!hasEncrypted)
{ {

View File

@ -35,6 +35,13 @@ void WindowsHost::ShutdownGL()
GL_Shutdown(); GL_Shutdown();
} }
void WindowsHost::SetWindowTitle(const char *message)
{
// Really need a better way to deal with versions.
std::string title = "PPSSPP v0.31 - ";
title += message;
SetWindowText(mainWindow_, title.c_str());
}
void WindowsHost::InitSound(PMixer *mixer) void WindowsHost::InitSound(PMixer *mixer)
{ {

View File

@ -6,9 +6,10 @@
class WindowsHost : public Host class WindowsHost : public Host
{ {
public: public:
WindowsHost(HWND _displayWindow) WindowsHost(HWND mainWindow, HWND displayWindow)
{ {
displayWindow = _displayWindow; mainWindow_ = mainWindow;
displayWindow_ = displayWindow;
input = getInputDevices(); input = getInputDevices();
} }
void UpdateMemView(); void UpdateMemView();
@ -31,8 +32,10 @@ public:
void BootDone(); void BootDone();
void PrepareShutdown(); void PrepareShutdown();
bool AttemptLoadSymbolMap(); bool AttemptLoadSymbolMap();
void SetWindowTitle(const char *message);
private: private:
HWND displayWindow; HWND displayWindow_;
HWND mainWindow_;
std::list<std::shared_ptr<InputDevice>> input; std::list<std::shared_ptr<InputDevice>> input;
}; };

View File

@ -75,12 +75,12 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin
InitCommonControlsEx(&comm); InitCommonControlsEx(&comm);
MainWindow::Init(_hInstance); MainWindow::Init(_hInstance);
host = new WindowsHost(MainWindow::GetDisplayHWND());
HACCEL hAccelTable = LoadAccelerators(_hInstance, (LPCTSTR)IDR_ACCELS); HACCEL hAccelTable = LoadAccelerators(_hInstance, (LPCTSTR)IDR_ACCELS);
g_hPopupMenus = LoadMenu(_hInstance, (LPCSTR)IDR_POPUPMENUS); g_hPopupMenus = LoadMenu(_hInstance, (LPCSTR)IDR_POPUPMENUS);
MainWindow::Show(_hInstance, iCmdShow); MainWindow::Show(_hInstance, iCmdShow);
host = new WindowsHost(MainWindow::GetHWND(), MainWindow::GetDisplayHWND());
HWND hwndMain = MainWindow::GetHWND(); HWND hwndMain = MainWindow::GetHWND();
HMENU menu = GetMenu(hwndMain); HMENU menu = GetMenu(hwndMain);

View File

@ -80,6 +80,7 @@ LOCAL_SRC_FILES := \
$(SRC)/GPU/Null/NullGpu.cpp \ $(SRC)/GPU/Null/NullGpu.cpp \
$(SRC)/Core/ELF/ElfReader.cpp \ $(SRC)/Core/ELF/ElfReader.cpp \
$(SRC)/Core/ELF/PrxDecrypter.cpp \ $(SRC)/Core/ELF/PrxDecrypter.cpp \
$(SRC)/Core/ELF/ParamSFO.cpp \
$(SRC)/Core/HW/MemoryStick.cpp \ $(SRC)/Core/HW/MemoryStick.cpp \
$(SRC)/Core/Core.cpp \ $(SRC)/Core/Core.cpp \
$(SRC)/Core/Config.cpp \ $(SRC)/Core/Config.cpp \