Skip to content
Permalink
Browse files

GCMemcard: Use BigEndianValue for BlockAlloc.m_last_allocated_block.

  • Loading branch information...
AdmiralCurtiss committed Nov 18, 2018
1 parent d3b61c3 commit eb6cc3dbab0fe71bf67162a34211fd35c4fdba0c
Showing with 11 additions and 12 deletions.
  1. +2 −3 Source/Core/Core/HW/GCMemcard/GCMemcard.cpp
  2. +9 −9 Source/Core/Core/HW/GCMemcard/GCMemcard.h
@@ -677,8 +677,7 @@ u32 GCMemcard::ImportFile(const DEntry& direntry, std::vector<GCMBlock>& saveBlo
}

// find first free data block
u16 firstBlock =
CurrentBat->NextFreeBlock(maxBlock, BE16(CurrentBat->m_last_allocated_block));
u16 firstBlock = CurrentBat->NextFreeBlock(maxBlock, CurrentBat->m_last_allocated_block);
if (firstBlock == 0xFFFF)
return OUTOFBLOCKS;
Directory UpdatedDir = *CurrentDir;
@@ -725,7 +724,7 @@ u32 GCMemcard::ImportFile(const DEntry& direntry, std::vector<GCMBlock>& saveBlo
else
nextBlock = UpdatedBat.NextFreeBlock(maxBlock, firstBlock + 1);
UpdatedBat.m_map[firstBlock - MC_FST_BLOCKS] = BE16(nextBlock);
UpdatedBat.m_last_allocated_block = BE16(firstBlock);
UpdatedBat.m_last_allocated_block = firstBlock;
firstBlock = nextBlock;
}

@@ -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
Common::BigEndianValue<u16> m_update_counter; // 0x0004 2 Update Counter
Common::BigEndianValue<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
Common::BigEndianValue<u16> m_free_blocks; // 0x0006 2 Free Blocks
Common::BigEndianValue<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);
@@ -270,12 +270,12 @@ struct BlockAlloc
{
memset(this, 0, BLOCK_SIZE);
m_free_blocks = (sizeMb * MBIT_TO_BLOCKS) - MC_FST_BLOCKS;
m_last_allocated_block = BE16(4);
m_last_allocated_block = 4;
fixChecksums();
}
u16 AssignBlocksContiguous(u16 length)
{
u16 starting = BE16(m_last_allocated_block) + 1;
u16 starting = m_last_allocated_block + 1;
if (length > m_free_blocks)
return 0xFFFF;
u16 current = starting;
@@ -285,7 +285,7 @@ struct BlockAlloc
current++;
}
m_map[current - 5] = 0xFFFF;
m_last_allocated_block = BE16(current);
m_last_allocated_block = current;
m_free_blocks = m_free_blocks - length;
fixChecksums();
return starting;

0 comments on commit eb6cc3d

Please sign in to comment.
You can’t perform that action at this time.