annotate playercode/load_xm.c @ 6:d14fd386d182

Initial entry of mikmod into the CVS tree.
author darius
date Fri, 23 Jan 1998 16:05:09 +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_XM.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 Fasttracker (XM) 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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
24 typedef struct XMHEADER
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
25 { CHAR id[17]; // ID text: 'Extended module: '
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
26 CHAR songname[21]; // Module name, padded with zeroes and 0x1a at the end
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
27 CHAR trackername[20]; // Tracker name
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
28 UWORD version; // (word) Version number, hi-byte major and low-byte minor
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
29 ULONG headersize; // Header size
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
30 UWORD songlength; // (word) Song length (in patten order table)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
31 UWORD restart; // (word) Restart position
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
32 UWORD numchn; // (word) Number of channels (2,4,6,8,10,...,32)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
33 UWORD numpat; // (word) Number of patterns (max 256)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
34 UWORD numins; // (word) Number of instruments (max 128)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
35 UWORD flags; // (word) Flags: bit 0: 0 = Amiga frequency table (see below) 1 = Linear frequency table
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
36 UWORD tempo; // (word) Default tempo
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
37 UWORD bpm; // (word) Default BPM
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
38 UBYTE orders[256]; // (byte) Pattern order table
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
39 } XMHEADER;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
40
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
41
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
42 typedef struct XMINSTHEADER
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
43 { ULONG size; // (dword) Instrument size
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
44 CHAR name[22]; // (char) Instrument name
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
45 UBYTE type; // (byte) Instrument type (always 0)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
46 UWORD numsmp; // (word) Number of samples in instrument
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
47 ULONG ssize; //
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
48 } XMINSTHEADER;
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
51 typedef struct XMPATCHHEADER
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
52 { UBYTE what[96]; // (byte) Sample number for all notes
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
53 UWORD volenv[24]; // (byte) Points for volume envelope
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
54 UWORD panenv[24]; // (byte) Points for panning envelope
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
55 UBYTE volpts; // (byte) Number of volume points
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
56 UBYTE panpts; // (byte) Number of panning points
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
57 UBYTE volsus; // (byte) Volume sustain point
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
58 UBYTE volbeg; // (byte) Volume loop start point
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
59 UBYTE volend; // (byte) Volume loop end point
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
60 UBYTE pansus; // (byte) Panning sustain point
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
61 UBYTE panbeg; // (byte) Panning loop start point
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
62 UBYTE panend; // (byte) Panning loop end point
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
63 UBYTE volflg; // (byte) Volume type: bit 0: On; 1: Sustain; 2: Loop
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
64 UBYTE panflg; // (byte) Panning type: bit 0: On; 1: Sustain; 2: Loop
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
65 UBYTE vibflg; // (byte) Vibrato type
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
66 UBYTE vibsweep; // (byte) Vibrato sweep
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
67 UBYTE vibdepth; // (byte) Vibrato depth
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
68 UBYTE vibrate; // (byte) Vibrato rate
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
69 UWORD volfade; // (word) Volume fadeout
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
70 UWORD reserved[11]; // (word) Reserved
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
71 } XMPATCHHEADER;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
72
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 typedef struct XMWAVHEADER
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
75 { ULONG length; // (dword) Sample length
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
76 ULONG loopstart; // (dword) Sample loop start
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
77 ULONG looplength; // (dword) Sample loop length
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
78 UBYTE volume; // (byte) Volume
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
79 SBYTE finetune; // (byte) Finetune (signed byte -128..+127)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
80 UBYTE type; // (byte) Type: Bit 0-1: 0 = No loop, 1 = Forward loop,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
81 // 2 = Ping-pong loop;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
82 // 4: 16-bit sampledata
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
83 UBYTE panning; // (byte) Panning (0-255)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
84 SBYTE relnote; // (byte) Relative note number (signed byte)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
85 UBYTE reserved; // (byte) Reserved
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
86 CHAR samplename[22]; // (char) Sample name
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 vibtype; // (byte) Vibrato type
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
89 UBYTE vibsweep; // (byte) Vibrato sweep
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
90 UBYTE vibdepth; // (byte) Vibrato depth
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
91 UBYTE vibrate; // (byte) Vibrato rate
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
92 } XMWAVHEADER;
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
95 typedef struct XMPATHEADE
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
96 { ULONG size; // (dword) Pattern header length
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
97 UBYTE packing; // (byte) Packing type (always 0)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
98 UWORD numrows; // (word) Number of rows in pattern (1..256)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
99 UWORD packsize; // (word) Packed patterndata size
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
100 } XMPATHEADER;
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 typedef struct MTMNOTE
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
103 { UBYTE a,b,c;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
104 } MTMNOTE;
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 typedef struct XMNOTE
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
108 { UBYTE note,ins,vol,eff,dat;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
109 }XMNOTE;
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 /**************************************************************************
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
112 **************************************************************************/
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
113
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
114 static XMNOTE *xmpat = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
115 static XMHEADER *mh = NULL;
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 BOOL XM_Test(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
118 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
119 UBYTE id[17];
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(!_mm_read_UBYTES(id,17,modfp)) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
122 if(!memcmp(id,"Extended Module: ",17)) return 1;
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
127 BOOL XM_Init(void)
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 if(!(mh=(XMHEADER *)_mm_calloc(1,sizeof(XMHEADER)))) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
130 return 1;
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
133
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
134 void XM_Cleanup(void)
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 if(mh!=NULL) free(mh);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
137 mh = NULL;
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
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 void XM_ReadNote(XMNOTE *n)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
142 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
143 UBYTE cmp;
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 memset(n,0,sizeof(XMNOTE));
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 cmp = _mm_read_UBYTE(modfp);
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(cmp&0x80)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
150 { if(cmp&1) n->note = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
151 if(cmp&2) n->ins = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
152 if(cmp&4) n->vol = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
153 if(cmp&8) n->eff = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
154 if(cmp&16) n->dat = _mm_read_UBYTE(modfp);
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 else
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
157 { n->note = cmp;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
158 n->ins = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
159 n->vol = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
160 n->eff = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
161 n->dat = _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 }
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 UBYTE *XM_Convert(XMNOTE *xmtrack,UWORD rows)
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 int t;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
169 UBYTE note,ins,vol,eff,dat;
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 UniReset();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
172
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
173 for(t=0; t<rows; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
174 { note = xmtrack->note;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
175 ins = xmtrack->ins;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
176 vol = xmtrack->vol;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
177 eff = xmtrack->eff;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
178 dat = xmtrack->dat;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
179
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
180 if(note!=0)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
181 { if(note==97)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
182 { UniWrite(UNI_KEYFADE);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
183 UniWrite(0);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
184 } else
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
185 UniNote(note-1);
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
188 if(ins!=0) UniInstrument(ins-1);
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 switch(vol>>4)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
191 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
192 case 0x6: // volslide down
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
193 if(vol&0xf)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
194 { UniWrite(UNI_XMEFFECTA);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
195 UniWrite(vol&0xf);
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 break;
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 case 0x7: // volslide up
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
200 if(vol&0xf)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
201 { UniWrite(UNI_XMEFFECTA);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
202 UniWrite(vol<<4);
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 break;
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 // volume-row fine volume slide is compatible with protracker
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
207 // EBx and EAx effects i.e. a zero nibble means DO NOT SLIDE, as
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
208 // opposed to 'take the last sliding value'.
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
209
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
210 case 0x8: // finevol down
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
211 UniPTEffect(0xe,0xb0 | (vol&0xf));
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
212 break;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
213
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
214 case 0x9: // finevol up
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
215 UniPTEffect(0xe,0xa0 | (vol&0xf));
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
216 break;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
217
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
218 case 0xa: // set vibrato speed
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
219 UniPTEffect(0x4,vol<<4);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
220 break;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
221
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
222 case 0xb: // vibrato
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
223 UniPTEffect(0x4,vol&0xf);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
224 break;
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 case 0xc: // set panning
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
227 UniPTEffect(0x8,vol<<4);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
228 break;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
229
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
230 case 0xd: // panning slide left
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
231 // only slide when data nibble not zero:
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
232
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
233 if(vol&0xf)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
234 { UniWrite(UNI_XMEFFECTP);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
235 UniWrite(vol&0xf);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
236 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
237 break;
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 case 0xe: // panning slide right
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
240 // only slide when data nibble not zero:
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 if(vol&0xf)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
243 { UniWrite(UNI_XMEFFECTP);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
244 UniWrite(vol<<4);
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 break;
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 case 0xf: // tone porta
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
249 UniPTEffect(0x3,vol<<4);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
250 break;
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 default:
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
253 if(vol>=0x10 && vol<=0x50)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
254 UniPTEffect(0xc,vol-0x10);
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
257 switch(eff)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
258 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
259 case 0x4: // Effect 4: Vibrato
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
260 UniWrite(UNI_XMEFFECT4);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
261 UniWrite(dat);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
262 break;
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 case 0xa:
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
265 UniWrite(UNI_XMEFFECTA);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
266 UniWrite(dat);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
267 break;
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 case 0xe:
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
270 switch(dat>>4)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
271 { case 0x1: // XM fine porta up
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
272 UniWrite(UNI_XMEFFECTE1);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
273 UniWrite(dat&0xf);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
274 break;
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 case 0x2: // XM fine porta down
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
277 UniWrite(UNI_XMEFFECTE2);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
278 UniWrite(dat&0xf);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
279 break;
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 case 0xa: // XM fine volume up
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
282 UniWrite(UNI_XMEFFECTEA);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
283 UniWrite(dat&0xf);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
284 break;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
285
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
286 case 0xb: // XM fine volume down
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
287 UniWrite(UNI_XMEFFECTEB);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
288 UniWrite(dat&0xf);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
289 break;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
290
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
291 default:
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
292 UniPTEffect(0x0e,dat);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
293 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
294 break;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
295
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
296 case 'G'-55: // G - set global volume
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
297 if(dat>64) dat = 64;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
298 UniWrite(UNI_XMEFFECTG);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
299 UniWrite(dat);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
300 break;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
301
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
302 case 'H'-55: // H - global volume slide
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
303 UniWrite(UNI_XMEFFECTH);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
304 UniWrite(dat);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
305 break;
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 case 'K'-55: // K - keyOff and KeyFade
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
308 UniWrite(UNI_KEYFADE);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
309 UniWrite(dat);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
310 break;
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 case 'L'-55: // L - set envelope position
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
313 UniWrite(UNI_XMEFFECTL);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
314 UniWrite(dat);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
315 break;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
316
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
317 case 'P'-55: // P - panning slide
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
318 UniWrite(UNI_XMEFFECTP);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
319 UniWrite(dat);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
320 break;
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 case 'R'-55: // R - multi retrig note
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
323 UniWrite(UNI_S3MEFFECTQ);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
324 UniWrite(dat);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
325 break;
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 case 'T'-55: // T - Tremor !! (== S3M effect I)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
328 UniWrite(UNI_S3MEFFECTI);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
329 UniWrite(dat);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
330 break;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
331
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
332 case 'X'-55:
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
333 if((dat>>4) == 1) // X1 - Extra Fine Porta up
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
334 { UniWrite(UNI_XMEFFECTX1);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
335 UniWrite(dat & 0xf);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
336 } else if((dat>>4) == 2) // X2 - Extra Fine Porta down
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
337 { UniWrite(UNI_XMEFFECTX2);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
338 UniWrite(dat & 0xf);
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 break;
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 default:
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
343 if(eff <= 0xf)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
344 { // Convert pattern jump from Dec to Hex
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
345 if(eff == 0xd)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
346 dat = (((dat&0xf0)>>4)*10)+(dat&0xf);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
347 UniPTEffect(eff,dat);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
348 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
349 break;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
350 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
351
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
352 UniNewline();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
353 xmtrack++;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
354 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
355 return UniDup();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
356 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
357
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
358
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 BOOL XM_Load(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
361 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
362 INSTRUMENT *d;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
363 SAMPLE *q;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
364 XMWAVHEADER *wh,*s;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
365 int t,u,v,p,numtrk;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
366 long next;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
367 ULONG nextwav[256];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
368 BOOL dummypat=0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
369
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
370 // try to read module header
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
371
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
372 _mm_read_string(mh->id,17,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
373 _mm_read_string(mh->songname,21,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
374 _mm_read_string(mh->trackername,20,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
375 mh->version =_mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
376 mh->headersize =_mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
377 mh->songlength =_mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
378 mh->restart =_mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
379 mh->numchn =_mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
380 mh->numpat =_mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
381 mh->numins =_mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
382 mh->flags =_mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
383 mh->tempo =_mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
384 mh->bpm =_mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
385 _mm_read_UBYTES(mh->orders,256,modfp);
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 if(feof(modfp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
388 { _mm_errno = MMERR_LOADING_HEADER;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
389 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
390 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
391
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
392 // set module variables
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
393 of.initspeed = mh->tempo;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
394 of.inittempo = mh->bpm;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
395 of.modtype = DupStr(mh->trackername,20);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
396 of.numchn = mh->numchn;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
397 of.numpat = mh->numpat;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
398 of.numtrk = (UWORD)of.numpat*of.numchn; // get number of channels
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
399 of.songname = DupStr(mh->songname,20); // make a cstr of songname
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
400 of.numpos = mh->songlength; // copy the songlength
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
401 of.reppos = mh->restart;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
402 of.numins = mh->numins;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
403 of.flags |= UF_XMPERIODS | UF_INST;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
404 if(mh->flags&1) of.flags |= UF_LINEAR;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
405
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
406 memset(of.chanvol,64,of.numchn); // store channel volumes
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
407
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
408 if(!AllocPositions(of.numpos+3)) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
409 for(t=0; t<of.numpos; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
410 of.positions[t] = mh->orders[t];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
411
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
412 /*
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
413 WHY THIS CODE HERE?? I CAN'T REMEMBER!
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 Well, I do know why, mikmak! Seems that FT2 doesn't always count blank
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
416 patterns AT ALL if they are at the END of the song. So, we have to check
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
417 for any patter numbers in the order list greater than the number of pat-
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
418 terns total. If one or more is found, we set it equal to the pattern total
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
419 and make a dummy pattern to accomidate for the discrepency!
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
420 */
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 for(t=0; t<of.numpos; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
423 { if(of.positions[t] > of.numpat)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
424 { of.positions[t] = of.numpat;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
425 dummypat = 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
426 }
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
429 if(dummypat) { of.numpat++; of.numtrk+=of.numchn; }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
430
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
431 if(!AllocTracks()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
432 if(!AllocPatterns()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
433
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
434 numtrk = 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
435 for(t=0; t<mh->numpat; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
436 { XMPATHEADER ph;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
437
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
438 ph.size =_mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
439 ph.packing =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
440 ph.numrows =_mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
441 ph.packsize =_mm_read_I_UWORD(modfp);
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 of.pattrows[t] = ph.numrows;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
444
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
445 // Gr8.. when packsize is 0, don't try to load a pattern.. it's empty.
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
446 // This bug was discovered thanks to Khyron's module..
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 if(!(xmpat=(XMNOTE *)_mm_calloc(ph.numrows*of.numchn,sizeof(XMNOTE)))) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
449
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
450 if(ph.packsize>0)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
451 { for(u=0; u<ph.numrows; u++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
452 { for(v=0; v<of.numchn; v++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
453 XM_ReadNote(&xmpat[(v*ph.numrows)+u]);
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 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
456
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
457 if(feof(modfp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
458 { _mm_errno = MMERR_LOADING_PATTERN;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
459 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
460 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
461
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
462 for(v=0; v<of.numchn; v++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
463 of.tracks[numtrk++] = XM_Convert(&xmpat[v*ph.numrows],ph.numrows);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
464
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
465 free(xmpat);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
466 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
467
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
468 if(dummypat)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
469 { of.pattrows[t] = 64;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
470 if(!(xmpat=(XMNOTE *)_mm_calloc(64*of.numchn,sizeof(XMNOTE)))) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
471 for(v=0; v<of.numchn; v++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
472 of.tracks[numtrk++] = XM_Convert(&xmpat[v*64],64);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
473 free(xmpat);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
474 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
475
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
476 if(!AllocInstruments()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
477 if((wh = (XMWAVHEADER *)_mm_calloc(256,sizeof(XMWAVHEADER))) == NULL) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
478 d = of.instruments;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
479 s = wh;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
480
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
481
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
482 for(t=0; t<of.numins; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
483 { XMINSTHEADER ih;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
484 int headend;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
485
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
486 memset(d->samplenumber,255,120);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
487
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
488 // read instrument header
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
489
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
490 headend = _mm_ftell(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
491 ih.size = _mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
492 headend += ih.size;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
493 _mm_read_string(ih.name, 22, modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
494 ih.type = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
495 ih.numsmp = _mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
496 d->insname = DupStr(ih.name,22);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
497
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
498 if(ih.size > 29)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
499 { ih.ssize = _mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
500 if(ih.numsmp > 0)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
501 { XMPATCHHEADER pth;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
502
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
503 _mm_read_UBYTES (pth.what, 96, modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
504 _mm_read_I_UWORDS (pth.volenv, 24, modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
505 _mm_read_I_UWORDS (pth.panenv, 24, modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
506 pth.volpts = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
507 pth.panpts = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
508 pth.volsus = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
509 pth.volbeg = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
510 pth.volend = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
511 pth.pansus = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
512 pth.panbeg = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
513 pth.panend = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
514 pth.volflg = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
515 pth.panflg = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
516 pth.vibflg = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
517 pth.vibsweep = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
518 pth.vibdepth = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
519 pth.vibrate = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
520 pth.volfade = _mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
521
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
522 // read the remainder of the header
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
523 for(u=headend-_mm_ftell(modfp); u; u--) _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
524
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
525 if(feof(modfp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
526 { _mm_errno = MMERR_LOADING_SAMPLEINFO;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
527 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
528 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
529
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
530 for(u=0; u<96; u++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
531 d->samplenumber[u] = pth.what[u] + of.numsmp;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
532
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
533 d->volfade = pth.volfade;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
534
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
535 memcpy(d->volenv,pth.volenv,24);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
536 if(pth.volflg & 1) d->volflg |= EF_ON;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
537 if(pth.volflg & 2) d->volflg |= EF_SUSTAIN;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
538 if(pth.volflg & 4) d->volflg |= EF_LOOP;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
539 d->volsusbeg = d->volsusend = pth.volsus;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
540 d->volbeg = pth.volbeg;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
541 d->volend = pth.volend;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
542 d->volpts = pth.volpts;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
543
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
544 // scale volume envelope:
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
545
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
546 for(p=0; p<12; p++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
547 d->volenv[p].val <<= 2;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
548
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
549 if((d->volflg & EF_ON) && (d->volpts < 2))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
550 d->volflg &= ~EF_ON;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
551
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
552 memcpy(d->panenv,pth.panenv,24);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
553 d->panflg = pth.panflg;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
554 d->pansusbeg = d->pansusend = pth.pansus;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
555 d->panbeg = pth.panbeg;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
556 d->panend = pth.panend;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
557 d->panpts = pth.panpts;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
558
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
559 // scale panning envelope:
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
560
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
561 for(p=0; p<12; p++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
562 d->panenv[p].val <<= 2;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
563 if((d->panflg & EF_ON) && (d->panpts < 2))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
564 d->panflg &= ~EF_ON;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
565
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
566 next = 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
567
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
568 // Samples are stored outside the instrument struct now, so we have
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
569 // to load them all into a temp area, count the of.numsmp along the
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
570 // way and then do an AllocSamples() and move everything over
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
571
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
572 for(u=0; u<ih.numsmp; u++,s++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
573 { s->length =_mm_read_I_ULONG (modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
574 s->loopstart =_mm_read_I_ULONG (modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
575 s->looplength =_mm_read_I_ULONG (modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
576 s->volume =_mm_read_UBYTE (modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
577 s->finetune =_mm_read_SBYTE (modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
578 s->type =_mm_read_UBYTE (modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
579 s->panning =_mm_read_UBYTE (modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
580 s->relnote =_mm_read_SBYTE (modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
581 s->vibtype = pth.vibflg;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
582 s->vibsweep = pth.vibsweep;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
583 s->vibdepth = pth.vibdepth*4;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
584 s->vibrate = pth.vibrate;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
585
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
586 s->reserved =_mm_read_UBYTE (modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
587 _mm_read_string(s->samplename, 22, modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
588
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
589 nextwav[of.numsmp+u] = next;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
590 next += s->length;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
591
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
592 if(feof(modfp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
593 { _mm_errno = MMERR_LOADING_SAMPLEINFO;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
594 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
595 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
596 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
597
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
598 for(u=0; u<ih.numsmp; u++) nextwav[of.numsmp++] += _mm_ftell(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
599 _mm_fseek(modfp,next,SEEK_CUR);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
600 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
601 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
602
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
603 d++;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
604 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
605
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
606 if(!AllocSamples()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
607 q = of.samples;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
608 s = wh;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
609
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
610 for(u=0; u<of.numsmp; u++,q++,s++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
611 { q->samplename = DupStr(s->samplename,22);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
612 q->length = s->length;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
613 q->loopstart = s->loopstart;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
614 q->loopend = s->loopstart+s->looplength;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
615 q->volume = s->volume;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
616 q->speed = s->finetune+128;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
617 q->panning = s->panning;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
618 q->seekpos = nextwav[u];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
619 q->vibtype = s->vibtype;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
620 q->vibsweep = s->vibsweep;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
621 q->vibdepth = s->vibdepth;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
622 q->vibrate = s->vibrate;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
623
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
624 if(s->type & 0x10)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
625 { q->length >>= 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
626 q->loopstart >>= 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
627 q->loopend >>= 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
628 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
629
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
630 q->flags|=SF_OWNPAN;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
631 if(s->type&0x3) q->flags|=SF_LOOP;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
632 if(s->type&0x2) q->flags|=SF_BIDI;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
633
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
634 if(s->type&0x10) q->flags|=SF_16BITS;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
635 q->flags|=SF_DELTA;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
636 q->flags|=SF_SIGNED;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
637 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
638
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
639 d = of.instruments;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
640 s = wh;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
641 for(u=0; u<of.numins; u++, d++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
642 { /*for(t=0; t<3; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
643 if((s[d->samplenumber[t]].relnote / 12) > )
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
644 { s[d->samplenumber[t]].relnote -= 12;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
645 of.samples[d->samplenumber[t]].speed <<= 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
646 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
647 */
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
648 for(t=0; t<96; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
649 d->samplenote[t] = (d->samplenumber[t]==of.numsmp) ? 255 : (t+s[d->samplenumber[t]].relnote);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
650 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
651
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
652 free(wh);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
653 return 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
654 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
655
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
656
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
657
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
658 CHAR *XM_LoadTitle(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
659 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
660 CHAR s[21];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
661
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
662 _mm_fseek(modfp,17,SEEK_SET);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
663 if(!fread(s,21,1,modfp)) return NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
664
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
665 return(DupStr(s,21));
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
666 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
667
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
668
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
669
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
670 MLOADER load_xm =
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
671 { NULL,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
672 "XM",
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
673 "Portable XM loader v0.5",
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
674 XM_Init,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
675 XM_Test,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
676 XM_Load,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
677 XM_Cleanup,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
678 XM_LoadTitle
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
679 };