memoserv/subprojects/memcard/src/content_info.cpp
King_DuckZ 4c655850de Committing old changes.
I'm not sure what this is, I think it's just adding a new
MemoryCard::content_info() method. There might be unwanted
debug stuff included in this commit too.
2020-03-19 19:48:28 +01:00

43 lines
973 B
C++

#include "memcard/content_info.hpp"
#include "memcard/block.hpp"
#include <algorithm>
namespace mc {
namespace {
template <typename T>
T read_as (const ConstBlock& block, std::size_t offset) {
T retval;
std::copy(
block.begin() + offset,
block.begin() + offset + sizeof(T),
reinterpret_cast<uint8_t*>(&retval)
);
return retval;
}
} //unnamed namespace
ContentInfo::ContentInfo (const ConstBlock& block) :
use_byte(read_as<uint32_t>(block, 0x84)),
available_blocks(BlockContent::Available)
{
auto block_content = read_as<uint8_t>(block, 0x80);
switch (block_content & 0xf) {
case 0x0:
available_blocks = BlockContent::Available;
break;
case 0x1:
available_blocks = BlockContent::UsedLinkNextBlock;
break;
case 0x2:
available_blocks = BlockContent::UsedMidLink;
break;
case 0x3:
available_blocks = BlockContent::UsedEndLink;
break;
case 0xf:
default:
available_blocks = BlockContent::Unusable;
break;
}
}
} //namespace mc