Скачиваний:
34
Добавлен:
15.09.2014
Размер:
2.67 Кб
Скачать
#include "windows.h"
#include "iostream.h"
#include "stdio.h"
#include "stdlib.h"
#include "conio.h"
#include "dos.h"
#include "stdarg.h"

int InitializeLPT();
void readEndprint(char *);
void printchar17(char);
void printchar21(char);
void printLPT(char *);

//using namespace std;
int addr;
char st;

int main()
{
	char buf[10000];
	char c;
	cout << "... Test LPT port ...\n\n";
	asm mov addr,0x0040;
	InitializeLPT();
	do
	{
        clrscr();
		cout << "1 - print from display - 17h\n";
		cout << "2 - print from file - 17h\n";
		cout << "3 - print from display - 21h\n";
		cout << "4 - print from file - 21h\n";
		cout << "5 - print\n";
		cout << "0 - exit\n";
		c = getch();
		switch(c)
		{
		case '1':
				st = c;
				cout << "Enter text:\n\n";
				gets(buf);
				printLPT(buf);
				break;
		case '2':
				st = c;
				cout << "Enter path to file:\n\n";
				gets(buf);
				readEndprint(buf);
				break;
		case '3':
				st = c;
				cout << "Enter text:\n\n";
				gets(buf);
				printLPT(buf);
				break;
		case '4':
				st = c;
				cout << "Enter path to file:\n\n";
				gets(buf);
				readEndprint(buf);
				break;
		case '5':
				_asm{
					mov ah, 00h
					mov al, 12
					mov dx, 00h
					int 17h
					mov ah, 01h
					mov dx, 00h
					int 17h
				}
				break;

		default:
				exit(EXIT_SUCCESS);
		}
	}while(c != '0');
	getch();
	return 0;
}


void readEndprint(char *buf)
{
	FILE* file;
	//hFile = CreateFileA(buf, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
	if((file = fopen(buf, "r")) == NULL)
		cout << "Error opening file\n";
	fseek(file, 3, 0);
	char c;
	int real;
	do
	{
		if(!fread(&c, sizeof(char), 1, file)) break;
		cout << c;
		if(st=='2')
			printchar17(c);
		else if(st=='4')
			printchar21(c);
	}while(c != EOF);
}

void printchar17(char c)
{
	_asm{
		mov ah,00h
		mov al,c
		mov dx,00h
		int 17h
	}
}


void printchar21(char c)
{
	_asm{
		mov ah, 05h
		mov dl, c
		int 21h
	}
}

int InitializeLPT()
{
	char SAH;
	int state;
	_asm{
		mov ah,02h
		mov dx,00h
		int 17h

		mov SAH,ah

		end ah,40h
		cmp ah,40h
		jne not_found

		mov ah,SAH
		end ah,90h
		cmp ah,90h
		jne is_busy
		//mov dx,037Ah

	}
	//puts("......READY.....");
	return 1;
not_found:
	//cout << (unsigned int)SAH;
	//puts("LPT printer not found .....");
	return 0;
is_busy:
	//puts("printer on LPT is busy....");
	return 0;
}

void printLPT(char *buf)
{
	int i = 0;
	while(buf[i])
	{
		if(st=='1')
			printchar17(buf[i++]);
		else if(st=='3')
			printchar21(buf[i++]);
	}
}