	.TITLE *** THE SLICE MCR FUNCTION ***
/ 
/ 
/                   FIRST PRINTING, FEBRUARY 1974
/ 
/ THE INFORMATION IN THIS DOCUMENT IS SUBJECT TO 
/ CHANGE WITHOUT NOTICE AND SHOULD NOT BE CONSTRUED
/ AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION.
/ DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPON-
/ SIBILITY FOR ANY ERRORS THAT MAY APPEAR IN THIS
/ DOCUMENT.
/ 
/ THE SOFTWARE DESCRIBED IN THIS DOCUMENT IS FUR-
/ NISHED TO THE PURCHASER UNDER A LICENSE FOR USE ON
/ A SINGLE COMPUTER SYSTEM AND CAN BE COPIED (WITH
/ INCLUSION OF DIGITAL'S COPYRIGHT NOTICE) ONLY FOR 
/ USE IN SUCH SYSTEM, EXCEPT AS MAY OTHERWISE BE PRO-
/ VIDED IN WRITING BY DIGITAL.
/ 
/ DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPONSIBILITY
/ FOR THE USE OR RELIABILITY OF ITS SOFTWARE ON EQUIP-
/ MENT THAT IS NOT SUPPLIED BY DIGITAL.
/ 
/ COPYRIGHT (C) 1974, BY DIGITAL EQUIPMENT CORPORATION
/ 
/ 
        .EJECT
/ 
/ COPYWRITE 1973 DIGITAL EQUIPMENT CORP., MAYNARD, MASS.
/ 
/ EDIT #8	AUG. 30 1974	M. HEBENSTREIT
/
/ THIS MCR FUCNTION CAN BE USED TO TURN TIME SLICING ON OR OFF.
/ WHEN TIME SLICING IS TURNED ON PARAMETERS IN THE EXEC ARE SET TO
/ INDICATE THE TIME SLICING TIME AND THE PRIORITY RANGE.
/ NO TASK'S STATUS IS CHANGED DURING THE EXECUTION OF THIS TASK.
/ THE TIME SLICING SUBROUTINE WILL CHANGE THE STATUS OF SOME TASKS
/ THE 1ST TIME THIS SUBROUTINE IS ENTERED, PROVIDED THAT TIME SLICING IS ON.
/ WHEN TIME SLICING IS TURNED OFF ALL TASKS WITH STATUS 7 HAVE
/ THEIR STATUS SET BACK TO 5. THE TIME SLICING TIME IS THEN
/ ZEROED TO INDICATE THAT TIME SLICING IS OFF.
/ 
/ THE COMMAND STRING FORMAT IS:
/ 
/	MCR>SLICE XXX-YYY ZZZ AAA$
/	      OR
/	MCR>SLICE XXX ZZZ AAA$
/ 
/ TO TURN TIME SLICING ON. WHERE XXX AND YYY ARE 3 DIGIT DECIMAL
/ NUMBERS INDICATING THE PRIORITY RANGE AND ZZZ IS THE NUMBER OF
/ TICKS (IN DECIMAL NOTATION) A TASK SHOULD REMAIN AT STATUS 5.
/ AAA IS THE NUMBER OF TIMES THE TIME SLICING SUBROUTINE IN THE
/ EXECUTIVE SHOULD BE ENTERED BEFORE ALLOWING SOME CPU TO FALL
/ THRU TO BATCH OR SOME OTHER LOW PRIORITY TASKS.
/ NOTE THAT THE LOWEST PRIORITY IN THE RANGE MUST BE
/ GREATER THAN OR EQUAL TO 100. THAT IS AAA>=100.
/ 
/ TO TURN TIME SLICING OFF:
/  
/	MCR>SLICE OFF$
/ 
/ IN ALL OF THE COMMAND STRINGS ABOVE $ INDICATES A LINE TERMINATOR.
/ 
/ 
.ENB=705521	/ENABLE INTERRUPTS
.INH=705522	/INHIBIT INTERRUPTS
ATL=244		/ADDRESS OF ATL LISTHEAD
FAC=174		/ADDRESS OF FETCH-A-CHARACTER SUBROUTINE
MCRRI=171	/MCR FLAG ADDRESS
SLITIM=315	/ADDRESS OF THE FLAG USED TO INDICATE IF
			/TIME SLICING IS ON OR OFF. IF OFF THE
			/WORD CONTAINS 0. IF ON THE WORD CONTAINS
			/THE 2'S COMP. OF THE SLICING TIME IN
			/TICKS.
SLIHR=316	/ADDRESS OF THE WORD USED TO STORE
			/THE HIGHEST PRIORITY IN THE TIME
			/SLICING RANGE.
SLILR=317	/ADDRESS OF THE WORD USED TO STORE THE
			/2'S COMP. OF THE LOWEST PRIORITY IN THE
			/TIME SLICING RANGE.
SLIPTR=157	/ADDRESS OF A POINTER TO THE COUNTER USED
			/TO DETERMINE WHEN THE NEXT TASK SHOULD
			/HAVE ITS PRIORITY SET TO 5.
IDX=ISZ		/USED WHEN THE INTENTION IS NEVER TO SKIP
/ 
START	LAC	(START		/COMPUTE THE XR ADJUSTMENT FACTOR
	AND	(070000
	TCA
	DAC	XADJ		/STORE THE ADJUSTMENT FACTOR IN XADJ
	JMS	NUMBER		/READ A DECIMAL NO. FROM CONSOLE
	JMP	ENDSLI		/RETURN HERE IF A POSSIBLE ERROR
				/WAS DETECTED.
	DAC	TEMP		/RETURN HERE IF NO ERROR -- SAVE THE
				/BREAK CHARACTER TEMPORARILY.
	LAC*	(SLITIM		/IS TIME SLICING ON ALREADY?
	SZA
	JMP	ERR3		/YES -- ERROR
	LAC	TEMP		/NO -- PICK UP BREAK CHAR. AGAIN
	SAD	(40		/WAS THE BREAK CHAR. A SPACE
	JMP	ONEPRI		/YES -- THEN ONLY ONE PRIO IN RANGE
	SAD	(55		/WAS BREAK CHAR. A MINUS?
	SKP
	JMP	ERR1		/NO -- FORMAT ERROR
	LACQ			/YES -- SAVE THE LOW PRIORITY
	DAC	LOWPRI
	JMS	NUMBER		/GET THE HIGH PRIORITY
	JMP	ERR1		/RETURN HERE ON AN ERROR
	LACQ			/RETURN HERE ON NO ERROR AND STORE
	DAC	HIPRI		/THE HIGH PRIORITY
	JMP	GETTIM		/GET READY TO GET THE NO. OF TICKS
ONEPRI	LACQ			/ONLY ONE PRIORITY WAS SPECIFIED SO
	DAC	LOWPRI		/STORE IT IN BOTH LOCATIONS.
	DAC	HIPRI
GETTIM	JMS	NUMBER		/GET THE NUMBER OF TICKS
	JMP	ERR1		/RETURN HERE ON AN ERROR
	DAC	TERM		/RETURN HERE IF OK AND STORE THE
				/BREAK CHARACTER.
	LACQ			/NOW PICK UP THE NO. OF TICKS
	SNA			/NO. OF TICKS IS ZERO?
	JMP	ERR4		/YES -- ERROR
	TCA			/NO -- COMPLEMENT THE NO. OF TICKS
	DAC	TIME		/AND SAVE THE 2'S COMP.
	LAC	TERM		/WAS THE BREAK CHAR A SPACE?
	SAD	(40
	SKP
	JMP	ERR1		/NO -- ERROR
	JMS	NUMBER		/YES -- GET NO. OF ENTRIES TO SLICE S.R.
	JMP	ERR1		/RETURN HERE ON AN ERROR
	DAC	TERM		/RETURN HERE IF OK AND SAVE BRK.
	LACQ			/GET THE NO. OF ENTRIES
	SPA!SNA			/MUST BE POSITIVE AND NON-ZERO
	JMP	ERR5		/IT'S NOT -- ERROR
	SAD	(1		/CAN'T BE 1 EITHER!
	JMP	ERR5		/IT IS A 1 -- ERROR
	TCA
	DAC	HOLDUP		/SAVE IT.
	LAC	TERM		/NOW SEARCH FOR THE REAL LINE 
				/TERMINATOR.
	SKP
	JMS*	(FAC		/READ A CHAR OFF CONSOLE TTY
	SAD	(175		/ALTMODE?
	SKP			/YES
	SAD	(15		/CARRIAGE RETURN?
	SKP			/YES
	JMP	.-5		/NO -- LOOK AT NEXT CHARACTER
/ 
	LAC	LOWPRI		/TEST THAT LOWPRI IS >=100 (10)
	.DEC
	AAC	-100
	.OCT
	SPA
	JMP	ERR2		/IT'S NOT SO THAT'S AN ERROR.
	LAC	(-1001		/IS HIPRI <= 512?
	TAD	HIPRI
	SMA
	JMP	ERR2		/NO -- THAT'S AN ERROR
	LAC	LOWPRI		/IS 0<LOWPRI<=HIPRI?
	SNA
	JMP	ERR2		/NO -- ERROR
	TCA
	TAD	HIPRI
	SPA
	JMP	ERR2		/NO -- ERROR
	LAC	LOWPRI		/YES -- STORE 2'S COMP OF LOWPRI
	TCA
	DAC*	(SLILR
	LAC	HIPRI		/STORE THE HIGH PRIORITY
	DAC*	(SLIHR
	LAC*	(SLIPTR		/PREPARE TO TURN TIME SLICING ON
				/BY SETTING THE TIME SLICING TIME
				/COUNTER AND THE TIME SLICING ON
				/INDICATOR
	DAC	TEMP		/SAVE THE ADDRESS OF THE TIME
				/SLICING COUNTER
	LAC	TIME		/PICK UP THE 2'S COMP OF THE TICKS
	.INH			/INHIBIT INTERRUPTS
	DAC*	TEMP		/SET THE COUNTER
	DAC*	(SLITIM		/SET THE FLAG TO INDICATE THAT TIME
				/SLICING IS NOW ON!
	IDX	TEMP		/MAKE TEMP POINT TO THE LOCATION
				/THAT STORES THE NUMBER OF TIMES
				/TIME SLICING HAS BEEN ENTERED
				/WITHOUT LETTING ANY TASKS BELOW THE
				/PRIORITY RANGE RUN.
	LAC	HOLDUP		/PUT A COUNTER IN THIS LOCATION SO
	DAC*	TEMP		/A 'TIME OUT' CAN BE DECLARED IN ORDER
				/THAT BATCH OR SOME LOW PRIORITY TASKS
				/CAN AT LEAST LOAD INTO CORE.
	IDX	TEMP		/SET UP TIME SLICING S.R. PARAMETER SO
	DAC*	TEMP		/THE S.R. CAN RE-INITIALIZE ITSELF.
	.ENB			/ENABLE INTERRUPTS
/
ALLDON=.
EXIT	LAC	TERM		/EXIT ACCORDING TO TERMINATOR
	SAD	(175
	JMP	.+3
EXITA	CAL	REQMCR
	CAL	(10
	DZM*	(MCRRI
	CAL	(10
/ 
/ COME HERE IF AN ERROR WAS FOUND IN THE FIRST DECIMAL NUMBER
/ WHICH WAS TYPED. MAYBE THE OPERATOR TYPED 'OFF' TO TURN
/ TIME SLICING OFF.
/ 
ENDSLI	SAD	(117		/WAS THE CHARACTER AN O?
	SKP
	JMP	ERR1		/NO -- FORMAT ERROR
	JMS*	(FAC		/YES -- GET NEXT CHAR.
	SAD	(106		/IS IT AN F?
	SKP
	JMP	ERR1		/NO -- FORMAT ERROR
	JMS*	(FAC		/YES -- GET NEXT CHAR
	SAD	(106		/F?
	SKP
	JMP	ERR1		/NO -- FORMAT ERROR
	JMS*	(FAC		/YES -- LOOK FOR LINE TERMINATOR
	SAD	(15
	SKP
	SAD	(175
	SKP
	JMP	.-5
	DAC	TERM		/SAVE THE TERMINATOR
/
	DZM*	(SLITIM		/ZERO SLITIM TO INDICATE THAT
				/TIME SLICING IS OFF!
	LAC	(ATL		/PREPARE TO SCAN ATL
	JMS	SETXR
ATLSCN	LAC	0,X		/END OF ATL?
	SAD	(ATL
	JMP	ALLDON		/YES -- PREPARE TO EXIT
	JMS	SETXR
	LAC	7,X		/IS TASK AT STATUS 7?
	SAD	(7
	SKP
	JMP	ATLSCN		/NO -- PROCESS NEXT NODE
	LAC	(5		/YES -- SET STATUS BACK TO 5
	DAC	7,X
	JMP	ATLSCN		/PROCESS NEXT NODE
	.EJECT
/ 
/ VARIABLES, MESSAGES, AND CPBS
/
MSG1	MSG2-MSG1/2*1000
	0
	.ASCII "FORMAT ERROR"<15>
MSG2	MSG3-MSG2/2*1000
	0
	.ASCII "ILLEGAL PRIORITY"<15>
MSG3	MSG4-MSG3/2*1000
	0
	.ASCII "TIME SLICING IS ALREADY ON"<15>
MSG4	MSG5-MSG4/2*1000
	0
	.ASCII "TICKS MUST BE NON-ZERO"<15>
MSG5	EV-MSG5/2*1000
	0
	.ASCII "INVALID ENTRY TIMES NUMBER"<15>
EV	0
HOLDUP	0
LOWPRI	0
HIPRI	0
TIME	0
XADJ	0
TERM	0
TEMP	0
FIRST	0
NUMT	0
CHAR	0
NUM	0
COUNT	0
NUMFLG	0
/ 
WRITE	2700
	EV
	3
	2
	XX
WAIT	20
	EV
REQMCR	1
	0
	.SIXBT "..."
	.SIXBT "MCR"
	0
	.EJECT
/ 
/ MISC ROUTINES AND SUBROUTINES
/
ERR5	LAC	(MSG5
	SKP
ERR4	LAC	(MSG4	/TICKS MUST BE NON-ZERO
	SKP
ERR3	LAC	(MSG3	/T.S. IS ALREADY ON
	SKP
ERR1	LAC	(MSG1	/FORMAT ERROR ROUTINE
	SKP
ERR2	LAC	(MSG2	/ILLEGAL PRIORITY ROUTINE
	DAC	WRITE+4
	CAL	WRITE
	CAL	WAIT
	LAC	(15
	DAC	TERM
	JMP	EXITA
/
/ SUBROUTINE SETXR -- ADJUST THE XR
/ 
/ ALTERED REGISTERS: AC AND XR
/ 
/ CALLING SEQUENCE:
/		LAC	ADDRESS
/		JMS	SETXR
/ 
SETXR	0
	TAD	XADJ
	PAX
	JMP*	SETXR
/
/ SUBROUTINE NUMBER -- READ A DECIMAL NUMBER OF UP TO 3 DIGITS
/			OFF THE MCR TTY.
/ 
/ ALTERED REGISTERS: AC AND MQ
/ 
/ CALLING SEQUENCE:
/		JMS	NUMBER
/		JMP	???	/RETURN HERE IF 1ST CHARACTER
/				/AFTER A BUNCH OF SPACES IS NOT
/				/A DECIMAL DIGIT WITH THE CHARACTER
/				/IN THE AC.
/		???	???	/RETURN HERE IF 1ST CHARACTER
/				/AFTER A BUNCH OF SPACES IS A DECIMAL
/				/DIGIT WITH THE BREAK CHARACTER IN THE
/				/AC AND THE NUMBER IN THE MQ.
/ 
NUMBER	0
	LAW	-3		/SET DIGIT COUNTER
	DAC	COUNT
	DZM	NUM		/ZERO PREVIOUS RESULTS
	CLC			/SET A FLAG TO INDICATE THAT SPACES
	DAC	NUMFLG		/ARE NOT BREAK CHARACTERS YET.
NUM1	JMS*	(FAC		/GET A CHARACTER
	SAD	(40		/WAS THE CHARACTER A SPACE?
	JMP	NUMSPC		/YES
	DZM	NUMFLG		/NO -- CLEAR FLAG TO INDICATE THAT ANY
				/SPACES ENCOUNTERED SHOULD BE USED AS
				/BREAK CHARACTERS.
	DAC	NUMT		/SAVE IT TEMPORARILY
	AAC	-60		/IS IT A DIGIT?
	SPA
	JMP	NUM2		/NO -- EITHER A BREAK OR AN ERROR
	DAC	CHAR		/SAVE THE POTENTIAL DIGIT
	AAC	-12
	SMA
	JMP	NUM2		/NO -- EITHER A BREAK OR AN ERROR
	LAC	NUM		/YES -- PICK UP THE REAL NUMBER
				/THAT HAS ALREADY BEEN CONSTRUCTED
	CLL
	MUL			/MULTIPLY IT BY 10 DECIMAL
	12
	LACQ			/GET RESULT INTO AC
	TAD	CHAR		/ADD THE DIGIT JUST READ
	DAC	NUM		/SAVE THE RESULTING DECIMAL NUMBER
	ISZ	COUNT		/HAVE 3 DIGITS BEEN READ?
	JMP	NUM1		/NO -- READ SOME MORE
	JMS*	(FAC		/YES -- READ A BREAK CHARACTER
NUM3	DAC	CHAR		/SAVE THE CHARACTER TEMPORARILY
	IDX	NUMBER		/PREPARE TO RETURN AT JMS+2
	LAC	NUM		/PICK UP THE DECIMAL NUMBER
	LMQ			/STORE IT IN THE MQ
	LAC	CHAR		/GET THE BREAK CHAR INTO THE AC
	JMP*	NUMBER		/RETURN AT JMS+2
NUM2	LAW	-3		/CHARACTER IS EITHER A BREAK OR ERROR
	SAD	COUNT		/IF THIS WAS THE 1ST CHARACTER READ
				/ITS AN ERROR. OTHERWIZE ITS A BREAK.
	JMP	NUMERR		/ERROR
	LAC	NUMT		/BREAK -- GET THE CHARACTER INTO AC
	JMP	NUM3
NUMERR	LAC	NUMT		/ERROR SO GET CHARACTER INTO AC
	JMP*	NUMBER		/AND RETURN AT JMS+1
NUMSPC	LAC	NUMFLG		/CHAR. WAS A SPACE -- IS IT A BREAK CHAR.?
	SZA
	JMP	NUM1		/NO -- THE SPACE SHOULD BE IGNORED
	LAC	(40		/YES -- TREAT THE SPACE AS A BREAK CHAR.
	DAC	NUMT
	JMP	NUM2
	.END
	DAC	TERM		/SAVE THE REAL LINE TERMINATOR
