annotate playercode/load_far.c @ 4:5d614bcc4287

Initial entry of mikmod into the CVS tree.
author darius
date Fri, 23 Jan 1998 16:05:08 +0000
parents
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_FAR.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 Farandole (FAR) module loader
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
7
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
8 Portability:
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
9 All systems - all compilers (hopefully)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
10
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
11 If this module is found to not be portable to any particular platform,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
12 please contact Jake Stine at dracoirs@epix.net (see MIKMOD.TXT for
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
13 more information on contacting the author).
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
14 */
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
15
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
16 #include <string.h>
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
17 #include "mikmod.h"
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
18
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
19
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
20 typedef struct FARSAMPLE
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
21 { CHAR samplename[32];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
22 ULONG length;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
23 UBYTE finetune;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
24 UBYTE volume;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
25 ULONG reppos;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
26 ULONG repend;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
27 UBYTE type;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
28 UBYTE loop;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
29 } FARSAMPLE;
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
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 FARHEADER1
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
34 { UBYTE id[4]; // file magic
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
35 CHAR songname[40]; // songname
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
36 CHAR blah[3]; // 13,10,26
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
37 UWORD headerlen; // remaining length of header in bytes
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
38 UBYTE version;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
39 UBYTE onoff[16];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
40 UBYTE edit1[9];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
41 UBYTE speed;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
42 UBYTE panning[16];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
43 UBYTE edit2[4];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
44 UWORD stlen;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
45 } FARHEADER1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
46
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
47
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
48 typedef struct FARHEADER2
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
49 { UBYTE orders[256];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
50 UBYTE numpat;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
51 UBYTE snglen;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
52 UBYTE loopto;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
53 UWORD patsiz[256];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
54 } FARHEADER2;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
55
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
56
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
57 typedef struct FARNOTE
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
58 { UBYTE note,ins,vol,eff;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
59 } FARNOTE;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
60
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
61
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
62
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
63 static CHAR FAR_Version[] = "Farandole";
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
64 static FARHEADER1 *mh1 = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
65 static FARHEADER2 *mh2 = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
66 static FARNOTE *pat = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
67
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
68
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
69 BOOL FAR_Test(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
70 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
71 UBYTE id[4];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
72
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
73 if(!_mm_read_UBYTES(id,4,modfp)) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
74 return(!memcmp(id,"FAR=",4));
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
75 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
76
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
77
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
78 BOOL FAR_Init(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
79 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
80 if(!(mh1 = (FARHEADER1 *)_mm_malloc(sizeof(FARHEADER1)))) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
81 if(!(mh2 = (FARHEADER2 *)_mm_malloc(sizeof(FARHEADER2)))) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
82 if(!(pat = (FARNOTE *)_mm_malloc(16*256*sizeof(FARNOTE)))) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
83
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
84 return 1;
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
87
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
88 void FAR_Cleanup(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
89 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
90 if(mh1!=NULL) free(mh1);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
91 if(mh2!=NULL) free(mh2);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
92 if(pat!=NULL) free(pat);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
93
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
94 mh1 = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
95 mh2 = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
96 pat = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
97 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
98
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
99
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
100 UBYTE *FAR_ConvertTrack(FARNOTE *n,int rows)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
101 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
102 int t;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
103
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
104 UniReset();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
105
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
106 for(t=0; t<rows; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
107 { if(n->note)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
108 { UniInstrument(n->ins);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
109 UniNote(n->note+23+12);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
110 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
111
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
112 if(n->vol&0xf) UniPTEffect(0xc,(n->vol&0xf)<<2);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
113 switch(n->eff>>4)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
114 { case 0xf:
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
115 UniPTEffect(0xf,n->eff&0xf);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
116 break;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
117
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
118 // others not yet implemented
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
119 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
120
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
121 UniNewline();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
122 n+=16;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
123 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
124 return UniDup();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
125 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
126
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
127
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
128 BOOL FAR_Load(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
129 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
130 int t,u,tracks=0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
131 SAMPLE *q;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
132 FARSAMPLE s;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
133 FARNOTE *crow;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
134 UBYTE smap[8];
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 // try to read module header (first part)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
137 _mm_read_UBYTES(mh1->id,4,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
138 _mm_read_SBYTES(mh1->songname,40,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
139 _mm_read_SBYTES(mh1->blah,3,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
140 mh1->headerlen = _mm_read_I_UWORD (modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
141 mh1->version = _mm_read_UBYTE (modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
142 _mm_read_UBYTES(mh1->onoff,16,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
143 _mm_read_UBYTES(mh1->edit1,9,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
144 mh1->speed = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
145 _mm_read_UBYTES(mh1->panning,16,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
146 _mm_read_UBYTES(mh1->edit2,4,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
147 mh1->stlen = _mm_read_I_UWORD (modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
148
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
149
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
150 // init modfile data
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 of.modtype = strdup(FAR_Version);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
153 of.songname = DupStr(mh1->songname,40);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
154 of.numchn = 16;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
155 of.initspeed = mh1->speed;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
156 of.inittempo = 99;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
157
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
158 for(t=0; t<16; t++) of.panning[t] = mh1->panning[t]<<4;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
159
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
160 // read songtext into comment field
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
161 if(!ReadComment(mh1->stlen)) 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 // try to read module header (second part)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
164 _mm_read_UBYTES(mh2->orders,256,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
165 mh2->numpat = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
166 mh2->snglen = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
167 mh2->loopto = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
168 _mm_read_I_UWORDS(mh2->patsiz,256,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
169
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
170 // of.numpat=mh2->numpat;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
171 of.numpos = mh2->snglen;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
172 if(!AllocPositions(of.numpos)) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
173 for(t=0; t<of.numpos; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
174 { if(mh2->orders[t]==0xff) break;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
175 of.positions[t] = mh2->orders[t];
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
178 // count number of patterns stored in file
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
179 of.numpat = 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
180 for(t=0; t<256; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
181 if(mh2->patsiz[t]) if((t+1)>of.numpat) of.numpat=t+1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
182
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
183 of.numtrk = of.numpat*of.numchn;
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 // seek across eventual new data
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
186 _mm_fseek(modfp,mh1->headerlen-(869+mh1->stlen),SEEK_CUR);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
187
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
188 // alloc track and pattern structures
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
189 if(!AllocTracks()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
190 if(!AllocPatterns()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
191
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
192 for(t=0; t<of.numpat; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
193 { UBYTE rows=0,tempo;
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 memset(pat,0,16*256*sizeof(FARNOTE));
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
196 if(mh2->patsiz[t])
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
197 { rows = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
198 tempo = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
199
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
200 crow = pat;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
201 for(u=mh2->patsiz[t]-2; u; u--, crow++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
202 { crow->note = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
203 crow->ins = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
204 crow->vol = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
205 crow->eff = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
206 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
207
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
208 if(feof(modfp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
209 { _mm_errno = MMERR_LOADING_PATTERN;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
210 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
211 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
212
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
213 of.pattrows[t] = rows+2;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
214 crow = pat;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
215 for(u=16; u; u--)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
216 if(!(of.tracks[tracks++] = FAR_ConvertTrack(crow,rows+2))) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
217 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
218 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
219
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
220 // read sample map
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
221 if(!_mm_read_UBYTES(smap,8,modfp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
222 { _mm_errno = MMERR_LOADING_HEADER;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
223 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
224 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
225
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
226 // count number of samples used
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
227 of.numins = 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
228 for(t=0; t<64; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
229 if(smap[t>>3] & (1 << (t&7))) of.numins++;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
230 of.numsmp = of.numins;
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 // alloc sample structs
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
233 if(!AllocSamples()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
234 q = of.samples;
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 for(t=0; t<64; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
237 { if(smap[t>>3] & (1 << (t&7)))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
238 { _mm_read_SBYTES(s.samplename,32,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
239 s.length = _mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
240 s.finetune = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
241 s.volume = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
242 s.reppos = _mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
243 s.repend = _mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
244 s.type = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
245 s.loop = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
246
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
247 q->samplename = DupStr(s.samplename,32);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
248 q->length = s.length;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
249 q->loopstart = s.reppos;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
250 q->loopend = s.repend;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
251 q->volume = 64;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
252 q->speed = 8363;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
253
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
254 q->flags=SF_SIGNED;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
255 if(s.type&1) q->flags|=SF_16BITS;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
256 if(s.loop) q->flags|=SF_LOOP;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
257
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
258 q->seekpos = _mm_ftell(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
259 _mm_fseek(modfp,q->length,SEEK_CUR);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
260 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
261 q++;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
262 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
263 return 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
264 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
265
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
266
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
267 CHAR *FAR_LoadTitle(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
268 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
269 CHAR s[40];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
270
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
271 _mm_fseek(modfp,4,SEEK_SET);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
272 if(!fread(s,40,1,modfp)) return NULL;
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 return(DupStr(s,40));
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
275 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
276
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
277
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
278 MLOADER load_far =
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
279 { NULL,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
280 "FAR",
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
281 "Portable FAR loader v0.1",
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
282 FAR_Init,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
283 FAR_Test,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
284 FAR_Load,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
285 FAR_Cleanup,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
286 FAR_LoadTitle
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