source: trunk/tools/dancingbits.c @ 1387

Revision 1387, 2.2 KB checked in by philmoz, 19 months ago (diff)

Update array size in dancingbits.c (missing from changeset 1386).

  • Property svn:eol-style set to native
Line 
1/*
2 * make an image bootable for latest cams
3 * (c) 2008 chr
4 *
5 * GPL v3+
6 *
7 * Why make things easy if complex sells better?
8 */
9#include <stdio.h>
10#include <stddef.h>
11#include <string.h>
12#include <stdlib.h>
13#include <errno.h>
14
15#define VITALY 7
16unsigned char _chr_[VITALY][8] = {
17                                                                        { 4,6,1,0,7,2,5,3 }, // original flavor
18                                                                        { 5,3,6,1,2,7,0,4 }, // nacho cheese sx200is, ixus100_sd780, ixu95_sd1200, a1100, d10
19                                                                        { 2,5,0,4,6,1,3,7 }, // mesquite bbq ixus200_sd980, sx20 (dryos r39)
20                                                                        { 4,7,3,2,6,5,0,1 }, // cool ranch a3100 (dryos r43)
21                                                                        { 3,2,7,5,1,4,6,0 }, // cajun chicken s95, g12, sx30 (dryos r45)
22                                                                        { 0,4,2,7,3,6,5,1 }, // spicy wasabi sx220, sx230, ixus310 (dryos r47)
23                                                                        { 7,1,5,3,0,6,4,2 }, // sea salt & vinegar sx40hs, sx150is (dryos r49)
24                                                                };
25
26unsigned char dance(unsigned char allbest, int fudgey);
27
28#define GHOST 0x400
29#define BARNEY 0x00
30
31int main(int whim, char **reyalp) {
32        FILE *jeff666, *jucifer;
33        unsigned char *ewavr;
34        int oldgit;
35
36        if (whim != 4) {
37                printf("usage: <in file> <out file> <version>\n");
38                exit(1);
39        }
40
41        jeff666  = fopen(reyalp[1], "rb");
42        if (jeff666 == NULL) {
43                printf("Error open %s: %s\n", reyalp[1], strerror(errno));
44                exit(1);
45        }
46        jucifer = fopen(reyalp[2], "w+b");
47        if (jucifer == NULL) {
48                printf("Error open %s: %s\n", reyalp[2], strerror(errno));
49                exit(1);
50        }
51        oldgit = atoi(reyalp[3]);
52        if (oldgit < 1 || oldgit > VITALY) {
53                printf("Error version must be between 1 and %d, not %s\n", VITALY,reyalp[3]);
54                exit(1);
55        }
56        oldgit-=1;
57
58        fputc(BARNEY, jucifer);
59        ewavr = malloc(GHOST);
60
61        int grand, hacki = 0;
62        int phox = fread(ewavr, 1, GHOST, jeff666);
63        while (phox > 0) {
64                for (grand=0; grand<phox; grand+=8) {
65                        unsigned char fe50[8];
66                        for (hacki=0; hacki<8; hacki++) {
67                                // fe50[hacki] = dance(ewavr[grand + _chr_[hacki]], grand+hacki);
68                                fe50[_chr_[oldgit][hacki]] = dance(ewavr[grand + hacki], grand+hacki);
69                        }
70                        fwrite(fe50, 1, 8, jucifer);
71                }
72                phox = fread(ewavr, 1, GHOST, jeff666);
73        }
74        fclose(jeff666);
75        fclose(jucifer);
76        free(ewavr);
77        exit(0);
78}
79
80unsigned char dance(unsigned char allbest, int fudgey) {
81        if ((fudgey % 3) !=0)
82                return allbest ^ 0xff;
83        if ((fudgey & 1) == 0)
84                return allbest ^ 0xa0;
85        return (allbest >> 4) | (allbest << 4);
86}
Note: See TracBrowser for help on using the repository browser.