/*
	pribit.c
*/
#define USAGE "\tプリンタにビットイメージファイルを出力\n"\
		"usage: pribit filename"

#include <stdio.h>
#include <stdlib.h>
#include <dos.h>

#define PRNDATA 0x800

char prnbusy( void );

void main( int argc,char **argv ){

	FILE *fp;
	if( argc != 2 ){
		fputs( argv[0] , stderr );
		fputs( USAGE , stderr );
		exit(1);
	}
	if( ( fp = fopen( argv[1],"rb" ) ) == NULL ){
		fputs( "file open err.", stderr );
		exit(1);
	}

	fputs( "quit: ESC key.", stderr );
	while( ! feof(fp) ){
		while( prnbusy() );
		outp( PRNDATA, fgetc(fp) );
	}
}

char prnbusy( void ){
	union REGS in,out;
	in.h.ah = 0x00; /* プリンタ状態の読み取り */
	in.h.al = 0x00;	/* 標準ポート */
	int86( 0x94,&in,&out ); /* プリンタBIOS */
	if( out.h.ah != 0 ) {
		fputs( "printer bios err.", stderr );
		exit(1);
	}
	if( kbhit() && getch()==0x1b ) {
		fputs( "abort." , stderr );
		exit(1);
	}
	return( out.h.dl );
}
