Match CMemoryCardDriver::IndexFiles

This commit is contained in:
Henrique Gemignani Passos Lima 2022-10-11 14:37:01 +03:00
parent 89c215ba4e
commit c3fd91f641
No known key found for this signature in database
GPG Key ID: E224F951761145F8
5 changed files with 120 additions and 35 deletions

View File

@ -306,8 +306,8 @@ SetStatus__14CMemoryCardSysFiiPC8CARDStat:
/* 8034D828 0034A788 38 21 00 10 */ addi r1, r1, 0x10
/* 8034D82C 0034A78C 4E 80 00 20 */ blr
.global GetStatus__14CMemoryCardSysFiiP8CARDStat
GetStatus__14CMemoryCardSysFiiP8CARDStat:
.global GetStatus__14CMemoryCardSysFQ214CMemoryCardSys15EMemoryCardPortiR8CardStat
GetStatus__14CMemoryCardSysFQ214CMemoryCardSys15EMemoryCardPortiR8CardStat:
/* 8034D830 0034A790 94 21 FF 80 */ stwu r1, -0x80(r1)
/* 8034D834 0034A794 7C 08 02 A6 */ mflr r0
/* 8034D838 0034A798 90 01 00 84 */ stw r0, 0x84(r1)
@ -379,13 +379,13 @@ StartRead__19SMemoryCardFileInfoFv:
/* 8034D910 0034A870 38 61 00 28 */ addi r3, r1, 0x28
/* 8034D914 0034A874 4B CB 5A 95 */ bl memset
/* 8034D918 0034A878 7F C3 F3 78 */ mr r3, r30
/* 8034D91C 0034A87C 48 00 11 89 */ bl GetFileNo__19SMemoryCardFileInfoFv
/* 8034D91C 0034A87C 48 00 11 89 */ bl GetFileNo__19SMemoryCardFileInfoCFv
/* 8034D920 0034A880 7C 7F 1B 78 */ mr r31, r3
/* 8034D924 0034A884 7F C3 F3 78 */ mr r3, r30
/* 8034D928 0034A888 48 00 11 85 */ bl GetFileCardPort__19SMemoryCardFileInfoFv
/* 8034D92C 0034A88C 7F E4 FB 78 */ mr r4, r31
/* 8034D930 0034A890 38 A1 00 28 */ addi r5, r1, 0x28
/* 8034D934 0034A894 4B FF FE FD */ bl GetStatus__14CMemoryCardSysFiiP8CARDStat
/* 8034D934 0034A894 4B FF FE FD */ bl GetStatus__14CMemoryCardSysFQ214CMemoryCardSys15EMemoryCardPortiR8CardStat
/* 8034D938 0034A898 2C 03 00 00 */ cmpwi r3, 0
/* 8034D93C 0034A89C 41 82 00 08 */ beq lbl_8034D944
/* 8034D940 0034A8A0 48 00 00 90 */ b lbl_8034D9D0
@ -522,7 +522,7 @@ GetStatus__13CCardFileInfoFP8CARDStat:
/* 8034DB04 0034AA64 48 00 0F 99 */ bl GetCardPort__13CCardFileInfoFv
/* 8034DB08 0034AA68 7F E4 FB 78 */ mr r4, r31
/* 8034DB0C 0034AA6C 7F A5 EB 78 */ mr r5, r29
/* 8034DB10 0034AA70 4B FF FD 21 */ bl GetStatus__14CMemoryCardSysFiiP8CARDStat
/* 8034DB10 0034AA70 4B FF FD 21 */ bl GetStatus__14CMemoryCardSysFQ214CMemoryCardSys15EMemoryCardPortiR8CardStat
/* 8034DB14 0034AA74 2C 03 00 00 */ cmpwi r3, 0
/* 8034DB18 0034AA78 41 82 00 08 */ beq lbl_8034DB20
/* 8034DB1C 0034AA7C 48 00 00 D8 */ b lbl_8034DBF4
@ -908,8 +908,8 @@ DeleteFile__14CMemoryCardSysFiPCc:
/* 8034E028 0034AF88 38 21 00 10 */ addi r1, r1, 0x10
/* 8034E02C 0034AF8C 4E 80 00 20 */ blr
.global "OpenFile__14CMemoryCardSysFQ214CMemoryCardSys15EMemoryCardPortRCQ24rstl66basic_string<c,Q24rstl14char_traits<c>,Q24rstl17rmemory_allocator>RQ214CMemoryCardSys13CCardFileInfo"
"OpenFile__14CMemoryCardSysFQ214CMemoryCardSys15EMemoryCardPortRCQ24rstl66basic_string<c,Q24rstl14char_traits<c>,Q24rstl17rmemory_allocator>RQ214CMemoryCardSys13CCardFileInfo":
.global "Open__19SMemoryCardFileInfoFv"
"Open__19SMemoryCardFileInfoFv":
/* 8034E030 0034AF90 94 21 FF F0 */ stwu r1, -0x10(r1)
/* 8034E034 0034AF94 7C 08 02 A6 */ mflr r0
/* 8034E038 0034AF98 90 01 00 14 */ stw r0, 0x14(r1)
@ -1319,8 +1319,8 @@ SetBannerFormat__8CARDStatFi:
/* 8034E594 0034B4F4 98 03 00 2E */ stb r0, 0x2e(r3)
/* 8034E598 0034B4F8 4E 80 00 20 */ blr
.global GetCommentAddr__8CARDStatFv
GetCommentAddr__8CARDStatFv:
.global GetCommentAddr__8CardStatCFv
GetCommentAddr__8CardStatCFv:
/* 8034E59C 0034B4FC 80 63 00 38 */ lwz r3, 0x38(r3)
/* 8034E5A0 0034B500 4E 80 00 20 */ blr
@ -1338,8 +1338,8 @@ GetBannerFormat__8CARDStatFv:
/* 8034E5BC 0034B51C 54 03 07 BE */ clrlwi r3, r0, 0x1e
/* 8034E5C0 0034B520 4E 80 00 20 */ blr
.global GetTime__8CARDStatFv
GetTime__8CARDStatFv:
.global GetTime__8CardStatCFv
GetTime__8CardStatCFv:
/* 8034E5C4 0034B524 80 63 00 24 */ lwz r3, 0x24(r3)
/* 8034E5C8 0034B528 4E 80 00 20 */ blr
@ -1621,13 +1621,13 @@ GetSaveDataOffset__19SMemoryCardFileInfoFRPv:
/* 8034E984 0034B8E4 38 61 00 08 */ addi r3, r1, 8
/* 8034E988 0034B8E8 4B CB 4A 21 */ bl memset
/* 8034E98C 0034B8EC 7F A3 EB 78 */ mr r3, r29
/* 8034E990 0034B8F0 48 00 01 15 */ bl GetFileNo__19SMemoryCardFileInfoFv
/* 8034E990 0034B8F0 48 00 01 15 */ bl GetFileNo__19SMemoryCardFileInfoCFv
/* 8034E994 0034B8F4 7C 7E 1B 78 */ mr r30, r3
/* 8034E998 0034B8F8 7F A3 EB 78 */ mr r3, r29
/* 8034E99C 0034B8FC 48 00 01 11 */ bl GetFileCardPort__19SMemoryCardFileInfoFv
/* 8034E9A0 0034B900 7F C4 F3 78 */ mr r4, r30
/* 8034E9A4 0034B904 38 A1 00 08 */ addi r5, r1, 8
/* 8034E9A8 0034B908 4B FF EE 89 */ bl GetStatus__14CMemoryCardSysFiiP8CARDStat
/* 8034E9A8 0034B908 4B FF EE 89 */ bl GetStatus__14CMemoryCardSysFQ214CMemoryCardSys15EMemoryCardPortiR8CardStat
/* 8034E9AC 0034B90C 2C 03 00 00 */ cmpwi r3, 0
/* 8034E9B0 0034B910 41 82 00 10 */ beq lbl_8034E9C0
/* 8034E9B4 0034B914 38 00 FF FF */ li r0, -1
@ -1706,8 +1706,8 @@ GetCardPort__13CCardFileInfoFv:
/* 8034EA9C 0034B9FC 80 63 00 04 */ lwz r3, 4(r3)
/* 8034EAA0 0034BA00 4E 80 00 20 */ blr
.global GetFileNo__19SMemoryCardFileInfoFv
GetFileNo__19SMemoryCardFileInfoFv:
.global GetFileNo__19SMemoryCardFileInfoCFv
GetFileNo__19SMemoryCardFileInfoCFv:
/* 8034EAA4 0034BA04 80 63 00 04 */ lwz r3, 4(r3)
/* 8034EAA8 0034BA08 4E 80 00 20 */ blr

View File

@ -944,11 +944,11 @@ ReadFinished__17CMemoryCardDriverFv:
/* 8024CE58 00249DB8 3B A6 01 08 */ addi r29, r6, 0x108
/* 8024CE5C 00249DBC 4B DB 65 4D */ bl memset
/* 8024CE60 00249DC0 7F A3 EB 78 */ mr r3, r29
/* 8024CE64 00249DC4 48 10 1C 41 */ bl GetFileNo__19SMemoryCardFileInfoFv
/* 8024CE64 00249DC4 48 10 1C 41 */ bl GetFileNo__19SMemoryCardFileInfoCFv
/* 8024CE68 00249DC8 7C 64 1B 78 */ mr r4, r3
/* 8024CE6C 00249DCC 80 7C 00 00 */ lwz r3, 0(r28)
/* 8024CE70 00249DD0 38 A1 00 44 */ addi r5, r1, 0x44
/* 8024CE74 00249DD4 48 10 09 BD */ bl GetStatus__14CMemoryCardSysFiiP8CARDStat
/* 8024CE74 00249DD4 48 10 09 BD */ bl GetStatus__14CMemoryCardSysFQ214CMemoryCardSys15EMemoryCardPortiR8CardStat
/* 8024CE78 00249DD8 2C 03 00 00 */ cmpwi r3, 0
/* 8024CE7C 00249DDC 41 82 00 10 */ beq lbl_8024CE8C
/* 8024CE80 00249DE0 7F 83 E3 78 */ mr r3, r28
@ -956,7 +956,7 @@ ReadFinished__17CMemoryCardDriverFv:
/* 8024CE88 00249DE8 48 00 03 08 */ b lbl_8024D190
lbl_8024CE8C:
/* 8024CE8C 00249DEC 38 61 00 44 */ addi r3, r1, 0x44
/* 8024CE90 00249DF0 48 10 17 35 */ bl GetTime__8CARDStatFv
/* 8024CE90 00249DF0 48 10 17 35 */ bl GetTime__8CardStatCFv
/* 8024CE94 00249DF4 90 7C 00 20 */ stw r3, 0x20(r28)
/* 8024CE98 00249DF8 38 61 00 20 */ addi r3, r1, 0x20
/* 8024CE9C 00249DFC 38 A0 0B BC */ li r5, 0xbbc
@ -1749,7 +1749,7 @@ StartFileRead__17CMemoryCardDriverFv:
/* 8024D978 0024A8D8 1C 00 00 48 */ mulli r0, r0, 0x48
/* 8024D97C 0024A8DC 7C 7F 02 14 */ add r3, r31, r0
/* 8024D980 0024A8E0 38 63 00 04 */ addi r3, r3, 4
/* 8024D984 0024A8E4 48 10 06 AD */ bl "OpenFile__14CMemoryCardSysFQ214CMemoryCardSys15EMemoryCardPortRCQ24rstl66basic_string<c,Q24rstl14char_traits<c>,Q24rstl17rmemory_allocator>RQ214CMemoryCardSys13CCardFileInfo"
/* 8024D984 0024A8E4 48 10 06 AD */ bl "Open__19SMemoryCardFileInfoFv"
/* 8024D988 0024A8E8 7C 64 1B 79 */ or. r4, r3, r3
/* 8024D98C 0024A8EC 41 82 00 10 */ beq lbl_8024D99C
/* 8024D990 0024A8F0 7F C3 F3 78 */ mr r3, r30
@ -1790,7 +1790,7 @@ StartFileDeleteAlt__17CMemoryCardDriverFv:
/* 8024DA08 0024A968 1C 00 00 48 */ mulli r0, r0, 0x48
/* 8024DA0C 0024A96C 7C 7F 02 14 */ add r3, r31, r0
/* 8024DA10 0024A970 38 63 01 08 */ addi r3, r3, 0x108
/* 8024DA14 0024A974 48 10 10 91 */ bl GetFileNo__19SMemoryCardFileInfoFv
/* 8024DA14 0024A974 48 10 10 91 */ bl GetFileNo__19SMemoryCardFileInfoCFv
/* 8024DA18 0024A978 7C 64 1B 78 */ mr r4, r3
/* 8024DA1C 0024A97C 80 7F 00 00 */ lwz r3, 0(r31)
/* 8024DA20 0024A980 48 10 05 6D */ bl FastDeleteFile__14CMemoryCardSysFii
@ -1826,7 +1826,7 @@ lbl_8024DA7C:
/* 8024DA84 0024A9E4 40 82 00 30 */ bne lbl_8024DAB4
/* 8024DA88 0024A9E8 90 7F 01 94 */ stw r3, 0x194(r31)
/* 8024DA8C 0024A9EC 38 64 00 04 */ addi r3, r4, 4
/* 8024DA90 0024A9F0 48 10 10 15 */ bl GetFileNo__19SMemoryCardFileInfoFv
/* 8024DA90 0024A9F0 48 10 10 15 */ bl GetFileNo__19SMemoryCardFileInfoCFv
/* 8024DA94 0024A9F4 7C 64 1B 78 */ mr r4, r3
/* 8024DA98 0024A9F8 80 7F 00 00 */ lwz r3, 0(r31)
/* 8024DA9C 0024A9FC 48 10 04 F1 */ bl FastDeleteFile__14CMemoryCardSysFii
@ -1866,7 +1866,7 @@ lbl_8024DB08:
/* 8024DB0C 0024AA6C 2C 00 00 00 */ cmpwi r0, 0
/* 8024DB10 0024AA70 40 82 00 B4 */ bne lbl_8024DBC4
/* 8024DB14 0024AA74 38 7E 00 04 */ addi r3, r30, 4
/* 8024DB18 0024AA78 48 10 05 19 */ bl "OpenFile__14CMemoryCardSysFQ214CMemoryCardSys15EMemoryCardPortRCQ24rstl66basic_string<c,Q24rstl14char_traits<c>,Q24rstl17rmemory_allocator>RQ214CMemoryCardSys13CCardFileInfo"
/* 8024DB18 0024AA78 48 10 05 19 */ bl "Open__19SMemoryCardFileInfoFv"
/* 8024DB1C 0024AA7C 2C 03 FF FC */ cmpwi r3, -4
/* 8024DB20 0024AA80 40 82 00 10 */ bne lbl_8024DB30
/* 8024DB24 0024AA84 38 00 00 01 */ li r0, 1
@ -1880,15 +1880,15 @@ lbl_8024DB30:
/* 8024DB40 0024AAA0 38 A0 00 6C */ li r5, 0x6c
/* 8024DB44 0024AAA4 4B DB 58 65 */ bl memset
/* 8024DB48 0024AAA8 38 7E 00 04 */ addi r3, r30, 4
/* 8024DB4C 0024AAAC 48 10 0F 59 */ bl GetFileNo__19SMemoryCardFileInfoFv
/* 8024DB4C 0024AAAC 48 10 0F 59 */ bl GetFileNo__19SMemoryCardFileInfoCFv
/* 8024DB50 0024AAB0 7C 64 1B 78 */ mr r4, r3
/* 8024DB54 0024AAB4 80 7F 00 00 */ lwz r3, 0(r31)
/* 8024DB58 0024AAB8 38 A1 00 74 */ addi r5, r1, 0x74
/* 8024DB5C 0024AABC 48 0F FC D5 */ bl GetStatus__14CMemoryCardSysFiiP8CARDStat
/* 8024DB5C 0024AABC 48 0F FC D5 */ bl GetStatus__14CMemoryCardSysFQ214CMemoryCardSys15EMemoryCardPortiR8CardStat
/* 8024DB60 0024AAC0 2C 03 00 00 */ cmpwi r3, 0
/* 8024DB64 0024AAC4 40 82 00 2C */ bne lbl_8024DB90
/* 8024DB68 0024AAC8 38 61 00 74 */ addi r3, r1, 0x74
/* 8024DB6C 0024AACC 48 10 0A 31 */ bl GetCommentAddr__8CARDStatFv
/* 8024DB6C 0024AACC 48 10 0A 31 */ bl GetCommentAddr__8CardStatCFv
/* 8024DB70 0024AAD0 2C 03 FF FF */ cmpwi r3, -1
/* 8024DB74 0024AAD4 40 82 00 10 */ bne lbl_8024DB84
/* 8024DB78 0024AAD8 38 00 00 03 */ li r0, 3
@ -1930,26 +1930,26 @@ lbl_8024DBC4:
/* 8024DBF4 0024AB54 38 A0 00 6C */ li r5, 0x6c
/* 8024DBF8 0024AB58 4B DB 57 B1 */ bl memset
/* 8024DBFC 0024AB5C 38 7D 00 04 */ addi r3, r29, 4
/* 8024DC00 0024AB60 48 10 0E A5 */ bl GetFileNo__19SMemoryCardFileInfoFv
/* 8024DC00 0024AB60 48 10 0E A5 */ bl GetFileNo__19SMemoryCardFileInfoCFv
/* 8024DC04 0024AB64 7C 64 1B 78 */ mr r4, r3
/* 8024DC08 0024AB68 80 7F 00 00 */ lwz r3, 0(r31)
/* 8024DC0C 0024AB6C 38 A1 00 08 */ addi r5, r1, 8
/* 8024DC10 0024AB70 48 0F FC 21 */ bl GetStatus__14CMemoryCardSysFiiP8CARDStat
/* 8024DC10 0024AB70 48 0F FC 21 */ bl GetStatus__14CMemoryCardSysFQ214CMemoryCardSys15EMemoryCardPortiR8CardStat
/* 8024DC14 0024AB74 2C 03 00 00 */ cmpwi r3, 0
/* 8024DC18 0024AB78 40 82 00 6C */ bne lbl_8024DC84
/* 8024DC1C 0024AB7C 38 61 00 08 */ addi r3, r1, 8
/* 8024DC20 0024AB80 48 10 09 A5 */ bl GetTime__8CARDStatFv
/* 8024DC20 0024AB80 48 10 09 A5 */ bl GetTime__8CardStatCFv
/* 8024DC24 0024AB84 7C 7E 1B 78 */ mr r30, r3
/* 8024DC28 0024AB88 38 7D 00 4C */ addi r3, r29, 0x4c
/* 8024DC2C 0024AB8C 48 10 0E 79 */ bl GetFileNo__19SMemoryCardFileInfoFv
/* 8024DC2C 0024AB8C 48 10 0E 79 */ bl GetFileNo__19SMemoryCardFileInfoCFv
/* 8024DC30 0024AB90 7C 64 1B 78 */ mr r4, r3
/* 8024DC34 0024AB94 80 7F 00 00 */ lwz r3, 0(r31)
/* 8024DC38 0024AB98 38 A1 00 08 */ addi r5, r1, 8
/* 8024DC3C 0024AB9C 48 0F FB F5 */ bl GetStatus__14CMemoryCardSysFiiP8CARDStat
/* 8024DC3C 0024AB9C 48 0F FB F5 */ bl GetStatus__14CMemoryCardSysFQ214CMemoryCardSys15EMemoryCardPortiR8CardStat
/* 8024DC40 0024ABA0 2C 03 00 00 */ cmpwi r3, 0
/* 8024DC44 0024ABA4 40 82 00 34 */ bne lbl_8024DC78
/* 8024DC48 0024ABA8 38 61 00 08 */ addi r3, r1, 8
/* 8024DC4C 0024ABAC 48 10 09 79 */ bl GetTime__8CARDStatFv
/* 8024DC4C 0024ABAC 48 10 09 79 */ bl GetTime__8CardStatCFv
/* 8024DC50 0024ABB0 7C 1E 18 40 */ cmplw r30, r3
/* 8024DC54 0024ABB4 40 81 00 10 */ ble lbl_8024DC64
/* 8024DC58 0024ABB8 38 00 00 00 */ li r0, 0

View File

@ -2,6 +2,7 @@
#define _CMEMORYCARDSYS
#include "types.h"
#include "string.h"
// TODO: likely comes from dolphin sdk
enum ECardResult {
@ -30,6 +31,18 @@ struct ProbeResults {
int x8_sectorSize; /* in bytes */
};
struct CardStat {
u8 x0_pad[0x6c];
CardStat()
{
memset(this, 0, sizeof(CardStat));
}
int GetTime() const;
int GetCommentAddr() const;
};
class CMemoryCardSys {
public:
enum EMemoryCardPort { kCS_SlotA, kCS_SlotB };
@ -38,7 +51,7 @@ public:
EMemoryCardPort slot;
FileHandle handle;
CardFileHandle(EMemoryCardPort slot) : slot(slot) {}
int getFileNo() const;
int GetFileNo() const;
};
class CCardFileInfo {
@ -57,6 +70,7 @@ public:
static ECardResult GetResultCode(int);
static ECardResult MountCard(EMemoryCardPort port);
static ECardResult CheckCard(EMemoryCardPort port);
static ECardResult GetStatus(EMemoryCardPort port, int fileNo, CardStat& statOut);
static ProbeResults IsMemoryCardInserted(EMemoryCardPort);
static ECardResult GetSerialNo(EMemoryCardPort port, long long& serialOut);

View File

@ -27,8 +27,8 @@ struct SMemoryCardFileInfo {
ECardResult Open();
ECardResult Close();
int GetFileCardPort() const { return x0_fileInfo.slot; }
int GetFileNo() const { return x0_fileInfo.getFileNo(); }
CMemoryCardSys::EMemoryCardPort GetFileCardPort() const { return x0_fileInfo.slot; }
int GetFileNo() const; // { return x0_fileInfo.GetFileNo(); }
ECardResult StartRead();
ECardResult TryFileRead();
ECardResult FileRead();

View File

@ -443,7 +443,78 @@ void CMemoryCardDriver::NoCardFound() {
gpMain->SetCardBusy(false);
}
void CMemoryCardDriver::IndexFiles() {}
void CMemoryCardDriver::IndexFiles() {
x14_error = kE_OK;
for (int i = 0; i < x100_mcFileInfos.capacity(); ++i) {
rstl::pair< EFileState, SMemoryCardFileInfo >& info = x100_mcFileInfos[i];
if (info.first == kFS_Unknown) {
ECardResult result = info.second.Open();
if (result == kCR_NOFILE) {
info.first = kFS_NoFile;
continue;
} else if (result == kCR_READY) {
CardStat stat;
if (CMemoryCardSys::GetStatus(x0_cardPort, info.second.GetFileNo(), stat) ==
kCR_READY) {
int comment = stat.GetCommentAddr();
if (comment == -1)
info.first = kFS_BadFile;
else
info.first = kFS_File;
} else {
NoCardFound();
return;
}
if (info.second.Close() == kCR_NOCARD) {
NoCardFound();
return;
}
} else {
NoCardFound();
return;
}
}
}
if (x100_mcFileInfos[0].first == kFS_File) {
if (x100_mcFileInfos[1].first == kFS_File) {
CardStat stat;
if (CMemoryCardSys::GetStatus(x0_cardPort, x100_mcFileInfos[0].second.GetFileNo(), stat) == kCR_READY) {
u32 timeA = stat.GetTime();
if (CMemoryCardSys::GetStatus(x0_cardPort, x100_mcFileInfos[1].second.GetFileNo(), stat) == kCR_READY) {
u32 timeB = stat.GetTime();
if (timeA > timeB)
x194_fileIdx = 0;
else
x194_fileIdx = 1;
StartFileRead();
return;
}
NoCardFound();
return;
}
NoCardFound();
return;
}
x194_fileIdx = 0;
StartFileRead();
return;
}
if (x100_mcFileInfos[1].first == kFS_File) {
x194_fileIdx = 1;
StartFileRead();
return;
}
if (x100_mcFileInfos[0].first == kFS_BadFile || x100_mcFileInfos[1].first == kFS_BadFile) {
x14_error = kE_FileCorrupted;
x10_state = kS_FileBad;
} else {
x14_error = kE_FileMissing;
x10_state = kS_FileBad;
}
}
void CMemoryCardDriver::StartFileDeleteBad() {}