Skip to content

Commit

Permalink
GCMemcard: Use BigEndianValue for BlockAlloc.m_update_counter.
Browse files Browse the repository at this point in the history
  • Loading branch information
AdmiralCurtiss committed Dec 9, 2018
1 parent 0f776fb commit 88bdab6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Source/Core/Core/HW/GCMemcard/GCMemcard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
12 changes: 6 additions & 6 deletions Source/Core/Core/HW/GCMemcard/GCMemcard.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/HW/GCMemcard/GCMemcardDirectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 88bdab6

Please sign in to comment.