diff options
-rw-r--r-- | apps/codecs/mod.c | 42 |
1 files changed, 15 insertions, 27 deletions
diff --git a/apps/codecs/mod.c b/apps/codecs/mod.c index 0d3eadf773..7bc87c8a42 100644 --- a/apps/codecs/mod.c +++ b/apps/codecs/mod.c | |||
@@ -374,7 +374,7 @@ STATICIRAM bool loadmod(void *modfile) ICODE_ATTR; | |||
374 | bool loadmod(void *modfile) | 374 | bool loadmod(void *modfile) |
375 | { | 375 | { |
376 | int i; | 376 | int i; |
377 | bool periodsconverted = false; | 377 | unsigned char *periodsconverted; |
378 | 378 | ||
379 | /* We don't support PowerPacker 2.0 Files */ | 379 | /* We don't support PowerPacker 2.0 Files */ |
380 | if (memcmp((char*) modfile, "PP20", 4) == 0) return false; | 380 | if (memcmp((char*) modfile, "PP20", 4) == 0) return false; |
@@ -401,26 +401,10 @@ bool loadmod(void *modfile) | |||
401 | {modsong.noofchannels = 8; modsong.noofinstruments = 31;} | 401 | {modsong.noofchannels = 8; modsong.noofinstruments = 31;} |
402 | else if (memcmp(fileformattag, "CD81", 4) == 0) | 402 | else if (memcmp(fileformattag, "CD81", 4) == 0) |
403 | {modsong.noofchannels = 8; modsong.noofinstruments = 31;} | 403 | {modsong.noofchannels = 8; modsong.noofinstruments = 31;} |
404 | else if (memcmp(fileformattag, "RS", 2) == 0) | ||
405 | { | ||
406 | /* This is a special internal in-memory fileformat | ||
407 | * where the periods have been already converted to offsets | ||
408 | * in our periodtable. | ||
409 | * It comes to use when rockbox reloads an already played | ||
410 | * module (e.g. on rewinding) */ | ||
411 | modsong.noofchannels = fileformattag[2]; | ||
412 | modsong.noofinstruments = fileformattag[3]; | ||
413 | periodsconverted = true; | ||
414 | } | ||
415 | else { | 404 | else { |
416 | /* The file has no format tag, so we take a guess */ | 405 | /* The file has no format tag, so most likely soundtracker */ |
417 | modsong.noofchannels = 4; | 406 | modsong.noofchannels = 4; |
418 | 407 | modsong.noofinstruments = 15; | |
419 | /* For the no of instruments we check if there is a sample #16 and | ||
420 | * if it has a (ascii) name */ | ||
421 | char *p = (char *)modfile + 470; | ||
422 | if ((*p >= 32) && (*p <= 126)) modsong.noofinstruments = 31; | ||
423 | else modsong.noofinstruments = 15; | ||
424 | } | 408 | } |
425 | 409 | ||
426 | /* Get the Song title | 410 | /* Get the Song title |
@@ -458,14 +442,19 @@ bool loadmod(void *modfile) | |||
458 | maxpatterns = modsong.patternordertable[i]; | 442 | maxpatterns = modsong.patternordertable[i]; |
459 | maxpatterns++; | 443 | maxpatterns++; |
460 | 444 | ||
461 | /* Get the pattern data */ | 445 | /* use 'restartposition' (historically set to 127) which is not used here |
462 | modsong.patterndata = (char*)modfile + 20 + | 446 | as a marker that periods have already been converted */ |
463 | modsong.noofinstruments*30 + 134; | 447 | |
448 | periodsconverted = (char*)modfile + 20 + modsong.noofinstruments*30 + 1; | ||
464 | 449 | ||
450 | /* Get the pattern data; ST doesn't have fileformattag, so 4 bytes less */ | ||
451 | modsong.patterndata = periodsconverted + | ||
452 | (modsong.noofinstruments==15 ? 129 : 133); | ||
453 | |||
465 | /* Convert the period values in the mod file to offsets | 454 | /* Convert the period values in the mod file to offsets |
466 | * in our periodtable (but only, if we haven't done this yet) */ | 455 | * in our periodtable (but only, if we haven't done this yet) */ |
467 | p = (unsigned char *) modsong.patterndata; | 456 | p = (unsigned char *) modsong.patterndata; |
468 | if (!periodsconverted) | 457 | if (*periodsconverted != 0xfe) |
469 | { | 458 | { |
470 | int note, note2, channel; | 459 | int note, note2, channel; |
471 | for (note=0;note<maxpatterns*64;note++) | 460 | for (note=0;note<maxpatterns*64;note++) |
@@ -487,10 +476,9 @@ bool loadmod(void *modfile) | |||
487 | p += 4; | 476 | p += 4; |
488 | } | 477 | } |
489 | /* Remember that we already converted the periods, | 478 | /* Remember that we already converted the periods, |
490 | * in case the file gets reloaded by rewinding */ | 479 | * in case the file gets reloaded by rewinding |
491 | fileformattag[0] = 'R'; fileformattag[1] = 'S'; | 480 | * with 0xfe (arbitary magic value > 127) */ |
492 | fileformattag[2] = modsong.noofchannels; | 481 | *periodsconverted = 0xfe; |
493 | fileformattag[3] = modsong.noofinstruments; | ||
494 | } | 482 | } |
495 | 483 | ||
496 | /* Get the samples | 484 | /* Get the samples |