unit compareu;{records comparisons unit}
{$I define.pas}
{$I nodebug.pas}
{ulantype}
interface
{v0.44}
function CompareRec(const Rec1; const Rec2; Size: Word): integer;
{/v0.44
function CompareRec(var Rec1; var Rec2; Size:Word):integer;}

function HasAllBytesEqualTo(var Rec; Count:word; AByte:byte):boolean;

implementation
type
  TBuffer = array[0..65520] of byte;

{v0.44}
function CompareRec(const Rec1; const Rec2; Size:Word):integer;
{/v0.44
function CompareRec(var Rec1; var Rec2; Size:Word):integer;}
var
  R1:TBuffer absolute Rec1;{byte buffer numbered from 0}
  R2:TBuffer absolute Rec2;
  i:integer;
  cmp:integer;
begin
  cmp := 0;
  for i := pred(Size) downto 0 do begin
    if R1[i] < R2[i] then begin
      cmp := -1;
      break;
    end else if R1[i] > R2[i] then begin
      cmp := 1;
      break;
    end;
  end;
  CompareRec := cmp;
end;

function HasAllBytesEqualTo(var Rec; Count:word; AByte:byte):boolean;
var
  R:TBuffer absolute Rec;{byte buffer numbered from 0}
begin
  HasAllBytesEqualTo := false;
  while Count > 0 do begin
    if R[Count - 1] <> AByte then
      exit;
    dec(Count);
  end;
  HasAllBytesEqualTo := true;
end;


{
function CompareRec(var Rec1; var Rec2; Size: Word): integer; assembler;
from editors unit, fix it:
asm
	PUSH	DS
	LES	DI,Rec1
	LDS	SI,Rec2
	MOV	CX,Size
	JCXZ	@@3
	CLD
	LODSB
	CMP	AL,1
	JB	@@5
	JA	@@1
	LODSB
	REPNE	SCASB
	JNE	@@3
	JMP	@@5
@@1:	XOR	AH,AH
	MOV	BX,AX
        DEC     BX
	MOV	DX,CX
	SUB	DX,AX
	JB	@@3
	LODSB
	INC	DX
	INC	DX
@@2:	DEC	DX
	MOV	CX,DX
	REPNE	SCASB
	JNE	@@3
	MOV	DX,CX
	MOV	CX,BX
	REP	CMPSB
	JE	@@4
	SUB	CX,BX
	ADD	SI,CX
	ADD	DI,CX
	INC	DI
	OR	DX,DX
	JNE	@@2
@@3:	XOR	AX,AX
	JMP	@@6
@@4:	SUB	DI,BX
@@5:	MOV	AX,DI
	SUB	AX,WORD PTR Block
@@6:	DEC	AX
	POP	DS
end;
}
end.


