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
23 #include <linux/cdrom.h>
24 #include <sys/ioctl.h>
34 static int cdfile = -1;
35 static char cd_dev[64] = "/dev/cdrom";
37 void CDAudio_SysEject (void)
42 if (ioctl(cdfile, CDROMEJECT) == -1)
43 Con_DPrintf("ioctl cdromeject failed\n");
47 void CDAudio_SysCloseDoor (void)
52 if (ioctl(cdfile, CDROMCLOSETRAY) == -1)
53 Con_DPrintf("ioctl cdromclosetray failed\n");
56 int CDAudio_SysGetAudioDiskInfo (void)
58 struct cdrom_tochdr tochdr;
60 if (ioctl(cdfile, CDROMREADTOCHDR, &tochdr) == -1)
62 Con_DPrintf("ioctl cdromreadtochdr failed\n");
66 if (tochdr.cdth_trk0 < 1)
68 Con_DPrintf("CDAudio: no music tracks\n");
72 return tochdr.cdth_trk1;
76 int CDAudio_SysPlay (qbyte track)
78 struct cdrom_tocentry entry;
84 // don't try to play a non-audio track
85 entry.cdte_track = track;
86 entry.cdte_format = CDROM_MSF;
87 if (ioctl(cdfile, CDROMREADTOCENTRY, &entry) == -1)
89 Con_DPrintf("ioctl cdromreadtocentry failed\n");
92 if (entry.cdte_ctrl == CDROM_DATA_TRACK)
94 Con_Printf("CDAudio: track %i is not audio\n", track);
101 ti.cdti_trk0 = track;
102 ti.cdti_trk1 = track;
106 if (ioctl(cdfile, CDROMPLAYTRKIND, &ti) == -1)
108 Con_DPrintf("ioctl cdromplaytrkind failed\n");
112 if (ioctl(cdfile, CDROMRESUME) == -1)
114 Con_DPrintf("ioctl cdromresume failed\n");
122 int CDAudio_SysStop (void)
127 if (ioctl(cdfile, CDROMSTOP) == -1)
129 Con_DPrintf("ioctl cdromstop failed (%d)\n", errno);
136 int CDAudio_SysPause (void)
141 if (ioctl(cdfile, CDROMPAUSE) == -1)
143 Con_DPrintf("ioctl cdrompause failed\n");
151 int CDAudio_SysResume (void)
156 if (ioctl(cdfile, CDROMRESUME) == -1)
157 Con_DPrintf("ioctl cdromresume failed\n");
162 int CDAudio_SysUpdate (void)
164 struct cdrom_subchnl subchnl;
165 static time_t lastchk = 0;
167 if (cdPlaying && lastchk < time(NULL)) {
168 lastchk = time(NULL) + 2; //two seconds between chks
169 subchnl.cdsc_format = CDROM_MSF;
170 if (ioctl(cdfile, CDROMSUBCHNL, &subchnl) == -1 ) {
171 Con_DPrintf("ioctl cdromsubchnl failed\n");
175 if (subchnl.cdsc_audiostatus != CDROM_AUDIO_PLAY &&
176 subchnl.cdsc_audiostatus != CDROM_AUDIO_PAUSED) {
179 CDAudio_Play(cdPlayTrack, true);
186 void CDAudio_SysInit (void)
190 if ((i = COM_CheckParm("-cddev")) != 0 && i < com_argc - 1)
191 strlcpy (cd_dev, com_argv[i + 1], sizeof (cd_dev));
194 int CDAudio_SysStartup (void)
196 if ((cdfile = open(cd_dev, O_RDONLY)) == -1)
198 Con_DPrintf("CDAudio_SysStartup: open of \"%s\" failed (%i)\n", cd_dev, errno);
206 void CDAudio_SysShutdown (void)