3 --- winquake/cd_linux.c.orig 1999-12-21 18:40:50.000000000 +0000
4 +++ winquake/cd_linux.c
5 @@ -31,7 +31,23 @@ Foundation, Inc., 59 Temple Place - Suit
10 #include <linux/cdrom.h>
13 +#if defined(__DragonFly__)
14 +#include <sys/cdio.h>
18 +#include <sys/cdio.h>
20 +/* resume seems to have some trouble right now. xcdplayer also can not resume
21 + the drive correctly. It appears to play, but no audio is heard */
23 +#define PAUSE_BY_STOPPING 1
29 @@ -46,165 +62,296 @@ static byte remap[100];
30 static byte playTrack;
33 +#ifdef PAUSE_BY_STOPPING
34 +static qboolean t_playLooping;
35 +static byte t_playTrack;
38 static int cdfile = -1;
40 static char cd_dev[64] = "/dev/cdrom";
44 +static char cd_dev[64] = "/dev/rcd0d";
48 +static char cd_dev[64] = "/dev/cd0d";
51 static void CDAudio_Eject(void)
53 - if (cdfile == -1 || !enabled)
54 - return; // no cd init'd
56 - if ( ioctl(cdfile, CDROMEJECT) == -1 )
57 - Con_DPrintf("ioctl cdromeject failed\n");
58 +#if defined(__NetBSD__) || defined(__DragonFly__)
62 + if (cdfile == -1 || !enabled)
63 + return; // no cd init'd
66 + if ( ioctl(cdfile, CDROMEJECT) == -1 )
67 + Con_DPrintf("ioctl cdromeject failed\n");
68 +#elif defined(__NetBSD__)
69 + if(ioctl(cdfile, DIOCLOCK, &arg) == -1)
70 + Con_DPrintf("ioctl cdromunlock failed\n");
72 + if ( ioctl(cdfile, DIOCEJECT, &arg) == -1 )
73 + Con_DPrintf("ioctl cdromeject failed\n");
74 +#elif defined(__DragonFly__)
75 + ioctl(cdfile, CDIOCALLOW);
76 + if ( ioctl(cdfile, CDIOCEJECT) == -1 )
77 + Con_DPrintf("ioctl cdromeject failed\n");
82 static void CDAudio_CloseDoor(void)
84 - if (cdfile == -1 || !enabled)
85 - return; // no cd init'd
86 +if (cdfile == -1 || !enabled)
87 + return; // no cd init'd
89 - if ( ioctl(cdfile, CDROMCLOSETRAY) == -1 )
90 - Con_DPrintf("ioctl cdromclosetray failed\n");
92 + if ( ioctl(cdfile, CDROMCLOSETRAY) == -1 )
93 + Con_DPrintf("ioctl cdromclosetray failed\n");
95 +#if defined(__NetBSD__) || defined(__DragonFly__)
96 + if(ioctl(cdfile, CDIOCCLOSE, NULL) == -1) {
97 + Con_DPrintf("ioctl cdromclosetray failed\n");
102 static int CDAudio_GetAudioDiskInfo(void)
104 - struct cdrom_tochdr tochdr;
108 +struct cdrom_tochdr tochdr;
110 +#if defined(__NetBSD__) || defined(__DragonFly__)
111 +struct ioc_toc_header tochdr;
117 +if ( ioctl(cdfile, CDROMREADTOCHDR, &tochdr) == -1 )
119 + Con_DPrintf("ioctl cdromreadtochdr failed\n");
124 +#if defined(__NetBSD__) || defined(__DragonFly__)
125 +if ( ioctl(cdfile, CDIOREADTOCHEADER, &tochdr) == -1 )
127 + Con_DPrintf("ioctl cdromreadtochdr failed\n");
133 +if (tochdr.cdth_trk0 < 1)
135 + Con_DPrintf("CDAudio: no music tracks\n");
139 +#if defined(__NetBSD__) || defined(__DragonFly__)
140 +if (tochdr.starting_track < 1)
142 + Con_DPrintf("CDAudio: no music tracks\n");
149 +maxTrack = tochdr.cdth_trk1;
151 +#if defined(__NetBSD__) || defined(__DragonFly__)
152 +maxTrack = tochdr.ending_track;
155 - if ( ioctl(cdfile, CDROMREADTOCHDR, &tochdr) == -1 )
157 - Con_DPrintf("ioctl cdromreadtochdr failed\n");
161 - if (tochdr.cdth_trk0 < 1)
163 - Con_DPrintf("CDAudio: no music tracks\n");
168 - maxTrack = tochdr.cdth_trk1;
175 void CDAudio_Play(byte track, qboolean looping)
177 - struct cdrom_tocentry entry;
178 - struct cdrom_ti ti;
180 + struct cdrom_tocentry entry;
181 + struct cdrom_ti ti;
184 +#if defined(__NetBSD__) || defined(__DragonFly__)
185 + struct ioc_read_toc_entry entry;
186 + struct ioc_play_track ti;
190 - if (cdfile == -1 || !enabled)
192 + if (cdfile == -1 || !enabled)
197 - CDAudio_GetAudioDiskInfo();
203 + CDAudio_GetAudioDiskInfo();
208 - track = remap[track];
209 + track = remap[track];
211 - if (track < 1 || track > maxTrack)
213 - Con_DPrintf("CDAudio: Bad track number %u.\n", track);
216 + if (track < 1 || track > maxTrack)
218 + Con_DPrintf("CDAudio: Bad track number %u.\n", track);
222 - // don't try to play a non-audio track
223 - entry.cdte_track = track;
224 - entry.cdte_format = CDROM_MSF;
225 - if ( ioctl(cdfile, CDROMREADTOCENTRY, &entry) == -1 )
227 - Con_DPrintf("ioctl cdromreadtocentry failed\n");
230 - if (entry.cdte_ctrl == CDROM_DATA_TRACK)
232 - Con_Printf("CDAudio: track %i is not audio\n", track);
235 +#ifdef __linux__ /* Not sure what the equiv is for NetBSD */
236 + /* don't try to play a non-audio track */
237 + entry.cdte_track = track;
238 + entry.cdte_format = CDROM_MSF;
239 + if ( ioctl(cdfile, CDROMREADTOCENTRY, &entry) == -1 )
241 + Con_DPrintf("ioctl cdromreadtocentry failed\n");
244 + if (entry.cdte_ctrl == CDROM_DATA_TRACK)
246 + Con_Printf("CDAudio: track %i is not audio\n", track);
252 - if (playTrack == track)
258 - ti.cdti_trk0 = track;
259 - ti.cdti_trk1 = track;
264 + if (playTrack == track)
269 - if ( ioctl(cdfile, CDROMPLAYTRKIND, &ti) == -1 )
271 + ti.cdti_trk0 = track;
272 + ti.cdti_trk1 = track;
275 + if ( ioctl(cdfile, CDROMPLAYTRKIND, &ti) == -1 )
277 - Con_DPrintf("ioctl cdromplaytrkind failed\n");
279 + Con_DPrintf("ioctl cdromplaytrkind failed\n");
283 - if ( ioctl(cdfile, CDROMRESUME) == -1 )
284 - Con_DPrintf("ioctl cdromresume failed\n");
285 + if ( ioctl(cdfile, CDROMRESUME) == -1 )
286 + Con_DPrintf("ioctl cdromresume failed\n");
289 +#if defined(__NetBSD__) || defined(__DragonFly__)
290 + ti.start_track = track;
291 + ti.end_track = track;
292 + ti.start_index = 1;
294 + if ( ioctl(cdfile, CDIOCPLAYTRACKS, &ti) == -1 )
296 + Con_DPrintf("ioctl cdromplaytrkind failed\n");
300 - playLooping = looping;
303 + if ( ioctl(cdfile, CDIOCRESUME, &arg) == -1 )
304 + Con_DPrintf("ioctl cdromresume failed\n");
307 + playLooping = looping;
311 - if (cdvolume == 0.0)
313 + if (cdvolume == 0.0)
318 void CDAudio_Stop(void)
320 - if (cdfile == -1 || !enabled)
322 + if (cdfile == -1 || !enabled)
330 - if ( ioctl(cdfile, CDROMSTOP) == -1 )
331 - Con_DPrintf("ioctl cdromstop failed (%d)\n", errno);
333 + if ( ioctl(cdfile, CDROMSTOP) == -1 )
334 + Con_DPrintf("ioctl cdromstop failed (%d)\n", errno);
336 +#if defined(__NetBSD__) || defined(__DragonFly__)
337 + if ( ioctl(cdfile, CDIOCSTOP) == -1 )
338 + Con_DPrintf("ioctl cdromstop failed (%d)\n", errno);
341 - wasPlaying = false;
343 + wasPlaying = false;
347 void CDAudio_Pause(void)
349 - if (cdfile == -1 || !enabled)
355 - if ( ioctl(cdfile, CDROMPAUSE) == -1 )
356 - Con_DPrintf("ioctl cdrompause failed\n");
357 +#ifdef PAUSE_BY_STOPPING
361 + if (cdfile == -1 || !enabled)
367 +#ifndef PAUSE_BY_STOPPING
369 + if ( ioctl(cdfile, CDROMPAUSE) == -1 )
370 + Con_DPrintf("ioctl cdrompause failed\n");
373 +#if defined(__NetBSD__) || defined(__DragonFly__)
374 + if ( ioctl(cdfile, CDIOCPAUSE) == -1 )
375 + Con_DPrintf("ioctl cdrompause failed\n");
378 + t_playLooping = playLooping;
379 + t_playTrack=playTrack;
385 - wasPlaying = playing;
387 + wasPlaying = playing;
392 void CDAudio_Resume(void)
394 - if (cdfile == -1 || !enabled)
396 + if (cdfile == -1 || !enabled)
409 - if ( ioctl(cdfile, CDROMRESUME) == -1 )
410 - Con_DPrintf("ioctl cdromresume failed\n");
412 +#ifndef PAUSE_BY_STOPPING
414 + if ( ioctl(cdfile, CDROMRESUME) == -1 )
415 + Con_DPrintf("ioctl cdromresume failed\n");
418 +#if defined(__NetBSD__) || defined(__DragonFly__)
419 + if ( ioctl(cdfile, CDIOCRESUME) == -1 )
420 + Con_DPrintf("ioctl cdromresume failed\n");
423 + CDAudio_Play(t_playTrack, t_playLooping);
429 static void CD_f (void)
430 @@ -327,43 +474,72 @@ static void CD_f (void)
432 void CDAudio_Update(void)
434 - struct cdrom_subchnl subchnl;
435 - static time_t lastchk;
437 + struct cdrom_subchnl subchnl;
439 +#if defined(__NetBSD__) || defined(__DragonFly__)
440 + struct ioc_read_subchannel subchnl;
441 + struct cd_sub_channel_info data;
443 + static time_t lastchk;
450 - if (bgmvolume.value != cdvolume)
451 + if (bgmvolume.value != cdvolume)
457 - Cvar_SetValue ("bgmvolume", 0.0);
458 - cdvolume = bgmvolume.value;
463 - Cvar_SetValue ("bgmvolume", 1.0);
464 - cdvolume = bgmvolume.value;
467 + Cvar_SetValue ("bgmvolume", 0.0);
468 + cdvolume = bgmvolume.value;
472 - if (playing && lastchk < time(NULL)) {
473 - lastchk = time(NULL) + 2; //two seconds between chks
474 - subchnl.cdsc_format = CDROM_MSF;
475 - if (ioctl(cdfile, CDROMSUBCHNL, &subchnl) == -1 ) {
476 - Con_DPrintf("ioctl cdromsubchnl failed\n");
480 - if (subchnl.cdsc_audiostatus != CDROM_AUDIO_PLAY &&
481 - subchnl.cdsc_audiostatus != CDROM_AUDIO_PAUSED) {
484 - CDAudio_Play(playTrack, true);
488 + Cvar_SetValue ("bgmvolume", 1.0);
489 + cdvolume = bgmvolume.value;
495 + if (playing && lastchk < time(NULL)) {
496 + lastchk = time(NULL) + 2; /* two seconds between chks */
498 + subchnl.cdsc_format = CDROM_MSF;
499 + if (ioctl(cdfile, CDROMSUBCHNL, &subchnl) == -1 ) {
500 + Con_DPrintf("ioctl cdromsubchnl failed\n");
504 + if (subchnl.cdsc_audiostatus != CDROM_AUDIO_PLAY &&
505 + subchnl.cdsc_audiostatus != CDROM_AUDIO_PAUSED) {
508 + CDAudio_Play(playTrack, true);
511 +#if defined(__NetBSD__) || defined(__DragonFly__)
512 + subchnl.address_format = CD_MSF_FORMAT;
513 + subchnl.data_format = CD_CURRENT_POSITION;
514 + subchnl.data_len = sizeof(data);
515 + subchnl.track = playTrack;
516 + subchnl.data = &data;
518 + if (ioctl(cdfile, CDIOCREADSUBCHANNEL, &subchnl) == -1 ) {
519 + Con_DPrintf("ioctl cdromsubchnl failed\n");
523 + if (subchnl.data->header.audio_status != CD_AS_PLAY_IN_PROGRESS &&
524 + subchnl.data->header.audio_status != CD_AS_PLAY_PAUSED) {
527 + CDAudio_Play(playTrack, true);
534 int CDAudio_Init(void)
535 @@ -382,9 +558,9 @@ int CDAudio_Init(void)
538 if ((cdfile = open(cd_dev, O_RDONLY)) == -1) {
539 - Con_Printf("CDAudio_Init: open of \"%s\" failed (%i)\n", cd_dev, errno);
542 + Con_Printf("CDAudio_Init: open of \"%s\" failed (%i)\n", cd_dev, errno);
547 for (i = 0; i < 100; i++)