Mercurial > hg > dmlib
comparison minijss/jloadxm.c @ 1217:96ad216e9b59
Improve some comments.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 05 Mar 2015 23:28:58 +0200 |
parents | 76c5bde4b943 |
children | e8f0305f8e6b |
comparison
equal
deleted
inserted
replaced
1216:f57dc769bd39 | 1217:96ad216e9b59 |
---|---|
317 int index, ret; | 317 int index, ret; |
318 XMPattern xmP; | 318 XMPattern xmP; |
319 | 319 |
320 for (index = 0; index < module->npatterns; index++) | 320 for (index = 0; index < module->npatterns; index++) |
321 { | 321 { |
322 // Get the pattern header | |
323 off_t remainder, pos = dmftell(inFile); | 322 off_t remainder, pos = dmftell(inFile); |
324 Uint32 headSize; | 323 Uint32 headSize; |
325 | 324 |
326 // Get the pattern header size | 325 // Get the pattern header size and packing |
327 if (!dmf_read_le32(inFile, &xmP.headSize) || | 326 if (!dmf_read_le32(inFile, &xmP.headSize) || |
328 !dmf_read_byte(inFile, &xmP.packing)) | 327 !dmf_read_byte(inFile, &xmP.packing)) |
329 JSSERROR(DMERR_FREAD, DMERR_FREAD, | 328 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
330 "Could not read pattern header #%d.\n", | 329 "Could not read pattern header #%d.\n", |
331 index); | 330 index); |
332 | 331 |
333 // Different format versions have slightly different headers | 332 // Different format versions have slightly different headers |
334 if (module->intVersion == 0x0102) | 333 if (module->intVersion == 0x0102) |
335 { | 334 { |
336 Uint8 tmp; | 335 Uint8 tmp; |
336 // 0x0102 has one byte number of rows | |
337 ret = dmf_read_byte(inFile, &tmp); | 337 ret = dmf_read_byte(inFile, &tmp); |
338 xmP.nrows = ((Uint16) tmp) + 1; | 338 xmP.nrows = ((Uint16) tmp) + 1; |
339 headSize = 4 + 1 + 1 + 2; | 339 headSize = 4 + 1 + 1 + 2; |
340 } | 340 } |
341 else | 341 else |
342 { | 342 { |
343 // 0x0104 has 16-bit word for nrows | |
343 ret = dmf_read_le16(inFile, &xmP.nrows); | 344 ret = dmf_read_le16(inFile, &xmP.nrows); |
344 headSize = 4 + 1 + 2 + 2; | 345 headSize = 4 + 1 + 2 + 2; |
345 } | 346 } |
346 | 347 |
348 // Check header size against known values | |
347 if (headSize != xmP.headSize) | 349 if (headSize != xmP.headSize) |
348 { | 350 { |
349 JSSERROR(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED, | 351 JSSERROR(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED, |
350 "Invalid pattern #%d header size %d, expected %d bytes.\n", | 352 "Invalid pattern #%d header size %d, expected %d bytes.\n", |
351 index, xmP.headSize, headSize); | 353 index, xmP.headSize, headSize); |
352 } | 354 } |
353 | 355 |
356 // Read rest of the header | |
354 if (!ret || !dmf_read_le16(inFile, &xmP.size)) | 357 if (!ret || !dmf_read_le16(inFile, &xmP.size)) |
355 { | 358 { |
356 JSSERROR(DMERR_FREAD, DMERR_FREAD, | 359 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
357 "Could not read pattern header data #%d.\n", | 360 "Could not read pattern header data #%d.\n", |
358 index); | 361 index); |
359 } | 362 } |
360 | 363 |
361 // Check rest of the header data | 364 // Sanity-check rest of the header data |
362 if (xmP.packing != 0) | 365 if (xmP.packing != 0) |
363 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | 366 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
364 "Pattern #%d packing type unsupported (%d)\n", | 367 "Pattern #%d packing type unsupported (%d)\n", |
365 index, xmP.packing); | 368 index, xmP.packing); |
366 | 369 |
389 | 392 |
390 if (ret != 0) | 393 if (ret != 0) |
391 JSSERROR(ret, ret, "Error in unpacking pattern #%d data\n", index); | 394 JSSERROR(ret, ret, "Error in unpacking pattern #%d data\n", index); |
392 } | 395 } |
393 | 396 |
394 // Skip extra data (if the file is damaged) | 397 // Skip extra data if there is any .. shouldn't usually happen tho. |
395 remainder = xmP.headSize - (dmftell(inFile) - pos); | 398 remainder = xmP.headSize - (dmftell(inFile) - pos); |
396 if (remainder > 0) | 399 if (remainder > 0) |
397 { | 400 { |
398 JSSDEBUG("xmP Skipping: %li\n", remainder); | 401 JSSDEBUG("xmP Skipping: %li\n", remainder); |
399 dmfseek(inFile, remainder, SEEK_CUR); | 402 dmfseek(inFile, remainder, SEEK_CUR); |
401 } | 404 } |
402 | 405 |
403 // Allocate the empty pattern | 406 // Allocate the empty pattern |
404 module->patterns[jsetMaxPatterns] = jssAllocatePattern(64, module->nchannels); | 407 module->patterns[jsetMaxPatterns] = jssAllocatePattern(64, module->nchannels); |
405 | 408 |
406 /* Convert song orders list by replacing nonexisting patterns | 409 /* Convert song orders list by replacing nonexisting |
407 * with pattern number jsetMaxPatterns. | 410 * pattern numbers with pattern number jsetMaxPatterns. |
408 */ | 411 */ |
409 for (index = 0; index < module->norders; index++) | 412 for (index = 0; index < module->norders; index++) |
410 { | 413 { |
411 int tmp = xmH->orderList[index]; | 414 int tmp = xmH->orderList[index]; |
412 if (tmp >= module->npatterns || | 415 if (tmp >= module->npatterns || |