-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfacedat_parser.cpp
114 lines (93 loc) · 1.94 KB
/
facedat_parser.cpp
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <iostream>
#include <map>
#include "buf_reader.h"
struct INST_INFO
{
int param_count;
void (*handler)(INST_INFO *info);
};
std::map<int, INST_INFO> inst_map;
void buildUpInst();
void draw_1byte(uint8_t byte);
bool is_inst(uint8_t value);
void handler_61(INST_INFO *info);
void handler_62(INST_INFO *info);
size_t getFileSize(FILE *fp);
char *bitString(uint8_t byte);
uint8_t *buf;
buf_reader_t *r;
int main(int argc, char *argv[])
{
if (argc < 2)
{
std::cout << "Usage: " << argv[0] << " <unpacked file>" << std::endl;
return 0;
}
FILE *fp = fopen(argv[1], "r");
if (!fp)
{
std::cout << "File not found: " << argv[1] << std::endl;
return 0;
}
size_t fileSize = getFileSize(fp);
buf = new uint8_t[fileSize];
fread(buf, 1, fileSize, fp);
fclose(fp);
r = create_buffer_reader(buf, fileSize, true);
while (!buf_end(r))
{
}
destroy_buffer_reader(r);
delete[] buf;
return 0;
}
void handler_61(INST_INFO *info)
{
uint8_t patterns[2];
read_bytes(r, patterns, 2);
for (int i = 0; i < 2; i++)
{
draw_1byte(patterns[0]);
draw_1byte(patterns[1]);
}
}
void handler_62(INST_INFO *info)
{
uint8_t patterns[2];
read_bytes(r, patterns, 2);
for (int i = 0; i < 3; i++)
{
draw_1byte(patterns[0]);
draw_1byte(patterns[1]);
}
}
void buildUpInst()
{
INST_INFO i61 = {2, handler_61};
INST_INFO i62 = {2, handler_62};
}
void draw_1byte(uint8_t byte)
{
printf("%s\n", bitString(byte));
}
bool is_inst(uint8_t byte)
{
}
char *bitString(uint8_t byte)
{
static char _str[9];
for (int i = 0; i < 8; i++)
{
_str[7 - i] = '0' + ((byte >> i) & 0x01);
}
_str[8] = 0;
return _str;
}
size_t getFileSize(FILE *fp)
{
long current = ftell(fp);
fseek(fp, 0, SEEK_END);
size_t size = (size_t)ftell(fp);
fseek(fp, current, SEEK_SET);
return size;
}