home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 113 / EnigmaAmiga113CD.iso / software / sviluppo / glquake_src / cd_amiga.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-16  |  5.1 KB  |  274 lines

  1. /* 
  2. Copyright (C) 1996-1997 Id Software, Inc. 
  3.  
  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. 
  8.  
  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.   
  12.  
  13. See the GNU General Public License for more details. 
  14.  
  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. 
  18.  
  19. */ 
  20.  
  21. #include "quakedef.h" 
  22. #include "twfsound_cd.h"
  23. #include <devices/timer.h>
  24. #include <proto/timer.h>
  25. #ifdef WOS
  26. #include <clib/powerpc_protos.h>
  27. #else
  28. #ifdef __PPC__ /* PowerUP */
  29. extern void GetSysTimePPC(struct timeval *);
  30. #endif
  31. #endif
  32.  
  33. extern int FirstTime;  /* from sys_amiga.c */
  34.  
  35. static qboolean cdValid = false;
  36. static qboolean cdPlaying = false;
  37. static qboolean cdWasPlaying = false;
  38. static qboolean cdInitialised = false;
  39. static qboolean cdEnabled = false;
  40. static byte     cdPlayTrack;
  41. static byte     cdMaxTrack;
  42. static int      cdEmulatedStart;
  43. static int      cdEmulatedLength;
  44.  
  45. struct TWFCDData *twfdata=0;
  46.  
  47.  
  48.  
  49. static int Milliseconds(void)
  50. {
  51.   struct timeval tv;
  52.   int ms;
  53.  
  54. #ifdef __PPC__
  55.   GetSysTimePPC(&tv);
  56. #else
  57.   GetSysTime(&tv);
  58. #endif
  59.   return (tv.tv_secs-FirstTime)*1000 + tv.tv_micro/1000;
  60. }
  61.  
  62.  
  63. int CDAudio_GetAudioDiskInfo()
  64. {
  65.  
  66.   int err;
  67.   cdValid = false;
  68.  
  69.   err=TWFCD_ReadTOC(twfdata);
  70.   if(err==TWFCD_FAIL)
  71.   {
  72.     Con_Printf("CD Audio: Drive not ready\n");
  73.     return(0);
  74.   }
  75.  
  76.   cdMaxTrack=(twfdata->TWFCD_Table).cda_LastTrack;
  77.   if ((twfdata->TWFCD_Table.cda_FirstAudio)==TWFCD_NOAUDIO)
  78.   {
  79.     Con_Printf("CD Audio: No music tracks\n");
  80.     return(0);
  81.   }
  82.   cdValid = true;
  83.   return(1);
  84. }
  85.  
  86. void CDAudio_Play2(int realtrack, qboolean looping)
  87. {
  88.   int err;
  89.   struct TagItem tags[]=
  90.   {
  91.     TWFCD_Track_Start,0,
  92.     TWFCD_Track_End,0,
  93.     TWFCD_Track_Count,0,
  94.     TWFCD_Track_PlayMode,SCSI_CMD_PLAYAUDIO12,
  95.     0,0
  96.   };
  97.  
  98.   if (!cdEnabled) return;
  99.  
  100.   if ((realtrack < 1) || (realtrack > cdMaxTrack))
  101.   {
  102.     CDAudio_Stop();
  103.     return;
  104.   }
  105.  
  106.   if (!cdValid)
  107.   {
  108.     CDAudio_GetAudioDiskInfo();
  109.     if (!cdValid) return;
  110.   }
  111.  
  112.   if (!((twfdata->TWFCD_Table.cda_TrackData[realtrack]).cdt_Audio))
  113.   {
  114.     Con_Printf("CD Audio: Track %i is not audio\n", realtrack);
  115.     return;
  116.   }
  117.  
  118.   if(cdPlaying)
  119.   {
  120.     if(cdPlayTrack == realtrack) return;
  121.     CDAudio_Stop();
  122.   }
  123.  
  124.   tags[0].ti_Data=realtrack;
  125.   tags[1].ti_Data=realtrack;
  126.   tags[2].ti_Data=1;
  127.   tags[3].ti_Data=SCSI_CMD_PLAYAUDIO12;
  128.   err=TWFCD_PlayTracks(twfdata,tags);
  129.   if (err!=TWFCD_OK)
  130.   {
  131.     tags[3].ti_Data=SCSI_CMD_PLAYAUDIO_TRACKINDEX;
  132.     err=TWFCD_PlayTracks(twfdata,tags);
  133.     if (err!=TWFCD_OK)
  134.     {
  135.       tags[3].ti_Data=SCSI_CMD_PLAYAUDIO10;
  136.       err=TWFCD_PlayTracks(twfdata,tags);
  137.     }
  138.   }
  139.  
  140.   if (err!=TWFCD_OK)
  141.   {
  142.     Con_Printf("CD Audio: CD PLAY failed\n");
  143.     return;
  144.   }
  145.   cdEmulatedLength = (((twfdata->TWFCD_Table.cda_TrackData[realtrack]).cdt_Length)/75)*1000;
  146.   cdEmulatedStart = Milliseconds();
  147.  
  148.   cdPlayTrack = realtrack;
  149.   cdPlaying = true;
  150. }
  151.  
  152.  
  153. void CDAudio_Play(byte track, qboolean looping) 
  154.   CDAudio_Play2(track, looping);
  155.  
  156.  
  157. void CDAudio_Stop(void) 
  158.   if (!cdEnabled) return;
  159.   if (!cdPlaying) return;
  160.  
  161.   TWFCD_MotorControl(twfdata,TWFCD_MOTOR_STOP);
  162.   cdWasPlaying = false;
  163.   cdPlaying = false;
  164.  
  165.  
  166. void CDAudio_Pause(void) 
  167.   if(!cdEnabled) return;
  168.   if(!cdPlaying) return;
  169.  
  170.   TWFCD_PausePlay(twfdata);
  171.   cdWasPlaying = cdPlaying;
  172.   cdPlaying = false;
  173.  
  174.  
  175. void CDAudio_Resume(void) 
  176.   int err;
  177.   if (!cdEnabled) return;
  178.   if (!cdWasPlaying) return;
  179.   if (!cdValid) return;
  180.  
  181.   err=TWFCD_PausePlay(twfdata);
  182.  
  183.   cdPlaying = true;
  184.   if (err==TWFCD_FAIL) cdPlaying = false;
  185.  
  186.  
  187. void CDAudio_LoopTrack()
  188. {
  189.   cdPlaying=false;
  190.   CDAudio_Play2(cdPlayTrack, true);
  191. }
  192.  
  193. void CDAudio_Update(void) 
  194.   if(!cdPlaying) return;
  195.  
  196.   if(Milliseconds() > (cdEmulatedStart + cdEmulatedLength))
  197.   {
  198.     CDAudio_LoopTrack();
  199.   }
  200.  
  201.  
  202. int CDAudio_HardwareInit()
  203. {
  204.   char devname[255];
  205.   char unitname[255];
  206.   int unit;
  207.   cdInitialised=true;
  208.   if (cdInitialised)
  209.   {
  210.     if (0<(GetVar("env:Quake1/cd_device",devname,255,0)))
  211.     {
  212.     }
  213.     else
  214.     {
  215.       cdInitialised=0;
  216.       return 0;
  217.     }
  218.  
  219.     if (0<GetVar("env:Quake1/cd_unit",unitname,255,0))
  220.     {
  221.       unit=atoi(unitname);
  222.     }
  223.     else
  224.     {
  225.       cdInitialised=0;
  226.       return 0;
  227.     }
  228.   }
  229.   if (cdInitialised)
  230.   {
  231.     char test[1024];
  232.     sprintf(test,"%s %i ",devname,unit);
  233.     Con_Printf(test);
  234.     twfdata=TWFCD_Setup(devname,unit);
  235.     if (!twfdata) cdInitialised=false;
  236.     return(CDAudio_GetAudioDiskInfo());
  237.   }
  238.   else return 0;
  239. }
  240.  
  241. int CDAudio_Init(void) 
  242.  
  243.   cdEnabled = false;
  244.   cdInitialised = false;
  245.   if (COM_CheckParm("-nocdaudio")) return -1;
  246.   cdEnabled = true;
  247.  
  248.   if(!CDAudio_HardwareInit())
  249.   {
  250.     cdEnabled=false;
  251.   }
  252.   Con_Printf("CD Audio Initialized\n");
  253.   return(0);
  254.  
  255.  
  256. void CDAudio_Shutdown(void) 
  257.   if(!cdInitialised) return;
  258.   CDAudio_Stop();
  259.   TWFCD_Shutdown(twfdata);
  260. }
  261.