
/*  This is actually not usable in a DOS BAT file.      */
/*  However you could easily modify it to work for you  */

#include <dos.h>

struct {
  unsigned char rhlen;     /* request header length    13     */
  unsigned char subu;      /* sub unit                  0     */
  unsigned char comc;      /* command code             12     */
  unsigned int  status;    /* status                    0     */
  unsigned char resvd[8];  /* reserved                  nulls */
  unsigned char mdb;       /* media descriptor byte     0     */
  unsigned int  toff;      /* transfer address offset   0     */
  unsigned int  tseg;      /* transfer address segment  0     */
  unsigned int  tranct;    /*  (sector count?)          1     */
  unsigned int  ssn;       /*  starting sector number   0     */
  unsigned int  volido;    /*  volume id                0     */
  unsigned int  volids;    /*  volume id                0     */
} ioctlo = { 13,0,12,0,"\0\0\0\0\0\0\0\0",0,0,0,1,0,0,0 };

struct {
  unsigned char job;       /* job   ( 0 = open, 5 = close )    */
} todo = { 0 };

void cddoor(unsigned char job, unsigned char drive) {

  todo.job = job;

  drive -= 'A';     /* make zero based (a=0, b=1, etc.) */

  _asm {
    push es
    pusha
    mov  cx,drive
    mov  bx,offset ioctlo
    mov  ax,seg ioctlo
    mov  es,ax
    mov  es:[bx+16],ax
    mov  ax,offset todo
    mov  es:[bx+14],ax
    mov  ax,1510h
    int  2Fh
    popa
    pop  es
	}
}

int main(void) {
  printf("\nOpening Door");
  cddoor(0x00, 'G');
  printf("\n  Press ENTER to continue...");
  getch();
  printf("\nClosing Door");
  cddoor(0x05, 'G');
  return(0);
}
