	.TITLE	INTERVAL TIMER SUPPORT
/
/ COPYRIGHT (C) 1975
/ DIGITAL EQUIPMENT CORPORATION, MAYNARD, MA. 01754, U.S.A.
/
/ THIS SOFTWARE IS FURNISHED UNDER A LICENSE FOR USE ONLY
/ ON A SINGLE COMPUTER SYSTEM AND MAY BE COPIED ONLY WITH
/ THE INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS 
/ SOFTWARE, OR ANY OTHER COPYIES THEROF, MAY NOT BE PRO-
/ VIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER PERSON
/ EXCEPT FOR USE ON SUCH SYSTEM AND TO ONE WHO AGREES TO
/ THESE LICENSE TERMS.  TITLE TO AND OWNERSHIP OF THE
/ SOFTWARE SHALL AT ALL TIMES REMAIN IN DEC.
/
/ THE INFORMATION IS THIS DOCUMENT IS SUBJECT TO CHANGE
/ WITHOUT NOTICE AND SHOULD NOT BE CONSTRUED AS A COM-
/ MITMENT BY DIGITAL EQUIPMENT CORPORATION.
/
/ DEC ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY
/ OF ITS SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DEC.
/
	.EJECT
/
/
/EDIT #000  27-AUG-75	KENT BLACKETT--CREATED.
//
/
/ SUBROUTINE TO DETERMINE ELAPSED TIME IN MINUTES, SECONDS, AND TENTHS.
/
/ CALLING SEQUENCE:
/
/	CALL TIME10(IMIN,ISEC,ISEC10,IOFF)
/
/ ACTION:
/
/ UPON CALL, IMIN, ISEC, ISEC10, AND IOF ARE ALL ZEROED, AND A .TIMER
/ REQUEST IS QUEUED FOR AN INTERVAL OF ONE TENTH OF A SECOND.  (THE NUMBER
/ OF SECONDS REQUIRED TO MAKE A SECOND IS AVAILABLE IN .SCOM+74)
/ EACH TIME THE INTERVAL OVERFLOWS, ROUTINE 'TIMEOUT' IN THIS
/ CODE IS CALLED BY THE MONITOR, THE VARIABLE 'IOFF' PASSED
/ IN THE USER'S CALL TO TIME IS EXAMINED FOR A NON-ZERO VALUE.
/ IF 'IOFF' IS NON-ZERO, THE TIME REQUEST IS NOT REQUEUED,
/ INDICATING END OF INTERVAL.  IF 'IOFF' IS STILL ZERO, THE MINUTES
/ SECOND, AND TENTH OF SECONDS WORDS IN THE USER'S CALL ARE
/ APPROPRIATELY UPDATED.
/
/
.SCOM=100	/ADDRESS OF DOS'S COMMUNICATION REGION
.INH=705522	/INHIBIT INTERRUPTS
.ENB=705521	/ENABLE INTERRUPTS
/
/
	.GLOBL	TIME10		/ ENTRY POINT
	.GLOBL	.DA		/ OTS GENERAL ARGUMENT 'GET' ROUTINE
/
/
TIME10	XX
	JMS*	.DA		/ GET USER'S ARGUMENTS
	JMP	.+5		/ I'M EXPECTING FOUR
IMIN	0			/ WORD TO HOLD THE MINUTES ELAPSED
ISEC	0			/ WORD TO HOLD THE SECONDS
ISEC10	0			/ WORD TO HOLD THE TENTH OF SECONDS
IOFF	0			/ FLAG WORD TELLING ME WHEN TO STOP TIMING
	DZM*	IMIN		/ ZERO ALL HIS WORDS
	DZM*	ISEC		//
	DZM*	ISEC10		//
	DZM*	IOFF		//
	LAW	-74		/ 60(10), NUMBER OF SECONDS IN MINUTE
	DAC	MIN#		/ SAVE IN TEMPORARY
	LAW	-12		/ NUMBER OF TENTHS IN A SECOND
	DAC	SEC#		//
	LAC*	(.SCOM+74)	/ NUMBER OF TICKS PER SECOND
	IDIVS			/ DETERMINE A TENTH OF A SECOND
	12			/ NOTE THAT WHILE THE EAE UNIT IS ONE'S COMPL.
				/ AND .SCOM+74 IS THE TWO'S COMPL. OF THE NUMBER
				/ OF TICKS IN A SECOND, FOR THE 50
				/ AND 60 HZ. SYSTEMS, THE QUOTIENT
				/ AFTER THE IDIVS IS CORRECT, I.E. -5 OR -6.
	LACQ
	DAC	TIMR+3		/ STUFF IN .TIMER INTERVAL VALUE
TIMR	.TIMER	XX,TIMEOUT	/ WAKE ME IN ONE SECOND OR SO
	JMP*	TIME10		/ THATS ALL.
/
/
/ THE CLOCK HAS COUNTED A TENTH OF A SECOND, WAKE UP AND UPDATE USER'S
/ ELAPSED TIME WORDS, AND ALSO SEE IF INTERVAL IS DONE, I.E.
/ SEE IF THE USER HAS TURNED ME OFF BY SETTING IOFF TO NON-ZERO.
/
/
TIMEOUT	XX			/ CLOCK HAS OVERRUN
	DAC	ACSAVE#		/ SAVE THE AC
				/ NOTE THAT XVM DOESN'T SAVE THE LINK FOR ME,
				/ BUT NOTE ALSO THAT I'M NOT GOING TO USE IT.
	ISZ*	ISEC10		/ TELL USER ANOTHER TENTH HAS GONE BY
	ISZ	SEC		/ HAS ANOTHER SECOND GONE BY?
	JMP	NOTMIN		/ NO, SO NEITHER COULD HAVE A MINUTE
	DZM*	ISEC10		/ YES, SO START TENTHS OVER AGAIN
	LAW	-12		/ AND RESET THE TENTH COUNTER
	DAC	SEC		//
	ISZ*	ISEC		/ TELL USER ANOTHER SECOND HAS GONE BY
	ISZ	MIN		/ BUMP MY COUNTER, HAS IT BEEN A MINUTE?
	JMP	NOTMIN		/ NO,
	ISZ*	IMIN		/ YES, THEN TELL HIM THAT, TOO
	DZM*	ISEC		/ AND RESET HIS SECONDS COUNT
	LAW	-74		/ THERE ARE STILL 60(10) SECOND/MINUTE
	DAC	MIN		/ PUT IT IN MY OWN COUTNER
NOTMIN	LAC*	IOFF		/ OK, DOES HE WANT ME TO STOP TIMING NOW?
	SNA!CLA			/ SKIP IF YES
	LAC	TIMR+3		/ NO, SO RE-SHEDULE AN INTERRUPT AT 1/10 SEC.
	.INH			/// TURN OFF INTERRUPTS NOW, FIRST API
	IOF			/// THEN PI
/
/
/ YOU SEE, AS SOON AS .SCOM+74 IS RESET TO A NON-ZERO VALUE THE .TIMER
/ MECHANISM IS ARMED.  IF AN INTERRUPT SHOULD OCCUR FOLLOWING
/ THE DAC* (.SCOM+60) WHICH TOOK LONGER THAN ONE SECOND TO PROCESS,
/ I WOULD GET RECALLED WHEN THE OTHER INTERRUPT ROUTINE FINISHED, WHICH
/ WOULD CAUSE ME TO LOSE THE RETURN ADDRESS OF THIS (THE FIRST) .TIMER
/ INTERRUPT.  AS YOU CAN SEE, THIS WOULD COMPROMIZE SYSTEM INTEGRITY.
/
/ NOTE ALSO, PLEASE, THAT I AM SAFE IN ALWAYS DOING THE IOF, ION SEQUENCE.
/ THERE ARE BASICLY TWO CASES.  IN CASE ONE OUR MACHINE HAS NO API
/ HARDWARE.  THUS SINCE WE ARE HERE IN RESPONS TO A PI INTERRUPT, IT
/ MUST HAVE BEEN ON, SO I CAN CLEARLY TURN IT OFF, THEN ON.
/ CASE TWO IS ON A MACHINE WITH API.  THE INTERESTING SENARIO IS THAT
/ A PI-ONLY DEVICE SUCH AS TTY OR PP HAS INTERRUPTED AND IS BEING
/ SERVICED WHEN A CLOCK TICK OC CURS WHICH CALLS THIS ROUTINE.  THE
/ QUESTION IS, AM I SAFE IN TURNING ON PI WHEN I LEAVE.  THE
/ ANSWER IS, I CAN'T GET CALLED UNDER THESE CIRCUMSTANCES, BECAUSE A
/ PI-ONLY INTERRUPT WITH API ENABLED IS THE SAME AS A LEVEL 3 BREAK, WHICH
/ IS WERE THE CLOCK IS.  THUS, THE CLOCK IS HELD OFF DURING PP OR TTY
/ INTERRUPT SERVICING.  THEREFORE, BOTH PI AND API ARE ENABLED
/ WHEN I'M RUNNING.  HOWEVER, DOS-15 (NOT TO BE CONFUSED WITH XVM/DOS)
/ WAS NOT ALWAYS SURE IN THESE CASES.  ALSO, THE PDP-9 WOULD ALLOW
/ THE CLOCK TO BREAK EVEN WHILE THE PI-ONLY DEVICE IS BEING SERVICED.
/
/
	DAC*	(.SCOM+60)	/// RE-ARM THE .TIMER STUFF
	LAC	ACSAVE		/// RESTORE THE AC
	.ENB			/// RE-ENABLE API BREAKS
	ION			/// RE-ENABLE PI INTERRUPTS
	JMP*	TIMEOUT		/// AND EXIT, UNINTERRUPTED!
	.END
