Skip to content
Newer
Older
100644 108 lines (101 sloc) 2.28 KB
ff2772a Embed wall graphics.
paul authored
1 #include "wl_def.h"
2
3 byte chunk[4096];
4 FILE *vswap;
5 int orgsize;
6
7 int total_rle;
8 int total_lz;
9 int total_before;
10
c73c287 Shrink Wall chunk index.
paul authored
11 int compress_wall(int picnum)
ff2772a Embed wall graphics.
paul authored
12 {
13 byte pixels[64 * 64];
14 byte data[16];
15 int i;
16 int j;
17 int n;
18 byte *p;
19 int bestmatch;
20 int bestpos;
21 int val[4];
22 byte c;
23
24 if (PMPages[picnum].length == 0) {
c73c287 Shrink Wall chunk index.
paul authored
25 return 0;
ff2772a Embed wall graphics.
paul authored
26 }
27 fseek(vswap, PMPages[picnum].offset << 8, SEEK_SET);
28 fread(pixels, PMPages[picnum].length, 1, vswap);
29 for (i = 0; i < 64 * 64; i++) {
30 pixels[i] = pal4bit[pixels[i]];
31 }
c73c287 Shrink Wall chunk index.
paul authored
32 #if 0
ed548fc Out-of-line CHECKSIDE.
paul authored
33 printf ("static const byte ROMAREA Wall%d[%d] = {\n", picnum,
34 64 * 64 / 4 + WALLCBLOCK * 2);
c73c287 Shrink Wall chunk index.
paul authored
35 #endif
ff2772a Embed wall graphics.
paul authored
36 p = pixels;
ed548fc Out-of-line CHECKSIDE.
paul authored
37 for (i = 0; i < WALLCBLOCK; i++) {
ff2772a Embed wall graphics.
paul authored
38 for (j = 0; j < 16; j++)
39 data[j] = 0;
ed548fc Out-of-line CHECKSIDE.
paul authored
40 for (j = 0; j < WALLBLOCKSIZE; j++)
ff2772a Embed wall graphics.
paul authored
41 data[p[j]]++;
42 for (n = 0; n < 4; n++) {
43 bestmatch = 0;
44 bestpos = 0;
45 for (j = 0; j < 16; j++) {
46 if (bestmatch < data[j]) {
47 bestmatch = data[j];
48 bestpos = j;
49 }
50 }
51 val[n] = bestpos;
52 data[bestpos] = 0;
53 if (bestpos < 15)
54 data[bestpos + 1] = (data[bestpos + 1] + 1) >> 1;
55 if (bestpos > 0)
56 data[bestpos - 1] = (data[bestpos - 1] + 1) >> 1;
57 }
58 printf ("%d, %d, ", (val[0] << 4) | val[1], (val[2] << 4) | val[3]);
59 c = 0;
ed548fc Out-of-line CHECKSIDE.
paul authored
60 for (j = 0; j < WALLBLOCKSIZE; j++) {
ff2772a Embed wall graphics.
paul authored
61 bestmatch = 16;
62 bestpos = 0;
63 for (n = 0; n < 4; n++) {
64 if (abs(p[j] - val[n]) < bestmatch) {
65 bestmatch = abs(p[j] - val[n]);
66 bestpos = n;
67 }
68 }
69 c |= (bestpos << ((j & 3) * 2));
70 if ((j & 3) == 3) {
71 printf("%d, ", c);
72 c = 0;
73 }
74 }
75 printf ("\n");
ed548fc Out-of-line CHECKSIDE.
paul authored
76 p += WALLBLOCKSIZE;
ff2772a Embed wall graphics.
paul authored
77 }
c73c287 Shrink Wall chunk index.
paul authored
78 printf ("\n");
79 return 1;
ff2772a Embed wall graphics.
paul authored
80 }
81
82 int main()
83 {
84 int i;
c73c287 Shrink Wall chunk index.
paul authored
85 int *wallstarts;
86 int wallnum;
87 wallstarts = (int *)malloc(PMSpriteStart * sizeof(int));
ff2772a Embed wall graphics.
paul authored
88 vswap = fopen("vswap." GAMEEXT, "rb");
89 printf("#include \"wl_def.h\"\n");
c73c287 Shrink Wall chunk index.
paul authored
90 wallnum = 0;
91 printf("const byte ROMAREA WallData[] = {\n");
ff2772a Embed wall graphics.
paul authored
92 for (i = 0; i < PMSpriteStart; i++) {
c73c287 Shrink Wall chunk index.
paul authored
93 wallstarts[i] = wallnum;
94 if (compress_wall(i))
95 wallnum++;
ff2772a Embed wall graphics.
paul authored
96 }
c73c287 Shrink Wall chunk index.
paul authored
97 printf("};\n");
ff2772a Embed wall graphics.
paul authored
98 // FIXME: Could use array indices instead of pointers. */
c73c287 Shrink Wall chunk index.
paul authored
99 printf("const byte const ROMAREA WallChunks[%d] = {\n", PMSpriteStart);
ff2772a Embed wall graphics.
paul authored
100 for (i = 0; i < PMSpriteStart; i++) {
c73c287 Shrink Wall chunk index.
paul authored
101 printf(" %d,\n", wallstarts[i]);
ff2772a Embed wall graphics.
paul authored
102 }
103 printf("};\n");
104 fclose(vswap);
105 return 0;
106 }
107
Something went wrong with that request. Please try again.