From fe8ada4d7ec1e6f8812f8118de872e823a166ba7 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 15 Mar 2014 17:20:34 -0700 Subject: [PATCH 1/4] Log the name of the save operation, not just #. Makes it a lot easier to read... --- Core/Dialog/PSPSaveDialog.cpp | 4 +++- Core/Dialog/SavedataParam.h | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Core/Dialog/PSPSaveDialog.cpp b/Core/Dialog/PSPSaveDialog.cpp index 4955804cf3..be7b041edd 100755 --- a/Core/Dialog/PSPSaveDialog.cpp +++ b/Core/Dialog/PSPSaveDialog.cpp @@ -64,7 +64,9 @@ int PSPSaveDialog::Init(int paramAddr) int retval = param.SetPspParam(&request); - INFO_LOG(SCEUTILITY,"sceUtilitySavedataInitStart(%08x) : Mode = %i", paramAddr, (SceUtilitySavedataType)(u32)param.GetPspParam()->mode); + const u32 mode = (u32)param.GetPspParam()->mode; + const char *modeName = mode < ARRAY_SIZE(utilitySavedataTypeNames) ? utilitySavedataTypeNames[mode] : "UNKNOWN"; + INFO_LOG(SCEUTILITY,"sceUtilitySavedataInitStart(%08x) - %s (%d)", paramAddr, modeName, mode); yesnoChoice = 1; switch ((SceUtilitySavedataFocus)(u32)param.GetPspParam()->focus) diff --git a/Core/Dialog/SavedataParam.h b/Core/Dialog/SavedataParam.h index 1aeffba75a..315cf49cb3 100644 --- a/Core/Dialog/SavedataParam.h +++ b/Core/Dialog/SavedataParam.h @@ -57,6 +57,32 @@ enum SceUtilitySavedataType SCE_UTILITY_SAVEDATA_TYPE_GETSIZE = 22, }; +static const char *const utilitySavedataTypeNames[] = { + "AUTOLOAD", + "AUTOSAVE", + "LOAD", + "SAVE", + "LISTLOAD", + "LISTSAVE", + "DELETE", + "LISTDELETE", + "SIZES", + "AUTODELETE", + "SINGLEDELETE", + "LIST", + "FILES", + "MAKEDATASECURE", + "MAKEDATA", + "READDATASECURE", + "READDATA", + "WRITEDATASECURE", + "WRITEDATA", + "ERASESECURE", + "ERASE", + "DELETEDATA", + "GETSIZE", +}; + enum SceUtilitySavedataFocus { SCE_UTILITY_SAVEDATA_FOCUS_NAME = 0, // specified by saveName[] From 68affb4a54d4ae01b55962a08e9a23e8f8cebaab Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 15 Mar 2014 17:23:08 -0700 Subject: [PATCH 2/4] Reduce log level of some tested sceFont funcs. --- Core/HLE/sceFont.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Core/HLE/sceFont.cpp b/Core/HLE/sceFont.cpp index 420a16a385..5a16b9dfbe 100644 --- a/Core/HLE/sceFont.cpp +++ b/Core/HLE/sceFont.cpp @@ -755,7 +755,7 @@ u32 sceFontOpen(u32 libHandle, u32 index, u32 mode, u32 errorCodePtr) { return -1; } - INFO_LOG(SCEFONT, "sceFontOpen(%x, %x, %x, %x)", libHandle, index, mode, errorCodePtr); + DEBUG_LOG(SCEFONT, "sceFontOpen(%x, %x, %x, %x)", libHandle, index, mode, errorCodePtr); FontLib *fontLib = GetFontLib(libHandle); if (fontLib == NULL) { *errorCode = ERROR_FONT_INVALID_LIBID; @@ -797,7 +797,7 @@ u32 sceFontOpenUserMemory(u32 libHandle, u32 memoryFontAddrPtr, u32 memoryFontLe return 0; } - INFO_LOG(SCEFONT, "sceFontOpenUserMemory(%08x, %08x, %08x, %08x)", libHandle, memoryFontAddrPtr, memoryFontLength, errorCodePtr); + DEBUG_LOG(SCEFONT, "sceFontOpenUserMemory(%08x, %08x, %08x, %08x)", libHandle, memoryFontAddrPtr, memoryFontLength, errorCodePtr); const u8 *fontData = Memory::GetPointer(memoryFontAddrPtr); Font *f = new Font(fontData, memoryFontLength); LoadedFont *font = fontLib->OpenFont(f, FONT_OPEN_USERBUFFER, *errorCode); @@ -864,7 +864,7 @@ int sceFontClose(u32 fontHandle) { LoadedFont *font = GetLoadedFont(fontHandle, false); if (font) { - INFO_LOG(SCEFONT, "sceFontClose(%x)", fontHandle); + DEBUG_LOG(SCEFONT, "sceFontClose(%x)", fontHandle); FontLib *fontLib = font->GetFontLib(); if (fontLib) fontLib->CloseFont(font); @@ -895,7 +895,7 @@ int sceFontFindOptimumFont(u32 libHandle, u32 fontStylePtr, u32 errorCodePtr) { return 0; } - INFO_LOG(SCEFONT, "sceFontFindOptimumFont(%08x, %08x, %08x)", libHandle, fontStylePtr, errorCodePtr); + DEBUG_LOG(SCEFONT, "sceFontFindOptimumFont(%08x, %08x, %08x)", libHandle, fontStylePtr, errorCodePtr); auto requestedStyle = PSPPointer::Create(fontStylePtr); @@ -962,7 +962,7 @@ int sceFontFindFont(u32 libHandle, u32 fontStylePtr, u32 errorCodePtr) { return 0; } - INFO_LOG(SCEFONT, "sceFontFindFont(%x, %x, %x)", libHandle, fontStylePtr, errorCodePtr); + DEBUG_LOG(SCEFONT, "sceFontFindFont(%x, %x, %x)", libHandle, fontStylePtr, errorCodePtr); auto requestedStyle = PSPPointer::Create(fontStylePtr); From ec4ce7e7e56000527d9fe2561d30acbc0f62d1a3 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 15 Mar 2014 18:50:14 -0700 Subject: [PATCH 3/4] Return proper SIZES info for existing savedata. Fixes Fieldrunners saving/loading. --- Core/Dialog/SavedataParam.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/Core/Dialog/SavedataParam.cpp b/Core/Dialog/SavedataParam.cpp index 0208c2faa8..95132cc9d6 100644 --- a/Core/Dialog/SavedataParam.cpp +++ b/Core/Dialog/SavedataParam.cpp @@ -871,16 +871,27 @@ int SavedataParam::GetSizes(SceUtilitySavedataParam *param) { const std::string gameName(param->msData->gameName, strnlen(param->msData->gameName, sizeof(param->msData->gameName))); const std::string saveName(param->msData->saveName, strnlen(param->msData->saveName, sizeof(param->msData->saveName))); - std::string path = GetSaveFilePath(param, gameName + saveName); + // TODO: How should <> be handled? + std::string path = GetSaveFilePath(param, gameName + (saveName == "<>" ? "" : saveName)); PSPFileInfo finfo = pspFileSystem.GetFileInfo(path); - if(finfo.exists) + if (finfo.exists) { - // TODO : fill correctly with the total save size, be aware of crypted file size - param->msData->info.usedClusters = 1; - param->msData->info.usedSpaceKB = 0x20; - strncpy(param->msData->info.usedSpaceStr, "", sizeof(param->msData->info.usedSpaceStr)); // "32 KB" // 8 u8 - param->msData->info.usedSpace32KB = 0x20; - strncpy(param->msData->info.usedSpace32Str, "", sizeof(param->msData->info.usedSpace32Str)); // "32 KB" // 8 u8 + param->msData->info.usedClusters = 0; + auto listing = pspFileSystem.GetDirListing(path); + for (auto it = listing.begin(), end = listing.end(); it != end; ++it) { + param->msData->info.usedClusters += (it->size + (u32)MemoryStick_SectorSize() - 1) / (u32)MemoryStick_SectorSize(); + } + + // The usedSpaceKB value is definitely based on clusters, not bytes or even KB. + // Fieldrunners expects 736 KB, even though the files add up to ~600 KB. + int total_size = param->msData->info.usedClusters * (u32)MemoryStick_SectorSize(); + param->msData->info.usedSpaceKB = total_size / 0x400; + std::string spaceTxt = SavedataParam::GetSpaceText(total_size); + strncpy(param->msData->info.usedSpaceStr, spaceTxt.c_str(), sizeof(param->msData->info.usedSpaceStr)); + + // TODO: What does this mean, then? Seems to be the same. + param->msData->info.usedSpace32KB = param->msData->info.usedSpaceKB; + strncpy(param->msData->info.usedSpace32Str, spaceTxt.c_str(), sizeof(param->msData->info.usedSpace32Str)); } else { From 241d5cb5a5110235c7a4e55880445b4f5cdbb00d Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 15 Mar 2014 18:50:44 -0700 Subject: [PATCH 4/4] Always count one cluster for usedata in SIZES. This matches values coming out of hardware... seems to make sense. --- Core/Dialog/SavedataParam.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/Dialog/SavedataParam.cpp b/Core/Dialog/SavedataParam.cpp index 95132cc9d6..66cdf1d499 100644 --- a/Core/Dialog/SavedataParam.cpp +++ b/Core/Dialog/SavedataParam.cpp @@ -907,7 +907,7 @@ int SavedataParam::GetSizes(SceUtilitySavedataParam *param) { int total_size = 0; total_size += getSizeNormalized(1); // SFO; - total_size += getSizeNormalized(param->dataSize); // Save Data + total_size += getSizeNormalized((u32)param->dataSize == 0 ? 1 : (u32)param->dataSize); // Save Data total_size += getSizeNormalized(param->icon0FileData.size); total_size += getSizeNormalized(param->icon1FileData.size); total_size += getSizeNormalized(param->pic1FileData.size);