[Dashboard\Audi\A8\A8 VDO 24C17 V1]

Size(280,300);

Form {
    Group("Пробег",5,5,140,50)
    {
        Digit(Distance," ",5,18,90);
        Label(lb1,"KM",110,20);
    }
    Group("Идентификация",5,60,270,65)
    {
        Label(Part," ",0,25);
        Label(Login," ",0,40);
    }
    Group("Информация",5,130,270,45)
    {
        Label(msg," ",0,18);
    }
    Group("Описание",5,165,270,85) 
    {
        Label(lb4,"Калькулятор пробега для Audi A8 VDO.",0,20);
        Label(lb5,"EEPROM 24C17",0,35);
        Label(lb2,"Введите нужное значение в окне <Пробег>.",0,50);
        Label(lb3,"и нажмите кнопку <Применить>.",0,65);
    }
    Picture(Logo,"Audi.bmp",170,20,0,0);
}

OnShow 
{
	Var0 = 0;
	Var2 = @0x2A; Var3 = @0x2B;
	
	if(Var2 != 0xFF) { Var0 = 1;}
    if(Var3 != 0xFF) { Var0 = 1;}
	
 	if(Var0 = 0)
	{
		msg.Color = 0x0000FF;
		msg.Bold = 1;
		msg = "Неверный дамп!";
		Distance = 0;
	}
	else
	{
		Part.Bold =1;
		Part = "VAG P/N: 4D0 919 "+#c.@0x2A+#c.@0x2B+#c.@0x2C+" "+#c.@0x2D+#c.@0x2E+"  "+#c.@0x32+#c.@0x33+#c.@0x34;
		Var2 = ((@0x2B0 | (@0x2B1 << 8)) ^ 0xFFFF) << 4;
        msg.Color = 0xFF0000;
        msg.Bold = 1;
        msg = "Дамп ОК. Введите новый пробег.";
        Distance = Var2 - 1000;
		Var0 = @0x7BC | (@0x7BD << 8);
		Var4 = (Var0 % 10) + 0x30; Var0 = Var0 / 10;
		Var5 = (Var0 % 10) + 0x30; Var0 = Var0 / 10;
		Var6 = (Var0 % 10) + 0x30; Var0 = Var0 / 10;
		Var7 = (Var0 % 10) + 0x30; Var0 = Var0 / 10;
		Var8 = (Var0 % 10) + 0x30;
		Login = "LOGIN: "+#c.Var8+#c.Var7+#c.Var6+#c.Var5+#c.Var4;
	}
}

OnApply 
{
    Var5 = 0;
    Var0 = Distance; 
	Var0 = Var0 + 1000; Var0 = Var0 >> 4 & 65535 ^ 0xFFFF; 

    if(Var0 > 999990) {Var5 = 1;}
    if(Var0 < 1000)   {Var5 = 1;}
    if(Var5 != 0)
    {
        msg.Color = 0x0000FF;
        msg.Bold = 1;
        msg = "Пробег должен быть от 1000 до 999900 км";
    }
    else
    {
		Var3 = 0;
		Var5 = 0x2B0;

		while(Var3 < 8) {

	        Var1 = Var0 & 0xFF; 
			Var2 = (Var0 >> 8) & 0xFF; 

			@Var5 = Var1;  @Var5.Mismatch = 1; Var5 = Var5 + 1;
			@Var5 = Var2;  @Var5.Mismatch = 1; Var5 = Var5 + 1;

			Var0 = Var0 * 2;
			if(Var0 > 0xFFFF) {Var0 = (Var0 & 0xFFFF) + 1;}
			Var3 = Var3 + 1;
        } 
	}

	msg.Color = 0xFF0000;
    msg.Bold = 1;
    msg = "Новый пробег записан.";
}
