#include <stdio.h>
#include <windows.h>
#include <winioctl.h>
#include <conio.h>

typedef ULONG (*OPENPRT)(ULONG,ULONG,ULONG);
OPENPRT OpenPrt;
typedef DWORD (*RP)(ULONG,ULONG);
RP R_P;
typedef void (*WP)(ULONG,ULONG,ULONG);
WP W_P;
typedef void (*CLOSEPRT)(ULONG);
CLOSEPRT ClosePrt;
typedef UCHAR (*COUNTLPT)(ULONG*,ULONG*,ULONG*);
COUNTLPT CountLPT;

main()
{
	HANDLE vicx;
	vicx = LoadLibrary("vicx.dll");
	if(!vicx) {
		puts("Error VICX.DLL ! Press any kay to exit...");
		getch();
		exit(0);
	}

	OpenPrt = (OPENPRT)GetProcAddress(vicx,"OpenPrt");
	R_P = (RP)GetProcAddress(vicx,"R_P");
	W_P = (WP)GetProcAddress(vicx,"W_P");
	ClosePrt = (CLOSEPRT)GetProcAddress(vicx,"ClosePrt");
	CountLPT = (COUNTLPT)GetProcAddress(vicx,"CountLPT");

	printf("Get data and time from BIOS\n\n");
	ULONG yearHigh,yearLow,month,day,hour,min,sec;
	ULONG port = OpenPrt(0x70,1,2);
		
	W_P(port,0x32,0);//Write to port 0x70
	Sleep(1);
	yearHigh = R_P(port,1);//Read from port 0x71

	W_P(port,0x09,0);
	Sleep(1);
	yearLow  = R_P(port,1);

	W_P(port,0x08,0);
	Sleep(1);
	month = R_P(port,1);

	W_P(port,0x07,0);
	Sleep(1);
	day = R_P(port,1);

	W_P(port,0x04,0);
	Sleep(1);
	hour = R_P(port,1);

	W_P(port,0x02,0);
	Sleep(1);
	min = R_P(port,1);

	W_P(port,0x00,0);
	Sleep(1);
	sec = R_P(port,1);

	
	printf("Data/Time === %0.2x/%0.2x/%0.4x   %0.2x:%0.2x:%0.2x \n\n",day,month,yearHigh*0x100+yearLow,hour,min,sec);
	W_P(port,0x10,0);
	Sleep(1);
	ULONG floppy = R_P(port,1);
	printf("Floppy A :     ");

	switch(floppy>>4) {
	case 0x00:
		puts(" No ");
		break;
	case 0x01:
		puts("360 K");
		break;
	case 0x02:
		puts("720 K");
		break;
	case 0x03:
		puts("1.2 M");
		break;
	case 0x04:
		puts("1.44 M");
		break;
	}
	printf("Floppy B :    ");
	switch(floppy-(floppy>>4)*0x10) {
	case 0x00:
		puts(" No ");
		break;
	case 0x01:
		puts("360 K");
		break;
	case 0x02:
		puts("720 K");
		break;
	case 0x03:
		puts("1.2 M");
		break;
	case 0x04:
		puts("1.44 M");
		break;
	}
	
	puts("");

	ULONG p1,p2,p3;
	UCHAR z = CountLPT(&p1,&p2,&p3);
	printf("Number of LPT - ports ===== %d\n",z);  
	printf("p1 ===== %#x\np2 ===== %#x\np3 ===== %#x\n\n",p1,p2,p3);
	
	ClosePrt(port);
	
	FreeLibrary("vicx");
	puts("Press any kay to exit...");
	getch();
	return 0;
}