95 lines
2.3 KiB
C++
95 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#include "memcard/frame.hpp"
|
|
#include "memcard/frame_iterator.hpp"
|
|
#include "memcard/country_code.hpp"
|
|
#include <cstdint>
|
|
#include <type_traits>
|
|
#include <vector>
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
namespace mc::psx {
|
|
enum class IconDisplayFlag {
|
|
NoIcon = 0x00,
|
|
OneFrame = 0x11,
|
|
TwoFrames = 0x12,
|
|
ThreeFrames = 0x13,
|
|
OneFrameAlt = 0x16,
|
|
TwoFramesAlt = 0x17,
|
|
ThreeFramesAlt = 0x18
|
|
};
|
|
|
|
template <bool Const>
|
|
class BasicBlock {
|
|
public:
|
|
using data_type = typename std::conditional<Const, const uint8_t, uint8_t>::type;
|
|
typedef FrameIterator<Const, Const> iterator;
|
|
typedef FrameIterator<true, Const> const_iterator;
|
|
|
|
static const constexpr std::size_t FrameCount = 64;
|
|
static const constexpr std::size_t TOCBlockIndex = 0;
|
|
|
|
BasicBlock (data_type* blk, std::size_t index);
|
|
BasicBlock (data_type* blk, BasicFrame<Const> toc_entry, std::size_t index);
|
|
~BasicBlock();
|
|
|
|
iterator begin();
|
|
iterator end();
|
|
const_iterator cbegin() const;
|
|
const_iterator begin() const;
|
|
const_iterator cend() const;
|
|
const_iterator end() const;
|
|
|
|
data_type* data() { return m_begin; }
|
|
const data_type* data() const { return m_begin; }
|
|
|
|
BasicFrame<Const> frame(unsigned int idx);
|
|
ConstFrame frame(unsigned int idx) const;
|
|
|
|
static constexpr std::size_t size() { return FrameCount; }
|
|
|
|
std::vector<uint8_t> icon_palette() const;
|
|
bool has_magic() const;
|
|
IconDisplayFlag icon_display_flag() const;
|
|
int block_count() const;
|
|
std::size_t index() const { return m_index; }
|
|
std::string title() const;
|
|
std::size_t available_blocks() const;
|
|
uint16_t link_order() const;
|
|
CountryCode country_code() const;
|
|
std::string product_code() const;
|
|
bool has_pocket_station_content() const;
|
|
std::string_view identifier() const;
|
|
uint8_t toc_checksum() const;
|
|
|
|
uint8_t calculate_toc_checksum() const;
|
|
|
|
private:
|
|
BasicFrame<Const> m_toc_entry;
|
|
std::size_t m_index;
|
|
data_type* m_begin;
|
|
};
|
|
|
|
[[gnu::const]]
|
|
inline int32_t calc_icon_count (IconDisplayFlag idf) {
|
|
switch (idf) {
|
|
case IconDisplayFlag::OneFrame:
|
|
case IconDisplayFlag::OneFrameAlt:
|
|
return 1;
|
|
case IconDisplayFlag::TwoFrames:
|
|
case IconDisplayFlag::TwoFramesAlt:
|
|
return 2;
|
|
case IconDisplayFlag::ThreeFrames:
|
|
case IconDisplayFlag::ThreeFramesAlt:
|
|
return 3;
|
|
|
|
case IconDisplayFlag::NoIcon:
|
|
default:
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
using Block = BasicBlock<false>;
|
|
using ConstBlock = BasicBlock<true>;
|
|
} //namespace mc::psx
|