	.TITLE COA.
 
/ .... EDIT #2 .... 6 NOV 69
 
/COPYRIGHT 1969, 1970, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.
 
/COA. --- BACKGROUND/FOREGROUND MONITOR SYSTEM.
/COA.=CORE TO CORE HANDLER
/TREATED AS A MULTIUNIT DEVICE HANDLER SO THAT
/IT CAN BE SHARED BY THE BGD AND FGD JOBS.
/J.J. MURPHY, JR  3-20-69.
/IT OPERATES COMPLETELY AT THE CAL LEVEL
/AND REQUIRES COMPLEMENTING REQUESTS
/BEFORE IT PERFORMS ANY DATA TRANSFERS.
/
.MED=3
.SCOM=100
	.GLOBL	COA.
COA.	JMS	CRSWAP		/SWAP BACKUP WITH LIVE REGS.
	0			/FOREGROUND BUSY REGISTER.
	0			/BACKGROUND BUSY REGISTER.
	0			/FOREGROUND .CLOSE REGISTER.
	0			/BACKGROUND .CLOSE REGISTER.
CRWD5	XX			/ION OR IOF
CRCNT	0			/TEMPORARY.
CROUT	XX			/RETURN POINTER.
/START OF BACKUP DATA REGISTERS.
CFUNC1	XX			/JMP ENTRY IN FUNCTION TABLE
CMODE1	XX			/0=FGRD, 1=BGRD
	XX
	XX
CDATA1	XX			/DATA MODE
CLBUF1	XX			/LINE BUFFER ADDRESS.
CWCNT1	XX			/LINE BUFFER WORD COUNT.
CREAL1	XX			/0=NOT REAL, PRIORITY/SUBR=REAL
/END OF BACKUP DATA REGISTERS.
/BEGINNING OF FUNCTION DISPATCH TABLE.
	JMP	CRINIT		/.INIT
	JMP	CRIGNR		/.OPER
	JMP	CRIGNR		/.SEEK
	JMP	CRIGNR		/.ENTER
	JMP	CRIGNR		/.CLEAR
	JMP	CRIGNR		/.CLOSE
	JMP	CRIGNR		/.MTAPE
CRIN	JMP	CRPROS		/.READ (.REALR)
	JMP	CRPROS		/.WRITE (.REALW)
CRTMP1	0			/.WAIT-PROCESSED BY CAL
	JMP	CRIGNR		/.TRAN
/END OF FUNCTION DISPATCH TABLE
CRSC35	0			/STORAGE FOR .SCOM+35
CRTMP2=CRSC35
	CSTOPF		/FGRD STOP I/O SUBROUTINE
	CSTOPB		/BGRD STOP I/O SUBROUTINE
	1		/HANDLER CODE
/START OF LIVE DATA REGISTERS.
CFUNC2	XX			/JMP ENTRY IN FUNCTION TABLE.
CMODE2	XX			/0=FGRD, 1=BGRD
	XX
	XX
CDATA2	XX			/DATA MODE
CLBUF2	XX			/LINE BUFFER ADDRESS.
CWCNT2	XX			/LINE BUFFER WORD COUNT.
CREAL2	XX			/0=NOT REAL, PRIORITY/SUBR=REAL
/.INIT PROCESSOR
CRINIT	LAC	(377		/RETURN 255 (10)
	DAC*	CWCNT2		/TO .INIT REGISTER.
/SUBROUTINE TO CLEAR APPROPRIATE BUSY FLAG
/AS A FUNCTION OF THE CONTENTS OF
/CMODE2 (0=FGRD, 1=BGRD)
CRIGNR	LAC	CMODE2		/0-FGRD, 1=BGRD
	TAD	(COA.+1
	DAC	CRTMP1		/ADDRESS OF F OR B BUSY REG.
	DZM*	CRTMP1		/CLEAR BUSY FLAG.
	JMS	CRCHNG		/SWAP BACKUP AND LIVE REGS.
	JMP*	CROUT
/
/.READ(.REALR) AND .WRITE(.REALW) PROCESSOR
/
CRPROS	LAC	CMODE2		/0=FGRD, 1=BGRD
	XOR	(1		/COMPLEMENT IN ORDER
	TAD	(COA.+1		/TO CHECK OTHER
	DAC	CRTMP1		/BUSY FLAG FOR
	LAC*	CRTMP1		/COMPLEMENTING I/O
	SNA
	JMP*	CROUT		/NO COMPLEMENTING I/O YET.
	LAC	CFUNC1
	SAD	CFUNC2
	JMP	CRNOT		/BOTH READS OR BOTH WRITES
	LAC	CDATA1		/COMPLEMENTING I/O
	SAD	CDATA2
	SKP
	JMP	CRNOT		/NOT SAME DATA MODE
	LAC	(JMP CRIN		/.READ(.REALR)
	SAD	CFUNC1
	JMP	CRBK2
CRBK1	LAC*	CLBUF1		/OUTPUT IN BACKUP.
	DAC*	CLBUF2		/INPUT IN FLIVE.
	ISZ	CLBUF1
	ISZ	CLBUF2
	ISZ	CWCNT2		/USE INPUT COUNTER.
	JMP	CRBK1
	JMP	CRDONE
CRBK2	LAC*	CLBUF2		/OUTPUT IN LIVE.
	DAC*	CLBUF1		/INPUT IN BACKUP.
	ISZ	CLBUF1
	ISZ	CLBUF2
	ISZ	CWCNT1		/USE INPUT COUNTER.
	JMP	CRBK2
CRDONE	DZM	COA.+1		/CLEAR FGRD AND
	DZM	COA.+2		/BGRD BUSY REGS.
/IS THIS DEVICE INVOLVED IN I/O BUSY SITUATION.
	LAC*	(.SCOM+52		/ADDRESS OF I/O
	DAC	CRTMP1		/BUSY TESTER.
	LAC	(400200		/PROTECT CALL.
	ISA
	IOF
	LAC	(COA.
	JMS*	CRTMP1
	DBK			/FROM LEVEL 0
	ION
CRREAL	LAC	CREAL1
	SZA
	JMS	CRNXTQ		/REAL TIME REQUEST
	LAC	CREAL2
	SZA
	JMS	CRNXTQ		/REAL TIME REQUEST
	JMP*	CROUT
/BACKGROUND REQUEST IGNORED BECAUSE IT DOES
/NOT COMPLEMENT FOREGROUND REQUEST.
CRNOT	LAC	CMODE2
	SZA
	JMS	CRCHNG		/PUT FGRD IN LIVE REGS.
	DZM	COA.+2		/CLEAR BGRD BUSY FLAG.
	JMP*	CROUT
/THIS SUBROUTINE IS EXECUTED (XCT) BY THE
/CAL HANDLER VIA WORD0 OF THIS HANDLER
/JUST PRIOR TO GIVING CONTROL TO THE
/HANDLER AT THE APPROPRIATE ENTRY IN
/THE FUNCTION DISPATCH TABLE.
CRSWAP	0
	XCT	CRWD5		/CORRECT PROGRAM INTERRUPT.
	DBK			/FROM LEVEL 0
	JMS	CRCHNG		/SWAP BACKUP AND LIVE REGS.
	JMP*	CRSWAP
/SWAP BACKUP AND LIVE DATA REGISTERS.
CRCHNG	0
	LAW	-10
	DAC	CRCNT		/COUNTER SET TO 8(10).
	LAC	(CFUNC1		/START OF BACKUP REGS.
	DAC	CRTMP1
	LAC	(CFUNC2		/START OF LIVE REGS.
	DAC	CRTMP2
CRBACK	LAC*	CRTMP1		/BACKUP TO
	DAC	CRTMP3		/TEMPORARY.
	LAC*	CRTMP2		/LIVE TO
	DAC*	CRTMP1		/BACKUP.
	LAC	CRTMP3		/TEMPORARY TO
	DAC*	CRTMP2		/LIVE.
	ISZ	CRTMP1		/INDEX
	ISZ	CRTMP2		/POINTERS.
	ISZ	CRCNT		/CHECK COUNT.
	JMP	CRBACK		/MORE TO MOVE.
	JMP*	CRCHNG		/ALL DONE.
/SUBROUTINE TO PLACE CONTENTS OF
/AC IN REAL TIME QUEUING SCHEME.
CRNXTQ	0
CRTMP3=CRNXTQ
	DAC	CRTMP1		/SAVE AC.
	LAC*	(.SCOM+51		/REALTP
	DAC	CRTMP2
	LAC	(400200		/RAISE TO API
	ISA			/LEVEL 0
	IOF			/TURN PIC OFF.
	LAC	CRTMP1		/RESTORE AC
	JMS*	CRTMP2		/CALL REAL TIME PROCESSOR
	DBK			/DEBREAK FROM LEVEL 0
	ION			/TURN ON PIC
	JMP*	CRNXTQ
/STOP FGRD I/O SUBROUTINE.
CSTOPF	0
	DZM	COA.+1		/CLEAR FGRD BUSY FLAG.
	JMP*	CSTOPF
/
/
/STOP BGRD I/O SUBROUTINE.
CSTOPB	0
	DZM	COA.+2		/CLEAR BGRD BUSY FLAG.
	JMP*	CSTOPB
	.END
