GCMemcard: Use BigEndianValue for BlockAlloc.m_last_allocated_block.

This commit is contained in:
Admiral H. Curtiss 2018-11-19 00:22:17 +01:00
parent d3b61c3ff0
commit eb6cc3dbab
2 changed files with 11 additions and 12 deletions

View File

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

View File

@ -257,7 +257,7 @@ struct BlockAlloc
u16 m_checksum_inv; // 0x0002 2 Inverse Checksum u16 m_checksum_inv; // 0x0002 2 Inverse Checksum
Common::BigEndianValue<u16> m_update_counter; // 0x0004 2 Update Counter Common::BigEndianValue<u16> m_update_counter; // 0x0004 2 Update Counter
Common::BigEndianValue<u16> m_free_blocks; // 0x0006 2 Free Blocks Common::BigEndianValue<u16> m_free_blocks; // 0x0006 2 Free Blocks
u16 m_last_allocated_block; // 0x0008 2 Last allocated Block Common::BigEndianValue<u16> m_last_allocated_block; // 0x0008 2 Last allocated Block
u16 m_map[BAT_SIZE]; // 0x000a 0x1ff8 Map of allocated Blocks u16 m_map[BAT_SIZE]; // 0x000a 0x1ff8 Map of allocated Blocks
u16 GetNextBlock(u16 Block) const; u16 GetNextBlock(u16 Block) const;
u16 NextFreeBlock(u16 MaxBlock, u16 StartingBlock = MC_FST_BLOCKS) const; u16 NextFreeBlock(u16 MaxBlock, u16 StartingBlock = MC_FST_BLOCKS) const;
@ -270,12 +270,12 @@ struct BlockAlloc
{ {
memset(this, 0, BLOCK_SIZE); memset(this, 0, BLOCK_SIZE);
m_free_blocks = (sizeMb * MBIT_TO_BLOCKS) - MC_FST_BLOCKS; m_free_blocks = (sizeMb * MBIT_TO_BLOCKS) - MC_FST_BLOCKS;
m_last_allocated_block = BE16(4); m_last_allocated_block = 4;
fixChecksums(); fixChecksums();
} }
u16 AssignBlocksContiguous(u16 length) u16 AssignBlocksContiguous(u16 length)
{ {
u16 starting = BE16(m_last_allocated_block) + 1; u16 starting = m_last_allocated_block + 1;
if (length > m_free_blocks) if (length > m_free_blocks)
return 0xFFFF; return 0xFFFF;
u16 current = starting; u16 current = starting;
@ -285,7 +285,7 @@ struct BlockAlloc
current++; current++;
} }
m_map[current - 5] = 0xFFFF; m_map[current - 5] = 0xFFFF;
m_last_allocated_block = BE16(current); m_last_allocated_block = current;
m_free_blocks = m_free_blocks - length; m_free_blocks = m_free_blocks - length;
fixChecksums(); fixChecksums();
return starting; return starting;