/****************************************************************************
*
*
*   $VER: OpenDoor.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 open the drive door by means of CD_EJECT command.
*                           Didactical use, so CLI & WB      :)
*
****************************************************************************/
#include <proto/exec.h>
#include <exec/devices.h>
#include <exec/io.h>
#include <stdio.h>

#include "atapi_cd.h"

#define OPEN_DOOR  1
#define CLOSE_DOOR 0

main (void)
{
    struct IOStdReq      *ioreq = NULL ;
    struct MsgPort       *reply = NULL ;
    
    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_EJECT ;
          ioreq->io_Length  = OPEN_DOOR ;  /*  <-- change here to close the drive door */
          ioreq->io_Offset  = 0 ;

          DoIO((struct IORequest*)ioreq);
          
          if (!ioreq->io_Error)              /* Command succeeded        */
          {

          }
          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);
    }
}
