annotate playercode/load_med.c @ 8:b30908f9d9f9

Initial entry of mikmod into the CVS tree.
author darius
date Fri, 23 Jan 1998 16:05:10 +0000
parents 5d614bcc4287
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
1 /*
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
2
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
3 Name: LOAD_MED.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 Amiga MED module loader
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
7
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
8 Portability:
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
9 All systems - all compilers (hopefully)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
10
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
11 If this module is found to not be portable to any particular platform,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
12 please contact Jake Stine at dracoirs@epix.net (see MIKMOD.TXT for
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
13 more information on contacting the author).
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
14
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
15 */
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
16
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
17 #include <string.h>
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
18 #include "mikmod.h"
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
19
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
20 #define MMD0_string 0x4D4D4430
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
21 #define MMD1_string 0x4D4D4431
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 typedef struct MMD0
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
24 { ULONG id;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
25 ULONG modlen;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
26 ULONG MMD0songP; // struct MMD0song *song;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
27 UWORD psecnum; // for the player routine, MMD2 only
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
28 UWORD pseq; // " " " "
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
29 ULONG MMD0BlockPP; // struct MMD0Block **blockarr;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
30 ULONG reserved1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
31 ULONG InstrHdrPP; // struct InstrHdr **smplarr;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
32 ULONG reserved2;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
33 ULONG MMD0expP; // struct MMD0exp *expdata;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
34 ULONG reserved3;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
35 UWORD pstate; // some data for the player routine
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
36 UWORD pblock;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
37 UWORD pline;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
38 UWORD pseqnum;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
39 SWORD actplayline;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
40 UBYTE counter;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
41 UBYTE extra_songs; // number of songs - 1
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
42 } MMD0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
43
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 typedef struct MMD0sample
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
46 { UWORD rep,replen; // offs: 0(s), 2(s)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
47 UBYTE midich; // offs: 4(s)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
48 UBYTE midipreset; // offs: 5(s)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
49 UBYTE svol; // offs: 6(s)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
50 SBYTE strans; // offs: 7(s)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
51 } MMD0sample;
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
54 typedef struct MMD0song
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
55 { MMD0sample sample[63]; // 63 * 8 bytes = 504 bytes
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
56 UWORD numblocks; // offs: 504
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
57 UWORD songlen; // offs: 506
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
58 UBYTE playseq[256]; // offs: 508
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
59 UWORD deftempo; // offs: 764
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
60 SBYTE playtransp; // offs: 766
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
61 UBYTE flags; // offs: 767
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
62 UBYTE flags2; // offs: 768
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
63 UBYTE tempo2; // offs: 769
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
64 UBYTE trkvol[16]; // offs: 770
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
65 UBYTE mastervol; // offs: 786
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
66 UBYTE numsamples; // offs: 787
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
67 } MMD0song;
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 typedef struct MMD0NOTE
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
71 { UBYTE a,b,c;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
72 } MMD0NOTE;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
73
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
74
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
75 typedef struct MMD1NOTE
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
76 { UBYTE a,b,c,d;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
77 } MMD1NOTE;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
78
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 typedef struct InstrHdr
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
81 { ULONG length;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
82 SWORD type;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
83 // Followed by actual data
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
84 } InstrHdr;
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 static MMD0 *mh = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
88 static MMD0song *ms = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
89 static ULONG *ba = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
90 static MMD0NOTE *mmd0pat = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
91 static MMD1NOTE *mmd1pat = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
92
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
93 #define d0note(row,col) mmd0pat[(row*(UWORD)of.numchn)+col]
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
94 #define d1note(row,col) mmd1pat[(row*(UWORD)of.numchn)+col]
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 CHAR MED_Version[] = "MED";
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 BOOL MED_Test(void)
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 UBYTE id[4];
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 if(!_mm_read_UBYTES(id,4,modfp)) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
105 if(!memcmp(id,"MMD0",4)) return 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
106 if(!memcmp(id,"MMD1",4)) return 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
107 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
108 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
109
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 BOOL MED_Init(void)
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 if(!(mh=(MMD0 *)_mm_calloc(1,sizeof(MMD0)))) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
114 if(!(ms=(MMD0song *)_mm_calloc(1,sizeof(MMD0song)))) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
115 return 1;
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
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 void MED_Cleanup(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
120 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
121 if(mh!=NULL) free(mh);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
122 if(ms!=NULL) free(ms);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
123 if(ba!=NULL) free(ba);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
124 if(mmd0pat!=NULL) free(mmd0pat);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
125 if(mmd1pat!=NULL) free(mmd1pat);
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 mh = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
128 ms = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
129 ba = NULL; // blockarr
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
130 mmd0pat = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
131 mmd1pat = NULL;
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 void EffectCvt(UBYTE eff,UBYTE dat)
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 switch(eff)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
138 { // 0x0 0x1 0x2 0x3 0x4 // PT effects
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
139 case 0x5: // PT vibrato with speed/depth nibbles swapped
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
140 UniPTEffect(0x4,(dat>>4) | ((dat&0xf)<<4) );
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
141 break;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
142
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
143 case 0x6: // not used
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
144 case 0x7: // not used
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
145 case 0x8: // midi hold/decay
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
146 break;
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 case 0x9:
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
149 if(dat<=0x20) UniPTEffect(0xf,dat);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
150 break;
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 // 0xa 0xb 0xc all PT effects
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 case 0xd: // same as PT volslide
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
155 UniPTEffect(0xa,dat);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
156 break;
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 case 0xe: // synth jmp - midi
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
159 break;
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 case 0xf:
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
162 // F00 does patternbreak with med
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
163 if(dat==0) UniPTEffect(0xd,0);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
164 else if(dat<=0xa) UniPTEffect(0xf,dat);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
165 else if(dat<0xf1) UniPTEffect(0xf,((UWORD)dat*125)/33);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
166 else if(dat==0xff) UniPTEffect(0xc,0); // stop note
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
167 break;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
168
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
169 default: // all normal PT effects are handled here :)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
170 // Convert pattern jump from Dec to Hex
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
171 if(eff == 0xd)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
172 dat = (((dat&0xf0)>>4)*10)+(dat&0xf);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
173 UniPTEffect(eff,dat);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
174 break;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
175 }
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
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 UBYTE *MED_Convert1(int col)
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 int t;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
183 UBYTE a,b,c,d,inst,note,eff,dat;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
184 MMD1NOTE *n;
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 { n = &d1note(t,col);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
189 a = n->a;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
190 b = n->b;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
191 c = n->c;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
192 d = n->d;
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 note = a&0x7f;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
195 inst = b&0x3f;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
196 eff = c&0xf;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
197 dat = d;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
198
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
199 if(inst!=0) UniInstrument(inst-1);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
200 if(note!=0) UniNote(note+23);
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 EffectCvt(eff,dat);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
203 UniNewline();
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
206 return UniDup();
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
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 UBYTE *MED_Convert0(int col)
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 int t;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
213 UBYTE a,b,c,inst,note,eff,dat;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
214 MMD0NOTE *n;
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 UniReset();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
217 for(t=0;t<64;t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
218 { n = &d0note(t,col);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
219 a = n->a;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
220 b = n->b;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
221 c = n->c;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
222
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
223 note = a & 0x3f;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
224 a >>= 6;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
225 a = ((a & 1) << 1) | (a >> 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 inst = (b >> 4) | (a << 4);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
228 eff = b & 0xf;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
229 dat = c;
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 if(inst!=0) UniInstrument(inst-1);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
232 if(note!=0) UniNote(note+35);
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 EffectCvt(eff,dat);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
235 UniNewline();
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 return UniDup();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
238 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
239
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
240
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
241 BOOL LoadMMD0Patterns(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
242 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
243 int t,row,col;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
244 UWORD numtracks,numlines,maxlines=0,track=0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
245 MMD0NOTE *mmdp;
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 // first, scan patterns to see how many channels are used
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
248 for(t=0; t<of.numpat; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
249 { _mm_fseek(modfp,ba[t],SEEK_SET);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
250 numtracks = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
251 numlines = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
252
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
253 if(numtracks>of.numchn) of.numchn = numtracks;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
254 if(numlines>maxlines) maxlines = numlines;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
255 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
256
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
257 of.numtrk = of.numpat*of.numchn;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
258 if(!AllocTracks()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
259 if(!AllocPatterns()) return 0;
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 if(!(mmd0pat=(MMD0NOTE*)_mm_calloc(of.numchn*(maxlines+1),sizeof(MMD0NOTE)))) return 0;
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 // second read: no more mr. nice guy,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
264 // really read and convert patterns
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 for(t=0; t<of.numpat; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
267 { _mm_fseek(modfp,ba[t],SEEK_SET);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
268 numtracks = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
269 numlines = _mm_read_UBYTE(modfp);
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 of.pattrows[t] = numlines+1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
272 memset(mmdp=mmd0pat,0,of.numchn*maxlines*sizeof(MMD0NOTE));
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
273 for(row=numlines+1; row; row--)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
274 { for(col=numtracks; col; col--,mmdp++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
275 { mmdp->a = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
276 mmdp->b = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
277 mmdp->c = _mm_read_UBYTE(modfp);
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 for(col=0; col<of.numchn; col++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
282 { of.tracks[track] = MED_Convert0(col);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
283 track++;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
284 }
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 return 1;
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
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 BOOL LoadMMD1Patterns(void)
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 int t,row,col;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
293 UWORD numtracks,numlines,maxlines=0,track=0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
294 MMD1NOTE *mmdp;
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 // first, scan patterns to see how many channels are used
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
297 for(t=0; t<of.numpat; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
298 { _mm_fseek(modfp,ba[t],SEEK_SET);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
299 numtracks = _mm_read_M_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
300 numlines = _mm_read_M_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
301
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
302 _mm_fseek(modfp,sizeof(ULONG),SEEK_CUR);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
303 if(numtracks>of.numchn) of.numchn = numtracks;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
304 if(numlines>maxlines) maxlines = numlines;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
305 }
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 of.numtrk = of.numpat*of.numchn;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
308 if(!AllocTracks()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
309 if(!AllocPatterns()) return 0;
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 if(!(mmd1pat=(MMD1NOTE*)_mm_calloc(of.numchn*(maxlines+1),sizeof(MMD1NOTE)))) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
312
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
313 // second read: no more mr. nice guy, really read and convert patterns
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
314 for(t=0; t<of.numpat; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
315 { _mm_fseek(modfp,ba[t],SEEK_SET);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
316 numtracks = _mm_read_M_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
317 numlines = _mm_read_M_UWORD(modfp);
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 _mm_fseek(modfp,sizeof(ULONG),SEEK_CUR);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
320 of.pattrows[t] = numlines;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
321 memset(mmdp=mmd1pat,0,of.numchn*maxlines*sizeof(MMD1NOTE));
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
322
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
323 for(row=numlines+1; row; row--)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
324 { for(col=numtracks; col; col--,mmdp++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
325 { mmdp->a = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
326 mmdp->b = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
327 mmdp->c = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
328 mmdp->d = _mm_read_UBYTE(modfp);
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
332 for(col=0;col<of.numchn;col++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
333 { of.tracks[track]=MED_Convert1(col);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
334 track++;
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 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
337 return 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
338 }
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
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 BOOL MED_Load(void)
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 t;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
345 ULONG sa[64];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
346 InstrHdr s;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
347 SAMPLE *q;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
348 MMD0sample *mss;
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 // try to read module header
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
351
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
352 mh->id = _mm_read_M_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
353 mh->modlen = _mm_read_M_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
354 mh->MMD0songP = _mm_read_M_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
355 mh->psecnum = _mm_read_M_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
356 mh->pseq = _mm_read_M_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
357 mh->MMD0BlockPP = _mm_read_M_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
358 mh->reserved1 = _mm_read_M_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
359 mh->InstrHdrPP = _mm_read_M_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
360 mh->reserved2 = _mm_read_M_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
361 mh->MMD0expP = _mm_read_M_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
362 mh->reserved3 = _mm_read_M_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
363 mh->pstate = _mm_read_M_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
364 mh->pblock = _mm_read_M_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
365 mh->pline = _mm_read_M_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
366 mh->pseqnum = _mm_read_M_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
367 mh->actplayline = _mm_read_M_SWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
368 mh->counter = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
369 mh->extra_songs = _mm_read_UBYTE(modfp);
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 // Seek to MMD0song struct
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
372 _mm_fseek(modfp,mh->MMD0songP,SEEK_SET);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
373
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
374
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
375 // Load the MMD0 Song Header
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 mss = ms->sample; // load the sample data first
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
378 for(t=63; t; t--, mss++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
379 { mss->rep = _mm_read_M_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
380 mss->replen = _mm_read_M_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
381 mss->midich = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
382 mss->midipreset = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
383 mss->svol = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
384 mss->strans = _mm_read_SBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
385 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
386
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
387 ms->numblocks = _mm_read_M_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
388 ms->songlen = _mm_read_M_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
389 _mm_read_UBYTES(ms->playseq,256,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
390 ms->deftempo = _mm_read_M_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
391 ms->playtransp = _mm_read_SBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
392 ms->flags = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
393 ms->flags2 = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
394 ms->tempo2 = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
395 _mm_read_UBYTES(ms->trkvol,16,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
396 ms->mastervol = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
397 ms->numsamples = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
398
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
399 // check for a bad header
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
400 if(feof(modfp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
401 { _mm_errno = MMERR_LOADING_HEADER;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
402 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
403 }
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 // seek to and read the samplepointer array
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
406 _mm_fseek(modfp,mh->InstrHdrPP,SEEK_SET);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
407 if(!_mm_read_M_ULONGS(sa,ms->numsamples,modfp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
408 { _mm_errno = MMERR_LOADING_HEADER;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
409 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
410 }
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 // alloc and read the blockpointer array
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
413 if(!(ba=(ULONG *)_mm_calloc(ms->numblocks, sizeof(ULONG)))) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
414 _mm_fseek(modfp,mh->MMD0BlockPP,SEEK_SET);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
415 if(!_mm_read_M_ULONGS(ba,ms->numblocks,modfp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
416 { _mm_errno = MMERR_LOADING_HEADER;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
417 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
418 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
419
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
420
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
421 // copy song positions
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
422 if(!AllocPositions(ms->songlen)) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
423 for(t=0; t<ms->songlen; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
424 of.positions[t] = ms->playseq[t];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
425
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
426 of.initspeed = 6;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
427 of.inittempo = ((UWORD)ms->deftempo*125)/33;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
428 of.modtype = strdup(MED_Version);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
429 of.numchn = 0; // will be counted later
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
430 of.numpat = ms->numblocks;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
431 of.numpos = ms->songlen;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
432 of.numins = ms->numsamples;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
433
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
434 of.numsmp = of.numins;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
435 if(!AllocSamples()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
436 q = of.samples;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
437
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
438 for(t=0; t<of.numins; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
439 { _mm_fseek(modfp,sa[t],SEEK_SET);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
440 s.length = _mm_read_M_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
441 s.type = _mm_read_M_SWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
442
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
443 if(feof(modfp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
444 { _mm_errno = MMERR_LOADING_SAMPLEINFO;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
445 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
446 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
447
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
448 q->samplename = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
449 q->length = s.length;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
450 q->seekpos = _mm_ftell(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
451 q->loopstart = ms->sample[t].rep<<1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
452 q->loopend = q->loopstart+(ms->sample[t].replen<<1);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
453 q->flags = SF_SIGNED;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
454 q->speed = 8363;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
455 q->volume = 64;
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(ms->sample[t].replen>1) q->flags|=SF_LOOP;
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 // don't load sample if length>='MMD0' hah.. hah.. very funny.. NOT!
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
460 if(q->length >= MMD0_string) q->length = 0;
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 q++;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
463 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
464
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
465
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
466 if(mh->id==MMD0_string)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
467 { if(!LoadMMD0Patterns()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
468 } else if(mh->id==MMD1_string)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
469 { if(!LoadMMD1Patterns()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
470 } else
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
471 { _mm_errno = MMERR_NOT_A_MODULE;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
472 return 0;
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
475 return 1;
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
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 MLOADER load_med =
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
480 { NULL,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
481 "MED",
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
482 "MED loader v0.1",
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
483 MED_Init,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
484 MED_Test,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
485 MED_Load,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
486 MED_Cleanup,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
487 NULL
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
488 };
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
489
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
490