summaryrefslogtreecommitdiff
path: root/apps/plugins/mikmod/load_asy.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/mikmod/load_asy.c')
-rw-r--r--apps/plugins/mikmod/load_asy.c91
1 files changed, 52 insertions, 39 deletions
diff --git a/apps/plugins/mikmod/load_asy.c b/apps/plugins/mikmod/load_asy.c
index 46e899f6bd..48d746c8e8 100644
--- a/apps/plugins/mikmod/load_asy.c
+++ b/apps/plugins/mikmod/load_asy.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,15 +20,15 @@
20 20
21/*============================================================================== 21/*==============================================================================
22 22
23 $Id: load_asy.c,v 1.3 2005/04/07 19:57:38 realtech Exp $ 23 $Id$
24 24
25 ASYLUM Music Format v1.0 (.amf) loader 25 ASYLUM Music Format v1.0 (.amf) loader
26 adapted from load_mod.c by Raphael Assenat <raph@raphnet.net>, 26 adapted from load_mod.c by Raphael Assenat <raph@raphnet.net>,
27 with the help of the AMF2MOD utility sourcecode, 27 with the help of the AMF2MOD utility sourcecode,
28 written to convert crusader's amf files into 8 28 written to convert crusader's amf files into 8
29 channels mod file in 1995 by Mr. P / Powersource 29 channels mod file in 1995 by Mr. P / Powersource
30 mrp@fish.share.net, ac054@sfn.saskatoon.sk.ca 30 mrp@fish.share.net, ac054@sfn.saskatoon.sk.ca
31 31
32 32
33==============================================================================*/ 33==============================================================================*/
34 34
@@ -76,8 +76,9 @@ typedef struct MODNOTE {
76 76
77/* This table is taken from AMF2MOD.C 77/* This table is taken from AMF2MOD.C
78 * written in 1995 by Mr. P / Powersource 78 * written in 1995 by Mr. P / Powersource
79 * mrp@fish.share.net, ac054@sfn.saskatoon.sk.ca */ 79 * mrp@fish.share.net, ac054@sfn.saskatoon.sk.ca */
80UWORD periodtable[]={6848,6464,6096,5760,5424,5120,4832,4560,4304, 80static const UWORD periodtable[] = {
81 6848,6464,6096,5760,5424,5120,4832,4560,4304,
81 4064,3840,3628,3424,3232,3048,2880,2712,2560, 82 4064,3840,3628,3424,3232,3048,2880,2712,2560,
82 2416,2280,2152,2032,1920,1814,1712,1616,1524, 83 2416,2280,2152,2032,1920,1814,1712,1616,1524,
83 1440,1356,1280,1208,1140,1076,1016, 960, 907, 84 1440,1356,1280,1208,1140,1076,1016, 960, 907,
@@ -108,7 +109,7 @@ static int ASY_CheckType(UBYTE *id, UBYTE *numchn, CHAR **descr)
108 modtype = 1; 109 modtype = 1;
109 return 1; 110 return 1;
110 } 111 }
111 112
112 return 0; 113 return 0;
113} 114}
114 115
@@ -140,14 +141,16 @@ static void ASY_Cleanup(void)
140{ 141{
141 MikMod_free(mh); 142 MikMod_free(mh);
142 MikMod_free(patbuf); 143 MikMod_free(patbuf);
144 mh = NULL;
145 patbuf = NULL;
143} 146}
144 147
145static void ConvertNote(MODNOTE *n) 148static int ConvertNote(MODNOTE *n)
146{ 149{
147 UBYTE instrument, effect, effdat, note; 150 UBYTE instrument, effect, effdat, note;
148 UWORD period; 151 UWORD period;
149 UBYTE lastnote = 0; 152 UBYTE lastnote = 0;
150 153
151 instrument = n->b&0x1f; 154 instrument = n->b&0x1f;
152 effect = n->c; 155 effect = n->c;
153 effdat = n->d; 156 effdat = n->d;
@@ -158,10 +161,10 @@ static void ConvertNote(MODNOTE *n)
158 } else { 161 } else {
159 period = 0; 162 period = 0;
160 } 163 }
161 164
162 /* Convert the period to a note number */ 165 /* Convert the period to a note number */
163 note = 0; 166 note = 0;
164 if (period) 167 if (period)
165 { 168 {
166 for (note = 0; note < 7 * OCTAVE; note++) 169 for (note = 0; note < 7 * OCTAVE; note++)
167 if (period >= npertab[note]) 170 if (period >= npertab[note])
@@ -186,8 +189,8 @@ static void ConvertNote(MODNOTE *n)
186 UniInstrument(instrument - 1); 189 UniInstrument(instrument - 1);
187 /* ...otherwise, only adjust volume... */ 190 /* ...otherwise, only adjust volume... */
188 else { 191 else {
189 /* ...unless an effect was specified, 192 /* ...unless an effect was specified,
190 * which forces a new note to be 193 * which forces a new note to be
191 * played */ 194 * played */
192 if (effect || effdat) { 195 if (effect || effdat) {
193 UniInstrument(instrument - 1); 196 UniInstrument(instrument - 1);
@@ -218,7 +221,15 @@ static void ConvertNote(MODNOTE *n)
218 if ((effect == 0xa) && (effdat & 0xf) && (effdat & 0xf0)) 221 if ((effect == 0xa) && (effdat & 0xf) && (effdat & 0xf0))
219 effdat &= 0xf0; 222 effdat &= 0xf0;
220 223
224 if (effect == 0x1b) {
225 return 0; /* UniEffect(UNI_S3MEFFECTQ,dat) ? */
226 }
227 if (effect > 0xf) {
228 return 0; /* return -1 to fail? */
229 }
230
221 UniPTEffect(effect, effdat); 231 UniPTEffect(effect, effdat);
232 return 0;
222} 233}
223 234
224static UBYTE *ConvertTrack(MODNOTE *n) 235static UBYTE *ConvertTrack(MODNOTE *n)
@@ -227,7 +238,8 @@ static UBYTE *ConvertTrack(MODNOTE *n)
227 238
228 UniReset(); 239 UniReset();
229 for (t = 0; t < 64; t++) { 240 for (t = 0; t < 64; t++) {
230 ConvertNote(n); 241 if (ConvertNote(n) < 0)
242 return NULL;
231 UniNewline(); 243 UniNewline();
232 n += of.numchn; 244 n += of.numchn;
233 } 245 }
@@ -237,8 +249,7 @@ static UBYTE *ConvertTrack(MODNOTE *n)
237/* Loads all patterns of a modfile and converts them into the 3 byte format. */ 249/* Loads all patterns of a modfile and converts them into the 3 byte format. */
238static int ML_LoadPatterns(void) 250static int ML_LoadPatterns(void)
239{ 251{
240 int t, tracks = 0; 252 unsigned int t, s, tracks = 0;
241 unsigned int s;
242 253
243 if (!AllocPatterns()) { 254 if (!AllocPatterns()) {
244 return 0; 255 return 0;
@@ -246,7 +257,7 @@ static int ML_LoadPatterns(void)
246 if (!AllocTracks()) { 257 if (!AllocTracks()) {
247 return 0; 258 return 0;
248 } 259 }
249 260
250 /* Allocate temporary buffer for loading and converting the patterns */ 261 /* Allocate temporary buffer for loading and converting the patterns */
251 if (!(patbuf = (MODNOTE *)MikMod_calloc(64U * of.numchn, sizeof(MODNOTE)))) 262 if (!(patbuf = (MODNOTE *)MikMod_calloc(64U * of.numchn, sizeof(MODNOTE))))
252 return 0; 263 return 0;
@@ -278,31 +289,31 @@ static int ASY_Load(int curious)
278 MSAMPINFO *s; 289 MSAMPINFO *s;
279 CHAR *descr=asylum; 290 CHAR *descr=asylum;
280 ULONG seekpos; 291 ULONG seekpos;
281 (void)curious; 292 (void)curious;
282 293
283 // no title in asylum amf files :( 294 /* no title in asylum amf files :( */
284 strcpy(mh->songname, ""); 295 mh->songname[0] = '\0';
285 296
286 _mm_fseek(modreader, 0x23, SEEK_SET); 297 _mm_fseek(modreader, 0x23, SEEK_SET);
287 mh->num_patterns = _mm_read_UBYTE(modreader); 298 mh->num_patterns = _mm_read_UBYTE(modreader);
288 mh->num_orders = _mm_read_UBYTE(modreader); 299 mh->num_orders = _mm_read_UBYTE(modreader);
289 300
290 // skip unknown byte 301 /* skip unknown byte */
291 (void)_mm_read_UBYTE(modreader); 302 _mm_skip_BYTE(modreader);
292 _mm_read_UBYTES(mh->positions, 256, modreader); 303 _mm_read_UBYTES(mh->positions, 256, modreader);
293 304
294 /* read samples headers*/ 305 /* read samples headers*/
295 for (t = 0; t < 64; t++) { 306 for (t = 0; t < 64; t++) {
296 s = &mh->samples[t]; 307 s = &mh->samples[t];
297 308
298 _mm_fseek(modreader, 0x126 + (t*37), SEEK_SET); 309 _mm_fseek(modreader, 0x126 + (t*37), SEEK_SET);
299 310
300 _mm_read_string(s->samplename, 22, modreader); 311 _mm_read_string(s->samplename, 22, modreader);
301 s->samplename[21] = 0; /* just in case */ 312 s->samplename[21] = 0; /* just in case */
302 313
303 s->finetune = _mm_read_UBYTE(modreader); 314 s->finetune = _mm_read_UBYTE(modreader);
304 s->volume = _mm_read_UBYTE(modreader); 315 s->volume = _mm_read_UBYTE(modreader);
305 (void)_mm_read_UBYTE(modreader); // skip unknown byte 316 _mm_skip_BYTE(modreader);/* skip unknown byte */
306 s->length = _mm_read_I_ULONG(modreader); 317 s->length = _mm_read_I_ULONG(modreader);
307 s->reppos = _mm_read_I_ULONG(modreader); 318 s->reppos = _mm_read_I_ULONG(modreader);
308 s->replen = _mm_read_I_ULONG(modreader); 319 s->replen = _mm_read_I_ULONG(modreader);
@@ -324,12 +335,16 @@ static int ASY_Load(int curious)
324 of.numpat = mh->num_patterns; 335 of.numpat = mh->num_patterns;
325 of.numtrk = of.numpat * of.numchn; 336 of.numtrk = of.numpat * of.numchn;
326 337
327
328 /* Copy positions (orders) */ 338 /* Copy positions (orders) */
329 if (!AllocPositions(of.numpos)) 339 if (!AllocPositions(of.numpos))
330 return 0; 340 return 0;
331 for (t = 0; t < of.numpos; t++) { 341 for (t = 0; t < of.numpos; t++) {
332 of.positions[t] = mh->positions[t]; 342 of.positions[t] = mh->positions[t];
343 if (of.positions[t]>of.numpat) { /* SANITIY CHECK */
344 /* fprintf(stderr,"positions[%d]=%d > numpat=%d\n",t,of.positions[t],of.numpat);*/
345 _mm_errno = MMERR_LOADING_HEADER;
346 return 0;
347 }
333 } 348 }
334 349
335 /* Finally, init the sampleinfo structures */ 350 /* Finally, init the sampleinfo structures */
@@ -343,7 +358,7 @@ static int ASY_Load(int curious)
343 for (t = 0; t < of.numins; t++) { 358 for (t = 0; t < of.numins; t++) {
344 /* convert the samplename */ 359 /* convert the samplename */
345 q->samplename = DupStr(s->samplename, 23, 1); 360 q->samplename = DupStr(s->samplename, 23, 1);
346 361
347 /* init the sampleinfo variables */ 362 /* init the sampleinfo variables */
348 q->speed = finetune[s->finetune & 0xf]; 363 q->speed = finetune[s->finetune & 0xf];
349 q->volume = s->volume & 0x7f; 364 q->volume = s->volume & 0x7f;
@@ -351,16 +366,16 @@ static int ASY_Load(int curious)
351 q->loopstart = (ULONG)s->reppos; 366 q->loopstart = (ULONG)s->reppos;
352 q->loopend = (ULONG)q->loopstart + (s->replen); 367 q->loopend = (ULONG)q->loopstart + (s->replen);
353 q->length = (ULONG)s->length; 368 q->length = (ULONG)s->length;
354 369
355 q->flags = SF_SIGNED; 370 q->flags = SF_SIGNED;
356 371
357 q->seekpos = seekpos; 372 q->seekpos = seekpos;
358 seekpos += q->length; 373 seekpos += q->length;
359 374
360 if ((s->replen) > 2) { 375 if ((s->replen) > 2) {
361 q->flags |= SF_LOOP; 376 q->flags |= SF_LOOP;
362 } 377 }
363 378
364 /* fix replen if repend > length */ 379 /* fix replen if repend > length */
365 if (q->loopend > q->length) 380 if (q->loopend > q->length)
366 q->loopend = q->length; 381 q->loopend = q->length;
@@ -369,7 +384,7 @@ static int ASY_Load(int curious)
369 q++; 384 q++;
370 } 385 }
371 386
372 of.modtype = StrDup(descr); 387 of.modtype = MikMod_strdup(descr);
373 388
374 if (!ML_LoadPatterns()) 389 if (!ML_LoadPatterns())
375 return 0; 390 return 0;
@@ -379,9 +394,7 @@ static int ASY_Load(int curious)
379 394
380static CHAR *ASY_LoadTitle(void) 395static CHAR *ASY_LoadTitle(void)
381{ 396{
382 CHAR *s = ""; // no titles 397 return MikMod_strdup("");
383
384 return (DupStr(s, 21, 1));
385} 398}
386 399
387/*========== Loader information */ 400/*========== Loader information */