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