diff --git a/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp b/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp index f610243238..adccd920fa 100644 --- a/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp +++ b/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp @@ -249,8 +249,11 @@ std::pair> GCMemcard::Open(std::str error_code |= bat_block_1_error_code; // select the in-use Dir and BAT blocks based on update counter - // TODO: Is there a special case for wraparound after 65535 block updates, or is it assumed that - // the hardware fails long before that anyway? + + // These are compared as signed values by the GC BIOS. There is no protection against overflow, so + // if one block is MAX_VAL and the other is MIN_VAL it still picks the MAX_VAL one as the active + // one, even if that results in a corrupted memory card. + // TODO: We could try to be smarter about this to rescue seemingly-corrupted cards. if (card.m_directory_blocks[0].m_update_counter >= card.m_directory_blocks[1].m_update_counter) card.m_active_directory = 0; diff --git a/Source/Core/Core/HW/GCMemcard/GCMemcard.h b/Source/Core/Core/HW/GCMemcard/GCMemcard.h index 8855a493de..50d0913787 100644 --- a/Source/Core/Core/HW/GCMemcard/GCMemcard.h +++ b/Source/Core/Core/HW/GCMemcard/GCMemcard.h @@ -311,8 +311,7 @@ struct Directory std::array m_padding; // 2 bytes at 0x1ffa: Update Counter - // TODO: What happens if this overflows? Is there a special case for preferring 0 over max value? - Common::BigEndianValue m_update_counter; + Common::BigEndianValue m_update_counter; // 2 bytes at 0x1ffc: Additive Checksum u16 m_checksum; @@ -343,7 +342,7 @@ struct BlockAlloc u16 m_checksum_inv; // 2 bytes at 0x0004: Update Counter - Common::BigEndianValue m_update_counter; + Common::BigEndianValue m_update_counter; // 2 bytes at 0x0006: Free Blocks Common::BigEndianValue m_free_blocks;