	.TITLE	TSKTM1
/
/  13 NOV 78 (013; PDH)	FOR 'YMMDD' FILES, THE EXTENSION MUST BE 'RAW'
/   1 NOV 78 (012; PDH) CHANGE TO 'YMMDD' DESIGNATION FOR FILE NAMES,
/			WHERE 'Y' IS ALPHABETIC, DERIVED FROM
/			'@' FOR 1970, 'A' FOR 1971, ETC.
/  11 FEB 78 (011; PDH) ADD 'CHECKPOINT' FACILITY FOR LOGGING IN;
/			INCREASE BUFFER SIZE TO 26
/  18 JAN 78 (010; PDH) FIX UP SOME FILE MANAGEMENT ERRORS
/  18 JAN 78 (009; PDH) CHECK FOR -6, -13 EV'S IN 'WTFOR'
/  17 JAN 78 (008; PDH) ADD CODE TO UPDATE "TO-DAY'S" ACCOUNTING
/			FILE WHEN ONE EXISTS (AFTER 'DOS', 'SAVE').
/  12 JAN 78 (007; PDH) PERFORM RELOCATION OF 'TSKTM2' VIA XR
/  11 JAN 78 (006; PDH) WAIT UNTIL 'TSKTM2' LOADED INTO CORE
/			BEFORE RELOCATING THE ADDRESSES.
/  11 JAN 78 (005; PDH) CHANGE 'WTFOR' TO SUPPLY BETTER INFORMATION
/   9 JAN 78 (004; PDH) RELOCATE ADDRESS IN CONTROL TABLE
/   9 JAN 78 (003; PDH) WE GOOFED WITH THE 'PARINF' CPB
/   9 JAN 78 (002; PDH) ADD 'DEBUG', 'SNAP' AND 'SUSPND'
/   6 JAN 78 - PAUL HENDERSON
/
/  THIS ROUTINE IS SECTION 1 OF A 2-SECTION TASK TO PERFORM
/  TASK TIMING.  ITS FUNCTION IS TO REQUEST THE EXECUTION OF
/  THE SECOND SECTION (TSKTM2), THEN DETERMINE THE BASE ADDRESS
/  OF ITS PARTITION SO THAT IT CAN RELOCATE THE ADDRESSES IN THE
/  TASK TIMING CONTROL TABLE.  ONCE THESE ADDRESSES HAVE BEEN
/  RELOCATED, IT IS SAFE TO SET 'TIMFLG' IN THE EXECUTIVE.
/     THIS SECTION WILL BE TASK BUILT WITH A PRIORITY OF 50 TO
/  RUN IN THE MCR PARTITION.
/
/     FOR DEBUGGING, THE SYMBOL
/DEBUG=1		/ IS DEFINED.
/
TIMFLG=312
IDX=ISZ
	.DEC							/(008)
DKI=57			/ DISK INPUT FILE			/(008)
DKO=58								/(008)
	.OCT							/(008)
I=400000							/(008)
IRS=711000							/(008)
IMP=711400							/(008)
IDV=712000							/(008)
ILD=713000							/(008)
IST=713600							/(008)
UNSWQ=715270							/(008)
/
	.NOLST	/ DON'T LIST SNAP DEFINITION IF NOT DEBUG	/(002)
	.IFDEF	DEBUG						/(002)
	.LST							/(002)
TT=3								/(002)
	.DEFIN	SNAP,ID,CODE,BEGIN,END				/(002)
	.GLOBL	.SNAP						/(002)
BG=BEGIN-1							/(002)
	.DEC							/(002)
ID2=ID								/(002)
	.OCT							/(002)
	JMS*	.SNAP						/(002)
	CODE+0*1000 ID2&777					/(002)
	BG							/(002)
	END-BG*777777						/(002)
	.ENDM							/(002)
	.ENDC							/(002)
	.LST							/(002)
/
	.EJECT							/(004)
	.GLOBL	.IOERR
/
TSKTM1	CAL	DATE		/ GET TO-DAY'S DATE		/(008)
	CAL	DELETM		/ 'UPDATE ACT' PROBABLY NOT	/(010)
	JMS	WTFOR		/ THERE, BUT DELETE IT ANYWAY	/(010)
	CAL	RENAME		/ ATTEMPT TO RENAME THE FILE	/(008)
	JMS	WTFOR		/ GENERATED ON LAST 'DOS', OR	/(008)
	SAD	(-13		/ OR 'SAVE'.			/(008)
	JMP	PARTIT		/ NO FILE. BYPASS UPDATING.	/(008)
	CAL	CLOSTM		/ RENAMING NECESSARY TO PREVENT	/(010)
	JMS	WTFOR		/ MAJOR I/O DISASTER		/(008)
				/ 'TEMPRY ACT' -> 'UPDATE ACT'	/(008)
	.DEC							/(012)
	LAC	DATE+4		/ GET YEAR			/(008)
	AAC	-70		/ AUTOMATICALLY CONVERTED TO	/(012)
	.OCT			/ THE CORRECT .SIXBT VALUE	/(012)
	CLQ!LRSS 6		/ TEMPORARILY STORE IN MQ	/(012)
/
	LAC	DATE+2		/ GET MONTH			/(008)
	PAX							/(008)
	LAC	MONTHS-1,X	/ GET 2-CHARACTER MONTH DESIGNATOR /(008)
	OMQ			/ INCLUDE YEAR DESIGNATION	/(012)
	DAC	S.NM1		/ PUT IN 'SEEK' CPB		/(008)
	DAC	C.NM1		/ AS WELL AS THE 'CLOSE'	/(008)
	DAC	D.NM1		/ AND 'DELETE' CPB'S		/(008)
/
	LAC	DATE+3		/ GET DAY OF MONTH		/(012)
	JMS	OCTDEC		/ CONVERT TO .SIXBT DECIMAL	/(012)
	LLSS	11		/ SHIFT TO CORRECT PLACE	/(012)
	DAC	S.NM2		/ FILE NAMES NOW COMPLETELY READY /(008)
	DAC	C.NM2						/(008)
	DAC	D.NM2						/(008)
/
	.EJECT
	CAL	ENTER		/ OPEN FILE 'TEMPRY ACT'	/(008)
	JMS	WTFOR						/(008)
	CAL	SEEK		/ SEE IF WE HAVE DONE ANY	/(008)
	JMS	WTFOR		/ ACCOUNTING YET TO-DAY.	/(008)
	SAD	(-13		/ ('YMMDD RAW')			/(008)
	JMP	APPEND		/ NO.  NOTHING TO UPDATE.	/(008)
/
	JMS	MOVE		/ COPY TO-DAY'S STATISTICS	/(008)
	CAL	CLOSEI						/(008)
	JMS	WTFOR						/(008)
APPEND	CAL	SEEKTM		/ 'UPDATE ACT'			/(008)
	JMS	WTFOR						/(008)
	JMS	MOVE		/ APPEND THE LATEST INFO	/(008)
	CAL	CLOSEI		/ CLOSE INPUT FILE 'UPDATE ACT'	/(010)
	JMS	WTFOR						/(010)
/
	CAL	CLOSE		/ CLOSE TEMPORARY OUTPUT FILE	/(008)
	JMS	WTFOR		/ 'TEMPRY ACT'			/(008)
	CAL	DELETM		/ DELETE FILE 'UPDATE ACT'	/(010)
	JMS	WTFOR						/(010)
	CAL	DELETE		/ DELETE ORIGINAL INPUT FILE	/(008)
	JMS	WTFOR		/ 'YMMDD RAW'			/(008)
	CAL	RENAME		/ RENAME TEMPORARY FILE TO ORIG NAME /(008)
	JMS	WTFOR						/(008)
	CAL	CLOSE		/ RENAMING OCCURS ON THE 'CLOSE' /(008)
	JMS	WTFOR		/ 'TEMPRY ACT' -> 'YMMDD RAW'	/(008)
/
	.EJECT
PARTIT	CAL	PARINF		/ INVESTIGATE PARTITION 'TSKTIM' /(008)
	JMS	WTFOR						/(006)
	.IFDEF	DEBUG						/(006)
	SNAP	1,1,P.BA,P.SZ					/(006)
	JMS	SUSPND						/(006)
	.ENDC							/(006)
	LAC	WTFOR		/ 'WTFOR' NOW CONTAINS A VALID	/(007)
	AND	(070000		/ ADDRESS FOR GENERATING	/(007)
	TCA			/ THE XR ADJUSTMENT FACTOR	/(007)
	DAC	XRADJ						/(007)
	LAC	P.BA		/ TO DETERMINE WHEN REQUESTED	/(006)
	AAC	20		/ TASK HAS BEEN LOADED INTO	/(006)
	TAD	XRADJ		/ CORE, WE WILL SET THE EVENT	/(007)
	PAX			/ VARIABLE LOCATION NON-ZERO,	/(007)
	DAC	PNTR		/ THEN WAIT FOR IT TO BECOME 0	/(006)
	LAW	-1						/(006)
	DAC	0,X		/ SET EV LOCATION		/(007)
/
	CAL	REQ		/ REQUEST TASK 'TSKTM2'		/(007)
	JMS	WTFOR
	.IFDEF	DEBUG						/(002)
	SNAP	2,401		/ SNAP REGISTERS		/(002)
	JMS	SUSPND		/ THEN SUSPEND TASK		/(002)
	.ENDC							/(002)
/
WAIT	LAC	PNTR		/ RESTORE XR LOST DURING 'CAL'	/(007)
	PAX							/(007)
	LAC	0,X		/ HAS TASK BEEN LOADED INTO	/(007)
	SNA			/ PARTITION YET?		/(006)
	JMP	LOADED		/ EV IS ZERO WHEN LOADED	/(006)
	CAL	MARK		/ NOT LOADED.  MARK TIME FOR	/(006)
	JMS	WTFOR		/ 1 CLOCK TICK, THEN		/(006)
	JMP	WAIT		/ TRY AGAIN			/(006)
/
LOADED	AXR	1		/ POINT TO 1ST ADDRESS IN	/(007)
				/ TASK TIMING CONTROL TABLE	/(006)
	LAW	-5		/ RELOCATE THE 5 ADDRESSES	/(004)
	DAC	CNTR		/ IN THE TIMING CONTROL TABLE	/(004)
/
LOOP	LAC	0,X		/ GET ADDRESS			/(007)
	TAD	P.BA		/ ADD RELOCATION FACTOR		/(004)
	DAC	0,X		/ ADDRESS NOW REAL-WORLD ADDRESS /(007)
	AXR	1						/(007)
	ISZ	CNTR						/(004)
	JMP	LOOP						/(004)
/
	.EJECT
	.IFDEF	DEBUG						/(007)
	LAC	P.BA		/ INSERT ADDRESS OF TIMING	/(007)
	AAC	20		/ CONTROL TABLE IN 'SNAP'	/(007)
	DAC	SNAP3+2		/ MACRO EXPANSION		/(007)
SNAP3	SNAP	3,0,1,10	/ SNAP THE RELOCATED TABLE	/(007)
	JMS	SUSPND						/(007)
	.ENDC							/(007)
	LAC	P.BA
	AAC	20		/ NORMAL MODE TASKS BEGIN AT 20
	DAC*	(TIMFLG		/ SET 'TIMFLG' TO BEGIN TASK TIMING
	.IFDEF	DEBUG						/(002)
	SNAP	4,401						/(002)
	JMS	SUSPND						/(002)
	.ENDC							/(002)
	CAL	REQCKP		/ CHECKPOINT START-UP IN CASE	/(011)
		/ WE NEED TO GENERATE A LOGIN TIME FOR SOMEONE	/(011)
	CAL	(10		/ THEN EXIT.
/
WTFOR	XX
	CAL	WAITFR
	LAC	EV
	SMA							/(005)
	JMP*	WTFOR
	SAD	(-13		/ 'FILE NOT FOUND'?		/(009)
	JMP*	WTFOR		/ THIS WILL BE ACCEPTED		/(009)
	SAD	(-6		/ IGNORE UNIMPLEMENTED FUNCTION	/(009)
	JMP*	WTFOR						/(009)
/
	LAC	WTFOR		/ INSERT ADDRESS INTO		/(005)
	DAC*	.IOERR		/ '.IOERR'			/(005)
	LAC	.IOERR						/(005)
	IAC			/ NOW POINT TO SECOND LOCATION	/(005)
	DAC	WTFOR						/(005)
	LAC	EV		/ RETRIEVE BAD EV		/(005)
	JMP*	WTFOR		/ GO TO '.IOERR' (NEVER RETURN)	/(005)
/
/  SUBROUTINE TO COPY A FILE, RECORD BY RECORD FROM ONE LUN TO ANOTHER.
/
MOVE	XX
READ	CAL	READL		/ READ A RECORD FROM INPUT FILE
	JMS	WTFOR
	LAC	LINE
	AND	(7
	SAD	(5
	JMP*	MOVE		/ RETURN ON END OF INPUT FILE
	CAL	WRITEL		/ COPY RECORD TO OUTPUT FILE
	JMS	WTFOR
	JMP	READ
/
	.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
	.NOLST							/(002)
	.IFDEF	DEBUG						/(002)
	.LST							/(002)
SUSPND	XX							/(002)
	CAL	WRSUS		/ 'TSKTM1' SUSPENDED		/(002)
	JMS	WTFOR						/(002)
	CAL	(6		/ SUSPEND THE TASK		/(002)
	JMP*	SUSPND						/(002)
/
WRSUS	2700;	EV;	TT; 2; SUSMSG				/(002)
SUSMSG	SM-.*400+2; 0; .ASCII "'TSKTM1' SUSPENDED"<15> ;SM=.	/(002)
	.ENDC							/(002)
	.LST							/(002)
/
/  VARIABLES AND CPB'S
/
EV;XRADJ;P.BA;P.SZ		/ P.BA & P.SZ MUST BE CONSECUTIVE
PNTR=P.SZ;CNTR=EV						/(004)
WAITFR	20;	EV
PARINF	26;	EV;	.SIXBT	'TSKTIM' ; P.BA			/(003)
MARK	13;	EV;	1; 1
REQ	01;	EV;	.SIXBT	'TSKTM2' ; 13
REQCKP	01;	0;	.SIXBT	'..CKP.' ; 2
DATE	24;	0;	.BLOCK	6
ENTER	3300;	EV;	DKO; .SIXBT 'TEMPRYACT'
SEEK	3200;	EV;	DKI;S.NM1;S.NM2; .SIXBT 'RAW'		/(013)
SEEKTM	3200;	EV;	DKI; .SIXBT 'UPDATEACT'
READL	2600;	EV;	DKI; 0; LINE; 26
WRITEL	2700;	EV;	DKO; 0; LINE
CLOSEI	3400;	EV;	DKI
CLOSE	3400;	EV;	DKO;C.NM1;C.NM2; .SIXBT 'RAW'		/(013)
CLOSTM	3400;	EV;	DKO; .SIXBT 'UPDATEACT'			/(010)
DELETE	3500;	EV;	DKI;D.NM1;D.NM2; .SIXBT 'RAW'		/(013)
DELETM	3500;	EV;	DKI; .SIXBT 'UPDATEACT'			/(010)
RENAME	3700;	EV;	DKO; .SIXBT 'TEMPRYACT'
LINE	.BLOCK	26
CHAR=LINE+1
/
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	TSKTM1
