	.TITLE	TRACER
/
/  11 OCT 77 (007; PDH) TRY AGAIN FOR SIGNIFICANT EVENT NUDGING!
/   7 OCT 77 (006; PDH) STOP HIGH SPEED CLOCK IN INTERRUPT SERVICE
/   6 OCT 77 (005; PDH) TRY TO STIMULATE IT FROM SIGNIFICANT EVENT
/  12 AUG 77 (004; PDH) CHANGE TO 'JMS* .IOERR'; SAVE OFFSET TO STORED INFORMATION
/  21 JUN 77 - PAUL HENDERSON
/
/  PROGRAM TO TRY TO GET A TRACE OF THE RSX SYSTEM, AND STORE
/  IT IN THE UPPER 48K.  THIS REQUIRES THAT THE PROGRAMS EXECUTING MUST
/  BE RESIDENT IN THE LOWER 32K.
/
/  THE ITEMS ARE STORED IN BLOCKS OF 30 (OCTAL) WORDS IN THE FOLLOWING ORDER:
/
/	 PC  AC  MQ  XR  LR  RR  T   S
/	X10 X11 X12 X13 X14 X15 X16 X17
/	L20  R1  R2  R3  R4  R5  R6
/
/  WHERE 'RR' IS THE RELOCATION REGISTER, 'T', 'S' ARE TICKS, SECONDS
/
FCRS=702601
FCLG=702607
FCCF=702624
FCEI=702642
FCDI=702644
/
X10=10
X11=11
X12=12
X13=13
X14=14
X15=15
X16=16
X17=17
L20=20
R1=101
R2=102
R3=103
R4=104
R5=105
R6=106
SET=ISZ
INC=ISZ
DELAY=7			/ NUMBER OF CLOCK TICKS (8 USEC) TO DELAY
/
	.GLOBL	.IOERR
/
CYCLES	0; 0		/ COUNTER FOR NUMBER OF TIMES TRACE WRAPPED AROUND
OFFSET			/ OFFSET TO STORED INFORMATION (UPDATED EVERY INTERRUPT)
			/ POINTS TO LAST BLOCK OF INFORMATION STORED
	.EJECT
TRACER	LAC	(TRACER
	AND	(070000
	TCA
	DAC	XADJ
	TAD	(100000		/ BEGINNING OF BUFFER
	DAC	XR		/ INITIALIZE XR VALUE
	DAC	XRBGIN		/ SAVE FOR RESETTING ON WRAP-AROUND
	LAC	(237777
	TAD	XADJ
	DAC	LR		/ ESTABLISH LIMIT
	DAC	LRBGIN
/
WTLOOP	CAL	(5		/ WAIT FOR NEXT SIGNIFICANT EVENT
	LAS
	SNA
	JMP	GO		/ ALL AC SWITCHES MUST BE ZERO TO BEGIN
	SMA
	JMP	WTLOOP		/ POSITIVE, NON-ZERO AC LOOPS
	FCRS
	FCDI
	CAL	DISCON
	LAW	-6		/ AC0=1 TO EXIT
	JMS*	.IOERR
/
GO	CAL	CONECT
	CAL	WAITFR
	LAC	EV
	SPA
	JMS*	.IOERR		/ MUST CONNECT TO BE USEFUL
/
	DZM	EV
	LAW	-DELAY		/ NOW GET US UNDERWAY.
	FCLG
	FCEI
	CAL	WAITFR		/ WAIT UNTIL AC SW NON-ZERO
	CAL	DISCON		/ DISCONNECT FROM INTERRUPT LINE
	JMP	WTLOOP
/
	.EJECT
FCINT	XX
	FCRS
	FCCF
	DBA			/ MUST OPERATE IN PAGE MODE FOR INDEXING
	DAC	ACSAVE
	LAC	(FCLG		/ RESTART CLOCK, NORMALLY
	DAC	RSCLK
	LAS
	SNA
	JMP	NOSET
	FCDI			/ WANT NO MORE INTERRUPTS
	SET	EV		/ WAKE UP THE SYSTEM AGAIN
/
NOSET	LAC	XADJ		/ TO GENERATE THE CORRECT OFFSET,
	TCA			/ WE MUST SUBTRACT THE XR ADJUSTMENT
	TAD	XR		/ FROM THE ADJUSTED VALUE, GIVING
	DAC	OFFSET		/ THE ABSOLUTE OFFSET ADDRESS
	PXA
	DAC	XRSAVE
	PLA
	DAC	LRSAVE
	LAC	LR
	PAL			/ ESTABLISH INTERNAL XR, LR VALUES
	LAC	XR
	PAX
	LAC	FCINT
	DAC	0,X
	AND	(077777		/ KEEP ONLY 15 BITS OF ADDRESS
	SAD	(4057
	SKP
	JMP	TRGO		/ NOT IDLE LOOP.  KEEP ON TRACING
	SAD	LASTPC		/ TRACE ONLY 1 STEP OF
	JMP	FCINT2		/ EXECUTIVE 'IDLE' LOOP
TRGO	DAC	LASTPC
	LAC	ACSAVE
	DAC	1,X
	LACQ
	DAC	2,X
	LAC	XRSAVE
	DAC	3,X
	LAC	LRSAVE
	DAC	4,X
	LAC*	(4343		/ GET SYSTEM-SAVED VALUE OF RELOCATION REGISTER
	DAC	5,X
	LAC*	(162		/ GET TICKS
	DAC	6,X
	LAC*	(163		/ GET SECONDS
	DAC	7,X
/
	.EJECT
	LAC*	(X10
	DAC	10,X		/ MOVE AUTO-INDEX REGISTERS
	LAC*	(X11
	DAC	11,X
	LAC*	(X12
	DAC	12,X
	LAC*	(X13
	DAC	13,X
	LAC*	(X14
	DAC	14,X
	LAC*	(X15
	DAC	15,X
	LAC*	(X16
	DAC	16,X
	LAC*	(X17
	DAC	17,X
	LAC*	(L20
	DAC	20,X
	LAC*	(R1
	DAC	21,X
	LAC*	(R2
	DAC	22,X
	LAC*	(R3
	DAC	23,X
	LAC*	(R4
	DAC	24,X
	LAC*	(R5
	DAC	25,X
	LAC*	(R6
	DAC	26,X
/
	AXS	30		/ MOVE TO NEXT BLOCK
	JMP	FCINT2
	INC	CYCLES+1	/ WRAP-AROUND.  INCREMENT COUNTER
	SKP
	INC	CYCLES
LNOP	NOP
	LAC	XRBGIN		/ RESET INDEX REGISTER VALUE
	DAC	XR
	LAC	LNOP		/ DON'T START CLOCK AFTER END OF MEMORY
	DAC	RSCLK
	LAW	-DELAY		/ IT WILL BE RESTARTED BY THE NEXT SIG EVENT
	SAD*	(4
	HLT			/ NO SIGNIFICANT EVENT IS A BAD SCENE!!
	DAC*	(4
	JMP	FCINT3
/
	.EJECT
FCINT2	PXA
	DAC	XR		/ SAVE XR VALUE FOR NEXT TIME
FCINT3	LAC	XRSAVE
	PAX
	LAC	LRSAVE
	PAL
	LAW	-DELAY
RSCLK	FCLG
	LAC	ACSAVE
	DBR
	JMP*	FCINT
/
/  VARIABLES AND CPB'S
/
XADJ;XRBGIN;LRBGIN;XR;LR;ACSAVE;XRSAVE;LRSAVE;EV;LASTPC
CONECT	11;	EV; 37; FCINT
DISCON	12;	0;  37; FCINT
WAITFR	20;	EV
	.END	TRACER
