#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

void ToKBD(int hd, unsigned char val)
{
    unsigned char byte;
    do { lseek(hd,0x64,SEEK_SET); read(hd,&byte,1); } while(byte & 0x02);
    lseek(hd,0x60,SEEK_SET); byte = val;    write(hd,&byte,1);
}

int main()
{
    unsigned char byte;
    
    int hd = open("/dev/port",O_RDWR);
    if(hd < 0)
    { 
	printf("Open /dev/port of error!");
	exit(-1);
    }
/*
    lseek(hd,0x60,SEEK_SET); byte = 0xED; write(hd,&byte,1); usleep(1000);
    lseek(hd,0x60,SEEK_SET); byte = 0x02; write(hd,&byte,1); usleep(1000);
    lseek(hd,0x60,SEEK_SET); byte = 0xED; write(hd,&byte,1); usleep(1000);
    lseek(hd,0x60,SEEK_SET); byte = 0x00; write(hd,&byte,1); usleep(1000);
*/

    for(int ii=0; ii<1000 ; ii++)
    {
	//show all
	for(int i=0; i<63; i++) { ToKBD(hd,0xED); ToKBD(hd,0x02); ToKBD(hd,0xED); ToKBD(hd,i); }
	sleep(5);
	//blym all
	for(int i=0; i<63; i++) { ToKBD(hd,0xED); ToKBD(hd,0x03); ToKBD(hd,0xED); ToKBD(hd,i); }
	sleep(5);	
	//blacking all
	for(int i=0; i<63; i++) { ToKBD(hd,0xED); ToKBD(hd,0x01); ToKBD(hd,0xED); ToKBD(hd,i); }
	sleep(5);
    }

    return(0);
}

