diff options
Diffstat (limited to 'apps/plugins/mikmod/load_s3m.c')
-rw-r--r-- | apps/plugins/mikmod/load_s3m.c | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/apps/plugins/mikmod/load_s3m.c b/apps/plugins/mikmod/load_s3m.c index e162388f15..076159afc5 100644 --- a/apps/plugins/mikmod/load_s3m.c +++ b/apps/plugins/mikmod/load_s3m.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_s3m.c,v 1.3 2005/04/07 19:57:38 realtech Exp $ | 23 | $Id$ |
24 | 24 | ||
25 | Screamtracker (S3M) module loader | 25 | Screamtracker (S3M) module loader |
26 | 26 | ||
@@ -104,7 +104,7 @@ static unsigned int tracker; /* tracker id */ | |||
104 | 104 | ||
105 | /* tracker identifiers */ | 105 | /* tracker identifiers */ |
106 | #define NUMTRACKERS 4 | 106 | #define NUMTRACKERS 4 |
107 | static CHAR* S3M_Version[] = { | 107 | static const CHAR * S3M_Version[] = { |
108 | "Screamtracker x.xx", | 108 | "Screamtracker x.xx", |
109 | "Imago Orpheus x.xx (S3M format)", | 109 | "Imago Orpheus x.xx (S3M format)", |
110 | "Impulse Tracker x.xx (S3M format)", | 110 | "Impulse Tracker x.xx (S3M format)", |
@@ -113,7 +113,7 @@ static CHAR* S3M_Version[] = { | |||
113 | "Impulse Tracker 2.14p4 (S3M format)" | 113 | "Impulse Tracker 2.14p4 (S3M format)" |
114 | }; | 114 | }; |
115 | /* version number position in above array */ | 115 | /* version number position in above array */ |
116 | static int numeric[NUMTRACKERS]={14,14,16,16}; | 116 | static const int numeric[NUMTRACKERS]={14,14,16,16}; |
117 | 117 | ||
118 | /*========== Loader code */ | 118 | /*========== Loader code */ |
119 | 119 | ||
@@ -144,6 +144,11 @@ static void S3M_Cleanup(void) | |||
144 | MikMod_free(poslookup); | 144 | MikMod_free(poslookup); |
145 | MikMod_free(mh); | 145 | MikMod_free(mh); |
146 | MikMod_free(origpositions); | 146 | MikMod_free(origpositions); |
147 | s3mbuf=NULL; | ||
148 | paraptr=NULL; | ||
149 | poslookup=NULL; | ||
150 | mh=NULL; | ||
151 | origpositions=NULL; | ||
147 | } | 152 | } |
148 | 153 | ||
149 | /* Because so many s3m files have 16 channels as the set number used, but really | 154 | /* Because so many s3m files have 16 channels as the set number used, but really |
@@ -154,9 +159,9 @@ static void S3M_Cleanup(void) | |||
154 | global variable 'remap' | 159 | global variable 'remap' |
155 | 160 | ||
156 | NOTE: You must first seek to the file location of the pattern before calling | 161 | NOTE: You must first seek to the file location of the pattern before calling |
157 | this procedure. | 162 | this procedure. |
158 | 163 | ||
159 | Returns 1 on fail. */ | 164 | Returns 0 on fail. */ |
160 | static int S3M_GetNumChannels(void) | 165 | static int S3M_GetNumChannels(void) |
161 | { | 166 | { |
162 | int row=0,flag,ch; | 167 | int row=0,flag,ch; |
@@ -166,19 +171,19 @@ static int S3M_GetNumChannels(void) | |||
166 | 171 | ||
167 | if(_mm_eof(modreader)) { | 172 | if(_mm_eof(modreader)) { |
168 | _mm_errno = MMERR_LOADING_PATTERN; | 173 | _mm_errno = MMERR_LOADING_PATTERN; |
169 | return 1; | 174 | return 0; |
170 | } | 175 | } |
171 | 176 | ||
172 | if(flag) { | 177 | if(flag) { |
173 | ch=flag&31; | 178 | ch=flag&31; |
174 | if(mh->channels[ch]<32) remap[ch] = 0; | 179 | if(mh->channels[ch]<32) remap[ch] = 0; |
175 | if(flag&32) {(void)_mm_read_UBYTE(modreader);(void)_mm_read_UBYTE(modreader);} | 180 | if(flag&32) {_mm_skip_BYTE(modreader);_mm_skip_BYTE(modreader);} |
176 | if(flag&64) (void)_mm_read_UBYTE(modreader); | 181 | if(flag&64) _mm_skip_BYTE(modreader); |
177 | if(flag&128){(void)_mm_read_UBYTE(modreader);(void)_mm_read_UBYTE(modreader);} | 182 | if(flag&128){_mm_skip_BYTE(modreader);_mm_skip_BYTE(modreader);} |
178 | } else row++; | 183 | } else row++; |
179 | } | 184 | } |
180 | return 0; | 185 | return 1; |
181 | } | 186 | } |
182 | 187 | ||
183 | static int S3M_ReadPattern(void) | 188 | static int S3M_ReadPattern(void) |
184 | { | 189 | { |
@@ -282,6 +287,10 @@ static int S3M_Load(int curious) | |||
282 | _mm_errno = MMERR_LOADING_HEADER; | 287 | _mm_errno = MMERR_LOADING_HEADER; |
283 | return 0; | 288 | return 0; |
284 | } | 289 | } |
290 | if(mh->ordnum > 255 || mh->insnum > 255 || mh->patnum > 255) { | ||
291 | _mm_errno = MMERR_NOT_A_MODULE; | ||
292 | return 0; | ||
293 | } | ||
285 | 294 | ||
286 | /* then we can decide the module type */ | 295 | /* then we can decide the module type */ |
287 | tracker=mh->tracker>>12; | 296 | tracker=mh->tracker>>12; |
@@ -294,7 +303,7 @@ static int S3M_Load(int curious) | |||
294 | tracker=NUMTRACKERS; /* IT 2.14p3 */ | 303 | tracker=NUMTRACKERS; /* IT 2.14p3 */ |
295 | else tracker--; | 304 | else tracker--; |
296 | } | 305 | } |
297 | of.modtype = StrDup(S3M_Version[tracker]); | 306 | of.modtype = MikMod_strdup(S3M_Version[tracker]); |
298 | if(tracker<NUMTRACKERS) { | 307 | if(tracker<NUMTRACKERS) { |
299 | of.modtype[numeric[tracker]] = ((mh->tracker>>8) &0xf)+'0'; | 308 | of.modtype[numeric[tracker]] = ((mh->tracker>>8) &0xf)+'0'; |
300 | of.modtype[numeric[tracker]+2] = ((mh->tracker>>4)&0xf)+'0'; | 309 | of.modtype[numeric[tracker]+2] = ((mh->tracker>>4)&0xf)+'0'; |
@@ -315,7 +324,7 @@ static int S3M_Load(int curious) | |||
315 | 324 | ||
316 | /* read the order data */ | 325 | /* read the order data */ |
317 | if(!AllocPositions(mh->ordnum)) return 0; | 326 | if(!AllocPositions(mh->ordnum)) return 0; |
318 | if(!(origpositions=MikMod_calloc(mh->ordnum,sizeof(UWORD)))) return 0; | 327 | if(!(origpositions=(UWORD*)MikMod_calloc(mh->ordnum,sizeof(UWORD)))) return 0; |
319 | 328 | ||
320 | for(t=0;t<mh->ordnum;t++) { | 329 | for(t=0;t<mh->ordnum;t++) { |
321 | origpositions[t]=_mm_read_UBYTE(modreader); | 330 | origpositions[t]=_mm_read_UBYTE(modreader); |
@@ -374,7 +383,8 @@ static int S3M_Load(int curious) | |||
374 | _mm_read_string(s.scrs,4,modreader); | 383 | _mm_read_string(s.scrs,4,modreader); |
375 | 384 | ||
376 | /* ScreamTracker imposes a 64000 bytes (not 64k !) limit */ | 385 | /* ScreamTracker imposes a 64000 bytes (not 64k !) limit */ |
377 | if (s.length > 64000) | 386 | /* enforce it, if we'll use S3MIT_SCREAM in S3M_ConvertTrack() */ |
387 | if (s.length > 64000 && tracker == 1) | ||
378 | s.length = 64000; | 388 | s.length = 64000; |
379 | 389 | ||
380 | if(_mm_eof(modreader)) { | 390 | if(_mm_eof(modreader)) { |
@@ -388,7 +398,7 @@ static int S3M_Load(int curious) | |||
388 | q->loopstart = s.loopbeg; | 398 | q->loopstart = s.loopbeg; |
389 | q->loopend = s.loopend; | 399 | q->loopend = s.loopend; |
390 | q->volume = s.volume; | 400 | q->volume = s.volume; |
391 | q->seekpos = (((long)s.memsegh)<<16|s.memsegl)<<4; | 401 | q->seekpos = (((ULONG)s.memsegh)<<16|s.memsegl)<<4; |
392 | 402 | ||
393 | if(s.flags&1) q->flags |= SF_LOOP; | 403 | if(s.flags&1) q->flags |= SF_LOOP; |
394 | if(s.flags&4) q->flags |= SF_16BITS; | 404 | if(s.flags&4) q->flags |= SF_16BITS; |
@@ -406,16 +416,16 @@ static int S3M_Load(int curious) | |||
406 | for(t=0;t<of.numpat;t++) { | 416 | for(t=0;t<of.numpat;t++) { |
407 | /* seek to pattern position (+2 skip pattern length) */ | 417 | /* seek to pattern position (+2 skip pattern length) */ |
408 | _mm_fseek(modreader,(long)((paraptr[of.numins+t])<<4)+2,SEEK_SET); | 418 | _mm_fseek(modreader,(long)((paraptr[of.numins+t])<<4)+2,SEEK_SET); |
409 | if(S3M_GetNumChannels()) return 0; | 419 | if(!S3M_GetNumChannels()) return 0; |
410 | } | 420 | } |
411 | 421 | ||
412 | /* build the remap array */ | 422 | /* build the remap array */ |
413 | for(t=0;t<32;t++) | 423 | for(t=0;t<32;t++) |
414 | if(!remap[t]) | 424 | if(!remap[t]) |
415 | remap[t]=of.numchn++; | 425 | remap[t]=of.numchn++; |
416 | 426 | ||
417 | /* set panning positions after building remap chart! */ | 427 | /* set panning positions after building remap chart! */ |
418 | for(t=0;t<32;t++) | 428 | for(t=0;t<32;t++) |
419 | if((mh->channels[t]<32)&&(remap[t]!=-1)) { | 429 | if((mh->channels[t]<32)&&(remap[t]!=-1)) { |
420 | if(mh->channels[t]<8) | 430 | if(mh->channels[t]<8) |
421 | of.panning[remap[t]]=0x30; | 431 | of.panning[remap[t]]=0x30; |