GCMemcard: Use BigEndianValue for BlockAlloc.m_update_counter.

This commit is contained in:
Admiral H. Curtiss 2018-11-19 00:12:07 +01:00
parent 0f776fb091
commit 88bdab6fe6
3 changed files with 10 additions and 10 deletions

View File

@ -219,7 +219,7 @@ void GCMemcard::InitDirBatPointers()
CurrentDir = &dir_backup;
PreviousDir = &dir;
}
if (BE16(bat.m_update_counter) > BE16(bat_backup.m_update_counter))
if (bat.m_update_counter > bat_backup.m_update_counter)
{
CurrentBat = &bat;
PreviousBat = &bat_backup;
@ -730,7 +730,7 @@ u32 GCMemcard::ImportFile(const DEntry& direntry, std::vector<GCMBlock>& saveBlo
}
UpdatedBat.m_free_blocks = BE16(BE16(UpdatedBat.m_free_blocks) - fileBlocks);
UpdatedBat.m_update_counter = BE16(BE16(UpdatedBat.m_update_counter) + 1);
UpdatedBat.m_update_counter = UpdatedBat.m_update_counter + 1;
*PreviousBat = UpdatedBat;
if (PreviousBat == &bat)
{
@ -761,7 +761,7 @@ u32 GCMemcard::RemoveFile(u8 index) // index in the directory array
BlockAlloc UpdatedBat = *CurrentBat;
if (!UpdatedBat.ClearBlocks(startingblock, numberofblocks))
return DELETE_FAIL;
UpdatedBat.m_update_counter = BE16(BE16(UpdatedBat.m_update_counter) + 1);
UpdatedBat.m_update_counter = UpdatedBat.m_update_counter + 1;
*PreviousBat = UpdatedBat;
if (PreviousBat == &bat)
{

View File

@ -253,12 +253,12 @@ static_assert(sizeof(Directory) == BLOCK_SIZE);
struct BlockAlloc
{
u16 m_checksum; // 0x0000 2 Additive Checksum
u16 m_checksum_inv; // 0x0002 2 Inverse Checksum
u16 m_update_counter; // 0x0004 2 Update Counter
u16 m_free_blocks; // 0x0006 2 Free Blocks
u16 m_last_allocated_block; // 0x0008 2 Last allocated Block
u16 m_map[BAT_SIZE]; // 0x000a 0x1ff8 Map of allocated Blocks
u16 m_checksum; // 0x0000 2 Additive Checksum
u16 m_checksum_inv; // 0x0002 2 Inverse Checksum
Common::BigEndianValue<u16> m_update_counter; // 0x0004 2 Update Counter
u16 m_free_blocks; // 0x0006 2 Free Blocks
u16 m_last_allocated_block; // 0x0008 2 Last allocated Block
u16 m_map[BAT_SIZE]; // 0x000a 0x1ff8 Map of allocated Blocks
u16 GetNextBlock(u16 Block) const;
u16 NextFreeBlock(u16 MaxBlock, u16 StartingBlock = MC_FST_BLOCKS) const;
bool ClearBlocks(u16 StartingBlock, u16 Length);

View File

@ -549,7 +549,7 @@ s32 GCMemcardDirectory::DirectoryWrite(u32 dest_address, u32 length, const u8* s
bool GCMemcardDirectory::SetUsedBlocks(int save_index)
{
BlockAlloc* current_bat;
if (BE16(m_bat2.m_update_counter) > BE16(m_bat1.m_update_counter))
if (m_bat2.m_update_counter > m_bat1.m_update_counter)
current_bat = &m_bat2;
else
current_bat = &m_bat1;