comparison minijss/jloadxm.c @ 2509:0c0576544d41

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 29 Apr 2020 01:31:20 +0300
parents f5bdd6ed298e
children 9807ae37ad69
comparison
equal deleted inserted replaced
2508:f5bdd6ed298e 2509:0c0576544d41
114 } while (0) 114 } while (0)
115 115
116 116
117 /* Convert XM note value to internal JSS note 117 /* Convert XM note value to internal JSS note
118 */ 118 */
119 static int jssXMConvertNote(int val) 119 static int jssXMConvertNote(const int val)
120 { 120 {
121 if (val < 1 || val > 97) 121 if (val < 1 || val > 97)
122 return jsetNotSet; 122 return jsetNotSet;
123 else 123 else
124 if (val == 97) 124 if (val == 97)
130 130
131 /* Unpack a XM pattern structure from resource to given JSS pattern 131 /* Unpack a XM pattern structure from resource to given JSS pattern
132 */ 132 */
133 static int jssXMUnpackPattern104(DMResource *inFile, int size, JSSPattern *pattern) 133 static int jssXMUnpackPattern104(DMResource *inFile, int size, JSSPattern *pattern)
134 { 134 {
135 JSSNote *pnote; 135 JSSNote *pnote = pattern->data;
136 int row, channel; 136
137 assert(pattern != NULL); 137 for (int row = 0; row < pattern->nrows && size > 0; row++)
138 138 for (int channel = 0; channel < pattern->nchannels && size > 0; channel++)
139 pnote = pattern->data;
140
141 for (row = 0; row < pattern->nrows && size > 0; row++)
142 for (channel = 0; channel < pattern->nchannels && size > 0; channel++)
143 { 139 {
144 int packb, tmp; 140 int packb, tmp;
145 JSGETBYTE(packb); 141 JSGETBYTE(packb);
146 if (packb & 0x80) 142 if (packb & 0x80)
147 { 143 {
218 } 214 }
219 215
220 216
221 static int jssXMUnpackPattern102(DMResource *inFile, int size, JSSPattern *pattern) 217 static int jssXMUnpackPattern102(DMResource *inFile, int size, JSSPattern *pattern)
222 { 218 {
223 JSSNote *pnote; 219 JSSNote *pnote = pattern->data;
224 int row, channel; 220
225 assert(pattern != NULL); 221 for (int row = 0; row < pattern->nrows && size > 0; row++)
226 222 for (int channel = 0; channel < pattern->nchannels && size > 0; channel++)
227 pnote = pattern->data;
228
229 for (row = 0; row < pattern->nrows && size > 0; row++)
230 for (channel = 0; channel < pattern->nchannels && size > 0; channel++)
231 { 223 {
232 int packb, tmp; 224 int packb, tmp;
233 JSGETBYTE(packb); 225 JSGETBYTE(packb);
234 if (packb & 0x80) 226 if (packb & 0x80)
235 { 227 {
312 } 304 }
313 305
314 306
315 static int jssXMLoadPatterns(DMResource *inFile, JSSModule *module, XMHeader *xmH) 307 static int jssXMLoadPatterns(DMResource *inFile, JSSModule *module, XMHeader *xmH)
316 { 308 {
317 int index, ret; 309 for (int index = 0; index < module->npatterns; index++)
318 XMPattern xmP; 310 {
319 311 XMPattern xmP;
320 for (index = 0; index < module->npatterns; index++)
321 {
322 off_t remainder, pos = dmftell(inFile); 312 off_t remainder, pos = dmftell(inFile);
323 Uint32 headSize = 0; 313 Uint32 headSize = 0;
314 BOOL ret = FALSE;
315 int res;
324 316
325 // Get the pattern header size and packing 317 // Get the pattern header size and packing
326 if (!dmf_read_le32(inFile, &xmP.headSize) || 318 if (!dmf_read_le32(inFile, &xmP.headSize) ||
327 !dmf_read_byte(inFile, &xmP.packing)) 319 !dmf_read_byte(inFile, &xmP.packing))
328 { 320 {
388 "Could not allocate memory for pattern #%d\n", index); 380 "Could not allocate memory for pattern #%d\n", index);
389 381
390 switch (module->intVersion) 382 switch (module->intVersion)
391 { 383 {
392 case 0x0104: 384 case 0x0104:
393 ret = jssXMUnpackPattern104(inFile, xmP.size, module->patterns[index]); 385 res = jssXMUnpackPattern104(inFile, xmP.size, module->patterns[index]);
394 break; 386 break;
395 case 0x0102: 387 case 0x0102:
396 ret = jssXMUnpackPattern102(inFile, xmP.size, module->patterns[index]); 388 res = jssXMUnpackPattern102(inFile, xmP.size, module->patterns[index]);
397 break; 389 break;
398 } 390 }
399 391
400 if (ret != 0) 392 if (res != DMERR_OK)
401 JSSERROR(ret, ret, "Error in unpacking pattern #%d data\n", index); 393 JSSERROR(res, res, "Error in unpacking pattern #%d data\n", index);
402 } 394 }
403 395
404 // Skip extra data if there is any .. shouldn't usually happen tho. 396 // Skip extra data if there is any .. shouldn't usually happen tho.
405 remainder = xmP.headSize - (dmftell(inFile) - pos); 397 remainder = xmP.headSize - (dmftell(inFile) - pos);
406 if (remainder > 0) 398 if (remainder > 0)
414 module->patterns[jsetMaxPatterns] = jssAllocatePattern(64, module->nchannels); 406 module->patterns[jsetMaxPatterns] = jssAllocatePattern(64, module->nchannels);
415 407
416 /* Convert song orders list by replacing nonexisting 408 /* Convert song orders list by replacing nonexisting
417 * pattern numbers with pattern number jsetMaxPatterns. 409 * pattern numbers with pattern number jsetMaxPatterns.
418 */ 410 */
419 for (index = 0; index < module->norders; index++) 411 for (int index = 0; index < module->norders; index++)
420 { 412 {
421 int tmp = xmH->orderList[index]; 413 int tmp = xmH->orderList[index];
422 if (tmp >= module->npatterns || 414 if (tmp >= module->npatterns ||
423 module->patterns[tmp] == NULL) 415 module->patterns[tmp] == NULL)
424 tmp = jsetMaxPatterns; 416 tmp = jsetMaxPatterns;
434 */ 426 */
435 static int jssXMConvertEnvelope( 427 static int jssXMConvertEnvelope(
436 JSSEnvelope *dst, XMEnvelope *src, 428 JSSEnvelope *dst, XMEnvelope *src,
437 const char *name, const int ninstr) 429 const char *name, const int ninstr)
438 { 430 {
439 int i;
440 (void) name; 431 (void) name;
441 (void) ninstr; 432 (void) ninstr;
442 433
443 // Convert envelope points 434 // Convert envelope points
444 for (i = 0; i < XM_MaxEnvPoints; i++) 435 for (int i = 0; i < XM_MaxEnvPoints; i++)
445 { 436 {
446 dst->points[i].frame = src->points[i].frame; 437 dst->points[i].frame = src->points[i].frame;
447 dst->points[i].value = src->points[i].value; 438 dst->points[i].value = src->points[i].value;
448 } 439 }
449 440
668 "Could not allocate %d bytes of sample data for instrument/sample #%d/%d.\n", 659 "Could not allocate %d bytes of sample data for instrument/sample #%d/%d.\n",
669 bsize, ninst, nsample); 660 bsize, ninst, nsample);
670 } 661 }
671 662
672 // Read sampledata 663 // Read sampledata
673 if (dmfread(inst->data, sizeof(Uint8), bsize, inFile) != bsize) 664 if (!dmf_read_str(inFile, inst->data, bsize))
674 { 665 {
675 JSSERROR(DMERR_FREAD, DMERR_FREAD, 666 JSSERROR(DMERR_FREAD, DMERR_FREAD,
676 "Error reading sample data for instrument #%d/%d, %d bytes.\n", 667 "Error reading sample data for instrument #%d/%d, %d bytes.\n",
677 ninst, nsample, bsize); 668 ninst, nsample, bsize);
678 } 669 }