| 1 |
#ifndef XSAEXTRACTOR_HH |
| 2 |
#define XSAEXTRACTOR_HH |
| 3 |
|
| 4 |
#include "DiskImageUtils.hh" |
| 5 |
|
| 6 |
#include "MemBuffer.hh" |
| 7 |
|
| 8 |
#include <array> |
| 9 |
#include <cstdint> |
| 10 |
#include <span> |
| 11 |
|
| 12 |
namespace openmsx { |
| 13 |
|
| 14 |
class XSAExtractor |
| 15 |
{ |
| 16 |
public: |
| 17 |
explicit XSAExtractor(std::span<const uint8_t> file); |
| 18 |
MemBuffer<SectorBuffer> extractData() &&; |
| 19 |
|
| 20 |
private: |
| 21 |
static constexpr int MAX_STR_LEN = 254; |
| 22 |
static constexpr int TBL_SIZE = 16; |
| 23 |
static constexpr int MAX_HUF_CNT = 127; |
| 24 |
|
| 25 |
[[nodiscard]] inline uint8_t charIn(); |
| 26 |
void chkHeader(); |
| 27 |
void unLz77(); |
| 28 |
[[nodiscard]] unsigned rdStrLen(); |
| 29 |
[[nodiscard]] int rdStrPos(); |
| 30 |
[[nodiscard]] bool bitIn(); |
| 31 |
void initHufInfo(); |
| 32 |
void mkHufTbl(); |
| 33 |
|
| 34 |
struct HufNode { |
| 35 |
HufNode* child1; |
| 36 |
HufNode* child2; |
| 37 |
int weight; |
| 38 |
}; |
| 39 |
|
| 40 |
private: |
| 41 |
std::span<const uint8_t> file; |
| 42 |
MemBuffer<SectorBuffer> output; |
| 43 |
|
| 44 |
int updHufCnt; |
| 45 |
std::array<int, TBL_SIZE + 1> cpDist; |
| 46 |
std::array<int, TBL_SIZE> tblSizes; |
| 47 |
std::array<HufNode, 2 * TBL_SIZE - 1> hufTbl; |
| 48 |
|
| 49 |
uint8_t bitFlg; |
| 50 |
uint8_t bitCnt; |
| 51 |
|
| 52 |
static constexpr std::array<uint8_t, TBL_SIZE> cpdExt = { |
| 53 |
0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 |
| 54 |
}; |
| 55 |
}; |
| 56 |
|
| 57 |
} |
| 58 |
|
| 59 |
#endif |