Mercurial > hg > xmms-sid
comparison src/xs_sidplay1.cpp @ 862:011ba70e271e
Major cleanups, make SIDPlayFP backend compile with libSIDPlayFP v1.0.0
alphas .. does not work for some reason yet, though. (Only plays silence.)
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 09 Nov 2012 02:11:21 +0200 |
parents | 5b93bd8c7814 |
children | 3a9bf45178ff |
comparison
equal
deleted
inserted
replaced
861:c6cf203be443 | 862:011ba70e271e |
---|---|
39 | 39 |
40 typedef struct { | 40 typedef struct { |
41 emuEngine *emu; | 41 emuEngine *emu; |
42 emuConfig currConfig; | 42 emuConfig currConfig; |
43 sidTune *tune; | 43 sidTune *tune; |
44 guint8 *buf; | |
45 size_t bufSize; | |
46 } XSSIDPlay1; | 44 } XSSIDPlay1; |
47 | 45 |
48 | 46 |
49 /* We need to 'export' all this pseudo-C++ crap */ | 47 /* We need to 'export' all this pseudo-C++ crap */ |
50 extern "C" { | 48 extern "C" { |
51 | |
52 | |
53 /* Return song information | |
54 */ | |
55 #define TFUNCTION xs_sidplay1_getinfo | |
56 #define TFUNCTION2 xs_sidplay1_updateinfo | |
57 #define TTUNEINFO sidTuneInfo | |
58 #define TTUNE sidTune | |
59 #define TENGINE XSSIDPlay1 | |
60 #include "xs_sidplay.h" | |
61 | 49 |
62 | 50 |
63 /* Check if we can play the given file | 51 /* Check if we can play the given file |
64 */ | 52 */ |
65 gboolean xs_sidplay1_probe(XSFile *f) | 53 gboolean xs_sidplay1_probe(XSFile *f) |
335 { | 323 { |
336 XSSIDPlay1 *engine; | 324 XSSIDPlay1 *engine; |
337 assert(state); | 325 assert(state); |
338 | 326 |
339 engine = (XSSIDPlay1 *) state->internal; | 327 engine = (XSSIDPlay1 *) state->internal; |
340 if (!engine) return FALSE; | 328 if (!engine) |
341 | 329 return FALSE; |
342 /* Try to get the tune */ | 330 |
343 if (!filename) return FALSE; | 331 if (!filename) |
344 | 332 return FALSE; |
345 if (xs_fload_buffer(filename, &(engine->buf), &(engine->bufSize)) != 0) | 333 |
346 return FALSE; | 334 if (!engine->tune->open(filename)) |
347 | |
348 if (!engine->tune->load(engine->buf, engine->bufSize)) | |
349 return FALSE; | 335 return FALSE; |
350 | 336 |
351 return TRUE; | 337 return TRUE; |
352 } | 338 } |
353 | 339 |
354 | 340 |
355 /* Delete INTERNAL information | 341 /* Delete INTERNAL information |
356 */ | 342 */ |
357 void xs_sidplay1_delete(XSEngineState * state) | 343 void xs_sidplay1_delete(XSEngineState * state) |
358 { | 344 { |
359 XSSIDPlay1 *engine; | 345 (void) state; |
360 assert(state); | 346 } |
347 | |
348 | |
349 /* This function gets most of the information, though we do miss some | |
350 * (those variables that are only set by libSIDPlay when tune is initialized). | |
351 * Rest of the information is acquired in xs_sidplay1_updateinfo() | |
352 */ | |
353 XSTuneInfo *xs_sidplay1_getinfo(const gchar *filename) | |
354 { | |
355 XSTuneInfo *res; | |
356 sidTune *tune; | |
357 sidTuneInfo info; | |
358 | |
359 /* Check if the tune exists and is readable */ | |
360 if ((tune = new sidTune(filename)) == NULL) | |
361 { | |
362 XSDEBUG("could not initialize tune from '%s'.\n", filename); | |
363 return NULL; | |
364 } | |
365 | |
366 if (!tune->getStatus()) | |
367 { | |
368 XSDEBUG("tune->getStatus() returned false for '%s'.\n", filename); | |
369 delete tune; | |
370 return NULL; | |
371 } | |
372 | |
373 /* Get general tune information */ | |
374 tune->getInfo(info); | |
375 | |
376 /* Allocate tuneinfo structure and set information */ | |
377 res = xs_tuneinfo_new(filename, | |
378 info.songs, info.startSong, | |
379 info.infoString[0], info.infoString[1], info.infoString[2], | |
380 info.loadAddr, info.initAddr, info.playAddr, | |
381 info.dataFileLen, info.formatString, | |
382 info.sidModel | |
383 ); | |
384 | |
385 delete tune; | |
386 return res; | |
387 } | |
388 | |
389 | |
390 /* Updates the information of currently playing tune | |
391 */ | |
392 gboolean xs_sidplay1_updateinfo(XSEngineState *state) | |
393 { | |
394 XSSIDPlay1 *engine; | |
395 sidTuneInfo info; | |
396 | |
397 /* Check if we have required structures initialized */ | |
398 if (!state || !state->tuneInfo || !state->internal) | |
399 return FALSE; | |
361 | 400 |
362 engine = (XSSIDPlay1 *) state->internal; | 401 engine = (XSSIDPlay1 *) state->internal; |
363 if (!engine) return; | 402 if (!(engine->tune)) |
364 | 403 return FALSE; |
365 g_free(engine->buf); | 404 |
366 engine->buf = NULL; | 405 /* Get general tune information */ |
367 engine->bufSize = 0; | 406 engine->tune->getInfo(info); |
368 } | 407 |
369 | 408 /* NOTICE! Here we assume that libSIDPlay[12] headers define |
409 * SIDTUNE_SIDMODEL_* similarly to our enums in xs_config.h ... | |
410 */ | |
411 state->tuneInfo->sidModel = info.sidModel; | |
412 | |
413 if (state->currSong > 0 && state->currSong <= state->tuneInfo->nsubTunes) | |
414 { | |
415 gint tmpSpeed = info.clockSpeed; | |
416 switch (info.clockSpeed) | |
417 { | |
418 case SIDTUNE_CLOCK_PAL: tmpSpeed = XS_CLOCK_PAL; break; | |
419 case SIDTUNE_CLOCK_NTSC: tmpSpeed = XS_CLOCK_NTSC; break; | |
420 case SIDTUNE_CLOCK_ANY: tmpSpeed = XS_CLOCK_ANY; break; | |
421 case SIDTUNE_CLOCK_UNKNOWN: | |
422 switch (info.songSpeed) | |
423 { | |
424 case SIDTUNE_SPEED_VBI: tmpSpeed = XS_CLOCK_VBI; break; | |
425 case SIDTUNE_SPEED_CIA_1A: tmpSpeed = XS_CLOCK_CIA; break; | |
426 default: tmpSpeed = info.songSpeed; break; | |
427 } | |
428 break; | |
429 } | |
430 state->tuneInfo->subTunes[state->currSong - 1].tuneSpeed = tmpSpeed; | |
431 } | |
432 | |
433 return TRUE; | |
434 } | |
370 | 435 |
371 } /* extern "C" */ | 436 } /* extern "C" */ |
372 #endif /* HAVE_SIDPLAY1 */ | 437 #endif /* HAVE_SIDPLAY1 */ |