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.
This commit is contained in:
parent
5102dae552
commit
4c655850de
7 changed files with 95 additions and 0 deletions
|
@ -28,6 +28,11 @@ int main() {
|
|||
duck::widget::BlockGrid grid1{frm, 3, true};
|
||||
duck::widget::BlockGrid grid2{frm, 3, true};
|
||||
|
||||
auto mc1_info = mc1.content_info();
|
||||
std::cout << "memory card 1:\n";
|
||||
std::cout << "\tuse byte: 0x" << std::hex << mc1_info.use_byte << std::dec << '\n';
|
||||
std::cout << "\tavailable blocks: 0x" << std::hex << static_cast<int>(mc1_info.available_blocks) << std::dec << '\n';
|
||||
|
||||
for (int z = 0; z < 15; ++z) {
|
||||
if (mc1[z].has_magic())
|
||||
grid1.emplace_back(duck::make_nana_animation(mc1[z], g_def_icon_size, g_def_icon_size, g_def_icon_fps));
|
||||
|
|
23
subprojects/memcard/include/memcard/content_info.hpp
Normal file
23
subprojects/memcard/include/memcard/content_info.hpp
Normal file
|
@ -0,0 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace mc {
|
||||
template <bool Const> class BasicBlock;
|
||||
using ConstBlock = BasicBlock<true>;
|
||||
|
||||
enum class BlockContent : uint8_t {
|
||||
Available = 0xA0,
|
||||
UsedLinkNextBlock = 0x51,
|
||||
UsedMidLink = 0x52,
|
||||
UsedEndLink = 0x53,
|
||||
Unusable = 0xff
|
||||
};
|
||||
|
||||
struct ContentInfo {
|
||||
ContentInfo (const ConstBlock& block);
|
||||
|
||||
uint32_t use_byte;
|
||||
BlockContent available_blocks;
|
||||
};
|
||||
} //namespace mc
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "memcard/block.hpp"
|
||||
#include "memcard/content_info.hpp"
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <cstdint>
|
||||
|
@ -16,8 +17,11 @@ public:
|
|||
|
||||
Block operator[] (std::size_t index);
|
||||
ConstBlock operator[] (std::size_t index) const;
|
||||
ContentInfo content_info() const;
|
||||
|
||||
private:
|
||||
std::vector<uint8_t> m_data;
|
||||
};
|
||||
|
||||
std::vector<std::size_t> block_group (const MemoryCard& mc, std::size_t index);
|
||||
} //namespace mc
|
||||
|
|
|
@ -11,6 +11,7 @@ memcard = shared_library('memcard',
|
|||
'src/resize_harris.cpp',
|
||||
'src/shiftjis.c',
|
||||
'src/shiftjis_to_utf8.cpp',
|
||||
'src/content_info.cpp',
|
||||
install: true,
|
||||
include_directories: [private_incl, library_incl],
|
||||
)
|
||||
|
|
|
@ -71,6 +71,15 @@ BasicBlock<Const>::BasicBlock (data_type* beg) :
|
|||
m_begin(beg)
|
||||
{
|
||||
assert(m_begin);
|
||||
|
||||
if (has_magic()) {
|
||||
uint32_t use_byte;
|
||||
static_assert(sizeof(use_byte) == 4, "Wrong type size");
|
||||
const constexpr int offs = 0x84;
|
||||
std::copy(m_begin + offs, m_begin + offs + 4, reinterpret_cast<unsigned char*>(&use_byte));
|
||||
std::clog << "Use byte for block " << title() << " (" << title().size() << ')' <<
|
||||
": 0x" << std::hex << use_byte << std::dec << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
template <bool Const>
|
||||
|
|
43
subprojects/memcard/src/content_info.cpp
Normal file
43
subprojects/memcard/src/content_info.cpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
#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
|
|
@ -34,4 +34,14 @@ ConstBlock MemoryCard::operator[] (std::size_t index) const {
|
|||
assert(index < 15);
|
||||
return ConstBlock(m_data.data() + (index + 1) * Block::size());
|
||||
}
|
||||
|
||||
ContentInfo MemoryCard::content_info() const {
|
||||
return {ConstBlock(m_data.data())};
|
||||
}
|
||||
|
||||
std::vector<std::size_t> block_group (const MemoryCard& mc, std::size_t index) {
|
||||
std::vector<std::size_t> retval;
|
||||
|
||||
auto block = mc[index];
|
||||
}
|
||||
} //namespace mc
|
||||
|
|
Loading…
Add table
Reference in a new issue