1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
|
/*
* This file is part of libextractor.
* (C) 2006, 2009, 2012 Toni Ruottu and Christian Grothoff
*
* 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 3, 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.
*
*/
/**
* @file plugins/nsf_extractor.c
* @brief plugin to support Nes Sound Format files
* @author Toni Ruottu
* @author Christian Grothoff
*/
#include "platform.h"
#include "extractor.h"
/* television system flags */
#define PAL_FLAG 0x01
#define DUAL_FLAG 0x02
/* sound chip flags */
#define VRCVI_FLAG 0x01
#define VRCVII_FLAG 0x02
#define FDS_FLAG 0x04
#define MMC5_FLAG 0x08
#define NAMCO_FLAG 0x10
#define SUNSOFT_FLAG 0x20
/**
* Header of an NSF file.
*/
struct header
{
/**
* Magic code.
*/
char magicid[5];
/**
* NSF version number.
*/
char nsfversion;
/**
* Number of songs.
*/
unsigned char songs;
/**
* Starting song.
*/
unsigned char firstsong;
/**
* Unknown.
*/
uint16_t loadaddr;
/**
* Unknown.
*/
uint16_t initaddr;
/**
* Unknown.
*/
uint16_t playaddr;
/**
* Album title.
*/
char title[32];
/**
* Artist name.
*/
char artist[32];
/**
* Copyright information.
*/
char copyright[32];
/**
* Unknown.
*/
uint16_t ntscspeed;
/**
* Unknown.
*/
char bankswitch[8];
/**
* Unknown.
*/
uint16_t palspeed;
/**
* Flags for TV encoding.
*/
char tvflags;
/**
* Flags about the decoder chip.
*/
char chipflags;
};
/**
* Give metadata to LE; return if 'proc' returns non-zero.
*
* @param s metadata value as UTF8
* @param t metadata type to use
*/
#define ADD(s,t) do { if (0 != ec->proc (ec->cls, "nsf", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen (s) + 1)) return; } while (0)
/**
* "extract" meta data from a Nes Sound Format file
*
* NSF specification version 1.61 was used, while this piece of
* software was originally written.
*
* @param ec extraction context
*/
void
EXTRACTOR_nsf_extract_method (struct EXTRACTOR_ExtractContext *ec)
{
char album[33];
char artist[33];
char copyright[33];
char songs[32];
char startingsong[32];
char nsfversion[32];
const struct header *head;
void *data;
ssize_t ds;
ds = ec->read (ec->cls,
&data,
sizeof (struct header));
if ( (-1 == ds) ||
(sizeof (struct header) > ds) )
return;
head = data;
if (NULL == head)
return;
/* Check "magic" id bytes */
if (memcmp (head->magicid, "NESM\x1a", 5))
return;
ADD ("audio/x-nsf", EXTRACTOR_METATYPE_MIMETYPE);
snprintf (nsfversion,
sizeof(nsfversion),
"%d",
head->nsfversion);
ADD (nsfversion, EXTRACTOR_METATYPE_FORMAT_VERSION);
snprintf (songs,
sizeof(songs),
"%d",
(int) head->songs);
ADD (songs, EXTRACTOR_METATYPE_SONG_COUNT);
snprintf (startingsong,
sizeof(startingsong),
"%d",
(int) head->firstsong);
ADD (startingsong, EXTRACTOR_METATYPE_STARTING_SONG);
memcpy (&album, head->title, 32);
album[32] = '\0';
ADD (album, EXTRACTOR_METATYPE_ALBUM);
memcpy (&artist, head->artist, 32);
artist[32] = '\0';
ADD (artist, EXTRACTOR_METATYPE_ARTIST);
memcpy (©right, head->copyright, 32);
copyright[32] = '\0';
ADD (copyright, EXTRACTOR_METATYPE_COPYRIGHT);
if (0 != (head->tvflags & DUAL_FLAG))
{
ADD ("PAL/NTSC", EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM);
}
else
{
if (0 != (head->tvflags & PAL_FLAG))
ADD ("PAL", EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM);
else
ADD ("NTSC", EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM);
}
/* Detect Extra Sound Chips needed to play the files */
if (0 != (head->chipflags & VRCVI_FLAG))
ADD ("VRCVI", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE);
if (0 != (head->chipflags & VRCVII_FLAG))
ADD ("VRCVII", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE);
if (0 != (head->chipflags & FDS_FLAG))
ADD ("FDS Sound", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE);
if (0 != (head->chipflags & MMC5_FLAG))
ADD ("MMC5 audio", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE);
if (0 != (head->chipflags & NAMCO_FLAG))
ADD ("Namco 106", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE);
if (0 != (head->chipflags & SUNSOFT_FLAG))
ADD ("Sunsoft FME-07", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE);
}
/* end of nsf_extractor.c */
|