2006-08-30 23:47:09 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 by Christian Hack
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2006-08-30 23:47:09 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2008-04-09 13:18:59 +00:00
|
|
|
extern void int2le(unsigned int val, unsigned char* addr);
|
|
|
|
extern unsigned int le2int(unsigned char* buf);
|
|
|
|
|
2006-08-30 23:47:09 +00:00
|
|
|
static FILE * openinfile( const char * filename )
|
|
|
|
{
|
|
|
|
FILE * F = fopen( filename, "rb" );
|
|
|
|
if( F == NULL )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Couldn't open input file %s\n", filename );
|
|
|
|
perror( "Error was " );
|
|
|
|
exit( -1 );
|
|
|
|
};
|
|
|
|
return F;
|
2008-04-10 21:16:00 +00:00
|
|
|
}
|
2006-08-30 23:47:09 +00:00
|
|
|
|
|
|
|
static FILE * openoutfile( const char * filename )
|
|
|
|
{
|
|
|
|
FILE * F = fopen( filename, "wb" );
|
|
|
|
if( F == NULL )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Couldn't open output file %s\n", filename );
|
|
|
|
perror( "Error was " );
|
|
|
|
exit( -1 );
|
|
|
|
};
|
|
|
|
return F;
|
2008-04-10 21:16:00 +00:00
|
|
|
}
|
2006-08-30 23:47:09 +00:00
|
|
|
|
|
|
|
int gigabeat_code(char *infile, char *outfile)
|
|
|
|
{
|
|
|
|
FILE *in, *out;
|
|
|
|
unsigned long size = 0;
|
|
|
|
unsigned long bytes_read;
|
2007-03-22 15:53:37 +00:00
|
|
|
unsigned char buf[4];
|
2006-08-30 23:47:09 +00:00
|
|
|
unsigned long data;
|
|
|
|
unsigned long key = 0x19751217;
|
|
|
|
|
|
|
|
in = openinfile(infile);
|
|
|
|
out = openoutfile(outfile);
|
|
|
|
|
|
|
|
while (!feof(in)) {
|
2007-03-22 15:53:37 +00:00
|
|
|
bytes_read = fread(buf, 1, 4, in);
|
2006-08-30 23:47:09 +00:00
|
|
|
|
2007-03-22 15:53:37 +00:00
|
|
|
/* Read in little-endian */
|
|
|
|
data = le2int(buf);
|
|
|
|
|
2006-08-30 23:47:09 +00:00
|
|
|
data = data ^ key;
|
|
|
|
|
|
|
|
key = key + (key << 1);
|
|
|
|
key = key + 0x19751217;
|
|
|
|
|
|
|
|
size += bytes_read;
|
|
|
|
|
2007-03-22 15:53:37 +00:00
|
|
|
/* Write out little-endian */
|
|
|
|
int2le(data, buf);
|
|
|
|
|
|
|
|
fwrite(buf, 1, bytes_read, out);
|
2006-08-30 23:47:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr, "File processed successfully\n" );
|
|
|
|
|
|
|
|
fclose(in);
|
|
|
|
fclose(out);
|
|
|
|
return(0);
|
|
|
|
}
|