/* Micro - C version of dosread */
#include <stdio.h>
extern int _AX_, _BX_, _CX_, _DX_;
char str[] = "c:/autoexec.bat";

main() {
  int handle;
  char dosbuf[1024];
  int size;
  char *filebuf;
  int a, b;
  printf ("&a = %x, &b = %x\n", &a, &b);
  printf ("&dosbuf[1] = %x\n", &dosbuf[1]);
  size = 1024;
  filebuf = malloc(size);
  printf ("ds = %x (%u)\n", get_ds());
  printf ("dosbuf = %x (%u)\n", dosbuf, dosbuf);
  printf ("filebuf = %x (%u)\n", filebuf, filebuf);
  memset (dosbuf, 0, 1024);
  memset (filebuf, 0, 1024);
  
  _AX_ = 0x3d00; /* open read only */
  _DX_ = (int)str;
  int86(0x21);
  handle = _AX_;
  printf ("handle = %d\n", handle);
  
  printf ("reading data from file\n");
  _AX_ = 0x3f00;
  _DX_ = (int)filebuf - size;
  _CX_ = size;
  _BX_ = handle;
  
  int86 (0x21);
  if (_AX_ > 0) {
    printf ("got some data\n");
    printf (dosbuf);
    printf (filebuf);
  }
  else {
    printf ("DOS error\n");
  }
  
  _AX_ = 0x3e00;
  _BX_ = handle;
  int86(0x21);
  free (filebuf); 
}
