comparison minijss/jloadxm.c @ 1192:8841c7f8c608

Some work on the 0x0102 pattern loader.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 05 Mar 2015 13:32:11 +0200
parents 1f1225b509fb
children 5d20c80df290
comparison
equal deleted inserted replaced
1191:1f1225b509fb 1192:8841c7f8c608
218 } 218 }
219 219
220 220
221 static int jssXMUnpackPattern102(DMResource *inFile, int size, JSSPattern *pattern) 221 static int jssXMUnpackPattern102(DMResource *inFile, int size, JSSPattern *pattern)
222 { 222 {
223 JSSNote *pnote;
224 int row, channel;
225 int orig = size;
226 assert(pattern != NULL);
227
228 pnote = pattern->data;
229
230 for (row = 0; row < pattern->nrows && size > 0; row++)
231 for (channel = 0; channel < pattern->nchannels && size > 0; channel++)
232 {
233 int packb, tmp;
234 JSGETBYTE(packb);
235 if (packb & 0x80)
236 {
237 if (packb & 0x01)
238 {
239 // PACK 0x01: Read note
240 JSGETBYTE(tmp);
241 pnote->note = jssXMConvertNote(tmp);
242 }
243
244 if (packb & 0x02)
245 {
246 // PACK 0x02: Read instrument
247 JSGETBYTE(tmp);
248 pnote->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet;
249 }
250
251 if (packb & 0x04)
252 {
253 // PACK 0x04: Read volume
254 JSGETBYTE(tmp);
255 pnote->volume = (tmp >= 0x10) ? tmp - 0x10 : jsetNotSet;
256 }
257
258 if (packb & 0x08)
259 {
260 // PACK 0x08: Read effect
261 JSGETBYTE(pnote->effect);
262 pnote->param = 0;
263 }
264
265 if (packb & 0x10)
266 {
267 // PACK 0x10: Read effect parameter
268 JSGETBYTE(pnote->param);
269 if (pnote->effect == jsetNotSet && pnote->param != 0)
270 pnote->effect = 0;
271 }
272 }
273 else
274 {
275 // All data available
276 pnote->note = jssXMConvertNote(packb & 0x7f);
277
278 // Get instrument
279 JSGETBYTE(tmp);
280 pnote->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet;
281
282 // Get volume
283 JSGETBYTE(tmp);
284 pnote->volume = (tmp >= 0x10) ? tmp - 0x10 : jsetNotSet;
285
286 if (tmp & 0xc0)
287 {
288 JSGETBYTE(pnote->effect);
289 JSGETBYTE(pnote->param);
290 }
291 else
292 {
293 JSGETBYTE(pnote->param);
294 pnote->effect = tmp & 0xf;
295 }
296
297 if (pnote->effect == 0 && pnote->param == 0)
298 pnote->effect = pnote->param = jsetNotSet;
299 }
300 pnote++;
301 }
223 302
224 // Check the state 303 // Check the state
225 if (size > 0) 304 if (size > 0)
226 { 305 {
227 // Some data left unparsed 306 // Some data left unparsed