/*
** CONTRAST.C
*/

#use op71l.lib
#use op71hw.lib
#use vdriver.lib
#use ENGFONTL.LIB

main() {
	auto struct _fontInfo fi;	//	declare struct to hold font information
	auto unsigned x,y,z;
	auto unsigned long timeMark;
	auto unsigned contrast;

	outport(DCNTL,(inport(DCNTL)&0xf)|0x60);	//	setup 3 I/O wait and 1 mem wait states
	VdInit();
	glInit();		//	initialize the software and hardware modules

	op71BackLight(1);
	
	glBlankScreen();		//	blank the screen

	glXFontInit(	//	initialize the font info structure needed later
		&fi,			//	pointer to the font info structure to fill
		6,				//	horizontal size (in pixels) of each character
		8,				//	vertical size (in pixels) of each character
		32,			//	beginning code of printable characters
		255,			//	ending code of printable characters
		engFont6x8	//	address of font bitmap in xmem
		);
	
	glSetBrushType(GL_XOR);		//	set exclusive-or mode

	z = 32;
	for (y = 8; y <= OP71YS-8; y += 8) {		//	display one less than the maximum rows
		glBuffLock();
		for (x = 0; x <= OP71XS-6; x+=6) {		//	display as many columns as we can
			glPrintf(x,y,&fi,"%c",z);		//	display the next ASCII code
			++z;										//	increment ASCII code
			if (z > 255) z = 32;					//	is it time to wrap around?
		}
		glBuffUnlock();
	}
	
	glSetBrushType(GL_BLOCK);		//	set block overwrite mode

	contrast = 0;
	while (1) {
		while (contrast < 63) {
			op71SetContrast(contrast);
			timeMark = MS_TIMER;
			glPrintf(0,0,&fi,"C=%3u",contrast);
			while (MS_TIMER - timeMark < 20);
			contrast += 1;
		}
		while (contrast > 0) {
			op71SetContrast(contrast);
			timeMark = MS_TIMER;
			glPrintf(0,0,&fi,"C=%3u",contrast);
			while (MS_TIMER - timeMark < 20);
			contrast -= 1;
		}
	}
}
