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