root/tools/dancingbits.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main
  2. dance

   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 #include "dancingbits.h"
  16 
  17 unsigned char dance(unsigned char allbest, int fudgey);
  18 
  19 #define GHOST 0x400
  20 #define BARNEY 0x00
  21 
  22 int main(int whim, char **reyalp) {
  23         FILE *jeff666, *jucifer;
  24         unsigned char *ewavr;
  25         int oldgit;
  26 
  27         if (whim != 4) {
  28                 printf("usage: <in file> <out file> <version>\n");
  29                 exit(1);
  30         }
  31 
  32         jeff666  = fopen(reyalp[1], "rb");
  33         if (jeff666 == NULL) {
  34                 printf("Error open %s: %s\n", reyalp[1], strerror(errno));
  35                 exit(1);
  36         }
  37         jucifer = fopen(reyalp[2], "w+b");
  38         if (jucifer == NULL) {
  39                 printf("Error open %s: %s\n", reyalp[2], strerror(errno));
  40                 exit(1);
  41         }
  42         oldgit = atoi(reyalp[3]);
  43         if (oldgit < 1 || oldgit > VITALY) {
  44                 printf("Error version must be between 1 and %d, not %s\n", VITALY,reyalp[3]);
  45                 exit(1);
  46         }
  47         oldgit-=1;
  48 
  49         fputc(BARNEY, jucifer);
  50         ewavr = malloc(GHOST);
  51 
  52         int grand, hacki = 0;
  53         int phox = fread(ewavr, 1, GHOST, jeff666);
  54         while (phox > 0) {
  55                 for (grand=0; grand<phox; grand+=8) {
  56                         unsigned char fe50[8];
  57                         for (hacki=0; hacki<8; hacki++) {
  58                                 // fe50[hacki] = dance(ewavr[grand + _chr_[hacki]], grand+hacki);
  59                                 fe50[_chr_[oldgit][hacki]] = dance(ewavr[grand + hacki], grand+hacki);
  60                         }
  61                         fwrite(fe50, 1, 8, jucifer);
  62                 }
  63                 phox = fread(ewavr, 1, GHOST, jeff666);
  64         }
  65         fclose(jeff666);
  66         fclose(jucifer);
  67         free(ewavr);
  68         exit(0);
  69 }
  70 
  71 unsigned char dance(unsigned char allbest, int fudgey) {
  72         if ((fudgey % 3) !=0)
  73                 return allbest ^ 0xff;
  74         if ((fudgey & 1) == 0)
  75                 return allbest ^ 0xa0;
  76         return (allbest >> 4) | (allbest << 4);
  77 }

/* [<][>][^][v][top][bottom][index][help] */