1 /* OpenCP Module Player
2  * copyright (c) '94-'10 Niklas Beisert <nbeisert@physik.tu-muenchen.de>
3  *
4  * ITPlay file type detection routines for the file selector
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  * revision history: (please note changes here)
21  *  -nb980510   Niklas Beisert <nbeisert@physik.tu-muenchen.de>
22  *    -first release
23  */
24 
25 #include "config.h"
26 #include <string.h>
27 #include "types.h"
28 #include "filesel/filesystem.h"
29 #include "filesel/mdb.h"
30 
31 
32 static int itpGetModuleType(const char *buf)
33 {
34 	if (*(uint32_t*)buf==uint32_little(0x4D504D49))
35 		return mtIT;
36 	return mtUnRead;
37 }
38 
39 
40 static int itpReadMemInfo(struct moduleinfostruct *m, const char *buf, size_t len)
41 {
42 	int type;
43 	int i;
44 
45 	if (!memcmp(buf, "ziRCONia", 8))
46 	{
47 		strcpy(m->modname, "MMCMPed module");
48 		return 0;
49 	}
50 
51 	if ((type=itpGetModuleType(buf))==mtUnRead)
52 		return 0;
53 	m->modtype=type;
54 	switch (type)
55 	{
56 		case mtIT:
57 			if (buf[0x2C]&4)
58 				if (buf[0x2B]<2)
59 					return 0;
60 			memcpy(m->modname, buf+4, 26);
61 			m->modname[26]=0;
62 			m->channels=0;
63 			for (i=0; i<64; i++)
64 				if (!(buf[64+i]&0x80))
65 					m->channels++;
66 			memset(&m->composer, 0, sizeof(m->composer));
67 			return 1;
68 	}
69 	return 0;
70 }
71 
72 static int itpReadInfo(struct moduleinfostruct *m, struct ocpfilehandle_t *fp, const char *bf, size_t len)
73 {
74 	return itpReadMemInfo (m, bf, len);
75 }
76 
77 struct mdbreadinforegstruct itpReadInfoReg = {itpReadMemInfo, itpReadInfo, 0 MDBREADINFOREGSTRUCT_TAIL};
78