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.
27 // If one of the functions fails, it returns -1, if not 0
29 // SDL supports multiple cd devices - so we are going to support this, too.
30 static void CDAudio_SDL_CDDrive_f( void );
32 // we only support playing one CD at a time
35 static int ValidateDrive( void )
37 if( cd && SDL_CDStatus( cd ) > 0 )
38 return cdValid = true;
40 return cdValid = false;
43 void CDAudio_SysEject (void)
49 void CDAudio_SysCloseDoor (void)
54 int CDAudio_SysGetAudioDiskInfo (void)
56 if( ValidateDrive() ) // everything > 0 is ok, 0 is trayempty and -1 is error
61 float CDAudio_SysGetVolume (void)
66 void CDAudio_SysSetVolume (float volume)
71 int CDAudio_SysPlay (int track)
73 return SDL_CDPlayTracks(cd, track-1, 0, 1, 0);
76 int CDAudio_SysStop (void)
78 return SDL_CDStop( cd );
81 int CDAudio_SysPause (void)
83 return SDL_CDPause( cd );
86 int CDAudio_SysResume (void)
88 return SDL_CDResume( cd );
91 int CDAudio_SysUpdate (void)
93 static time_t lastchk = 0;
95 if (cdPlaying && lastchk < time(NULL))
97 lastchk = time(NULL) + 2; //two seconds between chks
98 if( !cd || cd->status <= 0 ) {
102 if (SDL_CDStatus( cd ) == CD_STOPPED)
105 CDAudio_SysPlay( cdPlayTrack );
113 void CDAudio_SysInit (void)
115 if( SDL_InitSubSystem( SDL_INIT_CDROM ) == -1 )
116 Con_Print( "Failed to init the CDROM SDL subsystem!\n" );
118 Cmd_AddCommand( "cddrive", CDAudio_SDL_CDDrive_f, "select an SDL-detected CD drive by number" );
121 static int IsAudioCD( void )
124 for( i = 0 ; i < cd->numtracks ; i++ )
125 if( cd->track[ i ].type == SDL_AUDIO_TRACK )
130 int CDAudio_SysStartup (void)
135 numdrives = SDL_CDNumDrives();
136 if( numdrives == -1 ) // was the CDROM system initialized correctly?
139 Con_Printf( "Found %i cdrom drives.\n", numdrives );
141 for( i = 0 ; i < numdrives ; i++, cd = NULL ) {
142 cd = SDL_CDOpen( i );
144 Con_Printf( "CD drive %i is invalid.\n", i );
148 if( CD_INDRIVE( SDL_CDStatus( cd ) ) )
152 Con_Printf( "The CD in drive %i is not an audio cd.\n", i );
154 Con_Printf( "No CD in drive %i.\n", i );
159 if( i == numdrives && !cd )
165 void CDAudio_SysShutdown (void)
171 void CDAudio_SDL_CDDrive_f( void )
174 int numdrives = SDL_CDNumDrives();
176 if( Cmd_Argc() != 2 ) {
177 Con_Print( "cddrive <drivenr>\n" );
181 i = atoi( Cmd_Argv( 1 ) );
182 if( i >= numdrives ) {
183 Con_Printf("Only %i drives!\n", numdrives );
190 cd = SDL_CDOpen( i );
192 Con_Printf( "Couldn't open drive %i.\n", i );
196 if( !CD_INDRIVE( SDL_CDStatus( cd ) ) )
197 Con_Printf( "No cd in drive %i.\n", i );
198 else if( !IsAudioCD() )
199 Con_Printf( "The CD in drive %i is not an audio CD.\n", i );