[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r4250 - Extractor/src/plugins
From: |
cyberix |
Subject: |
[GNUnet-SVN] r4250 - Extractor/src/plugins |
Date: |
Sun, 7 Jan 2007 07:50:28 -0800 (PST) |
Author: cyberix
Date: 2007-01-07 07:50:24 -0800 (Sun, 07 Jan 2007)
New Revision: 4250
Modified:
Extractor/src/plugins/sidextractor.c
Log:
Rewrote the sid extractor for clarity.
Modified: Extractor/src/plugins/sidextractor.c
===================================================================
--- Extractor/src/plugins/sidextractor.c 2007-01-07 15:49:37 UTC (rev
4249)
+++ Extractor/src/plugins/sidextractor.c 2007-01-07 15:50:24 UTC (rev
4250)
@@ -1,21 +1,22 @@
/*
- This file is part of libextractor.
- (C) 2006 Toni Ruottu
-
- libextractor 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, or (at your
- option) any later version.
-
- libextractor is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with libextractor; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ * This file is part of libextractor.
+ * (C) 2006, 2007 Toni Ruottu
+ *
+ * libextractor 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, or (at your
+ * option) any later version.
+ *
+ * libextractor is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with libextractor; see the file COPYING. If not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
*/
#include "platform.h"
@@ -23,147 +24,206 @@
#include "convert.h"
-static struct EXTRACTOR_Keywords *
-addkword(EXTRACTOR_KeywordList *oldhead,
- const char * phrase,
- EXTRACTOR_KeywordType type) {
- EXTRACTOR_KeywordList * keyword;
+#define SID1_HEADER_SIZE 0x76
+#define SID2_HEADER_SIZE 0x7c
- keyword = malloc(sizeof(EXTRACTOR_KeywordList));
- keyword->next = oldhead;
- keyword->keyword = strdup(phrase);
- keyword->keywordType = type;
- return keyword;
+/* flags */
+
+#define MUSPLAYER_FLAG 0x01
+#define PLAYSID_FLAG 0x02
+#define PAL_FLAG 0x04
+#define NTSC_FLAG 0x08
+#define MOS6581_FLAG 0x10
+#define MOS8580_FLAG 0x20
+
+typedef char sidwrd[ 2 ];
+typedef char sidlongwrd[ 4 ];
+
+struct header
+{
+ char magicid[ 4 ];
+ sidwrd sidversion;
+ sidwrd dataoffset;
+ sidwrd loadaddr;
+ sidwrd initaddr;
+ sidwrd playaddr;
+ sidwrd songs;
+ sidwrd firstsong;
+ sidlongwrd speed;
+ char title[ 32 ];
+ char artist[ 32 ];
+ char copyright[ 32 ];
+ sidwrd flags; /* version 2 specific fields start */
+ char startpage;
+ char pagelength;
+ sidwrd reserved;
+};
+
+int sidword( sidwrd data )
+{
+ int value =
+ ( unsigned char ) data[ 0 ] * 0x100 +
+ ( unsigned char ) data[ 1 ];
+
+ return( value );
+
}
+static struct EXTRACTOR_Keywords * addkword
+(
+ EXTRACTOR_KeywordList *oldhead,
+ const char * phrase,
+ EXTRACTOR_KeywordType type
+)
+{
+ EXTRACTOR_KeywordList * keyword;
+ keyword = malloc( sizeof( EXTRACTOR_KeywordList ) );
+ keyword->next = oldhead;
+ keyword->keyword = strdup( phrase );
+ keyword->keywordType = type;
+ return( keyword );
+}
+
+
/* "extract" keyword from a SID file
*
* This plugin is based on the nsf extractor
*
- * */
-struct EXTRACTOR_Keywords *
-libextractor_sid_extract(const char * filename,
- char * data,
- size_t size,
- struct EXTRACTOR_Keywords * prev) {
- int i, version;
- char album[33];
- char artist[33];
- char copyright[33];
- char songs[32];
- char startingsong[32];
+ */
+struct EXTRACTOR_Keywords * libextractor_sid_extract
+(
+ const char * filename,
+ char * data,
+ size_t size,
+ struct EXTRACTOR_Keywords * prev
+)
+{
+ unsigned int flags;
+ int i, version;
+ char album[ 33 ];
+ char artist[ 33 ];
+ char copyright[ 33 ];
+ char songs[ 32 ];
+ char startingsong[ 32 ];
+ char sidversion[ 32 ];
+ struct header *head;
+ /* Check header size */
- /* Check header size and "magic" id bytes */
+ if( size < SID1_HEADER_SIZE )
+ {
+ return( prev );
+ }
- if
- (
- size < 0x76 ||
- ( data[0] != 'P' && data[0] != 'R' ) ||
- data[1] != 'S' ||
- data[2] != 'I' ||
- data[3] != 'D'
- )
- {
- return prev;
- }
+ head = ( struct header * ) data;
+ /* Check "magic" id bytes */
- /* Mime-type */
+ if
+ (
+ memcmp( head->magicid, "PSID", 4 ) &&
+ memcmp( head->magicid, "RSID", 4 )
+ )
+ {
+ return( prev );
+ }
- prev = addkword(prev, "audio/prs.sid", EXTRACTOR_MIMETYPE);
- /* Version of SID format */
+ /* Mime-type */
- version = data[4] * 0x100 + data[5];
- sprintf( startingsong, "%d", version );
- prev = addkword(prev, startingsong, EXTRACTOR_FORMAT_VERSION);
+ prev = addkword( prev, "audio/prs.sid", EXTRACTOR_MIMETYPE );
- /* Get song count */
+ /* Version of SID format */
- sprintf( songs, "%d", data[0x0e] * 0x100 + data[0x0f] );
- prev = addkword(prev, songs, EXTRACTOR_SONG_COUNT);
+ version = sidword( head->sidversion );
+ sprintf( sidversion, "%d", version );
+ prev = addkword( prev, sidversion, EXTRACTOR_FORMAT_VERSION );
- /* Get number of the first song to be played */
+ /* Get song count */
- sprintf( startingsong, "%d", data[0x10] * 0x100 + data[0x11] );
- prev = addkword(prev, startingsong, EXTRACTOR_STARTING_SONG);
+ sprintf( songs, "%d", sidword( head->songs ) );
+ prev = addkword( prev, songs, EXTRACTOR_SONG_COUNT );
- /* Parse album, artist, copyright fields */
+ /* Get number of the first song to be played */
- for( i = 0; i < 32; i++ )
- {
- album[i] = data[ 0x16 + i ];
- artist[i] = data[ 0x36 + i ];
- copyright[i] = data[ 0x56 + i ];
- }
+ sprintf( startingsong, "%d", sidword( head->firstsong ) );
+ prev = addkword( prev, startingsong, EXTRACTOR_STARTING_SONG );
- album[32] = '\0';
- artist[32] = '\0';
- copyright[32] = '\0';
- prev = addkword(prev, album, EXTRACTOR_ALBUM);
- prev = addkword(prev, artist, EXTRACTOR_ARTIST);
- prev = addkword(prev, copyright, EXTRACTOR_COPYRIGHT);
+ /* name, artist, copyright fields */
+ memcpy( &album, head->title, 32 );
+ memcpy( &artist, head->artist, 32 );
+ memcpy( ©right, head->copyright, 32 );
- if( version < 2 || size < 0x7c )
- {
- return prev;
- }
+ album[ 32 ] = '\0';
+ artist[ 32 ] = '\0';
+ copyright[ 32 ] = '\0';
- /* Version 2 specific options follow
- *
- * Note: Had some troubles understanding specification
- * on the flags in version 2. I hope this is correct.
- *
- */
+ prev = addkword( prev, album, EXTRACTOR_ALBUM );
+ prev = addkword( prev, artist, EXTRACTOR_ARTIST );
+ prev = addkword( prev, copyright, EXTRACTOR_COPYRIGHT );
- /* PAL or NTSC */
- if( data[0x77] & 16 )
- {
- if( data[0x77] & 32 )
- {
- prev = addkword(prev, "PAL/NTSC", EXTRACTOR_TELEVISION_SYSTEM);
- }
- else
- {
- prev = addkword(prev, "PAL", EXTRACTOR_TELEVISION_SYSTEM);
- }
- }
- else
- {
- if( data[0x77] & 32 )
- {
- prev = addkword(prev, "NTSC", EXTRACTOR_TELEVISION_SYSTEM);
- }
- }
+ if( version < 2 || size < SID2_HEADER_SIZE )
+ {
+ return( prev );
+ }
- /* Detect SID Chips suitable for play the files */
+ /* Version 2 specific options follow
+ *
+ * Note: Had some troubles understanding specification
+ * on the flags in version 2. I hope this is correct.
+ *
+ */
- if( data[0x77] & 4 )
- {
- if( data[0x77] & 8 )
- {
- prev = addkword(prev, "MOS6581/MOS8580", EXTRACTOR_HARDWARE_DEPENDENCY);
- }
- else
- {
- prev = addkword(prev, "MOS6581", EXTRACTOR_HARDWARE_DEPENDENCY);
- }
- }
- else
- {
- if( data[0x77] & 8 )
- {
- prev = addkword(prev, "MOS8580", EXTRACTOR_HARDWARE_DEPENDENCY);
- }
- }
+ flags = sidword( head->flags );
- return prev;
+ /* PAL or NTSC */
+
+ if( flags & PAL_FLAG )
+ {
+ if( flags & NTSC_FLAG )
+ {
+ prev = addkword( prev, "PAL/NTSC",
EXTRACTOR_TELEVISION_SYSTEM );
+ }
+ else
+ {
+ prev = addkword( prev, "PAL",
EXTRACTOR_TELEVISION_SYSTEM );
+ }
+ }
+ else
+ {
+ if( flags & NTSC_FLAG )
+ {
+ prev = addkword( prev, "NTSC",
EXTRACTOR_TELEVISION_SYSTEM );
+ }
+ }
+
+ /* Detect SID Chips suitable for play the files */
+
+ if( flags & MOS6581_FLAG )
+ {
+ if( flags & MOS8580_FLAG )
+ {
+ prev = addkword( prev, "MOS6581/MOS8580",
EXTRACTOR_HARDWARE_DEPENDENCY );
+ }
+ else
+ {
+ prev = addkword( prev, "MOS6581",
EXTRACTOR_HARDWARE_DEPENDENCY );
+ }
+ }
+ else
+ {
+ if( flags & MOS8580_FLAG )
+ {
+ prev = addkword( prev, "MOS8580",
EXTRACTOR_HARDWARE_DEPENDENCY );
+ }
+ }
+
+ return( prev );
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r4250 - Extractor/src/plugins,
cyberix <=