From d3b61c3ff05cd6c9769c29c5a0db722201371e65 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Mon, 19 Nov 2018 00:17:49 +0100 Subject: [PATCH] GCMemcard: Use BigEndianValue for BlockAlloc.m_free_blocks. --- Source/Core/Core/HW/GCMemcard/GCMemcard.cpp | 10 +++++----- Source/Core/Core/HW/GCMemcard/GCMemcard.h | 8 ++++---- Source/Core/Core/HW/GCMemcard/GCMemcardDirectory.cpp | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp b/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp index 25af228b23..bf42643d04 100644 --- a/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp +++ b/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp @@ -359,7 +359,7 @@ u16 GCMemcard::GetFreeBlocks() const if (!m_valid) return 0; - return BE16(CurrentBat->m_free_blocks); + return CurrentBat->m_free_blocks; } u8 GCMemcard::TitlePresent(const DEntry& d) const @@ -593,7 +593,7 @@ u16 BlockAlloc::GetNextBlock(u16 Block) const // not BAT index; that is, block 5 is the first file data block. u16 BlockAlloc::NextFreeBlock(u16 MaxBlock, u16 StartingBlock) const { - if (m_free_blocks) + if (m_free_blocks > 0) { StartingBlock = MathUtil::Clamp(StartingBlock, MC_FST_BLOCKS, BAT_SIZE + MC_FST_BLOCKS); MaxBlock = MathUtil::Clamp(MaxBlock, MC_FST_BLOCKS, BAT_SIZE + MC_FST_BLOCKS); @@ -625,7 +625,7 @@ bool BlockAlloc::ClearBlocks(u16 FirstBlock, u16 BlockCount) } for (unsigned int i = 0; i < length; ++i) m_map[blocks.at(i) - MC_FST_BLOCKS] = 0; - m_free_blocks = BE16(BE16(m_free_blocks) + BlockCount); + m_free_blocks = m_free_blocks + BlockCount; return true; } @@ -667,7 +667,7 @@ u32 GCMemcard::ImportFile(const DEntry& direntry, std::vector& saveBlo { return OUTOFDIRENTRIES; } - if (BE16(CurrentBat->m_free_blocks) < direntry.m_block_count) + if (CurrentBat->m_free_blocks < direntry.m_block_count) { return OUTOFBLOCKS; } @@ -729,7 +729,7 @@ u32 GCMemcard::ImportFile(const DEntry& direntry, std::vector& saveBlo firstBlock = nextBlock; } - UpdatedBat.m_free_blocks = BE16(BE16(UpdatedBat.m_free_blocks) - fileBlocks); + UpdatedBat.m_free_blocks = UpdatedBat.m_free_blocks - fileBlocks; UpdatedBat.m_update_counter = UpdatedBat.m_update_counter + 1; *PreviousBat = UpdatedBat; if (PreviousBat == &bat) diff --git a/Source/Core/Core/HW/GCMemcard/GCMemcard.h b/Source/Core/Core/HW/GCMemcard/GCMemcard.h index fc8bc702c0..0498f1c448 100644 --- a/Source/Core/Core/HW/GCMemcard/GCMemcard.h +++ b/Source/Core/Core/HW/GCMemcard/GCMemcard.h @@ -256,7 +256,7 @@ struct BlockAlloc u16 m_checksum; // 0x0000 2 Additive Checksum u16 m_checksum_inv; // 0x0002 2 Inverse Checksum Common::BigEndianValue m_update_counter; // 0x0004 2 Update Counter - u16 m_free_blocks; // 0x0006 2 Free Blocks + Common::BigEndianValue 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; @@ -269,14 +269,14 @@ struct BlockAlloc explicit BlockAlloc(u16 sizeMb = MemCard2043Mb) { memset(this, 0, BLOCK_SIZE); - m_free_blocks = BE16((sizeMb * MBIT_TO_BLOCKS) - MC_FST_BLOCKS); + m_free_blocks = (sizeMb * MBIT_TO_BLOCKS) - MC_FST_BLOCKS; m_last_allocated_block = BE16(4); fixChecksums(); } u16 AssignBlocksContiguous(u16 length) { u16 starting = BE16(m_last_allocated_block) + 1; - if (length > BE16(m_free_blocks)) + if (length > m_free_blocks) return 0xFFFF; u16 current = starting; while ((current - starting + 1) < length) @@ -286,7 +286,7 @@ struct BlockAlloc } m_map[current - 5] = 0xFFFF; m_last_allocated_block = BE16(current); - m_free_blocks = BE16(BE16(m_free_blocks) - length); + m_free_blocks = m_free_blocks - length; fixChecksums(); return starting; } diff --git a/Source/Core/Core/HW/GCMemcard/GCMemcardDirectory.cpp b/Source/Core/Core/HW/GCMemcard/GCMemcardDirectory.cpp index 4d18f221aa..45ee63f976 100644 --- a/Source/Core/Core/HW/GCMemcard/GCMemcardDirectory.cpp +++ b/Source/Core/Core/HW/GCMemcard/GCMemcardDirectory.cpp @@ -90,7 +90,7 @@ int GCMemcardDirectory::LoadGCI(const std::string& file_name, bool current_game_ return NO_INDEX; } int total_blocks = m_hdr.m_size_mb * MBIT_TO_BLOCKS - MC_FST_BLOCKS; - int free_blocks = BE16(m_bat1.m_free_blocks); + int free_blocks = m_bat1.m_free_blocks; if (total_blocks > free_blocks * 10) { PanicAlertT("%s\nwas not loaded because there is less than 10%% free blocks available on "