diff 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
line wrap: on
line diff
--- a/src/xs_sidplay1.cpp	Fri Nov 09 00:19:21 2012 +0200
+++ b/src/xs_sidplay1.cpp	Fri Nov 09 02:11:21 2012 +0200
@@ -41,8 +41,6 @@
     emuEngine *emu;
     emuConfig currConfig;
     sidTune *tune;
-    guint8 *buf;
-    size_t bufSize;
 } XSSIDPlay1;
 
 
@@ -50,16 +48,6 @@
 extern "C" {
 
 
-/* Return song information
- */
-#define TFUNCTION   xs_sidplay1_getinfo
-#define TFUNCTION2  xs_sidplay1_updateinfo
-#define TTUNEINFO   sidTuneInfo
-#define TTUNE       sidTune
-#define TENGINE     XSSIDPlay1
-#include "xs_sidplay.h"
-
-
 /* Check if we can play the given file
  */
 gboolean xs_sidplay1_probe(XSFile *f)
@@ -337,15 +325,13 @@
     assert(state);
 
     engine = (XSSIDPlay1 *) state->internal;
-    if (!engine) return FALSE;
+    if (!engine)
+        return FALSE;
 
-    /* Try to get the tune */
-    if (!filename) return FALSE;
-    
-    if (xs_fload_buffer(filename, &(engine->buf), &(engine->bufSize)) != 0)
+    if (!filename)
         return FALSE;
     
-    if (!engine->tune->load(engine->buf, engine->bufSize))
+    if (!engine->tune->open(filename))
         return FALSE;
 
     return TRUE;
@@ -356,17 +342,96 @@
  */
 void xs_sidplay1_delete(XSEngineState * state)
 {
-    XSSIDPlay1 *engine;
-    assert(state);
+    (void) state;
+}
+
+
+/* This function gets most of the information, though we do miss some
+ * (those variables that are only set by libSIDPlay when tune is initialized).
+ * Rest of the information is acquired in xs_sidplay1_updateinfo()
+ */
+XSTuneInfo *xs_sidplay1_getinfo(const gchar *filename)
+{
+    XSTuneInfo *res;
+    sidTune *tune;
+    sidTuneInfo info;
+
+    /* Check if the tune exists and is readable */
+    if ((tune = new sidTune(filename)) == NULL)
+    {
+        XSDEBUG("could not initialize tune from '%s'.\n", filename);
+        return NULL;
+    }
 
-    engine = (XSSIDPlay1 *) state->internal;
-    if (!engine) return;
+    if (!tune->getStatus())
+    {
+        XSDEBUG("tune->getStatus() returned false for '%s'.\n", filename);
+        delete tune;
+        return NULL;
+    }
+
+    /* Get general tune information */
+    tune->getInfo(info);
+
+    /* Allocate tuneinfo structure and set information */
+    res = xs_tuneinfo_new(filename,
+        info.songs, info.startSong,
+        info.infoString[0], info.infoString[1], info.infoString[2],
+        info.loadAddr, info.initAddr, info.playAddr,
+        info.dataFileLen, info.formatString,
+        info.sidModel
+        );
     
-    g_free(engine->buf);
-    engine->buf = NULL;
-    engine->bufSize = 0;
+    delete tune;
+    return res;
 }
 
 
+/* Updates the information of currently playing tune
+ */
+gboolean xs_sidplay1_updateinfo(XSEngineState *state)
+{
+    XSSIDPlay1 *engine;
+    sidTuneInfo info;
+    
+    /* Check if we have required structures initialized */
+    if (!state || !state->tuneInfo || !state->internal)
+        return FALSE;
+
+    engine = (XSSIDPlay1 *) state->internal;
+    if (!(engine->tune))
+        return FALSE;
+
+    /* Get general tune information */
+    engine->tune->getInfo(info);
+
+    /* NOTICE! Here we assume that libSIDPlay[12] headers define
+     * SIDTUNE_SIDMODEL_* similarly to our enums in xs_config.h ...
+     */
+    state->tuneInfo->sidModel = info.sidModel;
+
+    if (state->currSong > 0 && state->currSong <= state->tuneInfo->nsubTunes)
+    {
+        gint tmpSpeed = info.clockSpeed;
+        switch (info.clockSpeed)
+        {
+            case SIDTUNE_CLOCK_PAL:      tmpSpeed = XS_CLOCK_PAL; break;
+            case SIDTUNE_CLOCK_NTSC:     tmpSpeed = XS_CLOCK_NTSC; break;
+            case SIDTUNE_CLOCK_ANY:      tmpSpeed = XS_CLOCK_ANY; break;
+            case SIDTUNE_CLOCK_UNKNOWN:
+                switch (info.songSpeed)
+                {
+                    case SIDTUNE_SPEED_VBI:      tmpSpeed = XS_CLOCK_VBI; break;
+                    case SIDTUNE_SPEED_CIA_1A:   tmpSpeed = XS_CLOCK_CIA; break;
+                    default:                     tmpSpeed = info.songSpeed; break;
+                }
+                break;
+        }
+        state->tuneInfo->subTunes[state->currSong - 1].tuneSpeed = tmpSpeed;
+    }
+
+    return TRUE;
+}
+
 }    /* extern "C" */
 #endif    /* HAVE_SIDPLAY1 */