; TFU microcode: Standard disk microcode + compare routines
; Copyright Xerox Corporation 1979

;	Last modified November 10, 1979  10:29 AM

%0, 1777, 23, LOC23;
%0, 1777, 24, LOC24;
%0, 1777, 37, TRAP1;

#TriConMc.Mu;

; Standard R-registers usable by the emulator task

$AC3		$R0;	Accumulators
$AC2		$R1;
$AC1		$R2;
$AC0		$R3;
$NWW		$R4;	New wakeups waiting (communication between tasks)
$SAD		$R5;	Temporary private to emulator
$PC		$R6;	Program Counter for emulated Nova
$XREG		$R7;	Temporary private to emulator.
;			Contains instruction LCY 8 upon dispatch to TRAP1.
$XH		$R10;	Temporary private to emulator
$MTEMP		$R25;	Temporary usable by any task
$DWAX		$R35;	Temporary private to emulator
$MASK		$R36;	Temporary private to emulator

$LREG		$R40;	Another name for the M-register

#RamTrap.Mu;
#GetFrame.Mu;
#BcplUtil.Mu;


; JMPRAM(24)
;	AC0!0 = first address of buffer 1
;	AC0!1 = first address of buffer 2
;	AC0!2 = number of words to compare
;	Returns AC0= number of non-equal words

!1,2,CONTCOMP, EXITCOMP;
!1,2,NOTEQUAL, COMPLOOP;

LOC24:	MAR←T←AC0;  		GET FIRST BUFFER ADDR
	NOP;
	L←MD-1;
	SAD←L, MAR←T←0+T+1;	GET SECOND BUFFER ADDR
	NOP;
	L←MD-1;
	XREG←L, MAR←0+T+1;	GET COUNT
	L←0;
	AC0←L;			INITIALIZE ERROR TO 0
	L←MD, TASK;
	AC3←L;

COMPLOOP: MAR←L←SAD+1;  	GET FIRST BUFFER WORD
	SAD←L;
	L←AC3-1, BUS=0;
	AC3←L, :CONTCOMP;	[CONTCOMP, EXITCOMP]
CONTCOMP: T←MD;
	MAR←L←XREG+1;  		GET SECOND BUFFER WORD
	XREG←L;
	L←MD XOR T;
	SH=0, TASK;		TEST FOR WORDS EQUAL
	:NOTEQUAL;		[NOTEQUAL, COMPLOOP]

NOTEQUAL: L←AC0+1, TASK;	COUNT ERROR
	AC0←L, :COMPLOOP;

EXITCOMP: :EXITRAM;

; JMPRAM(23)
;  AC0!0=address
;  AC0!1=value
;  AC0!2=count
;  Returns AC0=0 if all ok; otherwise AC0 = bad address

LOC23:	MAR←T←AC0;  		GET BUFFER ADDR
	NOP;
	L←MD-1;
	AC0←L, MAR←T←0+T+1;	GET VALUE
	NOP;
	L←MD;
	SAD←L, MAR←0+T+1;	GET COUNT
	NOP;
	L←MD, TASK;
	AC1←L;

!1,2,CMCONT, CMDONE;
!1,2,CMBAD, CMLP;

CMLP:	MAR←L←AC0+1;
	AC0←L;
	SINK←AC1, BUS=0;
	T←SAD, :CMCONT;		[CMCONT, CMDONE]
CMCONT:	L←MD-T;
	L←AC1-1, SH=0, TASK;
	AC1←L, :CMBAD;		[CMBAD, CMLP]

CMDONE:	L←0, TASK;
	AC0←L, :EXITRAM;
CMBAD:	:EXITRAM;