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

typedef DWORD (*RP)(USHORT,UCHAR);
RP R_P;
typedef void (*WP)(USHORT,UCHAR,ULONG);
WP W_P;

main()
{
	USHORT port1  = 0x70;
	USHORT port2  = 0x71;
	HANDLE vicx;
	vicx = LoadLibrary("vicx95.dll");
	if(!vicx) {
		puts("Error VICX95.DLL ! Press any kay to exit...");
		getch();
		exit(0);
	}

	R_P = (RP)GetProcAddress(vicx,"R_P");
	W_P = (WP)GetProcAddress(vicx,"W_P");

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

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

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

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

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

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

	W_P(port1,1,0x00);
	Sleep(1);
	sec = R_P(port2,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);
	
	puts("");

	FreeLibrary("vicx");
	puts("Press any kay to exit...");
	getch();
	return 0;
}