; Main microcode for file searcher
; last edited July 31, 1980  5:52 PM
; Copyright Xerox Corporation 1979, 1980

#ALTOCONSTS23.MU;

; Constants and R registers
$4000	$4000;	(has other names in CONSTANTS)

$AC0	$R3;
$AC1	$R2;
$AC3	$R0;

$newL	$R40;	the M register

$addr	$R3;	(=AC0) memory address
$char	$R14;	Save odd character
$phase	$R15;	phase number, even/odd swap flag in bit 4 (for skip char.s)
$-K+1	$R16;	number of char.s for match

!7,10,Reset,Match,FetchEven,feSwap,FetchOdd,foSwap,Skip,Record;	entries to microcode
!13,4,ci0,ci1,ci2,ci3;	RWREG work area
!20,1,START;	return to Nova emulator
!37,1,trap;	trapped instructions
!1600,1,adisp;	character dispatch

; Returns to Nova emulator
START:	SWMODE;
	  :START;
trap:	SWMODE;
	  :trap;

; Main loop entries.  Different for even/odd character
!7,1,fex;
FetchEven:
	MAR ← L ← addr+1;
fe1:	addr ← L;
	L ← phase+1, IR ← phase;
	phase ← L;
fex:	L ← MD;	Override IR← dispatch
	char ← L LCY 8;
	SINK ← char, BUS, TASK;	dispatch on left char
	char ← L, :adisp;
foSwap:	MAR ← L ← addr+1, :fe1;	FetchOdd with even/odd swapped
!7,1,fox;
FetchOdd:
	L ← phase+1, IR ← phase;
fo1:	SINK ← char, BUS, TASK;	dispatch on right char
fox:	phase ← L, :adisp;	Override IR← dispatch
feSwap:	L ← phase+1, IR ← phase, :fo1;	FetchEven with even/odd swapped

; Register a match.  L=ctr # which was zero
Match:
	AC1 ← L;
	L ← phase, TASK;
	AC3 ← L, :START;

; Record boundary -- not implemented yet
;Record:

; Skip character
!1,2,ske,sko;
Skip:
	T ← phase-1, BUSODD;	Undo phase increment
	L ← 4000 XOR T, IDISP, :ske;	Invert swap bit
ske:	phase ← L, :FetchOdd;	even phase & now swapped, or opposite
sko:	phase ← L, :FetchEven;	odd phase & now swapped, or opposite