-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild_pictable.c
80 lines (71 loc) · 1.66 KB
/
build_pictable.c
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
#include "wl_def.h"
#ifndef EMBEDDED
#include "huffman.h"
void CAL_HuffExpand(const byte *source, byte *dest, long length,
const huffnode *htable)
{
const huffnode *headptr;
const huffnode *nodeon;
byte mask = 0x01;
word path;
byte *endoff = dest + length;
nodeon = headptr = htable + 254;
do {
if (*source & mask)
path = 1;
else
path = 0;
mask <<= 1;
if (mask == 0x00) {
mask = 0x01;
source++;
}
if (path ? nodeon->flag1 : nodeon->flag0) {
nodeon = (htable + nodeon->val[path]);
} else {
*dest = nodeon->val[path];
dest++;
nodeon = headptr;
}
} while (dest != endoff);
}
#endif
int main()
{
#ifndef EMBEDDED
byte *source;
byte *p;
int start;
int end;
int i;
int size;
int compressed;
FILE *f = fopen("vgagraph." GAMEEXT, "rb");
if (!f)
return 1;
start = grstarts[STRUCTPIC];
compressed = grstarts[STRUCTPIC + 1] - start;
source = malloc(compressed);
fread(source, 1, compressed, f);
fclose(f);
size = source[0]|(source[1]<<8)|(source[2]<<16)|(source[3]<<24);
source += 4;
p = malloc(size);
CAL_HuffExpand(source, p, size, grhuffman);
#endif
printf("#include \"wl_def.h\"\n");
#ifndef EMBEDDED
printf("#ifndef EMBEDDED\n");
printf("const pictabletype pictable[NUMPICS] = {\n", NUMPICS);
if (size / 4 < NUMPICS)
printf("#error NUMPICS > %d\n", size / 4);
for (i = 0; i < NUMPICS; i++)
{
printf("{%d,%d},\n", p[0] | (p[1] << 8), p[2] | (p[3] << 8));
p += 4;
}
printf("};\n");
printf("#endif\n");
#endif
return 0;
}