summaryrefslogtreecommitdiff
path: root/tools/gigabeat.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/gigabeat.c')
-rw-r--r--tools/gigabeat.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/tools/gigabeat.c b/tools/gigabeat.c
new file mode 100644
index 0000000000..863d0741f2
--- /dev/null
+++ b/tools/gigabeat.c
@@ -0,0 +1,76 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 by Christian Hack
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include <stdio.h>
21#include <stdlib.h>
22
23static FILE * openinfile( const char * filename )
24{
25 FILE * F = fopen( filename, "rb" );
26 if( F == NULL )
27 {
28 fprintf( stderr, "Couldn't open input file %s\n", filename );
29 perror( "Error was " );
30 exit( -1 );
31 };
32 return F;
33};
34
35static FILE * openoutfile( const char * filename )
36{
37 FILE * F = fopen( filename, "wb" );
38 if( F == NULL )
39 {
40 fprintf( stderr, "Couldn't open output file %s\n", filename );
41 perror( "Error was " );
42 exit( -1 );
43 };
44 return F;
45};
46
47int gigabeat_code(char *infile, char *outfile)
48{
49 FILE *in, *out;
50 unsigned long size = 0;
51 unsigned long bytes_read;
52 unsigned long data;
53 unsigned long key = 0x19751217;
54
55 in = openinfile(infile);
56 out = openoutfile(outfile);
57
58 while (!feof(in)) {
59 bytes_read = fread(&data, 1, 4, in);
60
61 data = data ^ key;
62
63 key = key + (key << 1);
64 key = key + 0x19751217;
65
66 size += bytes_read;
67
68 fwrite(&data, 1, bytes_read, out);
69 }
70
71 fprintf(stderr, "File processed successfully\n" );
72
73 fclose(in);
74 fclose(out);
75 return(0);
76}