Add CMemoryCardDriver::CMemoryCardDriver

Former-commit-id: 8d49e80502
This commit is contained in:
Henrique Gemignani Passos Lima 2022-10-11 00:46:32 +03:00
parent 2db05d2334
commit 077a16896f
6 changed files with 77 additions and 35 deletions

View File

@ -3178,8 +3178,8 @@ ClearFileInfo__17CMemoryCardDriverFv:
/* 8024EC10 0024BB70 38 21 00 10 */ addi r1, r1, 0x10 /* 8024EC10 0024BB70 38 21 00 10 */ addi r1, r1, 0x10
/* 8024EC14 0024BB74 4E 80 00 20 */ blr /* 8024EC14 0024BB74 4E 80 00 20 */ blr
.global __ct__17CMemoryCardDriverFv .global __ct__17CMemoryCardDriverF9ECardSlotUiUiUib
__ct__17CMemoryCardDriverFv: __ct__17CMemoryCardDriverF9ECardSlotUiUiUib:
/* 8024EC18 0024BB78 94 21 FF 30 */ stwu r1, -0xd0(r1) /* 8024EC18 0024BB78 94 21 FF 30 */ stwu r1, -0xd0(r1)
/* 8024EC1C 0024BB7C 7C 08 02 A6 */ mflr r0 /* 8024EC1C 0024BB7C 7C 08 02 A6 */ mflr r0
/* 8024EC20 0024BB80 39 20 00 00 */ li r9, 0 /* 8024EC20 0024BB80 39 20 00 00 */ li r9, 0
@ -3686,4 +3686,3 @@ lbl_803D47DB:
.4byte 0x3F3F2900 .4byte 0x3F3F2900
.asciz "%02d.%02d.%02d %02d:%02d" .asciz "%02d.%02d.%02d %02d:%02d"
.balign 4 .balign 4

View File

@ -1384,7 +1384,7 @@ ConstructCardDriver__15CSaveGameScreen:
/* 80250354 0024D2B4 7F 88 E3 78 */ mr r8, r28 /* 80250354 0024D2B4 7F 88 E3 78 */ mr r8, r28
/* 80250358 0024D2B8 80 FE 00 04 */ lwz r7, 4(r30) /* 80250358 0024D2B8 80 FE 00 04 */ lwz r7, 4(r30)
/* 8025035C 0024D2BC 38 80 00 00 */ li r4, 0 /* 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 /* 80250364 0024D2C4 7C 7D 1B 78 */ mr r29, r3
lbl_80250368: lbl_80250368:
/* 80250368 0024D2C8 80 01 00 24 */ lwz r0, 0x24(r1) /* 80250368 0024D2C8 80 01 00 24 */ lwz r0, 0x24(r1)

View File

@ -7,9 +7,34 @@
#include "rstl/auto_ptr.hpp" #include "rstl/auto_ptr.hpp"
#include "rstl/pair.hpp" #include "rstl/pair.hpp"
#include "rstl/reserved_vector.hpp"
#include "rstl/single_ptr.hpp" #include "rstl/single_ptr.hpp"
#include "rstl/vector.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 { class CMemoryCardDriver {
public: public:
@ -66,26 +91,9 @@ public:
kE_FileMissing, kE_FileMissing,
kE_FileCorrupted kE_FileCorrupted
}; };
enum EFileState { kFS_Unknown, kFS_NoFile, kFS_File, kFS_BadFile };
private: 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 { struct SGameFileSlot {
u8 x0_saveBuffer[940]; u8 x0_saveBuffer[940];
CGameState::GameFileStateInfo x944_fileInfo; CGameState::GameFileStateInfo x944_fileInfo;
@ -97,7 +105,6 @@ private:
// void DoPut(CMemoryStreamOut& w) const { w.Put(x0_saveBuffer.data(), x0_saveBuffer.size()); } // 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; ECardSlot x0_cardPort;
CAssetId x4_saveBanner; CAssetId x4_saveBanner;
@ -105,13 +112,13 @@ private:
CAssetId xc_saveIcon1; CAssetId xc_saveIcon1;
EState x10_state; EState x10_state;
EError x14_error; EError x14_error;
s32 x18_cardFreeBytes; int x18_cardFreeBytes;
s32 x1c_cardFreeFiles; int x1c_cardFreeFiles;
u32 x20_fileTime; uint x20_fileTime;
u64 x28_cardSerial; u64 x28_cardSerial;
u8 x30_systemData[174]; rstl::reserved_vector< u8, 174 > x30_systemData;
rstl::auto_ptr< SGameFileSlot > xe4_fileSlots[3]; rstl::reserved_vector< rstl::auto_ptr< SGameFileSlot >, 3 > xe4_fileSlots;
rstl::vector< rstl::pair< EFileState, SFileInfo > > x100_mcFileInfos; rstl::reserved_vector< rstl::pair< EFileState, SMemoryCardFileInfo >, 2 > x100_mcFileInfos;
u32 x194_fileIdx; u32 x194_fileIdx;
rstl::single_ptr< CMemoryCardSys::CCardFileInfo > x198_fileInfo; rstl::single_ptr< CMemoryCardSys::CCardFileInfo > x198_fileInfo;
bool x19c_; bool x19c_;
@ -120,7 +127,8 @@ private:
public: public:
static bool IsCardBusy(EState); static bool IsCardBusy(EState);
static bool IsCardWriting(EState); static bool IsCardWriting(EState);
CMemoryCardDriver(); CMemoryCardDriver(ECardSlot cardPort, CAssetId saveBanner, CAssetId saveIcon0, CAssetId saveIcon1,
bool importPersistent);
void ClearFileInfo(); void ClearFileInfo();
~CMemoryCardDriver(); ~CMemoryCardDriver();
void Update(); void Update();

View File

@ -18,9 +18,9 @@ public:
} }
} }
// TODO check // TODO check
// auto_ptr(const auto_ptr& other) : x0_has(other.x0_has), x4_item(other.x4_item) { auto_ptr(const auto_ptr& other) : x0_has(other.x0_has), x4_item(other.x4_item) {
// other.x0_has = false; other.x0_has = false;
// } }
// TODO check // TODO check
auto_ptr& operator=(const auto_ptr& other) { auto_ptr& operator=(const auto_ptr& other) {
if (this != &other) { if (this != &other) {
@ -29,7 +29,7 @@ public:
} }
x0_has = other.x0_has; x0_has = other.x0_has;
x4_item = other.x4_item; x4_item = other.x4_item;
const_cast< auto_ptr& >(other).x0_has = false; other.x0_has = false;
} }
return *this; return *this;
} }

View File

@ -10,6 +10,12 @@ public:
inline pair() {} inline pair() {}
inline pair(const L& first, const R& second) : first(first), second(second) {} 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; L first;
R second; R second;
}; };

View File

@ -4,7 +4,36 @@ bool CMemoryCardDriver::IsCardBusy(EState) { return false; }
bool CMemoryCardDriver::IsCardWriting(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() {} void CMemoryCardDriver::ClearFileInfo() {}