	.TITLE  SUPERVISOR
	.IODEV 1,2,3		/ASSIGN TTA TO DAT 1, LT1 TO DAT 2, LT2 TO DAT 3.
	.IODEV	4,5,6,7,-14,-15
	.GLOBL SAVE1,SAVE2,SAVE3,CWCHRC,SAV23,DIRSW
	.GLOBL	PS,SEMA,SUPER,COUNT,STOR1,G.MOVE,SAVE11,SAVE22,SAVE33,SEM1
PS	XX
	DAC	SPOT	/INCREMENT WAIT-LIST SEMAPHORE
	ISZ*	SPOT
	SKP
	JMP*	PS	/SEMAPHORE WAS -1
	ISZ	SPOT	/GET WAIT-LIST ADDRESS
PS1	LAC*	COUNT	/CHECK FOR COMPLETION OF INITIALIZATION
	SZA
	JMP	PS2	/COMPLETE
	XCT*	PS	/NOT COMPLETE GET SAVE ADDRESS
	DAC	SPOT
	JMP	PS3
PS2	LAC	READY	/FIND DEVICE SAVE ADDRESS
	SZA
	JMS	DEC
	JMP	SUPER	/NOTHING READY
PS3	DZM*	SPOT	/MARK END OF CHAIN
	ISZ	SPOT
	LAC	PS	/SAVE RETURN ADDRESS
	DAC*	SPOT
	ISZ	SPOT
	LACQ		/SAVE MQ
	DAC*	SPOT
	ISZ	SPOT
	LAC*	(AUTO10	/SAVE AUTOINDEX REGISTERS
	DAC*	SPOT
	ISZ	SPOT
	LAC*	(AUTO11
	DAC*	SPOT
	ISZ	SPOT
	LAC*	(AUTO12
	DAC*	SPOT
	ISZ	SPOT
	LAC*	(AUTO13
	DAC*	SPOT
	ISZ	SPOT
	LAC*	(AUTO14
	DAC*	SPOT
	ISZ	SPOT
	LAC*	(AUTO15
	DAC*	SPOT
	ISZ	SPOT
	LAC*	(AUTO16
	DAC*	SPOT
	ISZ	SPOT
	LAC*	(AUTO17
	DAC*	SPOT
SAVE	ISZ	SPOT	/SAVE BUFFER AREA
	LAW	-1030
	JMS	G.MOVE
	TAD	SEM1	/MOVE FROM THIS ADDRESS
	TAD	SPOT	/TO THIS ADDRESS
	LAC*	COUNT	/CHECK FOR COMPLETION OF INITIALIZATION
	SNA
	JMP	PSINC
	JMP	SUPER
PSINC	ISZ	PS
	ISZ	PS	/FIND RETURN ADDRESS IF COUNT 0
	JMP*	PS
DEC	0		/DECREMENT READY-LIST
	DAC	SPOT
	ISZ	DEC
	LAC*	READY
	DAC	READY
	JMP*	DEC
SUPER	LAC	READY	/CHECK READY-LIST
	SNA
	JMP	SCAN	/READY-LIST EMPTY
	DAC*	(AUTO17	/RESTORE SAVED BUFFER
	LAW	13
	AND	CMASK
	TAD	READY
	DAC	BOX
	LAW	-1040
	JMS	G.MOVE
	TAD	BOX	/MOVE FROM THIS ADDRESS
	TAD	SEM1	/TO THIS ADDRESS
	LAC*	(AUTO17	/RESTORE ROUTINE
	DAC	SPOT
	JMS	INC
	DAC	PS	/RESTORE RETURN ADDRESS,
	RAL		/LINK,
	JMS	INC
	LMQ		/MQ,
	JMS	INC
	DAC*	(AUTO10	/AND AUTOINDEX REGISTERS.
	JMS	INC
	DAC*	(AUTO11
	JMS	INC
	DAC*	(AUTO12
	JMS	INC
	DAC*	(AUTO13
	JMS	INC
	DAC*	(AUTO14
	JMS	INC
	DAC*	(AUTO15
	JMS	INC
	DAC*	(AUTO16
	JMS	INC
	DAC*	(AUTO17
	JMP*	PS	/RETURN
INC	0		/INCREMENT SAVE AREA ROUTINE
	ISZ	SPOT
	LAC*	SPOT
	JMP*	INC
SCAN	LAC	SEMA11	/CHECK SEMAPHORE FOR DEVICE -14
	SPA
	JMP	SCA1	/DEVICE -14 NOT USED
	LAC*	DIRSW	/CHECK I/O DIRECTION
	SPA
	JMP	SC12	/REVERSE DIRECTION
SC11	.WAITR	-14,SC1	/STATUS CHECK DEVICE -14
	LAC*	DIRSW	/CHECK I/O DIRECTION
	SPA
	JMP	SC14	/REVERSE DIRECTION
SC13	LAC	(SEMA11 /GET DEVICE ADDRESS
	JMS	DECRE	/DECREMENT DEVICE SEMAPHORE
	JMP	S1	/DEVICE READY
SCA1	LAC	SEMA12	/CHECK DEVICE -15 SEMAPHORE
	SPA
	JMP	SCAN1	/DEVICE -15 NOT USED
	LAC*	DIRSW	/CHECK I/O DIRECTION
	SPA
	JMP	SC11	/REVERSE DIRECTION
SC12	.WAITR	-15,SC1	/DEVICE -15 STATUS CHECK
	LAC*	DIRSW	/CHECK DIRECTION
	SPA
	JMP	SC13	/REVERSE DIRECTION
SC14	LAC	(SEMA12 /GET SEMAPHORE ADDRESS
	JMS	DECRE	/DECREMENT SEMAPHORE
	JMP	S1	/DEVICE READY
SCAN1	LAC	SEMA1	/CHECK DEVICE 1 SEMAPHORE
	SPA
	JMP	SC1	/DEVICE NOT USED
	.WAITR	1,SC1	/CHECK READY STATUS
	LAC	(SEMA1	/GET SEMAPHORE ADDRESS
	JMS	DECRE
S1	LAC	(SAVE1	/GET SAVE AREA ADDRESS
	JMS	VS
SC1	LAC	SEMA21	/CHECK DEVICE 4 SEMAPHORE
	SPA
	JMP	SCA2
	LAC*	DIRSW
	SPA
	JMP	SC22
SC21	.WAITR	4,SC2	/CHECK STATUS OF DEVICE 4
	LAC*	DIRSW
	SPA
	JMP	SC24
SC23	LAC	(SEMA21
	JMS	DECRE
	JMP	S2	/DEVICE READY
SCA2	LAC	SEMA22	/CHECK DEVICE 5 SEMAPHORE
	SPA
	JMP	SCAN2
	LAC*	DIRSW
	SPA
	JMP	SC21
SC22	.WAITR	5,SC2	/CHECK STATUS OF DEVICE 5
	LAC*	DIRSW
	SPA
	JMP	SC23
SC24	LAC	(SEMA22
	JMS	DECRE
	JMP	S2	/DEVICE READY
SCAN2	LAC	SEMA2	/CHECK DEVICE 2 SEMAPHORE
	SPA
	JMP	SC2
	.WAITR	2,SC2	/CHECK STATUS OF DEVICE 2
	LAC	(SEMA2
	JMS	DECRE
S2	LAC	(SAVE2
	JMS	VS
SC2	LAC	SEMA31	/CHECK DEVICE 6 SEMAPHORE
	SPA
	JMP	SCA3
	LAC*	DIRSW
	SPA
	JMP	SC32
SC31	.WAITR	6,SC3	/STATUS CHECK DEVICE 6
	LAC*	DIRSW
	SPA
	JMP	SC34
SC33	LAC	(SEMA31
	JMS	DECRE
	JMP	S3	/DEVICE READY
SCA3	LAC	SEMA32	/CHECK DEVICE 7 SEMAPHORE
	SPA
	JMP	SCAN3
	LAC*	DIRSW
	SPA
	JMP	SC31
SC32	.WAITR	7,SC3 	/STATUS CHECK DEVICE 7
	LAC*	DIRSW
	SPA
	JMP	SC33
SC34	LAC	(SEMA32
	JMS	DECRE
	JMP	S3	/DEVICE READY
SCAN3	LAC	SEMA3	/CHECK DEVICE 3 SEMAPHORE
	SPA
	JMP	SC3
	.WAITR	3,SC3	/STATUS CHECK DEVICE 3
	LAC	(SEMA3
	JMS	DECRE
S3	LAC	(SAVE3
	JMS	VS	/DEVICE READY
SC3	JMP	SUPER	/RECYCLE SUPERVISOR
DECRE	0		/DECREMENT DEVICE SEMAPHORE ROUTINE
	DAC	SPOT
	LAW	-1
	TAD*	SPOT
	DAC*	SPOT
	JMP*	DECRE
VS	XX
	DAC	BOX1	/GET SAVE AREA
	LAC	(SEMA	/DECREMENT WAIT-LIST SEMAPHORE
	DAC	SPOT
	LAW	-1
	TAD*	SPOT
	DAC*	SPOT
	SPA
	JMP*	VS	/NO DEVICE WAITING
	ISZ	SPOT
	LAC	SPOT
VS1	DAC	BOX	/FIND END OF WAIT-LIST
	LAC*	BOX
	SZA
	JMP	VS1
	LAC	BOX1	/CHAIN WAIT-LIST
	DAC*	BOX
	DZM*	BOX1
	LAC*	SPOT
	DAC	BOX
	LAC*	BOX
	DAC*	SPOT
	LAC	(READY	/GET READY-LIST
VS2	DAC	SPOT
	LAC*	SPOT	/FIND END OF READY-LIST
	SZA
	JMP	VS2
	LAC	BOX	/CHAIN READY-LIST
	DAC*	SPOT
	DZM*	BOX
	JMP*	VS	/RETURN
SPOT	0
BOX	0
BOX1	0
CMASK	007777
SEMA	-1; 0		/WAIT-LIST
READY	0		/READY-LIST
SAVE1	0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0
SEMA1	-1		/DEVICE 1 SEMAPHORE
SEMA11	-1		/DEVICE -14 SEMAPHORE
SEMA12	-1		/DEVICE -15 SEMAPHORE
SAVE11	.BLOCK	40
SAVE16	.BLOCK	765
SAVE13	2001		/DEVICE 1 TELETYPE I/O
SAVE14	3001		/IMAGE MODE
SAVE15	1001		/INITIALIZE DEVICE 1
SAVE17	SAVE11
SAV11	1763		/DEVICE -15
SAV12	0764		/DEVICE -14
SAV13	125		/DAT SLOT ADDRESS -14
SAV14	124		/DAT SLOT ADDRESS -15
SAVE2	0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0
SEMA2	-1		/DEVICE 2 SEMAPHORE
SEMA21	-1		/DEVICE -14 SEMAPHORE
SEMA22	-1		/DEVICE -15 SEMAPHORE
SAVE22	.BLOCK	40
SAVE27	.BLOCK	763
SAV23	2004		/DEVICE 4 FILE I/O
SAV22	2005		/DEVICE 5 FILE I/O
SAVE24	2002		/DEVICE 2 TELETYPE
SAVE25	3002		/IMAGE MODE
SAVE26	1002		/INITIALIZE
SAVE28	SAVE22
SAV20	1005		/DEVICE 5
SAV21	0004		/DEVICE 4
SAV24	145		/DAT SLOT ADDRESS 4
SAV25	146		/DAT SLOT ADDRESS 5
SAVE3	0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0
SEMA3	-1		/DEVICE 3 SEMAPHORE
SEMA31	-1		/DEVICE 6 SEMAPHORE
SEMA32	-1		/DEVICE 7 SEMAPHORE
SAVE33	.BLOCK	40
SAVE38	.BLOCK	763
SAV33	2006		/DEVICE 6
SAV32	2007		/DEVICE 7
SAVE35	2003		/DEVICE 3
SAVE36	3003		/IMAGE MODE
SAVE37	1003		/INITIALIZE
SAVE39	SAVE33
SAV30	1007		/DEVICE 7
SAV31	0006		/DEVICE 6
SAV34	147		/DAT SLOT ADDRESS 6
SAV35	150		/DAT SLOT ADDRESS 7
AUTO10=10
AUTO11=11
AUTO12=12
AUTO13=13
AUTO14=14
AUTO15=15
AUTO16=16
AUTO17=17
G.MOVE	XX		/MOVE ROUTINE
	DAC	MOVES
	LAW	-1
	XCT*	G.MOVE	/WHERE FROM
	DAC*	(AUTO10
	ISZ	G.MOVE
	LAW	-1
	XCT*	G.MOVE	/WHERE TO
	DAC*	(AUTO11
	ISZ	G.MOVE
	LAC*	AUTO10
	DAC*	AUTO11
	ISZ	MOVES
	JMP	.-3
	JMP*	G.MOVE
MOVES	XX
	.END
