[INHERIT ('SYS$LIBRARY:STARLET.PEN')]
MODULE Xor_Command;

{ Routines for performing the XOR command }

(****************** Declare External Variables and Constants ******************)

%INCLUDE 'HEX$DIRECTORY:HEXGLOB.INC/NOLIST'

(********************* External RTL Routine Declarations **********************)

%INCLUDE 'HEX$DIRECTORY:LIB.INC/NOLIST'

(****************** External Homemade Routine Declarations ********************)

[EXTERNAL] PROCEDURE Check_Extra_Chars; EXTERN;

(******************************************************************************)
(*									      *)
(*	 		    Function Byte_Xor				      *)
(*									      *)
(******************************************************************************)

FUNCTION Byte_Xor(Byte_1: Unsigned_Byte; Byte_2: Unsigned_Byte): Unsigned_Byte;

{ This function returns a byte containing the logical XOR of the two bytes
  passed as parameters. }

VAR
	I		: Unsigned_Byte;
	X		: Unsigned_Byte;
	Y		: Unsigned_Byte;
	Temp		: Unsigned_Byte;

BEGIN

  Temp := 0;
  FOR I := 0 TO 7 DO
    BEGIN
      X := Byte_1 MOD 2;
      Y := Byte_2 MOD 2;
      Byte_1 := Byte_1 DIV 2;
      Byte_2 := Byte_2 DIV 2;
      Temp := Temp + (2**I * ((X+Y) MOD 2));
    END;

  Byte_Xor := Temp;

END;


(******************************************************************************)
(*									      *)
(*			    Procedure Do_Xor				      *)
(*									      *)
(******************************************************************************)

[GLOBAL] FUNCTION Do_Xor: INTEGER;

{ This function XOR's the designated range of virtual memory with the
  specified value. }

VAR
	I		: UNSIGNED;
	VM_Index	: INTEGER;
	Temp		: INTEGER;

BEGIN

  I := From;
  WHILE (I <= Thru) DO
    BEGIN
      VM_Index := (I - Offset)::INTEGER;
      VM[VM_Index] := Byte_Xor(VM[VM_Index],With_Param);
      I := I + Step_Param;
    END;
  Check_Extra_Chars;
  Do_Xor := SS$_NORMAL;

END;

(******************************************************************************)

END. { module Xor }
