/***********************************************\
*                                               *
*          CDx Audio Access Sample Code         *
*                                               *
*  Prints out UPC numbers on disc (optional)    *
*                                               *
*  This version uses the cdx.device (v1.7+)     *
\***********************************************/

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

int   GetSubQ(struct SubQ *);

extern   struct   IOStdReq       *Req;

struct SubQ subq;


main(argc,argv)
int   argc;
char **argv;
{
   int   error,i,x,drive;
   char  scratch[21];

   ParseParams("CDupc [DRIVE n]",argc,argv,&drive,0);

   if (OpenCDx(drive))
      Cleanup("Drive not found",0);

   error = GetSubQ(&subq);
   if (error == CDERR_Stopped)         /* Not an error for UPC reading */
      error = 0;

   if (!error) {
      if (subq.UPCcode[0] == 0xFF)		/* No UPC code? */
         printf("Disc does not support encoded UPC\n");
      else {
         for (i=0,x=0;i<10;i++) {
            scratch[x++] = '0'+(subq.UPCcode[i]>>4);
            scratch[x++] = '0'+(subq.UPCcode[i]&0xF);
         }
         scratch[x] = 0;
         printf("UPC code: %ls\n",scratch);
      }
   }

   Cleanup(0,error);
}


int GetSubQ(subq)
struct SubQ *subq;
{
   Req->io_Command = CD_CURRENTLOCMSF;
   Req->io_Data = (APTR)subq;
   DoIO((struct IORequest *)Req);

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