2016-09-25 01:58:20 +00:00
|
|
|
#include "CMemoryCardSys.hpp"
|
|
|
|
#include "GameGlobalObjects.hpp"
|
|
|
|
#include "CSimplePool.hpp"
|
2016-09-30 22:43:19 +00:00
|
|
|
#include "CGameState.hpp"
|
2016-10-20 00:52:33 +00:00
|
|
|
#include "GuiSys/CStringTable.hpp"
|
2016-12-23 06:41:39 +00:00
|
|
|
#include "CCRC32.hpp"
|
|
|
|
#include "Graphics/CTexture.hpp"
|
2016-09-25 01:58:20 +00:00
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
2016-12-28 08:51:28 +00:00
|
|
|
using ECardResult = kabufuda::ECardResult;
|
|
|
|
|
2016-12-28 21:39:38 +00:00
|
|
|
static kabufuda::SystemString g_CardImagePaths[2] = {};
|
|
|
|
static kabufuda::Card g_CardStates[2] = {};
|
|
|
|
static kabufuda::ECardResult g_OpResults[2] = {};
|
2016-12-28 08:51:28 +00:00
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
CSaveWorldIntermediate::CSaveWorldIntermediate(CAssetId mlvl, CAssetId savw)
|
2016-09-25 01:58:20 +00:00
|
|
|
: x0_mlvlId(mlvl), x8_savwId(savw)
|
|
|
|
{
|
2017-11-15 04:12:13 +00:00
|
|
|
if (!savw.IsValid())
|
2016-09-25 01:58:20 +00:00
|
|
|
x2c_dummyWorld = std::make_unique<CDummyWorld>(mlvl, false);
|
|
|
|
else
|
2016-09-30 22:43:19 +00:00
|
|
|
x34_saveWorld = g_SimplePool->GetObj(SObjectTag{FOURCC('SAVW'), savw});
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CSaveWorldIntermediate::InitializePump()
|
|
|
|
{
|
|
|
|
if (x2c_dummyWorld)
|
|
|
|
{
|
|
|
|
CDummyWorld& wld = *x2c_dummyWorld;
|
|
|
|
if (!wld.ICheckWorldComplete())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
x4_strgId = wld.IGetStringTableAssetId();
|
|
|
|
x8_savwId = wld.IGetSaveWorldAssetId();
|
|
|
|
u32 areaCount = wld.IGetAreaCount();
|
|
|
|
|
|
|
|
xc_areaIds.reserve(areaCount);
|
|
|
|
for (u32 i=0 ; i<areaCount ; ++i)
|
|
|
|
{
|
|
|
|
const IGameArea* area = wld.IGetAreaAlways(i);
|
|
|
|
xc_areaIds.push_back(area->IGetAreaId());
|
|
|
|
}
|
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
CAssetId mlvlId = wld.IGetWorldAssetId();
|
2016-09-30 22:43:19 +00:00
|
|
|
CWorldState& mlvlState = g_GameState->StateForWorld(mlvlId);
|
2016-10-09 07:45:04 +00:00
|
|
|
x1c_defaultLayerStates = mlvlState.GetLayerState()->x0_areaLayers;
|
2016-09-30 22:43:19 +00:00
|
|
|
|
|
|
|
x34_saveWorld = g_SimplePool->GetObj(SObjectTag{FOURCC('SAVW'), x8_savwId});
|
|
|
|
x2c_dummyWorld.reset();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!x34_saveWorld)
|
|
|
|
return true;
|
|
|
|
if (x34_saveWorld.IsLoaded() && x34_saveWorld.GetObj())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2016-09-25 01:58:20 +00:00
|
|
|
}
|
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
bool CMemoryCardSys::HasSaveWorldMemory(CAssetId wldId) const
|
2017-01-09 03:44:00 +00:00
|
|
|
{
|
|
|
|
auto existingSearch =
|
|
|
|
std::find_if(xc_memoryWorlds.cbegin(), xc_memoryWorlds.cend(), [&](const auto& wld)
|
|
|
|
{ return wld.first == wldId; });
|
|
|
|
return existingSearch != xc_memoryWorlds.cend();
|
|
|
|
}
|
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
const CSaveWorldMemory& CMemoryCardSys::GetSaveWorldMemory(CAssetId wldId) const
|
2017-01-09 03:44:00 +00:00
|
|
|
{
|
|
|
|
auto existingSearch =
|
|
|
|
std::find_if(xc_memoryWorlds.cbegin(), xc_memoryWorlds.cend(), [&](const auto& wld)
|
|
|
|
{ return wld.first == wldId; });
|
|
|
|
return existingSearch->second;
|
|
|
|
}
|
|
|
|
|
2016-09-25 01:58:20 +00:00
|
|
|
CMemoryCardSys::CMemoryCardSys()
|
|
|
|
{
|
2016-10-08 20:32:36 +00:00
|
|
|
x0_hints = g_SimplePool->GetObj("HINT_Hints");
|
2016-09-25 01:58:20 +00:00
|
|
|
xc_memoryWorlds.reserve(16);
|
2016-09-30 22:43:19 +00:00
|
|
|
x1c_worldInter.emplace();
|
|
|
|
x1c_worldInter->reserve(16);
|
2017-02-08 06:48:43 +00:00
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
std::vector<std::pair<CAssetId, CAssetId>> orderedMLVLs;
|
2017-02-08 06:48:43 +00:00
|
|
|
orderedMLVLs.reserve(16);
|
2017-11-13 06:19:18 +00:00
|
|
|
g_ResFactory->EnumerateNamedResources([&](std::string_view name, const SObjectTag& tag) -> bool
|
2016-09-25 01:58:20 +00:00
|
|
|
{
|
|
|
|
if (tag.type == FOURCC('MLVL'))
|
|
|
|
{
|
2017-08-13 05:26:14 +00:00
|
|
|
CAssetId origId = g_ResFactory->TranslateNewToOriginal(tag.id);
|
2017-02-08 06:48:43 +00:00
|
|
|
orderedMLVLs.emplace_back(origId, tag.id);
|
2016-09-25 01:58:20 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
2017-02-08 06:48:43 +00:00
|
|
|
std::sort(orderedMLVLs.begin(), orderedMLVLs.end(),
|
|
|
|
[](const auto& a, const auto& b) -> bool { return a.first < b.first; });
|
|
|
|
|
|
|
|
for (const auto& mlvl : orderedMLVLs)
|
|
|
|
{
|
|
|
|
if (!HasSaveWorldMemory(mlvl.second))
|
|
|
|
{
|
|
|
|
xc_memoryWorlds.emplace_back(mlvl.second, CSaveWorldMemory{});
|
|
|
|
x1c_worldInter->emplace_back(mlvl.second, -1);
|
|
|
|
}
|
|
|
|
}
|
2017-05-14 19:58:44 +00:00
|
|
|
|
|
|
|
x30_scanCategoryCounts.resize(6);
|
2016-09-25 01:58:20 +00:00
|
|
|
}
|
|
|
|
|
2016-09-30 22:43:19 +00:00
|
|
|
bool CMemoryCardSys::InitializePump()
|
|
|
|
{
|
|
|
|
if (!x1c_worldInter)
|
|
|
|
{
|
|
|
|
for (const auto& world : xc_memoryWorlds)
|
|
|
|
{
|
|
|
|
const CSaveWorldMemory& wld = world.second;
|
2016-10-08 20:32:36 +00:00
|
|
|
if (!wld.GetWorldName())
|
|
|
|
continue;
|
2016-09-30 22:43:19 +00:00
|
|
|
if (!wld.GetWorldName().IsLoaded() ||
|
|
|
|
!wld.GetWorldName().GetObj())
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!x0_hints.IsLoaded() || !x0_hints.GetObj())
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool done = true;
|
|
|
|
for (CSaveWorldIntermediate& world : *x1c_worldInter)
|
|
|
|
{
|
|
|
|
if (world.InitializePump())
|
|
|
|
{
|
|
|
|
if (!world.x34_saveWorld)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
auto existingSearch =
|
|
|
|
std::find_if(xc_memoryWorlds.begin(), xc_memoryWorlds.end(), [&](const auto& test)
|
|
|
|
{ return test.first == world.x0_mlvlId; });
|
|
|
|
CSaveWorldMemory& wldMemOut = existingSearch->second;
|
|
|
|
wldMemOut.x4_savwId = world.x8_savwId;
|
|
|
|
wldMemOut.x0_strgId = world.x4_strgId;
|
|
|
|
wldMemOut.xc_areaIds = world.xc_areaIds;
|
2016-10-09 07:45:04 +00:00
|
|
|
wldMemOut.x1c_defaultLayerStates = world.x1c_defaultLayerStates;
|
2016-09-30 22:43:19 +00:00
|
|
|
|
|
|
|
CSaveWorld& savw = *world.x34_saveWorld;
|
|
|
|
wldMemOut.x8_areaCount = savw.GetAreaCount();
|
|
|
|
|
|
|
|
x20_scanStates.reserve(x20_scanStates.size() + savw.GetScans().size());
|
|
|
|
for (const CSaveWorld::SScanState& scan : savw.GetScans())
|
2017-02-06 03:21:58 +00:00
|
|
|
{
|
|
|
|
auto existingSearch =
|
|
|
|
std::find_if(x20_scanStates.begin(), x20_scanStates.end(), [&](const auto& test)
|
|
|
|
{ return test.first == scan.x0_id && test.second == scan.x4_category; });
|
|
|
|
if (existingSearch == x20_scanStates.end())
|
2017-05-14 19:58:44 +00:00
|
|
|
{
|
2017-02-06 03:21:58 +00:00
|
|
|
x20_scanStates.emplace_back(scan.x0_id, scan.x4_category);
|
2017-05-14 19:58:44 +00:00
|
|
|
++x30_scanCategoryCounts[int(scan.x4_category)];
|
|
|
|
}
|
2017-02-06 03:21:58 +00:00
|
|
|
}
|
2016-09-30 22:43:19 +00:00
|
|
|
|
|
|
|
wldMemOut.x3c_saveWorld = std::move(world.x34_saveWorld);
|
|
|
|
wldMemOut.x2c_worldName = g_SimplePool->GetObj(SObjectTag{FOURCC('STRG'), wldMemOut.x0_strgId});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
done = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (done)
|
2017-02-09 08:17:10 +00:00
|
|
|
{
|
|
|
|
std::sort(x20_scanStates.begin(), x20_scanStates.end(), [&](const auto& a, const auto& b) ->bool{
|
|
|
|
return g_ResFactory->TranslateNewToOriginal(a.first) < g_ResFactory->TranslateNewToOriginal(b.first);
|
|
|
|
});
|
2016-09-30 22:43:19 +00:00
|
|
|
x1c_worldInter = std::experimental::nullopt;
|
2017-02-09 08:17:10 +00:00
|
|
|
}
|
2016-09-30 22:43:19 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
void CMemoryCardSys::CCardFileInfo::LockBannerToken(CAssetId bannerTxtr, CSimplePool& sp)
|
2016-12-23 06:41:39 +00:00
|
|
|
{
|
|
|
|
x3c_bannerTex = bannerTxtr;
|
|
|
|
x40_bannerTok.emplace(sp.GetObj({FOURCC('TXTR'), bannerTxtr}, m_texParam));
|
|
|
|
}
|
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
CMemoryCardSys::CCardFileInfo::Icon::Icon(CAssetId id, kabufuda::EAnimationSpeed speed,
|
2016-12-28 08:51:28 +00:00
|
|
|
CSimplePool& sp, const CVParamTransfer& cv)
|
2016-12-23 06:41:39 +00:00
|
|
|
: x0_id(id), x4_speed(speed), x8_tex(sp.GetObj({FOURCC('TXTR'), id}, cv)) {}
|
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
void CMemoryCardSys::CCardFileInfo::LockIconToken(CAssetId iconTxtr, kabufuda::EAnimationSpeed speed, CSimplePool& sp)
|
2016-12-23 06:41:39 +00:00
|
|
|
{
|
|
|
|
x50_iconToks.emplace_back(iconTxtr, speed, sp, m_texParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 CMemoryCardSys::CCardFileInfo::CalculateBannerDataSize() const
|
|
|
|
{
|
|
|
|
u32 ret = 68;
|
2017-11-15 04:12:13 +00:00
|
|
|
if (x3c_bannerTex.IsValid())
|
2016-12-23 06:41:39 +00:00
|
|
|
{
|
|
|
|
if ((*x40_bannerTok)->GetMemoryCardTexelFormat() == ETexelFormat::RGB5A3)
|
|
|
|
ret = 6212;
|
|
|
|
else
|
|
|
|
ret = 3652;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool paletteTex = false;
|
|
|
|
for (const Icon& icon : x50_iconToks)
|
|
|
|
{
|
|
|
|
if (icon.x8_tex->GetMemoryCardTexelFormat() == ETexelFormat::RGB5A3)
|
|
|
|
ret += 2048;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret += 1024;
|
|
|
|
paletteTex = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (paletteTex)
|
|
|
|
ret += 512;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 CMemoryCardSys::CCardFileInfo::CalculateTotalDataSize() const
|
|
|
|
{
|
|
|
|
return (CalculateBannerDataSize() + xf4_saveBuffer.size() + 8191) & ~8191;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMemoryCardSys::CCardFileInfo::BuildCardBuffer()
|
|
|
|
{
|
|
|
|
u32 bannerSz = CalculateBannerDataSize();
|
|
|
|
x104_cardBuffer.resize((bannerSz + xf4_saveBuffer.size() + 8191) & ~8191);
|
|
|
|
|
|
|
|
CMemoryOutStream w(x104_cardBuffer.data(), x104_cardBuffer.size());
|
|
|
|
w.writeUint32Big(0);
|
2016-12-24 00:45:51 +00:00
|
|
|
char comment[64];
|
|
|
|
strncpy(comment, x28_comment.data(), 64);
|
|
|
|
w.writeBytes(comment, 64);
|
2016-12-23 06:41:39 +00:00
|
|
|
WriteBannerData(w);
|
|
|
|
WriteIconData(w);
|
|
|
|
memmove(x104_cardBuffer.data() + bannerSz, xf4_saveBuffer.data(), xf4_saveBuffer.size());
|
|
|
|
reinterpret_cast<u32&>(*x104_cardBuffer.data()) =
|
|
|
|
hecl::SBig(CCRC32::Calculate(x104_cardBuffer.data() + 4, x104_cardBuffer.size() - 4));
|
|
|
|
|
|
|
|
xf4_saveBuffer.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMemoryCardSys::CCardFileInfo::WriteBannerData(CMemoryOutStream& out) const
|
|
|
|
{
|
2017-11-15 04:12:13 +00:00
|
|
|
if (x3c_bannerTex.IsValid())
|
2016-12-23 06:41:39 +00:00
|
|
|
{
|
|
|
|
const TLockedToken<CTexture>& tex = *x40_bannerTok;
|
|
|
|
u32 bufSz;
|
|
|
|
ETexelFormat fmt;
|
|
|
|
std::unique_ptr<u8[]> palette;
|
|
|
|
std::unique_ptr<u8[]> texels = tex->BuildMemoryCardTex(bufSz, fmt, palette);
|
|
|
|
|
|
|
|
if (fmt == ETexelFormat::RGB5A3)
|
|
|
|
out.writeBytes(texels.get(), 6144);
|
|
|
|
else
|
|
|
|
out.writeBytes(texels.get(), 3072);
|
|
|
|
|
|
|
|
if (fmt == ETexelFormat::C8)
|
|
|
|
out.writeBytes(palette.get(), 512);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMemoryCardSys::CCardFileInfo::WriteIconData(CMemoryOutStream& out) const
|
|
|
|
{
|
|
|
|
std::unique_ptr<u8[]> palette;
|
|
|
|
for (const Icon& icon : x50_iconToks)
|
|
|
|
{
|
|
|
|
u32 bufSz;
|
|
|
|
ETexelFormat fmt;
|
|
|
|
std::unique_ptr<u8[]> texels = icon.x8_tex->BuildMemoryCardTex(bufSz, fmt, palette);
|
|
|
|
|
|
|
|
if (fmt == ETexelFormat::RGB5A3)
|
|
|
|
out.writeBytes(texels.get(), 2048);
|
|
|
|
else
|
|
|
|
out.writeBytes(texels.get(), 1024);
|
|
|
|
}
|
|
|
|
if (palette)
|
|
|
|
out.writeBytes(palette.get(), 512);
|
|
|
|
}
|
|
|
|
|
2016-12-28 08:51:28 +00:00
|
|
|
ECardResult CMemoryCardSys::CCardFileInfo::PumpCardTransfer()
|
2016-12-23 06:41:39 +00:00
|
|
|
{
|
|
|
|
if (x0_status == EStatus::Standby)
|
2016-12-24 05:23:50 +00:00
|
|
|
return ECardResult::READY;
|
2016-12-23 06:41:39 +00:00
|
|
|
else if (x0_status == EStatus::Transferring)
|
|
|
|
{
|
|
|
|
ECardResult result = CMemoryCardSys::GetResultCode(GetCardPort());
|
2016-12-24 05:23:50 +00:00
|
|
|
if (result != ECardResult::BUSY)
|
2016-12-23 06:41:39 +00:00
|
|
|
x104_cardBuffer.clear();
|
2016-12-24 05:23:50 +00:00
|
|
|
if (result != ECardResult::READY)
|
2016-12-23 06:41:39 +00:00
|
|
|
return result;
|
|
|
|
x0_status = EStatus::Done;
|
2016-12-28 08:51:28 +00:00
|
|
|
kabufuda::CardStat stat = {};
|
2016-12-23 06:41:39 +00:00
|
|
|
result = GetStatus(stat);
|
2016-12-24 05:23:50 +00:00
|
|
|
if (result != ECardResult::READY)
|
2016-12-23 06:41:39 +00:00
|
|
|
return result;
|
2017-01-24 07:41:33 +00:00
|
|
|
result = CMemoryCardSys::SetStatus(m_handle.slot, m_handle.getFileNo(), stat);
|
2016-12-24 05:23:50 +00:00
|
|
|
if (result != ECardResult::READY)
|
2016-12-23 06:41:39 +00:00
|
|
|
return result;
|
2016-12-24 05:23:50 +00:00
|
|
|
return ECardResult::BUSY;
|
2016-12-23 06:41:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ECardResult result = CMemoryCardSys::GetResultCode(GetCardPort());
|
2016-12-24 05:23:50 +00:00
|
|
|
if (result == ECardResult::READY)
|
2016-12-23 06:41:39 +00:00
|
|
|
x0_status = EStatus::Standby;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-28 08:51:28 +00:00
|
|
|
ECardResult CMemoryCardSys::CCardFileInfo::GetStatus(kabufuda::CardStat& stat) const
|
2016-12-23 06:41:39 +00:00
|
|
|
{
|
2017-01-24 07:41:33 +00:00
|
|
|
ECardResult result = CMemoryCardSys::GetStatus(m_handle.slot, m_handle.getFileNo(), stat);
|
2016-12-24 05:23:50 +00:00
|
|
|
if (result != ECardResult::READY)
|
2016-12-23 06:41:39 +00:00
|
|
|
return result;
|
|
|
|
|
|
|
|
stat.SetCommentAddr(4);
|
|
|
|
stat.SetIconAddr(68);
|
|
|
|
|
2016-12-28 08:51:28 +00:00
|
|
|
kabufuda::EImageFormat bannerFmt;
|
2017-11-15 04:12:13 +00:00
|
|
|
if (x3c_bannerTex.IsValid())
|
2016-12-23 06:41:39 +00:00
|
|
|
{
|
|
|
|
if ((*x40_bannerTok)->GetMemoryCardTexelFormat() == ETexelFormat::RGB5A3)
|
2016-12-28 08:51:28 +00:00
|
|
|
bannerFmt = kabufuda::EImageFormat::RGB5A3;
|
2016-12-23 06:41:39 +00:00
|
|
|
else
|
2016-12-28 08:51:28 +00:00
|
|
|
bannerFmt = kabufuda::EImageFormat::C8;
|
2016-12-23 06:41:39 +00:00
|
|
|
}
|
|
|
|
else
|
2016-12-28 08:51:28 +00:00
|
|
|
bannerFmt = kabufuda::EImageFormat::None;
|
2016-12-23 06:41:39 +00:00
|
|
|
stat.SetBannerFormat(bannerFmt);
|
|
|
|
|
|
|
|
int idx = 0;
|
|
|
|
for (const Icon& icon : x50_iconToks)
|
|
|
|
{
|
2016-12-28 08:51:28 +00:00
|
|
|
stat.SetIconFormat(icon.x8_tex->GetMemoryCardTexelFormat() == ETexelFormat::RGB5A3 ?
|
|
|
|
kabufuda::EImageFormat::RGB5A3 : kabufuda::EImageFormat::C8, idx);
|
2016-12-23 06:41:39 +00:00
|
|
|
stat.SetIconSpeed(icon.x4_speed, idx);
|
|
|
|
++idx;
|
|
|
|
}
|
|
|
|
if (idx < 8)
|
|
|
|
{
|
2016-12-28 08:51:28 +00:00
|
|
|
stat.SetIconFormat(kabufuda::EImageFormat::None, idx);
|
|
|
|
stat.SetIconSpeed(kabufuda::EAnimationSpeed::End, idx);
|
2016-12-23 06:41:39 +00:00
|
|
|
}
|
|
|
|
|
2016-12-24 05:23:50 +00:00
|
|
|
return ECardResult::READY;
|
2016-12-23 06:41:39 +00:00
|
|
|
}
|
|
|
|
|
2016-12-28 08:51:28 +00:00
|
|
|
ECardResult CMemoryCardSys::CCardFileInfo::CreateFile()
|
2016-12-23 06:41:39 +00:00
|
|
|
{
|
2016-12-28 08:51:28 +00:00
|
|
|
return CMemoryCardSys::CreateFile(m_handle.slot, x18_fileName.c_str(),
|
|
|
|
CalculateTotalDataSize(), m_handle);
|
2016-12-23 06:41:39 +00:00
|
|
|
}
|
|
|
|
|
2016-12-28 08:51:28 +00:00
|
|
|
ECardResult CMemoryCardSys::CCardFileInfo::WriteFile()
|
2016-12-23 06:41:39 +00:00
|
|
|
{
|
|
|
|
BuildCardBuffer();
|
2016-12-28 08:51:28 +00:00
|
|
|
//DCStoreRange(x104_cardBuffer.data(), x104_cardBuffer.size());
|
2017-02-04 03:46:12 +00:00
|
|
|
x0_status = EStatus::Transferring;
|
2016-12-28 08:51:28 +00:00
|
|
|
return CMemoryCardSys::WriteFile(m_handle, x104_cardBuffer.data(), x104_cardBuffer.size(), 0);
|
2016-12-23 06:41:39 +00:00
|
|
|
}
|
|
|
|
|
2016-12-28 08:51:28 +00:00
|
|
|
ECardResult CMemoryCardSys::CCardFileInfo::CloseFile()
|
2016-12-23 06:41:39 +00:00
|
|
|
{
|
2016-12-28 08:51:28 +00:00
|
|
|
return CMemoryCardSys::CloseFile(m_handle);
|
2016-12-23 06:41:39 +00:00
|
|
|
}
|
|
|
|
|
2016-12-28 08:51:28 +00:00
|
|
|
kabufuda::ProbeResults CMemoryCardSys::CardProbe(kabufuda::ECardSlot port)
|
2016-12-18 04:16:04 +00:00
|
|
|
{
|
2017-02-04 03:46:12 +00:00
|
|
|
g_CardImagePaths[0] = ResolveDolphinCardPath(kabufuda::ECardSlot::SlotA);
|
|
|
|
g_CardImagePaths[1] = ResolveDolphinCardPath(kabufuda::ECardSlot::SlotB);
|
|
|
|
|
2016-12-28 21:39:38 +00:00
|
|
|
kabufuda::ProbeResults res = kabufuda::Card::probeCardFile(g_CardImagePaths[int(port)]);
|
|
|
|
g_OpResults[int(port)] = res.x0_error;
|
|
|
|
return res;
|
2016-12-18 04:16:04 +00:00
|
|
|
}
|
|
|
|
|
2016-12-28 08:51:28 +00:00
|
|
|
ECardResult CMemoryCardSys::MountCard(kabufuda::ECardSlot port)
|
2016-12-18 04:16:04 +00:00
|
|
|
{
|
2016-12-28 08:51:28 +00:00
|
|
|
kabufuda::Card& card = g_CardStates[int(port)];
|
2017-02-04 03:46:12 +00:00
|
|
|
card.close();
|
2016-12-28 08:51:28 +00:00
|
|
|
card = kabufuda::Card(g_CardImagePaths[int(port)], "GM8E", "01");
|
|
|
|
ECardResult result = card.getError();
|
2016-12-28 21:39:38 +00:00
|
|
|
g_OpResults[int(port)] = result;
|
2016-12-28 08:51:28 +00:00
|
|
|
if (result == ECardResult::READY)
|
|
|
|
return ECardResult::READY;
|
|
|
|
return result;
|
2016-12-18 04:16:04 +00:00
|
|
|
}
|
|
|
|
|
2016-12-28 21:51:33 +00:00
|
|
|
ECardResult CMemoryCardSys::UnmountCard(kabufuda::ECardSlot port)
|
|
|
|
{
|
|
|
|
kabufuda::Card& card = g_CardStates[int(port)];
|
|
|
|
if (CardResult err = card.getError())
|
|
|
|
{
|
|
|
|
g_OpResults[int(port)] = err;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
card = kabufuda::Card();
|
|
|
|
g_OpResults[int(port)] = ECardResult::READY;
|
|
|
|
return ECardResult::READY;
|
|
|
|
}
|
|
|
|
|
2016-12-28 08:51:28 +00:00
|
|
|
ECardResult CMemoryCardSys::CheckCard(kabufuda::ECardSlot port)
|
2016-12-18 04:16:04 +00:00
|
|
|
{
|
2016-12-28 08:51:28 +00:00
|
|
|
kabufuda::Card& card = g_CardStates[int(port)];
|
2016-12-28 21:39:38 +00:00
|
|
|
ECardResult result = card.getError();
|
|
|
|
g_OpResults[int(port)] = result;
|
|
|
|
return result;
|
2016-12-28 08:51:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ECardResult CMemoryCardSys::CreateFile(kabufuda::ECardSlot port, const char* name, u32 size, CardFileHandle& info)
|
|
|
|
{
|
|
|
|
kabufuda::Card& card = g_CardStates[int(port)];
|
|
|
|
if (CardResult err = card.getError())
|
2016-12-28 21:39:38 +00:00
|
|
|
{
|
|
|
|
g_OpResults[int(port)] = err;
|
2016-12-28 08:51:28 +00:00
|
|
|
return err;
|
2016-12-28 21:39:38 +00:00
|
|
|
}
|
2016-12-28 08:51:28 +00:00
|
|
|
info.slot = port;
|
2016-12-28 21:39:38 +00:00
|
|
|
ECardResult result = card.createFile(name, size, info.handle);
|
|
|
|
g_OpResults[int(port)] = result;
|
|
|
|
return result;
|
2016-12-28 08:51:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ECardResult CMemoryCardSys::OpenFile(kabufuda::ECardSlot port, const char* name, CardFileHandle& info)
|
|
|
|
{
|
|
|
|
kabufuda::Card& card = g_CardStates[int(port)];
|
|
|
|
if (CardResult err = card.getError())
|
2016-12-28 21:39:38 +00:00
|
|
|
{
|
|
|
|
g_OpResults[int(port)] = err;
|
2016-12-28 08:51:28 +00:00
|
|
|
return err;
|
2016-12-28 21:39:38 +00:00
|
|
|
}
|
2016-12-28 08:51:28 +00:00
|
|
|
info.slot = port;
|
2016-12-28 21:39:38 +00:00
|
|
|
ECardResult result = card.openFile(name, info.handle);
|
|
|
|
g_OpResults[int(port)] = result;
|
|
|
|
return result;
|
2016-12-28 08:51:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ECardResult CMemoryCardSys::FastOpenFile(kabufuda::ECardSlot port, int fileNo, CardFileHandle& info)
|
|
|
|
{
|
|
|
|
kabufuda::Card& card = g_CardStates[int(port)];
|
|
|
|
if (CardResult err = card.getError())
|
2016-12-28 21:39:38 +00:00
|
|
|
{
|
|
|
|
g_OpResults[int(port)] = err;
|
2016-12-28 08:51:28 +00:00
|
|
|
return err;
|
2016-12-28 21:39:38 +00:00
|
|
|
}
|
2016-12-28 08:51:28 +00:00
|
|
|
info.slot = port;
|
2016-12-28 21:39:38 +00:00
|
|
|
ECardResult result = card.openFile(fileNo, info.handle);
|
|
|
|
g_OpResults[int(port)] = result;
|
|
|
|
return result;
|
2016-12-18 04:16:04 +00:00
|
|
|
}
|
|
|
|
|
2016-12-28 08:51:28 +00:00
|
|
|
ECardResult CMemoryCardSys::CloseFile(CardFileHandle& info)
|
2016-12-18 04:16:04 +00:00
|
|
|
{
|
2016-12-28 21:39:38 +00:00
|
|
|
kabufuda::Card& card = g_CardStates[int(info.slot)];
|
|
|
|
if (CardResult err = card.getError())
|
|
|
|
{
|
|
|
|
g_OpResults[int(info.slot)] = err;
|
|
|
|
return err;
|
|
|
|
}
|
2017-01-24 07:41:33 +00:00
|
|
|
card.closeFile(info.handle);
|
2016-12-24 05:23:50 +00:00
|
|
|
return ECardResult::READY;
|
2016-12-18 04:16:04 +00:00
|
|
|
}
|
|
|
|
|
2017-01-24 07:41:33 +00:00
|
|
|
ECardResult CMemoryCardSys::ReadFile(CardFileHandle& info, void* buf, s32 length, s32 offset)
|
2016-12-18 04:16:04 +00:00
|
|
|
{
|
2016-12-28 08:51:28 +00:00
|
|
|
kabufuda::Card& card = g_CardStates[int(info.slot)];
|
|
|
|
if (CardResult err = card.getError())
|
2016-12-28 21:39:38 +00:00
|
|
|
{
|
|
|
|
g_OpResults[int(info.slot)] = err;
|
2016-12-28 08:51:28 +00:00
|
|
|
return err;
|
2016-12-28 21:39:38 +00:00
|
|
|
}
|
2017-01-24 07:41:33 +00:00
|
|
|
card.seek(info.handle, offset, kabufuda::SeekOrigin::Begin);
|
|
|
|
card.read(info.handle, buf, length);
|
2016-12-28 21:39:38 +00:00
|
|
|
g_OpResults[int(info.slot)] = ECardResult::READY;
|
2016-12-24 05:23:50 +00:00
|
|
|
return ECardResult::READY;
|
2016-12-18 04:16:04 +00:00
|
|
|
}
|
|
|
|
|
2017-01-24 07:41:33 +00:00
|
|
|
ECardResult CMemoryCardSys::WriteFile(CardFileHandle& info, const void* buf, s32 length, s32 offset)
|
2016-12-20 21:51:50 +00:00
|
|
|
{
|
2016-12-28 08:51:28 +00:00
|
|
|
kabufuda::Card& card = g_CardStates[int(info.slot)];
|
|
|
|
if (CardResult err = card.getError())
|
2016-12-28 21:39:38 +00:00
|
|
|
{
|
|
|
|
g_OpResults[int(info.slot)] = err;
|
2016-12-28 08:51:28 +00:00
|
|
|
return err;
|
2016-12-28 21:39:38 +00:00
|
|
|
}
|
2017-01-24 07:41:33 +00:00
|
|
|
card.seek(info.handle, offset, kabufuda::SeekOrigin::Begin);
|
|
|
|
card.write(info.handle, buf, length);
|
2016-12-28 21:39:38 +00:00
|
|
|
g_OpResults[int(info.slot)] = ECardResult::READY;
|
2016-12-24 05:23:50 +00:00
|
|
|
return ECardResult::READY;
|
2016-12-20 21:51:50 +00:00
|
|
|
}
|
|
|
|
|
2016-12-28 08:51:28 +00:00
|
|
|
ECardResult CMemoryCardSys::GetNumFreeBytes(kabufuda::ECardSlot port, s32& freeBytes, s32& freeFiles)
|
2016-12-20 21:51:50 +00:00
|
|
|
{
|
2016-12-28 08:51:28 +00:00
|
|
|
kabufuda::Card& card = g_CardStates[int(port)];
|
|
|
|
if (CardResult err = card.getError())
|
2016-12-28 21:39:38 +00:00
|
|
|
{
|
|
|
|
g_OpResults[int(port)] = err;
|
2016-12-28 08:51:28 +00:00
|
|
|
return err;
|
2016-12-28 21:39:38 +00:00
|
|
|
}
|
2016-12-28 08:51:28 +00:00
|
|
|
card.getFreeBlocks(freeBytes, freeFiles);
|
2016-12-28 21:39:38 +00:00
|
|
|
g_OpResults[int(port)] = ECardResult::READY;
|
2016-12-24 05:23:50 +00:00
|
|
|
return ECardResult::READY;
|
2016-12-20 21:51:50 +00:00
|
|
|
}
|
|
|
|
|
2016-12-28 08:51:28 +00:00
|
|
|
ECardResult CMemoryCardSys::GetSerialNo(kabufuda::ECardSlot port, u64& serialOut)
|
2016-12-23 06:41:39 +00:00
|
|
|
{
|
2016-12-28 08:51:28 +00:00
|
|
|
kabufuda::Card& card = g_CardStates[int(port)];
|
|
|
|
if (CardResult err = card.getError())
|
2016-12-28 21:39:38 +00:00
|
|
|
{
|
|
|
|
g_OpResults[int(port)] = err;
|
2016-12-28 08:51:28 +00:00
|
|
|
return err;
|
2016-12-28 21:39:38 +00:00
|
|
|
}
|
2016-12-28 08:51:28 +00:00
|
|
|
card.getSerial(serialOut);
|
2016-12-28 21:39:38 +00:00
|
|
|
g_OpResults[int(port)] = ECardResult::READY;
|
2016-12-24 05:23:50 +00:00
|
|
|
return ECardResult::READY;
|
2016-12-23 06:41:39 +00:00
|
|
|
}
|
|
|
|
|
2016-12-28 08:51:28 +00:00
|
|
|
ECardResult CMemoryCardSys::GetResultCode(kabufuda::ECardSlot port)
|
2016-12-20 21:51:50 +00:00
|
|
|
{
|
2016-12-28 21:39:38 +00:00
|
|
|
return g_OpResults[int(port)];
|
2016-12-20 21:51:50 +00:00
|
|
|
}
|
|
|
|
|
2017-01-24 07:41:33 +00:00
|
|
|
ECardResult CMemoryCardSys::GetStatus(kabufuda::ECardSlot port, int fileNo, CardStat& statOut)
|
2016-12-20 21:51:50 +00:00
|
|
|
{
|
2017-01-24 07:41:33 +00:00
|
|
|
kabufuda::Card& card = g_CardStates[int(port)];
|
2016-12-28 21:39:38 +00:00
|
|
|
if (CardResult err = card.getError())
|
|
|
|
{
|
2017-01-24 07:41:33 +00:00
|
|
|
g_OpResults[int(port)] = err;
|
2016-12-28 21:39:38 +00:00
|
|
|
return err;
|
|
|
|
}
|
2017-01-24 07:41:33 +00:00
|
|
|
ECardResult result = card.getStatus(fileNo, statOut);
|
|
|
|
g_OpResults[int(port)] = result;
|
2016-12-28 21:39:38 +00:00
|
|
|
return result;
|
2016-12-20 21:51:50 +00:00
|
|
|
}
|
|
|
|
|
2017-01-24 07:41:33 +00:00
|
|
|
ECardResult CMemoryCardSys::SetStatus(kabufuda::ECardSlot port, int fileNo, const CardStat& stat)
|
2016-12-23 06:41:39 +00:00
|
|
|
{
|
2017-01-24 07:41:33 +00:00
|
|
|
kabufuda::Card& card = g_CardStates[int(port)];
|
2016-12-28 21:39:38 +00:00
|
|
|
if (CardResult err = card.getError())
|
|
|
|
{
|
2017-01-24 07:41:33 +00:00
|
|
|
g_OpResults[int(port)] = err;
|
2016-12-28 21:39:38 +00:00
|
|
|
return err;
|
|
|
|
}
|
2017-01-24 07:41:33 +00:00
|
|
|
ECardResult result = card.setStatus(fileNo, stat);
|
|
|
|
g_OpResults[int(port)] = result;
|
2016-12-28 21:39:38 +00:00
|
|
|
return result;
|
2016-12-23 06:41:39 +00:00
|
|
|
}
|
|
|
|
|
2016-12-28 08:51:28 +00:00
|
|
|
ECardResult CMemoryCardSys::DeleteFile(kabufuda::ECardSlot port, const char* name)
|
|
|
|
{
|
|
|
|
kabufuda::Card& card = g_CardStates[int(port)];
|
|
|
|
if (CardResult err = card.getError())
|
2016-12-28 21:39:38 +00:00
|
|
|
{
|
|
|
|
g_OpResults[int(port)] = err;
|
2016-12-28 08:51:28 +00:00
|
|
|
return err;
|
2016-12-28 21:39:38 +00:00
|
|
|
}
|
|
|
|
ECardResult result = card.deleteFile(name);
|
|
|
|
g_OpResults[int(port)] = result;
|
|
|
|
return result;
|
2016-12-28 08:51:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ECardResult CMemoryCardSys::FastDeleteFile(kabufuda::ECardSlot port, int fileNo)
|
|
|
|
{
|
|
|
|
kabufuda::Card& card = g_CardStates[int(port)];
|
|
|
|
if (CardResult err = card.getError())
|
2016-12-28 21:39:38 +00:00
|
|
|
{
|
|
|
|
g_OpResults[int(port)] = err;
|
2016-12-28 08:51:28 +00:00
|
|
|
return err;
|
2016-12-28 21:39:38 +00:00
|
|
|
}
|
|
|
|
ECardResult result = card.deleteFile(fileNo);
|
|
|
|
g_OpResults[int(port)] = result;
|
|
|
|
return result;
|
2016-12-28 08:51:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ECardResult CMemoryCardSys::Rename(kabufuda::ECardSlot port, const char* oldName, const char* newName)
|
|
|
|
{
|
|
|
|
kabufuda::Card& card = g_CardStates[int(port)];
|
|
|
|
if (CardResult err = card.getError())
|
2016-12-28 21:39:38 +00:00
|
|
|
{
|
|
|
|
g_OpResults[int(port)] = err;
|
2016-12-28 08:51:28 +00:00
|
|
|
return err;
|
2016-12-28 21:39:38 +00:00
|
|
|
}
|
|
|
|
ECardResult result = card.renameFile(oldName, newName);
|
|
|
|
g_OpResults[int(port)] = result;
|
|
|
|
return result;
|
2016-12-28 08:51:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ECardResult CMemoryCardSys::FormatCard(kabufuda::ECardSlot port)
|
2016-12-23 06:41:39 +00:00
|
|
|
{
|
2016-12-28 08:51:28 +00:00
|
|
|
kabufuda::Card& card = g_CardStates[int(port)];
|
2017-02-04 03:46:12 +00:00
|
|
|
card.format(port);
|
2016-12-28 08:51:28 +00:00
|
|
|
if (CardResult err = card.getError())
|
2016-12-28 21:39:38 +00:00
|
|
|
{
|
|
|
|
g_OpResults[int(port)] = err;
|
2016-12-28 08:51:28 +00:00
|
|
|
return err;
|
2016-12-28 21:39:38 +00:00
|
|
|
}
|
|
|
|
g_OpResults[int(port)] = ECardResult::READY;
|
2016-12-24 05:23:50 +00:00
|
|
|
return ECardResult::READY;
|
2016-12-23 06:41:39 +00:00
|
|
|
}
|
|
|
|
|
2016-12-28 21:51:33 +00:00
|
|
|
void CMemoryCardSys::CommitToDisk(kabufuda::ECardSlot port)
|
|
|
|
{
|
|
|
|
kabufuda::Card& card = g_CardStates[int(port)];
|
|
|
|
card.commit();
|
|
|
|
}
|
|
|
|
|
2017-02-04 03:46:12 +00:00
|
|
|
kabufuda::SystemString CMemoryCardSys::CreateDolphinCard(kabufuda::ECardSlot slot)
|
|
|
|
{
|
|
|
|
kabufuda::SystemString path = _CreateDolphinCard(slot);
|
|
|
|
CardProbe(slot);
|
|
|
|
MountCard(slot);
|
|
|
|
FormatCard(slot);
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2017-01-22 17:36:25 +00:00
|
|
|
void CMemoryCardSys::Shutdown()
|
|
|
|
{
|
|
|
|
UnmountCard(kabufuda::ECardSlot::SlotA);
|
|
|
|
UnmountCard(kabufuda::ECardSlot::SlotB);
|
|
|
|
}
|
|
|
|
|
2016-09-25 01:58:20 +00:00
|
|
|
}
|