Mercurial > hg > dmlib
annotate minijss/jloadxm.c @ 1124:b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 04 Mar 2015 06:01:26 +0200 |
parents | 97ecc0a9c21f |
children | 44ed439b1c6b |
rev | line source |
---|---|
0 | 1 /* |
2 * miniJSS - Fast Tracker ][ (XM) module loader | |
3 * Programmed and designed by Matti 'ccr' Hamalainen | |
4 * (C) Copyright 2006-2007 Tecnic Software productions (TNSP) | |
5 * | |
6 * TO DO: | |
7 * - Add support for 1.02/1.03 XM-format versions. | |
8 * (Not very useful, but if it's not too hard, then do it) | |
9 */ | |
10 #include "jssmod.h" | |
11 #include <string.h> | |
12 | |
13 | |
14 /* XM value limit definitions | |
15 */ | |
16 #define XM_MaxChannels (32) | |
17 #define XM_MaxPatterns (256) | |
18 #define XM_MaxOrders (255) | |
19 #define XM_MaxInstruments (128) | |
20 #define XM_MaxInstSamples (16) | |
21 #define XM_MaxEnvPoints (12) | |
22 #define XM_MaxNotes (96) | |
23 #define XM_MaxSampleVolume (64) | |
24 | |
25 | |
26 /* XM format structures | |
27 */ | |
28 typedef struct | |
29 { | |
30 char idMagic[17]; // XM header ID "Extended Module: " | |
31 char songName[20]; // Module song name | |
32 Uint8 unUsed1A; // ALWAYS 0x1a | |
33 char trackerName[20]; // ID-string of tracker software | |
34 Uint16 version; // XM-version 0x0104 | |
35 Uint32 headSize; // Module header size, FROM THIS POINT! | |
36 Uint16 norders, // Number of orders | |
37 defRestartPos, // Default song restart position | |
38 nchannels, // Number of channels | |
39 npatterns, // Number of patterns | |
40 ninstruments, // Number of instruments | |
552
d4cee32e7050
Rename internal structures, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
41 flags, // Module flags: |
d4cee32e7050
Rename internal structures, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
42 // bit0: 0 = Amiga frequency table |
d4cee32e7050
Rename internal structures, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
43 // 1 = Linear frequency table |
d4cee32e7050
Rename internal structures, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
44 // |
0 | 45 defSpeed, // Default speed |
46 defTempo; // Default tempo | |
47 Uint8 orderList[256]; // Order list | |
48 } XMHeader; | |
49 | |
50 | |
51 typedef struct | |
52 { | |
53 Uint32 headSize; // Instrument header size (see docs!) | |
54 char instName[22]; // Name/description | |
55 Uint8 instType; // Type | |
56 Uint16 nsamples; // Number of samples | |
57 } XMInstrument1; | |
58 | |
59 | |
60 typedef struct | |
61 { | |
62 Uint16 frame, value; | |
552
d4cee32e7050
Rename internal structures, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
63 } XMEnvPoint; |
0 | 64 |
65 | |
66 typedef struct | |
67 { | |
68 Uint8 flags, npoints, sustain, loopS, loopE; | |
552
d4cee32e7050
Rename internal structures, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
69 XMEnvPoint points[XM_MaxEnvPoints]; |
d4cee32e7050
Rename internal structures, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
70 } XMEnvelope; |
0 | 71 |
72 | |
73 typedef struct | |
74 { | |
75 Uint32 headSize; // Header size | |
76 Uint8 sNumForNotes[XM_MaxNotes]; // Sample numbers for notes | |
552
d4cee32e7050
Rename internal structures, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
77 XMEnvelope volumeEnv, panningEnv; |
0 | 78 Uint8 vibratoType, vibratoSweep, vibratoDepth, vibratoRate; |
79 | |
80 Uint16 fadeOut, ARESERVED; | |
81 } XMInstrument2; | |
82 | |
83 | |
84 typedef struct | |
85 { | |
86 Uint32 size, loopS, loopL; | |
87 Uint8 volume; | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
88 Sint8 fineTune; |
0 | 89 Uint8 type, panning; |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
90 Sint8 relNote; |
0 | 91 Uint8 ARESERVED; |
92 char sampleName[22]; | |
93 } XMSample; | |
94 | |
95 | |
96 typedef struct | |
97 { | |
98 Uint32 headSize; | |
99 Uint8 packing; | |
100 Uint16 nrows, size; | |
101 } XMPattern; | |
102 | |
103 | |
104 | |
105 /* Unpack XM-format pattern from file-stream into JSS-pattern structure | |
106 */ | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
107 #define JSGETBYTE(XV) do { \ |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
108 size--; \ |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
109 if (size < 0) \ |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
110 JSSERROR(DMERR_OUT_OF_DATA, DMERR_OUT_OF_DATA, \ |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
111 "Unexpected end of packed pattern data.\n"); \ |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
112 XV = dmfgetc(inFile); \ |
0 | 113 } while (0) |
114 | |
115 | |
313
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
116 static int jssXMConvertNote(int val) |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
117 { |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
118 if (val < 1 || val > 97) |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
119 return jsetNotSet; |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
120 else if (val == 97) |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
121 return jsetNoteOff; |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
122 else |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
123 return val - 1; |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
124 } |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
125 |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
126 |
0 | 127 static int jssXMUnpackPattern(DMResource *inFile, int size, JSSPattern *pattern) |
128 { | |
129 int packb, row, channel, tmp; | |
130 JSSNote *pnote; | |
131 assert(pattern != NULL); | |
132 | |
133 pnote = pattern->data; | |
134 | |
313
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
135 for (row = 0; row < pattern->nrows && size > 0; row++) |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
136 for (channel = 0; channel < pattern->nchannels && size > 0; channel++) |
0 | 137 { |
138 JSGETBYTE(packb); | |
139 if (packb & 0x80) | |
140 { | |
141 if (packb & 0x01) | |
142 { | |
143 // PACK 0x01: Read note | |
144 JSGETBYTE(tmp); | |
313
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
145 pnote->note = jssXMConvertNote(tmp); |
0 | 146 } |
147 | |
148 if (packb & 0x02) | |
149 { | |
150 // PACK 0x02: Read instrument | |
151 JSGETBYTE(tmp); | |
152 pnote->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet; | |
153 } | |
154 | |
155 if (packb & 0x04) | |
156 { | |
157 // PACK 0x04: Read volume | |
158 JSGETBYTE(tmp); | |
159 pnote->volume = (tmp >= 0x10) ? tmp - 0x10 : jsetNotSet; | |
160 } | |
161 | |
162 if (packb & 0x08) | |
163 { | |
164 // PACK 0x08: Read effect | |
165 JSGETBYTE(pnote->effect); | |
166 pnote->param = 0; | |
167 } | |
168 | |
169 if (packb & 0x10) | |
170 { | |
171 // PACK 0x10: Read effect parameter | |
172 JSGETBYTE(pnote->param); | |
173 if (pnote->effect == jsetNotSet && pnote->param != 0) | |
174 pnote->effect = 0; | |
175 } | |
176 } | |
177 else | |
178 { | |
179 // All data available | |
313
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
180 pnote->note = jssXMConvertNote(packb & 0x7f); |
0 | 181 |
182 // Get instrument | |
183 JSGETBYTE(tmp); | |
184 pnote->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet; | |
185 | |
186 // Get volume | |
187 JSGETBYTE(tmp); | |
188 pnote->volume = (tmp >= 0x10) ? tmp - 0x10 : jsetNotSet; | |
189 | |
190 // Get effect | |
191 JSGETBYTE(pnote->effect); | |
192 | |
193 // Get parameter | |
194 JSGETBYTE(pnote->param); | |
195 if (pnote->effect == 0 && pnote->param == 0) | |
196 pnote->effect = pnote->param = jsetNotSet; | |
197 } | |
198 pnote++; | |
199 } | |
200 | |
201 // Check the state | |
202 if (size > 0) | |
203 { | |
204 // Some data left unparsed | |
205 JSSWARNING(DMERR_EXTRA_DATA, DMERR_EXTRA_DATA, | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
206 "Unparsed data after pattern (%d bytes), possibly broken file.\n", size); |
0 | 207 } |
208 | |
209 return DMERR_OK; | |
210 } | |
211 | |
212 | |
213 /* Convert XM envelope structure to JSS envelope structure | |
214 */ | |
552
d4cee32e7050
Rename internal structures, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
215 static int jssXMConvertEnvelope(JSSEnvelope * d, XMEnvelope * s, char * e, int instr) |
0 | 216 { |
217 int i; | |
218 (void) e; (void) instr; | |
219 | |
220 // Convert envelope points | |
221 for (i = 0; i < XM_MaxEnvPoints; i++) | |
222 { | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
223 d->points[i].frame = s->points[i].frame; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
224 d->points[i].value = s->points[i].value; |
0 | 225 } |
226 | |
227 // Convert other values | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
228 d->npoints = s->npoints; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
229 d->sustain = s->sustain; |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
230 d->loopS = s->loopS; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
231 d->loopE = s->loopE; |
0 | 232 |
233 // Check if the envelope is used | |
234 if (s->flags & 0x01) | |
235 { | |
236 // Convert envelope flags | |
237 d->flags = jenvfUsed; | |
238 if (s->flags & 0x02) | |
239 d->flags |= jenvfSustain; | |
240 | |
241 if (s->flags & 0x04) | |
242 d->flags |= jenvfLooped; | |
243 | |
244 // Check other values | |
245 if (s->npoints > XM_MaxEnvPoints) | |
246 { | |
247 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
248 "Inst#%d/%s-env: nPoints > MAX, possibly broken file.\n", instr, e); |
0 | 249 s->npoints = XM_MaxEnvPoints; |
250 } | |
251 | |
252 if ((d->flags & jenvfSustain) && s->sustain > s->npoints) | |
253 { | |
254 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
255 "Inst#%d/%s-env: iSustain > nPoints (%d > %d), possibly broken file.\n", |
0 | 256 instr, e, s->sustain, s->npoints); |
257 s->sustain = s->npoints; | |
258 } | |
259 | |
260 if ((d->flags & jenvfLooped) && s->loopE > s->npoints) | |
261 { | |
262 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
263 "Inst#%d/%s-env: loopE > nPoints (%d > %d), possibly broken file.\n", |
0 | 264 instr, e, s->loopE, s->npoints); |
265 s->loopE = s->npoints; | |
266 } | |
267 | |
268 if ((d->flags & jenvfLooped) && s->loopS > s->loopE) | |
269 { | |
270 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
271 "Inst#%d/%s-env: loopS > loopE (%d > %d), possibly broken file.\n", |
0 | 272 instr, e, s->loopS, s->loopE); |
273 s->loopS = 0; | |
274 } | |
275 } | |
276 | |
277 return DMERR_OK; | |
278 } | |
279 | |
280 | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
281 static int jssXMLoadInstrument(DMResource *inFile, JSSModule *module, int ninst, int nsample, int *xmConvTable) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
282 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
283 XMSample xmS; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
284 JSSInstrument *inst; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
285 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
286 // Read header data |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
287 if (!dmf_read_le32(inFile, &xmS.size) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
288 !dmf_read_le32(inFile, &xmS.loopS) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
289 !dmf_read_le32(inFile, &xmS.loopL) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
290 !dmf_read_byte(inFile, &xmS.volume) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
291 !dmf_read_byte(inFile, (Uint8 *) &xmS.fineTune) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
292 !dmf_read_byte(inFile, &xmS.type) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
293 !dmf_read_byte(inFile, &xmS.panning) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
294 !dmf_read_byte(inFile, (Uint8 *) &xmS.relNote) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
295 !dmf_read_byte(inFile, &xmS.ARESERVED) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
296 !dmf_read_str(inFile, &xmS.sampleName, sizeof(xmS.sampleName))) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
297 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
298 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
299 "Error reading instrument sample header #%d/%d [%d]", |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
300 ninst, nsample, module->ninstruments); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
301 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
302 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
303 if (xmS.size <= 0) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
304 return DMERR_OK; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
305 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
306 // Allocate sample instrument |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
307 JSSDEBUG("Allocating sample #%d/%d [%d]\n", |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
308 ninst, nsample, module->ninstruments); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
309 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
310 xmConvTable[nsample] = module->ninstruments; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
311 inst = module->instruments[module->ninstruments] = jssAllocateInstrument(); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
312 if (inst == NULL) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
313 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
314 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
315 "Could not allocate sample #%d/%d [%d]\n", |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
316 ninst, nsample, module->ninstruments); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
317 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
318 module->ninstruments++; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
319 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
320 // Copy values |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
321 if (xmS.volume > XM_MaxSampleVolume) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
322 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
323 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
324 "Samp #%d/%d: volume > MAX\n", ninst, nsample); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
325 xmS.volume = XM_MaxSampleVolume; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
326 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
327 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
328 inst->volume = xmS.volume; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
329 inst->ERelNote = xmS.relNote; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
330 inst->EFineTune = xmS.fineTune; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
331 inst->EPanning = xmS.panning; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
332 #ifndef JSS_LIGHT |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
333 inst->desc = jssASCIItoStr(xmS.sampleName, 0, sizeof(xmS.sampleName)); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
334 #endif |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
335 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
336 // Convert flags |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
337 switch (xmS.type & 0x03) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
338 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
339 case 0: inst->flags = 0; break; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
340 case 1: inst->flags = jsfLooped; break; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
341 case 2: inst->flags = jsfLooped | jsfBiDi; break; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
342 default: |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
343 inst->flags = 0; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
344 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
345 "Samp #%d/%d: Invalid sample type 0x%x\n", |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
346 ninst, nsample, xmS.type); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
347 break; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
348 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
349 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
350 if (xmS.type & 0x10) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
351 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
352 // 16-bit sample |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
353 JSFSET(inst->flags, jsf16bit); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
354 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
355 inst->size = xmS.size / sizeof(Uint16); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
356 inst->loopS = xmS.loopS / sizeof(Uint16); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
357 inst->loopE = ((xmS.loopS + xmS.loopL) / sizeof(Uint16)); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
358 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
359 else |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
360 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
361 // 8-bit sample |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
362 inst->size = xmS.size; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
363 inst->loopS = xmS.loopS; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
364 inst->loopE = (xmS.loopS + xmS.loopL); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
365 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
366 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
367 if (xmS.loopL == 0) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
368 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
369 // Always unset loop, if loop length is zero |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
370 JSFUNSET(inst->flags, jsfLooped); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
371 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
372 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
373 if (inst->flags & jsfLooped) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
374 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
375 if (inst->loopS >= inst->size) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
376 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
377 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
378 "Samp #%d/%d: loopS >= size (%d >= %d)\n", |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
379 ninst, nsample, inst->loopS, inst->size); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
380 JSFUNSET(inst->flags, jsfLooped); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
381 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
382 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
383 if (inst->loopE > inst->size) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
384 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
385 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
386 "Samp #%d/%d: loopE > size (%d > %d)\n", |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
387 ninst, nsample, inst->loopE, inst->size); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
388 JSFUNSET(inst->flags, jsfLooped); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
389 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
390 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
391 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
392 // Allocate memory for sample data |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
393 if (inst->flags & jsf16bit) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
394 inst->data = dmCalloc(inst->size, sizeof(Uint16)); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
395 else |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
396 inst->data = dmCalloc(inst->size, sizeof(Uint8)); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
397 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
398 if (inst->data == NULL) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
399 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
400 "Could not allocate sample data #%d/%d.\n", ninst, nsample); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
401 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
402 return DMERR_OK; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
403 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
404 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
405 |
0 | 406 /* Load XM-format extended instrument from file-stream into JSS module's given inst |
407 */ | |
408 static int jssXMLoadExtInstrument(DMResource *inFile, int ninst, JSSModule *module) | |
409 { | |
410 XMInstrument1 xmI1; | |
411 off_t pos, remainder; | |
412 | |
413 // Get instrument header #1 | |
414 pos = dmftell(inFile); | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
415 if (!dmf_read_le32(inFile, &xmI1.headSize) || |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
416 !dmf_read_str(inFile, &xmI1.instName, sizeof(xmI1.instName)) || |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
417 !dmf_read_byte(inFile, &xmI1.instType) || |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
418 !dmf_read_le16(inFile, &xmI1.nsamples)) |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
419 return DMERR_FREAD; |
0 | 420 |
421 // If there are samples, there is header #2 | |
422 if (xmI1.nsamples > 0) | |
423 { | |
424 int i, nsample, tmp; | |
425 int xmConvTable[XM_MaxInstruments + 1]; | |
426 JSSExtInstrument *pEInst; | |
427 XMInstrument2 xmI2; | |
428 | |
429 // Allocate instrument | |
430 if ((pEInst = jssAllocateExtInstrument()) == NULL) | |
431 { | |
432 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
433 "Could not allocate extended instrument structure #%d\n", ninst); |
0 | 434 } |
435 | |
436 module->extInstruments[ninst] = pEInst; | |
437 | |
438 // Get instrument header #2 | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
439 if (!dmf_read_le32(inFile, &xmI2.headSize) || |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
440 !dmf_read_str(inFile, &xmI2.sNumForNotes, sizeof(xmI2.sNumForNotes))) |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
441 { |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
442 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
443 "Could not read secondary instrument header #1 for #%d.\n", ninst); |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
444 } |
0 | 445 |
446 for (i = 0; i < XM_MaxEnvPoints; i++) | |
447 { | |
448 dmf_read_le16(inFile, &xmI2.volumeEnv.points[i].frame); | |
449 dmf_read_le16(inFile, &xmI2.volumeEnv.points[i].value); | |
450 } | |
451 | |
452 for (i = 0; i < XM_MaxEnvPoints; i++) | |
453 { | |
454 dmf_read_le16(inFile, &xmI2.panningEnv.points[i].frame); | |
455 dmf_read_le16(inFile, &xmI2.panningEnv.points[i].value); | |
456 } | |
457 | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
458 if (!dmf_read_byte(inFile, &xmI2.volumeEnv.npoints) || |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
459 !dmf_read_byte(inFile, &xmI2.panningEnv.npoints) || |
0 | 460 |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
461 !dmf_read_byte(inFile, &xmI2.volumeEnv.sustain) || |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
462 !dmf_read_byte(inFile, &xmI2.volumeEnv.loopS) || |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
463 !dmf_read_byte(inFile, &xmI2.volumeEnv.loopE) || |
0 | 464 |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
465 !dmf_read_byte(inFile, &xmI2.panningEnv.sustain) || |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
466 !dmf_read_byte(inFile, &xmI2.panningEnv.loopS) || |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
467 !dmf_read_byte(inFile, &xmI2.panningEnv.loopE) || |
0 | 468 |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
469 !dmf_read_byte(inFile, &xmI2.volumeEnv.flags) || |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
470 !dmf_read_byte(inFile, &xmI2.panningEnv.flags) || |
0 | 471 |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
472 !dmf_read_byte(inFile, &xmI2.vibratoType) || |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
473 !dmf_read_byte(inFile, &xmI2.vibratoSweep) || |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
474 !dmf_read_byte(inFile, &xmI2.vibratoDepth) || |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
475 !dmf_read_byte(inFile, &xmI2.vibratoRate) || |
0 | 476 |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
477 !dmf_read_le16(inFile, &xmI2.fadeOut) || |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
478 !dmf_read_le16(inFile, &xmI2.ARESERVED)) |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
479 { |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
480 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
481 "Could not read secondary instrument header #2 for #%d.\n", ninst); |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
482 } |
0 | 483 |
484 // Skip the extra data after header #2 | |
485 remainder = xmI1.headSize - (dmftell(inFile) - pos); | |
486 if (remainder > 0) | |
487 { | |
98 | 488 JSSDEBUG("xmI1#1 Skipping: %li\n", remainder); |
0 | 489 dmfseek(inFile, remainder, SEEK_CUR); |
490 } | |
491 | |
492 // Check and convert all ext instrument information | |
493 #ifndef JSS_LIGHT | |
494 pEInst->desc = jssASCIItoStr(xmI1.instName, 0, sizeof(xmI1.instName)); | |
495 #endif | |
496 jssXMConvertEnvelope(&pEInst->volumeEnv, &xmI2.volumeEnv, "vol", ninst); | |
497 jssXMConvertEnvelope(&pEInst->panningEnv, &xmI2.panningEnv, "pan", ninst); | |
498 | |
499 switch (xmI2.vibratoType) | |
500 { | |
501 case 0: pEInst->vibratoType = jvibSine; break; | |
502 case 1: pEInst->vibratoType = jvibRamp; break; | |
503 case 2: pEInst->vibratoType = jvibSquare; break; | |
504 case 3: pEInst->vibratoType = jvibRandom; break; | |
505 default: | |
506 pEInst->vibratoType = jvibSine; | |
507 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | |
508 "Invalid extinstrument vibrato type %d for inst #%d\n", ninst); | |
509 break; | |
510 } | |
511 pEInst->vibratoSweep = xmI2.vibratoSweep; | |
512 pEInst->vibratoDepth = xmI2.vibratoDepth; | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
513 pEInst->vibratoRate = xmI2.vibratoRate; |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
514 pEInst->fadeOut = xmI2.fadeOut; |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
515 pEInst->nsamples = xmI1.nsamples; |
0 | 516 |
517 // Initialize the SNumForNotes conversion table | |
518 for (i = 0; i < XM_MaxInstruments; i++) | |
519 xmConvTable[i] = jsetNotSet; | |
520 | |
521 // Read sample headers | |
522 for (nsample = 0; nsample < xmI1.nsamples; nsample++) | |
523 { | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
524 int result; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
525 if ((result = jssXMLoadInstrument(inFile, module, ninst, nsample, xmConvTable)) != DMERR_OK) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
526 return result; |
0 | 527 } |
528 | |
529 // Read sample data | |
530 for (nsample = 0; nsample < xmI1.nsamples; nsample++) | |
531 if (xmConvTable[nsample] != jsetNotSet) | |
532 { | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
533 JSSInstrument *inst = module->instruments[xmConvTable[nsample]]; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
534 if (inst) |
0 | 535 { |
536 JSSDEBUG("desc....: '%s'\n" | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
537 "size....: %d\n" |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
538 "loopS...: %d\n" |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
539 "loopE...: %d\n" |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
540 "volume..: %d\n" |
0 | 541 "flags...: %x\n", |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
542 inst->desc, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
543 inst->size, inst->loopS, inst->loopE, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
544 inst->volume, inst->flags); |
0 | 545 |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
546 if (inst->flags & jsf16bit) |
0 | 547 { |
548 // Read sampledata | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
549 if (dmfread(inst->data, sizeof(Uint16), inst->size, inFile) != (size_t) inst->size) |
0 | 550 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
551 "Error reading sampledata for instrument #%d/%d, %d words.\n", |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
552 ninst, nsample, inst->size); |
0 | 553 |
554 // Convert data | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
555 jssDecodeSample16((Uint16 *) inst->data, inst->size, |
0 | 556 #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) |
557 (jsampDelta | jsampSwapEndianess) | |
558 #else | |
559 (jsampDelta) | |
560 #endif | |
561 ); | |
562 } | |
563 else | |
564 { | |
565 // Read sampledata | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
566 if (dmfread(inst->data, sizeof(Uint8), inst->size, inFile) != (size_t) inst->size) |
0 | 567 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
568 "Error reading sampledata for instrument #%d/%d, %d bytes.\n", |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
569 ninst, nsample, inst->size); |
0 | 570 |
571 // Convert data | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
572 jssDecodeSample8((Uint8 *) inst->data, inst->size, |
0 | 573 (jsampDelta | jsampFlipSign)); |
574 } | |
575 } | |
576 } | |
577 | |
578 // Apply new values to sNumForNotes values | |
579 for (i = 0; i < XM_MaxNotes; i++) | |
580 { | |
581 tmp = xmI2.sNumForNotes[i]; | |
582 if (tmp >= 0 && tmp < xmI1.nsamples) | |
583 pEInst->sNumForNotes[i] = xmConvTable[tmp]; | |
584 else | |
585 { | |
586 pEInst->sNumForNotes[i] = jsetNotSet; | |
587 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | |
588 "Ext.instrument #%d sNumForNotes[%d] out of range (%d).\n", | |
589 ninst, i, tmp); | |
590 } | |
591 } | |
592 } | |
593 else | |
594 { | |
595 // We may STILL need to skip extra data after 1st instr. header | |
596 remainder = xmI1.headSize - (dmftell(inFile) - pos); | |
597 if (remainder > 0) | |
598 { | |
98 | 599 JSSDEBUG("xmI1#2 Skipping: %li\n", remainder); |
0 | 600 dmfseek(inFile, remainder, SEEK_CUR); |
601 } | |
602 } | |
603 | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
604 return DMERR_OK; |
0 | 605 } |
606 | |
607 | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
608 static int jssXMLoadPatterns(DMResource *inFile, JSSModule *module, XMHeader *xmH) |
0 | 609 { |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
610 int index, result; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
611 XMPattern xmP; |
0 | 612 |
613 for (index = 0; index < module->npatterns; index++) | |
614 { | |
88 | 615 off_t pos, remainder; |
0 | 616 |
617 // Get the pattern header | |
98 | 618 pos = dmftell(inFile); |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
619 |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
620 if (!dmf_read_le32(inFile, &xmP.headSize) || |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
621 !dmf_read_byte(inFile, &xmP.packing) || |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
622 !dmf_read_le16(inFile, &xmP.nrows) || |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
623 !dmf_read_le16(inFile, &xmP.size)) |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
624 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
625 "Could not read pattern header data #%d.\n", |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
626 index); |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
627 |
0 | 628 |
629 // Check the header | |
630 if (xmP.packing != 0) | |
631 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
632 "Pattern #%d packing type unsupported (%d)\n", |
0 | 633 index, xmP.packing); |
634 | |
635 if (xmP.nrows == 0) | |
636 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
637 "Pattern #%d has %d rows, invalid data.\n", |
0 | 638 index, xmP.nrows); |
639 | |
640 if (xmP.size > 0) | |
641 { | |
642 // Allocate and unpack pattern | |
643 module->patterns[index] = jssAllocatePattern(xmP.nrows, module->nchannels); | |
644 if (module->patterns[index] == NULL) | |
645 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
646 "Could not allocate memory for pattern #%d\n", index); |
0 | 647 |
648 result = jssXMUnpackPattern(inFile, xmP.size, module->patterns[index]); | |
649 if (result != 0) | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
650 JSSERROR(result, result, "Error in unpacking pattern #%d data\n", index); |
0 | 651 } |
652 | |
653 // Skip extra data (if the file is damaged) | |
88 | 654 remainder = xmP.headSize - (dmftell(inFile) - pos); |
655 if (remainder > 0) | |
0 | 656 { |
98 | 657 JSSDEBUG("xmP Skipping: %li\n", remainder); |
88 | 658 dmfseek(inFile, remainder, SEEK_CUR); |
0 | 659 } |
660 } | |
661 | |
662 // Allocate the empty pattern | |
663 module->patterns[jsetMaxPatterns] = jssAllocatePattern(64, module->nchannels); | |
664 | |
665 /* Convert song orders list by replacing nonexisting patterns | |
666 * with pattern number jsetMaxPatterns. | |
667 */ | |
668 for (index = 0; index < module->norders; index++) | |
669 { | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
670 int tmp = xmH->orderList[index]; |
0 | 671 if (tmp >= module->npatterns || module->patterns[tmp] == NULL) |
672 tmp = jsetMaxPatterns; | |
673 | |
674 module->orderList[index] = tmp; | |
675 } | |
676 | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
677 return DMERR_OK; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
678 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
679 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
680 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
681 static int jssXMLoadInstruments(DMResource *inFile, JSSModule *module) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
682 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
683 int index; |
0 | 684 for (index = 0; index < module->nextInstruments; index++) |
685 { | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
686 int result = jssXMLoadExtInstrument(inFile, index, module); |
0 | 687 if (result != 0) |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
688 JSSERROR(result, result, "Errors while reading instrument #%d\n", index); |
0 | 689 } |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
690 return DMERR_OK; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
691 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
692 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
693 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
694 /* Load XM-format module from given file-stream |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
695 */ |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
696 int jssLoadXM(DMResource *inFile, JSSModule **ppModule, BOOL probe) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
697 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
698 JSSModule *module; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
699 XMHeader xmH; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
700 int index, result; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
701 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
702 assert(ppModule != NULL); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
703 assert(inFile != NULL); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
704 *ppModule = NULL; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
705 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
706 // Try to get the XM-header |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
707 if (!dmf_read_str(inFile, &xmH.idMagic, sizeof(xmH.idMagic)) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
708 !dmf_read_str(inFile, &xmH.songName, sizeof(xmH.songName)) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
709 !dmf_read_byte(inFile, &xmH.unUsed1A) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
710 !dmf_read_str(inFile, &xmH.trackerName, sizeof(xmH.trackerName)) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
711 !dmf_read_le16(inFile, &xmH.version) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
712 !dmf_read_le32(inFile, &xmH.headSize) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
713 !dmf_read_le16(inFile, &xmH.norders) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
714 !dmf_read_le16(inFile, &xmH.defRestartPos) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
715 !dmf_read_le16(inFile, &xmH.nchannels) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
716 !dmf_read_le16(inFile, &xmH.npatterns) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
717 !dmf_read_le16(inFile, &xmH.ninstruments) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
718 !dmf_read_le16(inFile, &xmH.flags) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
719 !dmf_read_le16(inFile, &xmH.defSpeed) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
720 !dmf_read_le16(inFile, &xmH.defTempo)) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
721 return DMERR_FREAD; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
722 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
723 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
724 // Check the fields, none of these are considered fatal |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
725 if (strncmp(xmH.idMagic, "Extended Module: ", 17) != 0) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
726 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
727 if (probe) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
728 return DMERR_NOT_SUPPORTED; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
729 else |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
730 JSSERROR(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
731 "Not a FT2 Extended Module (XM), header signature mismatch!\n"); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
732 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
733 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
734 if (xmH.unUsed1A != 0x1a) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
735 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
736 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
737 "Possibly modified or corrupted XM [%x]\n", xmH.unUsed1A); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
738 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
739 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
740 if (xmH.norders > XM_MaxOrders) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
741 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
742 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
743 "Number of orders %d > %d, possibly broken module.\n", |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
744 xmH.norders, XM_MaxOrders); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
745 xmH.norders = XM_MaxOrders; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
746 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
747 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
748 if (xmH.norders == 0) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
749 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
750 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
751 "Number of orders was zero.\n"); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
752 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
753 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
754 if (xmH.npatterns > XM_MaxPatterns) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
755 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
756 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
757 "Number of patterns %d > %d, possibly broken module.\n", |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
758 xmH.npatterns, XM_MaxPatterns); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
759 xmH.npatterns = XM_MaxPatterns; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
760 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
761 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
762 if (xmH.npatterns == 0) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
763 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
764 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
765 "Number of patterns was zero.\n"); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
766 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
767 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
768 if (xmH.nchannels <= 0 || xmH.nchannels > XM_MaxChannels) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
769 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
770 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
771 "Number of channels was invalid, %d (should be 1 - %d).\n", |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
772 xmH.nchannels, XM_MaxChannels); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
773 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
774 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
775 if (xmH.ninstruments <= 0 || xmH.ninstruments > XM_MaxInstruments) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
776 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
777 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
778 "Number of instruments was invalid, %d (should be 1 - %d).\n", |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
779 xmH.ninstruments, XM_MaxInstruments); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
780 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
781 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
782 if (!dmf_read_str(inFile, &xmH.orderList, sizeof(xmH.orderList))) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
783 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
784 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
785 "Error reading pattern order list.\n"); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
786 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
787 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
788 /* Okay, allocate a module structure |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
789 */ |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
790 module = jssAllocateModule(); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
791 if (module == NULL) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
792 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
793 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
794 "Could not allocate memory for module structure.\n"); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
795 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
796 *ppModule = module; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
797 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
798 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
799 // Convert and check the header data |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
800 module->moduleType = jmdtXM; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
801 module->intVersion = xmH.version; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
802 #ifndef JSS_LIGHT |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
803 module->moduleName = jssASCIItoStr(xmH.songName, 0, sizeof(xmH.songName)); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
804 module->trackerName = jssASCIItoStr(xmH.trackerName, 0, sizeof(xmH.trackerName)); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
805 #endif |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
806 module->defSpeed = xmH.defSpeed; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
807 module->defTempo = xmH.defTempo; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
808 module->nextInstruments = xmH.ninstruments; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
809 module->ninstruments = 0; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
810 module->npatterns = xmH.npatterns; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
811 module->norders = xmH.norders; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
812 module->nchannels = xmH.nchannels; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
813 module->defFlags = jmdfStereo | jmdfFT2Replay; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
814 module->defRestartPos = xmH.defRestartPos; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
815 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
816 if ((xmH.flags & 1) == 0) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
817 module->defFlags |= jmdfAmigaPeriods; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
818 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
819 // Setup the default pannings |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
820 for (index = 0; index < jsetNChannels; index++) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
821 module->defPanning[index] = jchPanMiddle; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
822 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
823 // Load rest of the module |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
824 if ((result = jssXMLoadPatterns(inFile, module, &xmH)) != DMERR_OK) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
825 return result; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
826 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
827 if ((result = jssXMLoadInstruments(inFile, module)) != DMERR_OK) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
828 return result; |
0 | 829 |
830 return DMERR_OK; | |
831 } |