annotate playercode/load_ult.c @ 9:990c9dadb348

Initial revision
author darius
date Fri, 23 Jan 1998 16:05:10 +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_ULT.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 Ultratracker (ULT) 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 #define ULTS_16BITS 4
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
22 #define ULTS_LOOP 8
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
23 #define ULTS_REVERSE 16
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
24
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
25
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
26 // Raw ULT header struct:
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
27
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
28 typedef struct ULTHEADER
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
29 { CHAR id[16];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
30 CHAR songtitle[32];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
31 UBYTE reserved;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
32 } ULTHEADER;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
33
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
34
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
35 // Raw ULT sampleinfo struct:
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
36
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
37 typedef struct ULTSAMPLE
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
38 { CHAR samplename[32];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
39 CHAR dosname[12];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
40 SLONG loopstart;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
41 SLONG loopend;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
42 SLONG sizestart;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
43 SLONG sizeend;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
44 UBYTE volume;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
45 UBYTE flags;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
46 SWORD finetune;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
47 } ULTSAMPLE;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
48
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
49
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
50 typedef struct ULTEVENT
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
51 { UBYTE note,sample,eff,dat1,dat2;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
52 } ULTEVENT;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
53
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 CHAR *ULT_Version[]=
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
56 { "Ultra Tracker V1.3",
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
57 "Ultra Tracker V1.4",
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
58 "Ultra Tracker V1.5",
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
59 "Ultra Tracker V1.6"
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
60 };
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
61
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
62
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
63 BOOL ULT_Test(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
64 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
65 CHAR id[16];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
66
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
67 if(!_mm_read_string(id,15,modfp)) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
68 return(!strncmp(id,"MAS_UTrack_V00",14));
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
69 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
70
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
71
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
72 BOOL ULT_Init(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
73 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
74 return 1;
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 void ULT_Cleanup(void)
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 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
81
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
82 ULTEVENT ev;
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
85
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
86 int ReadUltEvent(ULTEVENT *event)
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 UBYTE flag,rep=1;
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 flag = _mm_read_UBYTE(modfp);
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 if(flag==0xfc)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
93 { rep = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
94 event->note =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
95 } else
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
96 event->note = flag;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
97
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
98 event->sample =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
99 event->eff =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
100 event->dat1 =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
101 event->dat2 =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
102
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
103 return rep;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
104 }
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
107 BOOL ULT_Load(void)
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 int t,u,tracks=0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
110 SAMPLE *q;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
111 ULTSAMPLE s;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
112 ULTHEADER mh;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
113 UBYTE nos,noc,nop;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
114
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
115 // try to read module header
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
116
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
117 _mm_read_string(mh.id,15,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
118 _mm_read_string(mh.songtitle,32,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
119 mh.reserved = _mm_read_UBYTE(modfp);
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 if(feof(modfp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
122 { _mm_errno = MMERR_LOADING_HEADER;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
123 return 0;
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
126 if(mh.id[14]<'1' || mh.id[14]>'4')
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
127 { _mm_errno = MMERR_NOT_A_MODULE;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
128 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
129 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
130
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
131 of.modtype = strdup(ULT_Version[mh.id[14]-'1']);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
132 of.initspeed = 6;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
133 of.inittempo = 125;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
134
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
135 // read songtext
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 if(!ReadComment((UWORD)mh.reserved*32)) return 0;
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 nos = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
140
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
141 if(feof(modfp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
142 { _mm_errno = MMERR_LOADING_HEADER;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
143 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
144 }
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 of.songname = DupStr(mh.songtitle,32);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
147 of.numins = nos;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
148
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
149 if(!AllocSamples()) return 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 q = of.samples;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
152
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
153 for(t=0; t<nos; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
154 { // try to read sample info
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 _mm_read_string(s.samplename,32,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
157 _mm_read_string(s.dosname,12,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
158 s.loopstart =_mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
159 s.loopend =_mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
160 s.sizestart =_mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
161 s.sizeend =_mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
162 s.volume =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
163 s.flags =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
164 s.finetune =_mm_read_I_SWORD(modfp);
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 if(feof(modfp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
167 { _mm_errno = MMERR_LOADING_SAMPLEINFO;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
168 return 0;
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
171 q->samplename = DupStr(s.samplename,32);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
172 q->speed = 8363;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
173
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
174 if(mh.id[14]>='4')
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
175 { _mm_read_I_UWORD(modfp); // read 1.6 extra info(??) word
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
176 q->speed=s.finetune;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
177 }
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 q->length = s.sizeend-s.sizestart;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
180 q->volume = s.volume>>2;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
181 q->loopstart = s.loopstart;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
182 q->loopend = s.loopend;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
183
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
184 q->flags = SF_SIGNED;
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 if(s.flags&ULTS_LOOP)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
187 q->flags|=SF_LOOP;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
188
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
189 if(s.flags&ULTS_16BITS)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
190 { q->flags|=SF_16BITS;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
191 q->loopstart>>=1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
192 q->loopend>>=1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
193 }
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 q++;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
196 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
197
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
198 if(!AllocPositions(256)) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
199 for(t=0; t<256; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
200 of.positions[t] = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
201 for(t=0; t<256; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
202 if(of.positions[t]==255) break;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
203
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
204 of.numpos = t;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
205
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
206 noc = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
207 nop = _mm_read_UBYTE(modfp);
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 of.numchn = noc+1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
210 of.numpat = nop+1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
211 of.numtrk = of.numchn*of.numpat;
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 if(!AllocTracks()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
214 if(!AllocPatterns()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
215
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
216 for(u=0; u<of.numchn; u++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
217 { for(t=0; t<of.numpat; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
218 of.patterns[(t*of.numchn)+u]=tracks++;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
219 }
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 // read pan position table for v1.5 and higher
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
222
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
223 if(mh.id[14]>='3')
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
224 for(t=0; t<of.numchn; t++) of.panning[t]=_mm_read_UBYTE(modfp)<<4;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
225
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
226 for(t=0; t<of.numtrk; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
227 { int rep,s,done;
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 UniReset();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
230 done=0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
231
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
232 while(done<64)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
233 { rep=ReadUltEvent(&ev);
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(feof(modfp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
236 { _mm_errno = MMERR_LOADING_TRACK;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
237 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
238 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
239
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
240 for(s=0; s<rep; s++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
241 { UBYTE eff;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
242
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
243 if(ev.sample) UniInstrument(ev.sample-1);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
244 if(ev.note) UniNote(ev.note+23);
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 eff = ev.eff>>4;
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 // ULT panning effect fixed by Alexander Kerkhove :
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
249
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
250 if(eff==0xc) UniPTEffect(eff,ev.dat2>>2);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
251 else if(eff==0xb) UniPTEffect(8,ev.dat2*0xf);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
252 else UniPTEffect(eff,ev.dat2);
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 eff=ev.eff&0xf;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
255
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
256 if(eff==0xc) UniPTEffect(eff,ev.dat1>>2);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
257 else if(eff==0xb) UniPTEffect(8,ev.dat1*0xf);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
258 else UniPTEffect(eff,ev.dat1);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
259
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
260 UniNewline();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
261 done++;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
262 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
263 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
264 if(!(of.tracks[t]=UniDup())) return 0;
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
267 return 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
268 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
269
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
270
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
271 CHAR *ULT_LoadTitle(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
272 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
273 CHAR s[32];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
274
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
275 _mm_fseek(modfp,15,SEEK_SET);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
276 if(!fread(s,32,1,modfp)) return NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
277
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
278 return(DupStr(s,32));
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
282 MLOADER load_ult =
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
283 { NULL,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
284 "ULT",
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
285 "Portable ULT loader v0.1",
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
286 ULT_Init,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
287 ULT_Test,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
288 ULT_Load,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
289 ULT_Cleanup,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
290 ULT_LoadTitle
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
291 };
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
292