Information Technology Reference
In-Depth Information
16.3.1 BIOS printer
Program 16.1 uses the BIOS printer interrupt to test the status of the printer and output char-
acters to the printer.
Program 16.1
#include <dos.h>
#include <stdio.h>
#include <conio.h>
#define PRINTERR -1
void print_character(int ch);
int init_printer(void);
int main(void)
{
int status,ch;
status=init_printer();
if (status==PRINTERR) return(1);
do
{
printf("Enter character to output to printer");
ch=getch();
print_character(ch);
} while (ch!=4);
return(0);
}
int init_printer(void)
{
union REGS inregs,outregs;
inregs.h.ah=0x01; /* initialize printer */
inregs.x.dx=0; /* LPT1: */
int86(0x17,&inregs,&outregs);
if (inregs.h.ah & 0x20)
{ puts("Out of paper"); return(PRINTERR); }
else if (inregs.h.ah & 0x08)
{ puts("I/O error"); return(PRINTERR); }
else if (inregs.h.ah & 0x01)
{ puts("Printer timeout"); return(PRINTERR); }
return(0);
}
void print_character(int ch)
{
union REGS inregs,outregs;
inregs.h.ah=0x00; /* print character */
inregs.x.dx=0; /* LPT1: */
inregs.h.al=ch;
int86(0x17,&inregs,&outregs);
}
Search WWH ::




Custom Search