2 Copyright (C) 2004 Andreas Kirsch (used cd_null.c as template)
3 Copyright (C) 1996-1997 Id Software, Inc.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 SDL 1.2.7 and older seems to have a strange bug regarding CDPause and CDResume under WIN32.
27 If CDResume is called, it plays to end of the CD regardless what values for lasttrack and lastframe
28 were passed to CDPlayTracks.
31 // If one of the functions fails, it returns -1, if not 0
33 // SDL supports multiple cd devices - so we are going to support this, too.
34 static void CDAudio_SDL_CDDrive_f( void );
36 // we only support playing on CD at a time
39 static double pauseoffset;
40 static double endtime;
42 static int ValidateDrive( void )
44 if( cd && SDL_CDStatus( cd ) > 0 )
45 return cdValid = true;
47 return cdValid = false;
50 void CDAudio_SysEject (void)
56 void CDAudio_SysCloseDoor (void)
62 int CDAudio_SysGetAudioDiskInfo (void)
64 if( ValidateDrive() ) // everything > 0 is ok, 0 is trayempty and -1 is error
70 float CDAudio_SysGetVolume (void)
76 void CDAudio_SysSetVolume (float volume)
82 int CDAudio_SysPlay (qbyte track)
85 endtime = realtime + (float) cd->track[ track - 1 ].length / CD_FPS;
86 return SDL_CDPlayTracks( cd, track - 1, 0, track, 1 ); //FIXME: shall we play the whole cd or only the track?
90 int CDAudio_SysStop (void)
93 return SDL_CDStop( cd );
97 int CDAudio_SysPause (void)
100 pauseoffset = cd->cur_frame;
101 return SDL_CDPause( cd );
104 int CDAudio_SysResume (void)
107 endtime = realtime + (cd->track[ cdPlayTrack - 1 ].length - pauseoffset) / CD_FPS;
108 return SDL_CDPlayTracks( cd, cdPlayTrack - 1, pauseoffset, cdPlayTrack, 0 );
111 int CDAudio_SysUpdate (void)
113 if( !cd || cd->status <= 0 ) {
117 if( endtime > 0.0 && realtime >= endtime )
118 if( SDL_CDStatus( cd ) == CD_STOPPED ){
121 CDAudio_SysPlay( cdPlayTrack );
129 void CDAudio_SysInit (void)
131 if( SDL_InitSubSystem( SDL_INIT_CDROM ) == -1 )
132 Con_SafePrint( "Failed to init the CDROM SDL subsystem!\n" );
134 Cmd_AddCommand( "cddrive", CDAudio_SDL_CDDrive_f );
137 static int IsAudioCD( void )
140 for( i = 0 ; i < cd->numtracks ; i++ )
141 if( cd->track[ i ].type == SDL_AUDIO_TRACK )
146 int CDAudio_SysStartup (void)
151 numdrives = SDL_CDNumDrives();
152 if( numdrives == -1 ) // was the CDROM system initialized correctly?
155 Con_DPrintf( "Found %i cdrom drives.\n", numdrives );
157 for( i = 0 ; i < numdrives ; i++, cd = NULL ) {
158 cd = SDL_CDOpen( i );
160 Con_DPrintf( "CD drive %i is invalid.\n", i );
164 if( CD_INDRIVE( SDL_CDStatus( cd ) ) )
168 Con_DPrintf( "The CD in drive %i is not an audio cd.\n", i );
170 Con_DPrintf( "No CD in drive %i.\n", i );
175 if( i == numdrives && !cd )
183 void CDAudio_SysShutdown (void)
189 void CDAudio_SDL_CDDrive_f( void )
192 int numdrives = SDL_CDNumDrives();
194 if( Cmd_Argc() != 2 ) {
195 Con_Print( "cddrive <drivenr>\n" );
199 i = atoi( Cmd_Argv( 1 ) );
200 if( i >= numdrives ) {
201 Con_Printf("Only %i drives!\n", numdrives );
208 cd = SDL_CDOpen( i );
210 Con_Printf( "Couldn't open drive %i.\n", i );
214 if( !CD_INDRIVE( SDL_CDStatus( cd ) ) )
215 Con_Printf( "No cd in drive %i.\n", i );
216 else if( !IsAudioCD() )
217 Con_Printf( "The CD in drive %i is not an audio CD.\n", i );