Skip to content

Commit

Permalink
Io: Track initial free space for compat flag.
Browse files Browse the repository at this point in the history
This seems to be necessary for Assassin's Creed.  See hrydgard#12761.
  • Loading branch information
unknownbrackets committed Oct 20, 2020
1 parent e3a201f commit c95e695
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions Core/Compatibility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ void Compatibility::CheckSettings(IniFile &iniFile, const std::string &gameID) {
CheckSetting(iniFile, gameID, "ForceSoftwareRenderer", &flags_.ForceSoftwareRenderer);
CheckSetting(iniFile, gameID, "DarkStalkersPresentHack", &flags_.DarkStalkersPresentHack);
CheckSetting(iniFile, gameID, "ReportSmallMemstick", &flags_.ReportSmallMemstick);
CheckSetting(iniFile, gameID, "MemstickFixedFree", &flags_.MemstickFixedFree);
CheckSetting(iniFile, gameID, "DateLimited", &flags_.DateLimited);
}

Expand Down
1 change: 1 addition & 0 deletions Core/Compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ struct CompatFlags {
bool ForceSoftwareRenderer;
bool DarkStalkersPresentHack;
bool ReportSmallMemstick;
bool MemstickFixedFree;
bool DateLimited;
};

Expand Down
3 changes: 1 addition & 2 deletions Core/HLE/sceIo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,6 @@ static void __IoVblank() {
}

void __IoInit() {
MemoryStick_Init();

asyncNotifyEvent = CoreTiming::RegisterEvent("IoAsyncNotify", __IoAsyncNotify);
syncNotifyEvent = CoreTiming::RegisterEvent("IoSyncNotify", __IoSyncNotify);

Expand Down Expand Up @@ -663,6 +661,7 @@ void __IoInit() {

__KernelRegisterWaitTypeFuncs(WAITTYPE_ASYNCIO, __IoAsyncBeginCallback, __IoAsyncEndCallback);

MemoryStick_Init();
lastMemStickState = MemoryStick_State();
lastMemStickFatState = MemoryStick_FatState();
__DisplayListenVblank(__IoVblank);
Expand Down
17 changes: 15 additions & 2 deletions Core/HW/MemoryStick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ static MemStickState memStickState;
static MemStickFatState memStickFatState;
static bool memStickNeedsAssign = false;
static u64 memStickInsertedAt = 0;
static uint64_t memstickInitialFree = 0;

const u64 normalMemstickSize = 9ULL * 1024 * 1024 * 1024;
const u64 smallMemstickSize = 1ULL * 1024 * 1024 * 1024;

void MemoryStick_DoState(PointerWrap &p) {
auto s = p.Section("MemoryStick", 1, 4);
auto s = p.Section("MemoryStick", 1, 5);
if (!s)
return;

Expand All @@ -47,6 +48,9 @@ void MemoryStick_DoState(PointerWrap &p) {
u64 memStickSize = normalMemstickSize;
Do(p, memStickSize);
}
if (s >= 5) {
Do(p, memstickInitialFree);
}

if (s >= 3) {
Do(p, memStickNeedsAssign);
Expand All @@ -72,18 +76,26 @@ u64 MemoryStick_SectorSize() {
}

u64 MemoryStick_FreeSpace() {
const CompatFlags &flags = PSP_CoreParameter().compat.flags();
u64 realFreeSpace = pspFileSystem.FreeSpace("ms0:/");

// Cap the memory stick size to avoid math errors when old games get sizes that were
// not planned for back then (even though 2GB cards were available.)
// We have a compat setting to make it even smaller for Harry Potter : Goblet of Fire, see #13266.
const u64 memStickSize = PSP_CoreParameter().compat.flags().ReportSmallMemstick ? smallMemstickSize : (u64)g_Config.iMemStickSizeGB * 1024 * 1024 * 1024;
const u64 memStickSize = flags.ReportSmallMemstick ? smallMemstickSize : (u64)g_Config.iMemStickSizeGB * 1024 * 1024 * 1024;
// Assume the memory stick is only used to store savedata.
u64 usedSpace = pspFileSystem.getDirSize("ms0:/PSP/SAVEDATA/");
u64 simulatedFreeSpace = 0;
if (usedSpace < memStickSize) {
simulatedFreeSpace = memStickSize - usedSpace;
}
if (flags.MemstickFixedFree) {
// Assassin's Creed: Bloodlines fails to save if free space changes incorrectly during game.
realFreeSpace = 0;
if (usedSpace <= memstickInitialFree) {
realFreeSpace = memstickInitialFree - usedSpace;
}
}

return std::min(simulatedFreeSpace, realFreeSpace);
}
Expand Down Expand Up @@ -119,4 +131,5 @@ void MemoryStick_Init() {
}

memStickNeedsAssign = false;
memstickInitialFree = pspFileSystem.FreeSpace("ms0:/") + pspFileSystem.getDirSize("ms0:/PSP/SAVEDATA/");
}
6 changes: 6 additions & 0 deletions assets/compat.ini
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,12 @@ ULJM05225 = true
CPCS01043 = true
ULUS10062 = true

[MemstickFixedFree]
ULJM05571 = true
ULES01367 = true
NPEH00029 = true
ULUS10455 = true

[DateLimited]
# Car Jack Streets - issue #12698
NPUZ00043 = true
Expand Down

0 comments on commit c95e695

Please sign in to comment.