annotate playercode/load_it.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_IT.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 ImpulseTracker (IT) 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 Copyright 1997 by Jake Stine and Divine Entertainment
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
12
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
13 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
14 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
15 more information on contacting the author).
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
18 #include <string.h>
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
19 #include "mikmod.h"
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 ITNOTE
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
25 { UBYTE note,ins,volpan,cmd,inf;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
26 } ITNOTE;
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 UBYTE *IT_ConvertTrack(ITNOTE *tr,UWORD numrows);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
29
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
30
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
31 // Raw IT header struct:
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
32
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
33 typedef struct ITHEADER
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
34 { CHAR songname[26];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
35 UBYTE blank01[2];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
36 UWORD ordnum;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
37 UWORD insnum;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
38 UWORD smpnum;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
39 UWORD patnum;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
40 UWORD cwt; // Created with tracker (y.xx = 0x0yxx)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
41 UWORD cmwt; // Compatable with tracker ver > than val.
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
42 UWORD flags;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
43 UWORD special; // bit 0 set = song message attached
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
44 UBYTE globvol;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
45 UBYTE mixvol; // mixing volume [ignored]
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
46 UBYTE initspeed;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
47 UBYTE inittempo;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
48 UBYTE pansep; // panning separation between channels
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
49 UBYTE zerobyte;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
50 UWORD msglength;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
51 ULONG msgoffset;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
52 UBYTE blank02[4];
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 UBYTE pantable[64];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
55 UBYTE voltable[64];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
56 } ITHEADER;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
57
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
58
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
59 // Raw IT sampleinfo struct:
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 typedef struct ITSAMPLE
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
62 { CHAR filename[12];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
63 UBYTE zerobyte;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
64 UBYTE globvol;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
65 UBYTE flag;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
66 UBYTE volume;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
67 UBYTE panning;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
68 CHAR sampname[28];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
69 UWORD convert; // sample conversion flag
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
70 ULONG length;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
71 ULONG loopbeg;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
72 ULONG loopend;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
73 ULONG c5spd;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
74 ULONG susbegin;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
75 ULONG susend;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
76 ULONG sampoffset;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
77 UBYTE vibspeed;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
78 UBYTE vibdepth;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
79 UBYTE vibrate;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
80 UBYTE vibwave; // 0 = sine; 1 = rampdown; 2 = square; 3 = random (speed ignored)
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 UBYTE noteindex; // for converting c5spd to finetune
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
83 } ITSAMPLE;
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 typedef struct ITINSTHEADER
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
87 { ULONG size; // (dword) Instrument size
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
88 CHAR filename[12]; // (char) Instrument filename
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
89 UBYTE zerobyte; // (byte) Instrument type (always 0)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
90 UBYTE volflg;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
91 UBYTE volpts;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
92 UBYTE volbeg; // (byte) Volume loop start (node)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
93 UBYTE volend; // (byte) Volume loop end (node)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
94 UBYTE volsusbeg; // (byte) Volume sustain begin (node)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
95 UBYTE volsusend; // (byte) Volume Sustain end (node)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
96 UBYTE panflg;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
97 UBYTE panpts;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
98 UBYTE panbeg; // (byte) channel loop start (node)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
99 UBYTE panend; // (byte) channel loop end (node)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
100 UBYTE pansusbeg; // (byte) cahnnel sustain begin (node)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
101 UBYTE pansusend; // (byte) channel Sustain end (node)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
102 UBYTE pitflg;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
103 UBYTE pitpts;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
104 UBYTE pitbeg; // (byte) pitch loop start (node)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
105 UBYTE pitend; // (byte) pitch loop end (node)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
106 UBYTE pitsusbeg; // (byte) pitch sustain begin (node)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
107 UBYTE pitsusend; // (byte) pitch Sustain end (node)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
108 UWORD blank;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
109 UBYTE globvol;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
110 UBYTE chanpan;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
111 UWORD fadeout; // Envelope end / NNA volume fadeout
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
112 UBYTE dnc; // Duplicate note check
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
113 UBYTE dca; // Duplicate check action
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
114 UBYTE dct; // Duplicate check type
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
115 UBYTE nna; // New Note Action [0,1,2,3]
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
116 UWORD trkvers; // tracker version used to save [in files only]
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
117 UBYTE ppsep; // Pitch-pan Separation
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
118 UBYTE ppcenter; // Pitch-pan Center
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
119 UBYTE rvolvar; // random volume varations
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
120 UBYTE rpanvar; // random panning varations
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
121 UWORD numsmp; // Number of samples in instrument [in files only]
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
122 CHAR name[26]; // Instrument name
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
123 UBYTE blank01[6];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
124 UWORD samptable[120]; // sample for each note [note / samp pairs]
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 UBYTE volenv[200]; // volume envelope (IT 1.x stuff)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
127 UBYTE oldvoltick[25]; // volume tick position (IT 1.x stuff)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
128 UBYTE volnode[25]; // aplitude of volume nodes
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
129 UWORD voltick[25]; // tick value of volume nodes
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
130 SBYTE pannode[25]; // panenv - node points
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
131 UWORD pantick[25]; // tick value of panning nodes
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
132 SBYTE pitnode[25]; // pitchenv - node points
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
133 UWORD pittick[25]; // tick value of pitch nodes
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
134 } ITINSTHEADER;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
135
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
136
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
137 /**************************************************************************
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 extern SBYTE remap[64]; // for removing empty channels
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
141 extern UBYTE *poslookup; // S3M/IT fix - removing blank patterns needs a
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
142 // lookup table to fix position-jump commands
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
143 static ULONG *paraptr = NULL; // parapointer array (see IT docs)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
144 static ITHEADER *mh = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
145 static ITNOTE *itpat = NULL; // allocate to space for one full pattern
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
146 static UBYTE *mask = NULL; // arrays allocated to 64 elements and used for
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
147 static ITNOTE *last = NULL; // uncompressing IT's pattern information
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
148 static int numtrk = 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
149 static int old_effect; // if set, use S3M old-effects stuffs
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
150 static int *noteindex;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
151
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
152 CHAR IT_Version[] = "ImpulseTracker x.xx";
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
153
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
154
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
155 BOOL IT_Test(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
156 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
157 UBYTE id[4];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
158
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
159 if(!_mm_read_UBYTES(id,4,modfp)) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
160 if(!memcmp(id,"IMPM",4)) return 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
161 return 0;
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 BOOL IT_Init(void)
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((mh=(ITHEADER *)_mm_calloc(1,sizeof(ITHEADER)))==NULL) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
167 if((poslookup=(UBYTE *)_mm_malloc(256*sizeof(UBYTE)))==NULL) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
168 if((itpat=(ITNOTE *)_mm_malloc(200*64*sizeof(ITNOTE)))==NULL) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
169 if((mask=(UBYTE *)_mm_malloc(64*sizeof(UBYTE)))==NULL) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
170 if((last=(ITNOTE *)_mm_malloc(64*sizeof(ITNOTE)))==NULL) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
171
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
172 return 1;
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
175 void IT_Cleanup(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
176 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
177 if(mh!=NULL) free(mh);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
178 if(poslookup!=NULL) free(poslookup);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
179 if(itpat!=NULL) free(itpat);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
180 if(mask!=NULL) free(mask);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
181 if(last!=NULL) free(last);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
182 if(paraptr!=NULL) free(paraptr);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
183 if(noteindex!=NULL) free(noteindex);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
184
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
185 mh = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
186 poslookup = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
187 itpat = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
188 mask = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
189 last = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
190 paraptr = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
191 noteindex = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
192 }
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 BOOL IT_GetNumChannels(UWORD patrows)
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 // Because so many IT files have 64 channels as the set number used, but really
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
198 // only use far less (usually 8 to 12 still), I had to make this function,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
199 // which determines the number of channels that are actually USED by a pattern.
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
200 //
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
201 // For every channel that's used, it sets the appropriate array entry of the
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
202 // global varialbe 'isused'
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 // NOTE: You must first seek to the file location of the pattern before calling
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
205 // this procedure.
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
206 // Returns 1 on error
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
207 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
208 int row=0,flag,ch;
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 do
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
211 { flag = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
212 if(flag == EOF)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
213 { _mm_errno = MMERR_LOADING_PATTERN;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
214 return 1;
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
217 if(flag == 0)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
218 { row++;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
219 } else
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
220 { ch = (flag-1) & 63;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
221 remap[ch] = 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
222 if(flag & 128) mask[ch] = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
223 if(mask[ch] & 1) _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
224 if(mask[ch] & 2) _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
225 if(mask[ch] & 4) _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
226 if(mask[ch] & 8) { _mm_read_UBYTE(modfp); _mm_read_UBYTE(modfp); }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
227 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
228 } while(row < patrows);
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 return 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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
233
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
234 BOOL IT_ReadPattern(UWORD patrows)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
235 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
236 int blah;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
237 int row=0,flag,ch;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
238 ITNOTE *itt = itpat, dummy,*n,*l;
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 memset(itt,255,patrows*of.numchn*sizeof(ITNOTE));
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 do
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
243 { flag = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
244 if(feof(modfp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
245 { _mm_errno = MMERR_LOADING_PATTERN;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
246 return 0;
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 if(flag == 0)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
249 { itt = &itt[of.numchn];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
250 row++;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
251 } else
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
252 { ch = remap[(flag-1) & 63];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
253 if(ch != -1)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
254 { n = &itt[ch];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
255 l = &last[ch];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
256 } else
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
257 { n = l = &dummy; }
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 if(flag & 128) mask[ch] = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
260 if(mask[ch] & 1) if((l->note = n->note = _mm_read_UBYTE(modfp)) == 255)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
261 { l->note = n->note = 253; }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
262 if(mask[ch] & 2) l->ins = n->ins = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
263 if(mask[ch] & 4) l->volpan = n->volpan = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
264 if(mask[ch] & 8) { l->cmd = n->cmd = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
265 l->inf = n->inf = _mm_read_UBYTE(modfp); }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
266 if(mask[ch] & 16) n->note = l->note;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
267 if(mask[ch] & 32) n->ins = l->ins;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
268 if(mask[ch] & 64) n->volpan = l->volpan;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
269 if(mask[ch] & 128) { n->cmd = l->cmd;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
270 n->inf = l->inf; }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
271 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
272 } while(row < patrows);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
273
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
274 for(blah=0; blah<of.numchn; blah++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
275 of.tracks[numtrk++] = IT_ConvertTrack(&itpat[blah],patrows);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
276
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
277 return 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
278 }
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 void S3MIT_ProcessCmd(UBYTE cmd, UBYTE inf, BOOL oldeffect);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
282
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
283 // table for porta-to-note command within volume/panning column
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
284 static UBYTE portatable[] = "1, 4, 8, 16, 32, 64, 96, 128, 255";
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 UBYTE *IT_ConvertTrack(ITNOTE *tr, UWORD numrows)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
287 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
288 int t;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
289
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
290 UBYTE note,ins,volpan;
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 UniReset();
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 for(t=0; t<numrows; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
295 { note = tr[t*of.numchn].note;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
296 ins = tr[t*of.numchn].ins;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
297 volpan = tr[t*of.numchn].volpan;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
298
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
299 if(note!=255)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
300 { if(note==253)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
301 UniWrite(UNI_KEYOFF);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
302 else if(note==254)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
303 UniPTEffect(0xc,0); // <- note cut command
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
304 else
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
305 UniNote(note);
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
308 if((ins != 0) && (ins < 100)) UniInstrument(ins-1);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
309
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
310 // process volume / panning column
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
311 // volume / panning effects do NOT all share the same memory address
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
312 // yet. That requires more work than I care to apply at the moment ;)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
313
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
314 if(volpan<=64)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
315 { UniVolEffect(VOL_VOLUME,volpan);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
316 } else if((volpan>=65) && (volpan<=74)) // fine volume slide up (65-74)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
317 { UniVolEffect(VOL_VOLSLIDE,0x0f + ((volpan-65)<<4));
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
318 } else if((volpan>=75) && (volpan<=84)) // fine volume slide down (75-84)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
319 { UniVolEffect(VOL_VOLSLIDE,0xf0 + (volpan-75));
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
320 } else if((volpan>=85) && (volpan<=94)) // volume slide up (85-94)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
321 { UniVolEffect(VOL_VOLSLIDE,((volpan-85)<<4));
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
322 } else if((volpan>=95) && (volpan<=104)) // volume slide down (95-104)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
323 { UniVolEffect(VOL_VOLSLIDE,(volpan-95));
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
324 } else if((volpan>=105) && (volpan<=114)) // pitch slide up (105-114)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
325 { UniVolEffect(VOL_PITCHSLIDEDN,((volpan-105)<<4));
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
326 } else if((volpan>=115) && (volpan<=124)) // pitch slide down (115-124)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
327 { UniVolEffect(VOL_PITCHSLIDEUP,(volpan-115));
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
328 } else if((volpan>=128) && (volpan<=192))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
329 { UniVolEffect(VOL_PANNING,((volpan-128) == 64) ? 255 : ((volpan-128) << 2));
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
330 } else if((volpan>=193) && (volpan<=202)) // portamento to note
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
331 { UniVolEffect(VOL_PORTAMENTO,portatable[volpan-193]);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
332 } else if((volpan>=203) && (volpan<=212)) // vibrato
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
333 { UniVolEffect(VOL_VIBRATO,(volpan-203));
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
334 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
335
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
336 S3MIT_ProcessCmd(tr[t*of.numchn].cmd,tr[t*of.numchn].inf,old_effect);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
337
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
338 UniNewline();
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 return UniDup();
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
343
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
344 int cvt_c5spd_to_finetune(ULONG c5spd, int sampnum)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
345 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
346 int ctmp=0,tmp,note=1,finetune=0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
347
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
348 c5spd/=2;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
349
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
350 do
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
351 { tmp = getfrequency(of.flags,getlinearperiod(note,0));
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
352 if(tmp >= c5spd) break;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
353 ctmp = tmp;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
354 note++;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
355 } while(1);
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 if(tmp != c5spd)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
358 { if((tmp-c5spd) < (c5spd-ctmp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
359 while(tmp>c5spd) tmp = getfrequency(of.flags,getlinearperiod(note,--finetune));
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
360 else
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
361 { note--;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
362 while(ctmp<c5spd) ctmp = getfrequency(of.flags,getlinearperiod(note,++finetune));
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
363 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
364 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
365
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
366 noteindex[sampnum] = note-48;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
367 return finetune;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
368 }
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
371 BOOL IT_Load(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
372 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
373 int t,u,lp;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
374 INSTRUMENT *d;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
375 SAMPLE *q;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
376
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
377 numtrk = 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
378
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
379 // try to read module header
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
380
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
381 _mm_read_I_ULONG(modfp); // kill the 4 byte header
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
382 _mm_read_string(mh->songname,26,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
383 _mm_read_UBYTES(mh->blank01,2,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
384 mh->ordnum =_mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
385 mh->insnum =_mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
386 mh->smpnum =_mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
387 mh->patnum =_mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
388 mh->cwt =_mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
389 mh->cmwt =_mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
390 mh->flags =_mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
391 mh->special =_mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
392
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
393 mh->globvol =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
394 mh->mixvol =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
395 mh->initspeed =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
396 mh->inittempo =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
397 mh->pansep =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
398 mh->zerobyte =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
399 mh->msglength =_mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
400 mh->msgoffset =_mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
401 _mm_read_UBYTES(mh->blank02,4,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
402 _mm_read_UBYTES(mh->pantable,64,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
403 _mm_read_UBYTES(mh->voltable,64,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
404
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
405 if(feof(modfp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
406 { _mm_errno = MMERR_LOADING_HEADER;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
407 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
408 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
409
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
410 // set module variables
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 of.modtype = strdup(IT_Version);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
413 of.modtype[15] = (mh->cwt >> 8) + 0x30;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
414 of.modtype[17] = ((mh->cwt >> 4) & 0xf) + 0x30;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
415 of.modtype[18] = ((mh->cwt) & 0xf) + 0x30;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
416 of.songname = DupStr(mh->songname,26); // make a cstr of songname
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
417 of.reppos = 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
418 of.numpat = mh->patnum;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
419 of.numins = mh->insnum;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
420 of.numsmp = mh->smpnum;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
421 of.initspeed = mh->initspeed;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
422 of.inittempo = mh->inittempo;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
423 of.initvolume = mh->globvol;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
424
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
425 old_effect = 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
426 if(mh->flags & 8) { of.flags |= (UF_XMPERIODS | UF_LINEAR); old_effect |= 2; }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
427 if((mh->cwt >= 0x106) && (mh->flags & 16)) old_effect |= 1;
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 // set panning positions
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
430 for(t=0; t<64; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
431 { if(mh->pantable[t] < 64) of.panning[t] = mh->pantable[t] << 2;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
432 else if(mh->pantable[t]==64) of.panning[t] = 255;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
433 else if(mh->pantable[t]==100) of.panning[t] = PAN_SURROUND;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
434 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
435
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
436 // set channel volumes
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
437 memcpy(of.chanvol,mh->voltable,64);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
438
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
439 // read the order data
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
440 if(!AllocPositions(mh->ordnum)) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
441
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
442 for(t=0; t<mh->ordnum; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
443 of.positions[t] = _mm_read_UBYTE(modfp);
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 if(feof(modfp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
446 { _mm_errno = MMERR_LOADING_HEADER;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
447 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
448 }
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 of.numpos = 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
451 for(t=0; t<mh->ordnum; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
452 { of.positions[of.numpos] = of.positions[t];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
453 poslookup[t] = of.numpos; // bug fix for FREAKY S3Ms / ITs
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
454 if(of.positions[t]<254) of.numpos++;
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((paraptr=(ULONG *)_mm_malloc((mh->insnum+mh->smpnum+of.numpat)*sizeof(ULONG))) == NULL) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
458
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
459 // read the instrument, sample, and pattern parapointers
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
460 _mm_read_I_ULONGS(paraptr,mh->insnum+mh->smpnum+of.numpat,modfp);
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 // now is a good time to check if the header was too short :)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
463 if(feof(modfp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
464 { _mm_errno = MMERR_LOADING_HEADER;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
465 return 0;
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 // Check for and load song comment
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
469 if(mh->special & 1)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
470 { _mm_fseek(modfp,(long)(mh->msgoffset),SEEK_SET);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
471 if(!ReadComment(mh->msglength)) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
472 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
473
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
474 if(!(mh->flags & 4)) of.numins = of.numsmp;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
475 if(!AllocSamples()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
476
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
477 if((noteindex=(int *)_mm_malloc(mh->smpnum*sizeof(int)))==NULL) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
478
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
479 q = of.samples;
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 // Load all samples (they're used either way)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
482 for(t=0; t<mh->smpnum; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
483 { ITSAMPLE s;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
484
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
485 // seek to sample position
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
486 _mm_fseek(modfp,(long)(paraptr[mh->insnum+t] + 4),SEEK_SET);
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 // and load sample info
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
489 _mm_read_string(s.filename,12,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
490 s.zerobyte = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
491 s.globvol = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
492 s.flag = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
493 s.volume = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
494 _mm_read_string(s.sampname,26,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
495 s.convert = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
496 s.panning = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
497 s.length = _mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
498 s.loopbeg = _mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
499 s.loopend = _mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
500 s.c5spd = _mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
501 s.susbegin = _mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
502 s.susend = _mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
503 s.sampoffset = _mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
504 s.vibspeed = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
505 s.vibdepth = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
506 s.vibrate = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
507 s.vibwave = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
508
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
509
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
510 // Generate an error if c5spd is > 512k, or samplelength > 256 megs
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
511 // (nothing would EVER be that high)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
512
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
513 if(feof(modfp) || (s.c5spd > 0x7ffffL) || (s.length > 0xfffffffUL) ||
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
514 (s.loopbeg > 0xfffffffUL) || (s.loopend > 0xfffffffUL))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
515 { _mm_errno = MMERR_LOADING_SAMPLEINFO;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
516 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
517 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
518
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
519 q->samplename = DupStr(s.sampname,26);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
520
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
521 q->speed = s.c5spd / 2;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
522 q->panning = ((s.panning & 127)==64) ? 255 : (s.panning & 127) << 2;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
523 q->length = s.length;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
524 q->loopstart = s.loopbeg;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
525 q->loopend = s.loopend;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
526 q->volume = s.volume;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
527 q->globvol = s.globvol;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
528 q->seekpos = s.sampoffset;
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 // ===================================
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
531 // Convert speed to XM linear finetune
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 if(of.flags & UF_LINEAR)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
534 q->speed = cvt_c5spd_to_finetune(s.c5spd, t);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
535
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
536 if(s.panning & 128) q->flags |= SF_OWNPAN;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
537
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
538 if(s.vibrate)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
539 { q->vibflags |= AV_IT;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
540 q->vibtype = s.vibwave;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
541 q->vibsweep = s.vibrate * 2;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
542 q->vibdepth = s.vibdepth;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
543 q->vibrate = s.vibspeed;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
544 }
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 if(s.flag & 2) q->flags |= SF_16BITS;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
547 if(s.flag & 16) q->flags |= SF_LOOP;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
548 if(s.flag & 64) q->flags |= SF_BIDI;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
549
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
550 if(mh->cwt >= 0x200)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
551 { if(s.convert & 1) q->flags |= SF_SIGNED;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
552 if(s.convert & 4) q->flags |= SF_DELTA;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
553 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
554
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
555 q++;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
556 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
557
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
558 // Load instruments if instrument mode flag enabled
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
559
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
560 if(mh->flags & 4)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
561 { if(!AllocInstruments()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
562 d = of.instruments;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
563 of.flags |= UF_NNA | UF_INST;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
564
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
565 for(t=0; t<mh->insnum; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
566 { ITINSTHEADER ih;
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 // seek to instrument position
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
569 _mm_fseek(modfp,paraptr[t]+4,SEEK_SET);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
570
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
571 // and load instrument info
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
572 _mm_read_string(ih.filename,12,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
573 ih.zerobyte = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
574 if(mh->cwt < 0x200) // load IT 1.xx inst header
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
575 { ih.volflg = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
576 ih.volbeg = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
577 ih.volend = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
578 ih.volsusbeg = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
579 ih.volsusend = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
580 _mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
581 ih.fadeout = _mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
582 ih.nna = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
583 ih.dnc = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
584 } else // Read IT200+ header
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
585 { ih.nna = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
586 ih.dct = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
587 ih.dca = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
588 ih.fadeout = _mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
589 ih.ppsep = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
590 ih.ppcenter = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
591 ih.globvol = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
592 ih.chanpan = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
593 ih.rvolvar = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
594 ih.rpanvar = _mm_read_UBYTE(modfp);
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 ih.trkvers = _mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
598 ih.numsmp = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
599 _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
600 _mm_read_string(ih.name,26,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
601 _mm_read_UBYTES(ih.blank01,6,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
602 _mm_read_I_UWORDS(ih.samptable,120,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
603 if(mh->cwt < 0x200) // load IT 1xx volume envelope
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
604 { _mm_read_UBYTES(ih.volenv,200,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
605 for(lp=0; lp<25; lp++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
606 { ih.oldvoltick[lp] = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
607 ih.volnode[lp] = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
608 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
609 } else // load IT 2xx vol & chanpan & pitch envs
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
610 { ih.volflg = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
611 ih.volpts = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
612 ih.volbeg = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
613 ih.volend = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
614 ih.volsusbeg = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
615 ih.volsusend = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
616 for(lp=0; lp<25; lp++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
617 { ih.volnode[lp] = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
618 ih.voltick[lp] = _mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
619 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
620 _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
621
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
622 ih.panflg = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
623 ih.panpts = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
624 ih.panbeg = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
625 ih.panend = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
626 ih.pansusbeg = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
627 ih.pansusend = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
628 for(lp=0; lp<25; lp++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
629 { ih.pannode[lp] = _mm_read_SBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
630 ih.pantick[lp] = _mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
631 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
632 _mm_read_UBYTE(modfp);
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 ih.pitflg = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
635 ih.pitpts = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
636 ih.pitbeg = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
637 ih.pitend = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
638 ih.pitsusbeg = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
639 ih.pitsusend = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
640 for(lp=0; lp<25; lp++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
641 { ih.pitnode[lp] = _mm_read_SBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
642 ih.pittick[lp] = _mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
643 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
644 _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
645 }
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 if(feof(modfp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
648 { _mm_errno = MMERR_LOADING_SAMPLEINFO;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
649 return 0;
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 d->volflg |= EF_VOLENV;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
653 d->insname = DupStr(ih.name,26);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
654 d->nnatype = ih.nna;
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 if(mh->cwt < 0x200)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
657 { d->volfade = ih.fadeout << 6;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
658 if(ih.dnc)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
659 { d->dct = DCT_NOTE;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
660 d->dca = DCA_CUT;
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
663 if(ih.volflg & 1) d->volflg |= EF_ON;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
664 if(ih.volflg & 2) d->volflg |= EF_LOOP;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
665 if(ih.volflg & 4) d->volflg |= EF_SUSTAIN;
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 // XM conversion of IT envelope Array
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 d->volbeg = ih.volbeg;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
670 d->volend = ih.volend;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
671 d->volsusbeg = ih.volsusbeg;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
672 d->volsusend = ih.volsusend;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
673
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
674 if(ih.volflg & 1)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
675 { for(u=0; u<25; u++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
676 if(ih.oldvoltick[d->volpts] != 0xff)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
677 { d->volenv[d->volpts].val = (ih.volnode[d->volpts] << 2);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
678 d->volenv[d->volpts].pos = ih.oldvoltick[d->volpts];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
679 d->volpts++;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
680 } else break;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
681 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
682 } else
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
683 { d->panning = ((ih.chanpan&127) == 64) ? 255 : (ih.chanpan&127)<<2;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
684 if(!(ih.chanpan & 128)) d->flags |= IF_OWNPAN;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
685
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
686 if(!(ih.ppsep & 128))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
687 { d->pitpansep = ih.ppsep << 2;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
688 d->pitpancenter= ih.ppcenter;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
689 d->flags |= IF_PITCHPAN;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
690 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
691 d->globvol = ih.globvol >> 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
692 d->volfade = ih.fadeout << 5;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
693 d->dct = ih.dct;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
694 d->dca = ih.dca;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
695
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
696 if(mh->cwt >= 0x204)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
697 { d->rvolvar = ih.rvolvar;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
698 d->rpanvar = ih.rpanvar;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
699 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
700
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
701 if(ih.volflg & 1) d->volflg |= EF_ON;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
702 if(ih.volflg & 2) d->volflg |= EF_LOOP;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
703 if(ih.volflg & 4) d->volflg |= EF_SUSTAIN;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
704
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
705 if(ih.panflg & 1) d->panflg |= EF_ON;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
706 if(ih.panflg & 2) d->panflg |= EF_LOOP;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
707 if(ih.panflg & 4) d->panflg |= EF_SUSTAIN;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
708
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
709 if(ih.pitflg & 1) d->pitflg |= EF_ON;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
710 if(ih.pitflg & 2) d->pitflg |= EF_LOOP;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
711 if(ih.pitflg & 4) d->pitflg |= EF_SUSTAIN;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
712
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
713 d->volpts = ih.volpts;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
714 d->volbeg = ih.volbeg;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
715 d->volend = ih.volend;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
716 d->volsusbeg = ih.volsusbeg;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
717 d->volsusend = ih.volsusend;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
718
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
719 for(u=0; u<ih.volpts; u++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
720 { d->volenv[u].val = (ih.volnode[u] << 2);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
721 d->volenv[u].pos = ih.voltick[u];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
722 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
723
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
724 d->panpts = ih.panpts;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
725 d->panbeg = ih.panbeg;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
726 d->panend = ih.panend;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
727 d->pansusbeg = ih.pansusbeg;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
728 d->pansusend = ih.pansusend;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
729
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
730 for(u=0; u<ih.panpts; u++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
731 { d->panenv[u].val = (ih.pannode[u]+32) << 2;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
732 d->panenv[u].pos = ih.pantick[u];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
733 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
734
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
735 d->pitpts = ih.pitpts;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
736 d->pitbeg = ih.pitbeg;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
737 d->pitend = ih.pitend;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
738 d->pitsusbeg = ih.pitsusbeg;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
739 d->pitsusend = ih.pitsusend;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
740
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
741 for(u=0; u<ih.pitpts; u++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
742 { d->pitenv[u].val = (ih.pitnode[u]+32);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
743 d->pitenv[u].pos = ih.pittick[u];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
744 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
745 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
746
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
747 if(of.flags & UF_LINEAR)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
748 { for(u=0; u<120; u++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
749 { d->samplenote[u] = (ih.samptable[u] & 255);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
750 d->samplenumber[u] = (ih.samptable[u] >> 8) ? ((ih.samptable[u] >> 8) - 1) : 255;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
751 if(d->samplenumber[u]!=255)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
752 d->samplenote[u] += noteindex[d->samplenumber[u]];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
753 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
754 } else
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
755 { for(u=0; u<120; u++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
756 { d->samplenote[u] = (ih.samptable[u] & 255);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
757 d->samplenumber[u] = (ih.samptable[u] >> 8) ? ((ih.samptable[u] >> 8) - 1) : 255;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
758 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
759 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
760
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
761 d++;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
762 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
763 } else if(of.flags & UF_LINEAR)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
764 { if(!AllocInstruments()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
765 d = of.instruments;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
766 of.flags |= UF_INST;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
767
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
768 for(t=0; t<mh->smpnum; t++, d++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
769 { for(u=0; u<120; u++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
770 d->samplenote[u] += noteindex[d->samplenumber[u]];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
771 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
772 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
773
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
774
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
775 // Figure out how many channels this blasted song actually uses (what
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
776 // ever happened to common courtesy of storing this simple value
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
777 // somewhere in the damn module, eh!?)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
778
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
779 of.numchn = 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
780 memset(remap,-1,64*sizeof(UBYTE));
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
781
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
782 for(t=0; t<of.numpat; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
783 { UWORD packlen;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
784
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
785 // seek to pattern position
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
786 if(paraptr[mh->insnum+mh->smpnum+t] != 0) // No parapointer = pattern of 64 rows, EMPTY
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
787 { _mm_fseek(modfp,(((long)paraptr[mh->insnum+mh->smpnum+t])),SEEK_SET);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
788 packlen = _mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
789 packlen = _mm_read_I_UWORD(modfp); // read pattern length (# of rows)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
790 _mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
791 if(IT_GetNumChannels(packlen)) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
792 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
793 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
794
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
795 // give each of them a different number
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
796 for(t=0; t<64; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
797 { if(remap[t]==0)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
798 { remap[t] = of.numchn;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
799 of.numchn++;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
800 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
801 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
802
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
803 of.numtrk = of.numpat*of.numchn;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
804
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
805
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
806 if(!AllocPatterns()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
807 if(!AllocTracks()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
808
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
809 for(t=0; t<of.numpat; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
810 { UWORD packlen;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
811
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
812 // seek to pattern position
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
813 if(paraptr[mh->insnum+mh->smpnum+t] == 0) // No parapointer = pattern of 64 rows, EMPTY
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
814 { of.pattrows[t] = 64;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
815 for(u=0; u<of.numchn; u++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
816 { int k;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
817 UniReset();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
818 for(k=0; k<64; k++) UniNewline();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
819 of.tracks[numtrk++] = UniDup();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
820 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
821 } else
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
822 { _mm_fseek(modfp,(((long)paraptr[mh->insnum+mh->smpnum+t])),SEEK_SET);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
823 packlen = _mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
824 of.pattrows[t] = _mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
825 _mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
826
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
827 if(!IT_ReadPattern(of.pattrows[t])) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
828 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
829 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
830
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
831 return 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
832 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
833
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
834
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
835 CHAR *IT_LoadTitle(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
836 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
837 CHAR s[26];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
838
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
839 _mm_fseek(modfp,4,SEEK_SET);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
840 if(!fread(s,26,1,modfp)) return NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
841
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
842 return(DupStr(s,26));
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
843 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
844
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
845
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
846 MLOADER load_it =
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
847 { NULL,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
848 "IT",
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
849 "Portable IT loader v0.2",
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
850 IT_Init,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
851 IT_Test,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
852 IT_Load,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
853 IT_Cleanup,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
854
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
855 IT_LoadTitle
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
856 };
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
857