diff --git a/pcsx2/Sio.h b/pcsx2/Sio.h index 3f0d823788..8d03c6e737 100644 --- a/pcsx2/Sio.h +++ b/pcsx2/Sio.h @@ -34,17 +34,9 @@ struct _mcd u32 ForceEjection_Timeout; // in SIO checks wxDateTime ForceEjection_Timestamp; - struct McdSizeInfo - { - u16 SectorSize; // Size of each sector, in bytes. (only 512 and 1024 are valid) - u16 EraseBlockSizeInSectors; // Size of the erase block, in sectors (max is 16) - u32 McdSizeInSectors; // Total size of the card, in sectors (no upper limit) - u8 Xor; // Checksum of previous data - }; - void GetSizeInfo(McdSizeInfo &info) { - FileMcd_GetSizeInfo(port, slot, info); + FileMcd_GetSizeInfo(port, slot, &info); } bool IsPSX() @@ -91,7 +83,7 @@ struct _mcd } bool ReIndex(const wxString& filter = L"") { - return FileMcd_McdReIndex( port, slot, filter ); + return FileMcd_ReIndex(port, slot, filter); } }; diff --git a/pcsx2/gui/MemoryCardFile.cpp b/pcsx2/gui/MemoryCardFile.cpp index 7a0499ad57..de198b82be 100644 --- a/pcsx2/gui/MemoryCardFile.cpp +++ b/pcsx2/gui/MemoryCardFile.cpp @@ -26,7 +26,6 @@ // it, because some need to be able to alter its behavior using defines. Like this: struct Component_FileMcd; -#define PS2E_THISPTR Component_FileMcd* #include "MemoryCardFile.h" #include "MemoryCardFolder.h" @@ -179,7 +178,7 @@ public: void Close(); s32 IsPresent(uint slot); - void GetSizeInfo(uint slot, PS2E_McdSizeInfo& outways); + void GetSizeInfo(uint slot, McdSizeInfo& outways); bool IsPSX(uint slot); s32 Read(uint slot, u8* dest, u32 adr, int size); s32 Save(uint slot, const u8* src, u32 adr, int size); @@ -432,7 +431,7 @@ s32 FileMemoryCard::IsPresent(uint slot) return m_file[slot].IsOpened(); } -void FileMemoryCard::GetSizeInfo(uint slot, PS2E_McdSizeInfo& outways) +void FileMemoryCard::GetSizeInfo(uint slot, McdSizeInfo& outways) { outways.SectorSize = 512; // 0x0200 outways.EraseBlockSizeInSectors = 16; // 0x0010 @@ -587,11 +586,8 @@ u64 FileMemoryCard::GetCRC(uint slot) struct Component_FileMcd { - PS2E_ComponentAPI_Mcd api; // callbacks the plugin provides back to the emulator - FileMemoryCard impl; // class-based implementations we refer to when API is invoked + FileMemoryCard impl; // class-based implementations we refer to when API is invoked FolderMemoryCardAggregator implFolder; - - Component_FileMcd(); }; uint FileMcd_ConvertToSlot(uint port, uint slot) @@ -603,7 +599,7 @@ uint FileMcd_ConvertToSlot(uint port, uint slot) return slot + 4; // multitap 2 } -static void PS2E_CALLBACK FileMcd_EmuOpen(PS2E_THISPTR thisptr, const PS2E_SessionInfo* session) +static void FileMcd_EmuOpen() { // detect inserted memory card types for (uint slot = 0; slot < 8; ++slot) @@ -626,237 +622,152 @@ static void PS2E_CALLBACK FileMcd_EmuOpen(PS2E_THISPTR thisptr, const PS2E_Sessi } } - thisptr->impl.Open(); - thisptr->implFolder.SetFiltering(g_Conf->EmuOptions.McdFolderAutoManage); - thisptr->implFolder.Open(); + Component_FileMcd->impl.Open(); + Component_FileMcd->implFolder.SetFiltering(g_Conf->EmuOptions.McdFolderAutoManage); + Component_FileMcd->implFolder.Open(); } -static void PS2E_CALLBACK FileMcd_EmuClose(PS2E_THISPTR thisptr) +static void FileMcd_EmuClose() { - thisptr->implFolder.Close(); - thisptr->impl.Close(); + Component_FileMcd->implFolder.Close(); + Component_FileMcd->impl.Close(); } -static s32 PS2E_CALLBACK FileMcd_IsPresent(PS2E_THISPTR thisptr, uint port, uint slot) +static s32 FileMcd_IsPresent(uint port, uint slot) { const uint combinedSlot = FileMcd_ConvertToSlot(port, slot); switch (g_Conf->Mcd[combinedSlot].Type) { case MemoryCardType::MemoryCard_File: - return thisptr->impl.IsPresent(combinedSlot); + return Component_FileMcd->impl.IsPresent(combinedSlot); case MemoryCardType::MemoryCard_Folder: - return thisptr->implFolder.IsPresent(combinedSlot); + return Component_FileMcd->implFolder.IsPresent(combinedSlot); default: return false; } } -static void PS2E_CALLBACK FileMcd_GetSizeInfo(PS2E_THISPTR thisptr, uint port, uint slot, PS2E_McdSizeInfo* outways) +static void FileMcd_GetSizeInfo(uint port, uint slot, McdSizeInfo* outways) { const uint combinedSlot = FileMcd_ConvertToSlot(port, slot); switch (g_Conf->Mcd[combinedSlot].Type) { case MemoryCardType::MemoryCard_File: - thisptr->impl.GetSizeInfo(combinedSlot, *outways); + Component_FileMcd->impl.GetSizeInfo(combinedSlot, *outways); break; case MemoryCardType::MemoryCard_Folder: - thisptr->implFolder.GetSizeInfo(combinedSlot, *outways); + Component_FileMcd->implFolder.GetSizeInfo(combinedSlot, *outways); break; default: return; } } -static bool PS2E_CALLBACK FileMcd_IsPSX(PS2E_THISPTR thisptr, uint port, uint slot) +static bool FileMcd_IsPSX(uint port, uint slot) { const uint combinedSlot = FileMcd_ConvertToSlot(port, slot); switch (g_Conf->Mcd[combinedSlot].Type) { case MemoryCardType::MemoryCard_File: - return thisptr->impl.IsPSX(combinedSlot); + return Component_FileMcd->impl.IsPSX(combinedSlot); case MemoryCardType::MemoryCard_Folder: - return thisptr->implFolder.IsPSX(combinedSlot); + return Component_FileMcd->implFolder.IsPSX(combinedSlot); default: return false; } } -static s32 PS2E_CALLBACK FileMcd_Read(PS2E_THISPTR thisptr, uint port, uint slot, u8* dest, u32 adr, int size) +static s32 FileMcd_Read(uint port, uint slot, u8* dest, u32 adr, int size) { const uint combinedSlot = FileMcd_ConvertToSlot(port, slot); switch (g_Conf->Mcd[combinedSlot].Type) { case MemoryCardType::MemoryCard_File: - return thisptr->impl.Read(combinedSlot, dest, adr, size); + return Component_FileMcd->impl.Read(combinedSlot, dest, adr, size); case MemoryCardType::MemoryCard_Folder: - return thisptr->implFolder.Read(combinedSlot, dest, adr, size); + return Component_FileMcd->implFolder.Read(combinedSlot, dest, adr, size); default: return 0; } } -static s32 PS2E_CALLBACK FileMcd_Save(PS2E_THISPTR thisptr, uint port, uint slot, const u8* src, u32 adr, int size) +static s32 FileMcd_Save(uint port, uint slot, const u8* src, u32 adr, int size) { const uint combinedSlot = FileMcd_ConvertToSlot(port, slot); switch (g_Conf->Mcd[combinedSlot].Type) { case MemoryCardType::MemoryCard_File: - return thisptr->impl.Save(combinedSlot, src, adr, size); + return Component_FileMcd->impl.Save(combinedSlot, src, adr, size); case MemoryCardType::MemoryCard_Folder: - return thisptr->implFolder.Save(combinedSlot, src, adr, size); + return Component_FileMcd->implFolder.Save(combinedSlot, src, adr, size); default: return 0; } } -static s32 PS2E_CALLBACK FileMcd_EraseBlock(PS2E_THISPTR thisptr, uint port, uint slot, u32 adr) +static s32 FileMcd_EraseBlock(uint port, uint slot, u32 adr) { const uint combinedSlot = FileMcd_ConvertToSlot(port, slot); switch (g_Conf->Mcd[combinedSlot].Type) { case MemoryCardType::MemoryCard_File: - return thisptr->impl.EraseBlock(combinedSlot, adr); + return Component_FileMcd->impl.EraseBlock(combinedSlot, adr); case MemoryCardType::MemoryCard_Folder: - return thisptr->implFolder.EraseBlock(combinedSlot, adr); + return Component_FileMcd->implFolder.EraseBlock(combinedSlot, adr); default: return 0; } } -static u64 PS2E_CALLBACK FileMcd_GetCRC(PS2E_THISPTR thisptr, uint port, uint slot) +static u64 FileMcd_GetCRC(uint port, uint slot) { const uint combinedSlot = FileMcd_ConvertToSlot(port, slot); switch (g_Conf->Mcd[combinedSlot].Type) { case MemoryCardType::MemoryCard_File: - return thisptr->impl.GetCRC(combinedSlot); + return Component_FileMcd->impl.GetCRC(combinedSlot); case MemoryCardType::MemoryCard_Folder: - return thisptr->implFolder.GetCRC(combinedSlot); + return Component_FileMcd->implFolder.GetCRC(combinedSlot); default: return 0; } } -static void PS2E_CALLBACK FileMcd_NextFrame(PS2E_THISPTR thisptr, uint port, uint slot) +static void FileMcd_NextFrame(uint port, uint slot) { const uint combinedSlot = FileMcd_ConvertToSlot(port, slot); switch (g_Conf->Mcd[combinedSlot].Type) { //case MemoryCardType::MemoryCard_File: - // thisptr->impl.NextFrame( combinedSlot ); + // Component_FileMcd->impl.NextFrame( combinedSlot ); // break; case MemoryCardType::MemoryCard_Folder: - thisptr->implFolder.NextFrame(combinedSlot); + Component_FileMcd->implFolder.NextFrame(combinedSlot); break; default: return; } } -static bool PS2E_CALLBACK FileMcd_ReIndex(PS2E_THISPTR thisptr, uint port, uint slot, const wxString& filter) +static bool FileMcd_ReIndex(uint port, uint slot, const wxString& filter) { const uint combinedSlot = FileMcd_ConvertToSlot(port, slot); switch (g_Conf->Mcd[combinedSlot].Type) { //case MemoryCardType::MemoryCard_File: - // return thisptr->impl.ReIndex( combinedSlot, filter ); + // return Component_FileMcd->impl.ReIndex( combinedSlot, filter ); // break; case MemoryCardType::MemoryCard_Folder: - return thisptr->implFolder.ReIndex(combinedSlot, g_Conf->EmuOptions.McdFolderAutoManage, filter); + return Component_FileMcd->implFolder.ReIndex(combinedSlot, g_Conf->EmuOptions.McdFolderAutoManage, filter); break; default: return false; } } -Component_FileMcd::Component_FileMcd() -{ - memzero(api); - - api.Base.EmuOpen = FileMcd_EmuOpen; - api.Base.EmuClose = FileMcd_EmuClose; - - api.McdIsPresent = FileMcd_IsPresent; - api.McdGetSizeInfo = FileMcd_GetSizeInfo; - api.McdIsPSX = FileMcd_IsPSX; - api.McdRead = FileMcd_Read; - api.McdSave = FileMcd_Save; - api.McdEraseBlock = FileMcd_EraseBlock; - api.McdGetCRC = FileMcd_GetCRC; - api.McdNextFrame = FileMcd_NextFrame; - api.McdReIndex = FileMcd_ReIndex; -} - - // -------------------------------------------------------------------------------------- // Library API Implementations // -------------------------------------------------------------------------------------- -static const char* PS2E_CALLBACK FileMcd_GetName() -{ - return "PlainJane Mcd"; -} - -static const PS2E_VersionInfo* PS2E_CALLBACK FileMcd_GetVersion(u32 component) -{ - static const PS2E_VersionInfo version = {0, 1, 0, SVN_REV}; - return &version; -} - -static s32 PS2E_CALLBACK FileMcd_Test(u32 component, const PS2E_EmulatorInfo* xinfo) -{ - if (component != PS2E_TYPE_Mcd) - return 0; - - // Check and make sure the user has a hard drive? - // Probably not necessary :p - return 1; -} - -static PS2E_THISPTR PS2E_CALLBACK FileMcd_NewComponentInstance(u32 component) -{ - if (component != PS2E_TYPE_Mcd) - return NULL; - - try - { - return new Component_FileMcd(); - } - catch (std::bad_alloc&) - { - Console.Error("Allocation failed on Component_FileMcd! (out of memory?)"); - } - return NULL; -} - -static void PS2E_CALLBACK FileMcd_DeleteComponentInstance(PS2E_THISPTR instance) -{ - delete instance; -} - -static void PS2E_CALLBACK FileMcd_SetSettingsFolder(const char* folder) -{ -} - -static void PS2E_CALLBACK FileMcd_SetLogFolder(const char* folder) -{ -} - -static const PS2E_LibraryAPI FileMcd_Library = - { - FileMcd_GetName, - FileMcd_GetVersion, - FileMcd_Test, - FileMcd_NewComponentInstance, - FileMcd_DeleteComponentInstance, - FileMcd_SetSettingsFolder, - FileMcd_SetLogFolder}; - -// If made into an external plugin, this function should be renamed to PS2E_InitAPI, so that -// PCSX2 can find the export in the expected location. -extern "C" const PS2E_LibraryAPI* FileMcd_InitAPI(const PS2E_EmulatorInfo* emuinfo) -{ - return &FileMcd_Library; -} //Tests if a string is a valid name for a new file within a specified directory. //returns true if: diff --git a/pcsx2/gui/MemoryCardFile.h b/pcsx2/gui/MemoryCardFile.h index 9f27c3f93d..343b5638f5 100644 --- a/pcsx2/gui/MemoryCardFile.h +++ b/pcsx2/gui/MemoryCardFile.h @@ -15,16 +15,31 @@ #pragma once -// NOTICE! This file is intended as a temporary placebo only, until such time that the -// memorycard system is properly extracted into a plugin system (which would make it a -// separate project file). -// -// Please do not move contents from MemoryCardfile.cpp, such as class definitions, into -// this file. I'd prefer they stay in MemoryCardFile.cpp for now. --air +struct McdSizeInfo +{ + u16 SectorSize; // Size of each sector, in bytes. (only 512 and 1024 are valid) + u16 EraseBlockSizeInSectors; // Size of the erase block, in sectors (max is 16) + u32 McdSizeInSectors; // Total size of the card, in sectors (no upper limit) + u8 Xor; // Checksum of previous data +}; extern uint FileMcd_GetMtapPort(uint slot); extern uint FileMcd_GetMtapSlot(uint slot); -extern bool FileMcd_IsMultitapSlot( uint slot ); +extern bool FileMcd_IsMultitapSlot(uint slot); //extern wxFileName FileMcd_GetSimpleName(uint slot); extern wxString FileMcd_GetDefaultName(uint slot); -extern bool isValidNewFilename( wxString filenameStringToTest, wxDirName atBasePath, wxString& out_errorMessage, uint minNumCharacters=5 ); +extern bool isValidNewFilename(wxString filenameStringToTest, wxDirName atBasePath, wxString& out_errorMessage, uint minNumCharacters = 5); + + +uint FileMcd_ConvertToSlot(uint port, uint slot); +void FileMcd_EmuOpen(); +void FileMcd_EmuClose(); +s32 FileMcd_IsPresent(uint port, uint slot); +void FileMcd_GetSizeInfo(uint port, uint slot, McdSizeInfo* outways); +bool FileMcd_IsPSX(uint port, uint slot); +s32 FileMcd_Read(uint port, uint slot, u8* dest, u32 adr, int size); +s32 FileMcd_Save(uint port, uint slot, const u8* src, u32 adr, int size); +s32 FileMcd_EraseBlock(uint port, uint slot, u32 adr); +u64 FileMcd_GetCRC(uint port, uint slot); +void FileMcd_NextFrame(uint port, uint slot); +bool FileMcd_ReIndex(uint port, uint slot, const wxString& filter);