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.
21 #include <sys/types.h>
23 #include <sys/ioctl.h>
38 # define DEFAULT_CD_DEVICE _PATH_DEV "cd0"
40 # define DEFAULT_CD_DEVICE "/dev/acd0c"
43 static int cdfile = -1;
44 static char cd_dev[64] = DEFAULT_CD_DEVICE;
47 void CDAudio_SysEject (void)
52 ioctl(cdfile, CDIOCALLOW);
53 if (ioctl(cdfile, CDIOCEJECT) == -1)
54 Con_DPrint("ioctl CDIOCEJECT failed\n");
58 void CDAudio_SysCloseDoor (void)
63 ioctl(cdfile, CDIOCALLOW);
64 if (ioctl(cdfile, CDIOCCLOSE) == -1)
65 Con_DPrint("ioctl CDIOCCLOSE failed\n");
68 int CDAudio_SysGetAudioDiskInfo (void)
70 struct ioc_toc_header tochdr;
75 if (ioctl(cdfile, CDIOREADTOCHEADER, &tochdr) == -1)
77 Con_DPrint("ioctl CDIOREADTOCHEADER failed\n");
81 if (tochdr.starting_track < 1)
83 Con_DPrint("CDAudio: no music tracks\n");
87 return tochdr.ending_track;
91 float CDAudio_SysGetVolume (void)
98 if (ioctl (cdfile, CDIOCGETVOL, &vol) == -1)
100 Con_DPrint("ioctl CDIOCGETVOL failed\n");
104 return (vol.vol[0] + vol.vol[1]) / 2.0f / 255.0f;
108 void CDAudio_SysSetVolume (float volume)
115 vol.vol[0] = vol.vol[1] = volume * 255;
116 vol.vol[2] = vol.vol[3] = 0;
118 if (ioctl (cdfile, CDIOCSETVOL, &vol) == -1)
119 Con_DPrintf ("ioctl CDIOCSETVOL failed\n");
123 int CDAudio_SysPlay (qbyte track)
125 struct ioc_read_toc_entry rte;
126 struct cd_toc_entry entry;
127 struct ioc_play_track ti;
132 // don't try to play a non-audio track
133 rte.address_format = CD_MSF_FORMAT;
134 rte.starting_track = track;
135 rte.data_len = sizeof(entry);
137 if (ioctl(cdfile, CDIOREADTOCENTRYS, &rte) == -1)
139 Con_DPrint("ioctl CDIOREADTOCENTRYS failed\n");
142 if (entry.control & 4) // if it's a data track
144 Con_Printf("CDAudio: track %i is not audio\n", track);
151 ti.start_track = track;
152 ti.end_track = track;
156 if (ioctl(cdfile, CDIOCPLAYTRACKS, &ti) == -1)
158 Con_DPrint("ioctl CDIOCPLAYTRACKS failed\n");
162 if (ioctl(cdfile, CDIOCRESUME) == -1)
164 Con_DPrint("ioctl CDIOCRESUME failed\n");
172 int CDAudio_SysStop (void)
177 if (ioctl(cdfile, CDIOCSTOP) == -1)
179 Con_DPrintf("ioctl CDIOCSTOP failed (%d)\n", errno);
182 ioctl(cdfile, CDIOCALLOW);
187 int CDAudio_SysPause (void)
192 if (ioctl(cdfile, CDIOCPAUSE) == -1)
194 Con_DPrint("ioctl CDIOCPAUSE failed\n");
202 int CDAudio_SysResume (void)
207 if (ioctl(cdfile, CDIOCRESUME) == -1)
208 Con_DPrint("ioctl CDIOCRESUME failed\n");
213 int CDAudio_SysUpdate (void)
215 static time_t lastchk = 0;
216 struct ioc_read_subchannel subchnl;
217 struct cd_sub_channel_info data;
219 if (cdPlaying && lastchk < time(NULL))
221 lastchk = time(NULL) + 2; //two seconds between chks
223 bzero(&subchnl, sizeof(subchnl));
224 subchnl.data = &data;
225 subchnl.data_len = sizeof(data);
226 subchnl.address_format = CD_MSF_FORMAT;
227 subchnl.data_format = CD_CURRENT_POSITION;
229 if (ioctl(cdfile, CDIOCREADSUBCHANNEL, &subchnl) == -1)
231 Con_DPrint("ioctl CDIOCREADSUBCHANNEL failed\n");
235 if (data.header.audio_status != CD_AS_PLAY_IN_PROGRESS &&
236 data.header.audio_status != CD_AS_PLAY_PAUSED)
240 CDAudio_Play(cdPlayTrack, true);
243 cdPlayTrack = data.what.position.track_number;
249 void CDAudio_SysInit (void)
253 // COMMANDLINEOPTION: BSD Sound: -cddev <devicepath> chooses which CD drive to use
254 if ((i = COM_CheckParm("-cddev")) != 0 && i < com_argc - 1)
255 strlcpy(cd_dev, com_argv[i + 1], sizeof(cd_dev));
258 int CDAudio_SysStartup (void)
263 if ((cdfile = opendisk(cd_dev, O_RDONLY, buff, sizeof(buff), 0)) == -1)
265 if ((cdfile = open(cd_dev, O_RDONLY)) < 0)
268 Con_DPrintf("CDAudio_SysStartup: open of \"%s\" failed (%i)\n",
277 void CDAudio_SysShutdown (void)