3 --- WinQuake/cd_linux.c Tue Dec 21 18:40:50 1999
4 +++ ../work/WinQuake/cd_linux.c Sat Jan 15 10:52:27 2000
10 #include <linux/cdrom.h>
14 +#include <sys/cdio.h>
16 +/* resume seems to have some trouble right now. xcdplayer also can not resume
17 + the drive correctly. It appears to play, but no audio is heard */
19 +#define PAUSE_BY_STOPPING 1
26 static byte playTrack;
29 +#ifdef PAUSE_BY_STOPPING
30 +static qboolean t_playLooping;
31 +static byte t_playTrack;
34 static int cdfile = -1;
36 static char cd_dev[64] = "/dev/cdrom";
40 +static char cd_dev[64] = "/dev/rcd0d";
43 static void CDAudio_Eject(void)
45 - if (cdfile == -1 || !enabled)
46 - return; // no cd init'd
48 - if ( ioctl(cdfile, CDROMEJECT) == -1 )
49 - Con_DPrintf("ioctl cdromeject failed\n");
54 + if (cdfile == -1 || !enabled)
55 + return; // no cd init'd
58 + if ( ioctl(cdfile, CDROMEJECT) == -1 )
59 + Con_DPrintf("ioctl cdromeject failed\n");
62 + if(ioctl(cdfile, DIOCLOCK, &arg) == -1)
63 + Con_DPrintf("ioctl cdromunlock failed\n");
65 + if ( ioctl(cdfile, DIOCEJECT, &arg) == -1 )
66 + Con_DPrintf("ioctl cdromeject failed\n");
71 static void CDAudio_CloseDoor(void)
73 - if (cdfile == -1 || !enabled)
74 - return; // no cd init'd
75 +if (cdfile == -1 || !enabled)
76 + return; // no cd init'd
78 - if ( ioctl(cdfile, CDROMCLOSETRAY) == -1 )
79 - Con_DPrintf("ioctl cdromclosetray failed\n");
81 + if ( ioctl(cdfile, CDROMCLOSETRAY) == -1 )
82 + Con_DPrintf("ioctl cdromclosetray failed\n");
85 + if(ioctl(cdfile, CDIOCCLOSE, NULL) == -1) {
86 + Con_DPrintf("ioctl cdromclosetray failed\n");
91 static int CDAudio_GetAudioDiskInfo(void)
93 - struct cdrom_tochdr tochdr;
95 +struct cdrom_tochdr tochdr;
98 +struct ioc_toc_header tochdr;
104 - if ( ioctl(cdfile, CDROMREADTOCHDR, &tochdr) == -1 )
106 - Con_DPrintf("ioctl cdromreadtochdr failed\n");
110 +if ( ioctl(cdfile, CDROMREADTOCHDR, &tochdr) == -1 )
112 + Con_DPrintf("ioctl cdromreadtochdr failed\n");
117 - if (tochdr.cdth_trk0 < 1)
119 - Con_DPrintf("CDAudio: no music tracks\n");
123 +if ( ioctl(cdfile, CDIOREADTOCHEADER, &tochdr) == -1 )
125 + Con_DPrintf("ioctl cdromreadtochdr failed\n");
131 - maxTrack = tochdr.cdth_trk1;
133 +if (tochdr.cdth_trk0 < 1)
135 + Con_DPrintf("CDAudio: no music tracks\n");
140 +if (tochdr.starting_track < 1)
142 + Con_DPrintf("CDAudio: no music tracks\n");
149 +maxTrack = tochdr.cdth_trk1;
152 +maxTrack = tochdr.ending_track;
160 void CDAudio_Play(byte track, qboolean looping)
162 - struct cdrom_tocentry entry;
163 - struct cdrom_ti ti;
165 + struct cdrom_tocentry entry;
166 + struct cdrom_ti ti;
170 + struct ioc_read_toc_entry entry;
171 + struct ioc_play_track ti;
175 - if (cdfile == -1 || !enabled)
177 + if (cdfile == -1 || !enabled)
182 - CDAudio_GetAudioDiskInfo();
188 + CDAudio_GetAudioDiskInfo();
193 - track = remap[track];
194 + track = remap[track];
196 - if (track < 1 || track > maxTrack)
198 - Con_DPrintf("CDAudio: Bad track number %u.\n", track);
201 + if (track < 1 || track > maxTrack)
203 + Con_DPrintf("CDAudio: Bad track number %u.\n", track);
207 - // don't try to play a non-audio track
208 - entry.cdte_track = track;
209 - entry.cdte_format = CDROM_MSF;
210 - if ( ioctl(cdfile, CDROMREADTOCENTRY, &entry) == -1 )
212 - Con_DPrintf("ioctl cdromreadtocentry failed\n");
215 - if (entry.cdte_ctrl == CDROM_DATA_TRACK)
217 - Con_Printf("CDAudio: track %i is not audio\n", track);
220 +#ifdef __linux__ /* Not sure what the equiv is for NetBSD */
221 + /* don't try to play a non-audio track */
222 + entry.cdte_track = track;
223 + entry.cdte_format = CDROM_MSF;
224 + if ( ioctl(cdfile, CDROMREADTOCENTRY, &entry) == -1 )
226 + Con_DPrintf("ioctl cdromreadtocentry failed\n");
229 + if (entry.cdte_ctrl == CDROM_DATA_TRACK)
231 + Con_Printf("CDAudio: track %i is not audio\n", track);
237 - if (playTrack == track)
243 - ti.cdti_trk0 = track;
244 - ti.cdti_trk1 = track;
249 + if (playTrack == track)
254 - if ( ioctl(cdfile, CDROMPLAYTRKIND, &ti) == -1 )
256 + ti.cdti_trk0 = track;
257 + ti.cdti_trk1 = track;
260 + if ( ioctl(cdfile, CDROMPLAYTRKIND, &ti) == -1 )
262 - Con_DPrintf("ioctl cdromplaytrkind failed\n");
264 + Con_DPrintf("ioctl cdromplaytrkind failed\n");
268 - if ( ioctl(cdfile, CDROMRESUME) == -1 )
269 - Con_DPrintf("ioctl cdromresume failed\n");
270 + if ( ioctl(cdfile, CDROMRESUME) == -1 )
271 + Con_DPrintf("ioctl cdromresume failed\n");
275 + ti.start_track = track;
276 + ti.end_track = track;
277 + ti.start_index = 1;
279 + if ( ioctl(cdfile, CDIOCPLAYTRACKS, &ti) == -1 )
281 + Con_DPrintf("ioctl cdromplaytrkind failed\n");
285 - playLooping = looping;
288 + if ( ioctl(cdfile, CDIOCRESUME, &arg) == -1 )
289 + Con_DPrintf("ioctl cdromresume failed\n");
292 + playLooping = looping;
296 - if (cdvolume == 0.0)
298 + if (cdvolume == 0.0)
303 void CDAudio_Stop(void)
305 - if (cdfile == -1 || !enabled)
307 + if (cdfile == -1 || !enabled)
315 - if ( ioctl(cdfile, CDROMSTOP) == -1 )
316 - Con_DPrintf("ioctl cdromstop failed (%d)\n", errno);
318 + if ( ioctl(cdfile, CDROMSTOP) == -1 )
319 + Con_DPrintf("ioctl cdromstop failed (%d)\n", errno);
322 + if ( ioctl(cdfile, CDIOCSTOP) == -1 )
323 + Con_DPrintf("ioctl cdromstop failed (%d)\n", errno);
326 - wasPlaying = false;
328 + wasPlaying = false;
332 void CDAudio_Pause(void)
334 - if (cdfile == -1 || !enabled)
339 +#ifdef PAUSE_BY_STOPPING
343 + if (cdfile == -1 || !enabled)
349 +#ifndef PAUSE_BY_STOPPING
351 + if ( ioctl(cdfile, CDROMPAUSE) == -1 )
352 + Con_DPrintf("ioctl cdrompause failed\n");
356 + if ( ioctl(cdfile, CDIOCPAUSE) == -1 )
357 + Con_DPrintf("ioctl cdrompause failed\n");
360 + t_playLooping = playLooping;
361 + t_playTrack=playTrack;
367 - if ( ioctl(cdfile, CDROMPAUSE) == -1 )
368 - Con_DPrintf("ioctl cdrompause failed\n");
370 - wasPlaying = playing;
372 + wasPlaying = playing;
377 void CDAudio_Resume(void)
379 - if (cdfile == -1 || !enabled)
381 + if (cdfile == -1 || !enabled)
394 - if ( ioctl(cdfile, CDROMRESUME) == -1 )
395 - Con_DPrintf("ioctl cdromresume failed\n");
397 +#ifndef PAUSE_BY_STOPPING
399 + if ( ioctl(cdfile, CDROMRESUME) == -1 )
400 + Con_DPrintf("ioctl cdromresume failed\n");
404 + if ( ioctl(cdfile, CDIOCRESUME) == -1 )
405 + Con_DPrintf("ioctl cdromresume failed\n");
408 + CDAudio_Play(t_playTrack, t_playLooping);
414 static void CD_f (void)
415 @@ -327,43 +463,72 @@
417 void CDAudio_Update(void)
419 - struct cdrom_subchnl subchnl;
420 - static time_t lastchk;
422 + struct cdrom_subchnl subchnl;
425 + struct ioc_read_subchannel subchnl;
426 + struct cd_sub_channel_info data;
428 + static time_t lastchk;
435 - if (bgmvolume.value != cdvolume)
436 + if (bgmvolume.value != cdvolume)
442 - Cvar_SetValue ("bgmvolume", 0.0);
443 - cdvolume = bgmvolume.value;
448 - Cvar_SetValue ("bgmvolume", 1.0);
449 - cdvolume = bgmvolume.value;
452 + Cvar_SetValue ("bgmvolume", 0.0);
453 + cdvolume = bgmvolume.value;
457 - if (playing && lastchk < time(NULL)) {
458 - lastchk = time(NULL) + 2; //two seconds between chks
459 - subchnl.cdsc_format = CDROM_MSF;
460 - if (ioctl(cdfile, CDROMSUBCHNL, &subchnl) == -1 ) {
461 - Con_DPrintf("ioctl cdromsubchnl failed\n");
465 - if (subchnl.cdsc_audiostatus != CDROM_AUDIO_PLAY &&
466 - subchnl.cdsc_audiostatus != CDROM_AUDIO_PAUSED) {
469 - CDAudio_Play(playTrack, true);
473 + Cvar_SetValue ("bgmvolume", 1.0);
474 + cdvolume = bgmvolume.value;
480 + if (playing && lastchk < time(NULL)) {
481 + lastchk = time(NULL) + 2; /* two seconds between chks */
483 + subchnl.cdsc_format = CDROM_MSF;
484 + if (ioctl(cdfile, CDROMSUBCHNL, &subchnl) == -1 ) {
485 + Con_DPrintf("ioctl cdromsubchnl failed\n");
489 + if (subchnl.cdsc_audiostatus != CDROM_AUDIO_PLAY &&
490 + subchnl.cdsc_audiostatus != CDROM_AUDIO_PAUSED) {
493 + CDAudio_Play(playTrack, true);
497 + subchnl.address_format = CD_MSF_FORMAT;
498 + subchnl.data_format = CD_CURRENT_POSITION;
499 + subchnl.data_len = sizeof(data);
500 + subchnl.track = playTrack;
501 + subchnl.data = &data;
503 + if (ioctl(cdfile, CDIOCREADSUBCHANNEL, &subchnl) == -1 ) {
504 + Con_DPrintf("ioctl cdromsubchnl failed\n");
508 + if (subchnl.data->header.audio_status != CD_AS_PLAY_IN_PROGRESS &&
509 + subchnl.data->header.audio_status != CD_AS_PLAY_PAUSED) {
512 + CDAudio_Play(playTrack, true);
519 int CDAudio_Init(void)
523 if ((cdfile = open(cd_dev, O_RDONLY)) == -1) {
524 - Con_Printf("CDAudio_Init: open of \"%s\" failed (%i)\n", cd_dev, errno);
527 + Con_Printf("CDAudio_Init: open of \"%s\" failed (%i)\n", cd_dev, errno);
532 for (i = 0; i < 100; i++)