annotate playercode/load_mtm.c @ 4:5d614bcc4287

Initial entry of mikmod into the CVS tree.
author darius
date Fri, 23 Jan 1998 16:05:08 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
1 /*
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
2
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
3 Name: LOAD_MTM.C
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
4
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
5 Description:
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
6 MTM module loader
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
7
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
8 Portability:
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
9 All systems - all compilers (hopefully)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
10
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
11 If this module is found to not be portable to any particular platform,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
12 please contact Jake Stine at dracoirs@epix.net (see MIKMOD.TXT for
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
13 more information on contacting the author).
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
14
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
15 */
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
16
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
17 #include <string.h>
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
18 #include "mikmod.h"
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
19
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
20 /**************************************************************************
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
21 **************************************************************************/
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
22
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
23
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
24 typedef struct MTMSAMPLE
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
25 { CHAR samplename[22];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
26 ULONG length;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
27 ULONG reppos;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
28 ULONG repend;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
29 UBYTE finetune;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
30 UBYTE volume;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
31 UBYTE attribute;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
32 } MTMSAMPLE;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
33
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
34
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
35
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
36 typedef struct MTMHEADER
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
37 { UBYTE id[3]; // MTM file marker
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
38 UBYTE version; // upper major, lower nibble minor version number
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
39 char songname[20]; // ASCIIZ songname
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
40 UWORD numtracks; // number of tracks saved
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
41 UBYTE lastpattern; // last pattern number saved
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
42 UBYTE lastorder; // last order number to play (songlength-1)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
43 UWORD commentsize; // length of comment field
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
44 UBYTE numsamples; // number of samples saved
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
45 UBYTE attribute; // attribute byte (unused)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
46 UBYTE beatspertrack; //
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
47 UBYTE numchannels; // number of channels used
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
48 UBYTE panpos[32]; // voice pan positions
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
49 } MTMHEADER;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
50
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
51
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
52 typedef struct MTMNOTE
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
53 { UBYTE a,b,c;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
54 } MTMNOTE;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
55
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
56
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
57 /**************************************************************************
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
58 **************************************************************************/
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
59
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
60
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
61 static MTMHEADER *mh = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
62 static MTMNOTE *mtmtrk = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
63 static UWORD pat[32];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
64
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
65 char MTM_Version[] = "MTM";
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
66
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
67
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
68
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
69 BOOL MTM_Test(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
70 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
71 UBYTE id[3];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
72 if(!_mm_read_UBYTES(id,3,modfp)) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
73 if(!memcmp(id,"MTM",3)) return 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
74 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
75 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
76
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
77
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
78 BOOL MTM_Init(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
79 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
80 if(!(mtmtrk=(MTMNOTE *)_mm_calloc(64,sizeof(MTMNOTE)))) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
81 if(!(mh=(MTMHEADER *)_mm_calloc(1,sizeof(MTMHEADER)))) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
82
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
83 return 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
84 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
85
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
86
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
87 void MTM_Cleanup(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
88 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
89 if(mtmtrk!=NULL) free(mtmtrk);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
90 if(mh!=NULL) free(mh);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
91
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
92 mtmtrk = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
93 mh = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
94 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
95
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
96
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
97 UBYTE *MTM_Convert(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
98 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
99 int t;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
100 UBYTE a,b,c,inst,note,eff,dat;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
101
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
102 UniReset();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
103 for(t=0; t<64; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
104 { a = mtmtrk[t].a;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
105 b = mtmtrk[t].b;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
106 c = mtmtrk[t].c;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
107
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
108 inst = ((a&0x3)<<4)|(b>>4);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
109 note = a>>2;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
110
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
111 eff = b&0xf;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
112 dat = c;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
113
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
114 if(inst!=0) UniInstrument(inst-1);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
115 if(note!=0) UniNote(note+24);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
116
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
117 // mtm bug bugfix: when the effect is volslide,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
118 // slide-up _always_ overrides slide-dn.
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
119
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
120 if(eff==0xa && dat&0xf0) dat&=0xf0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
121
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
122 // Convert pattern jump from Dec to Hex
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
123 if(eff == 0xd)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
124 dat = (((dat&0xf0)>>4)*10)+(dat&0xf);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
125 UniPTEffect(eff,dat);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
126 UniNewline();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
127 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
128 return UniDup();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
129 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
130
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
131
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
132 BOOL MTM_Load(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
133 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
134 MTMSAMPLE s;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
135 SAMPLE *q;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
136
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
137 int t,u;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
138
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
139 // try to read module header
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
140
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
141 _mm_read_UBYTES(mh->id,3,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
142 mh->version =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
143 _mm_read_string(mh->songname,20,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
144 mh->numtracks =_mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
145 mh->lastpattern =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
146 mh->lastorder =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
147 mh->commentsize =_mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
148 mh->numsamples =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
149 mh->attribute =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
150 mh->beatspertrack=_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
151 mh->numchannels =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
152 _mm_read_UBYTES(mh->panpos,32,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
153
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
154 if(feof(modfp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
155 { _mm_errno = MMERR_LOADING_HEADER;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
156 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
157 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
158
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
159 // set module variables
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
160
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
161 of.initspeed = 6;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
162 of.inittempo = 125;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
163 of.modtype = strdup(MTM_Version);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
164 of.numchn = mh->numchannels;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
165 of.numtrk = mh->numtracks+1; // get number of channels
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
166 of.songname = DupStr(mh->songname,20); // make a cstr of songname
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
167 of.numpos = mh->lastorder+1; // copy the songlength
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
168 of.numpat = mh->lastpattern+1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
169 for(t=0; t<32; t++) of.panning[t] = mh->panpos[t] << 4;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
170
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
171 of.numins = of.numsmp = mh->numsamples;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
172 if(!AllocSamples()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
173
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
174 q = of.samples;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
175
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
176 for(t=0; t<of.numins; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
177 { // try to read sample info
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
178 _mm_read_string(s.samplename,22,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
179 s.length =_mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
180 s.reppos =_mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
181 s.repend =_mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
182 s.finetune =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
183 s.volume =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
184 s.attribute =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
185
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
186 if(feof(modfp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
187 { _mm_errno = MMERR_LOADING_SAMPLEINFO;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
188 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
189 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
190
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
191 q->samplename = DupStr(s.samplename,22);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
192 q->seekpos = 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
193 q->speed = finetune[s.finetune];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
194 q->length = s.length;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
195 q->loopstart = s.reppos;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
196 q->loopend = s.repend;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
197 q->volume = s.volume;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
198
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
199 if((s.repend-s.reppos) > 2) q->flags |= SF_LOOP;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
200
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
201 if(s.attribute & 1)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
202 { // If the sample is 16-bits, convert the length
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
203 // and replen byte-values into sample-values
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
204
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
205 q->flags|=SF_16BITS;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
206 q->length>>=1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
207 q->loopstart>>=1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
208 q->loopend>>=1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
209 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
210
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
211 q++;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
212 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
213
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
214 if(!AllocPositions(of.numpos)) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
215 for(t=0; t<of.numpos; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
216 of.positions[t] = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
217 for(; t<128; t++) _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
218
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
219 if(feof(modfp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
220 { _mm_errno = MMERR_LOADING_HEADER;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
221 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
222 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
223
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
224 if(!AllocTracks()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
225 if(!AllocPatterns()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
226
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
227 of.tracks[0] = MTM_Convert(); // track 0 is empty
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
228
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
229 for(t=1; t<of.numtrk; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
230 { int s;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
231
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
232 for(s=0; s<64; s++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
233 { mtmtrk[s].a=_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
234 mtmtrk[s].b=_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
235 mtmtrk[s].c=_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
236 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
237
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
238 if(feof(modfp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
239 { _mm_errno = MMERR_LOADING_TRACK;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
240 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
241 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
242
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
243 if(!(of.tracks[t]=MTM_Convert())) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
244 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
245
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
246 for(t=0; t<of.numpat; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
247 { _mm_read_I_UWORDS(pat,32,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
248
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
249 for(u=0; u<of.numchn; u++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
250 of.patterns[((long)t*of.numchn)+u]=pat[u];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
251 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
252
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
253 // read comment field
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
254
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
255 if(!ReadComment(mh->commentsize)) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
256
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
257 return 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
258 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
259
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
260
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
261 CHAR *MTM_LoadTitle(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
262 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
263 CHAR s[20];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
264
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
265 _mm_fseek(modfp,4,SEEK_SET);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
266 if(!fread(s,20,1,modfp)) return NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
267
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
268 return(DupStr(s,20));
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
269 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
270
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
271
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
272 MLOADER load_mtm =
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
273 { NULL,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
274 "MTM",
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
275 "Portable MTM loader v0.1",
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
276 MTM_Init,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
277 MTM_Test,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
278 MTM_Load,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
279 MTM_Cleanup,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
280 MTM_LoadTitle
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
281 };
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
282