2016-12-19 19:20:30 +00:00
|
|
|
#ifndef __URDE_CMEMORYCARDDRIVER_HPP__
|
|
|
|
#define __URDE_CMEMORYCARDDRIVER_HPP__
|
|
|
|
|
|
|
|
#include "CMemoryCardSys.hpp"
|
2016-12-20 21:51:50 +00:00
|
|
|
#include "CGameState.hpp"
|
2016-12-19 19:20:30 +00:00
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
namespace MP1
|
|
|
|
{
|
|
|
|
|
|
|
|
class CMemoryCardDriver
|
|
|
|
{
|
|
|
|
friend class CSaveUI;
|
|
|
|
public:
|
|
|
|
enum class EState
|
|
|
|
{
|
2016-12-24 05:23:50 +00:00
|
|
|
Initial = 0,
|
2016-12-23 06:41:39 +00:00
|
|
|
Ready = 1,
|
|
|
|
NoCard = 2,
|
2016-12-24 05:23:50 +00:00
|
|
|
DriverClosed = 3,
|
2016-12-23 06:41:39 +00:00
|
|
|
CardFormatted = 4,
|
2016-12-24 05:23:50 +00:00
|
|
|
CardProbeDone = 5,
|
2016-12-23 06:41:39 +00:00
|
|
|
CardMountDone = 6,
|
2016-12-24 05:23:50 +00:00
|
|
|
CardCheckDone = 7,
|
|
|
|
FileCreateDone = 8,
|
|
|
|
FileCreateTransactionalDone = 9,
|
|
|
|
FileWriteTransactionalDone = 10,
|
|
|
|
FileDeleteAltTransactionalDone = 11,
|
|
|
|
CardProbeFailed = 12,
|
|
|
|
CardMountFailed = 13,
|
|
|
|
CardCheckFailed = 14,
|
|
|
|
FileDeleteBadFailed = 15,
|
|
|
|
FileDeleteAltFailed = 16,
|
|
|
|
FileBad = 17,
|
|
|
|
FileCreateFailed = 18,
|
|
|
|
FileWriteFailed = 19,
|
|
|
|
FileCreateTransactionalFailed = 20,
|
|
|
|
FileWriteTransactionalFailed = 21,
|
|
|
|
FileDeleteAltTransactionalFailed = 22,
|
|
|
|
FileRenameBtoAFailed = 23,
|
|
|
|
CardFormatFailed = 24,
|
|
|
|
CardProbe = 25,
|
2016-12-23 06:41:39 +00:00
|
|
|
CardMount = 26,
|
2016-12-24 05:23:50 +00:00
|
|
|
CardCheck = 27,
|
|
|
|
FileDeleteBad = 28,
|
|
|
|
FileRead = 29,
|
|
|
|
FileDeleteAlt = 30,
|
|
|
|
FileCreate = 31,
|
|
|
|
FileWrite = 32,
|
|
|
|
FileCreateTransactional = 33,
|
|
|
|
FileWriteTransactional = 34,
|
|
|
|
FileDeleteAltTransactional = 35,
|
|
|
|
FileRenameBtoA = 36,
|
2016-12-23 06:41:39 +00:00
|
|
|
CardFormat = 37
|
2016-12-19 19:20:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum class EError
|
|
|
|
{
|
2016-12-24 05:23:50 +00:00
|
|
|
OK,
|
|
|
|
CardBroken,
|
|
|
|
CardWrongCharacterSet,
|
|
|
|
CardIOError,
|
|
|
|
CardWrongDevice,
|
|
|
|
CardFull,
|
|
|
|
CardStillFull, /* After attempting alt-delete (if needed) */
|
|
|
|
CardNon8KSectors,
|
|
|
|
FileMissing,
|
|
|
|
FileCorrupted
|
2016-12-19 19:20:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2016-12-20 21:51:50 +00:00
|
|
|
struct CARDFileInfo
|
2016-12-19 19:20:30 +00:00
|
|
|
{
|
|
|
|
CMemoryCardSys::EMemoryCardPort x0_cardPort;
|
2016-12-20 21:51:50 +00:00
|
|
|
int x4_fileNo = -1;
|
|
|
|
int x8_offset;
|
|
|
|
int xc_length;
|
|
|
|
u16 iBlock;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SFileInfo
|
|
|
|
{
|
|
|
|
CARDFileInfo x0_fileInfo;
|
2016-12-19 19:20:30 +00:00
|
|
|
std::string x14_name;
|
2016-12-20 21:51:50 +00:00
|
|
|
std::vector<u8> x24_saveFileData;
|
|
|
|
std::vector<u8> x34_saveData;
|
|
|
|
SFileInfo(CMemoryCardSys::EMemoryCardPort cardPort, const std::string& name);
|
2016-12-23 06:41:39 +00:00
|
|
|
CMemoryCardSys::ECardResult Open();
|
2016-12-20 21:51:50 +00:00
|
|
|
CMemoryCardSys::ECardResult Close();
|
|
|
|
CMemoryCardSys::EMemoryCardPort GetFileCardPort() const { return x0_fileInfo.x0_cardPort; }
|
|
|
|
int GetFileNo() const { return x0_fileInfo.x4_fileNo; }
|
2016-12-23 06:41:39 +00:00
|
|
|
CMemoryCardSys::ECardResult StartRead();
|
2016-12-20 21:51:50 +00:00
|
|
|
CMemoryCardSys::ECardResult TryFileRead();
|
|
|
|
CMemoryCardSys::ECardResult FileRead();
|
|
|
|
CMemoryCardSys::ECardResult GetSaveDataOffset(u32& offOut);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SSaveHeader
|
|
|
|
{
|
2016-12-24 00:45:51 +00:00
|
|
|
u32 x0_version = 0;
|
|
|
|
bool x4_savePresent[3];
|
|
|
|
void DoPut(CMemoryOutStream& out) const
|
|
|
|
{
|
|
|
|
out.writeUint32Big(x0_version);
|
|
|
|
for (int i=0 ; i<3 ; ++i)
|
|
|
|
out.writeBool(x4_savePresent[i]);
|
|
|
|
}
|
2016-12-20 21:51:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct SGameFileSlot
|
|
|
|
{
|
|
|
|
u8 x0_saveBuffer[940] = {};
|
|
|
|
CGameState::GameFileStateInfo x944_fileInfo;
|
|
|
|
SGameFileSlot();
|
2016-12-20 22:09:02 +00:00
|
|
|
SGameFileSlot(CMemoryInStream& in);
|
2016-12-20 21:51:50 +00:00
|
|
|
void InitializeFromGameState();
|
2016-12-24 00:45:51 +00:00
|
|
|
void DoPut(CMemoryOutStream& w) const
|
|
|
|
{
|
|
|
|
w.writeBytes(x0_saveBuffer, 940);
|
|
|
|
}
|
2016-12-19 19:20:30 +00:00
|
|
|
};
|
|
|
|
|
2016-12-24 05:23:50 +00:00
|
|
|
enum class EFileState
|
|
|
|
{
|
|
|
|
Unknown,
|
|
|
|
NoFile,
|
|
|
|
File,
|
|
|
|
BadFile
|
|
|
|
};
|
|
|
|
|
2016-12-19 19:20:30 +00:00
|
|
|
CMemoryCardSys::EMemoryCardPort x0_cardPort;
|
|
|
|
ResId x4_saveBanner;
|
|
|
|
ResId x8_saveIcon0;
|
|
|
|
ResId xc_saveIcon1;
|
2016-12-23 06:41:39 +00:00
|
|
|
EState x10_state = EState::Initial;
|
2016-12-24 05:23:50 +00:00
|
|
|
EError x14_error = EError::OK;
|
2016-12-19 19:20:30 +00:00
|
|
|
s32 x18_cardFreeBytes = 0;
|
|
|
|
s32 x1c_cardFreeFiles = 0;
|
2016-12-20 21:51:50 +00:00
|
|
|
u32 x20_fileTime = 0;
|
2016-12-19 19:20:30 +00:00
|
|
|
u64 x28_cardSerial = 0;
|
2016-12-20 21:51:50 +00:00
|
|
|
u8 x30_systemData[174] = {};
|
|
|
|
std::unique_ptr<SGameFileSlot> xe4_fileSlots[3];
|
2016-12-24 05:23:50 +00:00
|
|
|
std::vector<std::pair<EFileState, SFileInfo>> x100_mcFileInfos;
|
2016-12-20 21:51:50 +00:00
|
|
|
u32 x194_fileIdx = -1;
|
2016-12-23 06:41:39 +00:00
|
|
|
std::unique_ptr<CMemoryCardSys::CCardFileInfo> x198_fileInfo;
|
2016-12-19 19:20:30 +00:00
|
|
|
bool x19c_ = false;
|
2016-12-23 06:41:39 +00:00
|
|
|
bool x19d_doImportPersistent;
|
2016-12-19 19:20:30 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
CMemoryCardDriver(CMemoryCardSys::EMemoryCardPort cardPort, ResId saveBanner,
|
2016-12-23 06:41:39 +00:00
|
|
|
ResId saveIcon0, ResId saveIcon1, bool importPersistent);
|
2016-12-20 21:51:50 +00:00
|
|
|
|
2016-12-24 05:23:50 +00:00
|
|
|
void NoCardFound();
|
2016-12-20 21:51:50 +00:00
|
|
|
CGameState::GameFileStateInfo* GetGameFileStateInfo(int idx);
|
|
|
|
static SSaveHeader LoadSaveHeader(CMemoryInStream& in);
|
|
|
|
static std::unique_ptr<SGameFileSlot> LoadSaveFile(CMemoryInStream& in);
|
|
|
|
void ReadFinished();
|
2016-12-23 06:41:39 +00:00
|
|
|
void ImportPersistentOptions();
|
|
|
|
void ExportPersistentOptions();
|
2016-12-20 21:51:50 +00:00
|
|
|
void CheckCardCapacity();
|
2016-12-24 05:23:50 +00:00
|
|
|
void IndexFiles();
|
|
|
|
|
|
|
|
void StartCardProbe(); // 25
|
|
|
|
void StartMountCard(); // 26
|
|
|
|
void StartCardCheck(); // 27
|
|
|
|
void StartFileDeleteBad(); // 28
|
|
|
|
void StartFileRead(); // 29
|
|
|
|
void StartFileDeleteAlt(); // 30
|
|
|
|
void StartFileCreate(); // 31
|
|
|
|
void StartFileWrite(); // 32
|
|
|
|
void StartFileCreateTransactional(); // 33
|
|
|
|
void StartFileWriteTransactional(); // 34
|
|
|
|
void StartFileDeleteAltTransactional(); // 35
|
|
|
|
void StartFileRenameBtoA(); // 36
|
|
|
|
void StartCardFormat(); // 37
|
|
|
|
|
|
|
|
void UpdateCardProbe(); // 25
|
|
|
|
void UpdateMountCard(CMemoryCardSys::ECardResult result); // 26
|
|
|
|
void UpdateCardCheck(CMemoryCardSys::ECardResult result); // 27
|
|
|
|
void UpdateFileDeleteBad(CMemoryCardSys::ECardResult result); // 28
|
|
|
|
void UpdateFileRead(CMemoryCardSys::ECardResult result); // 29
|
|
|
|
void UpdateFileDeleteAlt(CMemoryCardSys::ECardResult result); // 30
|
|
|
|
void UpdateFileCreate(CMemoryCardSys::ECardResult result); // 31
|
|
|
|
void UpdateFileWrite(CMemoryCardSys::ECardResult result); // 32
|
|
|
|
void UpdateFileCreateTransactional(CMemoryCardSys::ECardResult result); // 33
|
|
|
|
void UpdateFileWriteTransactional(CMemoryCardSys::ECardResult result); // 34
|
|
|
|
void UpdateFileDeleteAltTransactional(CMemoryCardSys::ECardResult result); // 35
|
|
|
|
void UpdateFileRenameBtoA(CMemoryCardSys::ECardResult result); // 36
|
|
|
|
void UpdateCardFormat(CMemoryCardSys::ECardResult result); // 37
|
2016-12-23 06:41:39 +00:00
|
|
|
|
|
|
|
void ClearFileInfo() { x198_fileInfo.reset(); }
|
|
|
|
void InitializeFileInfo();
|
|
|
|
void WriteBackupBuf();
|
2016-12-19 19:20:30 +00:00
|
|
|
bool GetCardFreeBytes();
|
|
|
|
void HandleCardError(CMemoryCardSys::ECardResult result, EState state);
|
|
|
|
void Update();
|
2016-12-20 21:51:50 +00:00
|
|
|
|
2016-12-24 05:23:50 +00:00
|
|
|
static bool IsCardBusy(EState v)
|
2016-12-20 21:51:50 +00:00
|
|
|
{
|
2016-12-23 06:41:39 +00:00
|
|
|
return v >= EState::CardMount && v <= EState::CardFormat;
|
2016-12-20 21:51:50 +00:00
|
|
|
}
|
|
|
|
|
2016-12-24 05:23:50 +00:00
|
|
|
static bool IsOperationDestructive(EState v)
|
2016-12-20 21:51:50 +00:00
|
|
|
{
|
2016-12-24 05:23:50 +00:00
|
|
|
if (v < EState::CardProbe)
|
2016-12-20 21:51:50 +00:00
|
|
|
return false;
|
2016-12-24 05:23:50 +00:00
|
|
|
if (v == EState::CardCheck)
|
2016-12-20 21:51:50 +00:00
|
|
|
return false;
|
2016-12-24 05:23:50 +00:00
|
|
|
if (v == EState::FileRead)
|
2016-12-20 21:51:50 +00:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
2016-12-19 19:20:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // __URDE_CMEMORYCARDDRIVER_HPP__
|