annotate playercode/load_mod.c @ 18:db40f957950f

Replaced the shell scripts with a Makefile
author darius
date Thu, 23 Apr 1998 22:58:04 +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_MOD.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 Generic MOD loader (Protracker, StarTracker, FastTracker, etc)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
7
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
8 Portability:
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
9 All systems - all compilers (hopefully)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
10
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
11 If this module is found to not be portable to any particular platform,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
12 please contact Jake Stine at dracoirs@epix.net (see MIKMOD.TXT for
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
13 more information on contacting the author).
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
14
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
15 */
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
16
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
17 #include <string.h>
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
18 #include "mikmod.h"
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
19
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
20 /*************************************************************************
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
21 *************************************************************************/
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
22
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
23
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
24 typedef struct MSAMPINFO // sample header as it appears in a module
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
25 { CHAR samplename[22];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
26 UWORD length;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
27 UBYTE finetune;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
28 UBYTE volume;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
29 UWORD reppos;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
30 UWORD replen;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
31 } MSAMPINFO;
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
34 typedef struct MODULEHEADER // verbatim module header
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
35 { CHAR songname[20]; // the songname..
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
36 MSAMPINFO samples[31]; // all sampleinfo
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
37 UBYTE songlength; // number of patterns used
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
38 UBYTE magic1; // should be 127
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
39 UBYTE positions[128]; // which pattern to play at pos
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
40 UBYTE magic2[4]; // string "M.K." or "FLT4" or "FLT8"
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
41 } MODULEHEADER;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
42
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
43 #define MODULEHEADERSIZE 1084
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
44
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
45
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
46 typedef struct MODTYPE // struct to identify type of module
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
47 { CHAR id[5];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
48 UBYTE channels;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
49 CHAR *name;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
50 } MODTYPE;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
51
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
52
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
53 typedef struct MODNOTE
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
54 { UBYTE a,b,c,d;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
55 } MODNOTE;
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
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 *************************************************************************/
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 CHAR protracker[] = "Protracker";
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
63 CHAR startracker[] = "Startracker";
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
64 CHAR fasttracker[] = "Fasttracker";
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
65 CHAR ins15tracker[] = "15-instrument";
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
66 CHAR oktalyzer[] = "Oktalyzer";
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
67 CHAR taketracker[] = "TakeTracker";
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
70 MODTYPE modtypes[] =
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
71 { "M.K.",4,protracker, // protracker 4 channel
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
72 "M!K!",4,protracker, // protracker 4 channel
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
73 "FLT4",4,startracker, // startracker 4 channel
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
74 "2CHN",2,fasttracker, // fasttracker 2 channel
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
75 "4CHN",4,fasttracker, // fasttracker 4 channel
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
76 "6CHN",6,fasttracker, // fasttracker 6 channel
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
77 "8CHN",8,fasttracker, // fasttracker 8 channel
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
78 "10CH",10,fasttracker, // fasttracker 10 channel
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
79 "12CH",12,fasttracker, // fasttracker 12 channel
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
80 "14CH",14,fasttracker, // fasttracker 14 channel
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
81 "16CH",16,fasttracker, // fasttracker 16 channel
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
82 "18CH",18,fasttracker, // fasttracker 18 channel
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
83 "20CH",20,fasttracker, // fasttracker 20 channel
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
84 "22CH",22,fasttracker, // fasttracker 22 channel
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
85 "24CH",24,fasttracker, // fasttracker 24 channel
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
86 "26CH",26,fasttracker, // fasttracker 26 channel
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
87 "28CH",28,fasttracker, // fasttracker 28 channel
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
88 "30CH",30,fasttracker, // fasttracker 30 channel
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
89 "32CH",32,fasttracker, // fasttracker 32 channel
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
90 "CD81",8,oktalyzer, // atari oktalyzer 8 channel
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
91 "OKTA",8,oktalyzer, // atari oktalyzer 8 channel
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
92 "16CN",16,taketracker, // taketracker 16 channel
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
93 "32CN",32,taketracker, // taketracker 32 channel
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
94 " ",4,ins15tracker // 15-instrument 4 channel
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
95 };
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
96
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
97 static MODULEHEADER *mh = NULL; // raw as-is module header
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
98 static MODNOTE *patbuf = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
99 static int modtype = 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
100
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
101 BOOL MOD_Test(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
102 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
103 UBYTE id[4];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
104
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
105 _mm_fseek(modfp,MODULEHEADERSIZE-4,SEEK_SET);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
106 if(!fread(id,4,1,modfp)) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
107
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
108 // find out which ID string
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
109
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
110 for(modtype=0; modtype<23; modtype++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
111 if(!memcmp(id,modtypes[modtype].id,4)) return 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
112
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
113 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
114 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
115
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
116
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
117 BOOL MOD_Init(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
118 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
119 if(!(mh=(MODULEHEADER *)_mm_calloc(1,sizeof(MODULEHEADER)))) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
120 return 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
121 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
122
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 void MOD_Cleanup(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
125 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
126 if(mh!=NULL) free(mh);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
127 if(patbuf!=NULL) free(patbuf);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
128
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
129 mh = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
130 patbuf = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
131 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
132
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
133
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
134 /*
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
135 Old (amiga) noteinfo:
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 _____byte 1_____ byte2_ _____byte 3_____ byte4_
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 0000 0000-00000000 0000 0000-00000000
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
140
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
141 Upper four 12 bits for Lower four Effect command.
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
142 bits of sam- note period. bits of sam-
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
143 ple number. ple number.
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
144
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
145 */
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
146
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
147
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
148 void ConvertNote(MODNOTE *n)
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 UBYTE instrument,effect,effdat,note;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
151 UWORD period;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
152
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
153 // extract the various information from the 4 bytes that
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
154 // make up a single note
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
155
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
156 instrument = (n->a&0x10)|(n->c>>4);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
157 period = (((UWORD)n->a&0xf)<<8)+n->b;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
158 effect = n->c&0xf;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
159 effdat = n->d;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
160
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
161 // Convert the period to a note number
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 note=0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
164 if(period!=0)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
165 { for(note=0; note<60; note++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
166 if(period >= npertab[note]) break;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
167 note++;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
168 if(note==61) note = 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
169 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
170
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
171 if(instrument!=0) UniInstrument(instrument-1);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
172 if(note!=0) UniNote(note+23);
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 // Convert pattern jump from Dec to Hex
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
175 if(effect == 0xd)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
176 effdat = (((effdat&0xf0)>>4)*10)+(effdat&0xf);
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 UniPTEffect(effect,effdat);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
179 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
180
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
181
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
182 UBYTE *ConvertTrack(MODNOTE *n)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
183 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
184 int t;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
185
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
186 UniReset();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
187 for(t=0;t<64;t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
188 { ConvertNote(n);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
189 UniNewline();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
190 n+=of.numchn;
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 return UniDup();
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
196 BOOL ML_LoadPatterns(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
197 // Loads all patterns of a modfile and converts them into the
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
198 // 3 byte format.
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 int t,s,tracks = 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
201
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
202 if(!AllocPatterns()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
203 if(!AllocTracks()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
204
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
205 // Allocate temporary buffer for loading
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
206 // and converting the patterns
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(!(patbuf=(MODNOTE *)_mm_calloc(64U*of.numchn,sizeof(MODNOTE)))) return 0;
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 for(t=0; t<of.numpat; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
211 { // Load the pattern into the temp buffer
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
212 // and convert it
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
213
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
214 for(s=0; s<(64U*of.numchn); s++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
215 { patbuf[s].a = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
216 patbuf[s].b = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
217 patbuf[s].c = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
218 patbuf[s].d = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
219 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
220
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
221 for(s=0; s<of.numchn; s++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
222 if(!(of.tracks[tracks++]=ConvertTrack(patbuf+s))) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
223 }
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 return 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
226 }
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
229 BOOL MOD_Load(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
230 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
231 int t;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
232 SAMPLE *q;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
233 MSAMPINFO *s; // old module sampleinfo
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
234
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
235 // try to read module header
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
236
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
237 _mm_read_string((CHAR *)mh->songname,20,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
238
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
239 for(t=0; t<31; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
240 { s = &mh->samples[t];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
241 _mm_read_string(s->samplename,22,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
242 s->length =_mm_read_M_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
243 s->finetune =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
244 s->volume =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
245 s->reppos =_mm_read_M_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
246 s->replen =_mm_read_M_UWORD(modfp);
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
249 mh->songlength =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
250 mh->magic1 =_mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
251
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
252 _mm_read_UBYTES(mh->positions,128,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
253 _mm_read_UBYTES(mh->magic2,4,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
254
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
255 if(feof(modfp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
256 { _mm_errno = MMERR_LOADING_HEADER;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
257 return 0;
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
260 // set module variables
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
261
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
262 of.initspeed = 6;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
263 of.inittempo = 125;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
264 of.numchn = modtypes[modtype].channels; // get number of channels
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
265 of.modtype = strdup(modtypes[modtype].name); // get ascii type of mod
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
266 of.songname = DupStr(mh->songname,20); // make a cstr of songname
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
267 of.numpos = mh->songlength; // copy the songlength
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 if(!AllocPositions(of.numpos)) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
270 for(t=0; t<of.numpos; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
271 of.positions[t] = mh->positions[t];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
272
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
273 // Count the number of patterns
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
274
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
275 of.numpat = 0;
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 for(t=0; t<of.numpos; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
278 { if(of.positions[t] > of.numpat)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
279 of.numpat = of.positions[t];
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 of.numpat++;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
282 of.numtrk = of.numpat*of.numchn;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
283
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
284 // Finally, init the sampleinfo structures
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
285 of.numins = of.numsmp = 31;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
286
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
287 if(!AllocSamples()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
288
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
289 s = mh->samples; // init source pointer
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
290 q = of.samples;
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 for(t=0; t<of.numins; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
293 { // convert the samplename
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
294 q->samplename = DupStr(s->samplename, 22);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
295
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
296 // init the sampleinfo variables and
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
297 // convert the size pointers to longword format
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 q->speed = finetune[s->finetune & 0xf];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
300 q->volume = s->volume;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
301 q->loopstart = (ULONG)s->reppos << 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
302 q->loopend = q->loopstart + ((ULONG)s->replen << 1);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
303 q->length = (ULONG)s->length << 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
304
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
305 q->flags = SF_SIGNED;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
306 if(s->replen > 1) q->flags |= SF_LOOP;
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 // fix replen if repend > length
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
309 if(q->loopend > q->length) q->loopend = q->length;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
310
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
311 s++; // point to next source sampleinfo
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
312 q++;
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
315 if(!ML_LoadPatterns()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
316 return 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
317 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
318
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
319
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
320 CHAR *MOD_LoadTitle(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
321 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
322 CHAR s[20];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
323
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
324 _mm_fseek(modfp,0,SEEK_SET);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
325 if(!fread(s,20,1,modfp)) return NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
326
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
327 return(DupStr(s,20));
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
328 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
329
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
330
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
331 MLOADER load_mod =
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
332 { NULL,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
333 "Standard module",
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
334 "Portable MOD loader v0.11",
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
335 MOD_Init,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
336 MOD_Test,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
337 MOD_Load,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
338 MOD_Cleanup,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
339 MOD_LoadTitle
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
340 };
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
341