shithub: choc

Download patch

ref: 6e09cdf285c5f7526138c905130d17c7248eef63
parent: fe63589f1d69401f4a587b773832671112cc4cb6
author: Simon Howard <[email protected]>
date: Fri Oct 11 22:48:49 EDT 2013

Fix Hexen CD music (now working and tested with a real Hexen CD).

Subversion-branch: /branches/v2-branch
Subversion-revision: 2698

--- a/src/hexen/s_sound.c
+++ b/src/hexen/s_sound.c
@@ -289,7 +289,7 @@
 			cdTrack = P_GetCDStartTrack();
 		}
 */
-        if (!cdTrack)
+        if (cdTrack != 0)
         {
             cd_custom_track = 0;
             StartCDTrack(cdTrack, loop);
@@ -830,6 +830,8 @@
         {
             ST_Message("failed.\n");
         }
+
+        I_CDMusPrintStartup();
     }
 }
 
--- a/src/i_cdmus.c
+++ b/src/i_cdmus.c
@@ -35,6 +35,8 @@
 #include "i_cdmus.h"
 
 static SDL_CD *cd_handle = NULL;
+static char *startup_error = NULL;
+static char *cd_name = NULL;
 
 int cd_Error;
 
@@ -45,32 +47,40 @@
     // The initialize function is re-invoked when the CD track play cheat
     // is used, so use the opportunity to call SDL_CDStatus() to update
     // the status of the drive.
-    // TODO: Check this actually works.
 
-    if (cd_handle != NULL)
+    if (cd_handle == NULL)
     {
-        SDL_CDStatus(cd_handle);
-        cd_Error = 0;
-        return 0;
-    }
+        if (SDL_Init(SDL_INIT_CDROM) < 0)
+        {
+            startup_error = "Failed to init CD subsystem.";
+            cd_Error = 1;
+            return -1;
+        }
 
-    // TODO: config variable to control CDROM to use.
+        // TODO: config variable to control CDROM to use.
 
-    cd_handle = SDL_CDOpen(drive_num);
+        cd_handle = SDL_CDOpen(drive_num);
 
-    if (cd_handle == NULL)
+        if (cd_handle == NULL)
+        {
+            startup_error = "Failed to open CD-ROM drive.";
+            cd_Error = 1;
+            return -1;
+        }
+
+        cd_name = SDL_CDName(drive_num);
+    }
+
+    if (SDL_CDStatus(cd_handle) == CD_ERROR)
     {
-        fprintf(stderr, "I_CDMusInit: Failed to open CD-ROM drive.\n");
+        startup_error = "Failed to read CD status.";
         cd_Error = 1;
         return -1;
     }
 
-    printf("I_CDMusInit: Using CD-ROM drive: %s\n", SDL_CDName(drive_num));
-
     if (!CD_INDRIVE(cd_handle->status))
     {
-        fprintf(stderr, "I_CDMusInit: '%s': no CD in drive.\n",
-                        SDL_CDName(drive_num));
+        startup_error = "No CD in drive.";
         cd_Error = 1;
         return -1;
     }
@@ -78,6 +88,22 @@
     cd_Error = 0;
 
     return 0;
+}
+
+// We cannot print status messages inline during startup, they must
+// be deferred until after I_CDMusInit has returned.
+
+void I_CDMusPrintStartup(void)
+{
+    if (cd_name != NULL)
+    {
+        printf("I_CDMusInit: Using CD-ROM drive: %s\n", cd_name);
+    }
+
+    if (startup_error != NULL)
+    {
+        fprintf(stderr, "I_CDMusInit: %s\n", startup_error);
+    }
 }
 
 int I_CDMusPlay(int track)
--- a/src/i_cdmus.h
+++ b/src/i_cdmus.h
@@ -37,6 +37,7 @@
 extern int cd_Error;
 
 int I_CDMusInit(void);
+void I_CDMusPrintStartup(void);
 int I_CDMusPlay(int track);
 int I_CDMusStop(void);
 int I_CDMusResume(void);