#include <dos.h>
#include <stdio.h>
#include <stdlib.h>

void log (char *msg)
  {
    union REGS r;

    FILE *fp = fopen("out","a");

    fputs(msg, fp);
    fputc('\n', fp);

    fclose(fp);

    // check if ESC key pressed
    r.h.ah = 1;
    int86(0x16, &r, &r);
    if (r.x.flags & 1)
      {
	r.h.ah = 0;
	int86(0x16, &r, &r);
	if (r.h.al == 27)
	  exit(1);
      }
    return;
  }
