diff options
Diffstat (limited to 'apps/plugins/mikmod/load_uni.c')
-rw-r--r-- | apps/plugins/mikmod/load_uni.c | 163 |
1 files changed, 84 insertions, 79 deletions
diff --git a/apps/plugins/mikmod/load_uni.c b/apps/plugins/mikmod/load_uni.c index 7bedd8f16c..834fd3a85a 100644 --- a/apps/plugins/mikmod/load_uni.c +++ b/apps/plugins/mikmod/load_uni.c | |||
@@ -6,12 +6,12 @@ | |||
6 | it under the terms of the GNU Library General Public License as | 6 | it under the terms of the GNU Library General Public License as |
7 | published by the Free Software Foundation; either version 2 of | 7 | published by the Free Software Foundation; either version 2 of |
8 | the License, or (at your option) any later version. | 8 | the License, or (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU Library General Public License for more details. | 13 | GNU Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public | 15 | You should have received a copy of the GNU Library General Public |
16 | License along with this library; if not, write to the Free Software | 16 | License along with this library; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
@@ -20,7 +20,7 @@ | |||
20 | 20 | ||
21 | /*============================================================================== | 21 | /*============================================================================== |
22 | 22 | ||
23 | $Id: load_uni.c,v 1.3 2005/04/07 19:57:38 realtech Exp $ | 23 | $Id$ |
24 | 24 | ||
25 | UNIMOD (libmikmod's and APlayer's internal module format) loader | 25 | UNIMOD (libmikmod's and APlayer's internal module format) loader |
26 | 26 | ||
@@ -94,18 +94,18 @@ static UNISMP05 *wh=NULL,*s=NULL; | |||
94 | 94 | ||
95 | /*========== Loader code */ | 95 | /*========== Loader code */ |
96 | 96 | ||
97 | static char* readstring(void) | 97 | static char * readstring(void) |
98 | { | 98 | { |
99 | char *s=NULL; | 99 | char *str=NULL; |
100 | UWORD len; | 100 | UWORD len; |
101 | 101 | ||
102 | len=_mm_read_I_UWORD(modreader); | 102 | len=_mm_read_I_UWORD(modreader); |
103 | if(len) { | 103 | if(len) { |
104 | s=MikMod_malloc(len+1); | 104 | str=(char *) MikMod_malloc(len+1); |
105 | _mm_read_UBYTES(s,len,modreader); | 105 | _mm_read_UBYTES(str,len,modreader); |
106 | s[len]=0; | 106 | str[len]=0; |
107 | } | 107 | } |
108 | return s; | 108 | return str; |
109 | } | 109 | } |
110 | 110 | ||
111 | static int UNI_Test(void) | 111 | static int UNI_Test(void) |
@@ -133,7 +133,7 @@ static int UNI_Init(void) | |||
133 | static void UNI_Cleanup(void) | 133 | static void UNI_Cleanup(void) |
134 | { | 134 | { |
135 | MikMod_free(wh); | 135 | MikMod_free(wh); |
136 | s=NULL; | 136 | wh = s = NULL; |
137 | } | 137 | } |
138 | 138 | ||
139 | static UBYTE* readtrack(void) | 139 | static UBYTE* readtrack(void) |
@@ -148,7 +148,7 @@ static UBYTE* readtrack(void) | |||
148 | len=_mm_read_I_UWORD(modreader); | 148 | len=_mm_read_I_UWORD(modreader); |
149 | 149 | ||
150 | if(!len) return NULL; | 150 | if(!len) return NULL; |
151 | if(!(t=MikMod_malloc(len))) return NULL; | 151 | if(!(t=(UBYTE*)MikMod_malloc(len))) return NULL; |
152 | _mm_read_UBYTES(t,len,modreader); | 152 | _mm_read_UBYTES(t,len,modreader); |
153 | 153 | ||
154 | /* Check if the track is correct */ | 154 | /* Check if the track is correct */ |
@@ -221,65 +221,65 @@ static UBYTE* readtrack(void) | |||
221 | static int loadsmp6(void) | 221 | static int loadsmp6(void) |
222 | { | 222 | { |
223 | int t; | 223 | int t; |
224 | SAMPLE *s; | 224 | SAMPLE *sptr; |
225 | 225 | ||
226 | s=of.samples; | 226 | sptr=of.samples; |
227 | for(t=0;t<of.numsmp;t++,s++) { | 227 | for(t=0;t<of.numsmp;t++,sptr++) { |
228 | int flags; | 228 | int flags; |
229 | 229 | ||
230 | flags = _mm_read_M_UWORD(modreader); | 230 | flags = _mm_read_M_UWORD(modreader); |
231 | s->flags=0; | 231 | sptr->flags=0; |
232 | if(flags&0x0004) s->flags|=SF_STEREO; | 232 | if(flags&0x0004) sptr->flags|=SF_STEREO; |
233 | if(flags&0x0002) s->flags|=SF_SIGNED; | 233 | if(flags&0x0002) sptr->flags|=SF_SIGNED; |
234 | if(flags&0x0001) s->flags|=SF_16BITS; | 234 | if(flags&0x0001) sptr->flags|=SF_16BITS; |
235 | /* convert flags */ | 235 | /* convert flags */ |
236 | if(universion>=0x104) { | 236 | if(universion>=0x104) { |
237 | if(flags&0x2000) s->flags|=SF_UST_LOOP; | 237 | if(flags&0x2000) sptr->flags|=SF_UST_LOOP; |
238 | if(flags&0x1000) s->flags|=SF_OWNPAN; | 238 | if(flags&0x1000) sptr->flags|=SF_OWNPAN; |
239 | if(flags&0x0800) s->flags|=SF_SUSTAIN; | 239 | if(flags&0x0800) sptr->flags|=SF_SUSTAIN; |
240 | if(flags&0x0400) s->flags|=SF_REVERSE; | 240 | if(flags&0x0400) sptr->flags|=SF_REVERSE; |
241 | if(flags&0x0200) s->flags|=SF_BIDI; | 241 | if(flags&0x0200) sptr->flags|=SF_BIDI; |
242 | if(flags&0x0100) s->flags|=SF_LOOP; | 242 | if(flags&0x0100) sptr->flags|=SF_LOOP; |
243 | if(flags&0x0020) s->flags|=SF_ITPACKED; | 243 | if(flags&0x0020) sptr->flags|=SF_ITPACKED; |
244 | if(flags&0x0010) s->flags|=SF_DELTA; | 244 | if(flags&0x0010) sptr->flags|=SF_DELTA; |
245 | if(flags&0x0008) s->flags|=SF_BIG_ENDIAN; | 245 | if(flags&0x0008) sptr->flags|=SF_BIG_ENDIAN; |
246 | } else if(universion>=0x102) { | 246 | } else if(universion>=0x102) { |
247 | if(flags&0x0800) s->flags|=SF_UST_LOOP; | 247 | if(flags&0x0800) sptr->flags|=SF_UST_LOOP; |
248 | if(flags&0x0400) s->flags|=SF_OWNPAN; | 248 | if(flags&0x0400) sptr->flags|=SF_OWNPAN; |
249 | if(flags&0x0200) s->flags|=SF_SUSTAIN; | 249 | if(flags&0x0200) sptr->flags|=SF_SUSTAIN; |
250 | if(flags&0x0100) s->flags|=SF_REVERSE; | 250 | if(flags&0x0100) sptr->flags|=SF_REVERSE; |
251 | if(flags&0x0080) s->flags|=SF_BIDI; | 251 | if(flags&0x0080) sptr->flags|=SF_BIDI; |
252 | if(flags&0x0040) s->flags|=SF_LOOP; | 252 | if(flags&0x0040) sptr->flags|=SF_LOOP; |
253 | if(flags&0x0020) s->flags|=SF_ITPACKED; | 253 | if(flags&0x0020) sptr->flags|=SF_ITPACKED; |
254 | if(flags&0x0010) s->flags|=SF_DELTA; | 254 | if(flags&0x0010) sptr->flags|=SF_DELTA; |
255 | if(flags&0x0008) s->flags|=SF_BIG_ENDIAN; | 255 | if(flags&0x0008) sptr->flags|=SF_BIG_ENDIAN; |
256 | } else { | 256 | } else { |
257 | if(flags&0x400) s->flags|=SF_UST_LOOP; | 257 | if(flags&0x400) sptr->flags|=SF_UST_LOOP; |
258 | if(flags&0x200) s->flags|=SF_OWNPAN; | 258 | if(flags&0x200) sptr->flags|=SF_OWNPAN; |
259 | if(flags&0x100) s->flags|=SF_REVERSE; | 259 | if(flags&0x100) sptr->flags|=SF_REVERSE; |
260 | if(flags&0x080) s->flags|=SF_SUSTAIN; | 260 | if(flags&0x080) sptr->flags|=SF_SUSTAIN; |
261 | if(flags&0x040) s->flags|=SF_BIDI; | 261 | if(flags&0x040) sptr->flags|=SF_BIDI; |
262 | if(flags&0x020) s->flags|=SF_LOOP; | 262 | if(flags&0x020) sptr->flags|=SF_LOOP; |
263 | if(flags&0x010) s->flags|=SF_BIG_ENDIAN; | 263 | if(flags&0x010) sptr->flags|=SF_BIG_ENDIAN; |
264 | if(flags&0x008) s->flags|=SF_DELTA; | 264 | if(flags&0x008) sptr->flags|=SF_DELTA; |
265 | } | 265 | } |
266 | 266 | ||
267 | s->speed = _mm_read_M_ULONG(modreader); | 267 | sptr->speed = _mm_read_M_ULONG(modreader); |
268 | s->volume = _mm_read_UBYTE(modreader); | 268 | sptr->volume = _mm_read_UBYTE(modreader); |
269 | s->panning = _mm_read_M_UWORD(modreader); | 269 | sptr->panning = _mm_read_M_UWORD(modreader); |
270 | s->length = _mm_read_M_ULONG(modreader); | 270 | sptr->length = _mm_read_M_ULONG(modreader); |
271 | s->loopstart = _mm_read_M_ULONG(modreader); | 271 | sptr->loopstart = _mm_read_M_ULONG(modreader); |
272 | s->loopend = _mm_read_M_ULONG(modreader); | 272 | sptr->loopend = _mm_read_M_ULONG(modreader); |
273 | s->susbegin = _mm_read_M_ULONG(modreader); | 273 | sptr->susbegin = _mm_read_M_ULONG(modreader); |
274 | s->susend = _mm_read_M_ULONG(modreader); | 274 | sptr->susend = _mm_read_M_ULONG(modreader); |
275 | s->globvol = _mm_read_UBYTE(modreader); | 275 | sptr->globvol = _mm_read_UBYTE(modreader); |
276 | s->vibflags = _mm_read_UBYTE(modreader); | 276 | sptr->vibflags = _mm_read_UBYTE(modreader); |
277 | s->vibtype = _mm_read_UBYTE(modreader); | 277 | sptr->vibtype = _mm_read_UBYTE(modreader); |
278 | s->vibsweep = _mm_read_UBYTE(modreader); | 278 | sptr->vibsweep = _mm_read_UBYTE(modreader); |
279 | s->vibdepth = _mm_read_UBYTE(modreader); | 279 | sptr->vibdepth = _mm_read_UBYTE(modreader); |
280 | s->vibrate = _mm_read_UBYTE(modreader); | 280 | sptr->vibrate = _mm_read_UBYTE(modreader); |
281 | 281 | ||
282 | s->samplename=readstring(); | 282 | sptr->samplename=readstring(); |
283 | 283 | ||
284 | if(_mm_eof(modreader)) { | 284 | if(_mm_eof(modreader)) { |
285 | _mm_errno = MMERR_LOADING_SAMPLEINFO; | 285 | _mm_errno = MMERR_LOADING_SAMPLEINFO; |
@@ -308,7 +308,7 @@ static int loadinstr6(void) | |||
308 | i->rpanvar = _mm_read_UBYTE(modreader); | 308 | i->rpanvar = _mm_read_UBYTE(modreader); |
309 | i->volfade = _mm_read_M_UWORD(modreader); | 309 | i->volfade = _mm_read_M_UWORD(modreader); |
310 | 310 | ||
311 | #if defined __STDC__ || defined _MSC_VER || defined MPW_C | 311 | #if defined __STDC__ || defined _MSC_VER || defined __WATCOMC__ || defined MPW_C |
312 | #define UNI_LoadEnvelope6(name) \ | 312 | #define UNI_LoadEnvelope6(name) \ |
313 | i-> name##flg=_mm_read_UBYTE(modreader); \ | 313 | i-> name##flg=_mm_read_UBYTE(modreader); \ |
314 | i-> name##pts=_mm_read_UBYTE(modreader); \ | 314 | i-> name##pts=_mm_read_UBYTE(modreader); \ |
@@ -373,7 +373,7 @@ static int loadinstr5(void) | |||
373 | for(u=0;u<96;u++) | 373 | for(u=0;u<96;u++) |
374 | i->samplenumber[u]=of.numsmp+_mm_read_UBYTE(modreader); | 374 | i->samplenumber[u]=of.numsmp+_mm_read_UBYTE(modreader); |
375 | 375 | ||
376 | #if defined __STDC__ || defined _MSC_VER || defined MPW_C | 376 | #if defined __STDC__ || defined _MSC_VER || defined __WATCOMC__ || defined MPW_C |
377 | #define UNI_LoadEnvelope5(name) \ | 377 | #define UNI_LoadEnvelope5(name) \ |
378 | i-> name##flg=_mm_read_UBYTE(modreader); \ | 378 | i-> name##flg=_mm_read_UBYTE(modreader); \ |
379 | i-> name##pts=_mm_read_UBYTE(modreader); \ | 379 | i-> name##pts=_mm_read_UBYTE(modreader); \ |
@@ -415,7 +415,7 @@ static int loadinstr5(void) | |||
415 | /* Allocate more room for sample information if necessary */ | 415 | /* Allocate more room for sample information if necessary */ |
416 | if(of.numsmp+u==wavcnt) { | 416 | if(of.numsmp+u==wavcnt) { |
417 | wavcnt+=UNI_SMPINCR; | 417 | wavcnt+=UNI_SMPINCR; |
418 | if(!(wh=MikMod_realloc(wh,wavcnt*sizeof(UNISMP05)))) { | 418 | if(!(wh=(UNISMP05*)MikMod_realloc(wh,wavcnt*sizeof(UNISMP05)))) { |
419 | _mm_errno=MMERR_OUT_OF_MEMORY; | 419 | _mm_errno=MMERR_OUT_OF_MEMORY; |
420 | return 0; | 420 | return 0; |
421 | } | 421 | } |
@@ -447,7 +447,7 @@ static int loadinstr5(void) | |||
447 | 447 | ||
448 | /* sanity check */ | 448 | /* sanity check */ |
449 | if(!of.numsmp) { | 449 | if(!of.numsmp) { |
450 | if(wh) { MikMod_free(wh);wh=NULL; } | 450 | MikMod_free(wh);wh=NULL; |
451 | _mm_errno=MMERR_LOADING_SAMPLEINFO; | 451 | _mm_errno=MMERR_LOADING_SAMPLEINFO; |
452 | return 0; | 452 | return 0; |
453 | } | 453 | } |
@@ -504,8 +504,8 @@ static int UNI_Load(int curious) | |||
504 | char *modtype,*oldtype=NULL; | 504 | char *modtype,*oldtype=NULL; |
505 | INSTRUMENT *d; | 505 | INSTRUMENT *d; |
506 | SAMPLE *q; | 506 | SAMPLE *q; |
507 | (void)curious; | 507 | (void)curious; |
508 | 508 | ||
509 | /* read module header */ | 509 | /* read module header */ |
510 | _mm_read_UBYTES(mh.id,4,modreader); | 510 | _mm_read_UBYTES(mh.id,4,modreader); |
511 | if(mh.id[3]!='N') | 511 | if(mh.id[3]!='N') |
@@ -514,11 +514,11 @@ static int UNI_Load(int curious) | |||
514 | universion=0x100; | 514 | universion=0x100; |
515 | 515 | ||
516 | if(universion>=6) { | 516 | if(universion>=6) { |
517 | if (universion==6) | 517 | if (universion==6) { |
518 | (void)_mm_read_UBYTE(modreader); | 518 | _mm_skip_BYTE(modreader); |
519 | else | 519 | } else { |
520 | universion=_mm_read_M_UWORD(modreader); | 520 | universion=_mm_read_M_UWORD(modreader); |
521 | 521 | } | |
522 | mh.flags =_mm_read_M_UWORD(modreader); | 522 | mh.flags =_mm_read_M_UWORD(modreader); |
523 | mh.numchn =_mm_read_UBYTE(modreader); | 523 | mh.numchn =_mm_read_UBYTE(modreader); |
524 | mh.numvoices =_mm_read_UBYTE(modreader); | 524 | mh.numvoices =_mm_read_UBYTE(modreader); |
@@ -556,7 +556,7 @@ static int UNI_Load(int curious) | |||
556 | mh.flags &= UF_XMPERIODS | UF_LINEAR; | 556 | mh.flags &= UF_XMPERIODS | UF_LINEAR; |
557 | mh.flags |= UF_INST | UF_NOWRAP | UF_PANNING; | 557 | mh.flags |= UF_INST | UF_NOWRAP | UF_PANNING; |
558 | } | 558 | } |
559 | 559 | ||
560 | /* set module parameters */ | 560 | /* set module parameters */ |
561 | of.flags =mh.flags; | 561 | of.flags =mh.flags; |
562 | of.numchn =mh.numchn; | 562 | of.numchn =mh.numchn; |
@@ -578,21 +578,21 @@ static int UNI_Load(int curious) | |||
578 | oldtype=readstring(); | 578 | oldtype=readstring(); |
579 | if(oldtype) { | 579 | if(oldtype) { |
580 | size_t len=strlen(oldtype)+20; | 580 | size_t len=strlen(oldtype)+20; |
581 | if(!(modtype=MikMod_malloc(len))) return 0; | 581 | if(!(modtype=(char*)MikMod_malloc(len))) return 0; |
582 | #ifdef HAVE_SNPRINTF | 582 | #ifdef HAVE_SNPRINTF |
583 | snprintf(modtype,len,"%s (was %s)",(universion>=0x100)?"APlayer":"MikCvt2",oldtype); | 583 | snprintf(modtype,len,"%s (was %s)",(universion>=0x100)?"APlayer":"MikCvt2",oldtype); |
584 | #else | 584 | #else |
585 | sprintf(modtype,"%s (was %s)",(universion>=0x100)?"APlayer":"MikCvt2",oldtype); | 585 | sprintf(modtype,"%s (was %s)",(universion>=0x100)?"APlayer":"MikCvt2",oldtype); |
586 | #endif | 586 | #endif |
587 | } else { | 587 | } else { |
588 | if(!(modtype=MikMod_malloc(10))) return 0; | 588 | if(!(modtype=(char*)MikMod_malloc(10))) return 0; |
589 | #ifdef HAVE_SNPRINTF | 589 | #ifdef HAVE_SNPRINTF |
590 | snprintf(modtype,10,"%s",(universion>=0x100)?"APlayer":"MikCvt3"); | 590 | snprintf(modtype,10,"%s",(universion>=0x100)?"APlayer":"MikCvt3"); |
591 | #else | 591 | #else |
592 | sprintf(modtype,"%s",(universion>=0x100)?"APlayer":"MikCvt3"); | 592 | sprintf(modtype,"%s",(universion>=0x100)?"APlayer":"MikCvt3"); |
593 | #endif | 593 | #endif |
594 | } | 594 | } |
595 | of.modtype=StrDup(modtype); | 595 | of.modtype=MikMod_strdup(modtype); |
596 | MikMod_free(modtype);MikMod_free(oldtype); | 596 | MikMod_free(modtype);MikMod_free(oldtype); |
597 | of.comment=readstring(); | 597 | of.comment=readstring(); |
598 | 598 | ||
@@ -624,9 +624,14 @@ static int UNI_Load(int curious) | |||
624 | for(t=0;t<of.numchn;t++) of.panning[t]=mh.panning[t]; | 624 | for(t=0;t<of.numchn;t++) of.panning[t]=mh.panning[t]; |
625 | } | 625 | } |
626 | /* convert the ``end of song'' pattern code if necessary */ | 626 | /* convert the ``end of song'' pattern code if necessary */ |
627 | if(universion<0x106) | 627 | for(t=0;t<of.numpos;t++) { |
628 | for(t=0;t<of.numpos;t++) | 628 | if(universion<0x106 && of.positions[t]==255) of.positions[t]=LAST_PATTERN; |
629 | if(of.positions[t]==255) of.positions[t]=LAST_PATTERN; | 629 | else if (of.positions[t]>of.numpat) { /* SANITIY CHECK */ |
630 | /* fprintf(stderr,"position[%d]=%d > numpat=%d\n",t,of.positions[t],of.numpat);*/ | ||
631 | _mm_errno = MMERR_LOADING_HEADER; | ||
632 | return 0; | ||
633 | } | ||
634 | } | ||
630 | 635 | ||
631 | /* instruments and samples */ | 636 | /* instruments and samples */ |
632 | if(universion>=6) { | 637 | if(universion>=6) { |
@@ -642,7 +647,7 @@ static int UNI_Load(int curious) | |||
642 | if(!AllocInstruments()) return 0; | 647 | if(!AllocInstruments()) return 0; |
643 | if(!loadinstr5()) return 0; | 648 | if(!loadinstr5()) return 0; |
644 | if(!AllocSamples()) { | 649 | if(!AllocSamples()) { |
645 | if(wh) { MikMod_free(wh);wh=NULL; } | 650 | MikMod_free(wh);wh=NULL; |
646 | return 0; | 651 | return 0; |
647 | } | 652 | } |
648 | if(!loadsmp5()) return 0; | 653 | if(!loadsmp5()) return 0; |