#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

void 
io_delay(void)
{
int i;
for (i=0;i<2;i++)
	inp(0x201);
}

unsigned long
test_timer(int value)
{
unsigned char val;
int i;
unsigned long j;

outp(0x388,4);	/* point to timers */
io_delay();
outp(0x389,0x60);
io_delay();
outp(0x388,4);
io_delay();
outp(0x389,0x80);
val = inp(0x388);

// OK now program timer #1
outp(0x388,2);
io_delay();
outp(0x389,(unsigned char)value);
io_delay();		// should I leave this out ????

// OK now start timer
outp(0x388,4);
io_delay();
outp(0x389,0x21);
//io_delay();		// should I leave this out ????

val = inp(0x389);	// ??? stunts does this .....

#ifdef NEVER
for (i=0x12C;i!=0;i--)
	{
	val = inp(0x388);
	if ((val & 0xc0) == 0xc0)
		break;
	}

if (i == 0)
#endif
	{
	j=0;
disable();
	while(1)
		{
		j++;
		val = inp(0x388);
		if ((val & 0xc0) == 0xc0)
			break;
		}
enable();
	return(j);
	}
}

void main(int argc,char *argv[])
{
unsigned int value;
int i;
	
for(i = 0; i<=0xff; i++)
	{
	printf("preload = %d  --  # reads = %ld\n",i,test_timer(i));
	}
}

