changeset 2623:02dbe40dd0c3

Synchronized CVS libsidplay2 COM interface support from XMMS-SID. This is only the relevant code changes, the -plugins configure script needs to be adapted to make it actually used.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 22 May 2008 12:32:41 +0300
parents bac936960b49
children 73b785033e47
files src/sid/xs_sidplay2.cc
diffstat 1 files changed, 65 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/sid/xs_sidplay2.cc	Thu May 22 12:30:43 2008 +0300
+++ b/src/sid/xs_sidplay2.cc	Thu May 22 12:32:41 2008 +0300
@@ -30,22 +30,50 @@
 
 
 #include <sidplay/sidplay2.h>
-#ifdef HAVE_RESID_BUILDER
-#include <sidplay/builders/resid.h>
-#endif
-#ifdef HAVE_HARDSID_BUILDER
-#include <sidplay/builders/hardsid.h>
+#ifdef HAVE_SIDPLAY2_COMI
+#  include <sidplay/sidlazyiptr.h>
 #endif
 
 
-typedef struct {
+class xs_sidplay2_t {
+public:
+#ifdef HAVE_SIDPLAY2_COMI
+    SidIPtr<ISidplay2> currEng;
+    SidLazyIPtr<ISidUnknown> currBuilder;
+#else
     sidplay2 *currEng;
     sidbuilder *currBuilder;
+#endif
     sid2_config_t currConfig;
     SidTune *currTune;
     guint8 *buf;
     size_t bufSize;
-} xs_sidplay2_t;
+    
+    xs_sidplay2_t(void);
+    virtual ~xs_sidplay2_t(void) { ; }
+};
+
+
+#ifdef HAVE_RESID_BUILDER
+#  include <sidplay/builders/resid.h>
+#endif
+#ifdef HAVE_HARDSID_BUILDER
+#  include <sidplay/builders/hardsid.h>
+#endif
+
+
+xs_sidplay2_t::xs_sidplay2_t(void)
+#ifdef HAVE_SIDPLAY2_COMI
+:currEng(sidplay2::create())
+#else
+:currEng(NULL)
+#endif
+{
+    buf = NULL;
+    bufSize = 0;
+    currTune = NULL;
+    currBuilder = NULL;    
+}
 
 
 /* We need to 'export' all this pseudo-C++ crap */
@@ -54,11 +82,11 @@
 
 /* Return song information
  */
-#define TFUNCTION    xs_sidplay2_getinfo
-#define TFUNCTION2    xs_sidplay2_updateinfo
-#define TTUNEINFO    SidTuneInfo
-#define TTUNE        SidTune
-#define TENGINE        xs_sidplay2_t
+#define TFUNCTION   xs_sidplay2_getinfo
+#define TFUNCTION2  xs_sidplay2_updateinfo
+#define TTUNEINFO   SidTuneInfo
+#define TTUNE       SidTune
+#define TENGINE     xs_sidplay2_t
 #include "xs_sidplay.h"
 
 
@@ -91,12 +119,14 @@
     assert(myStatus);
 
     /* Allocate internal structures */
-    myEngine = (xs_sidplay2_t *) g_malloc0(sizeof(xs_sidplay2_t));
+    myEngine = new xs_sidplay2_t();
     myStatus->sidEngine = myEngine;
     if (!myEngine) return FALSE;
 
     /* Initialize the engine */
+#ifndef HAVE_SIDPLAY2_COMI
     myEngine->currEng = new sidplay2;
+#endif
     if (!myEngine->currEng) {
         xs_error("[SIDPlay2] Could not initialize emulation engine.\n");
         return FALSE;
@@ -228,9 +258,16 @@
     XSDEBUG("init builder #%i, maxsids=%i\n", xs_cfg.sid2Builder, (myEngine->currEng->info()).maxsids);
 #ifdef HAVE_RESID_BUILDER
     if (xs_cfg.sid2Builder == XS_BLD_RESID) {
+#ifdef HAVE_SIDPLAY2_COMI
+        myEngine->currBuilder = ReSIDBuilderCreate("");
+        SidLazyIPtr<IReSIDBuilder> rs(myEngine->currBuilder);
+        if (rs) {
+            myEngine->currConfig.sidEmulation = rs->iaggregate();
+#else
         ReSIDBuilder *rs = new ReSIDBuilder("ReSID builder");
         myEngine->currBuilder = (sidbuilder *) rs;
         if (rs) {
+#endif
             /* Builder object created, initialize it */
             rs->create((myEngine->currEng->info()).maxsids);
             if (!*rs) {
@@ -266,9 +303,16 @@
 #endif
 #ifdef HAVE_HARDSID_BUILDER
     if (xs_cfg.sid2Builder == XS_BLD_HARDSID) {
+#ifdef HAVE_SIDPLAY2_COMI
+        myEngine->currBuilder = HardSIDBuilderCreate("");
+        SidLazyIPtr<IHardSIDBuilder> hs(myEngine->currBuilder);
+        if (hs) {
+            myEngine->currConfig.sidEmulation = hs->iaggregate();
+#else
         HardSIDBuilder *hs = new HardSIDBuilder("HardSID builder");
         myEngine->currBuilder = (sidbuilder *) hs;
         if (hs) {
+#endif
             /* Builder object created, initialize it */
             hs->create((myEngine->currEng->info()).maxsids);
             if (!*hs) {
@@ -290,8 +334,10 @@
         return FALSE;
     }
 
+#ifndef HAVE_SIDPLAY2_COMI
+    myEngine->currConfig.sidEmulation = myEngine->currBuilder;
     XSDEBUG("%s\n", myEngine->currBuilder->credits());
-
+#endif
 
     /* Clockspeed settings */
     switch (xs_cfg.clockSpeed) {
@@ -311,7 +357,6 @@
 
 
     /* Configure rest of the emulation */
-    myEngine->currConfig.sidEmulation = myEngine->currBuilder;
     
     if (xs_cfg.forceSpeed) { 
         myEngine->currConfig.clockForced = true;
@@ -374,14 +419,18 @@
 
     /* Free internals */
     if (myEngine->currBuilder) {
+#ifndef HAVE_SIDPLAY2_COMI
         delete myEngine->currBuilder;
+#endif
         myEngine->currBuilder = NULL;
     }
 
+#ifndef HAVE_SIDPLAY2_COMI
     if (myEngine->currEng) {
         delete myEngine->currEng;
         myEngine->currEng = NULL;
     }
+#endif
 
     if (myEngine->currTune) {
         delete myEngine->currTune;
@@ -390,7 +439,7 @@
 
     xs_sidplay2_delete(myStatus);
 
-    g_free(myEngine);
+    delete myEngine;
     myStatus->sidEngine = NULL;
 }