#include <stdio.h>
#include <asm/types.h>
#include <unistd.h>
#include <asm/io.h>

#define LP_BASE 0x3bc

int main(int argc, char **argv) {

	__u8 portdata;

	if(argc < 2) {
		fprintf(stderr, "Must supply a value to send to port...\n");
		exit(1);
	}

	/* attempt to reserve region in io space */
	if(ioperm(LP_BASE, 3, 1) < 0) {
		fprintf(stderr, "Cannot reserve region in io space, aborting...\n");
		exit(1);
	}

	/* send data byte to io port */
	outb(0x, LP_BASE+2);

	/*
	** While the BUSY input line is set
	**   display dots on the console
	** end while
	** Toggle the data byte
	*/
	while( (inb(LP_BASE+1) & 0x0080) == 0) {
		printf("1");
	}
	outb(0xED, LP_BASE+2);
	outb(0xEC, LP_BASE+2);

	/* attempt to release reserved region in io space */
	if(ioperm(LP_BASE, 3, 0) < 0) {
		fprintf(stderr, "Cannot release region in io space, aborting...\n");
		exit(1);
	}

	return(0);  /* just to be nice ;) */

}
