/****************************************************************************
*
*
*   $VER: CDInfo.c  1.0 (22 Jan 1996) by M_Campinoti CD++
*
*   $HISTORY:
*
*   22 Jan 1996 : 001.000 : First and Last release of an example that show
*                           how to read and use the CDInfo structure.
*                           Didactical use, so CLI only      :)
*
****************************************************************************/

#include <proto/exec.h>
#include <exec/devices.h>
#include <exec/io.h>
#include <stdio.h>

#include "atapi_cd.h"


main (UBYTE argc,UBYTE **argv)
{
    struct IOStdReq      *ioreq = NULL ;
    struct MsgPort       *reply = NULL ;
    
    struct CDInfo        Info;
    
    if (argc== 0) return;   /* it came from workbench ..... */

    if( reply = CreateMsgPort() )
    {
      if( ioreq = (struct IOStdReq *)
             CreateIORequest(reply ,sizeof(struct  IOStdReq)) )
      {
        if(!OpenDevice("cd.device",0,(struct IORequest*)ioreq,NULL) )
        {
          ioreq->io_Command = CD_INFO;                /* Retrieve drive info.    */
          ioreq->io_Data    = (APTR)&Info;            /* Here's where we want it */
          ioreq->io_Length  = sizeof(struct CDInfo);  /* Return whole structure  */
          
          DoIO((struct IORequest*)ioreq);
          
          if (!ioreq->io_Error)                   /* Command succeeded        */
          {
           
           /* Printout the contents of the CDInfo structure .. */
           /* for more info see the file #include atapi_cd.h   */

            printf("------------------------------------------\n");
            printf("| CDInfo ©1995-1996 by M.Campinoti  CD++ |\n");
            printf("------------------------------------------\n");
            printf("Some data maybe wrong, depends by accuracy\n");
            printf("of your CDROM firmware !!!\n");
            printf("------------------------------------------\n");

            printf("Audio Play Speed            : %d\n",Info.PlaySpeed);
            printf("Date-rate of CD_READ        : %d\n",Info.ReadSpeed);
            printf("Date-rate of CD_READXL      : %d\n",Info.ReadXLSpeed);
            printf("Number of Bytes x Sectors   : %d\n",Info.SectorSize);
            if(Info.XLECC) printf("CDXL ECC enabled.\n");
            else           printf("CDXL ECC disabled.\n"); 
            if(Info.EjectReset) printf("Reset on Eject enabled.\n");
            else                printf("Reset on Eject disabled.\n");
            printf("Max speed drive can handle  : %d\n",Info.MaxSpeed);
            
            switch(Info.AudioPrecision)
            {
                case 0:
                        printf("Audio Precision     : No Attenuator\n");
                        break;
                case 1:
                        printf("Audio Precision     : Mute only\n");
                        break;
                default:
                        printf("Audio Precision             : %d Levels\n",Info.AudioPrecision);
                        break;
            }
            printf("------------------------------------------\n\n");
            printf("---------------STATUS FLAGS---------------\n");
           
            if (Info.Status & CDSTSF_CLOSED) printf("Drive Door is Closed\n");
            else                             printf("Drive Door is Open\n");

            if (Info.Status & CDSTSF_DISK) printf("A disk has been detected\n");
            else                           printf("No disk has been detected\n");

            if (Info.Status & CDSTSF_SPIN) printf("Disk is Spinning\n");
            else                           printf("Disk is not Spinning\n");

            if (Info.Status & CDSTSF_TOC) printf("TOC read, disk is valid\n");
            else                          printf("TOC not read, no valid disk\n");

            if (Info.Status & CDSTSF_CDROM) printf("Track 1 contains CDROM data\n");
            else                            printf("Track 1 no contains CDROM data\n");

            if (Info.Status & CDSTSF_PLAYING) printf("Audio is playing\n");
            else                              printf("Audio not playing\n");


            if (Info.Status & CDSTSF_PAUSED) printf("Pause Mode ON\n");
            else                             printf("Pause Mode OFF\n");

            if (Info.Status & CDSTSF_SEARCH) printf("Search Mode (FFW/FREW)\n");
            else                             printf("No Search Mode\n");

            if (Info.Status & CDSTSF_DIRECTION) printf("Search Direction: REVERSE\n");
            else                                printf("Search Direction: FORWARD\n");
           
            printf("------------------------------------------\n\n");
            
          }
          else printf("I/O error !\n");      /* analyze ioreq->io_Error to know what kind ... */
                                             /* ... see atapi_cd.h for #defines of it !       */
          
          CloseDevice((struct IORequest *)ioreq) ;
        }
        
        DeleteIORequest(ioreq) ;
      }

      DeleteMsgPort(reply);
    }
}

