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";
38 void CDAudio_SysEject (void)
43 if (ioctl(cdfile, CDROMEJECT) == -1)
44 Con_DPrint("ioctl CDROMEJECT failed\n");
48 void CDAudio_SysCloseDoor (void)
53 if (ioctl(cdfile, CDROMCLOSETRAY) == -1)
54 Con_DPrint("ioctl CDROMCLOSETRAY failed\n");
57 int CDAudio_SysGetAudioDiskInfo (void)
59 struct cdrom_tochdr tochdr;
64 if (ioctl(cdfile, CDROMREADTOCHDR, &tochdr) == -1)
66 Con_DPrint("ioctl CDROMREADTOCHDR failed\n");
70 if (tochdr.cdth_trk0 < 1)
72 Con_DPrint("CDAudio: no music tracks\n");
76 return tochdr.cdth_trk1;
80 int CDAudio_SysPlay (qbyte track)
82 struct cdrom_tocentry entry;
88 // don't try to play a non-audio track
89 entry.cdte_track = track;
90 entry.cdte_format = CDROM_MSF;
91 if (ioctl(cdfile, CDROMREADTOCENTRY, &entry) == -1)
93 Con_DPrint("ioctl CDROMREADTOCENTRY failed\n");
96 if (entry.cdte_ctrl == CDROM_DATA_TRACK)
98 Con_Printf("CDAudio: track %i is not audio\n", track);
105 ti.cdti_trk0 = track;
106 ti.cdti_trk1 = track;
110 if (ioctl(cdfile, CDROMPLAYTRKIND, &ti) == -1)
112 Con_DPrint("ioctl CDROMPLAYTRKIND failed\n");
116 if (ioctl(cdfile, CDROMRESUME) == -1)
118 Con_DPrint("ioctl CDROMRESUME failed\n");
126 int CDAudio_SysStop (void)
131 if (ioctl(cdfile, CDROMSTOP) == -1)
133 Con_DPrintf("ioctl CDROMSTOP failed (%d)\n", errno);
140 int CDAudio_SysPause (void)
145 if (ioctl(cdfile, CDROMPAUSE) == -1)
147 Con_DPrint("ioctl CDROMPAUSE failed\n");
155 int CDAudio_SysResume (void)
160 if (ioctl(cdfile, CDROMRESUME) == -1)
161 Con_DPrint("ioctl CDROMRESUME failed\n");
166 int CDAudio_SysUpdate (void)
168 struct cdrom_subchnl subchnl;
169 static time_t lastchk = 0;
171 if (cdPlaying && lastchk < time(NULL))
173 lastchk = time(NULL) + 2; //two seconds between chks
174 subchnl.cdsc_format = CDROM_MSF;
175 if (ioctl(cdfile, CDROMSUBCHNL, &subchnl) == -1)
177 Con_DPrint("ioctl CDROMSUBCHNL failed\n");
181 if (subchnl.cdsc_audiostatus != CDROM_AUDIO_PLAY &&
182 subchnl.cdsc_audiostatus != CDROM_AUDIO_PAUSED)
186 CDAudio_Play(cdPlayTrack, true);
189 cdPlayTrack = subchnl.cdsc_trk;
195 void CDAudio_SysInit (void)
199 if ((i = COM_CheckParm("-cddev")) != 0 && i < com_argc - 1)
200 strlcpy(cd_dev, com_argv[i + 1], sizeof(cd_dev));
203 int CDAudio_SysStartup (void)
205 if ((cdfile = open(cd_dev, O_RDONLY)) == -1)
207 Con_DPrintf("CDAudio_SysStartup: open of \"%s\" failed (%i)\n",
216 void CDAudio_SysShutdown (void)