mirror of
https://github.com/encounter/aurora.git
synced 2026-03-30 10:57:39 -07:00
18cdf141cb
Original repository: https://github.com/AxioDL/kabufuda Cleaned up & converted to `aurora::card`, with SDL3 file I/O. --------- Co-authored-by: Phillip Stephens <antidote.crk@gmail.com> Co-authored-by: Jack Andersen <jackoalan@gmail.com> Co-authored-by: Lioncash <mathew1800@gmail.com> Co-authored-by: Luke Street <luke@street.dev>
40 lines
1014 B
C++
40 lines
1014 B
C++
#pragma once
|
|
|
|
#include <array>
|
|
#include <cstdint>
|
|
|
|
#include "Constants.hpp"
|
|
|
|
namespace aurora::card {
|
|
class BlockAllocationTable {
|
|
friend class Card;
|
|
#pragma pack(push, 4)
|
|
union {
|
|
struct {
|
|
uint16_t m_checksum;
|
|
uint16_t m_checksumInv;
|
|
uint16_t m_updateCounter;
|
|
uint16_t m_freeBlocks;
|
|
uint16_t m_lastAllocated;
|
|
std::array<uint16_t, 0xFFB> m_map;
|
|
};
|
|
std::array<uint8_t, BlockSize> raw{};
|
|
};
|
|
#pragma pack(pop)
|
|
|
|
void swapEndian();
|
|
void updateChecksum();
|
|
bool valid() const;
|
|
|
|
public:
|
|
explicit BlockAllocationTable(uint32_t blockCount = (static_cast<uint32_t>(ECardSize::Card2043Mb) * MbitToBlocks));
|
|
~BlockAllocationTable() = default;
|
|
|
|
uint16_t getNextBlock(uint16_t block) const;
|
|
uint16_t nextFreeBlock(uint16_t maxBlock, uint16_t startingBlock) const;
|
|
bool clear(uint16_t first, uint16_t count);
|
|
uint16_t allocateBlocks(uint16_t count, uint16_t maxBlocks);
|
|
uint16_t numFreeBlocks() const { return m_freeBlocks; }
|
|
};
|
|
} // namespace aurora::card
|