comparison src/xs_sidplay1.cpp @ 869:3a9bf45178ff

Use xs_fload_buffer() again, to support potential VFS backends.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 09 Nov 2012 04:00:27 +0200
parents 011ba70e271e
children a5b118c853f5
comparison
equal deleted inserted replaced
868:3c3569894b23 869:3a9bf45178ff
319 319
320 /* Load a given SID-tune file 320 /* Load a given SID-tune file
321 */ 321 */
322 gboolean xs_sidplay1_load(XSEngineState * state, gchar * filename) 322 gboolean xs_sidplay1_load(XSEngineState * state, gchar * filename)
323 { 323 {
324 XSSIDPlay1 *engine; 324 XSSIDPlay1 *engine = (XSSIDPlay1 *) state->internal;
325 assert(state); 325 gboolean res = FALSE;
326 326 guint8 *buf = NULL;
327 engine = (XSSIDPlay1 *) state->internal; 327 size_t bufSize;
328
328 if (!engine) 329 if (!engine)
329 return FALSE; 330 return FALSE;
330 331
331 if (!filename) 332 if (!xs_fload_buffer(filename, &buf, &bufSize, XS_SIDBUF_SIZE, TRUE))
332 return FALSE; 333 goto error;
333 334
334 if (!engine->tune->open(filename)) 335 if (!engine->tune->load(buf, bufSize))
335 return FALSE; 336 {
336 337 xs_error("could not initialize tune from buffer, %p:%d '%s'.\n",
337 return TRUE; 338 buf, bufSize, filename);
339 goto error;
340 }
341
342 res = TRUE;
343
344 error:
345 g_free(buf);
346 return res;
338 } 347 }
339 348
340 349
341 /* Delete INTERNAL information 350 /* Delete INTERNAL information
342 */ 351 */
350 * (those variables that are only set by libSIDPlay when tune is initialized). 359 * (those variables that are only set by libSIDPlay when tune is initialized).
351 * Rest of the information is acquired in xs_sidplay1_updateinfo() 360 * Rest of the information is acquired in xs_sidplay1_updateinfo()
352 */ 361 */
353 XSTuneInfo *xs_sidplay1_getinfo(const gchar *filename) 362 XSTuneInfo *xs_sidplay1_getinfo(const gchar *filename)
354 { 363 {
355 XSTuneInfo *res; 364 XSTuneInfo *res = NULL;
356 sidTune *tune; 365 sidTune *tune = NULL;
357 sidTuneInfo info; 366 sidTuneInfo info;
367 guint8 *buf = NULL;
368 size_t bufSize;
358 369
359 /* Check if the tune exists and is readable */ 370 /* Check if the tune exists and is readable */
360 if ((tune = new sidTune(filename)) == NULL) 371 if (!xs_fload_buffer(filename, &buf, &bufSize, XS_SIDBUF_SIZE, TRUE))
372 {
373 XSDEBUG("could not load file '%s'.\n", filename);
374 goto error;
375 }
376
377 if ((tune = new sidTune(buf, bufSize)) == NULL)
361 { 378 {
362 XSDEBUG("could not initialize tune from '%s'.\n", filename); 379 XSDEBUG("could not initialize tune from '%s'.\n", filename);
363 return NULL; 380 goto error;
364 } 381 }
365 382
366 if (!tune->getStatus()) 383 if (!tune->getStatus())
367 { 384 {
368 XSDEBUG("tune->getStatus() returned false for '%s'.\n", filename); 385 XSDEBUG("tune->getStatus() returned false for '%s'.\n", filename);
369 delete tune; 386 goto error;
370 return NULL;
371 } 387 }
372 388
373 /* Get general tune information */ 389 /* Get general tune information */
374 tune->getInfo(info); 390 tune->getInfo(info);
375 391
380 info.loadAddr, info.initAddr, info.playAddr, 396 info.loadAddr, info.initAddr, info.playAddr,
381 info.dataFileLen, info.formatString, 397 info.dataFileLen, info.formatString,
382 info.sidModel 398 info.sidModel
383 ); 399 );
384 400
385 delete tune; 401 error:
402 if (tune)
403 delete tune;
404
405 g_free(buf);
386 return res; 406 return res;
387 } 407 }
388 408
389 409
390 /* Updates the information of currently playing tune 410 /* Updates the information of currently playing tune