Finishing touches to CMemoryCardDriver

This commit is contained in:
Jack Andersen 2016-12-23 19:23:50 -10:00
parent a7d2e62846
commit 5e2f2e3af8
7 changed files with 581 additions and 567 deletions

View File

@ -242,28 +242,28 @@ void CMemoryCardSys::CCardFileInfo::WriteIconData(CMemoryOutStream& out) const
CMemoryCardSys::ECardResult CMemoryCardSys::CCardFileInfo::PumpCardTransfer()
{
if (x0_status == EStatus::Standby)
return ECardResult::CARD_RESULT_READY;
return ECardResult::READY;
else if (x0_status == EStatus::Transferring)
{
ECardResult result = CMemoryCardSys::GetResultCode(GetCardPort());
if (result != ECardResult::CARD_RESULT_BUSY)
if (result != ECardResult::BUSY)
x104_cardBuffer.clear();
if (result != ECardResult::CARD_RESULT_READY)
if (result != ECardResult::READY)
return result;
x0_status = EStatus::Done;
CARDStat stat = {};
result = GetStatus(stat);
if (result != ECardResult::CARD_RESULT_READY)
if (result != ECardResult::READY)
return result;
result = CMemoryCardSys::SetStatus(GetCardPort(), GetFileNo(), stat);
if (result != ECardResult::CARD_RESULT_READY)
if (result != ECardResult::READY)
return result;
return ECardResult::CARD_RESULT_BUSY;
return ECardResult::BUSY;
}
else
{
ECardResult result = CMemoryCardSys::GetResultCode(GetCardPort());
if (result == ECardResult::CARD_RESULT_READY)
if (result == ECardResult::READY)
x0_status = EStatus::Standby;
return result;
}
@ -272,7 +272,7 @@ CMemoryCardSys::ECardResult CMemoryCardSys::CCardFileInfo::PumpCardTransfer()
CMemoryCardSys::ECardResult CMemoryCardSys::CCardFileInfo::GetStatus(CARDStat& stat) const
{
ECardResult result = CMemoryCardSys::GetStatus(GetCardPort(), GetFileNo(), stat);
if (result != ECardResult::CARD_RESULT_READY)
if (result != ECardResult::READY)
return result;
stat.SetCommentAddr(4);
@ -303,12 +303,12 @@ CMemoryCardSys::ECardResult CMemoryCardSys::CCardFileInfo::GetStatus(CARDStat& s
stat.SetIconSpeed(0, idx);
}
return ECardResult::CARD_RESULT_READY;
return ECardResult::READY;
}
CMemoryCardSys::ECardResult CMemoryCardSys::CCardFileInfo::CreateFile()
{
return ECardResult::CARD_RESULT_READY;
return ECardResult::READY;
}
CMemoryCardSys::ECardResult CMemoryCardSys::CCardFileInfo::Write()
@ -316,7 +316,7 @@ CMemoryCardSys::ECardResult CMemoryCardSys::CCardFileInfo::Write()
BuildCardBuffer();
//DCStoreRange(info.x104_cardBuffer.data(), info.x104_cardBuffer.size());
//CARDWriteAsync(&info.x4_info, info.x104_cardBuffer.data(), info.x104_cardBuffer.size(), 0, 0);
return ECardResult::CARD_RESULT_READY;
return ECardResult::READY;
}
CMemoryCardSys::ECardResult CMemoryCardSys::CCardFileInfo::Close()
@ -324,7 +324,7 @@ CMemoryCardSys::ECardResult CMemoryCardSys::CCardFileInfo::Close()
EMemoryCardPort port = GetCardPort();
//CARDClose(port);
x4_info.chan = port;
return ECardResult::CARD_RESULT_READY;
return ECardResult::READY;
}
CMemoryCardSys::CardProbeResults CMemoryCardSys::CardProbe(EMemoryCardPort port)
@ -334,57 +334,57 @@ CMemoryCardSys::CardProbeResults CMemoryCardSys::CardProbe(EMemoryCardPort port)
CMemoryCardSys::ECardResult CMemoryCardSys::MountCard(EMemoryCardPort port)
{
return ECardResult::CARD_RESULT_READY;
return ECardResult::READY;
}
CMemoryCardSys::ECardResult CMemoryCardSys::CheckCard(EMemoryCardPort port)
{
return ECardResult::CARD_RESULT_READY;
return ECardResult::READY;
}
CMemoryCardSys::ECardResult CMemoryCardSys::GetNumFreeBytes(EMemoryCardPort port, s32& freeBytes, s32& freeFiles)
{
return ECardResult::CARD_RESULT_READY;
return ECardResult::READY;
}
CMemoryCardSys::ECardResult CMemoryCardSys::GetSerialNo(EMemoryCardPort port, u64& serialOut)
{
return ECardResult::CARD_RESULT_READY;
return ECardResult::READY;
}
CMemoryCardSys::ECardResult CMemoryCardSys::GetResultCode(EMemoryCardPort port)
{
return ECardResult::CARD_RESULT_READY;
return ECardResult::READY;
}
CMemoryCardSys::ECardResult CMemoryCardSys::GetStatus(EMemoryCardPort port, int fileNo, CARDStat& statOut)
{
return ECardResult::CARD_RESULT_READY;
return ECardResult::READY;
}
CMemoryCardSys::ECardResult CMemoryCardSys::SetStatus(EMemoryCardPort port, int fileNo, const CARDStat& stat)
{
return ECardResult::CARD_RESULT_READY;
return ECardResult::READY;
}
CMemoryCardSys::ECardResult CMemoryCardSys::DeleteFile(EMemoryCardPort port, const char* name)
{
return ECardResult::CARD_RESULT_READY;
return ECardResult::READY;
}
CMemoryCardSys::ECardResult CMemoryCardSys::FastDeleteFile(EMemoryCardPort port, int fileNo)
{
return ECardResult::CARD_RESULT_READY;
return ECardResult::READY;
}
CMemoryCardSys::ECardResult CMemoryCardSys::Rename(EMemoryCardPort port, const char* oldName, const char* newName)
{
return ECardResult::CARD_RESULT_READY;
return ECardResult::READY;
}
CMemoryCardSys::ECardResult CMemoryCardSys::FormatCard(EMemoryCardPort port)
{
return ECardResult::CARD_RESULT_READY;
return ECardResult::READY;
}
}

View File

@ -8,6 +8,8 @@
#include "GuiSys/CStringTable.hpp"
#include <vector>
#undef NOFILE
// longest file name string excluding terminating zero
#define CARD_FILENAME_MAX 32
@ -76,16 +78,16 @@ public:
enum class ECardResult
{
CARD_RESULT_CRC_MISMATCH = -1003,
CARD_RESULT_FATAL_ERROR = -128,
CARD_RESULT_ENCODING = -13,
CARD_RESULT_BROKEN = -6,
CARD_RESULT_IOERROR = -5,
CARD_RESULT_NOFILE = -4,
CARD_RESULT_NOCARD = -3,
CARD_RESULT_WRONGDEVICE = -2,
CARD_RESULT_BUSY = -1,
CARD_RESULT_READY = 0
CRC_MISMATCH = -1003,
FATAL_ERROR = -128,
ENCODING = -13,
BROKEN = -6,
IOERROR = -5,
NOFILE = -4,
NOCARD = -3,
WRONGDEVICE = -2,
BUSY = -1,
READY = 0
};
struct CardProbeResults

File diff suppressed because it is too large Load Diff

View File

@ -15,58 +15,58 @@ class CMemoryCardDriver
public:
enum class EState
{
Initial,
Initial = 0,
Ready = 1,
NoCard = 2,
RuntimeBackup = 3,
DriverClosed = 3,
CardFormatted = 4,
CardNeedsMount = 5,
CardProbeDone = 5,
CardMountDone = 6,
SelectCardFile = 7,
WillWrite = 8,
Nine = 9,
Ten = 10,
Eleven = 11,
Twelve = 12,
Thirteen = 13,
Fourteen = 14,
Fifteen = 15,
Sixteen = 16,
Seventeen = 17,
Eighteen = 18,
Nineteen = 19,
Twenty = 20,
TwentyOne = 21,
TwentyTwo = 22,
TwentyThree = 23,
CardFormatBroken = 24,
TwentyFive = 25,
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,
CardMount = 26,
TwentySeven = 27,
TwentyEight = 28,
TwentyNine = 29,
Thirty = 30,
ThirtyOne = 31,
ThirtyTwo = 32,
FileBuild = 33,
FileWrite = 34,
ThirtyFive = 35,
FileRename = 36,
CardCheck = 27,
FileDeleteBad = 28,
FileRead = 29,
FileDeleteAlt = 30,
FileCreate = 31,
FileWrite = 32,
FileCreateTransactional = 33,
FileWriteTransactional = 34,
FileDeleteAltTransactional = 35,
FileRenameBtoA = 36,
CardFormat = 37
};
enum class EError
{
Zero,
One,
Two,
Three,
Four,
Five,
Six,
Seven,
Eight,
Nine
OK,
CardBroken,
CardWrongCharacterSet,
CardIOError,
CardWrongDevice,
CardFull,
CardStillFull, /* After attempting alt-delete (if needed) */
CardNon8KSectors,
FileMissing,
FileCorrupted
};
private:
@ -121,20 +121,27 @@ private:
}
};
enum class EFileState
{
Unknown,
NoFile,
File,
BadFile
};
CMemoryCardSys::EMemoryCardPort x0_cardPort;
ResId x4_saveBanner;
ResId x8_saveIcon0;
ResId xc_saveIcon1;
EState x10_state = EState::Initial;
EError x14_error = EError::Zero;
EError x14_error = EError::OK;
s32 x18_cardFreeBytes = 0;
s32 x1c_cardFreeFiles = 0;
u32 x20_fileTime = 0;
u32 x24_ = 0;
u64 x28_cardSerial = 0;
u8 x30_systemData[174] = {};
std::unique_ptr<SGameFileSlot> xe4_fileSlots[3];
std::vector<std::pair<u32, SFileInfo>> x100_mcFileInfos;
std::vector<std::pair<EFileState, SFileInfo>> x100_mcFileInfos;
u32 x194_fileIdx = -1;
std::unique_ptr<CMemoryCardSys::CCardFileInfo> x198_fileInfo;
bool x19c_ = false;
@ -143,44 +150,44 @@ private:
public:
CMemoryCardDriver(CMemoryCardSys::EMemoryCardPort cardPort, ResId saveBanner,
ResId saveIcon0, ResId saveIcon1, bool importPersistent);
void FinishedLoading();
void FinishedLoading2();
void NoCardFound();
void MountCard();
void CheckCard();
void NoCardFound();
CGameState::GameFileStateInfo* GetGameFileStateInfo(int idx);
static SSaveHeader LoadSaveHeader(CMemoryInStream& in);
static std::unique_ptr<SGameFileSlot> LoadSaveFile(CMemoryInStream& in);
void ReadFinished();
void ImportPersistentOptions();
void ExportPersistentOptions();
void DeleteFile();
void CheckCardCapacity();
void IndexFiles();
void Case26(CMemoryCardSys::ECardResult result);
void Case27(CMemoryCardSys::ECardResult result);
void Case28(CMemoryCardSys::ECardResult result);
void Case29(CMemoryCardSys::ECardResult result);
void Case30(CMemoryCardSys::ECardResult result);
void Case31(CMemoryCardSys::ECardResult result);
void Case32(CMemoryCardSys::ECardResult result);
void Case33(CMemoryCardSys::ECardResult result);
void Case34(CMemoryCardSys::ECardResult result);
void Case35(CMemoryCardSys::ECardResult result);
void Case36(CMemoryCardSys::ECardResult result);
void Case37(CMemoryCardSys::ECardResult result);
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 GoTo17();
void GoTo28();
void GoTo29();
void GoTo31();
void GoTo32();
void GoTo33();
void GoTo34();
void GoTo35();
void GoTo36();
void GoTo37();
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
void ClearFileInfo() { x198_fileInfo.reset(); }
void InitializeFileInfo();
@ -189,18 +196,18 @@ public:
void HandleCardError(CMemoryCardSys::ECardResult result, EState state);
void Update();
static bool InCardInsertedRange(EState v)
static bool IsCardBusy(EState v)
{
return v >= EState::CardMount && v <= EState::CardFormat;
}
static bool InRange2(EState v)
static bool IsOperationDestructive(EState v)
{
if (v < EState::TwentyFive)
if (v < EState::CardProbe)
return false;
if (v == EState::TwentySeven)
if (v == EState::CardCheck)
return false;
if (v == EState::TwentyNine)
if (v == EState::FileRead)
return false;
return true;
}

View File

@ -18,9 +18,9 @@ void CSaveUI::ResetCardDriver()
{
x92_ = false;
x6c_cardDriver.reset();
bool flag = (x0_instIdx == 0 && !x90_needsDriverReset);
x6c_cardDriver = ConstructCardDriver(flag);
x6c_cardDriver->FinishedLoading();
bool importState = (x0_instIdx == 0 && !x90_needsDriverReset);
x6c_cardDriver = ConstructCardDriver(importState);
x6c_cardDriver->StartCardProbe();
x10_uiType = UIType::Zero;
FinishedLoading();
}
@ -33,7 +33,7 @@ CIOWin::EMessageReturn CSaveUI::Update(float dt)
x50_loadedFrame->Update(dt);
x6c_cardDriver->Update();
if (x6c_cardDriver->x10_state == EState::RuntimeBackup)
if (x6c_cardDriver->x10_state == EState::DriverClosed)
{
if (x90_needsDriverReset)
{
@ -43,7 +43,7 @@ CIOWin::EMessageReturn CSaveUI::Update(float dt)
else
x80_iowRet = CIOWin::EMessageReturn::Exit;
}
else if (x6c_cardDriver->x10_state == EState::SelectCardFile && x10_uiType != UIType::Fourteen)
else if (x6c_cardDriver->x10_state == EState::CardCheckDone && x10_uiType != UIType::Fourteen)
{
if (x6c_cardDriver->x28_cardSerial && x8_serial)
{
@ -55,14 +55,14 @@ CIOWin::EMessageReturn CSaveUI::Update(float dt)
else
{
x8_serial = x6c_cardDriver->x28_cardSerial;
x6c_cardDriver->GoTo17();
x6c_cardDriver->IndexFiles();
}
}
}
else if (x6c_cardDriver->x10_state == EState::Ready)
{
if (x90_needsDriverReset)
x6c_cardDriver->GoTo33();
x6c_cardDriver->StartFileCreateTransactional();
}
if (x80_iowRet != CIOWin::EMessageReturn::Normal)
@ -76,18 +76,18 @@ CIOWin::EMessageReturn CSaveUI::Update(float dt)
if (x6c_cardDriver->x10_state == EState::NoCard)
{
auto res = CMemoryCardSys::CardProbe(CMemoryCardSys::EMemoryCardPort::SlotA);
if (res.x0_error == CMemoryCardSys::ECardResult::CARD_RESULT_READY ||
res.x0_error == CMemoryCardSys::ECardResult::CARD_RESULT_WRONGDEVICE)
if (res.x0_error == CMemoryCardSys::ECardResult::READY ||
res.x0_error == CMemoryCardSys::ECardResult::WRONGDEVICE)
ResetCardDriver();
}
else if (x6c_cardDriver->x10_state == EState::CardFormatted)
{
ResetCardDriver();
}
else if (x6c_cardDriver->x10_state == EState::Seventeen &&
x6c_cardDriver->x14_error == EError::Eight)
else if (x6c_cardDriver->x10_state == EState::FileBad &&
x6c_cardDriver->x14_error == EError::FileMissing)
{
x6c_cardDriver->GoTo31();
x6c_cardDriver->StartFileCreate();
}
return CIOWin::EMessageReturn::Normal;
@ -125,7 +125,7 @@ bool CSaveUI::PumpLoad()
std::bind(&CSaveUI::DoSelectionChange, this, std::placeholders::_1));
if (x0_instIdx == 1)
x6c_cardDriver->FinishedLoading();
x6c_cardDriver->StartCardProbe();
x10_uiType = SelectUIType();
FinishedLoading();
@ -146,43 +146,43 @@ CSaveUI::UIType CSaveUI::SelectUIType() const
default: break;
}
if (CMemoryCardDriver::InCardInsertedRange(x6c_cardDriver->x10_state))
if (CMemoryCardDriver::IsCardBusy(x6c_cardDriver->x10_state))
{
if (!CMemoryCardDriver::InRange2(x6c_cardDriver->x10_state))
if (!CMemoryCardDriver::IsOperationDestructive(x6c_cardDriver->x10_state))
return UIType::Two;
return UIType::One;
}
if (x6c_cardDriver->x10_state == EState::Ready)
{
if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::Six)
if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::CardStillFull)
return UIType::Twelve;
return UIType::Sixteen;
}
if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::One)
if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::CardBroken)
return UIType::Four;
if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::Two)
if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::CardWrongCharacterSet)
return UIType::Five;
if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::Four)
if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::CardWrongDevice)
return UIType::Seven;
if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::Five)
if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::CardFull)
{
if (x6c_cardDriver->x10_state == EState::Fourteen)
if (x6c_cardDriver->x10_state == EState::CardCheckFailed)
return UIType::Eight;
return UIType::Nine;
}
if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::Seven)
if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::CardNon8KSectors)
return UIType::Ten;
if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::Nine)
if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::FileCorrupted)
return UIType::Eleven;
if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::Three)
if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::CardIOError)
return UIType::Six;
return UIType::Zero;
@ -254,12 +254,12 @@ CSaveUI::CSaveUI(u32 instIdx, u64 serial)
}
}
std::unique_ptr<CMemoryCardDriver> CSaveUI::ConstructCardDriver(bool flag)
std::unique_ptr<CMemoryCardDriver> CSaveUI::ConstructCardDriver(bool importState)
{
return std::make_unique<CMemoryCardDriver>(CMemoryCardSys::EMemoryCardPort::SlotA,
g_ResFactory->GetResourceIdByName("TXTR_SaveBanner")->id,
g_ResFactory->GetResourceIdByName("TXTR_SaveIcon0")->id,
g_ResFactory->GetResourceIdByName("TXTR_SaveIcon1")->id, flag);
g_ResFactory->GetResourceIdByName("TXTR_SaveIcon1")->id, importState);
}
}

View File

@ -87,7 +87,7 @@ private:
void ResetCardDriver();
public:
static std::unique_ptr<CMemoryCardDriver> ConstructCardDriver(bool flag);
static std::unique_ptr<CMemoryCardDriver> ConstructCardDriver(bool importState);
CIOWin::EMessageReturn Update(float dt);
bool PumpLoad();
UIType SelectUIType() const;

View File

@ -214,7 +214,7 @@ private:
bool x160_28_ : 1;
bool x160_29_ : 1;
bool x160_30_ : 1;
bool x160_31_cardInserted : 1;
bool x160_31_cardBusy : 1;
bool x161_24_ : 1;
};
u16 _dummy = 0;
@ -251,7 +251,7 @@ public:
void ShutdownSubsystems() {}
EGameplayResult GetGameplayResult() const {return xe4_gameplayResult;}
void SetGameplayResult(EGameplayResult wl) {xe4_gameplayResult = wl;}
void SetCardInserted(bool v) {x160_31_cardInserted = v;}
void SetCardBusy(bool v) {x160_31_cardBusy = v;}
EFlowState GetFlowState() const { return x12c_flowState; }
};