diff options
Diffstat (limited to 'apps/plugins/mikmod/load_asy.c')
-rw-r--r-- | apps/plugins/mikmod/load_asy.c | 91 |
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 @@ it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. - + You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA @@ -20,15 +20,15 @@ /*============================================================================== - $Id: load_asy.c,v 1.3 2005/04/07 19:57:38 realtech Exp $ + $Id$ ASYLUM Music Format v1.0 (.amf) loader adapted from load_mod.c by Raphael Assenat <raph@raphnet.net>, with the help of the AMF2MOD utility sourcecode, written to convert crusader's amf files into 8 channels mod file in 1995 by Mr. P / Powersource - mrp@fish.share.net, ac054@sfn.saskatoon.sk.ca - + mrp@fish.share.net, ac054@sfn.saskatoon.sk.ca + ==============================================================================*/ @@ -76,8 +76,9 @@ typedef struct MODNOTE { /* This table is taken from AMF2MOD.C * written in 1995 by Mr. P / Powersource - * mrp@fish.share.net, ac054@sfn.saskatoon.sk.ca */ -UWORD periodtable[]={6848,6464,6096,5760,5424,5120,4832,4560,4304, + * mrp@fish.share.net, ac054@sfn.saskatoon.sk.ca */ +static const UWORD periodtable[] = { + 6848,6464,6096,5760,5424,5120,4832,4560,4304, 4064,3840,3628,3424,3232,3048,2880,2712,2560, 2416,2280,2152,2032,1920,1814,1712,1616,1524, 1440,1356,1280,1208,1140,1076,1016, 960, 907, @@ -108,7 +109,7 @@ static int ASY_CheckType(UBYTE *id, UBYTE *numchn, CHAR **descr) modtype = 1; return 1; } - + return 0; } @@ -140,14 +141,16 @@ static void ASY_Cleanup(void) { MikMod_free(mh); MikMod_free(patbuf); + mh = NULL; + patbuf = NULL; } -static void ConvertNote(MODNOTE *n) +static int ConvertNote(MODNOTE *n) { UBYTE instrument, effect, effdat, note; UWORD period; UBYTE lastnote = 0; - + instrument = n->b&0x1f; effect = n->c; effdat = n->d; @@ -158,10 +161,10 @@ static void ConvertNote(MODNOTE *n) } else { period = 0; } - + /* Convert the period to a note number */ note = 0; - if (period) + if (period) { for (note = 0; note < 7 * OCTAVE; note++) if (period >= npertab[note]) @@ -186,8 +189,8 @@ static void ConvertNote(MODNOTE *n) UniInstrument(instrument - 1); /* ...otherwise, only adjust volume... */ else { - /* ...unless an effect was specified, - * which forces a new note to be + /* ...unless an effect was specified, + * which forces a new note to be * played */ if (effect || effdat) { UniInstrument(instrument - 1); @@ -218,7 +221,15 @@ static void ConvertNote(MODNOTE *n) if ((effect == 0xa) && (effdat & 0xf) && (effdat & 0xf0)) effdat &= 0xf0; + if (effect == 0x1b) { + return 0; /* UniEffect(UNI_S3MEFFECTQ,dat) ? */ + } + if (effect > 0xf) { + return 0; /* return -1 to fail? */ + } + UniPTEffect(effect, effdat); + return 0; } static UBYTE *ConvertTrack(MODNOTE *n) @@ -227,7 +238,8 @@ static UBYTE *ConvertTrack(MODNOTE *n) UniReset(); for (t = 0; t < 64; t++) { - ConvertNote(n); + if (ConvertNote(n) < 0) + return NULL; UniNewline(); n += of.numchn; } @@ -237,8 +249,7 @@ static UBYTE *ConvertTrack(MODNOTE *n) /* Loads all patterns of a modfile and converts them into the 3 byte format. */ static int ML_LoadPatterns(void) { - int t, tracks = 0; - unsigned int s; + unsigned int t, s, tracks = 0; if (!AllocPatterns()) { return 0; @@ -246,7 +257,7 @@ static int ML_LoadPatterns(void) if (!AllocTracks()) { return 0; } - + /* Allocate temporary buffer for loading and converting the patterns */ if (!(patbuf = (MODNOTE *)MikMod_calloc(64U * of.numchn, sizeof(MODNOTE)))) return 0; @@ -278,31 +289,31 @@ static int ASY_Load(int curious) MSAMPINFO *s; CHAR *descr=asylum; ULONG seekpos; - (void)curious; + (void)curious; - // no title in asylum amf files :( - strcpy(mh->songname, ""); + /* no title in asylum amf files :( */ + mh->songname[0] = '\0'; _mm_fseek(modreader, 0x23, SEEK_SET); mh->num_patterns = _mm_read_UBYTE(modreader); mh->num_orders = _mm_read_UBYTE(modreader); - - // skip unknown byte - (void)_mm_read_UBYTE(modreader); + + /* skip unknown byte */ + _mm_skip_BYTE(modreader); _mm_read_UBYTES(mh->positions, 256, modreader); - + /* read samples headers*/ for (t = 0; t < 64; t++) { s = &mh->samples[t]; - + _mm_fseek(modreader, 0x126 + (t*37), SEEK_SET); - + _mm_read_string(s->samplename, 22, modreader); s->samplename[21] = 0; /* just in case */ - + s->finetune = _mm_read_UBYTE(modreader); s->volume = _mm_read_UBYTE(modreader); - (void)_mm_read_UBYTE(modreader); // skip unknown byte + _mm_skip_BYTE(modreader);/* skip unknown byte */ s->length = _mm_read_I_ULONG(modreader); s->reppos = _mm_read_I_ULONG(modreader); s->replen = _mm_read_I_ULONG(modreader); @@ -324,12 +335,16 @@ static int ASY_Load(int curious) of.numpat = mh->num_patterns; of.numtrk = of.numpat * of.numchn; - /* Copy positions (orders) */ if (!AllocPositions(of.numpos)) return 0; for (t = 0; t < of.numpos; t++) { of.positions[t] = mh->positions[t]; + if (of.positions[t]>of.numpat) { /* SANITIY CHECK */ + /* fprintf(stderr,"positions[%d]=%d > numpat=%d\n",t,of.positions[t],of.numpat);*/ + _mm_errno = MMERR_LOADING_HEADER; + return 0; + } } /* Finally, init the sampleinfo structures */ @@ -343,7 +358,7 @@ static int ASY_Load(int curious) for (t = 0; t < of.numins; t++) { /* convert the samplename */ q->samplename = DupStr(s->samplename, 23, 1); - + /* init the sampleinfo variables */ q->speed = finetune[s->finetune & 0xf]; q->volume = s->volume & 0x7f; @@ -351,16 +366,16 @@ static int ASY_Load(int curious) q->loopstart = (ULONG)s->reppos; q->loopend = (ULONG)q->loopstart + (s->replen); q->length = (ULONG)s->length; - + q->flags = SF_SIGNED; - + q->seekpos = seekpos; seekpos += q->length; - + if ((s->replen) > 2) { q->flags |= SF_LOOP; } - + /* fix replen if repend > length */ if (q->loopend > q->length) q->loopend = q->length; @@ -369,7 +384,7 @@ static int ASY_Load(int curious) q++; } - of.modtype = StrDup(descr); + of.modtype = MikMod_strdup(descr); if (!ML_LoadPatterns()) return 0; @@ -379,9 +394,7 @@ static int ASY_Load(int curious) static CHAR *ASY_LoadTitle(void) { - CHAR *s = ""; // no titles - - return (DupStr(s, 21, 1)); + return MikMod_strdup(""); } /*========== Loader information */ |