mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-06-28 09:59:32 -06:00
Merge pull request #13585 from tygyh/Core/HW/GCMemcard-Make-variables-constant
Core/HW/GCMemcard: Make variables constant
This commit is contained in:
@ -289,7 +289,7 @@ const BlockAlloc& GCMemcard::GetActiveBat() const
|
|||||||
void GCMemcard::UpdateDirectory(const Directory& directory)
|
void GCMemcard::UpdateDirectory(const Directory& directory)
|
||||||
{
|
{
|
||||||
// overwrite inactive dir with given data, then set active dir to written block
|
// overwrite inactive dir with given data, then set active dir to written block
|
||||||
int new_directory_index = m_active_directory == 0 ? 1 : 0;
|
const int new_directory_index = m_active_directory == 0 ? 1 : 0;
|
||||||
m_directory_blocks[new_directory_index] = directory;
|
m_directory_blocks[new_directory_index] = directory;
|
||||||
m_active_directory = new_directory_index;
|
m_active_directory = new_directory_index;
|
||||||
}
|
}
|
||||||
@ -297,7 +297,7 @@ void GCMemcard::UpdateDirectory(const Directory& directory)
|
|||||||
void GCMemcard::UpdateBat(const BlockAlloc& bat)
|
void GCMemcard::UpdateBat(const BlockAlloc& bat)
|
||||||
{
|
{
|
||||||
// overwrite inactive BAT with given data, then set active BAT to written block
|
// overwrite inactive BAT with given data, then set active BAT to written block
|
||||||
int new_bat_index = m_active_bat == 0 ? 1 : 0;
|
const int new_bat_index = m_active_bat == 0 ? 1 : 0;
|
||||||
m_bat_blocks[new_bat_index] = bat;
|
m_bat_blocks[new_bat_index] = bat;
|
||||||
m_active_bat = new_bat_index;
|
m_active_bat = new_bat_index;
|
||||||
}
|
}
|
||||||
@ -333,7 +333,7 @@ static std::pair<u16, u16> CalculateMemcardChecksums(const u8* data, size_t size
|
|||||||
|
|
||||||
for (size_t i = 0; i < size; i += 2)
|
for (size_t i = 0; i < size; i += 2)
|
||||||
{
|
{
|
||||||
u16 d = Common::swap16(&data[i]);
|
const u16 d = Common::swap16(&data[i]);
|
||||||
csum += d;
|
csum += d;
|
||||||
inv_csum += static_cast<u16>(d ^ 0xffff);
|
inv_csum += static_cast<u16>(d ^ 0xffff);
|
||||||
}
|
}
|
||||||
@ -434,7 +434,7 @@ u16 GCMemcard::DEntry_FirstBlock(u8 index) const
|
|||||||
if (!m_valid || index >= DIRLEN)
|
if (!m_valid || index >= DIRLEN)
|
||||||
return 0xFFFF;
|
return 0xFFFF;
|
||||||
|
|
||||||
u16 block = GetActiveDirectory().m_dir_entries[index].m_first_block;
|
const u16 block = GetActiveDirectory().m_dir_entries[index].m_first_block;
|
||||||
if (block > (u16)m_size_blocks)
|
if (block > (u16)m_size_blocks)
|
||||||
return 0xFFFF;
|
return 0xFFFF;
|
||||||
return block;
|
return block;
|
||||||
@ -445,7 +445,7 @@ u16 GCMemcard::DEntry_BlockCount(u8 index) const
|
|||||||
if (!m_valid || index >= DIRLEN)
|
if (!m_valid || index >= DIRLEN)
|
||||||
return 0xFFFF;
|
return 0xFFFF;
|
||||||
|
|
||||||
u16 blocks = GetActiveDirectory().m_dir_entries[index].m_block_count;
|
const u16 blocks = GetActiveDirectory().m_dir_entries[index].m_block_count;
|
||||||
if (blocks > (u16)m_size_blocks)
|
if (blocks > (u16)m_size_blocks)
|
||||||
return 0xFFFF;
|
return 0xFFFF;
|
||||||
return blocks;
|
return blocks;
|
||||||
@ -594,7 +594,7 @@ bool BlockAlloc::ClearBlocks(u16 starting_block, u16 block_count)
|
|||||||
}
|
}
|
||||||
if (starting_block > 0)
|
if (starting_block > 0)
|
||||||
{
|
{
|
||||||
size_t length = blocks.size();
|
const size_t length = blocks.size();
|
||||||
if (length != block_count)
|
if (length != block_count)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@ -615,7 +615,7 @@ void BlockAlloc::FixChecksums()
|
|||||||
|
|
||||||
u16 BlockAlloc::AssignBlocksContiguous(u16 length)
|
u16 BlockAlloc::AssignBlocksContiguous(u16 length)
|
||||||
{
|
{
|
||||||
u16 starting = m_last_allocated_block + 1;
|
const u16 starting = m_last_allocated_block + 1;
|
||||||
if (length > m_free_blocks)
|
if (length > m_free_blocks)
|
||||||
return 0xFFFF;
|
return 0xFFFF;
|
||||||
u16 current = starting;
|
u16 current = starting;
|
||||||
@ -753,7 +753,7 @@ GCMemcardImportFileRetVal GCMemcard::ImportFile(const Savefile& savefile)
|
|||||||
UpdatedDir.m_update_counter = UpdatedDir.m_update_counter + 1;
|
UpdatedDir.m_update_counter = UpdatedDir.m_update_counter + 1;
|
||||||
UpdateDirectory(UpdatedDir);
|
UpdateDirectory(UpdatedDir);
|
||||||
|
|
||||||
int fileBlocks = direntry.m_block_count;
|
const int fileBlocks = direntry.m_block_count;
|
||||||
|
|
||||||
std::vector<GCMBlock> blocks = savefile.blocks;
|
std::vector<GCMBlock> blocks = savefile.blocks;
|
||||||
FZEROGX_MakeSaveGameValid(m_header_block, direntry, blocks);
|
FZEROGX_MakeSaveGameValid(m_header_block, direntry, blocks);
|
||||||
@ -808,8 +808,8 @@ GCMemcardRemoveFileRetVal GCMemcard::RemoveFile(u8 index) // index in the direc
|
|||||||
if (index >= DIRLEN)
|
if (index >= DIRLEN)
|
||||||
return GCMemcardRemoveFileRetVal::DELETE_FAIL;
|
return GCMemcardRemoveFileRetVal::DELETE_FAIL;
|
||||||
|
|
||||||
u16 startingblock = GetActiveDirectory().m_dir_entries[index].m_first_block;
|
const u16 startingblock = GetActiveDirectory().m_dir_entries[index].m_first_block;
|
||||||
u16 numberofblocks = GetActiveDirectory().m_dir_entries[index].m_block_count;
|
const u16 numberofblocks = GetActiveDirectory().m_dir_entries[index].m_block_count;
|
||||||
|
|
||||||
BlockAlloc UpdatedBat = GetActiveBat();
|
BlockAlloc UpdatedBat = GetActiveBat();
|
||||||
if (!UpdatedBat.ClearBlocks(startingblock, numberofblocks))
|
if (!UpdatedBat.ClearBlocks(startingblock, numberofblocks))
|
||||||
@ -953,7 +953,7 @@ std::optional<std::vector<GCMemcardAnimationFrameRGBA8>> GCMemcard::ReadAnimRGBA
|
|||||||
|
|
||||||
// now that we have determined the data length, fetch the actual data from the save file
|
// now that we have determined the data length, fetch the actual data from the save file
|
||||||
// if anything is sketchy, bail so we don't access out of bounds
|
// if anything is sketchy, bail so we don't access out of bounds
|
||||||
auto save_data_bytes = GetSaveDataBytes(index, image_offset, data_length);
|
const auto save_data_bytes = GetSaveDataBytes(index, image_offset, data_length);
|
||||||
if (!save_data_bytes || save_data_bytes->size() != data_length)
|
if (!save_data_bytes || save_data_bytes->size() != data_length)
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
|
||||||
@ -1022,9 +1022,9 @@ bool GCMemcard::Format(u8* card_data, const CardFlashId& flash_id, u16 size_mbit
|
|||||||
if (!card_data)
|
if (!card_data)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Header header(flash_id, size_mbits, shift_jis, rtc_bias, sram_language, format_time);
|
const Header header(flash_id, size_mbits, shift_jis, rtc_bias, sram_language, format_time);
|
||||||
Directory dir;
|
const Directory dir;
|
||||||
BlockAlloc bat(size_mbits);
|
const BlockAlloc bat(size_mbits);
|
||||||
|
|
||||||
std::memcpy(&card_data[BLOCK_SIZE * 0], &header, BLOCK_SIZE);
|
std::memcpy(&card_data[BLOCK_SIZE * 0], &header, BLOCK_SIZE);
|
||||||
std::memcpy(&card_data[BLOCK_SIZE * 1], &dir, BLOCK_SIZE);
|
std::memcpy(&card_data[BLOCK_SIZE * 1], &dir, BLOCK_SIZE);
|
||||||
|
@ -45,7 +45,7 @@ static std::string GenerateDefaultGCIFilename(const Memcard::DEntry& entry,
|
|||||||
{
|
{
|
||||||
const auto string_decoder = card_encoding_is_shift_jis ? SHIFTJISToUTF8 : CP1252ToUTF8;
|
const auto string_decoder = card_encoding_is_shift_jis ? SHIFTJISToUTF8 : CP1252ToUTF8;
|
||||||
const auto strip_null = [](const std::string_view& s) {
|
const auto strip_null = [](const std::string_view& s) {
|
||||||
auto offset = s.find('\0');
|
const auto offset = s.find('\0');
|
||||||
if (offset == std::string_view::npos)
|
if (offset == std::string_view::npos)
|
||||||
return s;
|
return s;
|
||||||
return s.substr(0, offset);
|
return s.substr(0, offset);
|
||||||
@ -115,7 +115,7 @@ bool GCMemcardDirectory::LoadGCI(Memcard::GCIFile gci)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// actually load save file into memory card
|
// actually load save file into memory card
|
||||||
int idx = (int)m_saves.size();
|
const int idx = (int)m_saves.size();
|
||||||
m_dir1.Replace(gci.m_gci_header, idx);
|
m_dir1.Replace(gci.m_gci_header, idx);
|
||||||
m_saves.push_back(std::move(gci));
|
m_saves.push_back(std::move(gci));
|
||||||
SetUsedBlocks(idx);
|
SetUsedBlocks(idx);
|
||||||
@ -190,7 +190,7 @@ GCMemcardDirectory::GCMemcardDirectory(const std::string& directory, ExpansionIn
|
|||||||
}
|
}
|
||||||
|
|
||||||
const bool current_game_only = Config::Get(Config::SESSION_GCI_FOLDER_CURRENT_GAME_ONLY);
|
const bool current_game_only = Config::Get(Config::SESSION_GCI_FOLDER_CURRENT_GAME_ONLY);
|
||||||
std::vector<std::string> filenames = Common::DoFileSearch({m_save_directory}, {".gci"});
|
const std::vector<std::string> filenames = Common::DoFileSearch({m_save_directory}, {".gci"});
|
||||||
|
|
||||||
// split up into files for current games we should definitely load,
|
// split up into files for current games we should definitely load,
|
||||||
// and files for other games that we don't care too much about
|
// and files for other games that we don't care too much about
|
||||||
@ -298,8 +298,8 @@ GCMemcardDirectory::~GCMemcardDirectory()
|
|||||||
|
|
||||||
s32 GCMemcardDirectory::Read(u32 src_address, s32 length, u8* dest_address)
|
s32 GCMemcardDirectory::Read(u32 src_address, s32 length, u8* dest_address)
|
||||||
{
|
{
|
||||||
s32 block = src_address / Memcard::BLOCK_SIZE;
|
const s32 block = src_address / Memcard::BLOCK_SIZE;
|
||||||
u32 offset = src_address % Memcard::BLOCK_SIZE;
|
const u32 offset = src_address % Memcard::BLOCK_SIZE;
|
||||||
s32 extra = 0; // used for read calls that are across multiple blocks
|
s32 extra = 0; // used for read calls that are across multiple blocks
|
||||||
|
|
||||||
if (offset + length > Memcard::BLOCK_SIZE)
|
if (offset + length > Memcard::BLOCK_SIZE)
|
||||||
@ -358,8 +358,8 @@ s32 GCMemcardDirectory::Write(u32 dest_address, s32 length, const u8* src_addres
|
|||||||
std::unique_lock l(m_write_mutex);
|
std::unique_lock l(m_write_mutex);
|
||||||
if (length != 0x80)
|
if (length != 0x80)
|
||||||
INFO_LOG_FMT(EXPANSIONINTERFACE, "Writing to {:#x}. Length: {:#x}", dest_address, length);
|
INFO_LOG_FMT(EXPANSIONINTERFACE, "Writing to {:#x}. Length: {:#x}", dest_address, length);
|
||||||
s32 block = dest_address / Memcard::BLOCK_SIZE;
|
const s32 block = dest_address / Memcard::BLOCK_SIZE;
|
||||||
u32 offset = dest_address % Memcard::BLOCK_SIZE;
|
const u32 offset = dest_address % Memcard::BLOCK_SIZE;
|
||||||
s32 extra = 0; // used for write calls that are across multiple blocks
|
s32 extra = 0; // used for write calls that are across multiple blocks
|
||||||
|
|
||||||
if (offset + length > Memcard::BLOCK_SIZE)
|
if (offset + length > Memcard::BLOCK_SIZE)
|
||||||
@ -386,7 +386,7 @@ s32 GCMemcardDirectory::Write(u32 dest_address, s32 length, const u8* src_addres
|
|||||||
s32 bytes_written = 0;
|
s32 bytes_written = 0;
|
||||||
while (length > 0)
|
while (length > 0)
|
||||||
{
|
{
|
||||||
s32 to_write = std::min<s32>(Memcard::DENTRY_SIZE, length);
|
const s32 to_write = std::min<s32>(Memcard::DENTRY_SIZE, length);
|
||||||
bytes_written +=
|
bytes_written +=
|
||||||
DirectoryWrite(dest_address + bytes_written, to_write, src_address + bytes_written);
|
DirectoryWrite(dest_address + bytes_written, to_write, src_address + bytes_written);
|
||||||
length -= to_write;
|
length -= to_write;
|
||||||
@ -536,7 +536,7 @@ inline s32 GCMemcardDirectory::SaveAreaRW(u32 block, bool writing)
|
|||||||
SetUsedBlocks(i);
|
SetUsedBlocks(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
int idx = m_saves[i].UsesBlock(block);
|
const int idx = m_saves[i].UsesBlock(block);
|
||||||
if (idx != -1)
|
if (idx != -1)
|
||||||
{
|
{
|
||||||
if (!m_saves[i].LoadSaveBlocks())
|
if (!m_saves[i].LoadSaveBlocks())
|
||||||
@ -565,10 +565,10 @@ inline s32 GCMemcardDirectory::SaveAreaRW(u32 block, bool writing)
|
|||||||
|
|
||||||
s32 GCMemcardDirectory::DirectoryWrite(u32 dest_address, u32 length, const u8* src_address)
|
s32 GCMemcardDirectory::DirectoryWrite(u32 dest_address, u32 length, const u8* src_address)
|
||||||
{
|
{
|
||||||
u32 block = dest_address / Memcard::BLOCK_SIZE;
|
const u32 block = dest_address / Memcard::BLOCK_SIZE;
|
||||||
u32 offset = dest_address % Memcard::BLOCK_SIZE;
|
const u32 offset = dest_address % Memcard::BLOCK_SIZE;
|
||||||
Memcard::Directory* dest = (block == 1) ? &m_dir1 : &m_dir2;
|
Memcard::Directory* dest = (block == 1) ? &m_dir1 : &m_dir2;
|
||||||
u16 Dnum = offset / Memcard::DENTRY_SIZE;
|
const u16 Dnum = offset / Memcard::DENTRY_SIZE;
|
||||||
|
|
||||||
if (Dnum == Memcard::DIRLEN)
|
if (Dnum == Memcard::DIRLEN)
|
||||||
{
|
{
|
||||||
|
@ -60,7 +60,7 @@ MemoryCard::MemoryCard(const std::string& filename, ExpansionInterface::Slot car
|
|||||||
m_memcard_data = std::make_unique<u8[]>(m_memory_card_size);
|
m_memcard_data = std::make_unique<u8[]>(m_memory_card_size);
|
||||||
|
|
||||||
// Fills in the first 5 blocks (MC_HDR_SIZE bytes)
|
// Fills in the first 5 blocks (MC_HDR_SIZE bytes)
|
||||||
auto& sram = Core::System::GetInstance().GetSRAM();
|
const auto& sram = Core::System::GetInstance().GetSRAM();
|
||||||
const CardFlashId& flash_id = sram.settings_ex.flash_id[Memcard::SLOT_A];
|
const CardFlashId& flash_id = sram.settings_ex.flash_id[Memcard::SLOT_A];
|
||||||
const bool shift_jis = m_filename.find(".JAP.raw") != std::string::npos;
|
const bool shift_jis = m_filename.find(".JAP.raw") != std::string::npos;
|
||||||
const u32 rtc_bias = sram.settings.rtc_bias;
|
const u32 rtc_bias = sram.settings.rtc_bias;
|
||||||
@ -107,10 +107,10 @@ void MemoryCard::FlushThread()
|
|||||||
{
|
{
|
||||||
// If triggered, we're exiting.
|
// If triggered, we're exiting.
|
||||||
// If timed out, check if we need to flush.
|
// If timed out, check if we need to flush.
|
||||||
bool do_exit = m_flush_trigger.WaitFor(flush_interval);
|
const bool do_exit = m_flush_trigger.WaitFor(flush_interval);
|
||||||
if (!do_exit)
|
if (!do_exit)
|
||||||
{
|
{
|
||||||
bool is_dirty = m_dirty.TestAndClear();
|
const bool is_dirty = m_dirty.TestAndClear();
|
||||||
if (!is_dirty)
|
if (!is_dirty)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
@ -32,7 +32,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
bool IsAddressInBounds(u32 address, u32 length) const
|
bool IsAddressInBounds(u32 address, u32 length) const
|
||||||
{
|
{
|
||||||
u64 end_address = static_cast<u64>(address) + static_cast<u64>(length);
|
const u64 end_address = static_cast<u64>(address) + static_cast<u64>(length);
|
||||||
return end_address <= static_cast<u64>(m_memory_card_size);
|
return end_address <= static_cast<u64>(m_memory_card_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ bool HasDuplicateIdentity(std::span<const Savefile> savefiles)
|
|||||||
static void ByteswapDEntrySavHeader(std::array<u8, DENTRY_SIZE>& entry)
|
static void ByteswapDEntrySavHeader(std::array<u8, DENTRY_SIZE>& entry)
|
||||||
{
|
{
|
||||||
// several bytes in SAV are swapped compared to the internal memory card format
|
// several bytes in SAV are swapped compared to the internal memory card format
|
||||||
for (size_t p : {0x06, 0x2C, 0x2E, 0x30, 0x32, 0x34, 0x36, 0x38, 0x3A, 0x3C, 0x3E})
|
for (const size_t p : {0x06, 0x2C, 0x2E, 0x30, 0x32, 0x34, 0x36, 0x38, 0x3A, 0x3C, 0x3E})
|
||||||
std::swap(entry[p], entry[p + 1]);
|
std::swap(entry[p], entry[p + 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,10 +304,10 @@ bool WriteSavefile(const std::string& filename, const Savefile& savefile, Savefi
|
|||||||
|
|
||||||
std::string GenerateFilename(const DEntry& entry)
|
std::string GenerateFilename(const DEntry& entry)
|
||||||
{
|
{
|
||||||
std::string maker(reinterpret_cast<const char*>(entry.m_makercode.data()),
|
const std::string maker(reinterpret_cast<const char*>(entry.m_makercode.data()),
|
||||||
entry.m_makercode.size());
|
entry.m_makercode.size());
|
||||||
std::string gamecode(reinterpret_cast<const char*>(entry.m_gamecode.data()),
|
const std::string gamecode(reinterpret_cast<const char*>(entry.m_gamecode.data()),
|
||||||
entry.m_gamecode.size());
|
entry.m_gamecode.size());
|
||||||
|
|
||||||
// prevent going out of bounds when all bytes of m_filename are non-null
|
// prevent going out of bounds when all bytes of m_filename are non-null
|
||||||
size_t length = 0;
|
size_t length = 0;
|
||||||
@ -317,7 +317,7 @@ std::string GenerateFilename(const DEntry& entry)
|
|||||||
break;
|
break;
|
||||||
++length;
|
++length;
|
||||||
}
|
}
|
||||||
std::string filename(reinterpret_cast<const char*>(entry.m_filename.data()), length);
|
const std::string filename(reinterpret_cast<const char*>(entry.m_filename.data()), length);
|
||||||
|
|
||||||
return Common::EscapeFileName(maker + '-' + gamecode + '-' + filename);
|
return Common::EscapeFileName(maker + '-' + gamecode + '-' + filename);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user