// Author: Uberteg, Andrew Shinn
num hRev1	= -1;
num hRev2	= -1;

num hVtec1	= -1;
num hVtec2	= -1;
num hVtec3	= -1;
num hVtec4	= -1;

num hIab1	= -1;
num hIab2	= -1;

void open()
{
// Rev Limiter	
	num rev;
	num iab;
	num x = 10;
	num y = 10;

	CreateBorder(x, y, 200, 65, 5, 0, "Rev");
	CreateStatic(x+5, y-5, 100, 20, 5, 0, "Rev Limits");
	
	x = x + 20;
	y = y + 20;

	hRev1 = CreateEdit(x, y, 75, 20, 5, 0, "Rev1");
	CreateStatic(x+80, y, 90, 20, 5, 0, "Fuel Cut");
	setitem(hRev1, round(1875600 / readword(readword(0x3F5F)+2),0));
	
	y = y + 20;
	hRev2 = CreateEdit(x, y, 75, 20, 5, 0, "Rev2");
	CreateStatic(x+80, y, 90, 20, 5, 0, "Fuel Resume");
	setitem(hRev2, round(1875600 / readword(readword(0x3F5C)+2),0));


// VTEC
	x = 220;
	y = 10;

	CreateBorder(x, y, 240, 105, 5, 0, "VTEC Points");
	CreateStatic(x+5, y-5, 100, 20, 5, 0, "VTEC Points");

	x = x + 20;
	y = y + 20;

	rev = ((readbyte(0x645D) - 128) * 62.52);
	hVtec1 = CreateEdit(x, y, 75, 20, 5, 0, "Rev1");
	CreateStatic(x+80, y, 120, 20, 5, 0, "RPM Disengage");
	setitem(hVtec1, round(rev),0);
	
	y = y + 20;
	rev = (readbyte(0x645F) - 128) * 62.52;
	hVtec2 = CreateEdit(x, y, 75, 20, 5, 0, "Rev2");
	CreateStatic(x+80, y, 120, 20, 5, 0, "RPM Disengage");
	setitem(hVtec2, round(rev),0);

	y = y + 20;
	rev = (readbyte(0x6464) - 128) * 62.52;
	hVtec3 = CreateEdit(x, y, 75, 20, 5, 0, "Rev3");
	CreateStatic(x+80, y, 120, 20, 5, 0, "RPM Engage");
	setitem(hVtec3, round(rev),0);

	y = y + 20;
	rev = (readbyte(0x6466) - 128) * 62.52;
	hVtec4 = CreateEdit(x, y, 75, 20, 5, 0, "Rev4");
	CreateStatic(x+80, y, 120, 20, 5, 0, "RPM Engage");
	setitem(hVtec4, round(rev),0);


// IAB
	x = 10;
	y = 90;
	CreateBorder(x,y, 200, 65, 5, 0, "IAB");
	CreateStatic(x+5, y-5, 100, 20, 5, 0, "IAB RPM's");
	
	x = x + 20;
	y = y + 20;

	iab = (readbyte(0x43A2) - 128) * 62.52;
	hIab1 = CreateEdit(x, y, 75, 20, 5, 0, "Iab1");
	CreateStatic(x+80, y, 90, 20, 5, 0, "IAB Open");
	setitem(hIab1, round(iab),0);	

	y = y + 20;
	iab = (readbyte(0x439D) - 128) * 62.52;
	hIab2 = CreateEdit(x, y, 75, 20, 5, 0, "Iab2");
	CreateStatic(x+80, y, 90, 20, 5, 0, "IAB Close");
	setitem(hIab2, round(iab),0);	

}

void save()
{
	num rev;
	num iab;

	// Rev Limiter
	writeword(readword(0x3F5F)+2, 1875600 / getitem(hRev1));
	writeword(readword(0x3F5C)+2, 1875600 / getitem(hRev2));
	writeword(readword(0x3F68)+2, 1875600 / getitem(hRev1));
	writeword(readword(0x3F65)+2, 1875600 / getitem(hRev2));

	
	// VTEC
	rev = ((getitem(hVtec1) / 1562) * 25) + 128;
	writebyte(0x645D, rev);

	rev = ((getitem(hVtec2) / 1562) * 25) + 128;
	writebyte(0x645F, rev);

	rev = ((getitem(hVtec3) / 1562) * 25) + 128;
	writebyte(0x6464, rev);

	rev = ((getitem(hVtec4) / 1562) * 25) + 128;
	writebyte(0x6466, rev);

	
	// IAB
	iab = ((getitem(hIab1) / 1562) * 25) + 128;
	writebyte(0x43A2, iab);

	iab = ((getitem(hIab2) / 1562) * 25) + 128;
	writebyte(0x439D, iab);
}
