summaryrefslogtreecommitdiff
path: root/apps/plugins/mikmod/load_gdm.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/mikmod/load_gdm.c')
-rw-r--r--apps/plugins/mikmod/load_gdm.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/apps/plugins/mikmod/load_gdm.c b/apps/plugins/mikmod/load_gdm.c
index 694d534236..5f06f9c70b 100644
--- a/apps/plugins/mikmod/load_gdm.c
+++ b/apps/plugins/mikmod/load_gdm.c
@@ -20,7 +20,7 @@
20 20
21/*============================================================================== 21/*==============================================================================
22 22
23 $Id: load_gdm.c,v 1.3 2005/04/07 19:57:38 realtech Exp $ 23 $Id$
24 24
25 General DigiMusic (GDM) module loader 25 General DigiMusic (GDM) module loader
26 26
@@ -114,7 +114,7 @@ typedef struct GDMSAMPLE {
114static GDMHEADER *mh=NULL; /* pointer to GDM header */ 114static GDMHEADER *mh=NULL; /* pointer to GDM header */
115static GDMNOTE *gdmbuf=NULL; /* pointer to a complete GDM pattern */ 115static GDMNOTE *gdmbuf=NULL; /* pointer to a complete GDM pattern */
116 116
117CHAR GDM_Version[]="General DigiMusic 1.xx"; 117static CHAR GDM_Version[]="General DigiMusic 1.xx";
118 118
119static int GDM_Test(void) 119static int GDM_Test(void)
120{ 120{
@@ -146,36 +146,45 @@ static void GDM_Cleanup(void)
146{ 146{
147 MikMod_free(mh); 147 MikMod_free(mh);
148 MikMod_free(gdmbuf); 148 MikMod_free(gdmbuf);
149 mh=NULL;
150 gdmbuf=NULL;
149} 151}
150 152
151static int GDM_ReadPattern(void) 153static int GDM_ReadPattern(void)
152{ 154{
153 int pos,flag,ch,i,maxch; 155 int pos,flag,ch,i;
154 GDMNOTE n; 156 GDMNOTE n;
155 UWORD length,x=0; 157 SLONG length,x=0;
156 158
157 /* get pattern length */ 159 /* get pattern length */
158 length=_mm_read_I_UWORD(modreader)-2; 160 length=(SLONG)_mm_read_I_UWORD(modreader);
161 length-=2;
159 162
160 /* clear pattern data */ 163 /* clear pattern data */
161 memset(gdmbuf,255,32*64*sizeof(GDMNOTE)); 164 memset(gdmbuf,255,32*64*sizeof(GDMNOTE));
162 pos=0; 165 pos=0;
163 maxch=0;
164 166
165 while (x<length) { 167 while (x<length) {
166 memset(&n,255,sizeof(GDMNOTE)); 168 memset(&n,255,sizeof(GDMNOTE));
167 flag=_mm_read_UBYTE(modreader); 169 flag=_mm_read_UBYTE(modreader);
168 x++; 170 x++;
169 171
170 if (_mm_eof(modreader)) { 172 if (_mm_eof(modreader))
171 _mm_errno=MMERR_LOADING_PATTERN;
172 return 0; 173 return 0;
173 }
174 174
175 ch=flag&31; 175 ch=flag&31;
176 if (ch>maxch) maxch=ch; 176 if (ch > of.numchn)
177 return 0;
178
177 if (!flag) { 179 if (!flag) {
178 pos++; 180 pos++;
181 if (x==length) {
182 if (pos > 64)
183 return 0;
184 } else {
185 if (pos >= 64)
186 return 0;
187 }
179 continue; 188 continue;
180 } 189 }
181 if (flag&0x60) { 190 if (flag&0x60) {
@@ -343,7 +352,7 @@ static int GDM_Load(int curious)
343 SAMPLE *q; 352 SAMPLE *q;
344 GDMSAMPLE s; 353 GDMSAMPLE s;
345 ULONG position; 354 ULONG position;
346 (void)curious; 355 (void)curious;
347 356
348 /* read header */ 357 /* read header */
349 _mm_read_string(mh->id1,4,modreader); 358 _mm_read_string(mh->id1,4,modreader);
@@ -390,7 +399,7 @@ static int GDM_Load(int curious)
390 } 399 }
391 400
392 /* now we fill */ 401 /* now we fill */
393 of.modtype=StrDup(GDM_Version); 402 of.modtype=MikMod_strdup(GDM_Version);
394 of.modtype[18]=mh->majorver+'0'; 403 of.modtype[18]=mh->majorver+'0';
395 of.modtype[20]=mh->minorver/10+'0'; 404 of.modtype[20]=mh->minorver/10+'0';
396 of.modtype[21]=mh->minorver%10+'0'; 405 of.modtype[21]=mh->minorver%10+'0';