annotate playercode/load_s3m.c @ 22:d9f79436e0af default tip

Makefile Add ranlib for the library
author darius
date Fri, 24 Apr 1998 08:05:26 +0000
parents 5d614bcc4287
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
1 /*
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
2
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
3 Name: LOAD_S3M.C
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
4
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
5 Description:
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
6 Screamtracker (S3M) module loader
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
7
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
8 Portability:
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
9 All systems - all compilers (hopefully)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
10
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
11 If this module is found to not be portable to any particular platform,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
12 please contact Jake Stine at dracoirs@epix.net (see MIKMOD.TXT for
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
13 more information on contacting the author).
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
14
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
15 */
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
16
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
17 #include <string.h>
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
18 #include "mikmod.h"
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
19
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
20 /**************************************************************************
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
21 **************************************************************************/
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
22
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
23 typedef struct S3MNOTE
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
24 { UBYTE note,ins,vol,cmd,inf;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
25 } S3MNOTE;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
26
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
27 typedef S3MNOTE S3MTRACK[64];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
28
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
29
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
30 // Raw S3M header struct:
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
31
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
32 typedef struct S3MHEADER
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
33 { CHAR songname[28];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
34 UBYTE t1a;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
35 UBYTE type;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
36 UBYTE unused1[2];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
37 UWORD ordnum;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
38 UWORD insnum;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
39 UWORD patnum;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
40 UWORD flags;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
41 UWORD tracker;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
42 UWORD fileformat;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
43 CHAR scrm[4];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
44 UBYTE mastervol;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
45 UBYTE initspeed;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
46 UBYTE inittempo;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
47 UBYTE mastermult;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
48 UBYTE ultraclick;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
49 UBYTE pantable;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
50 UBYTE unused2[8];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
51 UWORD special;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
52 UBYTE channels[32];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
53 } S3MHEADER;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
54
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
55
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
56 // Raw S3M sampleinfo struct:
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
57
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
58 typedef struct S3MSAMPLE
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
59 { UBYTE type;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
60 CHAR filename[12];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
61 UBYTE memsegh;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
62 UWORD memsegl;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
63 ULONG length;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
64 ULONG loopbeg;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
65 ULONG loopend;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
66 UBYTE volume;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
67 UBYTE dsk;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
68 UBYTE pack;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
69 UBYTE flags;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
70 ULONG c2spd;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
71 UBYTE unused[12];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
72 CHAR sampname[28];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
73 CHAR scrs[4];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
74 } S3MSAMPLE;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
75
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
76 /**************************************************************************
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
77 **************************************************************************/
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
78
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
79
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
80 extern UBYTE *poslookup; // S3M/IT fix - removing blank patterns needs a
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
81 // lookup table to fix position-jump commands
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
82 extern SBYTE remap[64]; // for removing empty channels
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
83
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
84 static S3MNOTE *s3mbuf = NULL; // pointer to a complete S3M pattern
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
85 static S3MHEADER *mh = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
86 static UWORD *paraptr = NULL; // parapointer array (see S3M docs)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
87
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
88 CHAR S3M_Version[] = "Screamtracker 3.xx";
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
89
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
90 BOOL S3M_Test(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
91 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
92 UBYTE id[4];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
93
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
94 _mm_fseek(modfp,0x2c,SEEK_SET);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
95 if(!_mm_read_UBYTES(id,4,modfp)) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
96 if(!memcmp(id,"SCRM",4)) return 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
97 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
98 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
99
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
100 BOOL S3M_Init(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
101 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
102 if(!(s3mbuf = (S3MNOTE *)_mm_malloc(16*64*sizeof(S3MNOTE)))) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
103 if(!(mh = (S3MHEADER *)_mm_calloc(1,sizeof(S3MHEADER)))) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
104 if(!(poslookup = (UBYTE *)_mm_malloc(sizeof(UBYTE)*128))) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
105
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
106 return 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
107 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
108
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
109 void S3M_Cleanup(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
110 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
111 if(s3mbuf!=NULL) free(s3mbuf);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
112 if(paraptr!=NULL) free(paraptr);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
113 if(poslookup!=NULL) free(poslookup);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
114 if(mh!=NULL) free(mh);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
115
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
116 paraptr = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
117 s3mbuf = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
118 poslookup = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
119 mh = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
120 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
121
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
122
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
123 BOOL S3M_GetNumChannels(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
124
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
125 // Because so many s3m files have 16 channels as the set number used, but really
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
126 // only use far less (usually 8 to 12 still), I had to make this function,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
127 // which determines the number of channels that are actually USED by a pattern.
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
128 //
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
129 // For every channel that's used, it sets the appropriate array entry of the
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
130 // global varialbe 'isused'
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
131 //
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
132 // NOTE: You must first seek to the file location of the pattern before calling
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
133 // this procedure.
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
134 // Returns 1 on fail.
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
135
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
136 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
137 int row=0,flag,ch;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
138
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
139 while(row<64)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
140 { flag = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
141
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
142 if(feof(modfp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
143 { _mm_errno = MMERR_LOADING_PATTERN;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
144 return 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
145 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
146
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
147 if(flag)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
148 { ch = flag&31;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
149 if(mh->channels[ch] < 16) remap[ch] = 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
150
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
151 if(flag&32)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
152 { _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
153 _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
154 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
155
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
156 if(flag&64)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
157 _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
158
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
159 if(flag&128)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
160 { _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
161 _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
162 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
163 } else row++;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
164 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
165
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
166 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
167 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
168
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
169
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
170 BOOL S3M_ReadPattern(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
171 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
172 int row=0,flag,ch;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
173 S3MNOTE *n;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
174 S3MNOTE dummy;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
175
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
176 // clear pattern data
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
177 memset(s3mbuf,255,16*64*sizeof(S3MNOTE));
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
178
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
179 while(row<64)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
180 { flag = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
181
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
182 if(flag==EOF)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
183 { _mm_errno = MMERR_LOADING_PATTERN;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
184 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
185 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
186
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
187 if(flag)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
188 { ch = remap[flag&31];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
189
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
190 if(ch != -1)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
191 n = &s3mbuf[(64U*ch)+row];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
192 else
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
193 n = &dummy;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
194
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
195 if(flag&32)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
196 { n->note = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
197 n->ins = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
198 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
199
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
200 if(flag&64)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
201 n->vol = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
202
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
203 if(flag&128)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
204 { n->cmd = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
205 n->inf = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
206 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
207 } else row++;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
208 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
209 return 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
210 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
211
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
212
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
213 void S3MIT_ProcessCmd(UBYTE cmd, UBYTE inf, BOOL oldeffect);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
214
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
215 UBYTE *S3M_ConvertTrack(S3MNOTE *tr)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
216 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
217 int t;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
218
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
219 UBYTE note,ins,vol;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
220
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
221 UniReset();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
222 for(t=0; t<64; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
223 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
224 note = tr[t].note;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
225 ins = tr[t].ins;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
226 vol = tr[t].vol;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
227
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
228
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
229 if(ins!=0 && ins!=255) UniInstrument(ins-1);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
230 if(note!=255)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
231 { if(note==254) UniPTEffect(0xc,0); // <- note off command
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
232 else UniNote(((note>>4)*12)+(note&0xf)); // <- normal note
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
233 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
234
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
235 if(vol<255)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
236 UniPTEffect(0xc,vol);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
237
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
238 S3MIT_ProcessCmd(tr[t].cmd,tr[t].inf,1);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
239 UniNewline();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
240 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
241
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
242 return UniDup();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
243 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
244
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
245
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
246 BOOL S3M_Load(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
247 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
248 int t,u,track = 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
249 SAMPLE *q;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
250 UBYTE pan[32];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
251
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
252 // try to read module header
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
253
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
254 _mm_read_string(mh->songname,28,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
255 mh->t1a =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
256 mh->type =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
257 _mm_read_UBYTES(mh->unused1,2,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
258 mh->ordnum =_mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
259 mh->insnum =_mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
260 mh->patnum =_mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
261 mh->flags =_mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
262 mh->tracker =_mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
263 mh->fileformat =_mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
264 _mm_read_string(mh->scrm,4,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
265
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
266 mh->mastervol =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
267 mh->initspeed =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
268 mh->inittempo =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
269 mh->mastermult =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
270 mh->ultraclick =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
271 mh->pantable =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
272 _mm_read_UBYTES(mh->unused2,8,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
273 mh->special =_mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
274 _mm_read_UBYTES(mh->channels,32,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
275
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
276 if(feof(modfp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
277 { _mm_errno = MMERR_LOADING_HEADER;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
278 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
279 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
280
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
281 // set module variables
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
282
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
283 of.modtype = strdup(S3M_Version);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
284 of.modtype[14] = ((mh->tracker >> 8) &0xf) + 0x30;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
285 of.modtype[16] = ((mh->tracker >> 4)&0xf) + 0x30;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
286 of.modtype[17] = ((mh->tracker)&0xf) + 0x30;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
287 of.songname = DupStr(mh->songname,28);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
288 of.numpat = mh->patnum;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
289 of.reppos = 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
290 of.numins = of.numsmp = mh->insnum;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
291 of.initspeed = mh->initspeed;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
292 of.inittempo = mh->inittempo;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
293 of.initvolume = mh->mastervol<<1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
294
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
295 // read the order data
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
296 if(!AllocPositions(mh->ordnum)) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
297 for(t=0; t<mh->ordnum; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
298 of.positions[t] = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
299
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
300 of.numpos = 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
301 for(t=0; t<mh->ordnum; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
302 { of.positions[of.numpos] = of.positions[t];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
303 poslookup[t] = of.numpos; // bug fix for FREAKY S3Ms
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
304 if(of.positions[t]<254) of.numpos++;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
305 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
306
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
307 if((paraptr=(UWORD *)_mm_malloc((of.numins+of.numpat)*sizeof(UWORD)))==NULL) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
308
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
309 // read the instrument+pattern parapointers
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
310 _mm_read_I_UWORDS(paraptr,of.numins+of.numpat,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
311
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
312
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
313 if(mh->pantable==252)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
314 { // read the panning table (ST 3.2 addition. See below for further
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
315 // portions of channel panning [past reampper]).
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
316 _mm_read_UBYTES(pan,32,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
317 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
318
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
319
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
320 // now is a good time to check if the header was too short :)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
321
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
322 if(feof(modfp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
323 { _mm_errno = MMERR_LOADING_HEADER;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
324 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
325 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
326
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
327
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
328 // ==============================================
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
329 // Load those darned Samples! (no insts in ST3)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
330
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
331 if(!AllocSamples()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
332
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
333 q = of.samples;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
334
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
335 for(t=0; t<of.numins; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
336 { S3MSAMPLE s;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
337
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
338 // seek to instrument position
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
339
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
340 _mm_fseek(modfp,((long)paraptr[t])<<4,SEEK_SET);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
341
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
342 // and load sample info
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
343
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
344 s.type =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
345 _mm_read_string(s.filename,12,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
346 s.memsegh =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
347 s.memsegl =_mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
348 s.length =_mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
349 s.loopbeg =_mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
350 s.loopend =_mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
351 s.volume =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
352 s.dsk =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
353 s.pack =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
354 s.flags =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
355 s.c2spd =_mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
356 _mm_read_UBYTES(s.unused,12,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
357 _mm_read_string(s.sampname,28,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
358 _mm_read_string(s.scrs,4,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
359
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
360 if(feof(modfp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
361 { _mm_errno = MMERR_LOADING_SAMPLEINFO;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
362 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
363 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
364
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
365 q->samplename = DupStr(s.sampname,28);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
366 q->speed = s.c2spd;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
367 q->length = s.length;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
368 q->loopstart = s.loopbeg;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
369 q->loopend = s.loopend;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
370 q->volume = s.volume;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
371 q->seekpos = (((long)s.memsegh)<<16|s.memsegl)<<4;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
372
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
373 if(s.flags&1) q->flags |= SF_LOOP;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
374 if(s.flags&4) q->flags |= SF_16BITS;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
375 if(mh->fileformat==1) q->flags |= SF_SIGNED;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
376
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
377 // DON'T load sample if it doesn't have the SCRS tag
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
378 if(memcmp(s.scrs,"SCRS",4)!=0) q->length = 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
379
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
380 q++;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
381 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
382
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
383 // ====================================
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
384 // Determine the number of channels actually used. (what ever happened
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
385 // to the concept of a single "numchn" variable, eh?!
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
386
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
387 of.numchn = 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
388 memset(remap,-1,32*sizeof(UBYTE));
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
389
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
390 for(t=0; t<of.numpat; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
391 { // seek to pattern position ( + 2 skip pattern length )
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
392 _mm_fseek(modfp,(long)((paraptr[of.numins+t])<<4)+2,SEEK_SET);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
393 if(S3M_GetNumChannels()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
394 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
395
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
396 // build the remap array
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
397 for(t=0; t<32; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
398 { if(remap[t]==0)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
399 { remap[t] = of.numchn;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
400 of.numchn++;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
401 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
402 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
403
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
404 // ============================================================
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
405 // set panning positions AFTER building remap chart!
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
406
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
407 for(t=0; t<32; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
408 { if((mh->channels[t]<16) && (remap[t]!=-1))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
409 { if(mh->channels[t]<8)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
410 of.panning[remap[t]] = 0x20; // 0x30 = std s3m val
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
411 else
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
412 of.panning[remap[t]] = 0xd0; // 0xc0 = std s3m val
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
413 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
414 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
415
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
416 if(mh->pantable==252)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
417 { // set panning positions according to panning table (new for st3.2)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
418 for(t=0; t<32; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
419 { if((pan[t]&0x20) && (mh->channels[t]<16) && (remap[t]!=-1))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
420 of.panning[remap[t]] = (pan[t]&0xf)<<4;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
421 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
422 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
423
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
424
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
425 // ==============================
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
426 // Load the pattern info now!
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
427
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
428 of.numtrk = of.numpat*of.numchn;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
429 if(!AllocTracks()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
430 if(!AllocPatterns()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
431
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
432 for(t=0; t<of.numpat; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
433 { // seek to pattern position ( + 2 skip pattern length )
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
434 _mm_fseek(modfp,(((long)paraptr[of.numins+t])<<4)+2,SEEK_SET);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
435 if(!S3M_ReadPattern()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
436 for(u=0; u<of.numchn; u++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
437 if(!(of.tracks[track++]=S3M_ConvertTrack(&s3mbuf[u*64]))) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
438 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
439
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
440 return 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
441 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
442
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
443
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
444 CHAR *S3M_LoadTitle(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
445 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
446 CHAR s[28];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
447
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
448 _mm_fseek(modfp,0,SEEK_SET);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
449 if(!fread(s,28,1,modfp)) return NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
450
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
451 return(DupStr(s,28));
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
452 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
453
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
454
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
455 MLOADER load_s3m =
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
456 { NULL,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
457 "S3M",
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
458 "S3M loader v0.3",
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
459 S3M_Init,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
460 S3M_Test,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
461 S3M_Load,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
462 S3M_Cleanup,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
463
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
464 S3M_LoadTitle
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
465 };
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
466