From 6e09cdf285c5f7526138c905130d17c7248eef63 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sat, 12 Oct 2013 02:48:49 +0000 Subject: Fix Hexen CD music (now working and tested with a real Hexen CD). Subversion-branch: /branches/v2-branch Subversion-revision: 2698 --- src/hexen/s_sound.c | 4 +++- src/i_cdmus.c | 54 +++++++++++++++++++++++++++++++++++++++-------------- src/i_cdmus.h | 1 + 3 files changed, 44 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/hexen/s_sound.c b/src/hexen/s_sound.c index de770bab..f6509d1c 100644 --- a/src/hexen/s_sound.c +++ b/src/hexen/s_sound.c @@ -289,7 +289,7 @@ void S_StartSongName(char *songLump, boolean loop) cdTrack = P_GetCDStartTrack(); } */ - if (!cdTrack) + if (cdTrack != 0) { cd_custom_track = 0; StartCDTrack(cdTrack, loop); @@ -830,6 +830,8 @@ void S_Init(void) { ST_Message("failed.\n"); } + + I_CDMusPrintStartup(); } } 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; diff --git a/src/i_cdmus.h b/src/i_cdmus.h index 3915a986..75f04947 100644 --- 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); -- cgit v1.2.3