annotate playercode/load_dsm.c @ 6:d14fd386d182

Initial entry of mikmod into the CVS tree.
author darius
date Fri, 23 Jan 1998 16:05:09 +0000
parents 5d614bcc4287
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
1 /*
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
2
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
3 Name: LOAD_DSM.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 DSIK Internal Format (DSM) module loader
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
7
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
8 Portability:
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
9 All systems - all compilers (hopefully)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
10
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
11 If this module is found to not be portable to any particular platform,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
12 please contact Jake Stine at dracoirs@epix.net (see MIKMOD.TXT for
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
13 more information on contacting the author).
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
14 */
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
15
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
16 #include <string.h>
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
17 #include "mikmod.h"
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
18
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
19
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
20 typedef struct DSMNOTE
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
21 { UBYTE note,ins,vol,cmd,inf;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
22 } DSMNOTE;
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
25 typedef struct DSMINST
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
26 { CHAR filename[13];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
27 UWORD flags;
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 ULONG length;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
30 ULONG loopstart;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
31 ULONG loopend;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
32 ULONG reserved1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
33 UWORD c2spd;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
34 UWORD reserved2;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
35 CHAR samplename[28];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
36 } DSMINST;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
37
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
38
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
39 typedef struct DSMSONG
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
40 { CHAR songname[28];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
41 UWORD reserved1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
42 UWORD flags;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
43 ULONG reserved2;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
44 UWORD numord;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
45 UWORD numsmp;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
46 UWORD numpat;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
47 UWORD numtrk;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
48 UBYTE globalvol;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
49 UBYTE mastervol;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
50 UBYTE speed;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
51 UBYTE bpm;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
52 UBYTE panpos[16];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
53 UBYTE orders[128];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
54 } DSMSONG;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
55
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
56
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
57
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
58 static CHAR *SONGID = "SONG";
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
59 static CHAR *INSTID = "INST";
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
60 static CHAR *PATTID = "PATT";
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
61
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
62
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
63 static UBYTE blockid[4];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
64 static ULONG blockln;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
65 static ULONG blocklp;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
66 static DSMSONG *mh = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
67 static DSMNOTE *dsmbuf = NULL;
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 static CHAR DSM_Version[] = "DSIK DSM-format";
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
70
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
71
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
72 BOOL DSM_Test(void)
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 UBYTE id[12];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
75
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
76 if(_mm_read_UBYTES((UBYTE *)id,12,modfp)) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
77 if(!memcmp(id,"RIFF",4) && !memcmp(&id[8],"DSMF",4)) return 1;
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 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
80 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
81
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
82
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
83 BOOL DSM_Init(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
84 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
85 if(!(dsmbuf=(DSMNOTE *)_mm_malloc(16*64*sizeof(DSMNOTE)))) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
86 if(!(mh=(DSMSONG *)_mm_calloc(1,sizeof(DSMSONG)))) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
87 return 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
88 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
89
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
90
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
91 void DSM_Cleanup(void)
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 if(dsmbuf!=NULL) free(dsmbuf);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
94 if(mh!=NULL) free(mh);
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 dsmbuf = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
97 mh = NULL;
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
101 BOOL GetBlockHeader(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 // make sure we're at the right position for reading the
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
104 // next riff block, no matter how many bytes read
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
105
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
106 _mm_fseek(modfp, blocklp+blockln, SEEK_SET);
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 while(1)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
109 { _mm_read_UBYTES(blockid,4,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
110 blockln = _mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
111 if(feof(modfp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
112 { _mm_errno = MMERR_LOADING_HEADER;
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 if(memcmp(blockid,SONGID,4) && memcmp(blockid,INSTID,4) && memcmp(blockid,PATTID,4))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
117 { //printf("Skipping unknown block type %4.4s\n",&blockid);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
118 _mm_fseek(modfp, blockln, SEEK_CUR);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
119 } else break;
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
122 blocklp = _mm_ftell(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
123 return 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
124 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
125
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
126
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
127 BOOL DSM_ReadPattern(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
128 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
129 int row=0,flag;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
130 DSMNOTE *n;
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 // clear pattern data
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
133 memset(dsmbuf,255,16*64*sizeof(DSMNOTE));
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
134 _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
135 _mm_read_UBYTE(modfp);
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 while(row<64)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
138 { flag = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
139 if(feof(modfp))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
140 { _mm_errno = MMERR_LOADING_PATTERN;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
141 return 0;
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
144 if(flag)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
145 { n = &dsmbuf[((flag&0xf)*64)+row];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
146 if(flag&0x80) n->note = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
147 if(flag&0x40) n->ins = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
148 if(flag&0x20) n->vol = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
149 if(flag&0x10)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
150 { n->cmd = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
151 n->inf = _mm_read_UBYTE(modfp);
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 } else row++;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
154 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
155 return 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
156 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
157
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
158
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
159 UBYTE *DSM_ConvertTrack(DSMNOTE *tr)
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 int t;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
162 UBYTE note,ins,vol,cmd,inf;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
163
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
164 UniReset();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
165 for(t=0; t<64; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
166 { note = tr[t].note;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
167 ins = tr[t].ins;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
168 vol = tr[t].vol;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
169 cmd = tr[t].cmd;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
170 inf = tr[t].inf;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
171
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
172 if(ins!=0 && ins!=255) UniInstrument(ins-1);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
173 if(note!=255) UniNote(note-1); // <- normal note
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
174 if(vol<65) UniPTEffect(0xc,vol);
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 if(cmd!=255)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
177 { if(cmd==0x8)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
178 { if(inf<=0x80)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
179 { inf = (inf<0x80) ? inf<<1 : 255;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
180 UniPTEffect(cmd,inf);
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 } else if(cmd==0xb)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
183 { if(inf<=0x7f) UniPTEffect(cmd,inf);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
184 } else
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
185 { // Convert pattern jump from Dec to Hex
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
186 if(cmd == 0xd)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
187 inf = (((inf&0xf0)>>4)*10)+(inf&0xf);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
188 UniPTEffect(cmd,inf);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
189 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
190 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
191 UniNewline();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
192 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
193 return UniDup();
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
197 BOOL DSM_Load(void)
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 int t;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
200 DSMINST s;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
201 SAMPLE *q;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
202 int cursmp = 0, curpat = 0, track = 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
203
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
204 blocklp = 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
205 blockln = 12;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
206
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
207 if(!GetBlockHeader()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
208 if(memcmp(blockid,SONGID,4))
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
209 { _mm_errno = MMERR_LOADING_HEADER;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
210 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
211 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
212
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
213 _mm_read_UBYTES(mh->songname,28,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
214 mh->reserved1 = _mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
215 mh->flags = _mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
216 mh->reserved2 = _mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
217 mh->numord = _mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
218 mh->numsmp = _mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
219 mh->numpat = _mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
220 mh->numtrk = _mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
221 mh->globalvol = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
222 mh->mastervol = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
223 mh->speed = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
224 mh->bpm = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
225 _mm_read_UBYTES(mh->panpos,16,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
226 _mm_read_UBYTES(mh->orders,128,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
227
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
228 // set module variables
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
229 of.initspeed = mh->speed;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
230 of.inittempo = mh->bpm;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
231 of.modtype = strdup(DSM_Version);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
232 of.numchn = mh->numtrk;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
233 of.numpat = mh->numpat;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
234 of.numtrk = of.numchn*of.numpat;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
235 of.songname = DupStr(mh->songname,28); // make a cstr of songname
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 for(t=0; t<16; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
238 of.panning[t] = mh->panpos[t]<0x80 ? (mh->panpos[t]<<1) : 255;
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 if(!AllocPositions(mh->numord)) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
241 of.numpos = 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
242 for(t=0; t<mh->numord; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
243 { of.positions[of.numpos] = mh->orders[t];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
244 if(mh->orders[t]<254) of.numpos++;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
245 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
246
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
247 of.numins = of.numsmp = mh->numsmp;
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 if(!AllocSamples()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
250 if(!AllocTracks()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
251 if(!AllocPatterns()) return 0;
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 while(cursmp<of.numins || curpat<of.numpat)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
254 { if(!GetBlockHeader()) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
255 if(!memcmp(blockid,INSTID,4) && cursmp<of.numins)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
256 { q = &of.samples[cursmp];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
257
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
258 // try to read sample info
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
259 _mm_read_UBYTES(s.filename,13,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
260 s.flags = _mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
261 s.volume = _mm_read_UBYTE(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
262 s.length = _mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
263 s.loopstart = _mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
264 s.loopend = _mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
265 s.reserved1 = _mm_read_I_ULONG(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
266 s.c2spd = _mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
267 s.reserved2 = _mm_read_I_UWORD(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
268 _mm_read_UBYTES(s.samplename,28,modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
269
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
270 q->samplename= DupStr(s.samplename,28);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
271 q->seekpos = _mm_ftell(modfp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
272 q->speed = s.c2spd;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
273 q->length = s.length;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
274 q->loopstart = s.loopstart;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
275 q->loopend = s.loopend;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
276 q->volume = s.volume;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
277
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
278 if(s.flags&1) q->flags|=SF_LOOP;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
279 if(s.flags&2) q->flags|=SF_SIGNED;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
280 cursmp++;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
281 } else if(!memcmp(blockid,PATTID,4) && curpat<of.numpat)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
282 { DSM_ReadPattern();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
283 for(t=0; t<of.numchn; t++)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
284 if(!(of.tracks[track++] = DSM_ConvertTrack(&dsmbuf[t*64]))) return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
285 curpat++;
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 }
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 return 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
290 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
291
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
292
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
293 CHAR *DSM_LoadTitle(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
294 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
295 CHAR s[28];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
296
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
297 _mm_fseek(modfp,12,SEEK_SET);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
298 if(!fread(s,28,1,modfp)) return NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
299
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
300 return(DupStr(s,28));
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
303
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
304 MLOADER load_dsm =
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
305 { NULL,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
306 "DSM",
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
307 "Portable DSM loader v0.1",
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
308 DSM_Init,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
309 DSM_Test,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
310 DSM_Load,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
311 DSM_Cleanup,
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
312 DSM_LoadTitle
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