	.TITLE	TSKTM2
/
/   1 NOV 78 (016; PDH)	CHANGE TO 'YMMDD' DESIGNATION FOR FILE NAMES,
/			WHERE 'Y' IS ALPHABETIC, DERIVED FROM
/			'@' FOR 1970, 'A' FOR 1971, ETC; REDUCE 'ENTRYS'
/			SO TASK WILL FIT PARTITION.
/  20 SEP 78 (015; PDH)	CHANGE OF PHILOSOPHY.  SINCE EDIT #16 IS A
/			RETRO-FIT, EDIT #15 IS NOT PRESENT IN THIS FILE.
/  15 MAR 78 (014; PDH) WHEN TASK TIMING EVENT VARIABLE IS NEGATIVE,
/			DUMP BOTH BUFFERS AND CONTINUE, DON'T ABORT.
/  11 FEB 78 (013; PDH)	CHANGE I/O COUNT TO I*4 (INCREASES BUFFER
/			SIZE TO 26); DUMP ADDITIONAL TASK '..DOS.'
/			WHEN 'EXITFL' SET; DUMP BOTH BUFFERS IF
/			TIMING EV=3 (USED FOR CHECKPOINTING)
/  31 JAN 78 (012; PDH) DON'T LIST UNDEFINED VARIABLES; IMPROVE
/			ADDRESS REPORTING FOR '.IOERR'.
/  31 JAN 78 (011; PDH) SET ESIZE=6 FOR MULTIACCESS
/  23 JAN 78 (010) SET 'BUFPT' CORRECTLY WHEN 'EXITFL' SET
/  18 JAN 78 (009; PDH) NEED TO SAVE XR IN 'DUMP' FOR I/O
/  17 JAN 78 (008; PDH) ALLOW FOR 'DOS' AND 'SAVE' TO PREMATURELY
/			HAVE THE BUFFERS DUMPED, AND THIS TASK TO EXIT.
/  16 JAN 78 (007; PDH) INCREASE 'ENTRYS' TO 64 (DECIMAL)
/  12 JAN 78 (006; PDH) DON'T INCLUDE 'POLLER', 'NODCNT', 'AUTORM'
/  12 JAN 78 (005; PDH) USE CORRECT ADDRESS FOR 'XRADJ' CALCULATION;
/			REMOVE SNAPS
/  11 JAN 78 (004; PDH) ADD SOME SNAPS FOR DEBUGGING
/  11 JAN 78 (003; PDH) USE NEW ADDRESS FOR BUFFER DUMPING
/   9 JAN 78 (002; PDH) SET ESIZE=4 TO DEBUG WITH XVM/RSX V1A
/   5 JAN 78 - PAUL HENDERSON (DERIVED, IN PART, FROM 'SAVE 007'
/				OF THE 'ARK...' TASK)
/
/     THIS IS SECTION 2 OF THE 2-SECTION TASK TO PERFORM TASK
/  TIMING AND ACCOUNTING.  ITS FUNCTION IS TO RECORD, ON DISK,
/  THE INFORMATION STORED IN THE TASK TIMING BUFFERS BY THE
/  'EXIT' PROCESSOR OF THE EXECUTIVE.  THE 'EXIT' PROCESSOR HAS
/  BEEN MODIFIED TO INCLUDE I/O COUNT AND USER'S UIC INFORMATION,
/  AS WELL AS THE USUAL TASK NAME AND CPU TIME INFORMATION.
/     THE INFORMATION STORED IN THE TASK TIMING BLOCK IS AS FOLLOWS:
/
/	WORD 0	TASK NAME, FIRST HALF
/	     1	TASK NAME, SECOND HALF
/	WORD 2	DOUBLE INTEGER, NUMBER OF 10 USEC XM CLOCK
/	     3	TICKS OF CPU TIME FOR TASK
/	WORD 4	I/O COUNT
/	WORD 5	UIC
/
/     IT HAS BEEN ESTIMATED THAT WITH A BUFFER SIZE LARGE ENOUGH
/  TO CONTAIN 16 (DECIMAL) ENTRIES, THERE WILL BE SUFFICIENT
/  SYSTEM ACTIVITY WITH 'POLLER' (EVERY MINUTE), 'NODCNT' (EVERY
/  2 MINUTES) AND 'AUTORM' (EVERY 5 MINUTES) TO DUMP THE TIMING
/  BUFFERS ABOUT EVERY 10 MINUTES.  OBVIOUSLY WITH USER ACTIVITY,
/  THE DUMPING WILL OCCUR MORE OFTEN.
/
	.EJECT
/     THE DUMPING WILL BE DONE IN OTS BINARY, WHICH GREATLY
/  SIMPLIFIES THE FORMATTING REQUIRED BY THIS TASK.  EACH LOGICAL
/  RECORD WILL CONTAIN THE ACCOUNTING INFORMATION FOR A SINGLE
/  TASK AS FOLLOWS:
/
/ WORD	 0	13000	HEADER WORD 0
/	 1	0	HEADER WORD 1 (CHECKSUM)
/	 2	400000	OTS BINARY FLAG WORD
/ WORD	 3	24	'DATE' CPB INVOKED AT BEGINNING OF BUFFER DUMP
/	 4	0	NO EVENT VARIABLE ADDRESS
/	 5		MONTH
/	 6		DAY
/	 7		YEAR
/	10		HOUR
/	11		MINUTE
/	12		SECOND
/ WORD	13		FIRST HALF OF TASK NAME (A3)
/	14
/	15		SECOND HALF OF TASK NAME (A3)
/	16
/ WORD	17		XM CLOCK OVERFLOWS
/	20		XM CLOCK TICKS ABOVE OVERFLOW
/ WORD	21		I/O COUNT (I*4)
/	22
/ WORD	23		UIC (A3)
/	24
/	25		UNUSED WORD
/
/
/  EVERY TIME THE BUFFERS ARE DUMPED, A FILE WITH A NAME OF THE
/  FORM 'DDMMYY ACT' IS OPENED.  IF THE FILE EXISTS, ITS CURRENT
/  CONTENTS ARE COPIED FROM THE INPUT LUN TO A TEMPORARY FILE ON
/  THE OUTPUT LUN, THEN THE ABOVE INFORMATION IS APPENDED.  FINALLY,
/  THE ORIGINAL FILE IS DELETED, AND THE TEMPORARY FILE IS
/  GIVEN THE ORIGINAL FILE NAME.  IT FOLLOWS, OF COURSE, THAT THE
/  INPUT AND OUTPUT LUN'S MUST POINT TO THE SAME DISK AND UFD,
/  PREFERABLY 'SY <ACT>'.
/
	.EJECT
	.DEC
ENTRYS=60		/ NUMBER OF TASK EXIT ENTRIES PER BUFFER /(016)
ESIZE=6			/ NUMBER OF WORDS PER ENTRY (ENTRY SIZE)
/ESIZE=4			/ PROPER SIZE FOR XVM/RSX V1A	/(002)
BUFSIZ=ESIZE*ENTRYS
DKI=57
DKO=58
	.OCT
I=400000
IDX=ISZ
ECLA=641000
IRS=711000
IMP=711400
IDV=712000
ILD=713000
IST=713600
UNSWQ=715270
/
	.GLOBL	.IOERR
/
	.EJECT
/  THE FIVE ADDRESSES IN THE CONTROL TABLE ARE RELOCATED BY
/  'TSKTM1' TO POINT TO REAL ADDRESS, NOT VIRTUAL ADDRESSES.
/
CTLTB	0			/ TASK TIMING EVENT VARIABLE
	START1			/ START OF BUFFER 1
	END1
	START2			/ START OF BUFFER 2
	END2
	START1			/ BUFFER POINTER USED BY 'EXIT'
EXITFL	0	/ LOCATION SET NON-ZERO WHEN THIS TASK IS TO	/(008)
		/ PERFORM A FINAL BUFFER DUMP, THEN EXIT.	/(008)
		/ THIS LOCATION SHOULD NOT BE SET UNLESS TASK	/(008)
		/ TIMING HAS BEEN DISABLED.			/(008)
/
TSKTM2	LAC	(START1						/(005)
	AND	(070000		/ CALCULATE XR ADJUSTMENT FACTOR
	TCA
	DAC	XRADJ
/
TMWAIT	CAL	TMWTFR		/ WAIT FOR BUFFER TO FILL
	CAL	DATE		/ GET DATE AND TIME FROM SYSTEM
	LAC	EXITFL		/ CHECK 'DUMP & EXIT' FLAG	/(008)
	SNA
	JMP	NORMAL		/ CONTINUE NORMAL OPERATION.	/(008)
/
	LAW	-ENTRYS*2-1	/ DUMP BOTH BUFFERS AND		/(013)
	DAC	COUNT		/ THE 'LOGOUT' ENTRY '..DOS.'	/(013)
	CAL	ENTER		/ IN THIS SEQUENCE, WE WILL	/(008)
	JMS	WTFOR		/ WRITE OUT ONLY THE CURRENT	/(008)
	LAC	(START1		/ DATA, BEGINNING WITH BUFFER 1	/(010)
	JMP	DUMP2		/ THE FILE WILL NOT BE UPDATED	/(010)
/
	.EJECT
DBOTH	LAC	(START1-ESIZE	/ BEGINNING WITH BUFFER 1,	/(013)
	DAC	BUFPT		/ PREPARE TO DUMP BOTH BUFFERS	/(013)
	LAW	-ENTRYS*2					/(013)
	JMP	SETCNT						/(013)
/
NORMAL	LAC	CTLTB						/(008)
	DZM	CTLTB		/ ZEROING EV HERE MINIMIZES CHANCE
				/ OF LOSING ACCOUNTING DATA.
	SAD	(3		/ WE HAVE BEEN CHECKPOINTED.	/(013)
	JMP	DBOTH		/ MUST DUMP BOTH BUFFERS	/(013)
	SPA!CLL!RAR		/ VALIDATE TIMING EVENT VARIABLE
	JMP	DBOTH		/ BAD SCENE!  DUMP BOTH BUFFERS	/(014)
				/ AND CARRY ON AS BEST WE CAN	/(014)
	LAC	(START1		/ ASSUME WE DUMP BUFFER 1	/(003)
	SNL
	LAC	(START2		/ EV WAS EVEN - DUMP BUFFER 2	/(003)
	AAC	-ESIZE		/ POINTER INDEXED AT START OF LOOP
	DAC	BUFPT
	LAW	-ENTRYS
SETCNT	DAC	COUNT		/ INITIALIZE COUNTER
/
	.EJECT
	.DEC							/(016)
	LAC	DATE+4		/ GET YEAR
	AAC	-70		/ AUTOMATICALLY CONVERTED TO	/(016)
	.OCT			/ THE CORRECT .SIXBT VALUE	/(016)
	CLQ!LRSS 6		/ TEMPORARILY STORE IN MQ	/(016)
/
	LAC	DATE+2		/ GET MONTH
	PAX
	LAC	MONTHS-1,X	/ GET 2-CHARACTER MONTH DESIGNATOR
	OMQ			/ INCLUDE YEAR DESIGNATION	/(016)
	DAC	S.NM1		/ PUT IN 'SEEK' CPB
	DAC	C.NM1		/ AS WELL AS THE 'CLOSE'
	DAC	D.NM1		/ AND 'DELETE' CPB'S
/
	LAC	DATE+3		/ GET DAY OF MONTH		/(016)
	JMS	OCTDEC		/ CONVERT TO .SIXBT DECIMAL	/(016)
	LLSS	11		/ SHIFT TO CORRECT PLACE	/(016)
	DAC	S.NM2		/ FILE NAMES NOW COMPLETELY READY
	DAC	C.NM2
	DAC	D.NM2
/
	CAL	ENTER		/ OPEN FILE 'TEMPRY ACT'
	JMS	WTFOR
	CAL	SEEK		/ SEE IF WE HAVE DONE SOME ACCOUNTING
	JMS	WTFOR		/ YET TO-DAY.
	SAD	(-13
	JMP	DUMP		/ NO.  NOTHING TO UPDATE
/
MOVE	CAL	READL		/ READ A RECORD FROM INPUT FILE
	JMS	WTFOR
	LAC	LINE
	AND	(7
	SAD	(5
	JMP	EOF		/ END OF INPUT FILE
	CAL	WRITEL		/ COPY RECORD TO OUTPUT FILE
	JMS	WTFOR
	JMP	MOVE
/
EOF	CAL	CLOSEI		/ CLOSE INPUT FILE
	JMS	WTFOR
/
	.EJECT
/  THIS SECTION APPENDS THE NEW ACCOUNTING INFORMATION TO THE
/  DATA ALREADY STORED PREVIOUSLY.  IF THE TASK NAME IS 'POLLER',
/  'NODCNT', 'AUTORM' OR IS AN MCR FUNCTION, DO NOT INCLUDE IT.
/
DUMP	LAC	BUFPT
	AAC	ESIZE
DUMP2	DAC	BUFPT		/ INDEX BUFFER POINTER
	TAD	XRADJ
	DAC	XRSAVE		/ SAVE XR FOR RESTORATION AFTER	/(009)
	PAX			/ I/O OPERATION
	LAC	0,X		/ GET FIRST HALF OF TASK NAME
	SNA							/(008)
	JMP	NOLIST		/ DON'T INCLUDE BLANK ENTRY	/(008)
	SAD	(400000		/ OTHER VERSION OF BLANK ENTRY	/(012)
	JMP	NOLIST						/(012)
	SAD	DOTS						/(006)
	JMP	NOLIST		/ DON'T INCLUDE MCR FUNCTION	/(006)
	SAD	POLLER						/(006)
	JMP	POLL2		/ OR 'POLLER'			/(006)
	SAD	NODCNT						/(006)
	JMP	NODE2		/ OR 'NODCNT'			/(006)
	SAD	AUTORM						/(006)
	JMP	AUTO2		/ OR 'AUTORM'			/(006)
LIST	JMS	ASCII		/ CONVERT TO A3 FORMAT AND	/(006)
	TSKNM1			/ STORE IT IN OUTPUT BUFFER
	LAC	1,X		/ SECOND HALF OF TASK NAME
	JMS	ASCII
	TSKNM2
	LAC	2,X		/ XM CLOCK OVERFLOWS
	DAC	MOSTXM
	LAC	3,X		/ XM CLOCK TICKS
	DAC	LEASTXM
	LAC	4,X		/ I/O COUNT
	DAC	IOCNT+1						/(013)
	LAC	5,X		/ UIC OF TASK
	JMS	ASCII
	UIC
	CAL	WRITE		/ WRITE DATA TO DISK
	JMS	WTFOR
NOLIST	LAC	XRSAVE		/ RESTORE XR			/(009)
	PAX							/(009)
	DZM	0,X		/ INDICATE ENTRY HAS BEEN USED	/(008)
	ISZ	COUNT
	JMP	DUMP		/ DO NEXT BUFFER ENTRY
/
	.EJECT
	CAL	CLOSE		/ CLOSE TEMPORARY OUTPUT FILE
	JMS	WTFOR
	LAC	EXITFL		/ IF 'EXITFL' IS SET, THEN	/(008)
	DZM	EXITFL		/ TASK TIMING IS BEING		/(008)
	SZA			/ TERMINATED AT THIS TIME, AND	/(008)
	CAL	(10		/ THE TASK IS TO EXIT.		/(008)
	CAL	DELETE		/ DELETE ORIGINAL INPUT FILE
	JMS	WTFOR
	CAL	RENAME		/ RENAME TEMPORARY FILE TO ORIG NAME
	JMS	WTFOR
	CAL	CLOSE		/ RENAMING OCCURS ON THE 'CLOSE'
	JMS	WTFOR
	JMP	TMWAIT		/ WE ARE DONE.  WAIT FOR BUFFERS TO FILL AGAIN.
/
POLL2	LAC	1,X		/ CHECK 2ND HALF FOR 'LER'	/(006)
	SAD	POLLER+1					/(006)
	JMP	NOLIST						/(006)
LST	LAC	0,X		/ TASK NAME IS VALID.  RETRIEVE	/(006)
	JMP	LIST		/ 1ST HALF OF NAME & PROCESS IT	/(006)
/
NODE2	LAC	1,X		/ CHECK 2ND HALF FOR 'CNT'	/(006)
	SAD	NODCNT+1					/(006)
	JMP	NOLIST						/(006)
	JMP	LST						/(006)
/
AUTO2	LAC	1,X		/ CHECK FOR 'ORM'		/(006)
	SAD	AUTORM+1					/(006)
	JMP	NOLIST						/(006)
	JMP	LST						/(006)
/
DOTS	.SIXBT	'...'		/ 1ST HALF OF MCR FUNCTION	/(006)
POLLER	.SIXBT	'POLLER'					/(006)
NODCNT	.SIXBT	'NODCNT'					/(006)
AUTORM	.SIXBT	'AUTORM'					/(006)
	.EJECT
/  SUBROUTINE TO CONVERT AN OCTAL (BINARY) NUMBER TO DECIMAL, SELECT THE
/  TWO LEAST SIGNIFICANT DIGITS, AND PLACE THEM IN THE AC & MQ
/  SO THAT SHIFTING LEFT BY 3 PLACES THEM IN THE AC (.SIXBT CODE).
/
/  CALLING SEQUENCE:
/
/	LAC	BINVAL
/	JMS	OCTDEC
/	(RETURN)		/ .SIXBT VALUES IN AC, MQ
/
OCTDEC	XX
	DAC	CHAR
	LAW	-4
	DAC	WTFOR		/ CONVERT 4 DIGITS
	LAC	(DIVISR
	DAC	FPADR1
	LAC	(ANS
	DAC	FPADR2
	ILD;	CHAR
CONVRT	IDV;FPADR1
	IST;FPADR2		/ QUOTIENT IS NEXT CONVERTED DIGIT
/***	UNSWQ;	0		/ REMAINDER IS NEXT DIVIDEND
	IMP;	I+FPADR1	/*** PROGRAM AROUND HARDWARE FAULT
	IRS;	CHAR		/***
	IST;	CHAR		/*** END OF FUDGE
	IDX	FPADR1		/ POINT TO NEXT DIVISOR
	IDX	FPADR2
	ISZ	WTFOR
	JMP	CONVRT
	LAC	ANS+3		/ GET LEAST SIGNIFICANT ANSWER DIGIT
	XOR	(60		/ CONVERT TO .SIXBT ASCII
	CLQ!LRSS 6		/ SHIFT INTO MQ
	LAC	ANS+2		/ GET OTHER DESIRED DIGIT
	XOR	(60		/ CONVERT IT TO .SIXBT ASCII
	LLSS	3
	JMP*	OCTDEC		/ LEAVE WITH ANSWER IN AC, MQ
/
	.DEC
DIVISR	1000;	100;	10;	1
ANS	.BLOCK	4;	.OCT
	.EJECT
/  SUBROUTINE TO CONVERT 3 .SIXBT CHARACTERS (1 WORD) TO 5/7
/  ASCII (A3 FORMAT), CONVERTING NULLS TO SPACES.
/
/  CALLING SEQUENCE:
/
/	LAC	.SIXBT
/	JMS	ASCII
/	RESULT		/ POINTER TO 2-WORD 5/7 ASCII BUFFER
/	(RETURN)
/
ASCII	XX
	LMQ			/ STORE .SIXBT IN MQ
	LAC*	ASCII		/ GET RESULT POINTER
	IDX	ASCII		/ INDEX PAST ARGUMENT
	DAC	CHARPT
	JMS	ONECHR		/ GET NEXT CHARACTER
	ALSS	13
	DAC*	CHARPT
	JMS	ONECHR		/ 2ND CHARACTER
	ALSS	4
	XOR*	CHARPT
	DAC*	CHARPT
	JMS	ONECHR		/ 3RD CHARACTER
	CLQ!LRSS 3
	XOR*	CHARPT
	DAC*	CHARPT
	IDX	CHARPT		/ POINT TO SECOND WORD OF ANSWER
	LACQ
	DAC*	CHARPT
	JMP*	ASCII
/
/  SUBROUTINE TO GET THE NEXT CHARACTER FROM MQ AND CONVERT TO
/  7-BIT.
/
ONECHR	XX
	ECLA!LLSS 6		/ SHIFT IN NEXT CHARACTER
	SNA
	AAC	40		/ CONVERT NULL TO SPACE
	DAC	CHAR		/ TEMPORARILY SAVE CHARACTER
	AND	(40
	SNA!CLA
	AAC	100		/ SET 7TH BIT, AS APPROPRIATE
	XOR	CHAR		/ MERGE WITH .SIXBT REPRESENTATION
	JMP*	ONECHR		/ LEAVE WITH 7-BIT ASCII IN AC
/
	.EJECT
WTFOR	XX
	LAC	EV
	SNA
	CAL	WAITFR		/ WAIT ONLY WHEN NECESSARY
	LAC	EV		/ VALIDATE EVENT VARIABLE
	SPA
	SAD	(-13		/ WE'LL LET THIS ONE PASS
	JMP*	WTFOR
	SAD	(-6		/ IGNORE UNIMPLEMENTED FUNCTION
	JMP*	WTFOR
	LAC	WTFOR		/ WE ARE ABOUT TO COMPLAIN	/(012)
	DAC*	.IOERR		/ BITTERLY AND INFORMATIVELY	/(012)
	LAC	.IOERR		/ PUT REAL TROUBLE ADDRESS	/(012)
	IAC			/ WHERE IT WILL BE REPORTED	/(012)
	DAC	WTFOR						/(012)
	LAC	EV		/ RETRIEVE EVENT VARIABLE	/(012)
	JMP*	WTFOR		/ COMPLAIN TERMINALLY		/(012)
/
	.EJECT
/  VARIABLES, CPB'S, AND BUFFERS
/
EV;XRADJ;XRSAVE;BUFPT;COUNT;CHAR;CHARPT
TMWTFR	20;	CTLTB
WAITFR	20;	EV
ENTER	3300;	EV;	DKO; .SIXBT 'TEMPRYACT'
SEEK	3200;	EV;	DKI;S.NM1;S.NM2; .SIXBT 'RAW'		/(016)
READL	2600;	EV;	DKI; 0; LINE; 26			/(013)
WRITEL	2700;	EV;	DKO; 0; LINE
WRITE	2700;	EV;	DKO; 0; UDATA
CLOSEI	3400;	EV;	DKI
CLOSE	3400;	EV;	DKO;C.NM1;C.NM2; .SIXBT 'RAW'		/(016)
DELETE	3500;	EV;	DKI;D.NM1;D.NM2; .SIXBT 'RAW'		/(016)
RENAME	3700;	EV;	DKO; .SIXBT 'TEMPRYACT'
START1	.BLOCK	BUFSIZ-1;END1
START2	.BLOCK	BUFSIZ-1;END2
LOGOUT	.SIXBT	'..DOS.' ; 0; 0; 0; 0				/(013)
LINE	.BLOCK	26						/(013)
/
UDATA	13000;	0;	400000		/ USER DATA RECORD	(013)
DATE	24;	0;	.BLOCK 6	/ WORDS 3-12
TSKNM1	0;	0			/ WORDS 13-14
TSKNM2	0;	0			/ WORDS 15-16
MOSTXM;LEASTXM				/ WORDS 17-20		/(013)
IOCNT	0; 0				/ WORDS 21-22		/(013)
UIC	0;	0			/ WORDS 23-24
	0				/ WORD 25 UNUSED	/(013)
/
MONTHS	.SIXBT	'@JA'
	.SIXBT	'@FE'
	.SIXBT	'@MR'
	.SIXBT	'@AP'
	.SIXBT	'@MY'
	.SIXBT	'@JN'
	.SIXBT	'@JL'
	.SIXBT	'@AU'
	.SIXBT	'@SE'
	.SIXBT	'@OC'
	.SIXBT	'@NV'
	.SIXBT	'@DC'
/
	.END	TSKTM2
