summaryrefslogtreecommitdiff
path: root/src/i_cdmus.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/i_cdmus.c')
-rw-r--r--src/i_cdmus.c54
1 files changed, 40 insertions, 14 deletions
diff --git a/src/i_cdmus.c b/src/i_cdmus.c
index d05b5bd1..e9756dd9 100644
--- 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 @@ int I_CDMusInit(void)
// 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;
}
@@ -80,6 +90,22 @@ int I_CDMusInit(void)
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)
{
int result;