Replace MemoryCard251 setting with generic MemoryCardSize

This allows for a broader range of game-specific memory card sizes to
be configured.
This commit is contained in:
Techjar 2021-05-27 01:59:12 -04:00
parent 52a388af9a
commit 33a6701e56
12 changed files with 44 additions and 23 deletions

View File

@ -4,7 +4,7 @@
# Values set here will override the main Dolphin settings. # Values set here will override the main Dolphin settings.
# This game does not work properly with large memorycards, use a 251 block card # This game does not work properly with large memorycards, use a 251 block card
# see https://www.nintendo.com/consumer/memorycard1019.jsp # see https://www.nintendo.com/consumer/memorycard1019.jsp
MemoryCard251 = True MemoryCardSize = 2
[OnLoad] [OnLoad]
# Add memory patches to be loaded once on boot here. # Add memory patches to be loaded once on boot here.

View File

@ -4,7 +4,7 @@
# Values set here will override the main Dolphin settings. # Values set here will override the main Dolphin settings.
# This game does not work properly with large memorycards, use a 251 block card # This game does not work properly with large memorycards, use a 251 block card
# see https://www.nintendo.com/consumer/memorycard1019.jsp # see https://www.nintendo.com/consumer/memorycard1019.jsp
MemoryCard251 = True MemoryCardSize = 2
[OnLoad] [OnLoad]
# Add memory patches to be loaded once on boot here. # Add memory patches to be loaded once on boot here.

View File

@ -2,4 +2,4 @@
[Core] [Core]
# Values set here will override the main Dolphin settings. # Values set here will override the main Dolphin settings.
MemoryCard251 = True MemoryCardSize = 2

View File

@ -2,7 +2,7 @@
[Core] [Core]
# Values set here will override the main Dolphin settings. # Values set here will override the main Dolphin settings.
MemoryCard251 = True MemoryCardSize = 2
[OnLoad] [OnLoad]
# Add memory patches to be loaded once on boot here. # Add memory patches to be loaded once on boot here.

View File

@ -4,7 +4,7 @@
# Values set here will override the main Dolphin settings. # Values set here will override the main Dolphin settings.
# This game does not work properly with large memorycards, use a 251 block card # This game does not work properly with large memorycards, use a 251 block card
# see https://www.nintendo.com/consumer/memorycard1019.jsp # see https://www.nintendo.com/consumer/memorycard1019.jsp
MemoryCard251 = True MemoryCardSize = 2
CPUThread = False CPUThread = False
[OnLoad] [OnLoad]

View File

@ -75,11 +75,12 @@ void Init()
CEXIMemoryCard::Init(); CEXIMemoryCard::Init();
{ {
bool use_memcard_251; u16 size_mbits = Memcard::MBIT_SIZE_MEMORY_CARD_2043;
int size_override;
IniFile gameIni = SConfig::GetInstance().LoadGameIni(); IniFile gameIni = SConfig::GetInstance().LoadGameIni();
gameIni.GetOrCreateSection("Core")->Get("MemoryCard251", &use_memcard_251, false); gameIni.GetOrCreateSection("Core")->Get("MemoryCardSize", &size_override, -1);
const u16 size_mbits = if (size_override >= 0 && size_override <= 4)
use_memcard_251 ? Memcard::MBIT_SIZE_MEMORY_CARD_251 : Memcard::MBIT_SIZE_MEMORY_CARD_2043; size_mbits = Memcard::MBIT_SIZE_MEMORY_CARD_59 << size_override;
const bool shift_jis = const bool shift_jis =
SConfig::ToGameCubeRegion(SConfig::GetInstance().m_region) == DiscIO::Region::NTSC_J; SConfig::ToGameCubeRegion(SConfig::GetInstance().m_region) == DiscIO::Region::NTSC_J;
const CardFlashId& flash_id = g_SRAM.settings_ex.flash_id[Memcard::SLOT_A]; const CardFlashId& flash_id = g_SRAM.settings_ex.flash_id[Memcard::SLOT_A];

View File

@ -236,8 +236,11 @@ void CEXIMemoryCard::SetupRawMemcard(u16 size_mb)
SConfig::GetDirectoryForRegion(SConfig::ToGameCubeRegion(SConfig::GetInstance().m_region)); SConfig::GetDirectoryForRegion(SConfig::ToGameCubeRegion(SConfig::GetInstance().m_region));
MemoryCard::CheckPath(filename, region_dir, is_slot_a); MemoryCard::CheckPath(filename, region_dir, is_slot_a);
if (size_mb == Memcard::MBIT_SIZE_MEMORY_CARD_251) if (size_mb < Memcard::MBIT_SIZE_MEMORY_CARD_2043)
filename.insert(filename.find_last_of('.'), ".251"); {
filename.insert(filename.find_last_of('.'),
fmt::format(".{}", Memcard::MbitToFreeBlocks(size_mb)));
}
m_memory_card = std::make_unique<MemoryCard>(filename, m_card_index, size_mb); m_memory_card = std::make_unique<MemoryCard>(filename, m_card_index, size_mb);
} }

View File

@ -673,7 +673,7 @@ std::optional<DEntry> GCMemcard::GetDEntry(u8 index) const
BlockAlloc::BlockAlloc(u16 size_mbits) BlockAlloc::BlockAlloc(u16 size_mbits)
{ {
memset(this, 0, BLOCK_SIZE); memset(this, 0, BLOCK_SIZE);
m_free_blocks = (size_mbits * MBIT_TO_BLOCKS) - MC_FST_BLOCKS; m_free_blocks = MbitToFreeBlocks(size_mbits);
m_last_allocated_block = 4; m_last_allocated_block = 4;
FixChecksums(); FixChecksums();
} }

View File

@ -141,6 +141,11 @@ constexpr u8 MEMORY_CARD_ICON_FORMAT_CI8_UNIQUE_PALETTE = 3;
// each palette entry is 16 bits in RGB5A3 format // each palette entry is 16 bits in RGB5A3 format
constexpr u32 MEMORY_CARD_CI8_PALETTE_ENTRIES = 256; constexpr u32 MEMORY_CARD_CI8_PALETTE_ENTRIES = 256;
constexpr u32 MbitToFreeBlocks(u16 size_mb)
{
return size_mb * MBIT_TO_BLOCKS - MC_FST_BLOCKS;
}
struct GCMBlock struct GCMBlock
{ {
GCMBlock(); GCMBlock();

View File

@ -203,8 +203,7 @@ GCMemcardDirectory::GCMemcardDirectory(const std::string& directory, int slot,
} }
// leave about 10% of free space on the card if possible // leave about 10% of free space on the card if possible
const int total_blocks = const int total_blocks = Memcard::MbitToFreeBlocks(m_hdr.m_data.m_size_mb);
m_hdr.m_data.m_size_mb * Memcard::MBIT_TO_BLOCKS - Memcard::MC_FST_BLOCKS;
const int reserved_blocks = total_blocks / 10; const int reserved_blocks = total_blocks / 10;
// load files for other games // load files for other games

View File

@ -39,6 +39,7 @@
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
#include "Core/GeckoCode.h" #include "Core/GeckoCode.h"
#include "Core/HW/EXI/EXI_DeviceIPL.h" #include "Core/HW/EXI/EXI_DeviceIPL.h"
#include "Core/HW/GCMemcard/GCMemcard.h"
#include "Core/HW/SI/SI.h" #include "Core/HW/SI/SI.h"
#include "Core/HW/SI/SI_Device.h" #include "Core/HW/SI/SI_Device.h"
#include "Core/HW/SI/SI_DeviceGCController.h" #include "Core/HW/SI/SI_DeviceGCController.h"
@ -856,8 +857,8 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
bool is_slot_a; bool is_slot_a;
std::string region; std::string region;
bool mc251; int size_override;
packet >> is_slot_a >> region >> mc251; packet >> is_slot_a >> region >> size_override;
// This check is mainly intended to filter out characters which have special meanings in paths // This check is mainly intended to filter out characters which have special meanings in paths
if (region != JAP_DIR && region != USA_DIR && region != EUR_DIR) if (region != JAP_DIR && region != USA_DIR && region != EUR_DIR)
@ -866,8 +867,15 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
return 0; return 0;
} }
std::string size_suffix;
if (size_override >= 0 && size_override <= 4)
{
size_suffix = fmt::format(
".{}", Memcard::MbitToFreeBlocks(Memcard::MBIT_SIZE_MEMORY_CARD_59 << size_override));
}
const std::string path = File::GetUserPath(D_GCUSER_IDX) + GC_MEMCARD_NETPLAY + const std::string path = File::GetUserPath(D_GCUSER_IDX) + GC_MEMCARD_NETPLAY +
(is_slot_a ? "A." : "B.") + region + (mc251 ? ".251" : "") + ".raw"; (is_slot_a ? "A." : "B.") + region + size_suffix + ".raw";
if (File::Exists(path) && !File::Delete(path)) if (File::Exists(path) && !File::Delete(path))
{ {
PanicAlertFmtT("Failed to delete NetPlay memory card. Verify your write permissions."); PanicAlertFmtT("Failed to delete NetPlay memory card. Verify your write permissions.");

View File

@ -41,6 +41,7 @@
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
#include "Core/GeckoCode.h" #include "Core/GeckoCode.h"
#include "Core/GeckoCodeConfig.h" #include "Core/GeckoCodeConfig.h"
#include "Core/HW/GCMemcard/GCMemcard.h"
#include "Core/HW/GCMemcard/GCMemcardDirectory.h" #include "Core/HW/GCMemcard/GCMemcardDirectory.h"
#include "Core/HW/GCMemcard/GCMemcardRaw.h" #include "Core/HW/GCMemcard/GCMemcardRaw.h"
#include "Core/HW/Sram.h" #include "Core/HW/Sram.h"
@ -1572,17 +1573,21 @@ bool NetPlayServer::SyncSaveData()
MemoryCard::CheckPath(path, region, is_slot_a); MemoryCard::CheckPath(path, region, is_slot_a);
bool mc251; int size_override;
IniFile gameIni = SConfig::LoadGameIni(game->GetGameID(), game->GetRevision()); IniFile gameIni = SConfig::LoadGameIni(game->GetGameID(), game->GetRevision());
gameIni.GetOrCreateSection("Core")->Get("MemoryCard251", &mc251, false); gameIni.GetOrCreateSection("Core")->Get("MemoryCardSize", &size_override, -1);
if (mc251) if (size_override >= 0 && size_override <= 4)
path.insert(path.find_last_of('.'), ".251"); {
path.insert(path.find_last_of('.'),
fmt::format(".{}", Memcard::MbitToFreeBlocks(Memcard::MBIT_SIZE_MEMORY_CARD_59
<< size_override)));
}
sf::Packet pac; sf::Packet pac;
pac << static_cast<MessageId>(NP_MSG_SYNC_SAVE_DATA); pac << static_cast<MessageId>(NP_MSG_SYNC_SAVE_DATA);
pac << static_cast<MessageId>(SYNC_SAVE_DATA_RAW); pac << static_cast<MessageId>(SYNC_SAVE_DATA_RAW);
pac << is_slot_a << region << mc251; pac << is_slot_a << region << size_override;
if (File::Exists(path)) if (File::Exists(path))
{ {