-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCompress.h
68 lines (59 loc) · 2.28 KB
/
Compress.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef COMPRESS_H
#define COMPRESS_H
#include <QVector>
namespace ROMUtils
{
class RLEMetadata
{
private:
unsigned short *JumpTable;
protected:
void *data;
unsigned int data_len;
virtual void InitializeJumpTable() = 0;
virtual int GetTypeIdentifier() = 0;
virtual int GetMinimumRunSize() = 0;
virtual void AddOpcode(QVector<unsigned char> &compressedData, unsigned short opcode, bool runmode) = 0;
RLEMetadata(void *data, unsigned int len) : data(data), data_len(len) {}
void InitializeJumpTableHelper(unsigned short jumpLimit);
unsigned int GetCompressedLengthHelper(unsigned int opcodeSize);
public:
virtual unsigned int GetCompressedLength() = 0;
void *GetCompressedData();
virtual ~RLEMetadata() { delete[] JumpTable; }
};
class RLEMetadata8Bit : public RLEMetadata
{
protected:
void InitializeJumpTable() { InitializeJumpTableHelper(0x7F); }
int GetTypeIdentifier() { return 1; }
int GetMinimumRunSize() { return 3; }
void AddOpcode(QVector<unsigned char> &compressedData, unsigned short opcode, bool runmode)
{
if (runmode)
opcode |= 0x80;
compressedData.append((unsigned char) opcode);
}
public:
RLEMetadata8Bit(void *data, unsigned int len) : RLEMetadata(data, len) { InitializeJumpTable(); }
unsigned int GetCompressedLength() { return GetCompressedLengthHelper(1); }
};
class RLEMetadata16Bit : public RLEMetadata
{
protected:
void InitializeJumpTable() { InitializeJumpTableHelper(0x7FFF); }
int GetTypeIdentifier() { return 2; }
int GetMinimumRunSize() { return 5; }
void AddOpcode(QVector<unsigned char> &compressedData, unsigned short opcode, bool runmode)
{
if (runmode)
opcode |= 0x8000;
compressedData.append((unsigned char) (opcode >> 8));
compressedData.append((unsigned char) opcode);
}
public:
RLEMetadata16Bit(void *data, unsigned int len) : RLEMetadata(data, len) { InitializeJumpTable(); }
unsigned int GetCompressedLength() { return GetCompressedLengthHelper(2); }
};
} // namespace ROMUtils
#endif // COMPRESS_H