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.
25 #if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2
26 // SDL 1.2 has CD audio
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 one CD at a time
39 static int ValidateDrive( void )
41 if( cd && SDL_CDStatus( cd ) > 0 )
42 return cdValid = true;
44 return cdValid = false;
47 void CDAudio_SysEject (void)
53 void CDAudio_SysCloseDoor (void)
58 int CDAudio_SysGetAudioDiskInfo (void)
60 if( ValidateDrive() ) // everything > 0 is ok, 0 is trayempty and -1 is error
65 float CDAudio_SysGetVolume (void)
70 void CDAudio_SysSetVolume (float volume)
75 int CDAudio_SysPlay (int track)
77 return SDL_CDPlayTracks(cd, track-1, 0, 1, 0);
80 int CDAudio_SysStop (void)
82 return SDL_CDStop( cd );
85 int CDAudio_SysPause (void)
87 return SDL_CDPause( cd );
90 int CDAudio_SysResume (void)
92 return SDL_CDResume( cd );
95 int CDAudio_SysUpdate (void)
97 static time_t lastchk = 0;
99 if (cdPlaying && lastchk < time(NULL))
101 lastchk = time(NULL) + 2; //two seconds between chks
102 if( !cd || cd->status <= 0 ) {
106 if (SDL_CDStatus( cd ) == CD_STOPPED)
109 CDAudio_SysPlay( cdPlayTrack );
117 void CDAudio_SysInit (void)
119 if( SDL_InitSubSystem( SDL_INIT_CDROM ) == -1 )
120 Con_Print( "Failed to init the CDROM SDL subsystem!\n" );
122 Cmd_AddCommand( "cddrive", CDAudio_SDL_CDDrive_f, "select an SDL-detected CD drive by number" );
125 static int IsAudioCD( void )
128 for( i = 0 ; i < cd->numtracks ; i++ )
129 if( cd->track[ i ].type == SDL_AUDIO_TRACK )
134 int CDAudio_SysStartup (void)
139 numdrives = SDL_CDNumDrives();
140 if( numdrives == -1 ) // was the CDROM system initialized correctly?
143 Con_Printf( "Found %i cdrom drives.\n", numdrives );
145 for( i = 0 ; i < numdrives ; i++, cd = NULL ) {
146 cd = SDL_CDOpen( i );
148 Con_Printf( "CD drive %i is invalid.\n", i );
152 if( CD_INDRIVE( SDL_CDStatus( cd ) ) )
156 Con_Printf( "The CD in drive %i is not an audio cd.\n", i );
158 Con_Printf( "No CD in drive %i.\n", i );
163 if( i == numdrives && !cd )
169 void CDAudio_SysShutdown (void)
175 void CDAudio_SDL_CDDrive_f( void )
178 int numdrives = SDL_CDNumDrives();
180 if( Cmd_Argc() != 2 ) {
181 Con_Print( "cddrive <drivenr>\n" );
185 i = atoi( Cmd_Argv( 1 ) );
186 if( i >= numdrives ) {
187 Con_Printf("Only %i drives!\n", numdrives );
194 cd = SDL_CDOpen( i );
196 Con_Printf( "Couldn't open drive %i.\n", i );
200 if( !CD_INDRIVE( SDL_CDStatus( cd ) ) )
201 Con_Printf( "No cd in drive %i.\n", i );
202 else if( !IsAudioCD() )
203 Con_Printf( "The CD in drive %i is not an audio CD.\n", i );
213 // SDL 1.3 does not have CD audio
215 void CDAudio_SysEject (void)
220 void CDAudio_SysCloseDoor (void)
225 int CDAudio_SysGetAudioDiskInfo (void)
231 float CDAudio_SysGetVolume (void)
237 void CDAudio_SysSetVolume (float fvolume)
242 int CDAudio_SysPlay (int track)
248 int CDAudio_SysStop (void)
254 int CDAudio_SysPause (void)
259 int CDAudio_SysResume (void)
264 int CDAudio_SysUpdate (void)
270 void CDAudio_SysInit (void)
274 int CDAudio_SysStartup (void)
279 void CDAudio_SysShutdown (void)