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 <sys/types.h>
25 #include <sys/ioctl.h>
36 static int cdfile = -1;
37 static char cd_dev[64] = _PATH_DEV "cd0";
40 void CDAudio_SysEject (void)
45 ioctl(cdfile, CDIOCALLOW);
46 if (ioctl(cdfile, CDIOCEJECT) == -1)
47 Con_DPrintf("ioctl CDIOCEJECT failed\n");
51 void CDAudio_SysCloseDoor (void)
56 ioctl(cdfile, CDIOCALLOW);
57 if (ioctl(cdfile, CDIOCCLOSE) == -1)
58 Con_DPrintf("ioctl CDIOCCLOSE failed\n");
61 int CDAudio_SysGetAudioDiskInfo (void)
63 struct ioc_toc_header tochdr;
65 if (ioctl(cdfile, CDIOREADTOCHEADER, &tochdr) == -1)
67 Con_DPrintf("ioctl CDIOREADTOCHEADER failed\n");
71 if (tochdr.starting_track < 1)
73 Con_DPrintf("CDAudio: no music tracks\n");
77 return tochdr.ending_track;
81 int CDAudio_SysPlay (qbyte track)
83 struct ioc_read_toc_entry rte;
84 struct cd_toc_entry entry;
85 struct ioc_play_track ti;
90 // don't try to play a non-audio track
91 rte.address_format = CD_MSF_FORMAT;
92 rte.starting_track = track;
93 rte.data_len = sizeof(entry);
95 if (ioctl(cdfile, CDIOREADTOCENTRYS, &rte) == -1)
97 Con_DPrintf("ioctl CDIOREADTOCENTRYS failed\n");
100 if (entry.control & 4) // if it's a data track
102 Con_Printf("CDAudio: track %i is not audio\n", track);
109 ti.start_track = track;
110 ti.end_track = track;
114 if (ioctl(cdfile, CDIOCPLAYTRACKS, &ti) == -1)
116 Con_DPrintf("ioctl CDIOCPLAYTRACKS failed\n");
120 if (ioctl(cdfile, CDIOCRESUME) == -1)
122 Con_DPrintf("ioctl CDIOCRESUME failed\n");
130 int CDAudio_SysStop (void)
135 if (ioctl(cdfile, CDIOCSTOP) == -1)
137 Con_DPrintf("ioctl CDIOCSTOP failed (%d)\n", errno);
140 ioctl(cdfile, CDIOCALLOW);
145 int CDAudio_SysPause (void)
150 if (ioctl(cdfile, CDIOCPAUSE) == -1)
152 Con_DPrintf("ioctl CDIOCPAUSE failed\n");
160 int CDAudio_SysResume (void)
165 if (ioctl(cdfile, CDIOCRESUME) == -1)
166 Con_DPrintf("ioctl CDIOCRESUME failed\n");
171 int CDAudio_SysUpdate (void)
173 static time_t lastchk = 0;
174 struct ioc_read_subchannel subchnl;
175 struct cd_sub_channel_info data;
177 if (cdPlaying && lastchk < time(NULL))
179 lastchk = time(NULL) + 2; //two seconds between chks
181 bzero(&subchnl, sizeof(subchnl));
182 subchnl.data = &data;
183 subchnl.data_len = sizeof(data);
184 subchnl.address_format = CD_MSF_FORMAT;
185 subchnl.data_format = CD_CURRENT_POSITION;
187 if (ioctl(cdfile, CDIOCREADSUBCHANNEL, &subchnl) == -1)
189 Con_DPrintf("ioctl CDIOCREADSUBCHANNEL failed\n");
193 if (data.header.audio_status != CD_AS_PLAY_IN_PROGRESS &&
194 data.header.audio_status != CD_AS_PLAY_PAUSED)
198 CDAudio_Play(cdPlayTrack, true);
201 cdPlayTrack = data.what.position.track_number;
207 void CDAudio_SysInit (void)
211 if ((i = COM_CheckParm("-cddev")) != 0 && i < com_argc - 1)
212 strlcpy(cd_dev, com_argv[i + 1], sizeof(cd_dev));
215 int CDAudio_SysStartup (void)
219 if ((cdfile = opendisk(cd_dev, O_RDONLY, buff, sizeof(buff), 0)) == -1)
221 Con_DPrintf("CDAudio_SysStartup: open of \"%s\" failed (%i)\n",
230 void CDAudio_SysShutdown (void)