	.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 AND SECONDS.
/
/ CALLING SEQUENCE:
/
/	CALL TIME(IMIN,ISEC,IOFF)
/
/ ACTION:
/
/ UPON CALL, IMIN, ISEC, AND IOF ARE ALL ZEROED, AND A .TIMER
/ REQUEST IS QUEUED FOR AN INTERVAL OF ONE 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
/ AND SECONDS WORDS IN THE USER'S CALL ARE APROPRIATELY UPDATED.
/
/
.SCOM=100	/ADDRESS OF DOS'S COMMUNICATION REGION
.INH=705522	/INHIBIT INTERRUPTS
.ENB=705521	/ENABLE INTERRUPTS
/
/
	.GLOBL	TIME		/ ENTRY POINT
	.GLOBL	.DA		/ OTS GENERAL ARGUMENT 'GET' ROUTINE
/
/
TIME	XX
	JMS*	.DA		/ GET USER'S ARGUMENTS
	JMP	.+4		/ I'M EXPECTING THREE
IMIN	0			/ WORD TO HOLD THE MINUTES ELAPSED
ISEC	0			/ WORD TO HOLD THE SECONDS
IOFF	0			/ FLAG WORD TELLING ME WHEN TO STOP TIMING
	DZM*	IMIN		/ ZERO ALL HIS WORDS
	DZM*	ISEC		//
	DZM*	IOFF		//
	LAW	-74		/ 60(10), NUMBER OF SECONDS IN MINUTE
	DAC	MIN#		/ SAVE IN TEMPORARY
	LAC*	(.SCOM+74)	/ NUMBER OF TICKS PER SECOND
	DAC	TIMR+3		/ STUFF IN .TIMER INTERVAL VALUE
TIMR	.TIMER	XX,TIMEOUT	/ WAKE ME IN ONE SECOND OR SO
	JMP*	TIME		/ THAT ALL.
/
/
/ THE CLOCK HAS COUNTED 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*	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*	(.SCOM+74)	/ NO, SO RE-SHEDULE AN INTERRUPT AT ONE SECOND
	.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.
/
/
	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
