diff --git a/asm/MetroidPrime/CMemoryCardDriver.s b/asm/MetroidPrime/CMemoryCardDriver.s index 73c223d7..90c142fb 100644 --- a/asm/MetroidPrime/CMemoryCardDriver.s +++ b/asm/MetroidPrime/CMemoryCardDriver.s @@ -3178,8 +3178,8 @@ ClearFileInfo__17CMemoryCardDriverFv: /* 8024EC10 0024BB70 38 21 00 10 */ addi r1, r1, 0x10 /* 8024EC14 0024BB74 4E 80 00 20 */ blr -.global __ct__17CMemoryCardDriverFv -__ct__17CMemoryCardDriverFv: +.global __ct__17CMemoryCardDriverF9ECardSlotUiUiUib +__ct__17CMemoryCardDriverF9ECardSlotUiUiUib: /* 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 @@ -3686,4 +3686,3 @@ lbl_803D47DB: .4byte 0x3F3F2900 .asciz "%02d.%02d.%02d %02d:%02d" .balign 4 - diff --git a/asm/MetroidPrime/CSaveGameScreen.s b/asm/MetroidPrime/CSaveGameScreen.s index 82f14fe5..2fa7f7e6 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__17CMemoryCardDriverFv +/* 80250360 0024D2C0 4B FF E8 B9 */ bl __ct__17CMemoryCardDriverF9ECardSlotUiUiUib /* 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/MetroidPrime/CMemoryCardDriver.hpp b/include/MetroidPrime/CMemoryCardDriver.hpp index 108276fc..ae27a410 100644 --- a/include/MetroidPrime/CMemoryCardDriver.hpp +++ b/include/MetroidPrime/CMemoryCardDriver.hpp @@ -7,9 +7,34 @@ #include "rstl/auto_ptr.hpp" #include "rstl/pair.hpp" +#include "rstl/reserved_vector.hpp" #include "rstl/single_ptr.hpp" #include "rstl/vector.hpp" +struct SMemoryCardFileInfo { + CMemoryCardSys::CardFileHandle x0_fileInfo; + + rstl::string x14_name; + rstl::vector< u8 > x24_saveFileData; + rstl::vector< u8 > x34_saveData; + + SMemoryCardFileInfo(int cardPort, const rstl::string& name); + SMemoryCardFileInfo(const SMemoryCardFileInfo& other) + : x0_fileInfo(other.x0_fileInfo) + , x14_name(other.x14_name) + , x24_saveFileData(other.x24_saveFileData) + , x34_saveData(other.x34_saveData) + {} + + ECardResult Open(); + ECardResult Close(); + int GetFileCardPort() const { return x0_fileInfo.slot; } + int GetFileNo() const { return x0_fileInfo.getFileNo(); } + ECardResult StartRead(); + ECardResult TryFileRead(); + ECardResult FileRead(); + ECardResult GetSaveDataOffset(u32& offOut) const; +}; class CMemoryCardDriver { public: @@ -66,26 +91,9 @@ public: kE_FileMissing, kE_FileCorrupted }; + enum EFileState { kFS_Unknown, kFS_NoFile, kFS_File, kFS_BadFile }; private: - struct SFileInfo { - CMemoryCardSys::CardFileHandle x0_fileInfo; - - rstl::string x14_name; - rstl::vector< u8 > x24_saveFileData; - rstl::vector< u8 > x34_saveData; - // SFileInfo(kabufuda::ECardSlot cardPort, std::string_view name); - - ECardResult Open(); - ECardResult Close(); - ECardSlot GetFileCardPort() const { return x0_fileInfo.slot; } - int GetFileNo() const { return x0_fileInfo.getFileNo(); } - ECardResult StartRead(); - ECardResult TryFileRead(); - ECardResult FileRead(); - ECardResult GetSaveDataOffset(u32& offOut) const; - }; - struct SGameFileSlot { u8 x0_saveBuffer[940]; CGameState::GameFileStateInfo x944_fileInfo; @@ -97,7 +105,6 @@ private: // void DoPut(CMemoryStreamOut& w) const { w.Put(x0_saveBuffer.data(), x0_saveBuffer.size()); } }; - enum EFileState { kFS_Unknown, kFS_NoFile, kFS_File, kFS_BadFile }; ECardSlot x0_cardPort; CAssetId x4_saveBanner; @@ -105,13 +112,13 @@ private: CAssetId xc_saveIcon1; EState x10_state; EError x14_error; - s32 x18_cardFreeBytes; - s32 x1c_cardFreeFiles; - u32 x20_fileTime; + int x18_cardFreeBytes; + int x1c_cardFreeFiles; + uint x20_fileTime; u64 x28_cardSerial; - u8 x30_systemData[174]; - rstl::auto_ptr< SGameFileSlot > xe4_fileSlots[3]; - rstl::vector< rstl::pair< EFileState, SFileInfo > > x100_mcFileInfos; + rstl::reserved_vector< u8, 174 > x30_systemData; + rstl::reserved_vector< rstl::auto_ptr< SGameFileSlot >, 3 > xe4_fileSlots; + rstl::reserved_vector< rstl::pair< EFileState, SMemoryCardFileInfo >, 2 > x100_mcFileInfos; u32 x194_fileIdx; rstl::single_ptr< CMemoryCardSys::CCardFileInfo > x198_fileInfo; bool x19c_; @@ -120,7 +127,8 @@ private: public: static bool IsCardBusy(EState); static bool IsCardWriting(EState); - CMemoryCardDriver(); + CMemoryCardDriver(ECardSlot cardPort, CAssetId saveBanner, CAssetId saveIcon0, CAssetId saveIcon1, + bool importPersistent); void ClearFileInfo(); ~CMemoryCardDriver(); void Update(); diff --git a/include/rstl/auto_ptr.hpp b/include/rstl/auto_ptr.hpp index 198a3cd6..d3a70ddd 100644 --- a/include/rstl/auto_ptr.hpp +++ b/include/rstl/auto_ptr.hpp @@ -18,9 +18,9 @@ public: } } // TODO check - // auto_ptr(const auto_ptr& other) : x0_has(other.x0_has), x4_item(other.x4_item) { - // other.x0_has = false; - // } + auto_ptr(const auto_ptr& other) : x0_has(other.x0_has), x4_item(other.x4_item) { + other.x0_has = false; + } // TODO check auto_ptr& operator=(const auto_ptr& other) { if (this != &other) { @@ -29,7 +29,7 @@ public: } x0_has = other.x0_has; x4_item = other.x4_item; - const_cast< auto_ptr& >(other).x0_has = false; + other.x0_has = false; } return *this; } diff --git a/include/rstl/pair.hpp b/include/rstl/pair.hpp index ddfda070..44187ff2 100644 --- a/include/rstl/pair.hpp +++ b/include/rstl/pair.hpp @@ -10,6 +10,12 @@ public: inline pair() {} inline pair(const L& first, const R& second) : first(first), second(second) {} + inline pair& operator=(const pair& other) { + first = other.first; + second = other.second; + return *this; + } + L first; R second; }; diff --git a/src/MetroidPrime/CMemoryCardDriver.cpp b/src/MetroidPrime/CMemoryCardDriver.cpp index 622ebe31..291b9c6d 100644 --- a/src/MetroidPrime/CMemoryCardDriver.cpp +++ b/src/MetroidPrime/CMemoryCardDriver.cpp @@ -4,7 +4,36 @@ bool CMemoryCardDriver::IsCardBusy(EState) { return false; } bool CMemoryCardDriver::IsCardWriting(EState) { return false; } -CMemoryCardDriver::CMemoryCardDriver() {} +CMemoryCardDriver::CMemoryCardDriver(ECardSlot cardPort, CAssetId saveBanner, CAssetId saveIcon0, CAssetId saveIcon1, + bool importPersistent) + : x0_cardPort(cardPort) + , x4_saveBanner(saveBanner) + , x8_saveIcon0(saveIcon0) + , xc_saveIcon1(saveIcon1) + , x10_state(kS_Initial) + , x14_error(kE_OK) + , x18_cardFreeBytes(0) + , x1c_cardFreeFiles(0) + , x20_fileTime(0) + , x28_cardSerial(0) + + , x30_systemData(0) + , xe4_fileSlots(nullptr) + , x100_mcFileInfos() + , x194_fileIdx(-1) + , x198_fileInfo(nullptr) + , x19c_(false) + , x19d_importPersistent(importPersistent) +{ + 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 >( + kFS_Unknown, + SMemoryCardFileInfo(x0_cardPort, rstl::string_l("MetroidPrime B")) + )); +} void CMemoryCardDriver::ClearFileInfo() {}