[Dashboard\Nissan\Prima Star\Prima Star 93C66]

Size(280,250); 

Form
{
	Group("Пробег",5,5,140,50)
	{
		Digit(Distance," ",5,18,90);
		Label(lb1,"KM",110,20);
	}
	Group("Информация",5,58,270,45)
	{
		Label(message," ",0,18);
	}
	Group("Описание",5,105,270,100) 
	{
		Label(lb4,"Калькулятор для Nissan Prima Star.",0,20);
		Label(lb5,"EEPROM 93C66",0,35);
		Label(lb2,"Введите нужное значение в окне ПРОБЕГ",0,55);
		Label(lb3,"и нажмите кнопку <Применить>.",0,70);
	}
	Picture(Picture1,"Nissan.bmp",170,0,0,0);
}

Var Address, StartAddr, EndAddr, MaxDist, CRC, CRCDump, Error;

OnShow 
{
	Error = 0;
	MaxDist = 0;
	Address = 0x7C;
	StartAddr = Address;
	EndAddr = StartAddr + 0x10;
    Message.Bold = 1;
    while(StartAddr < EndAddr)
	{
		CRCDump = @(StartAddr + 3) + @StartAddr + @(StartAddr + 1);
		CRCDump = CRCDump & 0xFF;
		CRC = (@(StartAddr + 2)) ^ 0xFF;
		if(CRCDump != CRC) {Error = 1; StartAddr = EndAddr;}
		Var1 = (@(StartAddr + 3) << 16) | (@StartAddr << 8) | @(StartAddr + 1);
		if(MaxDist < Var1) {MaxDist = Var1;}
		StartAddr = StartAddr + 4;
	}
	
	if(Error != 0)
	{
		message.Color = 0x0000FF; 	
		Message = "Неверный дамп!";     
		Distance = 0;                   
	}
	else
	{
		message.Color = 0xFF0000;                    
		message = "Дамп ОК. Введите новый пробег.";  
		Distance =  MaxDist;  
	}                          
}

OnApply
{
	Var0 = Distance; 
	Error = 0;

	if(Var0 < 100)	{ Error = 1; }
	if(Var0 > 999900)   { Error = 1; }

	if(Error != 0)
	{
		message.Color = 0x0000FF; 
		Message = "Пробег должен быть от 100 до 999900 км.";
	}
	else
	{
		Address = 0x7C;
		StartAddr = Address;
		EndAddr = StartAddr + 0x10;
		Var1 = (Var0 >> 16) & 0xFF;
		Var2 = (Var0 >> 8) & 0xFF;
		Var3 = Var0 & 0xFF;
		CRC = (Var1 + Var2 + Var3) & 0xFF;
		CRC = CRC ^ 0xFF;
		while(StartAddr < EndAddr)
		{
			@StartAddr = Var2; StartAddr = StartAddr + 1;
			@StartAddr = Var3; StartAddr = StartAddr + 1;
			@StartAddr = CRC; StartAddr = StartAddr + 1;
			@StartAddr = Var1; StartAddr = StartAddr + 1;
		}
		message.Color = 0xFF0000;  
		message = "Новый пробег записан. Дамп ОК.";
	}
}





















