From 3fca1f9c89602c4a178ee29b284b03ec853a49d1 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Tue, 11 Oct 2022 00:00:52 -0400 Subject: [PATCH] CMemoryCardDriver progress Former-commit-id: 32a5ad5b7165ef6e5e979a6f126250eb63d6ca8e --- asm/Kyoto/DolphinCMemoryCardSys.s | 12 +- asm/MetroidPrime/CMemoryCardDriver.s | 32 ++-- asm/MetroidPrime/CSaveGameScreen.s | 2 +- include/Kyoto/CMemoryCardSys.hpp | 5 + include/MetroidPrime/CArchitectureMessage.hpp | 1 + include/rstl/construct.hpp | 2 +- src/MetroidPrime/CMemoryCardDriver.cpp | 158 ++++++++++++++++-- 7 files changed, 175 insertions(+), 37 deletions(-) diff --git a/asm/Kyoto/DolphinCMemoryCardSys.s b/asm/Kyoto/DolphinCMemoryCardSys.s index 9c6874c7..331c7f29 100644 --- a/asm/Kyoto/DolphinCMemoryCardSys.s +++ b/asm/Kyoto/DolphinCMemoryCardSys.s @@ -597,8 +597,8 @@ lbl_8034DBF4: /* 8034DC0C 0034AB6C 38 21 00 20 */ addi r1, r1, 0x20 /* 8034DC10 0034AB70 4E 80 00 20 */ blr -.global PumpCardTransfer__13CCardFileInfoFv -PumpCardTransfer__13CCardFileInfoFv: +.global PumpCardTransfer__Q214CMemoryCardSys13CCardFileInfoFv +PumpCardTransfer__Q214CMemoryCardSys13CCardFileInfoFv: /* 8034DC14 0034AB74 94 21 FF 60 */ stwu r1, -0xa0(r1) /* 8034DC18 0034AB78 7C 08 02 A6 */ mflr r0 /* 8034DC1C 0034AB7C 90 01 00 A4 */ stw r0, 0xa4(r1) @@ -804,8 +804,8 @@ CheckCard__14CMemoryCardSysFv: /* 8034DED0 0034AE30 38 21 00 10 */ addi r1, r1, 0x10 /* 8034DED4 0034AE34 4E 80 00 20 */ blr -.global Rename__14CMemoryCardSysFiPCcPCc -Rename__14CMemoryCardSysFiPCcPCc: +.global "Rename__14CMemoryCardSysFQ214CMemoryCardSys15EMemoryCardPortRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RCQ24rstl66basic_string,Q24rstl17rmemory_allocator>" +"Rename__14CMemoryCardSysFQ214CMemoryCardSys15EMemoryCardPortRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RCQ24rstl66basic_string,Q24rstl17rmemory_allocator>": /* 8034DED8 0034AE38 94 21 FF F0 */ stwu r1, -0x10(r1) /* 8034DEDC 0034AE3C 7C 08 02 A6 */ mflr r0 /* 8034DEE0 0034AE40 38 C0 00 00 */ li r6, 0 @@ -818,8 +818,8 @@ Rename__14CMemoryCardSysFiPCcPCc: /* 8034DEFC 0034AE5C 38 21 00 10 */ addi r1, r1, 0x10 /* 8034DF00 0034AE60 4E 80 00 20 */ blr -.global Close__13CCardFileInfoFv -Close__13CCardFileInfoFv: +.global CloseFile__Q214CMemoryCardSys13CCardFileInfoFv +CloseFile__Q214CMemoryCardSys13CCardFileInfoFv: /* 8034DF04 0034AE64 94 21 FF F0 */ stwu r1, -0x10(r1) /* 8034DF08 0034AE68 7C 08 02 A6 */ mflr r0 /* 8034DF0C 0034AE6C 90 01 00 14 */ stw r0, 0x14(r1) diff --git a/asm/MetroidPrime/CMemoryCardDriver.s b/asm/MetroidPrime/CMemoryCardDriver.s index 6d2f8f95..06e1c43f 100644 --- a/asm/MetroidPrime/CMemoryCardDriver.s +++ b/asm/MetroidPrime/CMemoryCardDriver.s @@ -1361,7 +1361,7 @@ lbl_8024D41C: StartFileDeleteAltTransactional__17CMemoryCardDriverFv: /* 8024D430 0024A390 94 21 FF E0 */ stwu r1, -0x20(r1) /* 8024D434 0024A394 7C 08 02 A6 */ mflr r0 -/* 8024D438 0024A398 38 82 B8 B0 */ addi r4, r2, lbl_805AD5D0@sda21 +/* 8024D438 0024A398 38 82 B8 B0 */ addi r4, r2, skSaveFileNames@sda21 /* 8024D43C 0024A39C 90 01 00 24 */ stw r0, 0x24(r1) /* 8024D440 0024A3A0 38 00 00 00 */ li r0, 0 /* 8024D444 0024A3A4 93 E1 00 1C */ stw r31, 0x1c(r1) @@ -1461,7 +1461,7 @@ lbl_8024D568: /* 8024D594 0024A4F4 7C 7E 1B 79 */ or. r30, r3, r3 /* 8024D598 0024A4F8 41 82 00 34 */ beq lbl_8024D5CC /* 8024D59C 0024A4FC 80 1F 01 94 */ lwz r0, 0x194(r31) -/* 8024D5A0 0024A500 38 82 B8 B0 */ addi r4, r2, lbl_805AD5D0@sda21 +/* 8024D5A0 0024A500 38 82 B8 B0 */ addi r4, r2, skSaveFileNames@sda21 /* 8024D5A4 0024A504 38 61 00 08 */ addi r3, r1, 8 /* 8024D5A8 0024A508 54 00 10 3A */ slwi r0, r0, 2 /* 8024D5AC 0024A50C 7C 84 00 2E */ lwzx r4, r4, r0 @@ -1695,7 +1695,7 @@ lbl_8024D898: /* 8024D8B8 0024A818 7C 7E 1B 79 */ or. r30, r3, r3 /* 8024D8BC 0024A81C 41 82 00 34 */ beq lbl_8024D8F0 /* 8024D8C0 0024A820 80 1F 01 94 */ lwz r0, 0x194(r31) -/* 8024D8C4 0024A824 38 82 B8 B0 */ addi r4, r2, lbl_805AD5D0@sda21 +/* 8024D8C4 0024A824 38 82 B8 B0 */ addi r4, r2, skSaveFileNames@sda21 /* 8024D8C8 0024A828 38 61 00 08 */ addi r3, r1, 8 /* 8024D8CC 0024A82C 54 00 10 3A */ slwi r0, r0, 2 /* 8024D8D0 0024A830 7C 84 00 2E */ lwzx r4, r4, r0 @@ -2243,7 +2243,7 @@ StartFileRenameBtoA__17CMemoryCardDriverFv: /* 8024DFFC 0024AF5C 38 60 00 00 */ li r3, 0 /* 8024E000 0024AF60 38 00 00 24 */ li r0, 0x24 /* 8024E004 0024AF64 90 7E 00 14 */ stw r3, 0x14(r30) -/* 8024E008 0024AF68 38 82 B8 B0 */ addi r4, r2, lbl_805AD5D0@sda21 +/* 8024E008 0024AF68 38 82 B8 B0 */ addi r4, r2, skSaveFileNames@sda21 /* 8024E00C 0024AF6C 38 61 00 18 */ addi r3, r1, 0x18 /* 8024E010 0024AF70 90 1E 00 10 */ stw r0, 0x10(r30) /* 8024E014 0024AF74 80 BE 01 94 */ lwz r5, 0x194(r30) @@ -2253,14 +2253,14 @@ StartFileRenameBtoA__17CMemoryCardDriverFv: /* 8024E024 0024AF84 54 BF D9 7E */ srwi r31, r5, 5 /* 8024E028 0024AF88 4B DB 6C 91 */ bl string_l__4rstlFPCc /* 8024E02C 0024AF8C 57 E0 10 3A */ slwi r0, r31, 2 -/* 8024E030 0024AF90 38 62 B8 B0 */ addi r3, r2, lbl_805AD5D0@sda21 +/* 8024E030 0024AF90 38 62 B8 B0 */ addi r3, r2, skSaveFileNames@sda21 /* 8024E034 0024AF94 7C 83 00 2E */ lwzx r4, r3, r0 /* 8024E038 0024AF98 38 61 00 08 */ addi r3, r1, 8 /* 8024E03C 0024AF9C 4B DB 6C 7D */ bl string_l__4rstlFPCc /* 8024E040 0024AFA0 80 7E 00 00 */ lwz r3, 0(r30) /* 8024E044 0024AFA4 38 81 00 18 */ addi r4, r1, 0x18 /* 8024E048 0024AFA8 38 A1 00 08 */ addi r5, r1, 8 -/* 8024E04C 0024AFAC 48 0F FE 8D */ bl Rename__14CMemoryCardSysFiPCcPCc +/* 8024E04C 0024AFAC 48 0F FE 8D */ bl "Rename__14CMemoryCardSysFQ214CMemoryCardSys15EMemoryCardPortRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RCQ24rstl66basic_string,Q24rstl17rmemory_allocator>" /* 8024E050 0024AFB0 7C 60 1B 78 */ mr r0, r3 /* 8024E054 0024AFB4 38 61 00 08 */ addi r3, r1, 8 /* 8024E058 0024AFB8 7C 1F 03 78 */ mr r31, r0 @@ -2315,13 +2315,13 @@ UpdateFileWriteTransactional__17CMemoryCardDriverF11ECardResult: /* 8024E0F4 0024B054 7C 7F 1B 78 */ mr r31, r3 /* 8024E0F8 0024B058 40 82 00 74 */ bne lbl_8024E16C /* 8024E0FC 0024B05C 80 7F 01 98 */ lwz r3, 0x198(r31) -/* 8024E100 0024B060 48 0F FB 15 */ bl PumpCardTransfer__13CCardFileInfoFv +/* 8024E100 0024B060 48 0F FB 15 */ bl PumpCardTransfer__Q214CMemoryCardSys13CCardFileInfoFv /* 8024E104 0024B064 2C 03 00 00 */ cmpwi r3, 0 /* 8024E108 0024B068 40 82 00 34 */ bne lbl_8024E13C /* 8024E10C 0024B06C 38 00 00 0A */ li r0, 0xa /* 8024E110 0024B070 90 1F 00 10 */ stw r0, 0x10(r31) /* 8024E114 0024B074 80 7F 01 98 */ lwz r3, 0x198(r31) -/* 8024E118 0024B078 48 0F FD ED */ bl Close__13CCardFileInfoFv +/* 8024E118 0024B078 48 0F FD ED */ bl CloseFile__Q214CMemoryCardSys13CCardFileInfoFv /* 8024E11C 0024B07C 2C 03 00 00 */ cmpwi r3, 0 /* 8024E120 0024B080 41 82 00 10 */ beq lbl_8024E130 /* 8024E124 0024B084 7F E3 FB 78 */ mr r3, r31 @@ -2385,13 +2385,13 @@ UpdateFileWrite__17CMemoryCardDriverF11ECardResult: /* 8024E1D8 0024B138 7C 7F 1B 78 */ mr r31, r3 /* 8024E1DC 0024B13C 40 82 00 68 */ bne lbl_8024E244 /* 8024E1E0 0024B140 80 7F 01 98 */ lwz r3, 0x198(r31) -/* 8024E1E4 0024B144 48 0F FA 31 */ bl PumpCardTransfer__13CCardFileInfoFv +/* 8024E1E4 0024B144 48 0F FA 31 */ bl PumpCardTransfer__Q214CMemoryCardSys13CCardFileInfoFv /* 8024E1E8 0024B148 2C 03 00 00 */ cmpwi r3, 0 /* 8024E1EC 0024B14C 40 82 00 28 */ bne lbl_8024E214 /* 8024E1F0 0024B150 38 00 00 01 */ li r0, 1 /* 8024E1F4 0024B154 90 1F 00 10 */ stw r0, 0x10(r31) /* 8024E1F8 0024B158 80 7F 01 98 */ lwz r3, 0x198(r31) -/* 8024E1FC 0024B15C 48 0F FD 09 */ bl Close__13CCardFileInfoFv +/* 8024E1FC 0024B15C 48 0F FD 09 */ bl CloseFile__Q214CMemoryCardSys13CCardFileInfoFv /* 8024E200 0024B160 2C 03 00 00 */ cmpwi r3, 0 /* 8024E204 0024B164 41 82 00 48 */ beq lbl_8024E24C /* 8024E208 0024B168 7F E3 FB 78 */ mr r3, r31 @@ -3160,8 +3160,8 @@ ClearFileInfo__17CMemoryCardDriverFv: /* 8024EC10 0024BB70 38 21 00 10 */ addi r1, r1, 0x10 /* 8024EC14 0024BB74 4E 80 00 20 */ blr -.global __ct__17CMemoryCardDriverF9ECardSlotUiUiUib -__ct__17CMemoryCardDriverF9ECardSlotUiUiUib: +.global __ct__17CMemoryCardDriverFQ214CMemoryCardSys15EMemoryCardPortUiUiUib +__ct__17CMemoryCardDriverFQ214CMemoryCardSys15EMemoryCardPortUiUiUib: /* 8024EC18 0024BB78 94 21 FF 30 */ stwu r1, -0xd0(r1) /* 8024EC1C 0024BB7C 7C 08 02 A6 */ mflr r0 /* 8024EC20 0024BB80 39 20 00 00 */ li r9, 0 @@ -3284,7 +3284,7 @@ lbl_8024EDB0: /* 8024EDB4 0024BD14 38 60 FF FF */ li r3, -1 /* 8024EDB8 0024BD18 90 BE 01 00 */ stw r5, 0x100(r30) /* 8024EDBC 0024BD1C 38 00 00 01 */ li r0, 1 -/* 8024EDC0 0024BD20 80 82 B8 B0 */ lwz r4, lbl_805AD5D0@sda21(r2) +/* 8024EDC0 0024BD20 80 82 B8 B0 */ lwz r4, skSaveFileNames@sda21(r2) /* 8024EDC4 0024BD24 90 7E 01 94 */ stw r3, 0x194(r30) /* 8024EDC8 0024BD28 38 61 00 20 */ addi r3, r1, 0x20 /* 8024EDCC 0024BD2C 90 BE 01 98 */ stw r5, 0x198(r30) @@ -3306,7 +3306,7 @@ lbl_8024EDB0: /* 8024EE0C 0024BD6C 4B FF FC 59 */ bl "__dt__Q24rstl29pairFv" /* 8024EE10 0024BD70 38 61 00 20 */ addi r3, r1, 0x20 /* 8024EE14 0024BD74 48 0E EC CD */ bl "internal_dereference__Q24rstl66basic_string,Q24rstl17rmemory_allocator>Fv" -/* 8024EE18 0024BD78 38 82 B8 B0 */ addi r4, r2, lbl_805AD5D0@sda21 +/* 8024EE18 0024BD78 38 82 B8 B0 */ addi r4, r2, skSaveFileNames@sda21 /* 8024EE1C 0024BD7C 38 61 00 10 */ addi r3, r1, 0x10 /* 8024EE20 0024BD80 80 84 00 04 */ lwz r4, 4(r4) /* 8024EE24 0024BD84 4B DB 5E 95 */ bl string_l__4rstlFPCc @@ -3557,8 +3557,8 @@ lbl_8024F164: .section .sdata2, "a" .balign 8 -.global lbl_805AD5D0 -lbl_805AD5D0: +.global skSaveFileNames +skSaveFileNames: # ROM: 0x3F9E70 .4byte lbl_803D47CC .4byte lbl_803D47DB diff --git a/asm/MetroidPrime/CSaveGameScreen.s b/asm/MetroidPrime/CSaveGameScreen.s index 2fa7f7e6..ffe9b735 100644 --- a/asm/MetroidPrime/CSaveGameScreen.s +++ b/asm/MetroidPrime/CSaveGameScreen.s @@ -1384,7 +1384,7 @@ ConstructCardDriver__15CSaveGameScreen: /* 80250354 0024D2B4 7F 88 E3 78 */ mr r8, r28 /* 80250358 0024D2B8 80 FE 00 04 */ lwz r7, 4(r30) /* 8025035C 0024D2BC 38 80 00 00 */ li r4, 0 -/* 80250360 0024D2C0 4B FF E8 B9 */ bl __ct__17CMemoryCardDriverF9ECardSlotUiUiUib +/* 80250360 0024D2C0 4B FF E8 B9 */ bl __ct__17CMemoryCardDriverFQ214CMemoryCardSys15EMemoryCardPortUiUiUib /* 80250364 0024D2C4 7C 7D 1B 78 */ mr r29, r3 lbl_80250368: /* 80250368 0024D2C8 80 01 00 24 */ lwz r0, 0x24(r1) diff --git a/include/Kyoto/CMemoryCardSys.hpp b/include/Kyoto/CMemoryCardSys.hpp index dd9554b6..eac3961a 100644 --- a/include/Kyoto/CMemoryCardSys.hpp +++ b/include/Kyoto/CMemoryCardSys.hpp @@ -46,6 +46,9 @@ public: public: ~CCardFileInfo(); + + ECardResult PumpCardTransfer(); + ECardResult CloseFile(); }; CMemoryCardSys(); @@ -54,6 +57,8 @@ public: static ECardResult GetResultCode(int); static ProbeResults IsMemoryCardInserted(EMemoryCardPort); static ECardResult GetSerialNo(EMemoryCardPort port, long long& serialOut); + static void UnmountCard(EMemoryCardPort); + static ECardResult Rename(EMemoryCardPort, const rstl::string&, const rstl::string&); void Initialize(); diff --git a/include/MetroidPrime/CArchitectureMessage.hpp b/include/MetroidPrime/CArchitectureMessage.hpp index c7155ee1..e6b52382 100644 --- a/include/MetroidPrime/CArchitectureMessage.hpp +++ b/include/MetroidPrime/CArchitectureMessage.hpp @@ -34,6 +34,7 @@ class CArchitectureMessage { public: EArchMsgType GetType() const { return x4_type; } + private: EArchMsgTarget x0_target; EArchMsgType x4_type; diff --git a/include/rstl/construct.hpp b/include/rstl/construct.hpp index 0db9a9c7..7e2e4760 100644 --- a/include/rstl/construct.hpp +++ b/include/rstl/construct.hpp @@ -41,7 +41,7 @@ inline void uninitialized_copy_n(S src, int n, D dest) { template < typename D, typename S > inline void uninitialized_fill_n(D dest, int n, const S& value) { D cur = dest; - for (size_t i = 0; i < n; ++i, ++cur) { + for (int i = 0; i < n; ++i, ++cur) { construct(&*cur, value); } } diff --git a/src/MetroidPrime/CMemoryCardDriver.cpp b/src/MetroidPrime/CMemoryCardDriver.cpp index b75098ec..799344ec 100644 --- a/src/MetroidPrime/CMemoryCardDriver.cpp +++ b/src/MetroidPrime/CMemoryCardDriver.cpp @@ -2,9 +2,20 @@ #include "MetroidPrime/CMain.hpp" -bool CMemoryCardDriver::IsCardBusy(EState) { return false; } +static bool lbl_805A9118; +static const char* const skSaveFileNames[2] = {"MetroidPrime A", "MetroidPrime B"}; -bool CMemoryCardDriver::IsCardWriting(EState) { return false; } +bool CMemoryCardDriver::IsCardBusy(EState v) { return v >= kS_CardMount && v <= kS_CardFormat; } + +bool CMemoryCardDriver::IsCardWriting(EState v) { + if (v < kS_CardProbe) + return false; + if (v == kS_CardCheck) + return false; + if (v == kS_FileRead) + return false; + return true; +} CMemoryCardDriver::CMemoryCardDriver(CMemoryCardSys::EMemoryCardPort cardPort, CAssetId saveBanner, CAssetId saveIcon0, CAssetId saveIcon1, bool importPersistent) @@ -18,7 +29,6 @@ CMemoryCardDriver::CMemoryCardDriver(CMemoryCardSys::EMemoryCardPort cardPort, C , x1c_cardFreeFiles(0) , x20_fileTime(0) , x28_cardSerial(0) - , x30_systemData(0) , xe4_fileSlots(nullptr) , x100_mcFileInfos() @@ -26,6 +36,7 @@ CMemoryCardDriver::CMemoryCardDriver(CMemoryCardSys::EMemoryCardPort cardPort, C , x198_fileInfo(nullptr) , x19c_(false) , x19d_importPersistent(importPersistent) { + lbl_805A9118 = true; x100_mcFileInfos.push_back(rstl::pair< EFileState, SMemoryCardFileInfo >( kFS_Unknown, SMemoryCardFileInfo(x0_cardPort, rstl::string_l("MetroidPrime A")))); x100_mcFileInfos.push_back(rstl::pair< EFileState, SMemoryCardFileInfo >( @@ -34,7 +45,11 @@ CMemoryCardDriver::CMemoryCardDriver(CMemoryCardSys::EMemoryCardPort cardPort, C void CMemoryCardDriver::ClearFileInfo() { x198_fileInfo = nullptr; } -CMemoryCardDriver::~CMemoryCardDriver() {} +CMemoryCardDriver::~CMemoryCardDriver() { + CMemoryCardSys::UnmountCard(x0_cardPort); + lbl_805A9118 = false; + gpMain->SetCardBusy(false); +} void CMemoryCardDriver::Update() { ProbeResults result = CMemoryCardSys::IsMemoryCardInserted(x0_cardPort); @@ -59,6 +74,8 @@ void CMemoryCardDriver::Update() { cardBusy = true; switch (x10_state) { + case kS_CardProbe: + break; case kS_CardMount: UpdateMountCard(resultCode); break; @@ -105,6 +122,8 @@ void CMemoryCardDriver::Update() { void CMemoryCardDriver::HandleCardError(ECardResult result, EState state) { switch (result) { + case kCR_BUSY: + break; case kCR_WRONGDEVICE: x10_state = state; x14_error = kE_CardWrongDevice; @@ -162,7 +181,12 @@ void CMemoryCardDriver::UpdateFileRead(ECardResult result) { return; } - int altFileIdx = !bool(x194_fileIdx); + int altFileIdx; + if (x194_fileIdx == 0) { + altFileIdx = 1; + } else { + altFileIdx = 0; + } if (readRes == kCR_READY) { x10_state = kS_Ready; ReadFinished(); @@ -190,21 +214,129 @@ void CMemoryCardDriver::UpdateFileRead(ECardResult result) { } } -void CMemoryCardDriver::UpdateFileDeleteAlt(ECardResult) {} +void CMemoryCardDriver::UpdateFileDeleteAlt(ECardResult result) { + if (result == kCR_READY) { + x10_state = kS_Ready; + if (GetCardFreeBytes()) { + CheckCardCapacity(); + } + } else { + HandleCardError(result, kS_FileDeleteAltFailed); + } +} -void CMemoryCardDriver::UpdateFileDeleteBad(ECardResult) {} +void CMemoryCardDriver::UpdateFileDeleteBad(ECardResult result) { + if (result == kCR_READY) { + x100_mcFileInfos[x194_fileIdx].first = kFS_NoFile; + if (x100_mcFileInfos[x194_fileIdx ? 0 : 1].first == kFS_BadFile) { + x10_state = kS_FileBad; + StartFileDeleteBad(); + } else { + x10_state = kS_CardCheckDone; + if (!GetCardFreeBytes()) { + return; + } + IndexFiles(); + } + } else { + HandleCardError(result, kS_FileDeleteBadFailed); + } +} -void CMemoryCardDriver::UpdateFileCreate(ECardResult) {} +void CMemoryCardDriver::UpdateFileCreate(ECardResult result) { + if (result == kCR_READY) { + x10_state = kS_FileCreateDone; + StartFileWrite(); + } else { + HandleCardError(result, kS_FileCreateFailed); + } +} -void CMemoryCardDriver::UpdateFileWrite(ECardResult) {} +void CMemoryCardDriver::UpdateFileWrite(ECardResult result) { + if (result == kCR_READY) { + ECardResult xferResult = x198_fileInfo->PumpCardTransfer(); + if (xferResult == kCR_READY) { + x10_state = kS_Ready; + if (x198_fileInfo->CloseFile() != kCR_READY) { + NoCardFound(); + } + return; + } + if (xferResult == kCR_BUSY) { + return; + } + if (xferResult == kCR_IOERROR) { + x10_state = kS_FileWriteFailed; + x14_error = kE_CardIOError; + return; + } + NoCardFound(); + } else { + HandleCardError(result, kS_FileWriteFailed); + } +} -void CMemoryCardDriver::UpdateFileCreateTransactional(ECardResult) {} +void CMemoryCardDriver::UpdateFileCreateTransactional(ECardResult result) { + if (result == kCR_READY) { + x10_state = kS_FileCreateTransactionalDone; + StartFileWriteTransactional(); + } else { + HandleCardError(result, kS_FileCreateTransactionalFailed); + } +} -void CMemoryCardDriver::UpdateFileWriteTransactional(ECardResult) {} +void CMemoryCardDriver::UpdateFileWriteTransactional(ECardResult result) { + if (result == kCR_READY) { + ECardResult xferResult = x198_fileInfo->PumpCardTransfer(); + if (xferResult == kCR_READY) { + x10_state = kS_FileWriteTransactionalDone; + if (x198_fileInfo->CloseFile() != kCR_READY) { + NoCardFound(); + } else { + StartFileDeleteAltTransactional(); + } + return; + } + if (xferResult == kCR_BUSY) { + return; + } + if (xferResult == kCR_IOERROR) { + x10_state = kS_FileWriteTransactionalFailed; + x14_error = kE_CardIOError; + return; + } + NoCardFound(); + } else { + HandleCardError(result, kS_FileWriteTransactionalFailed); + } +} -void CMemoryCardDriver::UpdateFileRenameBtoA(ECardResult) {} +void CMemoryCardDriver::UpdateFileRenameBtoA(ECardResult result) { + if (result == kCR_READY) { + x10_state = kS_DriverClosed; + WriteBackupBuf(); + } else { + HandleCardError(result, kS_FileRenameBtoAFailed); + } +} -void CMemoryCardDriver::StartFileRenameBtoA() {} +void CMemoryCardDriver::StartFileRenameBtoA() { + if (x194_fileIdx == 1) { + /* Rename B file to A file (ideally the card is always left with 'A' only) */ + x14_error = kE_OK; + x10_state = kS_FileRenameBtoA; + int bidx = x194_fileIdx == 0 ? 1 : 0; + ECardResult result = + CMemoryCardSys::Rename(x0_cardPort, rstl::string_l(skSaveFileNames[x194_fileIdx]), + rstl::string_l(skSaveFileNames[bidx])); + if (result != kCR_READY) { + UpdateFileRenameBtoA(result); + } + } else { + x10_state = kS_DriverClosed; + WriteBackupBuf(); + } +} void CMemoryCardDriver::WriteBackupBuf() {}