Mercurial > hg > dmlib
annotate minijss/jloadjss.c @ 1198:5d20c80df290
Improve probing.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 05 Mar 2015 16:14:40 +0200 |
parents | 0ee6ba7b3e4a |
children | fa758951720f |
rev | line source |
---|---|
0 | 1 /* |
2 * miniJSS - JSSMOD module loader | |
3 * Programmed and designed by Matti 'ccr' Hamalainen | |
1163 | 4 * (C) Copyright 2007-2015 Tecnic Software productions (TNSP) |
0 | 5 */ |
6 #include "jssmod.h" | |
7 | |
8 | |
1196 | 9 // If all pattern modes are required, enable them here |
0 | 10 #ifdef JM_SUP_PATMODE_ALL |
282 | 11 # define JM_SUP_PATMODE_1 1 |
12 # define JM_SUP_PATMODE_2 1 | |
13 # define JM_SUP_PATMODE_3 1 | |
14 # define JM_SUP_PATMODE_4 1 | |
15 # define JM_SUP_PATMODE_5 1 | |
0 | 16 #endif |
17 | |
18 | |
1196 | 19 // Short helper macros for reading data |
20 #define JSGETBUF(XV, XT) \ | |
21 if (!dmf_read_str(inFile, XV, sizeof(XT))) \ | |
22 return DMERR_OUT_OF_DATA | |
23 | |
24 #define JSGETBYTE(XV) \ | |
25 if (!dmf_read_byte(inFile, XV)) \ | |
26 return DMERR_OUT_OF_DATA | |
0 | 27 |
28 | |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
29 #if defined(JM_SUP_PATMODE_1) || defined(JM_SUP_PATMODE_3) |
1197 | 30 static int jssGetConvertedNote(DMResource *inFile, JSSNote *pnote) |
0 | 31 { |
32 Uint8 tmp; | |
33 | |
34 JSGETBYTE(&tmp); | |
35 | |
36 if (tmp == 127) | |
1197 | 37 pnote->note = jsetNoteOff; |
0 | 38 else if (tmp == 0) |
1197 | 39 pnote->note = jsetNotSet; |
0 | 40 else |
1197 | 41 pnote->note = tmp - 1; |
0 | 42 |
43 JSGETBYTE(&tmp); | |
1197 | 44 pnote->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet; |
0 | 45 |
46 JSGETBYTE(&tmp); | |
1197 | 47 pnote->volume = (tmp > 0) ? tmp - 1 : jsetNotSet; |
0 | 48 |
49 JSGETBYTE(&tmp); | |
1197 | 50 pnote->effect = (tmp > 0) ? tmp - 1 : jsetNotSet; |
0 | 51 |
52 JSGETBYTE(&tmp); | |
1197 | 53 pnote->param = (tmp == 0 && pnote->effect == jsetNotSet) ? jsetNotSet : tmp; |
0 | 54 |
55 return DMERR_OK; | |
56 } | |
57 #endif | |
58 | |
59 | |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
60 #if defined(JM_SUP_PATMODE_2) || defined(JM_SUP_PATMODE_4) |
1197 | 61 static int jssGetCompressedNote(DMResource *inFile, JSSNote *pnote) |
0 | 62 { |
63 Uint8 packb, tmp; | |
64 | |
65 JSGETBYTE(&packb); | |
66 if (packb & 0x80) | |
67 { | |
68 if (packb & COMP_NOTE) | |
69 { | |
70 JSGETBYTE(&tmp); | |
71 if (tmp == 127) | |
1197 | 72 pnote->note = jsetNoteOff; |
0 | 73 else |
1197 | 74 pnote->note = tmp; |
0 | 75 } |
76 | |
77 if (packb & COMP_INSTRUMENT) | |
78 { | |
79 JSGETBYTE(&tmp); | |
1197 | 80 pnote->instrument = tmp; |
0 | 81 } |
82 | |
83 if (packb & COMP_VOLUME) | |
84 { | |
85 JSGETBYTE(&tmp); | |
1197 | 86 pnote->volume = tmp; |
0 | 87 } |
88 | |
89 if (packb & COMP_EFFECT) | |
90 { | |
91 JSGETBYTE(&tmp); | |
1197 | 92 pnote->effect = tmp; |
93 pnote->param = 0; | |
0 | 94 } |
95 | |
96 if (packb & COMP_PARAM) | |
97 { | |
98 JSGETBYTE(&tmp); | |
1197 | 99 pnote->param = tmp; |
0 | 100 } |
101 } | |
102 else | |
103 { | |
104 tmp = packb; | |
105 | |
106 if (tmp == 127) | |
1197 | 107 pnote->note = jsetNoteOff; |
1196 | 108 else |
109 if (tmp == 0) | |
1197 | 110 pnote->note = jsetNotSet; |
0 | 111 else |
1197 | 112 pnote->note = tmp - 1; |
0 | 113 |
114 JSGETBYTE(&tmp); | |
1197 | 115 pnote->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet; |
0 | 116 |
117 JSGETBYTE(&tmp); | |
1197 | 118 pnote->volume = (tmp > 0) ? tmp - 1 : jsetNotSet; |
0 | 119 |
120 JSGETBYTE(&tmp); | |
1197 | 121 pnote->effect = (tmp > 0) ? tmp - 1 : jsetNotSet; |
0 | 122 |
123 JSGETBYTE(&tmp); | |
1197 | 124 pnote->param = (tmp == 0 && pnote->effect == jsetNotSet) ? jsetNotSet : tmp; |
0 | 125 } |
126 | |
127 return DMERR_OK; | |
128 } | |
129 #endif | |
130 | |
131 | |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
132 #ifdef JM_SUP_PATMODE_2 |
777
ed60a7ee3ebb
Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
133 static int jssGetPatternCompHoriz(DMResource *inFile, JSSPattern *pattern) |
0 | 134 { |
135 int row, channel; | |
136 | |
137 assert(buf != NULL); | |
138 assert(pattern != NULL); | |
139 | |
140 for (row = 0; row < pattern->nrows; row++) | |
141 for (channel = 0; channel < pattern->nchannels; channel++) | |
142 { | |
1197 | 143 JSSNote *pnote = &pattern->data[(pattern->nchannels * row) + channel]; |
144 int res = jssGetCompressedNote(inFile, pnote); | |
0 | 145 if (res != DMERR_OK) |
1197 | 146 JSSERROR(res, res, "Error uncompressing note on row=%d, chn=%d\n", |
147 row, channel); | |
0 | 148 } |
149 | |
150 return DMERR_OK; | |
151 } | |
152 #endif | |
153 | |
154 | |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
155 #ifdef JM_SUP_PATMODE_4 |
777
ed60a7ee3ebb
Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
156 static int jssGetPatternCompVert(DMResource *inFile, JSSPattern *pattern) |
0 | 157 { |
158 int row, channel; | |
159 | |
160 assert(buf != NULL); | |
161 assert(pattern != NULL); | |
162 | |
163 for (channel = 0; channel < pattern->nchannels; channel++) | |
164 for (row = 0; row < pattern->nrows; row++) | |
165 { | |
1197 | 166 JSSNote *pnote = &pattern->data[(pattern->nchannels * row) + channel]; |
167 int res = jssGetCompressedNote(inFile, pnote); | |
0 | 168 if (res != DMERR_OK) |
1197 | 169 JSSERROR(res, res, "Error uncompressing note on row=%d, chn=%d\n", |
170 row, channel); | |
0 | 171 } |
172 | |
173 return DMERR_OK; | |
174 } | |
175 #endif | |
176 | |
177 | |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
178 #ifdef JM_SUP_PATMODE_1 |
777
ed60a7ee3ebb
Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
179 static int jssGetPatternRawHoriz(DMResource *inFile, JSSPattern *pattern) |
0 | 180 { |
181 int row, channel; | |
182 | |
183 assert(buf != NULL); | |
184 assert(pattern != NULL); | |
185 | |
186 for (row = 0; row < pattern->nrows; row++) | |
187 for (channel = 0; channel < pattern->nchannels; channel++) | |
188 { | |
1197 | 189 JSSNote *pnote = &pattern->data[(pattern->nchannels * row) + channel]; |
190 int res = jssGetConvertedNote(inFile, pnote); | |
0 | 191 if (res != DMERR_OK) |
1197 | 192 JSSERROR(res, res, "Error converting note on row=%d, chn=%d\n", |
193 row, channel); | |
0 | 194 } |
195 | |
196 return DMERR_OK; | |
197 } | |
198 #endif | |
199 | |
200 | |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
201 #ifdef JM_SUP_PATMODE_3 |
777
ed60a7ee3ebb
Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
202 static int jssGetPatternRawVert(DMResource *inFile, JSSPattern *pattern) |
0 | 203 { |
204 int row, channel; | |
205 | |
206 assert(buf != NULL); | |
207 assert(pattern != NULL); | |
208 | |
209 for (channel = 0; channel < pattern->nchannels; channel++) | |
210 for (row = 0; row < pattern->nrows; row++) | |
211 { | |
1197 | 212 JSSNote *pnote = &pattern->data[(pattern->nchannels * row) + channel]; |
213 int res = jssGetConvertedNote(inFile, pnote); | |
0 | 214 if (res != DMERR_OK) |
1197 | 215 JSSERROR(res, res, "Error converting note on row=%d, chn=%d\n", |
216 row, channel); | |
0 | 217 } |
218 | |
219 return DMERR_OK; | |
220 } | |
221 #endif | |
222 | |
223 | |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
224 #ifdef JM_SUP_PATMODE_5 |
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
225 |
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
226 #undef JSGETBYTE |
777
ed60a7ee3ebb
Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
227 #define JSGETBYTE(XV) if (!dmf_read_byte(inFile, XV)) return DMERR_OUT_OF_DATA |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
228 |
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
229 #define JSFOREACHNOTE1 \ |
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
230 for (channel = 0; channel < pattern->nchannels; channel++) \ |
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
231 for (row = 0; row < pattern->nrows; row++) { \ |
1197 | 232 JSSNote *pnote = pattern->data + (pattern->nchannels * row) + channel; |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
233 |
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
234 #define JSFOREACHNOTE2 } |
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
235 |
777
ed60a7ee3ebb
Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
236 static int jssGetPatternRawVertElem(DMResource *inFile, JSSPattern *pattern) |
0 | 237 { |
238 int row, channel; | |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
239 Uint8 tmp; |
0 | 240 |
241 assert(buf != NULL); | |
242 assert(pattern != NULL); | |
243 | |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
244 JSFOREACHNOTE1 |
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
245 JSGETBYTE(&tmp); |
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
246 if (tmp == 0) |
1197 | 247 pnote->note = jsetNotSet; |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
248 else if (tmp == 127) |
1197 | 249 pnote->note = jsetNoteOff; |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
250 else |
1197 | 251 pnote->note = tmp - 1; |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
252 JSFOREACHNOTE2 |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1118
diff
changeset
|
253 |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
254 JSFOREACHNOTE1 |
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
255 JSGETBYTE(&tmp); |
1197 | 256 pnote->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet; |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
257 JSFOREACHNOTE2 |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1118
diff
changeset
|
258 |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
259 JSFOREACHNOTE1 |
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
260 JSGETBYTE(&tmp); |
1197 | 261 pnote->volume = (tmp > 0) ? tmp - 1 : jsetNotSet; |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
262 JSFOREACHNOTE2 |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1118
diff
changeset
|
263 |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
264 JSFOREACHNOTE1 |
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
265 JSGETBYTE(&tmp); |
1197 | 266 pnote->effect = (tmp > 0) ? tmp - 1 : jsetNotSet; |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
267 JSFOREACHNOTE2 |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1118
diff
changeset
|
268 |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
269 JSFOREACHNOTE1 |
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
270 JSGETBYTE(&tmp); |
1197 | 271 pnote->param = (tmp == 0 && pnote->effect == jsetNotSet) ? jsetNotSet : tmp; |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
272 JSFOREACHNOTE2 |
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
273 |
0 | 274 return DMERR_OK; |
275 } | |
276 #endif | |
277 | |
278 | |
279 #undef JSGETBUF | |
280 #undef JSGETBYTE | |
281 #define JSGETBUF(XV, XT) do { \ | |
777
ed60a7ee3ebb
Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
282 if (!dmf_read_str(inFile, XV, sizeof(XT))) \ |
0 | 283 JSSERROR(DMERR_OUT_OF_DATA, DMERR_OUT_OF_DATA, \ |
284 "Out of data at getting " # XT " (%d bytes)\n", sizeof(XT)); \ | |
285 } while (0) | |
777
ed60a7ee3ebb
Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
286 #define JSGETBYTE(XV) if (!dmf_read_byte(inFile, XV)) return DMERR_OUT_OF_DATA |
0 | 287 |
288 | |
289 #ifdef JM_SUP_EXT_INSTR | |
290 static void jssCopyEnvelope(JSSEnvelope *e, JSSMODEnvelope *je) | |
291 { | |
292 int i; | |
293 | |
294 e->flags = je->flags; | |
295 e->npoints = je->npoints; | |
296 e->sustain = je->sustain; | |
297 e->loopS = je->loopS; | |
298 e->loopE = je->loopE; | |
299 | |
300 for (i = 0; i < je->npoints; i++) | |
301 { | |
302 e->points[i].frame = je->points[i].frame; | |
303 e->points[i].value = je->points[i].value; | |
304 } | |
305 } | |
306 #endif | |
307 | |
308 | |
796 | 309 int jssLoadJSSMOD(DMResource *inFile, JSSModule **ppModule, BOOL probe) |
0 | 310 { |
311 JSSModule *module; | |
312 JSSMODHeader jssH; | |
313 int index; | |
314 | |
315 *ppModule = NULL; | |
316 | |
317 // Check the JSSMOD header | |
1167 | 318 dmMemset(&jssH, 0, sizeof(jssH)); |
0 | 319 JSGETBUF(&jssH, JSSMODHeader); |
320 | |
321 if (memcmp(jssH.idMagic, "JM", 2) != 0) | |
322 { | |
796 | 323 if (probe) |
324 return DMERR_NOT_SUPPORTED; | |
325 else | |
326 JSSERROR(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED, | |
327 "Not a JSSMOD file, header signature mismatch!\n"); | |
0 | 328 } |
329 | |
330 if (jssH.idVersion != JSSMOD_VERSION) | |
331 { | |
1198 | 332 if (probe) |
333 return DMERR_VERSION; | |
334 else | |
0 | 335 JSSERROR(DMERR_VERSION, DMERR_VERSION, |
336 "Unsupported version of JSSMOD 0x%4x, this version only supports 0x%4x!\n", | |
337 jssH.idVersion, JSSMOD_VERSION); | |
338 } | |
339 | |
1198 | 340 if (probe) |
341 return DMERR_OK; | |
342 | |
0 | 343 // Allocate the module |
344 module = jssAllocateModule(); | |
345 if (module == NULL) | |
346 { | |
347 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, | |
348 "Could not allocate memory for module structure.\n"); | |
349 } | |
350 *ppModule = module; | |
351 | |
352 // Copy header information | |
353 module->norders = jssH.norders; | |
354 module->npatterns = jssH.npatterns; | |
355 module->nchannels = jssH.nchannels; | |
356 module->nextInstruments = jssH.nextInstruments; | |
357 module->ninstruments = jssH.ninstruments; | |
358 module->defFlags = jssH.defFlags; | |
359 module->intVersion = jssH.intVersion; | |
360 module->defRestartPos = jssH.defRestartPos; | |
361 module->defSpeed = jssH.defSpeed; | |
362 module->defTempo = jssH.defTempo; | |
363 | |
364 // Get the orders list | |
365 for (index = 0; index < module->norders; index++) | |
366 { | |
367 Sint16 order; | |
368 JSGETBUF(&order, Sint16); | |
369 module->orderList[index] = order; | |
370 } | |
371 | |
372 // Parse the patterns | |
373 for (index = 0; index < module->npatterns; index++) | |
374 { | |
375 JSSMODPattern jssP; | |
376 int result = DMERR_INVALID_DATA; | |
377 | |
378 // Get header and check size | |
1167 | 379 dmMemset(&jssP, 0, sizeof(jssP)); |
0 | 380 JSGETBUF(&jssP, JSSMODPattern); |
381 | |
382 // Allocate pattern | |
383 module->patterns[index] = jssAllocatePattern(jssP.nrows, module->nchannels); | |
384 if (module->patterns[index] == NULL) | |
385 { | |
386 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, | |
387 "Could not allocate memory for pattern #%d.\n", index); | |
388 } | |
389 | |
390 // Get pattern data | |
391 switch (jssH.patMode) | |
392 { | |
393 #ifdef JM_SUP_PATMODE_1 | |
394 case PATMODE_RAW_HORIZ: | |
777
ed60a7ee3ebb
Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
395 result = jssGetPatternRawHoriz(inFile, module->patterns[index]); |
0 | 396 break; |
397 #endif | |
398 #ifdef JM_SUP_PATMODE_2 | |
399 case PATMODE_COMP_HORIZ: | |
777
ed60a7ee3ebb
Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
400 result = jssGetPatternCompHoriz(inFile, module->patterns[index]); |
0 | 401 break; |
402 #endif | |
403 #ifdef JM_SUP_PATMODE_3 | |
404 case PATMODE_RAW_VERT: | |
777
ed60a7ee3ebb
Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
405 result = jssGetPatternRawVert(inFile, module->patterns[index]); |
0 | 406 break; |
407 #endif | |
408 #ifdef JM_SUP_PATMODE_4 | |
409 case PATMODE_COMP_VERT: | |
777
ed60a7ee3ebb
Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
410 result = jssGetPatternCompVert(inFile, module->patterns[index]); |
0 | 411 break; |
412 #endif | |
413 #ifdef JM_SUP_PATMODE_5 | |
414 case PATMODE_RAW_ELEM: | |
777
ed60a7ee3ebb
Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
415 result = jssGetPatternRawVertElem(inFile, module->patterns[index]); |
0 | 416 break; |
417 #endif | |
418 default: | |
419 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | |
420 "Unsupported pattern mode %d. Check compilation options.", jssH.patMode); | |
421 break; | |
422 } | |
423 | |
424 if (result != DMERR_OK) | |
425 { | |
426 JSSERROR(result, result, "Error in unpacking pattern #%i data\n", index); | |
427 } | |
428 } | |
429 | |
430 #ifdef JM_SUP_EXT_INSTR | |
431 // Read extended instruments | |
432 for (index = 0; index < module->nextInstruments; index++) | |
433 { | |
434 JSSMODExtInstrument jssE; | |
435 JSSExtInstrument *einst; | |
436 int i; | |
437 | |
1167 | 438 dmMemset(&jssE, 0, sizeof(jssE)); |
0 | 439 JSGETBUF(&jssE, JSSMODExtInstrument); |
440 | |
441 if ((einst = jssAllocateExtInstrument()) == NULL) | |
442 { | |
443 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, | |
444 "Could not allocate extended instrument structure #%i\n", index); | |
445 } | |
446 | |
447 module->extInstruments[index] = einst; | |
448 | |
449 einst->nsamples = jssE.nsamples; | |
450 einst->vibratoType = jssE.vibratoType; | |
451 einst->vibratoSweep = jssE.vibratoSweep; | |
452 einst->vibratoDepth = jssE.vibratoDepth; | |
453 einst->vibratoRate = jssE.vibratoRate; | |
454 einst->fadeOut = jssE.fadeOut; | |
455 | |
456 for (i = 0; i < jsetNNotes; i++) | |
457 { | |
458 int snum = jssE.sNumForNotes[i]; | |
1118
de25e0f2b856
Fix sNumForNotes conversion/handling in JSSMOD loader and xm2jss.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
459 einst->sNumForNotes[i] = (snum > 0) ? snum - 1 : jsetNotSet; |
0 | 460 } |
461 | |
462 jssCopyEnvelope(&(einst->volumeEnv), &jssE.volumeEnv); | |
463 jssCopyEnvelope(&(einst->panningEnv), &jssE.panningEnv); | |
464 } | |
465 | |
466 #ifdef JM_SUP_INSTR | |
467 // Read sample instrument headers | |
468 for (index = 0; index < module->ninstruments; index++) | |
469 { | |
470 JSSMODInstrument jssI; | |
471 JSSInstrument *inst; | |
472 | |
1167 | 473 dmMemset(&jssI, 0, sizeof(jssI)); |
0 | 474 JSGETBUF(&jssI, JSSMODInstrument); |
475 | |
476 if ((inst = jssAllocateInstrument()) == NULL) | |
477 { | |
478 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, | |
479 "Could not allocate instrument structure #%i\n", index); | |
480 } | |
481 | |
482 module->instruments[index] = inst; | |
483 | |
484 inst->size = jssI.size; | |
485 inst->loopS = jssI.loopS; | |
486 inst->loopE = jssI.loopE; | |
487 inst->volume = jssI.volume; | |
488 inst->flags = jssI.flags; | |
489 inst->C4BaseSpeed = jssI.C4BaseSpeed; | |
490 inst->ERelNote = jssI.ERelNote; | |
491 inst->EFineTune = jssI.EFineTune; | |
492 inst->EPanning = jssI.EPanning; | |
493 inst->hasData = jssI.hasData; | |
494 inst->convFlags = jssI.convFlags; | |
495 } | |
496 | |
497 #ifdef JM_SUP_SAMPLES | |
498 // Read sample data | |
499 for (index = 0; index < module->ninstruments; index++) | |
500 { | |
501 JSSInstrument *inst = module->instruments[index]; | |
502 | |
503 if (inst && inst->hasData) | |
504 { | |
1129
e466d10dae6d
Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
505 int ret; |
0 | 506 size_t sz; |
507 | |
508 // Calculate data size | |
509 if (inst->flags & jsf16bit) | |
510 sz = inst->size * sizeof(Uint16); | |
511 else | |
512 sz = inst->size * sizeof(Uint8); | |
513 | |
514 // Allocate | |
515 if ((inst->data = dmMalloc(sz)) == NULL) | |
516 { | |
517 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, | |
518 "Could not allocate sample data #%d\n", index); | |
519 } | |
520 | |
521 // Copy data | |
777
ed60a7ee3ebb
Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
522 if (!dmf_read_str(inFile, inst->data, sz)) |
ed60a7ee3ebb
Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
523 { |
ed60a7ee3ebb
Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
524 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
ed60a7ee3ebb
Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
525 "Could not read sample data for #%d\n", index); |
ed60a7ee3ebb
Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
526 } |
0 | 527 |
528 // Convert, if needed | |
529 if (inst->flags & jsf16bit) | |
1129
e466d10dae6d
Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
530 ret = jssDecodeSample16(inst->data, inst->size, inst->convFlags); |
0 | 531 else |
1129
e466d10dae6d
Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
532 ret = jssDecodeSample8(inst->data, inst->size, inst->convFlags); |
e466d10dae6d
Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
533 |
e466d10dae6d
Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
534 if (ret != DMERR_OK) |
e466d10dae6d
Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
535 { |
e466d10dae6d
Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
536 JSSERROR(ret, ret, |
e466d10dae6d
Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
537 "Failed to decode sample data for #%d\n", index); |
e466d10dae6d
Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
538 } |
0 | 539 } |
540 } | |
541 #else | |
282 | 542 # warning Not including JSSMOD sample loading! |
0 | 543 #endif // JM_SUP_SAMPLES |
544 #else | |
282 | 545 # warning Not including JSSMOD instrument loading! |
0 | 546 #endif // JM_SUP_INSTR |
547 #else | |
282 | 548 # warning Not including JSSMOD ext.instrument loading! |
0 | 549 #endif // JM_SUP_EXT_INSTR |
550 | |
551 return DMERR_OK; | |
552 } |