Mercurial > hg > dmlib
annotate minijss/jloadjss.c @ 2299:ad019d930401
Add initial (broken) read support for Flinterlazer 1.0 images.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 04 Jul 2019 11:09:51 +0300 |
parents | fc58f62f100c |
children | dcf1016f3d27 |
rev | line source |
---|---|
0 | 1 /* |
2 * miniJSS - JSSMOD module loader | |
3 * Programmed and designed by Matti 'ccr' Hamalainen | |
2279 | 4 * (C) Copyright 2007-2019 Tecnic Software productions (TNSP) |
0 | 5 */ |
6 #include "jssmod.h" | |
7 | |
8 | |
1196 | 9 // If all pattern modes are required, enable them here |
0 | 10 #ifdef JM_SUP_PATMODE_ALL |
282 | 11 # define JM_SUP_PATMODE_1 1 |
12 # define JM_SUP_PATMODE_2 1 | |
13 # define JM_SUP_PATMODE_3 1 | |
14 # define JM_SUP_PATMODE_4 1 | |
15 # define JM_SUP_PATMODE_5 1 | |
0 | 16 #endif |
17 | |
18 | |
2278
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
19 static inline JSSNote * jssGetNotePtr(JSSPattern *pattern, const int channel, const int row) |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
20 { |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
21 return pattern->data + (pattern->nchannels * row) + pattern->map[channel]; |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
22 } |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
23 |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
24 |
1196 | 25 // Short helper macros for reading data |
26 #define JSGETBYTE(XV) \ | |
27 if (!dmf_read_byte(inFile, XV)) \ | |
28 return DMERR_OUT_OF_DATA | |
0 | 29 |
30 | |
2278
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
31 static int jssDoGetConvertedNote(DMResource *inFile, JSSNote *pnote, const Uint8 note) |
0 | 32 { |
33 Uint8 tmp; | |
34 | |
1208
fa758951720f
Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1198
diff
changeset
|
35 if (note == 127) |
1197 | 36 pnote->note = jsetNoteOff; |
1208
fa758951720f
Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1198
diff
changeset
|
37 else |
fa758951720f
Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1198
diff
changeset
|
38 if (note == 0) |
1197 | 39 pnote->note = jsetNotSet; |
0 | 40 else |
1208
fa758951720f
Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1198
diff
changeset
|
41 pnote->note = note - 1; |
0 | 42 |
43 JSGETBYTE(&tmp); | |
1197 | 44 pnote->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet; |
0 | 45 |
46 JSGETBYTE(&tmp); | |
1197 | 47 pnote->volume = (tmp > 0) ? tmp - 1 : jsetNotSet; |
0 | 48 |
49 JSGETBYTE(&tmp); | |
1197 | 50 pnote->effect = (tmp > 0) ? tmp - 1 : jsetNotSet; |
0 | 51 |
52 JSGETBYTE(&tmp); | |
1197 | 53 pnote->param = (tmp == 0 && pnote->effect == jsetNotSet) ? jsetNotSet : tmp; |
0 | 54 |
55 return DMERR_OK; | |
56 } | |
1208
fa758951720f
Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1198
diff
changeset
|
57 |
fa758951720f
Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1198
diff
changeset
|
58 |
2278
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
59 static inline int jssGetConvertedNote(DMResource *inFile, |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
60 JSSPattern *pattern, const int channel, const int row) |
1208
fa758951720f
Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1198
diff
changeset
|
61 { |
fa758951720f
Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1198
diff
changeset
|
62 Uint8 tmp; |
2278
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
63 int res; |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
64 |
1208
fa758951720f
Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1198
diff
changeset
|
65 JSGETBYTE(&tmp); |
2278
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
66 if ((res = jssDoGetConvertedNote(inFile, |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
67 jssGetNotePtr(pattern, channel, row), tmp)) != DMERR_OK) |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
68 JSSERROR(res, res, "Error converting note on row=%d, chn=%d\n", |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
69 row, channel); |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
70 |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
71 return res; |
1208
fa758951720f
Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1198
diff
changeset
|
72 } |
0 | 73 |
74 | |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
75 #if defined(JM_SUP_PATMODE_2) || defined(JM_SUP_PATMODE_4) |
2278
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
76 static int jssGetCompressedNoteDo(DMResource *inFile, |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
77 JSSPattern *pattern, const int channel, const int row) |
0 | 78 { |
2278
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
79 JSSNote *pnote = jssGetNotePtr(pattern, channel, row); |
0 | 80 Uint8 packb, tmp; |
2278
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
81 int res = DMERR_OK; |
0 | 82 |
83 JSGETBYTE(&packb); | |
84 if (packb & 0x80) | |
85 { | |
1210
6b48bad13399
Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1208
diff
changeset
|
86 if (packb & JM_COMP_NOTE) |
0 | 87 { |
88 JSGETBYTE(&tmp); | |
89 if (tmp == 127) | |
1197 | 90 pnote->note = jsetNoteOff; |
0 | 91 else |
1197 | 92 pnote->note = tmp; |
0 | 93 } |
94 | |
1210
6b48bad13399
Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1208
diff
changeset
|
95 if (packb & JM_COMP_INSTRUMENT) |
0 | 96 { |
97 JSGETBYTE(&tmp); | |
1197 | 98 pnote->instrument = tmp; |
0 | 99 } |
100 | |
1210
6b48bad13399
Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1208
diff
changeset
|
101 if (packb & JM_COMP_VOLUME) |
0 | 102 { |
103 JSGETBYTE(&tmp); | |
1197 | 104 pnote->volume = tmp; |
0 | 105 } |
106 | |
1210
6b48bad13399
Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1208
diff
changeset
|
107 if (packb & JM_COMP_EFFECT) |
0 | 108 { |
109 JSGETBYTE(&tmp); | |
1197 | 110 pnote->effect = tmp; |
111 pnote->param = 0; | |
0 | 112 } |
113 | |
1210
6b48bad13399
Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1208
diff
changeset
|
114 if (packb & JM_COMP_PARAM) |
0 | 115 { |
116 JSGETBYTE(&tmp); | |
1197 | 117 pnote->param = tmp; |
0 | 118 } |
119 } | |
120 else | |
121 { | |
2278
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
122 res = jssDoGetConvertedNote(inFile, pnote, packb); |
0 | 123 } |
124 | |
2278
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
125 return res; |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
126 } |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
127 |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
128 |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
129 static int jssGetCompressedNote(DMResource *inFile, |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
130 JSSPattern *pattern, const int channel, const int row) |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
131 { |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
132 int res = jssGetCompressedNoteDo(inFile, pattern, channel, row); |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
133 |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
134 if (res != DMERR_OK) |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
135 JSSERROR(res, res, "Error uncompressing note on row=%d, chn=%d\n", |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
136 row, channel); |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
137 |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
138 return res; |
0 | 139 } |
140 #endif | |
141 | |
142 | |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
143 #ifdef JM_SUP_PATMODE_2 |
777
ed60a7ee3ebb
Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
144 static int jssGetPatternCompHoriz(DMResource *inFile, JSSPattern *pattern) |
0 | 145 { |
2278
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
146 for (int row = 0; row < pattern->nrows; row++) |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
147 for (int channel = 0; channel < pattern->nmap; channel++) |
0 | 148 { |
2278
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
149 int res = jssGetCompressedNote(inFile, pattern, channel, row); |
0 | 150 if (res != DMERR_OK) |
2278
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
151 return res; |
0 | 152 } |
153 | |
154 return DMERR_OK; | |
155 } | |
156 #endif | |
157 | |
158 | |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
159 #ifdef JM_SUP_PATMODE_4 |
777
ed60a7ee3ebb
Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
160 static int jssGetPatternCompVert(DMResource *inFile, JSSPattern *pattern) |
0 | 161 { |
2278
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
162 for (int channel = 0; channel < pattern->nmap; channel++) |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
163 for (int row = 0; row < pattern->nrows; row++) |
0 | 164 { |
2278
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
165 int res = jssGetCompressedNote(inFile, pattern, channel, row); |
0 | 166 if (res != DMERR_OK) |
2278
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
167 return res; |
0 | 168 } |
169 | |
170 return DMERR_OK; | |
171 } | |
172 #endif | |
173 | |
174 | |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
175 #ifdef JM_SUP_PATMODE_1 |
777
ed60a7ee3ebb
Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
176 static int jssGetPatternRawHoriz(DMResource *inFile, JSSPattern *pattern) |
0 | 177 { |
2278
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
178 for (int row = 0; row < pattern->nrows; row++) |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
179 for (int channel = 0; channel < pattern->nmap; channel++) |
0 | 180 { |
2278
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
181 int res = jssGetConvertedNote(inFile, pattern, channel, row); |
0 | 182 if (res != DMERR_OK) |
2278
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
183 return res; |
0 | 184 } |
185 | |
186 return DMERR_OK; | |
187 } | |
188 #endif | |
189 | |
190 | |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
191 #ifdef JM_SUP_PATMODE_3 |
777
ed60a7ee3ebb
Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
192 static int jssGetPatternRawVert(DMResource *inFile, JSSPattern *pattern) |
0 | 193 { |
2278
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
194 for (int channel = 0; channel < pattern->nmap; channel++) |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
195 for (int row = 0; row < pattern->nrows; row++) |
0 | 196 { |
2278
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
197 int res = jssGetConvertedNote(inFile, pattern, channel, row); |
0 | 198 if (res != DMERR_OK) |
2278
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
199 return res; |
0 | 200 } |
201 | |
202 return DMERR_OK; | |
203 } | |
204 #endif | |
205 | |
206 | |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
207 #ifdef JM_SUP_PATMODE_5 |
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
208 |
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
209 #undef JSGETBYTE |
777
ed60a7ee3ebb
Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
210 #define JSGETBYTE(XV) if (!dmf_read_byte(inFile, XV)) return DMERR_OUT_OF_DATA |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
211 |
2278
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
212 #define JSFOREACHNOTE1 \ |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
213 for (int channel = 0; channel < pattern->nmap; channel++) \ |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
214 for (int row = 0; row < pattern->nrows; row++) { \ |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
215 JSSNote *pnote = pattern->data + (pattern->nchannels * row) + pattern->map[channel]; |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
216 |
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
217 #define JSFOREACHNOTE2 } |
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
218 |
2278
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
219 |
777
ed60a7ee3ebb
Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
220 static int jssGetPatternRawVertElem(DMResource *inFile, JSSPattern *pattern) |
0 | 221 { |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
222 Uint8 tmp; |
0 | 223 |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
224 JSFOREACHNOTE1 |
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
225 JSGETBYTE(&tmp); |
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
226 if (tmp == 0) |
1197 | 227 pnote->note = jsetNotSet; |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
228 else if (tmp == 127) |
1197 | 229 pnote->note = jsetNoteOff; |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
230 else |
1197 | 231 pnote->note = tmp - 1; |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
232 JSFOREACHNOTE2 |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1118
diff
changeset
|
233 |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
234 JSFOREACHNOTE1 |
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
235 JSGETBYTE(&tmp); |
1197 | 236 pnote->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet; |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
237 JSFOREACHNOTE2 |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1118
diff
changeset
|
238 |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
239 JSFOREACHNOTE1 |
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
240 JSGETBYTE(&tmp); |
1197 | 241 pnote->volume = (tmp > 0) ? tmp - 1 : jsetNotSet; |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
242 JSFOREACHNOTE2 |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1118
diff
changeset
|
243 |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
244 JSFOREACHNOTE1 |
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
245 JSGETBYTE(&tmp); |
1197 | 246 pnote->effect = (tmp > 0) ? tmp - 1 : jsetNotSet; |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
247 JSFOREACHNOTE2 |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1118
diff
changeset
|
248 |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
249 JSFOREACHNOTE1 |
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
250 JSGETBYTE(&tmp); |
1197 | 251 pnote->param = (tmp == 0 && pnote->effect == jsetNotSet) ? jsetNotSet : tmp; |
204
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
252 JSFOREACHNOTE2 |
d3a9a3804079
Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
253 |
0 | 254 return DMERR_OK; |
255 } | |
256 #endif | |
257 | |
258 | |
259 #ifdef JM_SUP_EXT_INSTR | |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
260 static int jssMODLoadEnvelope(DMResource *inFile, |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
261 JSSEnvelope *env, const char *name, const int ninst) |
0 | 262 { |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
263 JSSMODEnvelope jssEnv; |
0 | 264 |
1350
dcb5c16ecdb9
Silence warnings about unused function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1349
diff
changeset
|
265 (void) name; |
dcb5c16ecdb9
Silence warnings about unused function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1349
diff
changeset
|
266 (void) ninst; |
dcb5c16ecdb9
Silence warnings about unused function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1349
diff
changeset
|
267 |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
268 // Read envelope data |
1250
99852310dc02
Some more work on the loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1247
diff
changeset
|
269 if (!dmf_read_byte(inFile, &jssEnv.flags) || |
99852310dc02
Some more work on the loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1247
diff
changeset
|
270 !dmf_read_byte(inFile, &jssEnv.npoints) || |
99852310dc02
Some more work on the loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1247
diff
changeset
|
271 !dmf_read_byte(inFile, &jssEnv.sustain) || |
99852310dc02
Some more work on the loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1247
diff
changeset
|
272 !dmf_read_byte(inFile, &jssEnv.loopS) || |
99852310dc02
Some more work on the loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1247
diff
changeset
|
273 !dmf_read_byte(inFile, &jssEnv.loopE)) |
1314 | 274 { |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
275 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
276 "Failed to read %s-envelope data for instrument #%d.\n", |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
277 name, ninst); |
1314 | 278 } |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
279 |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
280 // Do some sanity checking |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
281 if (jssEnv.npoints > jsetMaxEnvPoints || |
1331
c0479e984242
Fix a envelope "sanity check" in jmod loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1316
diff
changeset
|
282 jssEnv.loopS > jssEnv.loopE || |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
283 jssEnv.loopS > jssEnv.npoints || |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
284 jssEnv.loopE > jssEnv.npoints) |
1314 | 285 { |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
286 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
287 "Invalid values in %s-envelope for instrument #%d.\n", |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
288 name, ninst); |
1314 | 289 } |
0 | 290 |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
291 // Copy data |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
292 env->flags = jssEnv.flags; |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
293 env->npoints = jssEnv.npoints; |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
294 env->sustain = jssEnv.sustain; |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
295 env->loopS = jssEnv.loopS; |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
296 env->loopE = jssEnv.loopE; |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
297 |
1314 | 298 for (int i = 0; i < jssEnv.npoints; i++) |
0 | 299 { |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
300 Uint16 frame, value; |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
301 if (!dmf_read_le16(inFile, &frame) || |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
302 !dmf_read_le16(inFile, &value)) |
1314 | 303 { |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
304 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
305 "Failed to read %s-envelope values (%d) for instrument #%d.\n", |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
306 name, i, ninst); |
1314 | 307 } |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
308 |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
309 env->points[i].frame = frame; |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
310 env->points[i].value = value; |
0 | 311 } |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
312 |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
313 return DMERR_OK; |
0 | 314 } |
315 #endif | |
316 | |
317 | |
1256 | 318 int jssLoadJSSMOD(DMResource *inFile, JSSModule **pmodule, BOOL probe) |
0 | 319 { |
320 JSSModule *module; | |
321 JSSMODHeader jssH; | |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
322 int index, ret = DMERR_OK; |
0 | 323 |
1256 | 324 *pmodule = NULL; |
0 | 325 |
326 // Check the JSSMOD header | |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
327 if (!dmf_read_str(inFile, &jssH.idMagic, sizeof(jssH.idMagic)) || |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
328 !dmf_read_byte(inFile, &jssH.idVersion)) |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
329 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
330 "Failed to read JSSMOD header #1.\n"); |
0 | 331 |
332 if (memcmp(jssH.idMagic, "JM", 2) != 0) | |
333 { | |
796 | 334 if (probe) |
335 return DMERR_NOT_SUPPORTED; | |
336 else | |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1271
diff
changeset
|
337 { |
796 | 338 JSSERROR(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED, |
339 "Not a JSSMOD file, header signature mismatch!\n"); | |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1271
diff
changeset
|
340 } |
0 | 341 } |
342 | |
343 if (jssH.idVersion != JSSMOD_VERSION) | |
344 { | |
1198 | 345 if (probe) |
346 return DMERR_VERSION; | |
347 else | |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1271
diff
changeset
|
348 { |
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1271
diff
changeset
|
349 JSSERROR(DMERR_VERSION, DMERR_VERSION, |
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1271
diff
changeset
|
350 "Unsupported version of JSSMOD 0x%2x, this version only supports 0x%2x!\n", |
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1271
diff
changeset
|
351 jssH.idVersion, JSSMOD_VERSION); |
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1271
diff
changeset
|
352 } |
0 | 353 } |
354 | |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
355 // Read rest of the header |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
356 if (!dmf_read_le16(inFile, &jssH.defFlags) || |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
357 !dmf_read_le16(inFile, &jssH.intVersion) || |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
358 !dmf_read_le16(inFile, &jssH.norders) || |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
359 !dmf_read_le16(inFile, &jssH.npatterns) || |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
360 !dmf_read_le16(inFile, &jssH.nextInstruments) || |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
361 !dmf_read_le16(inFile, &jssH.ninstruments) || |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
362 !dmf_read_le16(inFile, &jssH.defRestartPos) || |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1271
diff
changeset
|
363 |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
364 !dmf_read_byte(inFile, &jssH.nchannels) || |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
365 !dmf_read_byte(inFile, &jssH.defSpeed) || |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
366 !dmf_read_byte(inFile, &jssH.defTempo) || |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
367 !dmf_read_byte(inFile, &jssH.patMode)) |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1271
diff
changeset
|
368 { |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
369 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
370 "Failed to read JSSMOD header #2.\n"); |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1271
diff
changeset
|
371 } |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
372 |
1198 | 373 if (probe) |
374 return DMERR_OK; | |
375 | |
1218
30c2dbf05841
Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents:
1214
diff
changeset
|
376 // Check some of the things for sanity |
30c2dbf05841
Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents:
1214
diff
changeset
|
377 if (jssH.nchannels > jsetMaxChannels || |
30c2dbf05841
Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents:
1214
diff
changeset
|
378 jssH.nchannels == 0 || |
30c2dbf05841
Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents:
1214
diff
changeset
|
379 jssH.norders > jsetMaxOrders || |
30c2dbf05841
Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents:
1214
diff
changeset
|
380 jssH.npatterns > jsetMaxPatterns || |
30c2dbf05841
Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents:
1214
diff
changeset
|
381 jssH.nextInstruments > jsetMaxInstruments || |
30c2dbf05841
Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents:
1214
diff
changeset
|
382 jssH.ninstruments > jsetMaxInstruments) |
30c2dbf05841
Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents:
1214
diff
changeset
|
383 { |
30c2dbf05841
Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents:
1214
diff
changeset
|
384 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
30c2dbf05841
Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents:
1214
diff
changeset
|
385 "Invalid values in JSSMOD header.\n"); |
30c2dbf05841
Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents:
1214
diff
changeset
|
386 } |
30c2dbf05841
Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents:
1214
diff
changeset
|
387 |
0 | 388 // Allocate the module |
1256 | 389 if ((*pmodule = module = jssAllocateModule()) == NULL) |
0 | 390 { |
391 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, | |
392 "Could not allocate memory for module structure.\n"); | |
393 } | |
394 | |
395 // Copy header information | |
1216 | 396 module->defFlags = jssH.defFlags; |
397 module->intVersion = jssH.intVersion; | |
398 | |
0 | 399 module->norders = jssH.norders; |
400 module->npatterns = jssH.npatterns; | |
401 module->nchannels = jssH.nchannels; | |
402 module->nextInstruments = jssH.nextInstruments; | |
403 module->ninstruments = jssH.ninstruments; | |
404 module->defRestartPos = jssH.defRestartPos; | |
405 module->defSpeed = jssH.defSpeed; | |
406 module->defTempo = jssH.defTempo; | |
407 | |
408 // Get the orders list | |
409 for (index = 0; index < module->norders; index++) | |
410 { | |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
411 Uint16 tmp; |
1250
99852310dc02
Some more work on the loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1247
diff
changeset
|
412 if (!dmf_read_le16(inFile, &tmp)) |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
413 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
414 "Failed to read orders list entry #%d.\n", |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
415 index); |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
416 |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
417 if (tmp != 0xffff && tmp > jssH.npatterns) |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
418 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
419 "Invalid orders list entry #%d value %d > %d.\n", |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
420 index, tmp, jssH.npatterns); |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
421 |
1311 | 422 module->orderList[index] = (tmp == 0xffff) ? jsetNotSet : tmp; |
0 | 423 } |
424 | |
425 // Parse the patterns | |
426 for (index = 0; index < module->npatterns; index++) | |
427 { | |
1255
f9bf71071f0b
Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1250
diff
changeset
|
428 JSSPattern *pattern; |
0 | 429 JSSMODPattern jssP; |
430 | |
1255
f9bf71071f0b
Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1250
diff
changeset
|
431 // Read pattern header |
f9bf71071f0b
Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1250
diff
changeset
|
432 if (!dmf_read_le32(inFile, &jssP.size) || |
2278
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
433 !dmf_read_le16(inFile, &jssP.nrows) || |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
434 !dmf_read_le16(inFile, &jssP.nchannels)) |
1255
f9bf71071f0b
Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1250
diff
changeset
|
435 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
f9bf71071f0b
Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1250
diff
changeset
|
436 "Failed to read JSSMOD pattern header #%d.\n", |
f9bf71071f0b
Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1250
diff
changeset
|
437 index); |
f9bf71071f0b
Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1250
diff
changeset
|
438 |
f9bf71071f0b
Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1250
diff
changeset
|
439 // Validate |
f9bf71071f0b
Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1250
diff
changeset
|
440 if (jssP.nrows == 0 || jssP.nrows > jsetMaxRows) |
f9bf71071f0b
Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1250
diff
changeset
|
441 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
f9bf71071f0b
Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1250
diff
changeset
|
442 "Invalid number of rows in pattern #%d: %d.\n", |
1257 | 443 index, jssP.nrows); |
0 | 444 |
2278
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
445 if (jssP.nchannels == 0 || jssP.nchannels > module->nchannels) |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
446 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
447 "Invalid number of channels in pattern #%d: %d.\n", |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
448 index, jssP.nchannels); |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
449 |
0 | 450 // Allocate pattern |
1255
f9bf71071f0b
Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1250
diff
changeset
|
451 pattern = module->patterns[index] = jssAllocatePattern(jssP.nrows, module->nchannels); |
f9bf71071f0b
Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1250
diff
changeset
|
452 if (pattern == NULL) |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1271
diff
changeset
|
453 { |
0 | 454 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, |
1212 | 455 "Could not allocate memory for pattern #%d.\n", |
456 index); | |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1271
diff
changeset
|
457 } |
0 | 458 |
2278
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
459 // Read channel mappings, if any |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
460 pattern->nmap = jssP.nchannels; |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
461 if (jssP.nchannels != module->nchannels) |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
462 { |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
463 if (!dmf_read_str(inFile, pattern->map, |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
464 sizeof(pattern->map[0]) * jssP.nchannels)) |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
465 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
466 "Failed to read JSSMOD channel mapping data for pattern #%d.\n", |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
467 index); |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
468 |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
469 // Check mapping |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
470 for (int nch = 0; nch < jssP.nchannels; nch++) |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
471 { |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
472 if (pattern->map[nch] >= module->nchannels) |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
473 { |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
474 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
475 "Invalid channel mapping in pattern #%d: chn %d -> %d.\n", |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
476 index, nch, pattern->map[nch]); |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
477 } |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
478 } |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
479 } |
40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents:
1817
diff
changeset
|
480 |
0 | 481 // Get pattern data |
482 switch (jssH.patMode) | |
483 { | |
484 #ifdef JM_SUP_PATMODE_1 | |
485 case PATMODE_RAW_HORIZ: | |
1255
f9bf71071f0b
Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1250
diff
changeset
|
486 ret = jssGetPatternRawHoriz(inFile, pattern); |
0 | 487 break; |
488 #endif | |
489 #ifdef JM_SUP_PATMODE_2 | |
490 case PATMODE_COMP_HORIZ: | |
1255
f9bf71071f0b
Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1250
diff
changeset
|
491 ret = jssGetPatternCompHoriz(inFile, pattern); |
0 | 492 break; |
493 #endif | |
494 #ifdef JM_SUP_PATMODE_3 | |
495 case PATMODE_RAW_VERT: | |
1255
f9bf71071f0b
Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1250
diff
changeset
|
496 ret = jssGetPatternRawVert(inFile, pattern); |
0 | 497 break; |
498 #endif | |
499 #ifdef JM_SUP_PATMODE_4 | |
500 case PATMODE_COMP_VERT: | |
1255
f9bf71071f0b
Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1250
diff
changeset
|
501 ret = jssGetPatternCompVert(inFile, pattern); |
0 | 502 break; |
503 #endif | |
504 #ifdef JM_SUP_PATMODE_5 | |
505 case PATMODE_RAW_ELEM: | |
1255
f9bf71071f0b
Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1250
diff
changeset
|
506 ret = jssGetPatternRawVertElem(inFile, pattern); |
0 | 507 break; |
508 #endif | |
509 default: | |
510 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | |
1212 | 511 "Unsupported pattern mode %d. Check compilation options.", |
512 jssH.patMode); | |
0 | 513 break; |
514 } | |
515 | |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
516 if (ret != DMERR_OK) |
0 | 517 { |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
518 JSSERROR(ret, ret, |
1212 | 519 "Error in unpacking pattern #%d data.\n", |
520 index); | |
0 | 521 } |
522 } | |
523 | |
524 #ifdef JM_SUP_EXT_INSTR | |
525 // Read extended instruments | |
526 for (index = 0; index < module->nextInstruments; index++) | |
527 { | |
528 JSSMODExtInstrument jssE; | |
529 JSSExtInstrument *einst; | |
530 int i; | |
531 | |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
532 // Read header data |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
533 if (!dmf_read_byte(inFile, &jssE.nsamples) || |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
534 !dmf_read_byte(inFile, &jssE.vibratoType) || |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
535 !dmf_read_le16(inFile, &jssE.vibratoSweep) || |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
536 !dmf_read_le16(inFile, &jssE.vibratoDepth) || |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
537 !dmf_read_le16(inFile, &jssE.vibratoRate) || |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
538 !dmf_read_le16(inFile, &jssE.fadeOut)) |
1271 | 539 { |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
540 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
541 "Failed to read ext.instrument #%d header.\n", |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
542 index); |
1271 | 543 } |
1817 | 544 |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
545 // Allocate instrument |
1311 | 546 einst = module->extInstruments[index] = jssAllocateExtInstrument(); |
547 if (einst == NULL) | |
0 | 548 { |
549 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, | |
1214 | 550 "Could not allocate extended instrument structure #%d\n", index); |
0 | 551 } |
552 | |
553 einst->nsamples = jssE.nsamples; | |
554 einst->vibratoType = jssE.vibratoType; | |
555 einst->vibratoSweep = jssE.vibratoSweep; | |
556 einst->vibratoDepth = jssE.vibratoDepth; | |
557 einst->vibratoRate = jssE.vibratoRate; | |
558 einst->fadeOut = jssE.fadeOut; | |
559 | |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
560 // Read and somewhat validate sNumForNotes |
0 | 561 for (i = 0; i < jsetNNotes; i++) |
562 { | |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
563 int snum; |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
564 Uint32 tmp; |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
565 |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
566 if (!dmf_read_le32(inFile, &tmp)) |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
567 { |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
568 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
569 "Failed to read ext.instrument #%d sNumForNotes[%d].\n", |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
570 index, i); |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
571 } |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
572 |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
573 einst->sNumForNotes[i] = snum = (tmp > 0) ? ((int) tmp - 1) : jsetNotSet; |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
574 |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
575 if (snum != jsetNotSet && snum > module->ninstruments) |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
576 { |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
577 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
578 "Ext.instrument #%d has invalid sNumForNotes[%d] = %d > %d max.\n", |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
579 index, i, snum, module->ninstruments); |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
580 } |
0 | 581 } |
582 | |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
583 // Read and validate envelopes |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
584 if ((ret = jssMODLoadEnvelope(inFile, &einst->volumeEnv, "volume", index)) != DMERR_OK || |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
585 (ret = jssMODLoadEnvelope(inFile, &einst->panningEnv, "panning", index)) != DMERR_OK) |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
586 return ret; |
0 | 587 } |
588 | |
589 #ifdef JM_SUP_INSTR | |
590 // Read sample instrument headers | |
591 for (index = 0; index < module->ninstruments; index++) | |
592 { | |
593 JSSMODInstrument jssI; | |
594 JSSInstrument *inst; | |
595 | |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
596 // Read header data |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
597 if (!dmf_read_le32(inFile, &jssI.size) || |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
598 !dmf_read_le32(inFile, &jssI.loopS) || |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
599 !dmf_read_le32(inFile, &jssI.loopE) || |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
600 !dmf_read_le16(inFile, &jssI.flags) || |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
601 !dmf_read_le16(inFile, &jssI.C4BaseSpeed) || |
1349
5adf67d1dea4
Fix loading of instrument relative note, finetune and panning values, which should be signed.
Matti Hamalainen <ccr@tnsp.org>
parents:
1331
diff
changeset
|
602 !dmf_read_le16(inFile, (Uint16 *) &jssI.ERelNote) || |
5adf67d1dea4
Fix loading of instrument relative note, finetune and panning values, which should be signed.
Matti Hamalainen <ccr@tnsp.org>
parents:
1331
diff
changeset
|
603 !dmf_read_le16(inFile, (Uint16 *) &jssI.EFineTune) || |
5adf67d1dea4
Fix loading of instrument relative note, finetune and panning values, which should be signed.
Matti Hamalainen <ccr@tnsp.org>
parents:
1331
diff
changeset
|
604 !dmf_read_le16(inFile, (Uint16 *) &jssI.EPanning) || |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
605 !dmf_read_byte(inFile, &jssI.volume) || |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
606 !dmf_read_byte(inFile, &jssI.convFlags)) |
0 | 607 { |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
608 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
609 "Failed to read sample instrument #%d header.\n", |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
610 index); |
0 | 611 } |
612 | |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
613 // Validate what we can |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
614 if (jssI.loopS > jssI.size || |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
615 jssI.loopE > jssI.size || |
1311 | 616 jssI.loopS > jssI.loopE) |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
617 { |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
618 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
619 "Invalid or corrupted sample instrument #%d.\n", |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
620 index); |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
621 } |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
622 |
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
623 // Allocate instrument |
1311 | 624 inst = module->instruments[index] = jssAllocateInstrument(); |
625 if (inst == NULL) | |
626 { | |
627 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, | |
628 "Could not allocate sample instrument structure #%d\n", | |
629 index); | |
630 } | |
0 | 631 |
1231 | 632 // Copy data |
0 | 633 inst->size = jssI.size; |
634 inst->loopS = jssI.loopS; | |
635 inst->loopE = jssI.loopE; | |
636 inst->flags = jssI.flags; | |
637 inst->C4BaseSpeed = jssI.C4BaseSpeed; | |
638 inst->ERelNote = jssI.ERelNote; | |
639 inst->EFineTune = jssI.EFineTune; | |
640 inst->EPanning = jssI.EPanning; | |
1247
5ae2ce21c7ae
Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
641 inst->volume = jssI.volume; |
0 | 642 inst->convFlags = jssI.convFlags; |
643 } | |
644 | |
645 #ifdef JM_SUP_SAMPLES | |
646 // Read sample data | |
647 for (index = 0; index < module->ninstruments; index++) | |
648 { | |
649 JSSInstrument *inst = module->instruments[index]; | |
1312 | 650 if (inst != NULL && (inst->convFlags & jsampHasData) != 0) |
0 | 651 { |
1129
e466d10dae6d
Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
652 int ret; |
1213
505317227ab4
Rename variable, improve two error messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1212
diff
changeset
|
653 size_t bsize = (inst->flags & jsf16bit) ? sizeof(Uint16) : sizeof(Uint8); |
505317227ab4
Rename variable, improve two error messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1212
diff
changeset
|
654 bsize *= inst->size; |
0 | 655 |
1316 | 656 // Allocate sample data memory |
1213
505317227ab4
Rename variable, improve two error messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1212
diff
changeset
|
657 if ((inst->data = dmMalloc(bsize)) == NULL) |
0 | 658 { |
659 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, | |
1213
505317227ab4
Rename variable, improve two error messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1212
diff
changeset
|
660 "Could not allocate %d bytes of sample data #%d\n", |
505317227ab4
Rename variable, improve two error messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1212
diff
changeset
|
661 bsize, index); |
0 | 662 } |
663 | |
1316 | 664 // Read data |
1213
505317227ab4
Rename variable, improve two error messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1212
diff
changeset
|
665 if (!dmf_read_str(inFile, inst->data, bsize)) |
777
ed60a7ee3ebb
Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
666 { |
ed60a7ee3ebb
Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
667 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
1213
505317227ab4
Rename variable, improve two error messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1212
diff
changeset
|
668 "Could not read %d bytes of sample data for #%d\n", |
505317227ab4
Rename variable, improve two error messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1212
diff
changeset
|
669 bsize, index); |
777
ed60a7ee3ebb
Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
670 } |
0 | 671 |
672 // Convert, if needed | |
673 if (inst->flags & jsf16bit) | |
1129
e466d10dae6d
Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
674 ret = jssDecodeSample16(inst->data, inst->size, inst->convFlags); |
0 | 675 else |
1129
e466d10dae6d
Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
676 ret = jssDecodeSample8(inst->data, inst->size, inst->convFlags); |
e466d10dae6d
Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
677 |
e466d10dae6d
Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
678 if (ret != DMERR_OK) |
e466d10dae6d
Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
679 { |
e466d10dae6d
Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
680 JSSERROR(ret, ret, |
e466d10dae6d
Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
681 "Failed to decode sample data for #%d\n", index); |
e466d10dae6d
Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
682 } |
0 | 683 } |
684 } | |
685 #else | |
282 | 686 # warning Not including JSSMOD sample loading! |
0 | 687 #endif // JM_SUP_SAMPLES |
688 #else | |
282 | 689 # warning Not including JSSMOD instrument loading! |
0 | 690 #endif // JM_SUP_INSTR |
691 #else | |
282 | 692 # warning Not including JSSMOD ext.instrument loading! |
0 | 693 #endif // JM_SUP_EXT_INSTR |
694 | |
695 return DMERR_OK; | |
696 } |