/***********************************************\
*                                               *
*          CDx Audio Access Sample Code         *
*                                               *
*  Display/Set the output volume                *
*                                               *
*  This version uses the cdx.device (v1.7+)     *
\***********************************************/

#include <exec/types.h>
#include <exec/io.h>
#include <CDx.h>

int   GetVolume(int *,int *);
int   SetVolume(int,int);

extern   struct   IOStdReq       *Req;

main(argc,argv)
int   argc;
char **argv;
{
   int   left,right,error,drive,setit;

   setit = 0;
   error = ParseParams(0,argc,argv,&drive,0);		/* No volumes specified? */
   if (error) {
      ParseParams("CDvolume [DRIVE n] [<left> <right>]",
         argc,argv,&drive,2,&left,&right);
      setit = 1;
   }
   
   if (OpenCDx(drive))
      Cleanup("Drive not found",0);

   if (setit)
      error = SetVolume(left,right);
   else
      error = GetVolume(&left,&right);

   if (!error) {
      if (setit)
         printf("Set\n");
      else
         printf("Volume: L = %ld  R = %ld\n",left,right);
   }
   else if (error == CDERR_NotSupported) {
      printf("Your drive does not support volume control from software\n");
      error = 0;
   }

   Cleanup(0,error);
}


int GetVolume(left,right)
int   *left,*right;
{
   Req->io_Command = CD_GETVOLUME;
   DoIO((struct IORequest *)Req);

   *left = (Req->io_Actual>>8) & 0xFF;
   *right = Req->io_Actual & 0xFF;

   return((int)Req->io_Error);
}


int SetVolume(left,right)
int   left,right;
{
   Req->io_Command = CD_SETVOLUME;
   Req->io_Offset = left;
   Req->io_Length = right;
   DoIO((struct IORequest *)Req);

   return((int)Req->io_Error);
}
