2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 // Quake is a trademark of Id Software, Inc., (c) 1996 Id Software, Inc. All
25 // Prototypes of the system dependent functions
26 extern void CDAudio_SysEject (void);
27 extern void CDAudio_SysCloseDoor (void);
28 extern int CDAudio_SysGetAudioDiskInfo (void);
29 extern int CDAudio_SysPlay (qbyte track);
30 extern int CDAudio_SysStop (void);
31 extern int CDAudio_SysPause (void);
32 extern int CDAudio_SysResume (void);
33 extern int CDAudio_SysUpdate (void);
34 extern void CDAudio_SysInit (void);
35 extern int CDAudio_SysStartup (void);
36 extern void CDAudio_SysShutdown (void);
38 // used by menu to ghost CD audio slider
39 cvar_t cdaudioinitialized = {CVAR_READONLY,"cdaudioinitialized","0"};
41 static qboolean wasPlaying = false;
42 static qboolean initialized = false;
43 static qboolean enabled = false;
44 static float cdvolume;
45 static qbyte remap[100];
46 static qbyte maxTrack;
49 qboolean cdValid = false;
50 qboolean cdPlaying = false;
51 qboolean cdPlayLooping = false;
55 static void CDAudio_Eject (void)
64 static void CDAudio_CloseDoor (void)
69 CDAudio_SysCloseDoor();
72 static int CDAudio_GetAudioDiskInfo (void)
78 ret = CDAudio_SysGetAudioDiskInfo();
89 void CDAudio_Play (qbyte track, qboolean looping)
96 CDAudio_GetAudioDiskInfo();
101 track = remap[track];
102 if (track < 1 || track > maxTrack)
104 Con_DPrintf("CDAudio: Bad track number %u.\n", track);
108 if (cdPlaying && cdPlayTrack == track)
111 if (CDAudio_SysPlay(track) == -1)
114 cdPlayLooping = looping;
123 void CDAudio_Stop (void)
125 if (!enabled || !cdPlaying)
128 if (CDAudio_SysStop() == -1)
135 void CDAudio_Pause (void)
137 if (!enabled || !cdPlaying)
140 if (CDAudio_SysPause() == -1)
143 wasPlaying = cdPlaying;
148 void CDAudio_Resume (void)
150 if (!enabled || !cdValid || !wasPlaying)
153 if (CDAudio_SysResume() == -1)
158 static void CD_f (void)
167 command = Cmd_Argv (1);
169 if (strcasecmp(command, "on") == 0)
175 if (strcasecmp(command, "off") == 0)
183 if (strcasecmp(command, "reset") == 0)
188 for (n = 0; n < 100; n++)
190 CDAudio_GetAudioDiskInfo();
194 if (strcasecmp(command, "remap") == 0)
196 ret = Cmd_Argc() - 2;
199 for (n = 1; n < 100; n++)
201 Con_Printf(" %u -> %u\n", n, remap[n]);
204 for (n = 1; n <= ret; n++)
205 remap[n] = atoi(Cmd_Argv (n+1));
209 if (strcasecmp(command, "close") == 0)
217 CDAudio_GetAudioDiskInfo();
220 Con_Printf("No CD in player.\n");
225 if (strcasecmp(command, "play") == 0)
227 CDAudio_Play((qbyte)atoi(Cmd_Argv (2)), false);
231 if (strcasecmp(command, "loop") == 0)
233 CDAudio_Play((qbyte)atoi(Cmd_Argv (2)), true);
237 if (strcasecmp(command, "stop") == 0)
243 if (strcasecmp(command, "pause") == 0)
249 if (strcasecmp(command, "resume") == 0)
255 if (strcasecmp(command, "eject") == 0)
264 if (strcasecmp(command, "info") == 0)
266 Con_Printf("%u tracks\n", maxTrack);
268 Con_Printf("Currently %s track %u\n", cdPlayLooping ? "looping" : "playing", cdPlayTrack);
270 Con_Printf("Paused %s track %u\n", cdPlayLooping ? "looping" : "playing", cdPlayTrack);
271 Con_Printf("Volume is %f\n", cdvolume);
276 void CDAudio_Update (void)
281 if (bgmvolume.value != cdvolume)
285 Cvar_SetValueQuick (&bgmvolume, 0.0);
286 cdvolume = bgmvolume.value;
291 Cvar_SetValueQuick (&bgmvolume, 1.0);
292 cdvolume = bgmvolume.value;
300 int CDAudio_Init (void)
304 if (cls.state == ca_dedicated)
307 if (COM_CheckParm("-nocdaudio") || COM_CheckParm("-safe"))
312 for (i = 0; i < 100; i++)
315 Cvar_RegisterVariable(&cdaudioinitialized);
316 Cvar_SetValueQuick(&cdaudioinitialized, true);
319 Cmd_AddCommand("cd", CD_f);
324 int CDAudio_Startup (void)
326 if (CDAudio_SysStartup() == -1)
329 if (CDAudio_GetAudioDiskInfo())
331 Con_DPrintf("CDAudio_Init: No CD in player.\n");
337 Con_DPrintf("CD Audio Initialized\n");
342 void CDAudio_Shutdown (void)
347 CDAudio_SysShutdown();