#include "client.h"
#include "mscdex.h"

int ismscdex (void) {
  DOS_CMD = CALL_IRQ;
  DOS_ARG = MSCDEX_INT;
  
  DOS_AX = MSCDEX_GETNUM;
  DOS_BX = 0;
  DOS_CX = 0;
  call_dosemu();
  return DOS_BX > 0;
}

int numdrvs (void) {
  if (!ismscdex()) 
    return 0;
  return DOS_BX;
}

int firstdrv (void) {
  if (!ismscdex())
    return 0;
  return DOS_CX;
}

double mscdex_ver (void) {
  if (!ismscdex())
    return 0.0;
  
  DOS_AX = MSCDEX_VER;
  DOS_BX = 0;
  DOS_CX = 0;
  DOS_CMD = CALL_IRQ;
  DOS_ARG = MSCDEX_INT;
  call_dosemu();
  return double ((DOS_BX >> 8)) + (double ((DOS_BX & 0xff)) * 0.01);
}


void senddevreq (int arg1, int arg2) {
  DOS_AX = MSCDEX_DEVREQ;
  DOS_BX = arg2;
  DOS_CX = arg1;
  DOS_CMD = CALL_IRQ;
  DOS_ARG = MSCDEX_INT;
  call_dosemu();
}

void cdstop (int drive) {
  ioctlstop * ios = (ioctlstop *)server->data_area;
  ios->hdr.command = CD_STOP_AUDIO;
  ios->hdr.len = 13;
  ios->hdr.status = 0;
  ios->hdr.subunit = (unsigned char) drive;
  senddevreq(drive, DOS_BUFFER);
}
  
