// Различные процедуры, которые выводят информацию о текущем состоянии
// сжатия.

?define	Step 8192

dword cStep;
byte rescmp=0;
dword sNum;
byte DBuff[20];

void fastcall ToDec(EAX,EDI)
{
	ECX = 10;
	EBX = 0;
	WHILE(EAX >= ECX){
		EAX=EAX/ECX;
		$push EDX
		EBX++;
	}
	$push EAX;
	EBX++;
	loop (EBX){
		$pop EAX
		AL += '0';
		$stosb
	}
	AL = '%';
	$stosb
	AL = 0;
	$stosb
}

void fastcall ToDecNum(EAX,EDI)
{
	ECX = 10;
	EBX = 0;
	WHILE (EAX >= ECX){
		EAX=EAX/ECX;
		$push EDX
		EBX++;
	}
	$push EAX;
	EBX++;
	AL  = '(';
	$stosb
	loop (EBX){
		$pop EAX
		AL += '0';
		$stosb
	}
	AL = ')';
	$stosb
	AL = 0;
	$stosb
}

void XcInit()
{
	cStep=xPos+Step;
}

void XcCheck()
{
	if (xPos > cStep){
		cStep+=Step;
		IF(!consolemode)SendMessageA(hBar1,PBM_STEPIT,0,0);
		EAX = xPos-xrSrc;
		IF (rescmp == 1) EAX = xPos-NewRR2+ResPhys;
		IF(!consolemode){
			$push EAX
			ToDecNum(EAX,#DBuff);
			SetWindowTextA(hText3,#DBuff);
			$pop  EAX
		}
		EAX = EAX*100/xrSze;
		ToDec(EAX,#DBuff);
		IF(consolemode){
			printf("%s%% \x08\x08",#DBuff);
			BackChar(strlen(#DBuff));
		}
		else{
			SetWindowTextA(hS1,#DBuff);
			EAX = xPos-xrSrc;
			IF (rescmp == 1) EAX = xPos-NewRR2+ResPhys;
			$push  EAX
			ECX = sNum;
			EAX >>= CL;
			EAX <<= 16;
			SendMessageA(hBar2,PBM_SETRANGE,0,EAX);
			EAX = xBst-xrDst;
			$push  EAX
			$push  EAX
			ToDecNum(EAX,#DBuff);
			SetWindowTextA(hText4,#DBuff);
			$pop   EAX
			ECX = sNum;
			EAX >>= CL;
			SendMessageA(hBar2,PBM_SETPOS,EAX,0);
			$pop   EBX
			$pop   ESI
			EAX = EBX*100/ESI;
			ToDec(EAX,#DBuff);
			SetWindowTextA(hS2,#DBuff);
		}
	}
}
