Add files from parent branch HEAD:
[pkgsrc.git] / games / quake / patches / patch-ag
1 $NetBSD$
2
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
6  #include <time.h>
7  #include <errno.h>
8  
9 +#ifdef __linux__
10  #include <linux/cdrom.h>
11 +#endif
12 +
13 +#if defined(__DragonFly__)
14 +#include <sys/cdio.h>
15 +#endif
16 +
17 +#ifdef __NetBSD__
18 +#include <sys/cdio.h>
19 +
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 */
22 +
23 +#define PAUSE_BY_STOPPING 1
24 +
25 +#endif
26  
27  #include "quakedef.h"
28  
29 @@ -46,165 +62,296 @@ static byte       remap[100];
30  static byte            playTrack;
31  static byte            maxTrack;
32  
33 +#ifdef PAUSE_BY_STOPPING
34 +static qboolean t_playLooping;
35 +static byte t_playTrack;
36 +#endif
37 +
38  static int cdfile = -1;
39 +#ifdef __linux__
40  static char cd_dev[64] = "/dev/cdrom";
41 +#endif
42 +
43 +#ifdef __NetBSD__
44 +static char cd_dev[64] = "/dev/rcd0d";
45 +#endif
46 +
47 +#ifdef __DragonFly__
48 +static char cd_dev[64] = "/dev/cd0d";
49 +#endif
50  
51  static void CDAudio_Eject(void)
52  {
53 -       if (cdfile == -1 || !enabled)
54 -               return; // no cd init'd
55 -
56 -       if ( ioctl(cdfile, CDROMEJECT) == -1 ) 
57 -               Con_DPrintf("ioctl cdromeject failed\n");
58 +#if defined(__NetBSD__) || defined(__DragonFly__)
59 +  int arg=0;
60 +#endif
61 +
62 +  if (cdfile == -1 || !enabled)
63 +    return; // no cd init'd
64 +
65 +#ifdef __linux__
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");
71 +  arg = 1;
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");
78 +#endif
79  }
80  
81  
82  static void CDAudio_CloseDoor(void)
83  {
84 -       if (cdfile == -1 || !enabled)
85 -               return; // no cd init'd
86 +if (cdfile == -1 || !enabled)
87 +    return; // no cd init'd
88  
89 -       if ( ioctl(cdfile, CDROMCLOSETRAY) == -1 ) 
90 -               Con_DPrintf("ioctl cdromclosetray failed\n");
91 +#ifdef __linux__
92 +  if ( ioctl(cdfile, CDROMCLOSETRAY) == -1 ) 
93 +    Con_DPrintf("ioctl cdromclosetray failed\n");
94 +#endif
95 +#if defined(__NetBSD__) || defined(__DragonFly__)
96 +  if(ioctl(cdfile, CDIOCCLOSE, NULL) == -1) {
97 +    Con_DPrintf("ioctl cdromclosetray failed\n");
98 +  }
99 +#endif
100  }
101  
102  static int CDAudio_GetAudioDiskInfo(void)
103  {
104 -       struct cdrom_tochdr tochdr;
105 -
106 -       cdValid = false;
107 +#ifdef __linux__
108 +struct cdrom_tochdr tochdr;
109 +#endif
110 +#if defined(__NetBSD__) || defined(__DragonFly__)
111 +struct ioc_toc_header tochdr;
112 +#endif
113 +
114 +cdValid = false;
115 +
116 +#ifdef __linux
117 +if ( ioctl(cdfile, CDROMREADTOCHDR, &tochdr) == -1 ) 
118 +{
119 +  Con_DPrintf("ioctl cdromreadtochdr failed\n");
120 +  return -1;
121 +}
122 +#endif
123 +
124 +#if defined(__NetBSD__) || defined(__DragonFly__)
125 +if ( ioctl(cdfile, CDIOREADTOCHEADER, &tochdr) == -1 ) 
126 +{
127 +  Con_DPrintf("ioctl cdromreadtochdr failed\n");
128 +  return -1;
129 +}
130 +#endif
131 +
132 +#ifdef __linux__
133 +if (tochdr.cdth_trk0 < 1)
134 +  {
135 +    Con_DPrintf("CDAudio: no music tracks\n");
136 +    return -1;
137 +  }
138 +#endif
139 +#if defined(__NetBSD__) || defined(__DragonFly__)
140 +if (tochdr.starting_track < 1)
141 +  {
142 +    Con_DPrintf("CDAudio: no music tracks\n");
143 +    return -1;
144 +  }
145 +#endif
146 +
147 +cdValid = true;
148 +#ifdef __linux__
149 +maxTrack = tochdr.cdth_trk1;
150 +#endif
151 +#if defined(__NetBSD__) || defined(__DragonFly__)
152 +maxTrack = tochdr.ending_track;
153 +#endif
154  
155 -       if ( ioctl(cdfile, CDROMREADTOCHDR, &tochdr) == -1 ) 
156 -    {
157 -      Con_DPrintf("ioctl cdromreadtochdr failed\n");
158 -         return -1;
159 -    }
160 -
161 -       if (tochdr.cdth_trk0 < 1)
162 -       {
163 -               Con_DPrintf("CDAudio: no music tracks\n");
164 -               return -1;
165 -       }
166 -
167 -       cdValid = true;
168 -       maxTrack = tochdr.cdth_trk1;
169 -
170 -       return 0;
171 +return 0;
172  }
173  
174  
175  void CDAudio_Play(byte track, qboolean looping)
176  {
177 -       struct cdrom_tocentry entry;
178 -       struct cdrom_ti ti;
179 +#ifdef __linux__
180 +  struct cdrom_tocentry entry;
181 +  struct cdrom_ti ti;
182 +#endif
183 +
184 +#if defined(__NetBSD__) || defined(__DragonFly__)
185 +  struct ioc_read_toc_entry entry;
186 +  struct ioc_play_track ti;
187 +  int arg=1;
188 +#endif
189  
190 -       if (cdfile == -1 || !enabled)
191 -               return;
192 +  if (cdfile == -1 || !enabled)
193 +    return;
194         
195 -       if (!cdValid)
196 -       {
197 -               CDAudio_GetAudioDiskInfo();
198 -               if (!cdValid)
199 -                       return;
200 -       }
201 +  if (!cdValid)
202 +    {
203 +      CDAudio_GetAudioDiskInfo();
204 +      if (!cdValid)
205 +       return;
206 +    }
207  
208 -       track = remap[track];
209 +  track = remap[track];
210  
211 -       if (track < 1 || track > maxTrack)
212 -       {
213 -               Con_DPrintf("CDAudio: Bad track number %u.\n", track);
214 -               return;
215 -       }
216 +  if (track < 1 || track > maxTrack)
217 +    {
218 +      Con_DPrintf("CDAudio: Bad track number %u.\n", track);
219 +      return;
220 +    }
221  
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 )
226 -       {
227 -               Con_DPrintf("ioctl cdromreadtocentry failed\n");
228 -               return;
229 -       }
230 -       if (entry.cdte_ctrl == CDROM_DATA_TRACK)
231 -       {
232 -               Con_Printf("CDAudio: track %i is not audio\n", track);
233 -               return;
234 -       }
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 )
240 +    {
241 +      Con_DPrintf("ioctl cdromreadtocentry failed\n");
242 +      return;
243 +    }
244 +  if (entry.cdte_ctrl == CDROM_DATA_TRACK)
245 +    {
246 +      Con_Printf("CDAudio: track %i is not audio\n", track);
247 +      return;
248 +    }
249  
250 -       if (playing)
251 -       {
252 -               if (playTrack == track)
253 -                       return;
254 -               CDAudio_Stop();
255 -       }
256 +#endif
257  
258 -       ti.cdti_trk0 = track;
259 -       ti.cdti_trk1 = track;
260 -       ti.cdti_ind0 = 1;
261 -       ti.cdti_ind1 = 99;
262 +  if (playing)
263 +    {
264 +      if (playTrack == track)
265 +       return;
266 +      CDAudio_Stop();
267 +    }
268  
269 -       if ( ioctl(cdfile, CDROMPLAYTRKIND, &ti) == -1 ) 
270 +#ifdef __linux__
271 +  ti.cdti_trk0 = track;
272 +  ti.cdti_trk1 = track;
273 +  ti.cdti_ind0 = 1;
274 +  ti.cdti_ind1 = 99;
275 +  if ( ioctl(cdfile, CDROMPLAYTRKIND, &ti) == -1 ) 
276      {
277 -               Con_DPrintf("ioctl cdromplaytrkind failed\n");
278 -               return;
279 +      Con_DPrintf("ioctl cdromplaytrkind failed\n");
280 +      return;
281      }
282  
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");
287 +#endif
288 +
289 +#if defined(__NetBSD__) || defined(__DragonFly__)
290 +  ti.start_track = track;
291 +  ti.end_track = track;
292 +  ti.start_index = 1;
293 +  ti.end_index = 99;
294 +  if ( ioctl(cdfile, CDIOCPLAYTRACKS, &ti) == -1 ) 
295 +    {
296 +      Con_DPrintf("ioctl cdromplaytrkind failed\n");
297 +      return;
298 +    }
299  
300 -       playLooping = looping;
301 -       playTrack = track;
302 -       playing = true;
303 +  if ( ioctl(cdfile, CDIOCRESUME, &arg) == -1 ) 
304 +    Con_DPrintf("ioctl cdromresume failed\n");
305 +#endif
306 +
307 +  playLooping = looping;
308 +  playTrack = track;
309 +  playing = true;
310  
311 -       if (cdvolume == 0.0)
312 -               CDAudio_Pause ();
313 +  if (cdvolume == 0.0)
314 +    CDAudio_Pause ();
315  }
316  
317  
318  void CDAudio_Stop(void)
319  {
320 -       if (cdfile == -1 || !enabled)
321 -               return;
322 +  if (cdfile == -1 || !enabled)
323 +    return;
324         
325 -       if (!playing)
326 -               return;
327 +  if (!playing)
328 +    return;
329  
330 -       if ( ioctl(cdfile, CDROMSTOP) == -1 )
331 -               Con_DPrintf("ioctl cdromstop failed (%d)\n", errno);
332 +#ifdef __linux__
333 +  if ( ioctl(cdfile, CDROMSTOP) == -1 )
334 +    Con_DPrintf("ioctl cdromstop failed (%d)\n", errno);
335 +#endif
336 +#if defined(__NetBSD__) || defined(__DragonFly__)
337 +  if ( ioctl(cdfile, CDIOCSTOP) == -1 )
338 +    Con_DPrintf("ioctl cdromstop failed (%d)\n", errno);
339 +#endif
340  
341 -       wasPlaying = false;
342 -       playing = false;
343 +  wasPlaying = false;
344 +  playing = false;
345  }
346  
347  void CDAudio_Pause(void)
348  {
349 -       if (cdfile == -1 || !enabled)
350 -               return;
351 -
352 -       if (!playing)
353 -               return;
354 -
355 -       if ( ioctl(cdfile, CDROMPAUSE) == -1 ) 
356 -               Con_DPrintf("ioctl cdrompause failed\n");
357 +#ifdef PAUSE_BY_STOPPING
358 +  qboolean t;
359 +#endif
360 +
361 +  if (cdfile == -1 || !enabled)
362 +    return;
363 +
364 +  if (!playing)
365 +    return;
366 +
367 +#ifndef PAUSE_BY_STOPPING
368 +#ifdef __linux__
369 +  if ( ioctl(cdfile, CDROMPAUSE) == -1 ) 
370 +    Con_DPrintf("ioctl cdrompause failed\n");
371 +#endif
372 +
373 +#if defined(__NetBSD__) || defined(__DragonFly__)
374 +  if ( ioctl(cdfile, CDIOCPAUSE) == -1 ) 
375 +    Con_DPrintf("ioctl cdrompause failed\n");
376 +#endif
377 +#else
378 +  t_playLooping = playLooping;
379 +  t_playTrack=playTrack;
380 +  t=playing;
381 +  CDAudio_Stop();
382 +  playing=t;
383 +#endif
384  
385 -       wasPlaying = playing;
386 -       playing = false;
387 +  wasPlaying = playing;
388 +  playing = false;
389  }
390  
391  
392  void CDAudio_Resume(void)
393  {
394 -       if (cdfile == -1 || !enabled)
395 -               return;
396 +  if (cdfile == -1 || !enabled)
397 +    return;
398         
399 -       if (!cdValid)
400 -               return;
401 +  if (!cdValid)
402 +    return;
403  
404 -       if (!wasPlaying)
405 -               return;
406 +  if (!wasPlaying)
407 +    return;
408         
409 -       if ( ioctl(cdfile, CDROMRESUME) == -1 ) 
410 -               Con_DPrintf("ioctl cdromresume failed\n");
411 -       playing = true;
412 +#ifndef PAUSE_BY_STOPPING
413 +#ifdef __linux__
414 +  if ( ioctl(cdfile, CDROMRESUME) == -1 ) 
415 +    Con_DPrintf("ioctl cdromresume failed\n");
416 +#endif
417 +
418 +#if defined(__NetBSD__) || defined(__DragonFly__)
419 +  if ( ioctl(cdfile, CDIOCRESUME) == -1 ) 
420 +    Con_DPrintf("ioctl cdromresume failed\n");
421 +#endif
422 +#else
423 +  CDAudio_Play(t_playTrack, t_playLooping);
424 +#endif
425 +
426 +  playing = true;
427  }
428  
429  static void CD_f (void)
430 @@ -327,43 +474,72 @@ static void CD_f (void)
431  
432  void CDAudio_Update(void)
433  {
434 -       struct cdrom_subchnl subchnl;
435 -       static time_t lastchk;
436 +#ifdef __linux__
437 +  struct cdrom_subchnl subchnl;
438 +#endif
439 +#if defined(__NetBSD__) || defined(__DragonFly__)
440 +  struct ioc_read_subchannel subchnl;
441 +  struct cd_sub_channel_info data;
442 +#endif
443 +  static time_t lastchk;
444  
445 -       if (!enabled)
446 -               return;
447 +  if (!enabled)
448 +    return;
449  
450 -       if (bgmvolume.value != cdvolume)
451 +  if (bgmvolume.value != cdvolume)
452 +    {
453 +      if (cdvolume)
454         {
455 -               if (cdvolume)
456 -               {
457 -                       Cvar_SetValue ("bgmvolume", 0.0);
458 -                       cdvolume = bgmvolume.value;
459 -                       CDAudio_Pause ();
460 -               }
461 -               else
462 -               {
463 -                       Cvar_SetValue ("bgmvolume", 1.0);
464 -                       cdvolume = bgmvolume.value;
465 -                       CDAudio_Resume ();
466 -               }
467 +         Cvar_SetValue ("bgmvolume", 0.0);
468 +         cdvolume = bgmvolume.value;
469 +         CDAudio_Pause ();
470         }
471 -
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");
477 -                       playing = false;
478 -                       return;
479 -               }
480 -               if (subchnl.cdsc_audiostatus != CDROM_AUDIO_PLAY &&
481 -                       subchnl.cdsc_audiostatus != CDROM_AUDIO_PAUSED) {
482 -                       playing = false;
483 -                       if (playLooping)
484 -                               CDAudio_Play(playTrack, true);
485 -               }
486 +      else
487 +       {
488 +         Cvar_SetValue ("bgmvolume", 1.0);
489 +         cdvolume = bgmvolume.value;
490 +         CDAudio_Resume ();
491         }
492 +    }
493 +
494 +
495 +  if (playing && lastchk < time(NULL)) {
496 +    lastchk = time(NULL) + 2;    /* two seconds between chks */
497 +#ifdef __linux
498 +    subchnl.cdsc_format = CDROM_MSF;
499 +    if (ioctl(cdfile, CDROMSUBCHNL, &subchnl) == -1 ) {
500 +      Con_DPrintf("ioctl cdromsubchnl failed\n");
501 +      playing = false;
502 +      return;
503 +    }
504 +    if (subchnl.cdsc_audiostatus != CDROM_AUDIO_PLAY &&
505 +       subchnl.cdsc_audiostatus != CDROM_AUDIO_PAUSED) {
506 +      playing = false;
507 +      if (playLooping)
508 +       CDAudio_Play(playTrack, true);
509 +    }
510 +#endif
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;
517 +
518 +    if (ioctl(cdfile, CDIOCREADSUBCHANNEL, &subchnl) == -1 ) {
519 +      Con_DPrintf("ioctl cdromsubchnl failed\n");
520 +      playing = false;
521 +      return;
522 +    }
523 +    if (subchnl.data->header.audio_status != CD_AS_PLAY_IN_PROGRESS &&
524 +       subchnl.data->header.audio_status != CD_AS_PLAY_PAUSED) {
525 +      playing = false;
526 +      if (playLooping)
527 +       CDAudio_Play(playTrack, true);
528 +    }
529 +#endif
530 +  }
531 +
532  }
533  
534  int CDAudio_Init(void)
535 @@ -382,9 +558,9 @@ int CDAudio_Init(void)
536         }
537  
538         if ((cdfile = open(cd_dev, O_RDONLY)) == -1) {
539 -               Con_Printf("CDAudio_Init: open of \"%s\" failed (%i)\n", cd_dev, errno);
540 -               cdfile = -1;
541 -               return -1;
542 +         Con_Printf("CDAudio_Init: open of \"%s\" failed (%i)\n", cd_dev, errno);
543 +         cdfile = -1;
544 +         return -1;
545         }
546  
547         for (i = 0; i < 100; i++)