GCMemcard: Remove byteswapping macros

We can just specify the functions directly instead of relying on
preprocessor textual replacement.
This commit is contained in:
Lioncash 2019-11-27 22:54:50 -05:00
parent 1f1a02151e
commit e33c366502
4 changed files with 24 additions and 27 deletions

View File

@ -166,7 +166,9 @@ void CEXIMemoryCard::SetupGciFolder(u16 sizeMb)
u32 CurrentGameId = 0;
if (game_id.length() >= 4 && game_id != "00000000" &&
SConfig::GetInstance().GetTitleID() != Titles::SYSTEM_MENU)
CurrentGameId = BE32((u8*)game_id.c_str());
{
CurrentGameId = Common::swap32(reinterpret_cast<const u8*>(game_id.c_str()));
}
const bool shift_jis = region == DiscIO::Region::NTSC_J;

View File

@ -815,9 +815,8 @@ GCMemcardGetSaveDataRetVal GCMemcard::GetSaveData(u8 index, std::vector<GCMBlock
if (!m_valid)
return GCMemcardGetSaveDataRetVal::NOMEMCARD;
u16 block = DEntry_FirstBlock(index);
u16 BlockCount = DEntry_BlockCount(index);
// u16 memcardSize = BE16(hdr.m_size_mb) * MBIT_TO_BLOCKS;
const u16 block = DEntry_FirstBlock(index);
const u16 BlockCount = DEntry_BlockCount(index);
if ((block == 0xFFFF) || (BlockCount == 0xFFFF))
{
@ -1427,10 +1426,10 @@ s32 GCMemcard::FZEROGX_MakeSaveGameValid(const Header& cardheader, const DEntry&
const auto [serial1, serial2] = cardheader.CalculateSerial();
// set new serial numbers
*(u16*)&FileBuffer[1].m_block[0x0066] = BE16(BE32(serial1) >> 16);
*(u16*)&FileBuffer[3].m_block[0x1580] = BE16(BE32(serial2) >> 16);
*(u16*)&FileBuffer[1].m_block[0x0060] = BE16(BE32(serial1) & 0xFFFF);
*(u16*)&FileBuffer[1].m_block[0x0200] = BE16(BE32(serial2) & 0xFFFF);
*(u16*)&FileBuffer[1].m_block[0x0066] = Common::swap16(u16(Common::swap32(serial1) >> 16));
*(u16*)&FileBuffer[3].m_block[0x1580] = Common::swap16(u16(Common::swap32(serial2) >> 16));
*(u16*)&FileBuffer[1].m_block[0x0060] = Common::swap16(u16(Common::swap32(serial1) & 0xFFFF));
*(u16*)&FileBuffer[1].m_block[0x0200] = Common::swap16(u16(Common::swap32(serial2) & 0xFFFF));
// calc 16-bit checksum
for (i = 0x02; i < 0x8000; i++)
@ -1448,7 +1447,7 @@ s32 GCMemcard::FZEROGX_MakeSaveGameValid(const Header& cardheader, const DEntry&
}
// set new checksum
*(u16*)&FileBuffer[0].m_block[0x00] = BE16(~chksum);
*(u16*)&FileBuffer[0].m_block[0x00] = Common::swap16(u16(~chksum));
return 1;
}
@ -1520,7 +1519,7 @@ s32 GCMemcard::PSO_MakeSaveGameValid(const Header& cardheader, const DEntry& dir
}
// set new checksum
*(u32*)&FileBuffer[1].m_block[0x0048] = BE32(chksum ^ 0xFFFFFFFF);
*(u32*)&FileBuffer[1].m_block[0x0048] = Common::swap32(chksum ^ 0xFFFFFFFF);
return 1;
}
@ -1639,7 +1638,7 @@ Directory::Directory()
{
memset(this, 0xFF, BLOCK_SIZE);
m_update_counter = 0;
m_checksum = BE16(0xF003);
m_checksum = Common::swap16(0xF003);
m_checksum_inv = 0;
}

View File

@ -24,10 +24,6 @@ namespace File
class IOFile;
}
#define BE64(x) (Common::swap64(x))
#define BE32(x) (Common::swap32(x))
#define BE16(x) (Common::swap16(x))
enum
{
SLOT_A = 0,

View File

@ -102,7 +102,7 @@ std::vector<std::string> GCMemcardDirectory::GetFileNamesForGameID(const std::st
u32 game_code = 0;
if (game_id.length() >= 4 && game_id != "00000000")
game_code = BE32(reinterpret_cast<const u8*>(game_id.c_str()));
game_code = Common::swap32(reinterpret_cast<const u8*>(game_id.c_str()));
std::vector<std::string> loaded_saves;
for (const std::string& file_name : Common::DoFileSearch({directory}, {".gci"}))
@ -136,7 +136,7 @@ std::vector<std::string> GCMemcardDirectory::GetFileNamesForGameID(const std::st
// card (see above method), but since we're only loading the saves for one GameID here, we're
// definitely not going to run out of space.
if (game_code == BE32(gci.m_gci_header.m_gamecode.data()))
if (game_code == Common::swap32(gci.m_gci_header.m_gamecode.data()))
{
loaded_saves.push_back(gci_filename);
filenames.push_back(file_name);
@ -175,7 +175,7 @@ GCMemcardDirectory::GCMemcardDirectory(const std::string& directory, int slot, u
continue;
}
if (m_game_id == BE32(gci.m_gci_header.m_gamecode.data()))
if (m_game_id == Common::swap32(gci.m_gci_header.m_gamecode.data()))
gci_current_game.emplace_back(std::move(gci));
else if (!current_game_only)
gci_other_games.emplace_back(std::move(gci));
@ -443,7 +443,7 @@ inline void GCMemcardDirectory::SyncSaves()
if (current->m_dir_entries[i].m_gamecode != DEntry::UNINITIALIZED_GAMECODE)
{
INFO_LOG(EXPANSIONINTERFACE, "Syncing save 0x%x",
BE32(current->m_dir_entries[i].m_gamecode.data()));
Common::swap32(current->m_dir_entries[i].m_gamecode.data()));
bool added = false;
while (i >= m_saves.size())
{
@ -456,16 +456,16 @@ inline void GCMemcardDirectory::SyncSaves()
memcmp((u8*)&(m_saves[i].m_gci_header), (u8*)&(current->m_dir_entries[i]), DENTRY_SIZE))
{
m_saves[i].m_dirty = true;
u32 gamecode = BE32(m_saves[i].m_gci_header.m_gamecode.data());
u32 new_gamecode = BE32(current->m_dir_entries[i].m_gamecode.data());
u32 old_start = m_saves[i].m_gci_header.m_first_block;
u32 new_start = current->m_dir_entries[i].m_first_block;
const u32 gamecode = Common::swap32(m_saves[i].m_gci_header.m_gamecode.data());
const u32 new_gamecode = Common::swap32(current->m_dir_entries[i].m_gamecode.data());
const u32 old_start = m_saves[i].m_gci_header.m_first_block;
const u32 new_start = current->m_dir_entries[i].m_first_block;
if ((gamecode != 0xFFFFFFFF) && (gamecode != new_gamecode))
{
PanicAlertT("Game overwrote with another games save. Data corruption ahead 0x%x, 0x%x",
BE32(m_saves[i].m_gci_header.m_gamecode.data()),
BE32(current->m_dir_entries[i].m_gamecode.data()));
Common::swap32(m_saves[i].m_gci_header.m_gamecode.data()),
Common::swap32(current->m_dir_entries[i].m_gamecode.data()));
}
memcpy((u8*)&(m_saves[i].m_gci_header), (u8*)&(current->m_dir_entries[i]), DENTRY_SIZE);
if (old_start != new_start)
@ -483,7 +483,7 @@ inline void GCMemcardDirectory::SyncSaves()
else if ((i < m_saves.size()) && (*(u32*)&(m_saves[i].m_gci_header) != 0xFFFFFFFF))
{
INFO_LOG(EXPANSIONINTERFACE, "Clearing and/or deleting save 0x%x",
BE32(m_saves[i].m_gci_header.m_gamecode.data()));
Common::swap32(m_saves[i].m_gci_header.m_gamecode.data()));
m_saves[i].m_gci_header.m_gamecode = DEntry::UNINITIALIZED_GAMECODE;
m_saves[i].m_save_data.clear();
m_saves[i].m_used_blocks.clear();
@ -660,7 +660,7 @@ void GCMemcardDirectory::FlushToFile()
// simultaneously
// this ensures that the save data for all of the current games gci files are stored in the
// savestate
u32 gamecode = BE32(m_saves[i].m_gci_header.m_gamecode.data());
const u32 gamecode = Common::swap32(m_saves[i].m_gci_header.m_gamecode.data());
if (gamecode != m_game_id && gamecode != 0xFFFFFFFF && !m_saves[i].m_save_data.empty())
{
INFO_LOG(EXPANSIONINTERFACE, "Flushing savedata to disk for %s",