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