2022-10-09 05:13:17 +00:00
|
|
|
#ifndef _CMEMORYCARDSYS
|
|
|
|
#define _CMEMORYCARDSYS
|
2022-04-10 00:17:06 +00:00
|
|
|
|
2022-10-11 11:37:01 +00:00
|
|
|
#include "string.h"
|
2022-10-11 12:09:23 +00:00
|
|
|
#include "types.h"
|
|
|
|
|
2022-10-11 13:41:20 +00:00
|
|
|
#include "Kyoto/CSimplePool.hpp"
|
|
|
|
#include "Kyoto/Streams/CMemoryStreamOut.hpp"
|
|
|
|
|
2022-10-11 12:09:23 +00:00
|
|
|
#include "rstl/string.hpp"
|
2022-04-10 00:17:06 +00:00
|
|
|
|
2022-10-10 19:58:03 +00:00
|
|
|
// TODO: likely comes from dolphin sdk
|
2022-10-11 12:09:23 +00:00
|
|
|
enum ECardResult {
|
2022-10-10 23:02:10 +00:00
|
|
|
kCR_CRC_MISMATCH = -1003, /* Extension enum for Retro's CRC check */
|
|
|
|
kCR_FATAL_ERROR = -128,
|
|
|
|
kCR_ENCODING = -13,
|
|
|
|
kCR_NAMETOOLONG = -12,
|
|
|
|
kCR_INSSPACE = -9,
|
|
|
|
kCR_NOENT = -8,
|
|
|
|
kCR_EXIST = -7,
|
|
|
|
kCR_BROKEN = -6,
|
|
|
|
kCR_IOERROR = -5,
|
|
|
|
kCR_NOFILE = -4,
|
|
|
|
kCR_NOCARD = -3,
|
|
|
|
kCR_WRONGDEVICE = -2,
|
|
|
|
kCR_BUSY = -1,
|
|
|
|
kCR_READY = 0
|
|
|
|
};
|
2022-10-11 12:09:23 +00:00
|
|
|
enum EMemoryCardPort { kCS_SlotA, kCS_SlotB };
|
|
|
|
|
2022-10-10 22:53:28 +00:00
|
|
|
struct FileHandle {
|
|
|
|
u8 x0_pad[0x10];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ProbeResults {
|
|
|
|
ECardResult x0_error;
|
2022-10-11 09:41:19 +00:00
|
|
|
int x4_cardSize; /* in megabits */
|
|
|
|
int x8_sectorSize; /* in bytes */
|
2022-10-10 22:53:28 +00:00
|
|
|
};
|
2022-10-10 19:58:03 +00:00
|
|
|
|
2022-10-11 11:37:01 +00:00
|
|
|
struct CardStat {
|
|
|
|
u8 x0_pad[0x6c];
|
|
|
|
|
2022-10-11 12:09:23 +00:00
|
|
|
CardStat() { memset(this, 0, sizeof(CardStat)); }
|
2022-10-11 11:37:01 +00:00
|
|
|
|
|
|
|
int GetTime() const;
|
|
|
|
int GetCommentAddr() const;
|
|
|
|
};
|
|
|
|
|
2022-10-11 12:09:23 +00:00
|
|
|
class CCardFileInfo {
|
2022-10-11 13:41:20 +00:00
|
|
|
uchar pad[0xf4];
|
|
|
|
rstl::vector<u8> xf4_saveBuffer;
|
|
|
|
rstl::vector<u8> x104_cardBuffer;
|
2022-10-11 12:09:23 +00:00
|
|
|
|
2022-04-10 00:17:06 +00:00
|
|
|
public:
|
2022-10-11 12:09:23 +00:00
|
|
|
CCardFileInfo(EMemoryCardPort port, const rstl::string& name);
|
|
|
|
~CCardFileInfo();
|
|
|
|
|
2022-10-11 13:41:20 +00:00
|
|
|
void SetComment(const rstl::string& name);
|
|
|
|
void LockBannerToken(CAssetId bannerTxtr, CSimplePool& sp);
|
|
|
|
void LockIconToken(CAssetId iconTxtr, int speed, CSimplePool& sp);
|
|
|
|
|
2022-10-11 12:09:23 +00:00
|
|
|
ECardResult PumpCardTransfer();
|
|
|
|
ECardResult CreateFile();
|
2022-10-11 12:19:51 +00:00
|
|
|
ECardResult WriteFile();
|
2022-10-11 12:09:23 +00:00
|
|
|
ECardResult CloseFile();
|
2022-10-11 13:41:20 +00:00
|
|
|
|
|
|
|
inline CMemoryStreamOut BeginMemoryOut(uint sz) {
|
|
|
|
xf4_saveBuffer.resize(sz, '\x00');
|
|
|
|
return CMemoryStreamOut(xf4_saveBuffer.data(), sz, CMemoryStreamOut::kOS_NotOwned, sz);
|
|
|
|
}
|
2022-10-11 12:09:23 +00:00
|
|
|
};
|
2022-10-11 13:41:20 +00:00
|
|
|
CHECK_SIZEOF(CCardFileInfo, 0x114)
|
2022-10-10 22:53:28 +00:00
|
|
|
|
2022-10-11 12:09:23 +00:00
|
|
|
class CMemoryCardSys {
|
|
|
|
public:
|
2022-10-10 19:58:03 +00:00
|
|
|
struct CardFileHandle {
|
2022-10-10 22:53:28 +00:00
|
|
|
EMemoryCardPort slot;
|
2022-10-10 19:58:03 +00:00
|
|
|
FileHandle handle;
|
2022-10-10 22:53:28 +00:00
|
|
|
CardFileHandle(EMemoryCardPort slot) : slot(slot) {}
|
2022-10-11 11:37:01 +00:00
|
|
|
int GetFileNo() const;
|
2022-10-10 19:58:03 +00:00
|
|
|
};
|
|
|
|
|
2022-09-13 04:26:54 +00:00
|
|
|
CMemoryCardSys();
|
2022-04-10 00:17:06 +00:00
|
|
|
~CMemoryCardSys();
|
|
|
|
|
2022-10-10 22:53:28 +00:00
|
|
|
static ECardResult GetResultCode(int);
|
2022-10-11 09:43:09 +00:00
|
|
|
static ECardResult MountCard(EMemoryCardPort port);
|
2022-10-11 09:44:26 +00:00
|
|
|
static ECardResult CheckCard(EMemoryCardPort port);
|
2022-10-11 11:37:01 +00:00
|
|
|
static ECardResult GetStatus(EMemoryCardPort port, int fileNo, CardStat& statOut);
|
2022-10-11 12:29:57 +00:00
|
|
|
static ECardResult DeleteFile(EMemoryCardPort port, const rstl::string& name);
|
2022-10-11 11:50:30 +00:00
|
|
|
static ECardResult FastDeleteFile(EMemoryCardPort port, int fileNo);
|
2022-10-11 12:30:49 +00:00
|
|
|
static ECardResult FormatCard(EMemoryCardPort port);
|
2022-10-11 09:44:26 +00:00
|
|
|
|
2022-10-10 22:53:28 +00:00
|
|
|
static ProbeResults IsMemoryCardInserted(EMemoryCardPort);
|
2022-10-10 23:08:19 +00:00
|
|
|
static ECardResult GetSerialNo(EMemoryCardPort port, long long& serialOut);
|
2022-10-11 04:00:52 +00:00
|
|
|
static void UnmountCard(EMemoryCardPort);
|
|
|
|
static ECardResult Rename(EMemoryCardPort, const rstl::string&, const rstl::string&);
|
2022-10-11 17:02:35 +00:00
|
|
|
static ECardResult GetNumFreeBytes(EMemoryCardPort port, uint& freeBytes, uint& freeFiles);
|
2022-10-10 22:53:28 +00:00
|
|
|
|
2022-09-13 04:26:54 +00:00
|
|
|
void Initialize();
|
|
|
|
|
2022-04-10 00:17:06 +00:00
|
|
|
private:
|
|
|
|
// TODO
|
|
|
|
};
|
|
|
|
|
2022-10-09 05:13:17 +00:00
|
|
|
#endif // _CMEMORYCARDSYS
|