comparison playercode/load_uni.c @ 4:5d614bcc4287

Initial entry of mikmod into the CVS tree.
author darius
date Fri, 23 Jan 1998 16:05:08 +0000
parents
children
comparison
equal deleted inserted replaced
3:71e20a32bd84 4:5d614bcc4287
1 /*
2
3 Name: LOAD_UNI.C
4
5 Description:
6 UNIMOD (mikmod's internal format) module loader.
7 Currently only supports UniMOD 06 - the internal format for MikMod 3.0.
8
9 Portability:
10 All systems - all compilers (hopefully)
11
12 */
13
14 #include <string.h>
15 #include "mikmod.h"
16
17
18 BOOL UNI_Test(void)
19 {
20 UBYTE id[4];
21
22 _mm_read_UBYTES(id,4,modfp);
23 if(!memcmp(id, "UN06", 4)) return 1;
24
25 return 0;
26 }
27
28
29 BOOL UNI_Init(void)
30 {
31 return 1;
32 }
33
34
35 void UNI_Cleanup(void)
36 {
37 }
38
39
40 UBYTE *TrkRead(void)
41 {
42 UBYTE *t;
43 UWORD len;
44
45 len = _mm_read_M_UWORD(modfp);
46 t = (UBYTE *)malloc(len);
47 _mm_read_UBYTES(t,len,modfp);
48
49 return t;
50 }
51
52
53 BOOL UNI_Load(void)
54 {
55 int t,v,w;
56 INSTRUMENT *i;
57 SAMPLE *s;
58
59 // UNI format version 3.0 (#6)
60
61 of.modtype = strdup("MikMod UniFormat 3.0");
62
63 _mm_fseek(modfp,5,SEEK_SET); // skip the header
64
65 of.flags = _mm_read_M_UWORD(modfp);
66 of.numchn = _mm_read_UBYTE(modfp);
67 of.numvoices = _mm_read_UBYTE(modfp);
68 of.numpos = _mm_read_M_UWORD(modfp);
69 of.numpat = _mm_read_M_UWORD(modfp);
70 of.numtrk = _mm_read_M_UWORD(modfp);
71 of.numins = _mm_read_M_UWORD(modfp);
72 of.numsmp = _mm_read_M_UWORD(modfp);
73 of.reppos = _mm_read_M_UWORD(modfp);
74 of.initspeed = _mm_read_UBYTE(modfp);
75 of.inittempo = _mm_read_UBYTE(modfp);
76 of.initvolume = _mm_read_UBYTE(modfp);
77
78 if(feof(modfp))
79 { _mm_errno = MMERR_LOADING_HEADER;
80 return 0;
81 }
82
83 of.songname = StringRead(modfp);
84 of.composer = StringRead(modfp);
85 of.comment = StringRead(modfp);
86
87 if(feof(modfp))
88 { _mm_errno = MMERR_LOADING_HEADER;
89 return 0;
90 }
91
92 if(!AllocSamples()) return 0;
93 if(!AllocTracks()) return 0;
94 if(!AllocPatterns()) return 0;
95 if(!AllocPositions(of.numpos)) return 0;
96
97 _mm_read_UBYTES(of.positions,of.numpos,modfp);
98 _mm_read_M_UWORDS(of.panning,of.numchn,modfp);
99 _mm_read_UBYTES(of.chanvol,of.numchn,modfp);
100
101
102 // Load sample headers
103
104 s = of.samples;
105 for(v=0; v<of.numsmp; v++, s++)
106 { s->flags = _mm_read_M_UWORD(modfp);
107 s->speed = _mm_read_M_ULONG(modfp);
108 s->volume = _mm_read_UBYTE(modfp);
109 s->panning = _mm_read_M_UWORD(modfp);
110 s->length = _mm_read_M_ULONG(modfp);
111 s->loopstart = _mm_read_M_ULONG(modfp);
112 s->loopend = _mm_read_M_ULONG(modfp);
113 s->susbegin = _mm_read_M_ULONG(modfp);
114 s->susend = _mm_read_M_ULONG(modfp);
115
116 s->globvol = _mm_read_UBYTE(modfp);
117 s->vibflags = _mm_read_UBYTE(modfp);
118 s->vibtype = _mm_read_UBYTE(modfp);
119 s->vibsweep = _mm_read_UBYTE(modfp);
120 s->vibdepth = _mm_read_UBYTE(modfp);
121 s->vibrate = _mm_read_UBYTE(modfp);
122 s->samplename = StringRead(modfp);
123
124 if(feof(modfp))
125 { _mm_errno = MMERR_LOADING_HEADER;
126 return 0;
127 }
128 }
129
130 // Load instruments
131
132 if(of.flags & UF_INST)
133 { if(!AllocInstruments()) return 0;
134 i = of.instruments;
135
136 for(v=0; v<of.numins; v++, i++)
137 { i->flags = _mm_read_UBYTE(modfp);
138 i->nnatype = _mm_read_UBYTE(modfp);
139 i->dca = _mm_read_UBYTE(modfp);
140 i->dct = _mm_read_UBYTE(modfp);
141 i->globvol = _mm_read_UBYTE(modfp);
142 i->panning = _mm_read_M_UWORD(modfp);
143 i->pitpansep = _mm_read_UBYTE(modfp);
144 i->pitpancenter = _mm_read_UBYTE(modfp);
145 i->rvolvar = _mm_read_UBYTE(modfp);
146 i->rpanvar = _mm_read_UBYTE(modfp);
147
148 i->volfade = _mm_read_M_UWORD(modfp);
149
150 i->volflg = _mm_read_UBYTE(modfp);
151 i->volpts = _mm_read_UBYTE(modfp);
152 i->volsusbeg = _mm_read_UBYTE(modfp);
153 i->volsusend = _mm_read_UBYTE(modfp);
154 i->volbeg = _mm_read_UBYTE(modfp);
155 i->volend = _mm_read_UBYTE(modfp);
156
157 for(w=0; w<i->volpts; w++)
158 { i->volenv[w].pos = _mm_read_M_SWORD(modfp);
159 i->volenv[w].val = _mm_read_M_SWORD(modfp);
160 }
161
162 i->panflg = _mm_read_UBYTE(modfp);
163 i->panpts = _mm_read_UBYTE(modfp);
164 i->pansusbeg = _mm_read_UBYTE(modfp);
165 i->pansusend = _mm_read_UBYTE(modfp);
166 i->panbeg = _mm_read_UBYTE(modfp);
167 i->panend = _mm_read_UBYTE(modfp);
168
169 for(w=0; w<i->panpts; w++)
170 { i->panenv[w].pos = _mm_read_M_SWORD(modfp);
171 i->panenv[w].val = _mm_read_M_SWORD(modfp);
172 }
173
174 i->pitflg = _mm_read_UBYTE(modfp);
175 i->pitpts = _mm_read_UBYTE(modfp);
176 i->pitsusbeg = _mm_read_UBYTE(modfp);
177 i->pitsusend = _mm_read_UBYTE(modfp);
178 i->pitbeg = _mm_read_UBYTE(modfp);
179 i->pitend = _mm_read_UBYTE(modfp);
180
181 for(w=0; w<i->pitpts; w++)
182 { i->pitenv[w].pos = _mm_read_M_SWORD(modfp);
183 i->pitenv[w].val = _mm_read_M_SWORD(modfp);
184 }
185
186 _mm_read_UBYTES(i->samplenumber, 120, modfp);
187 _mm_read_UBYTES(i->samplenote, 120, modfp);
188
189 i->insname = StringRead(modfp);
190
191 if(feof(modfp))
192 { _mm_errno = MMERR_LOADING_HEADER;
193 return 0;
194 }
195 }
196 }
197
198 // Read patterns
199
200 _mm_read_M_UWORDS(of.pattrows,of.numpat,modfp);
201 _mm_read_M_UWORDS(of.patterns,of.numpat*of.numchn,modfp);
202
203 // Read tracks
204
205 for(t=0; t<of.numtrk; t++)
206 of.tracks[t] = TrkRead();
207
208 return 1;
209 }
210
211
212 CHAR *UNI_LoadTitle(void)
213 {
214 _mm_fseek(modfp,24,SEEK_SET);
215 return(StringRead(modfp));
216 }
217
218
219 MLOADER load_uni =
220 { NULL,
221 "UNI",
222 "Portable UniFormat 3.0 Loader",
223 UNI_Init,
224 UNI_Test,
225 UNI_Load,
226 UNI_Cleanup,
227 UNI_LoadTitle
228 };
229