summaryrefslogtreecommitdiff
path: root/apps/plugins/mikmod/load_dsm.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/mikmod/load_dsm.c')
-rw-r--r--apps/plugins/mikmod/load_dsm.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/apps/plugins/mikmod/load_dsm.c b/apps/plugins/mikmod/load_dsm.c
index 59abf0bcfe..e995f7dfad 100644
--- a/apps/plugins/mikmod/load_dsm.c
+++ b/apps/plugins/mikmod/load_dsm.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_dsm.c,v 1.3 2005/04/07 19:57:38 realtech Exp $ 23 $Id$
24 24
25 DSIK internal format (DSM) module loader 25 DSIK internal format (DSM) module loader
26 26
@@ -89,9 +89,9 @@ typedef struct DSMNOTE {
89 89
90/*========== Loader variables */ 90/*========== Loader variables */
91 91
92static CHAR* SONGID="SONG"; 92static const CHAR* SONGID="SONG";
93static CHAR* INSTID="INST"; 93static const CHAR* INSTID="INST";
94static CHAR* PATTID="PATT"; 94static const CHAR* PATTID="PATT";
95 95
96static UBYTE blockid[4]; 96static UBYTE blockid[4];
97static ULONG blockln; 97static ULONG blockln;
@@ -101,7 +101,7 @@ static DSMNOTE* dsmbuf=NULL;
101 101
102static CHAR DSM_Version[]="DSIK DSM-format"; 102static CHAR DSM_Version[]="DSIK DSM-format";
103 103
104static unsigned char DSMSIG[4+4]={'R','I','F','F','D','S','M','F'}; 104static const unsigned char DSMSIG[4+4]={'R','I','F','F','D','S','M','F'};
105 105
106/*========== Loader code */ 106/*========== Loader code */
107 107
@@ -126,6 +126,8 @@ static void DSM_Cleanup(void)
126{ 126{
127 MikMod_free(dsmbuf); 127 MikMod_free(dsmbuf);
128 MikMod_free(mh); 128 MikMod_free(mh);
129 dsmbuf = NULL;
130 mh = NULL;
129} 131}
130 132
131static int GetBlockHeader(void) 133static int GetBlockHeader(void)
@@ -133,7 +135,7 @@ static int GetBlockHeader(void)
133 /* make sure we're at the right position for reading the 135 /* make sure we're at the right position for reading the
134 next riff block, no matter how many bytes read */ 136 next riff block, no matter how many bytes read */
135 _mm_fseek(modreader, blocklp+blockln, SEEK_SET); 137 _mm_fseek(modreader, blocklp+blockln, SEEK_SET);
136 138
137 while(1) { 139 while(1) {
138 _mm_read_UBYTES(blockid,4,modreader); 140 _mm_read_UBYTES(blockid,4,modreader);
139 blockln=_mm_read_I_ULONG(modreader); 141 blockln=_mm_read_I_ULONG(modreader);
@@ -237,7 +239,7 @@ static int DSM_Load(int curious)
237 DSMINST s; 239 DSMINST s;
238 SAMPLE *q; 240 SAMPLE *q;
239 int cursmp=0,curpat=0,track=0; 241 int cursmp=0,curpat=0,track=0;
240 (void)curious; 242 (void)curious;
241 243
242 blocklp=0; 244 blocklp=0;
243 blockln=12; 245 blockln=12;
@@ -266,7 +268,7 @@ static int DSM_Load(int curious)
266 /* set module variables */ 268 /* set module variables */
267 of.initspeed=mh->speed; 269 of.initspeed=mh->speed;
268 of.inittempo=mh->bpm; 270 of.inittempo=mh->bpm;
269 of.modtype=StrDup(DSM_Version); 271 of.modtype=MikMod_strdup(DSM_Version);
270 of.numchn=mh->numtrk; 272 of.numchn=mh->numtrk;
271 of.numpat=mh->numpat; 273 of.numpat=mh->numpat;
272 of.numtrk=of.numchn*of.numpat; 274 of.numtrk=of.numchn*of.numpat;
@@ -286,6 +288,11 @@ static int DSM_Load(int curious)
286 for(t=0;t<mh->numord;t++) { 288 for(t=0;t<mh->numord;t++) {
287 int order=mh->orders[t]; 289 int order=mh->orders[t];
288 if(order==255) order=LAST_PATTERN; 290 if(order==255) order=LAST_PATTERN;
291 else if (of.positions[t]>of.numpat) { /* SANITIY CHECK */
292 /* fprintf(stderr,"positions[%d]=%d > numpat=%d\n",t,of.positions[t],of.numpat);*/
293 _mm_errno = MMERR_LOADING_HEADER;
294 return 0;
295 }
289 of.positions[of.numpos]=order; 296 of.positions[of.numpos]=order;
290 if(mh->orders[t]<254) of.numpos++; 297 if(mh->orders[t]<254) of.numpos++;
291 } 298 }
@@ -344,7 +351,7 @@ static CHAR *DSM_LoadTitle(void)
344 351
345 _mm_fseek(modreader,12,SEEK_SET); 352 _mm_fseek(modreader,12,SEEK_SET);
346 if(!_mm_read_UBYTES(s,28,modreader)) return NULL; 353 if(!_mm_read_UBYTES(s,28,modreader)) return NULL;
347 354
348 return(DupStr(s,28,1)); 355 return(DupStr(s,28,1));
349} 356}
350 357