From 4625a2d43ab5989b2211ccd7f2f6999f22af6374 Mon Sep 17 00:00:00 2001 From: RedPanda4552 Date: Fri, 27 Dec 2024 22:45:27 -0500 Subject: [PATCH 1/2] Memcard: Remove support for legacy PSX card types with headers Supporting legacy PSX cards with headers required constant size checks, thrashing IOP performance. --- pcsx2/SIO/Memcard/MemoryCardFile.cpp | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/pcsx2/SIO/Memcard/MemoryCardFile.cpp b/pcsx2/SIO/Memcard/MemoryCardFile.cpp index e48a0eacb7ae2..3e24140825681 100644 --- a/pcsx2/SIO/Memcard/MemoryCardFile.cpp +++ b/pcsx2/SIO/Memcard/MemoryCardFile.cpp @@ -360,24 +360,7 @@ void FileMemoryCard::Close() // Returns FALSE if the seek failed (is outside the bounds of the file). bool FileMemoryCard::Seek(std::FILE* f, u32 adr) { - const s64 size = FileSystem::FSize64(f); - - // If anyone knows why this filesize logic is here (it appears to be related to legacy PSX - // cards, perhaps hacked support for some special emulator-specific memcard formats that - // had header info?), then please replace this comment with something useful. Thanks! -- air - - u32 offset = 0; - - if (size == MCD_SIZE + 64) - offset = 64; - else if (size == MCD_SIZE + 3904) - offset = 3904; - else - { - // perform sanity checks here? - } - - return (FileSystem::FSeek64(f, adr + offset, SEEK_SET) == 0); + return (FileSystem::FSeek64(f, adr, SEEK_SET) == 0); } // returns FALSE if an error occurred (either permission denied or disk full) From 3e3f8f0fe604a7d98fa148c078ce2e9e109332e0 Mon Sep 17 00:00:00 2001 From: RedPanda4552 Date: Sat, 28 Dec 2024 12:23:09 -0500 Subject: [PATCH 2/2] Memcard: Track file size globally at open Prevents FSeek64 hits on every retrieval of memcard attributes --- pcsx2/SIO/Memcard/MemoryCardFile.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/pcsx2/SIO/Memcard/MemoryCardFile.cpp b/pcsx2/SIO/Memcard/MemoryCardFile.cpp index 3e24140825681..1a31a2839dfd5 100644 --- a/pcsx2/SIO/Memcard/MemoryCardFile.cpp +++ b/pcsx2/SIO/Memcard/MemoryCardFile.cpp @@ -157,6 +157,7 @@ class FileMemoryCard { protected: std::FILE* m_file[8] = {}; + s64 m_fileSize[8] = {}; std::string m_filenames[8] = {}; std::vector m_currentdata; u64 m_chksum[8] = {}; @@ -246,7 +247,13 @@ std::string FileMcd_GetDefaultName(uint slot) return StringUtil::StdStringFromFormat("Mcd%03u.ps2", slot + 1); } -FileMemoryCard::FileMemoryCard() = default; +FileMemoryCard::FileMemoryCard() +{ + for (u8 slot = 0; slot < 8; slot++) + { + m_fileSize[slot] = -1; + } +} FileMemoryCard::~FileMemoryCard() = default; @@ -314,12 +321,14 @@ void FileMemoryCard::Open() } else // Load checksum { + m_fileSize[slot] = FileSystem::FSize64(m_file[slot]); + Console.WriteLnFmt(Color_Green, "McdSlot {} [File]: {} [{} MB, {}]", slot, Path::GetFileName(fname), - (FileSystem::FSize64(m_file[slot]) + (MCD_SIZE + 1)) / MC2_MBSIZE, + (m_fileSize[slot] + (MCD_SIZE + 1)) / MC2_MBSIZE, FileMcd_IsMemoryCardFormatted(m_file[slot]) ? "Formatted" : "UNFORMATTED"); m_filenames[slot] = std::move(fname); - m_ispsx[slot] = FileSystem::FSize64(m_file[slot]) == 0x20000; + m_ispsx[slot] = m_fileSize[slot] == 0x20000; m_chkaddr = 0x210; if (!m_ispsx[slot] && FileSystem::FSeek64(m_file[slot], m_chkaddr, SEEK_SET) == 0) @@ -354,6 +363,7 @@ void FileMemoryCard::Close() } m_filenames[slot] = {}; + m_fileSize[slot] = -1; } } @@ -398,7 +408,7 @@ void FileMemoryCard::GetSizeInfo(uint slot, McdSizeInfo& outways) pxAssert(m_file[slot]); if (m_file[slot]) - outways.McdSizeInSectors = static_cast(FileSystem::FSize64(m_file[slot])) / (outways.SectorSize + outways.EraseBlockSizeInSectors); + outways.McdSizeInSectors = static_cast(m_fileSize[slot]) / (outways.SectorSize + outways.EraseBlockSizeInSectors); else outways.McdSizeInSectors = 0x4000; @@ -525,7 +535,7 @@ u64 FileMemoryCard::GetCRC(uint slot) if (!Seek(mcfp, 0)) return 0; - const s64 mcfpsize = FileSystem::FSize64(mcfp); + const s64 mcfpsize = m_fileSize[slot]; if (mcfpsize < 0) return 0;