#include <dos.h>
#include <keys.h>

/*************************************************
  Check printer status and flash message on screen
  if not ready.  User can abort by hitting Esc key
  returning a -1.  Routine will return a 0 when
  printer has been put online and is ready.
**************************************************/
chk_printer()
{
        while ((prtest()) != 0x90) {   /* Check for printer error */
            if (kbhit())
                if ((getch()) == ESCAPE)   /* Abort if escape is pressed */
                    return(-1);
            prterr();   /* Otherwise flash error message */
        }
     return(0);
}


prterr()   /* Error message for printer */
{
    char *tscr;

    tscr = malloc(4000);
    getscrn(tscr, 0);
    put_screen("                            ", 0x4f, 28, 1,
      25, 11, 0);
    put_screen(" ERROR - Printer not ready! ", 0x4f, 28, 1,
      25, 12, 0);
    put_screen("        ESC to exit         ", 0x4f, 28, 1,
      25, 13, 0);

    wait(2);
    putscrn(tscr, 0);
    free(tscr);
}


prtest()   /* Test for printer status (0x90 is good) */
{
    union REGS REG;

    REG.h.ah = 0x2;   /* Function 2 */
    REG.x.dx = 0;     /* First printer number */
    int86(0x17, &REG, &REG);
    return(REG.h.ah);
}


