diff --git a/Runtime/CMemoryCardSys.cpp b/Runtime/CMemoryCardSys.cpp index 08d54cc36..b518e2a38 100644 --- a/Runtime/CMemoryCardSys.cpp +++ b/Runtime/CMemoryCardSys.cpp @@ -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; } } diff --git a/Runtime/CMemoryCardSys.hpp b/Runtime/CMemoryCardSys.hpp index 582e6d370..679ccc1d7 100644 --- a/Runtime/CMemoryCardSys.hpp +++ b/Runtime/CMemoryCardSys.hpp @@ -8,6 +8,8 @@ #include "GuiSys/CStringTable.hpp" #include +#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 diff --git a/Runtime/MP1/CMemoryCardDriver.cpp b/Runtime/MP1/CMemoryCardDriver.cpp index 40cdfa57e..1b27f805e 100644 --- a/Runtime/MP1/CMemoryCardDriver.cpp +++ b/Runtime/MP1/CMemoryCardDriver.cpp @@ -19,13 +19,13 @@ using EMemoryCardPort = CMemoryCardSys::EMemoryCardPort; ECardResult CMemoryCardDriver::SFileInfo::Open() { //CARDOpen(GetFileCardPort(), x14_name.data(), &x0_fileInfo); - return ECardResult::CARD_RESULT_READY; + return ECardResult::READY; } ECardResult CMemoryCardDriver::SFileInfo::Close() { auto backup = GetFileCardPort(); - ECardResult result = ECardResult::CARD_RESULT_READY; + ECardResult result = ECardResult::READY; //result = CARDClose(backup); x0_fileInfo.x0_cardPort = backup; return result; @@ -35,20 +35,20 @@ CMemoryCardSys::ECardResult CMemoryCardDriver::SFileInfo::StartRead() { CMemoryCardSys::CARDStat stat = {}; ECardResult result = CMemoryCardSys::GetStatus(GetFileCardPort(), GetFileNo(), stat); - if (result != ECardResult::CARD_RESULT_READY) + if (result != ECardResult::READY) return result; u32 length = stat.GetFileLength(); x34_saveData.clear(); x24_saveFileData.resize(length); //return CARDReadAsync(&x0_fileInfo, x24_saveFileData.data(), length, 0, 0); - return ECardResult::CARD_RESULT_READY; + return ECardResult::READY; } ECardResult CMemoryCardDriver::SFileInfo::TryFileRead() { ECardResult res = CMemoryCardSys::GetResultCode(GetFileCardPort()); - if (res == ECardResult::CARD_RESULT_READY) + if (res == ECardResult::READY) res = FileRead(); return res; } @@ -62,7 +62,7 @@ ECardResult CMemoryCardDriver::SFileInfo::FileRead() { u32 saveDataOff; ECardResult result = GetSaveDataOffset(saveDataOff); - if (result != ECardResult::CARD_RESULT_READY) + if (result != ECardResult::READY) { x24_saveFileData.clear(); return result; @@ -72,12 +72,12 @@ ECardResult CMemoryCardDriver::SFileInfo::FileRead() x34_saveData.resize(saveSize); memmove(x34_saveData.data(), x24_saveFileData.data() + saveDataOff, saveSize); x24_saveFileData.clear(); - return ECardResult::CARD_RESULT_READY; + return ECardResult::READY; } else { x24_saveFileData.clear(); - return ECardResult::CARD_RESULT_CRC_MISMATCH; + return ECardResult::CRC_MISMATCH; } } @@ -85,7 +85,7 @@ ECardResult CMemoryCardDriver::SFileInfo::GetSaveDataOffset(u32& offOut) { CMemoryCardSys::CARDStat stat = {}; ECardResult result = CMemoryCardSys::GetStatus(GetFileCardPort(), GetFileNo(), stat); - if (result != ECardResult::CARD_RESULT_READY) + if (result != ECardResult::READY) { offOut = -1; return result; @@ -121,7 +121,7 @@ ECardResult CMemoryCardDriver::SFileInfo::GetSaveDataOffset(u32& offOut) if (paletteIcon) offOut += 512; - return ECardResult::CARD_RESULT_READY; + return ECardResult::READY; } CMemoryCardDriver::SGameFileSlot::SGameFileSlot() @@ -155,64 +155,14 @@ CMemoryCardDriver::CMemoryCardDriver(EMemoryCardPort cardPort, ResId saveBanner, x8_saveIcon0(saveIcon0), xc_saveIcon1(saveIcon1), x19d_doImportPersistent(importPersistent) { x100_mcFileInfos.reserve(2); - x100_mcFileInfos.emplace_back(0, SFileInfo(x0_cardPort, SaveFileNames[0])); - x100_mcFileInfos.emplace_back(0, SFileInfo(x0_cardPort, SaveFileNames[1])); -} - -void CMemoryCardDriver::FinishedLoading() -{ - x10_state = EState::TwentyFive; - x14_error = EError::Zero; - FinishedLoading2(); -} - -void CMemoryCardDriver::FinishedLoading2() -{ - auto result = CMemoryCardSys::CardProbe(x0_cardPort); - switch (result.x0_error) - { - case ECardResult::CARD_RESULT_READY: - if (result.x8_sectorSize != 0x2000) - { - x10_state = EState::Twelve; - x14_error = EError::Seven; - return; - } - x10_state = EState::CardNeedsMount; - MountCard(); - break; - case ECardResult::CARD_RESULT_BUSY: - break; - case ECardResult::CARD_RESULT_WRONGDEVICE: - x10_state = EState::Twelve; - x14_error = EError::Four; - break; - default: - NoCardFound(); - break; - } + x100_mcFileInfos.emplace_back(EFileState::Unknown, SFileInfo(x0_cardPort, SaveFileNames[0])); + x100_mcFileInfos.emplace_back(EFileState::Unknown, SFileInfo(x0_cardPort, SaveFileNames[1])); } void CMemoryCardDriver::NoCardFound() { x10_state = EState::NoCard; - static_cast(g_Main)->SetCardInserted(false); -} - -void CMemoryCardDriver::MountCard() -{ - x10_state = EState::CardMount; - x14_error = EError::Zero; - ECardResult result = CMemoryCardSys::MountCard(x0_cardPort); - if (result != ECardResult::CARD_RESULT_READY) - Case26(result); -} - -void CMemoryCardDriver::CheckCard() -{ - ECardResult result = CMemoryCardSys::CheckCard(x0_cardPort); - if (result != ECardResult::CARD_RESULT_READY) - Case27(result); + static_cast(g_Main)->SetCardBusy(false); } CGameState::GameFileStateInfo* CMemoryCardDriver::GetGameFileStateInfo(int idx) @@ -241,7 +191,8 @@ void CMemoryCardDriver::ReadFinished() { CMemoryCardSys::CARDStat stat = {}; SFileInfo& fileInfo = x100_mcFileInfos[x194_fileIdx].second; - if (CMemoryCardSys::GetStatus(x0_cardPort, fileInfo.GetFileNo(), stat) != ECardResult::CARD_RESULT_READY) + if (CMemoryCardSys::GetStatus(x0_cardPort, fileInfo.GetFileNo(), stat) != + ECardResult::READY) { NoCardFound(); return; @@ -275,286 +226,43 @@ void CMemoryCardDriver::ExportPersistentOptions() opts.PutTo(w); } -void CMemoryCardDriver::DeleteFile() -{ - x14_error = EError::Zero; - x10_state = EState::Thirty; - SFileInfo& fileInfo = x100_mcFileInfos[!bool(x194_fileIdx)].second; - ECardResult result = CMemoryCardSys::FastDeleteFile(x0_cardPort, fileInfo.GetFileNo()); - if (result != ECardResult::CARD_RESULT_READY) - Case30(result); -} - void CMemoryCardDriver::CheckCardCapacity() { if (x18_cardFreeBytes < 0x2000 || !x1c_cardFreeFiles) - x14_error = EError::Six; + x14_error = EError::CardStillFull; } -void CMemoryCardDriver::Case26(ECardResult result) +void CMemoryCardDriver::IndexFiles() { - switch (result) + x14_error = EError::OK; + for (std::pair& info : x100_mcFileInfos) { - case ECardResult::CARD_RESULT_READY: - x10_state = EState::CardMountDone; - CheckCard(); - break; - case ECardResult::CARD_RESULT_BROKEN: - x10_state = EState::CardMountDone; - x14_error = EError::One; - CheckCard(); - break; - default: - HandleCardError(result, EState::Thirteen); - break; - } -} - -void CMemoryCardDriver::Case27(ECardResult result) -{ - switch (result) - { - case ECardResult::CARD_RESULT_READY: - x10_state = EState::SelectCardFile; - if (!GetCardFreeBytes()) - return; - if (CMemoryCardSys::GetSerialNo(x0_cardPort, x28_cardSerial) == ECardResult::CARD_RESULT_READY) - return; - NoCardFound(); - break; - case ECardResult::CARD_RESULT_BROKEN: - x10_state = EState::Fourteen; - x14_error = EError::One; - break; - default: - HandleCardError(result, EState::Fourteen); - } -} - -void CMemoryCardDriver::Case28(ECardResult result) -{ - if (result == ECardResult::CARD_RESULT_READY) - { - x100_mcFileInfos[x194_fileIdx].first = 1; - if (x100_mcFileInfos[!bool(x194_fileIdx)].first == 3) - { - x10_state = EState::Seventeen; - GoTo28(); - } - else - { - x10_state = EState::SelectCardFile; - if (!GetCardFreeBytes()) - return; - GoTo17(); - } - } - else - HandleCardError(result, EState::Fifteen); -} - -void CMemoryCardDriver::Case29(ECardResult result) -{ - if (result == ECardResult::CARD_RESULT_READY) - { - auto& fileInfo = x100_mcFileInfos[x194_fileIdx]; - ECardResult readRes = fileInfo.second.TryFileRead(); - if (fileInfo.second.Close() != ECardResult::CARD_RESULT_READY) - { - NoCardFound(); - return; - } - - u32 fileIdx = !bool(x194_fileIdx); - if (readRes == ECardResult::CARD_RESULT_READY) - { - x10_state = EState::Ready; - ReadFinished(); - u32 fileId = x100_mcFileInfos[fileIdx].first; - if (fileId == 1) - CheckCardCapacity(); - else - DeleteFile(); - return; - } - - if (readRes == ECardResult::CARD_RESULT_CRC_MISMATCH) - { - x100_mcFileInfos[x194_fileIdx].first = 3; - if (x100_mcFileInfos[fileIdx].first == 2) - { - x10_state = EState::SelectCardFile; - GoTo17(); - } - else - { - x10_state = EState::Seventeen; - x14_error = EError::Nine; - } - } - } - else - HandleCardError(result, EState::Seventeen); -} - -void CMemoryCardDriver::Case30(ECardResult result) -{ - if (result == ECardResult::CARD_RESULT_READY) - { - x10_state = EState::Ready; - if (GetCardFreeBytes()) - CheckCardCapacity(); - } - else - HandleCardError(result, EState::Sixteen); -} - -void CMemoryCardDriver::Case31(ECardResult result) -{ - if (result == ECardResult::CARD_RESULT_READY) - { - x10_state = EState::WillWrite; - GoTo32(); - } - else - HandleCardError(result, EState::Eighteen); -} - -void CMemoryCardDriver::Case32(ECardResult result) -{ - if (result == ECardResult::CARD_RESULT_READY) - { - ECardResult xferResult = x198_fileInfo->PumpCardTransfer(); - if (xferResult == ECardResult::CARD_RESULT_READY) - { - x10_state = EState::Ready; - if (x198_fileInfo->Close() == ECardResult::CARD_RESULT_READY) - return; - NoCardFound(); - return; - } - if (xferResult == ECardResult::CARD_RESULT_BUSY) - return; - if (xferResult == ECardResult::CARD_RESULT_IOERROR) - { - x10_state = EState::Nineteen; - x14_error = EError::Three; - return; - } - NoCardFound(); - } - else - HandleCardError(result, EState::Nineteen); -} - -void CMemoryCardDriver::Case33(ECardResult result) -{ - if (result == ECardResult::CARD_RESULT_READY) - { - x10_state = EState::Nine; - GoTo34(); - } - else - HandleCardError(result, EState::Twenty); -} - -void CMemoryCardDriver::Case34(ECardResult result) -{ - if (result == ECardResult::CARD_RESULT_READY) - { - ECardResult xferResult = x198_fileInfo->PumpCardTransfer(); - if (xferResult == ECardResult::CARD_RESULT_READY) - { - x10_state = EState::Ten; - if (x198_fileInfo->Close() != ECardResult::CARD_RESULT_READY) - { - NoCardFound(); - return; - } - GoTo35(); - return; - } - if (xferResult == ECardResult::CARD_RESULT_BUSY) - return; - if (xferResult == ECardResult::CARD_RESULT_IOERROR) - { - x10_state = EState::TwentyOne; - x14_error = EError::Three; - return; - } - NoCardFound(); - } - else - HandleCardError(result, EState::TwentyOne); -} - -void CMemoryCardDriver::Case35(ECardResult result) -{ - if (result == ECardResult::CARD_RESULT_READY) - { - x10_state = EState::Eleven; - if (GetCardFreeBytes()) - GoTo36(); - } - else - HandleCardError(result, EState::TwentyTwo); -} - -void CMemoryCardDriver::Case36(ECardResult result) -{ - if (result == ECardResult::CARD_RESULT_READY) - { - x10_state = EState::RuntimeBackup; - WriteBackupBuf(); - } - else - HandleCardError(result, EState::TwentyThree); -} - -void CMemoryCardDriver::Case37(ECardResult result) -{ - if (result == ECardResult::CARD_RESULT_READY) - x10_state = EState::CardFormatted; - else if (result == ECardResult::CARD_RESULT_BROKEN) - { - x10_state = EState::CardFormatBroken; - x14_error = EError::Three; - } - else - HandleCardError(result, EState::CardFormatBroken); -} - -void CMemoryCardDriver::GoTo17() -{ - x14_error = EError::Zero; - for (std::pair& info : x100_mcFileInfos) - { - if (info.first == 0) + if (info.first == EFileState::Unknown) { ECardResult result = info.second.Open(); - if (result == ECardResult::CARD_RESULT_NOFILE) + if (result == ECardResult::NOFILE) { - info.first = 1; + info.first = EFileState::NoFile; continue; } - else if (result == ECardResult::CARD_RESULT_READY) + else if (result == ECardResult::READY) { CMemoryCardSys::CARDStat stat = {}; if (CMemoryCardSys::GetStatus(x0_cardPort, info.second.GetFileNo(), stat) == - ECardResult::CARD_RESULT_READY) + ECardResult::READY) { u32 comment = stat.GetCommentAddr(); if (comment == -1) - info.first = 3; + info.first = EFileState::BadFile; else - info.first = 2; + info.first = EFileState::File; } else { NoCardFound(); return; } - if (info.second.Close() == ECardResult::CARD_RESULT_NOCARD) + if (info.second.Close() == ECardResult::NOCARD) { NoCardFound(); return; @@ -568,24 +276,24 @@ void CMemoryCardDriver::GoTo17() } } - if (x100_mcFileInfos[0].first == 2) + if (x100_mcFileInfos[0].first == EFileState::File) { - if (x100_mcFileInfos[1].first == 2) + if (x100_mcFileInfos[1].first == EFileState::File) { CMemoryCardSys::CARDStat stat = {}; if (CMemoryCardSys::GetStatus(x0_cardPort, x100_mcFileInfos[0].second.GetFileNo(), stat) == - ECardResult::CARD_RESULT_READY) + ECardResult::READY) { u32 timeA = stat.GetTime(); if (CMemoryCardSys::GetStatus(x0_cardPort, x100_mcFileInfos[1].second.GetFileNo(), stat) == - ECardResult::CARD_RESULT_READY) + ECardResult::READY) { u32 timeB = stat.GetTime(); if (timeA > timeB) x194_fileIdx = 0; else x194_fileIdx = 1; - GoTo29(); + StartFileRead(); return; } NoCardFound(); @@ -595,43 +303,69 @@ void CMemoryCardDriver::GoTo17() return; } x194_fileIdx = 0; - GoTo29(); + StartFileRead(); return; } - if (x100_mcFileInfos[1].first == 2) + if (x100_mcFileInfos[1].first == EFileState::File) { x194_fileIdx = 1; - GoTo29(); + StartFileRead(); return; } - if (x100_mcFileInfos[0].first == 3 || x100_mcFileInfos[1].first == 3) + if (x100_mcFileInfos[0].first == EFileState::BadFile || + x100_mcFileInfos[1].first == EFileState::BadFile) { - x10_state = EState::Seventeen; - x14_error = EError::Nine; + x10_state = EState::FileBad; + x14_error = EError::FileCorrupted; } else { - x10_state = EState::Seventeen; - x14_error = EError::Eight; + x10_state = EState::FileBad; + x14_error = EError::FileMissing; } } -void CMemoryCardDriver::GoTo28() +void CMemoryCardDriver::StartCardProbe() { - x14_error = EError::Zero; - x10_state = EState::TwentyEight; + x10_state = EState::CardProbe; + x14_error = EError::OK; + UpdateCardProbe(); +} + +void CMemoryCardDriver::StartMountCard() +{ + x10_state = EState::CardMount; + x14_error = EError::OK; + ECardResult result = CMemoryCardSys::MountCard(x0_cardPort); + if (result != ECardResult::READY) + UpdateMountCard(result); +} + +void CMemoryCardDriver::StartCardCheck() +{ + x14_error = EError::OK; + x10_state = EState::CardCheck; + ECardResult result = CMemoryCardSys::CheckCard(x0_cardPort); + if (result != ECardResult::READY) + UpdateCardCheck(result); +} + +void CMemoryCardDriver::StartFileDeleteBad() +{ + x14_error = EError::OK; + x10_state = EState::FileDeleteBad; int idx = 0; - for (std::pair& info : x100_mcFileInfos) + for (std::pair& info : x100_mcFileInfos) { - if (info.first == 3) + if (info.first == EFileState::BadFile) { x194_fileIdx = idx; ECardResult result = CMemoryCardSys::FastDeleteFile(x0_cardPort, info.second.GetFileNo()); - if (result != ECardResult::CARD_RESULT_READY) + if (result != ECardResult::READY) { - Case28(result); + UpdateFileDeleteBad(result); return; } } @@ -639,113 +373,385 @@ void CMemoryCardDriver::GoTo28() } } -void CMemoryCardDriver::GoTo29() +void CMemoryCardDriver::StartFileRead() { - x14_error = EError::Zero; - x10_state = EState::TwentyNine; + x14_error = EError::OK; + x10_state = EState::FileRead; ECardResult result = x100_mcFileInfos[x194_fileIdx].second.Open(); - if (result != ECardResult::CARD_RESULT_READY) + if (result != ECardResult::READY) { - Case29(result); + UpdateFileRead(result); return; } result = x100_mcFileInfos[x194_fileIdx].second.StartRead(); - if (result != ECardResult::CARD_RESULT_READY) - Case29(result); + if (result != ECardResult::READY) + UpdateFileRead(result); } -void CMemoryCardDriver::GoTo31() +void CMemoryCardDriver::StartFileDeleteAlt() { - x14_error = EError::Zero; - x10_state = EState::ThirtyOne; + x14_error = EError::OK; + x10_state = EState::FileDeleteAlt; + SFileInfo& fileInfo = x100_mcFileInfos[!bool(x194_fileIdx)].second; + ECardResult result = CMemoryCardSys::FastDeleteFile(x0_cardPort, fileInfo.GetFileNo()); + if (result != ECardResult::READY) + UpdateFileDeleteAlt(result); +} + +void CMemoryCardDriver::StartFileCreate() +{ + x14_error = EError::OK; + x10_state = EState::FileCreate; if (x18_cardFreeBytes < 8192 || x1c_cardFreeFiles < 2) { - x10_state = EState::Eighteen; - x14_error = EError::Five; + x10_state = EState::FileCreateFailed; + x14_error = EError::CardFull; return; } x198_fileInfo = std::make_unique(x0_cardPort, SaveFileNames[x194_fileIdx]); InitializeFileInfo(); ECardResult result = x198_fileInfo->CreateFile(); - if (result != ECardResult::CARD_RESULT_READY) - Case31(result); + if (result != ECardResult::READY) + UpdateFileCreate(result); } -void CMemoryCardDriver::GoTo32() +void CMemoryCardDriver::StartFileWrite() { - x14_error = EError::Zero; - x10_state = EState::ThirtyTwo; + x14_error = EError::OK; + x10_state = EState::FileWrite; ECardResult result = x198_fileInfo->Write(); - if (result != ECardResult::CARD_RESULT_READY) - Case32(result); + if (result != ECardResult::READY) + UpdateFileWrite(result); } -void CMemoryCardDriver::GoTo33() +void CMemoryCardDriver::StartFileCreateTransactional() { - x14_error = EError::Zero; - x10_state = EState::FileBuild; + x14_error = EError::OK; + x10_state = EState::FileCreateTransactional; ClearFileInfo(); if (x18_cardFreeBytes < 8192 || !x1c_cardFreeFiles) { - x10_state = EState::Twenty; - x14_error = EError::Five; + x10_state = EState::FileCreateTransactionalFailed; + x14_error = EError::CardFull; return; } + x194_fileIdx = !bool(x194_fileIdx); x198_fileInfo = std::make_unique(x0_cardPort, SaveFileNames[x194_fileIdx]); InitializeFileInfo(); ECardResult result = x198_fileInfo->CreateFile(); - if (result != ECardResult::CARD_RESULT_READY) - Case33(result); + if (result != ECardResult::READY) + UpdateFileCreateTransactional(result); } -void CMemoryCardDriver::GoTo34() +void CMemoryCardDriver::StartFileWriteTransactional() { - x14_error = EError::Zero; - x10_state = EState::FileWrite; + x14_error = EError::OK; + x10_state = EState::FileWriteTransactional; ECardResult result = x198_fileInfo->Write(); - if (result != ECardResult::CARD_RESULT_READY) - Case34(result); + if (result != ECardResult::READY) + UpdateFileWriteTransactional(result); } -void CMemoryCardDriver::GoTo35() +void CMemoryCardDriver::StartFileDeleteAltTransactional() { - x14_error = EError::Zero; - x10_state = EState::ThirtyFive; + x14_error = EError::OK; + x10_state = EState::FileDeleteAltTransactional; ECardResult result = CMemoryCardSys::DeleteFile(x0_cardPort, SaveFileNames[!bool(x194_fileIdx)]); - if (result != ECardResult::CARD_RESULT_READY) - Case35(result); + if (result != ECardResult::READY) + UpdateFileDeleteAltTransactional(result); } -void CMemoryCardDriver::GoTo36() +void CMemoryCardDriver::StartFileRenameBtoA() { if (x194_fileIdx == 1) { - x14_error = EError::Zero; - x10_state = EState::FileRename; + /* Rename B file to A file (ideally the card is always left with 'A' only) */ + x14_error = EError::OK; + x10_state = EState::FileRenameBtoA; ECardResult result = CMemoryCardSys::Rename(x0_cardPort, SaveFileNames[x194_fileIdx], SaveFileNames[!bool(x194_fileIdx)]); - if (result != ECardResult::CARD_RESULT_READY) - Case36(result); + if (result != ECardResult::READY) + UpdateFileRenameBtoA(result); } else { - x10_state = EState::RuntimeBackup; + x10_state = EState::DriverClosed; WriteBackupBuf(); } } -void CMemoryCardDriver::GoTo37() +void CMemoryCardDriver::StartCardFormat() { - x14_error = EError::Zero; + x14_error = EError::OK; x10_state = EState::CardFormat; ECardResult result = CMemoryCardSys::FormatCard(x0_cardPort); - if (result != ECardResult::CARD_RESULT_READY) - Case37(result); + if (result != ECardResult::READY) + UpdateCardFormat(result); +} + +void CMemoryCardDriver::UpdateMountCard(ECardResult result) +{ + switch (result) + { + case ECardResult::READY: + x10_state = EState::CardMountDone; + StartCardCheck(); + break; + case ECardResult::BROKEN: + x10_state = EState::CardMountDone; + x14_error = EError::CardBroken; + StartCardCheck(); + break; + default: + HandleCardError(result, EState::CardMountFailed); + break; + } +} + +void CMemoryCardDriver::UpdateCardProbe() +{ + auto result = CMemoryCardSys::CardProbe(x0_cardPort); + switch (result.x0_error) + { + case ECardResult::READY: + if (result.x8_sectorSize != 0x2000) + { + x10_state = EState::CardProbeFailed; + x14_error = EError::CardNon8KSectors; + return; + } + x10_state = EState::CardProbeDone; + StartMountCard(); + break; + case ECardResult::BUSY: + break; + case ECardResult::WRONGDEVICE: + x10_state = EState::CardProbeFailed; + x14_error = EError::CardWrongDevice; + break; + default: + NoCardFound(); + break; + } +} + +void CMemoryCardDriver::UpdateCardCheck(ECardResult result) +{ + switch (result) + { + case ECardResult::READY: + x10_state = EState::CardCheckDone; + if (!GetCardFreeBytes()) + return; + if (CMemoryCardSys::GetSerialNo(x0_cardPort, x28_cardSerial) == ECardResult::READY) + return; + NoCardFound(); + break; + case ECardResult::BROKEN: + x10_state = EState::CardCheckFailed; + x14_error = EError::CardBroken; + break; + default: + HandleCardError(result, EState::CardCheckFailed); + } +} + +void CMemoryCardDriver::UpdateFileDeleteBad(ECardResult result) +{ + if (result == ECardResult::READY) + { + x100_mcFileInfos[x194_fileIdx].first = EFileState::NoFile; + if (x100_mcFileInfos[!bool(x194_fileIdx)].first == EFileState::BadFile) + { + x10_state = EState::FileBad; + StartFileDeleteBad(); + } + else + { + x10_state = EState::CardCheckDone; + if (!GetCardFreeBytes()) + return; + IndexFiles(); + } + } + else + HandleCardError(result, EState::FileDeleteBadFailed); +} + +void CMemoryCardDriver::UpdateFileRead(ECardResult result) +{ + if (result == ECardResult::READY) + { + auto& fileInfo = x100_mcFileInfos[x194_fileIdx]; + ECardResult readRes = fileInfo.second.TryFileRead(); + if (fileInfo.second.Close() != ECardResult::READY) + { + NoCardFound(); + return; + } + + u32 altFileIdx = !bool(x194_fileIdx); + if (readRes == ECardResult::READY) + { + x10_state = EState::Ready; + ReadFinished(); + EFileState fileSt = x100_mcFileInfos[altFileIdx].first; + if (fileSt == EFileState::NoFile) + CheckCardCapacity(); + else + StartFileDeleteAlt(); + return; + } + + if (readRes == ECardResult::CRC_MISMATCH) + { + x100_mcFileInfos[x194_fileIdx].first = EFileState::BadFile; + if (x100_mcFileInfos[altFileIdx].first == EFileState::File) + { + x10_state = EState::CardCheckDone; + IndexFiles(); + } + else + { + x10_state = EState::FileBad; + x14_error = EError::FileCorrupted; + } + } + } + else + HandleCardError(result, EState::FileBad); +} + +void CMemoryCardDriver::UpdateFileDeleteAlt(ECardResult result) +{ + if (result == ECardResult::READY) + { + x10_state = EState::Ready; + if (GetCardFreeBytes()) + CheckCardCapacity(); + } + else + HandleCardError(result, EState::FileDeleteAltFailed); +} + +void CMemoryCardDriver::UpdateFileCreate(ECardResult result) +{ + if (result == ECardResult::READY) + { + x10_state = EState::FileCreateDone; + StartFileWrite(); + } + else + HandleCardError(result, EState::FileCreateFailed); +} + +void CMemoryCardDriver::UpdateFileWrite(ECardResult result) +{ + if (result == ECardResult::READY) + { + ECardResult xferResult = x198_fileInfo->PumpCardTransfer(); + if (xferResult == ECardResult::READY) + { + x10_state = EState::Ready; + if (x198_fileInfo->Close() == ECardResult::READY) + return; + NoCardFound(); + return; + } + if (xferResult == ECardResult::BUSY) + return; + if (xferResult == ECardResult::IOERROR) + { + x10_state = EState::FileWriteFailed; + x14_error = EError::CardIOError; + return; + } + NoCardFound(); + } + else + HandleCardError(result, EState::FileWriteFailed); +} + +void CMemoryCardDriver::UpdateFileCreateTransactional(ECardResult result) +{ + if (result == ECardResult::READY) + { + x10_state = EState::FileCreateTransactionalDone; + StartFileWriteTransactional(); + } + else + HandleCardError(result, EState::FileCreateTransactionalFailed); +} + +void CMemoryCardDriver::UpdateFileWriteTransactional(ECardResult result) +{ + if (result == ECardResult::READY) + { + ECardResult xferResult = x198_fileInfo->PumpCardTransfer(); + if (xferResult == ECardResult::READY) + { + x10_state = EState::FileWriteTransactionalDone; + if (x198_fileInfo->Close() != ECardResult::READY) + { + NoCardFound(); + return; + } + StartFileDeleteAltTransactional(); + return; + } + if (xferResult == ECardResult::BUSY) + return; + if (xferResult == ECardResult::IOERROR) + { + x10_state = EState::FileWriteTransactionalFailed; + x14_error = EError::CardIOError; + return; + } + NoCardFound(); + } + else + HandleCardError(result, EState::FileWriteTransactionalFailed); +} + +void CMemoryCardDriver::UpdateFileDeleteAltTransactional(ECardResult result) +{ + if (result == ECardResult::READY) + { + x10_state = EState::FileDeleteAltTransactionalDone; + if (GetCardFreeBytes()) + StartFileRenameBtoA(); + } + else + HandleCardError(result, EState::FileDeleteAltTransactionalFailed); +} + +void CMemoryCardDriver::UpdateFileRenameBtoA(ECardResult result) +{ + if (result == ECardResult::READY) + { + x10_state = EState::DriverClosed; + WriteBackupBuf(); + } + else + HandleCardError(result, EState::FileRenameBtoAFailed); +} + +void CMemoryCardDriver::UpdateCardFormat(ECardResult result) +{ + if (result == ECardResult::READY) + x10_state = EState::CardFormatted; + else if (result == ECardResult::BROKEN) + { + x10_state = EState::CardFormatFailed; + x14_error = EError::CardIOError; + } + else + HandleCardError(result, EState::CardFormatFailed); } void CMemoryCardDriver::InitializeFileInfo() @@ -789,7 +795,7 @@ bool CMemoryCardDriver::GetCardFreeBytes() ECardResult result = CMemoryCardSys::GetNumFreeBytes(x0_cardPort, x18_cardFreeBytes, x1c_cardFreeFiles); - if (result == ECardResult::CARD_RESULT_READY) + if (result == ECardResult::READY) return true; NoCardFound(); return false; @@ -799,19 +805,19 @@ void CMemoryCardDriver::HandleCardError(ECardResult result, EState state) { switch (result) { - case ECardResult::CARD_RESULT_WRONGDEVICE: + case ECardResult::WRONGDEVICE: x10_state = state; - x14_error = EError::Four; + x14_error = EError::CardWrongDevice; break; - case ECardResult::CARD_RESULT_NOCARD: + case ECardResult::NOCARD: NoCardFound(); break; - case ECardResult::CARD_RESULT_IOERROR: + case ECardResult::IOERROR: x10_state = state; - x14_error = EError::Three; - case ECardResult::CARD_RESULT_ENCODING: + x14_error = EError::CardIOError; + case ECardResult::ENCODING: x10_state = state; - x14_error = EError::Two; + x14_error = EError::CardWrongCharacterSet; break; default: break; } @@ -821,72 +827,71 @@ void CMemoryCardDriver::Update() { CMemoryCardSys::CardProbeResults result = CMemoryCardSys::CardProbe(x0_cardPort); - if (result.x0_error == ECardResult::CARD_RESULT_NOCARD) + if (result.x0_error == ECardResult::NOCARD) { if (x10_state != EState::NoCard) NoCardFound(); - static_cast(g_Main)->SetCardInserted(false); + static_cast(g_Main)->SetCardBusy(false); return; } - if (x10_state == EState::TwentyFive) + if (x10_state == EState::CardProbe) { - FinishedLoading2(); - static_cast(g_Main)->SetCardInserted(false); + UpdateCardProbe(); + static_cast(g_Main)->SetCardBusy(false); return; } + ECardResult resultCode = CMemoryCardSys::GetResultCode(x0_cardPort); + bool cardBusy = false; - ECardResult resultCode = g_MemoryCardSys->GetResultCode(x0_cardPort); - bool cardInserted = false; - - if (InCardInsertedRange(x10_state)) + if (IsCardBusy(x10_state)) { - cardInserted = true; + cardBusy = true; switch (x10_state) { case EState::CardMount: - Case26(resultCode); + UpdateMountCard(resultCode); break; - case EState::TwentySeven: - Case27(resultCode); + case EState::CardCheck: + UpdateCardCheck(resultCode); break; - case EState::TwentyEight: - Case28(resultCode); + case EState::FileDeleteBad: + UpdateFileDeleteBad(resultCode); break; - case EState::TwentyNine: - Case29(resultCode); + case EState::FileRead: + UpdateFileRead(resultCode); break; - case EState::Thirty: - Case30(resultCode); + case EState::FileDeleteAlt: + UpdateFileDeleteAlt(resultCode); break; - case EState::ThirtyOne: - Case31(resultCode); - break; - case EState::ThirtyTwo: - Case32(resultCode); - break; - case EState::FileBuild: - Case33(resultCode); + case EState::FileCreate: + UpdateFileCreate(resultCode); break; case EState::FileWrite: - Case34(resultCode); + UpdateFileWrite(resultCode); break; - case EState::ThirtyFive: - Case35(resultCode); + case EState::FileCreateTransactional: + UpdateFileCreateTransactional(resultCode); break; - case EState::FileRename: - Case36(resultCode); + case EState::FileWriteTransactional: + UpdateFileWriteTransactional(resultCode); + break; + case EState::FileDeleteAltTransactional: + UpdateFileDeleteAltTransactional(resultCode); + break; + case EState::FileRenameBtoA: + UpdateFileRenameBtoA(resultCode); break; case EState::CardFormat: - Case37(resultCode); + UpdateCardFormat(resultCode); break; default: break; } } - static_cast(g_Main)->SetCardInserted(cardInserted); + static_cast(g_Main)->SetCardBusy(cardBusy); } } diff --git a/Runtime/MP1/CMemoryCardDriver.hpp b/Runtime/MP1/CMemoryCardDriver.hpp index a4c5219e3..0f561a8ab 100644 --- a/Runtime/MP1/CMemoryCardDriver.hpp +++ b/Runtime/MP1/CMemoryCardDriver.hpp @@ -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 xe4_fileSlots[3]; - std::vector> x100_mcFileInfos; + std::vector> x100_mcFileInfos; u32 x194_fileIdx = -1; std::unique_ptr 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 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; } diff --git a/Runtime/MP1/CSaveUI.cpp b/Runtime/MP1/CSaveUI.cpp index 2c9de2bc3..4529365a8 100644 --- a/Runtime/MP1/CSaveUI.cpp +++ b/Runtime/MP1/CSaveUI.cpp @@ -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 CSaveUI::ConstructCardDriver(bool flag) +std::unique_ptr CSaveUI::ConstructCardDriver(bool importState) { return std::make_unique(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); } } diff --git a/Runtime/MP1/CSaveUI.hpp b/Runtime/MP1/CSaveUI.hpp index 317850420..9ebeb98c4 100644 --- a/Runtime/MP1/CSaveUI.hpp +++ b/Runtime/MP1/CSaveUI.hpp @@ -87,7 +87,7 @@ private: void ResetCardDriver(); public: - static std::unique_ptr ConstructCardDriver(bool flag); + static std::unique_ptr ConstructCardDriver(bool importState); CIOWin::EMessageReturn Update(float dt); bool PumpLoad(); UIType SelectUIType() const; diff --git a/Runtime/MP1/MP1.hpp b/Runtime/MP1/MP1.hpp index 12d20fb7f..c0109af85 100644 --- a/Runtime/MP1/MP1.hpp +++ b/Runtime/MP1/MP1.hpp @@ -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; } };