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