Google
 

Trailing-Edge - PDP-10 Archives - BB-Y393K-SM - monitor-sources/dtesrv.mac
There are 49 other files named dtesrv.mac in the archive. Click here to see a list.
; UPD ID= 47, FARK:<4-1-WORKING-SOURCES.MONITOR>DTESRV.MAC.2,   3-Apr-82 18:59:40 by ZIMA
;Edit 2607 - add ENDAV.s to ACVARs to use v5 MACSYM, change some to SAVEAC.
;<4-1-FIELD-IMAGE.MONITOR>DTESRV.MAC.3, 25-Feb-82 20:20:10, EDIT BY DONAHUE
;UPDATE COPYRIGHT DATE
; UPD ID= 721, FARK:<4-WORKING-SOURCES.MONITOR>DTESRV.MAC.3,  19-Aug-81 10:36:55 by ZIMA
;Edit 1925 - put edit 1830 in standard form.  No code changes.
; UPD ID= 387, FARK:<4-WORKING-SOURCES.MONITOR>DTESRV.MAC.2,   3-Feb-81 16:10:51 by DEUFEL
;Edit 1830 - Prevent RESBAZ BUGCHKs when running DECnet-20 on KL10's
; UPD ID= 190, FARK:<4-WORKING-SOURCES.MONITOR>DTESRV.MAC.3,   4-Sep-80 13:13:16 by ZIMA
;Edit 1780 - prevent possible J0NRUN from fork zero blocking in ASGNOD.
; UPD ID= 73, FARK:<4-WORKING-SOURCES.MONITOR>DTESRV.MAC.2,  11-Jun-80 14:12:12 by ZIMA
;EDIT 1739 - Fix BOOT JSYS to not return zero error code
;<4.MONITOR>DTESRV.MAC.58,  3-Jan-80 08:08:37, EDIT BY R.ACE
;UPDATE COPYRIGHT DATE
;<4.MONITOR>DTESRV.MAC.57, 31-Oct-79 15:55:26, EDIT BY MILLER
;ADD DTEFLA. FLUSH ALL REQUESTS FOR A LINE
;<4.MONITOR>DTESRV.MAC.56, 31-Oct-79 15:23:21, EDIT BY MILLER
;FLUSH DTEQS IN SCHEDULER WHENEVER DTRLD IS SET OR DETECTED ON
;<4.MONITOR>DTESRV.MAC.55, 26-Sep-79 16:13:49, EDIT BY HALL
;LODSEC IN BOOT JSYS - CALL BLTUM1 INSTEAD OF BLTUM FOR EXTENDED
;ADDRESSING
;<4.MONITOR>DTESRV.MAC.54, 26-Sep-79 15:57:14, EDIT BY MILLER
;AVOID AWAKING JOB 0 AT TKACK2 IF DBUGSW IS 2
;<4.MONITOR>DTESRV.MAC.53, 20-Sep-79 12:29:31, EDIT BY MILLER
;ADD RLDFRK
;<4.MONITOR>DTESRV.MAC.52, 20-Sep-79 11:51:10, EDIT BY MILLER
;FIX DNSNGL
;<4.MONITOR>DTESRV.MAC.51, 19-Sep-79 17:05:08, EDIT BY MILLER
;<4.MONITOR>DTESRV.MAC.50, 19-Sep-79 11:25:59, EDIT BY MILLER
;CHECK FOR SINGLE CHAR PACKET IN CLRDTE
;<4.MONITOR>DTESRV.MAC.49, 19-Sep-79 10:43:35, EDIT BY MILLER
;ONE MORE TRY. CLEAR DTERL FIRST
;<4.MONITOR>DTESRV.MAC.48, 14-Sep-79 12:36:12, EDIT BY MILLER
;TCO 4.2467. FIX -11 RELOAD
;<OSMAN.MON>DTESRV.MAC.1, 10-Sep-79 15:27:43, EDIT BY OSMAN
;TCO 4.2412 - Move definition of BUGHLTs, BUGCHKs, and BUGINFs to BUGS.MAC
;<4.MONITOR>DTESRV.MAC.46, 30-Aug-79 19:49:02, EDIT BY MILLER
;FIX CODE AT DTPOL3 TO CALL DOFRGM WITH CORRECT ARGS
;<4.MONITOR>DTESRV.MAC.45,  3-Aug-79 14:32:03, EDIT BY ENGEL
;AVOID NOSKED PAGE FAULT AT PROINI
;<4.MONITOR>DTESRV.MAC.44, 11-Jun-79 17:32:50, Edit by KONEN
;REMOVE CALL TO KILPAG IN UNLPAG
;<4.MONITOR>DTESRV.MAC.43,  9-Jun-79 14:03:59, EDIT BY MILLER
;<4.MONITOR>DTESRV.MAC.42,  9-Jun-79 14:03:07, EDIT BY MILLER
;REPLACE MOST BUGHLTS WITH FE RELOADS.
;<4.MONITOR>DTESRV.MAC.41, 26-May-79 14:05:09, EDIT BY MILLER
;FIX ILULK2 BUGHLTS
;<4.MONITOR>DTESRV.MAC.40, 16-May-79 15:24:47, EDIT BY MILLER
;FIX DTEINA TO NOT WAIT FOREVER FOR TO -11 I/O COMPLETION
;<4.MONITOR>DTESRV.MAC.39, 20-Apr-79 10:23:44, EDIT BY KIRSCHEN
;SAVE ERROR CODE WHEN BOOT FUNCTION FAILS
;<4.MONITOR>DTESRV.MAC.38,  4-Apr-79 14:39:28, EDIT BY MILLER
;<4.MONITOR>DTESRV.MAC.37,  4-Apr-79 13:57:33, EDIT BY MILLER
;ZERO DTEEBP AND DTETBP AT DTREST
;<4.MONITOR>DTESRV.MAC.36, 26-Mar-79 10:09:24, EDIT BY MILLER
;<4.MONITOR>DTESRV.MAC.35, 23-Mar-79 09:28:19, EDIT BY MILLER
;PUT BACK TEST. BLOCK PROCESS IF CALL IS FOR MASTER DTE
;<4.MONITOR>DTESRV.MAC.34, 22-Mar-79 21:12:21, Edit by MCLEAN
;REMOVE JN DTERLD IN DTEQ12 SO WE DON'T LOOSE THINGS DURING RELOAD
;<4.MONITOR>DTESRV.MAC.33,  7-Mar-79 14:46:23, Edit by MCLEAN
;ADD A SETZM  DTECMD TO RELOAD TO PREVENT ILQ FRONT-END HALTS
;<4.MONITOR>DTESRV.MAC.32,  4-Mar-79 15:32:17, EDIT BY KONEN
;UPDATE COPYRIGHT FOR RELEASE 4
;<4.MONITOR>DTESRV.MAC.31,  4-Mar-79 14:44:33, EDIT BY MILLER
;ADD CODE TO CHECK FOR TO -10 TRANSFER TOO LONG
;<4.MONITOR>DTESRV.MAC.30, 14-Feb-79 16:56:07, EDIT BY MILLER
;<4.MONITOR>DTESRV.MAC.29, 14-Feb-79 16:46:35, EDIT BY MILLER
;SWITCH MEANINGS OF CMPCT AND CMQCT FOR MCB PROTOCOL
;<4.MONITOR>DTESRV.MAC.28,  7-Feb-79 15:42:07, EDIT BY KIRSCHEN
;FIX COMMENT ON DOFRGM
;<4.MONITOR>DTESRV.MAC.27,  1-Feb-79 17:05:35, EDIT BY KIRSCHEN
;DO NOT CLEAR -TO11 BYTE POINTER IN KILPAG; ALREADY CLEARED IN RMGRNK
;<4.MONITOR>DTESRV.MAC.26,  1-Feb-79 16:04:50, EDIT BY MILLER
;ADD DTE NUMBER TO ALL BUGCHK AND BUGINF MESSAGES
;<4.MONITOR>DTESRV.MAC.25, 30-Jan-79 13:47:43, EDIT BY KIRSCHEN
;CLEAR TO-11 BYTE POINTER IN EPT WHEN UNMAPPING DTERBT PAGE
;<4.MONITOR>DTESRV.MAC.24, 30-Jan-79 12:06:00, EDIT BY MILLER
;DON'T CHECK DTERL BIT IN DTEIOP
;<4.MONITOR>DTESRV.MAC.23, 14-Jan-79 15:08:09, Edit by MCLEAN
;REMOVE TTMVSP
;<4.MONITOR>DTESRV.MAC.21, 12-Jan-79 21:06:13, EDIT BY KIRSCHEN
;CHANGE SETZM T4, TO SETZ T4, IN BTCPN
;<4.MONITOR>DTESRV.MAC.20, 21-Dec-78 17:06:15, EDIT BY MILLER
;FIX BOOTTB FOR ILLEGAL FUNCTION TRANSFERS
;<4.MONITOR>DTESRV.MAC.19, 18-Dec-78 16:20:23, EDIT BY ENGEL
;FIX BAD PLACEMENT OF .BTCLI CHECK
;<4.MONITOR>DTESRV.MAC.18, 15-Dec-78 16:29:45, EDIT BY ENGEL
;FIX DTE CHECKING FOR .BTCLI (NOT WANTED)
;<4.MONITOR>DTESRV.MAC.17, 15-Nov-78 20:16:24, EDIT BY MILLER
;CHNAGE RMGRNK TO CLEAR BYTE COUNT REG AND TO -10 POINTER
;<4.MONITOR>DTESRV.MAC.16, 11-Nov-78 18:43:35, Edit by MCLEAN
;<4.MONITOR>DTESRV.MAC.15, 11-Nov-78 18:34:24, Edit by MCLEAN
;MAKE DTEFLO CHECK FOR INTERRUPT ADDRESS INSTEAD OF CODE
;THIS WILL HELP PREVENT MONPDL'S AND PERMIT XON/XOFF TO PASS
;<4.MONITOR>DTESRV.MAC.14,  6-Nov-78 16:29:13, EDIT BY ENGEL
;ADD RETSKP TO BTCPN
;<4.MONITOR>DTESRV.MAC.13,  6-Nov-78 14:27:05, EDIT BY ENGEL
;CHANGE COMPARE IN BTCLI
;<4.MONITOR>DTESRV.MAC.12,  6-Nov-78 11:03:42, EDIT BY ENGEL
;DON'T CHECK FOR NULL IN .BTCLI
;<4.MONITOR>DTESRV.MAC.11, 27-Oct-78 17:45:19, EDIT BY HALL
;FIX THE CHECKS ON Q2 AGAINST DTEN - WENT THE WRONG WAY
;<4.MONITOR>DTESRV.MAC.10, 27-Oct-78 10:10:38, EDIT BY ENGEL
;ADD .BTCLI AND .BTCPN
;<4.MONITOR>DTESRV.MAC.9, 18-Oct-78 14:43:36, EDIT BY KIRSCHEN
;REMOVE .BTLST
;<4.MONITOR>DTESRV.MAC.8, 13-Oct-78 09:07:34, EDIT BY KIRSCHEN
;FIX BOOT JSYS DISPATCH TABLE
;<4.MONITOR>DTESRV.MAC.7,  6-Oct-78 15:01:33, EDIT BY KIRSCHEN
;ADD BTLST FUNCTION TO BOOT JSYS
;<4.MONITOR>DTESRV.MAC.6, 16-Aug-78 11:19:42, EDIT BY MILLER
;FIX PROTOCOL PAUSE ROUTINES NOT TO GET CONFUSED IF IN SECONDARY PROTOCOL
;<4.MONITOR>DTESRV.MAC.5, 27-Jul-78 17:40:48, EDIT BY MILLER
;FIX RELOAD TO TRY MASTER FE AT LEAST 3 TIMES
;<4.MONITOR>DTESRV.MAC.4, 18-Jul-78 08:46:20, EDIT BY MILLER
;MORE OF "CONTINUED" CHANGES
;<4.MONITOR>DTESRV.MAC.3, 17-Jul-78 08:55:20, EDIT BY MILLER
;SUPPRESS "CONTINUED" MESSAGE ON PROTOCOL PAUSE
;<4.MONITOR>DTESRV.MAC.2, 14-Jul-78 13:59:58, EDIT BY MILLER
;MORE FIXES FOR RELAODING A DTE. FIX DTE SCHEDULER SO IT CAN RUN IN SECTION 1


;THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED
;  OR COPIED IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE.
;
;COPYRIGHT (C) 1976,1977,1978,1979,1980,1981,1982 BY DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.

	SEARCH PROLOG,SERCOD
	TTITLE DTESRV

   IFN KLFLG,<
	SEARCH PROKL>
	RESCD
MAXSGL==6
SNGHDR==3
SNGONQ==1B2
SNGAVL==1B3
SNGACT==1B4


;LOCAL DEFINITIONS FOR RELOAD WAITS

PWRDN1==^D1150			;-11 MUST COMPLETE POWER DOWN IN THIS TIME
ROMTIM==^D2000			;ROM MUST ACK -10 IN THIS TIME
BUTTIM==^D5000			;-11 BOOTSTRAP TRANSFER TIME
DRBTIM==^D60000			;-11 RELOAD TIME
T10TIM==^D3000			;MAX TIME FOR 1K OF -11 CORE TO BE
				; TRANSFERRED TO THE -10
MONPRO==^D5000			;MUST ENTER MONITOR PROTOCOL IN THIS TIME
PRIPRO==^D10000			;MUST ENTER PRIMARY IN THIS TIME
MCINI0==^D1500			;TIME FOR MCB TO INIT COMM REGIONS
MCINI1==^D500			;TIME TO COMPLETE PROTOCOL TRANSITION

;EXTERNAL DEFINITIONS DEFINED IN STORAGE

	EXTN <TAD11,TO11TM,DTETIM>	;WORDS TO TRANSMIT TIME
	EXTN <DLSRCF,DLSCXF,CARONB> ;TTYSRV DEFINITIONS
	EXTN <TTYHGU,TTYDLU>		;MORE TTYSRV DEFS
	EXTN <IEXSIZ,CTYUNT,DTEDTE>
	EXTN <DTEQS,COMQ,COMH,DTESTS,DTEST1>
	EXTN <DTBFWD,DTETRA,DTEACB>
	EXTN <DTEIND,PKTADR,COMBUF>
	EXTN <DTESTK,BUFSIZ,NQPKT>
	EXTN <DTEN,COMSIZ>
	EXTN <DTETRP,TTYINT,SVDTRJ>
	EXTN <PKTSIZ,QPKT>
	EXTN <CNDO,DATO,BYTBUF>
	EXTN <DTESTO,KIEPT,TMZONE>
	EXTN <MAXDEV,MINDEV,DTEDTV>
	EXTN <INIDV1,MCPRON,RLDFRK>

	DTENL==^D256		;LINES PER DTE20
	SDTE==3			;SHIFT VALUE FOR DTE UNITS
	MAXINP==^D254		;MAX NUMBER OF BYTES IN AN INDIRECT
				; PACKET WHICH IS EVEN
	DSK11==1B28		;RP RELOAD DEVICE IN -11 ROM
;SPECIAL DEFINITIONS FOR SCHEDULER PRIORITY WORDS

BOTPRI==1			;SPECIAL PRIORITY WORD FOR BOOT JSYS INIT
RLDPRI==<XWD ^D80,1>		;SPECIAL MASTER -11 RELOAD PRIORITY
;DTE20 EPT DEFINITIONS

DTEEPW==:KIEPT+144		;EXAMINE PROTECTION WORD
DTEERW==KIEPT+145		;EXAMINE RELOCATION WORD
DTEDPW==KIEPT+146		;DEPOSIT PROTECTION WORD
DTEDRW==KIEPT+147		;DEPOSIT RELOCATION WORD
DTEINT==:KIEPT+142		;INTERRUPT LOCATION
DTEEBP==KIEPT+140		;TO -11 BYTE POINTER
DTETBP==KIEPT+141		;TO -10 BYTE POINTER
;DTE SERVICE ROUTINE. THIS CODE CONTAINS THE INITIALIZATION CODE,
;THE QUEUE HANDLING AND SCHEDULING CODE AND THE INTERRUPT HANDLER
;FOR THE DTE.

;LOCAL DEFINITIONS

PVERSN==1			;PROTOCOL VERSION NUMBER
CVERSN==2			;COMMUNICATIONS VERSION NUMBER
LDTEPI==DTEPI0+DLSCHN+DTEPIE	;TURN ON ALL PI'S
MAG11N==1365			;THE RELOAD INDICATOR FOR THE -11 ROM

;DEFINE LOCAL STORAGE

DEFSTR (QLINK,0,35,18)		;LINK TO NEXT PACKET
DEFSTR (QINT,0,17,18)		;INT LOC FOR THIS FUNCTION
DEFSTR (QFNC,1,17,18)		;FUNCTION WORD FOR THIS REQUEST
DEFSTR (QDEV,1,35,18)		;DTE DEVICE CODE FOR THIS REQUEST
DEFSTR (QNSPH,1,35,36)		;FULL WORD FOR NSP BYTE POINTER
DEFSTR (QLIN,2,17,18)		;DEVICE UNIT NUMBER
DEFSTR (QMODE,2,18,1)		;IF ONE, INDIRECT DATA MUST BE BYTE MODE
DEFSTR (QCNT,2,35,17)		;BYTE COUNT OR BYTE OR 0
DEFSTR (QPNTR,3,35,36)		;BYTE POINTER FOR INDIRECT OPERATION
				;OR LOCAL 8-BIT DATUM IF QCNT=0
DEFSTR (QCOD,4,35,36)		;UNIQUE CODE RETURNED TO INTERRUPT 
				; ROUTINE
;DTE STATUS DEFINITIONS IN DTESTS


DEFSTR (DTEST,DTESTS,35,6)	;DTE STATUS
	DTET10==1		;-10 IS RECIEVING LAST FRAGMENT OF A MESSAGE
	DTE11==2		;-11 IS RECEIVING BYTES
	DTE11I==4		;-11 IS RECEIVING AN INDIRECT QUEUE ENTRY
	DTET1F==10		;10 RECEIVING FIRST FRAFMENT OF
				; A MESSAGE
DEFSTR(DTERL,DTESTS,0,1)	;BIT TO SAY DTE IS RUNNING A PROTOCOL
DEFSTR(DTEBF,DTESTS,1,1)	;WHICH BUFFER IS IN USE FOR RSX20F
DEFSTR(DTEBC,DTESTS,29,12)	;BYTE COUNT REMAINING FOR SUBSEQUENT
DEFSTR (DTBLK,DTESTS,2,1)	;FOR MCB, TO -10 IS BLOCKED ON FREE
				; SPACE
DEFSTR(DTRLD,DTESTS,3,1)	;IF ONE, THIS -11 BEING RELOADED
DEFSTR (DTKAC,DTESTS,4,1)	;IF ONE, THIS -11 IS ILL
DEFSTR (DTSTI,DTESTS,5,1)	;STATUS PACKET IS SPLIT
DEFSTR(DTEB1,DTESTS,17,12)	;BYTE COUNT OF LAST TRANSFER

;PARALLEL STATUS TABLE CONTAINING CURRENT OPERATION DATA
DEFSTR(DT1FC,DTEST1,15,16)	;CURRENT FUNCTION CODE
DEFSTR(DT1DV,DTEST1,31,16)	;CURRENT DEVICE CODE
;
;SPECIAL REQUEST BITS FOR TO 11 CONDITIONS

DEFSTR(DT1TM,DTEST1,32,1)	;-11 WANTS TIME OF DAY
DEFSTR(DT1ID,DTEST1,33,1)	;WAITING FOR INDIRECT SETUP

;MORE STORAGE DEFINITIONS



;STORAGE FOR INDIRECT PACKETS
	DEFSTR (INUNT,DTEIND,7,8)
	DEFSTR (INCNT,DTEIND,15,8)
	DEFSTR (INVLD,DTEIND,16,1) ;SAYS IF UNIT FIELD IS VALID
;********* FOR MCB, DTEIND CONTAINS FREE SPACE BLOCK ********


;DEFINITIONS FOR DTE PACKETS

DEFSTR (HDCNT,0,15,16)		;COUNT
DEFSTR (HDFNC,0,31,16)		;FUNCTION
DEFSTR (HDDEV,1,15,16)		;DEVICE CODE
DEFSTR (HDSPR,1,31,16)		;SPARE
DEFSTR (HDLIN,2,7,8)		;LINE NUMBER
DEFSTR (HDDAT,2,15,8)		;DATUM
DEFSTR (HDDT1,2,15,16)		;DATUM FOR SINGLE DATUM PACKET
;DEFINE THE COMMUNICATIONS REGION


;FIELD DEFINITIONS FOR THE COMMUNCIATIONS REGION
;FIRST THE OWNED AREA

	DEFSTR (CMTEN,0,0,1)	;TEN INDICATOR IN HEADER
	DEFSTR (CMVER,0,3,3)	;VERSION NUMBER
	DEFSTR (CPVER,0,11,6)	;COMMUNCIATIONS PROTOCOL VERSION NUMBER
	DEFSTR (CMNPR,0,16,5)	;NUMBER OF PROCESSORS HERE
	DEFSTR (CMSIZ,0,19,3)	;SIZE IN MULTIPLES OF 8 WORDS
	DEFSTR (CMNAM,0,35,16)	;PROCESSOR NAME
	DEFSTR (CMLNK,1,35,36)	;POINTER TO NEXT PROCESSOR
	DEFSTR (CMKAC,KPALIV,35,36) ;PROCESSOR KEEP ALIVE COUNTER
		CMPCW==6	;PC WORD
		CMPIWD==7	;CONI PI, WORD
		CMPGWD==10	;CONI PAG, WORD
		CMPDWD==11	;DATI PAG, WORD
		CMAPRW==12	;CONI APR, WORD
		CMDAPR==13	;DATI APR, WORD

;NOW THE "TO" AREA
	DEFSTR (CMPRO,0,0,1)	;1 IF THIS IS CONNECTION TO A -10
	DEFSTR (CMDTE,0,1,1)	;I IF A DTE IS CONNECTING THESE TWO
	DEFSTR (CMDTN,0,3,2)	;DTE NUMBER
	DEFSTR (CMSZ,0,19,3)	;SIZE OF BLOCK/8
	DEFSTR (CMVRR,0,16,5)	;PROTOCOL IN USE BY THE TWO PROCESSORS
	DEFSTR (CMPNM,0,35,16)	;PROCESSOR NUMBER
	DEFSTR (CMPPT,1,35,36)	;POINTER TO ASSOCIATE PROCESSOR
	DEFSTR (CMPWF,2,0,1)	;POWER FAIL INDICATOR
	DEFSTR (CML11,2,1,1)	;LOAD-11 INDICATOR
	DEFSTR (CMINI,2,2,1)	;INI BIT FOR MCB PROTOCOL ONLY
	DEFSTR (CMTST,2,3,1)	;VALID EXAMINE BIT
	DEFSTR (CMQP,2,13,1)	;1 IF USING QUEUED PROTOCOL
	DEFSTR (CMFWD,2,17,1)	;SAYS TO DO FULL WORD TRANSFER
	MSKSTR (CMIP,2,400000)	;INDIRECT POINTER IS SET UP
	MSKSTR (CMTOT,2,200000) ;TOIT BIT
	DEFSTR (CM0IC,2,27,8)	;TO10IC FOR QUEUE TRANSFERS
	DEFSTR (CM1IC,2,35,8)	;TO11IC FOR QUEUE TRANSFERS
	DEFSTR (CMQCT,3,35,16)	;COUNT OF WORDS IN CURRENT QUEUE

;DEFINITIONS FOR PROTOCOL VERSION .VNMCB ONLY

	DEFSTR (CMPCT,3,19,16)	;COUNT OF ALL PIECES (OR QUEUES)
	DEFSTR (CMTMD,3,3,4)	;MODE OF THE TRANSFER
	DEFSTR (CMTBP,4,35,36)	;TO -10 POINTER AT END OF TRANSFER

;COMMON DEFINITIONS

	DEFSTR (CMRLF,4,35,36)	;RELOAD PARAMETER FOR THIS -11
	DEFSTR (CMKAK,5,35,36)	;MY COPY OF HIS CMKAC
	CMCLR1==2		;FIRST DYNAMIC WORD TO CLEAR
	CMCLR2==3		;OTHER WORD TO CLEAR
;FUNCTION TRANSFER VECTOR FOR RSX20F PROTOCOL (.VN20F) ONLY

FNCTBL:	TAKCTY			;FE TELLING ABOUT THE CTY
	400000,,TAKDS		;STRING DATA (FOR CDR)
	TAKLC			;LINE CHARACTERS (FOR DLS)
	NOOP			;NOT YET IMPLEMENTED
	NOOP			;NOT YET IMPLEMENTED
	400000,,TAKSTD		;-11 SENDING ERROR INFORMATION
	NOOP			;UNSUPPORTED
	SNDTOD			;-11 WANTS TIME OF DAY
	400000,,TAKTOD		;-11 IS SENDING TIME OF DAY
	NOOP			;FLUSH OUTPUT NOT SUPPORTED
	NOOP			;SEND ALL NOT SUPPORTED
	DIALUP			;A LINE DIALED UP
	HANGUP			;A LINE HUNG UP
	EMPTY			;LINE BUFFER EMPTY
	NOOP			;XOFF
	NOOP			;XON
	400000,,TAKSPD		;SET LINE SPEED
	LINEAL			;SET LINE ALLOCATION
	TAKRLW			;TAKE -11 RELOAD INFORMATION
	TAKACK			;ACK ALL DEVICES AND UNITS
	NOOP			;TURN ON/OFF LINES
	NOOP			;ENABLE/DISABLE DATASETS
	NOOP			;LOAD TRANSLATION RAM
	NOOP			;LOAD VFU
	NOOP			;SUPPRESS SYSTEM MESSAGES
	400000,,TAKKLI		;TAKE KLINIK DATA
MINFNC==2			;FIRST IMPLEMENTED FUNCTION
MAXFNC==.-FNCTBL+MINFNC-1	;MAX FUNCTION NUMBER

;DEFINITIONS FOR NSP HEADER PACKET USING MCB PROTOCOL

NSPDN==177777B23		;POSITION OF DEST NODE ADDRESS
NSPMF==377B15			;POSIITON OF MESSAGE FLAGS (WORD 1)
NSPRF==377B7			;POSITION OF ROUTING FLAGS
NSPS0==377B31			;POSITION OF FIRST BYTE OF SOURCE NODE
NSPS1==377B7			;POSITION OF SECOND BYTE OF SOURCE NODE
				; (WORD 1)

;COMM REGION MODE TYPES FOR MCB BYTE TRANSFERS

.TMBYT==0			;BYTE MODE TRANSFERS
.TMWRD==2			;WORD MODE TRANSFERS
.TMBWD==1			;BYTES IN WORD MODE TRNASFERS
;THIS IS THE DTE INITIALIZATION CODE. IT SETS  UP THE 
;COMMUNICATIONS AREA FOR THE MASTER DTE ONLY (WHICH RUNS .VN20F PROTOCOL)

	SWAPCD			;IS CALLED FROM JOB 0
PROINI::SETOM BTLOCK		;INITIALIZE BOOT PAGE LOCK
	SETOM RLDFRK		;INIT REOAD FORK I.D.
	MOVEI A,^D5000		;MAKE 5 SEC CHECK
	MOVEM A,DTETIM		;TO THE TIMER
	SETZM CTYUNT		;****TEMP VALUE FOR CTY
	SETZM TO11TM		;FREE UP TIME PACKET
	MOVE A,[DTEEPW,,DTEEPW+1] ;AVOID NOSKED PAGE FAULT
	NOSKED			;NO SCHEDULING
	CHNOFF DLSCHN		;TURN OFF THE DTE CHANNEL
	BLT A,DTEDRW+<DTEN-1>*10 ;CLEAR ENTIRE REGION IN THE EPT
STBUF1:	SETZ A,			;FIRST COMMUNICATIONS REGION
	MOVEI B,DTEN		;NUMBER TO DO
STOBUF:	MOVEM A,COMBUF(B)	;STORE THIS GUY
	ADD A,[1B11+COMSIZ]	;NEXT REGION
	CAIN B,DTEN		;IS THIS THE -10'S REGION?
	ADDI A,COMRGN*<DTEN-1>	;YES. ADD IN SPACE FOR ALL OF THE -11'S
	SOJGE B,STOBUF		;DO ALL OF REGION
	SETZM COMBAS		;SET UP TO CLEAR ENTIRE COM AREA
	MOVSI A,COMBAS		;FIRST WORD
	HRRI A,COMBUF+DTEN+2	;FIRST WORD BEYOND THAT
	BLT A,COMBUF+DTEN+IEXSIZ ;CLEAR ENTIRE COMM REGION

;NOW CREATE THE REQUEST QUEUE

	MOVSI A,1-NQPKT		;NUMBER OF LINKS TO MAKE
DOQLNK:	MOVEI B,QPKT+COMQ(A)	;THE NEXT PACKET
	MOVEM B,COMQ(A)		;MAKE A LINK
	ADDI A,QPKT-1		;TO MAKE THE AOBJN WORK
	AOBJN A,DOQLNK		;DO ALL PACKETS
	MOVEI A,COMQ		;THE FIRST PACKET
	MOVEM A,COMH		;MAKE THE HEADER POINT TO THE FIRST
	; ..
;DTEINI...

; INIT QUEUE HEADERS

	MOVSI A,-DTEN		;NUMBER TO DO
BUFFLP:	SETZM DTEQS(A)		;INIT SCHEDULER QUEUE
	AOBJN A,BUFFLP		;DO ALL DTE'S
	MOVE A,MSTRDT		;GET NUMBER OF MASTER DTE
	MOVEI B,.VN20F		;INIT IT TO RSX20F PROTOCOL
	CALL DTINIT		;DO IT
	CHNON DLSCHN		;TURN ON DTE CHANNEL
	OKSKED			;AND ALLOW SCHEDULING AGAIN
	CALL DFNDL1		;GO FIX UP SPECIAL LINES ON THE FE
	CALLRET INIDV1		;AND GO DO THE FRONT END DEVICES

;ROUTINE TO DO POWER FAIL INIT FOR EACH OF THE DTE'S.

	RESCD			;MUST BE RESIDENT SO RESTART WORKS

STODT2:	SAVEP			;SAVE PERMANENT REGISTERS
	MOVSI P1,-DTEN		;NUMBER OF DTE'S
STODTE:	JE DTERL,(P1),NODTEH	;RUNNING?
	MOVEI A,0(P1)		;YES. GET DTE NUMBER
	CALL DTINTP		;GO DO POWER FAIL RECOVERY
NODTEH:	AOBJN P1,STODTE		;GO DO ALL OF THEM
	CHNON DLSCHN		;ALLOW INTS NOW
	OKSKD1			;TURN ON SCHEDULING IF NECESSARY
	RET			;AND DONE

;CODE TO RESTART THE DTE'S ONE SYSTEM RESTART.
;CALLED FROM SYSRST

DTERST::NOSKD1			;NO SCHEDULING PLEASE
	CHNOFF DLSCHN		;AND NO DTE INTS
	CALLRET STODT2		;GO DO THE WORK

;ROUTINE TO CHECK IF A GIVEN DTE IS RUNNING A PROTOCOL
;	A/ DTE NUMBER
;RETURNS:
;	+1 /NOT RUNNING A PROTOCOL
;	+2/RUNNING A PROTOCOL
	SWAPCD			;IS SWAPPABLE

CHKDTE::CAIL A,DTEN		;AN EXTANT DTE?
	RETBAD			;NO
	JE DTERL,(A),R		;IF NOT RUNNING A PROTOCOL FAIL
	RETSKP			;SUCCESS
;ROUTINES TO INIT INDIVIDUAL DTE DATA BASES. CALLED FROM DTEINI
;AS WELL AS FROM THE REBOOT CODE
;MAY RUN WITH INTS AND SCHEDULING ENABLED
;ACCEPTS	A/ DTE NUMBER
;		B/ PROTOCOL VERSION TO INIT IF ENTRY IS AT DTINIT
;IF ENTRY IS AT DTINTP, PROTOCOL WILL BE INITED TO PREVAILING TYPE
;ACCEPTS:	A/ DTE #
;		B/ PROTOCOL VERSION NUMBER FOR DTINIT ONLY
;DTINTP WILL INIT DTE TO THE PROTOCOL IN EFFECT BEFORE THE POWER FAIL

	RESCD			;MUST BE RESIDENT FOR RESTART

DTINTP:	SETO B,			;REMEMBER POWER RESTART ENTRY
DTINIT:	STKVAR <DTNUMB,PROVER>	;TO SAVE DTE NUMBER
	HRRZS A			;GET DTE NUMBER ONLY
	MOVEM B,PROVER		;SAVE PROTOCOL VERSION NUMBER
	SETZM DTESTS(A)		;CLEAR STATUS WORD
	SETZM DTEST1(A)		;AND THE OTHER ONE
	CALL DTREST		;GO RESET THIS DTE
	SKIPGE PROVER		;POWER RESTART ENTRY?
	JRST DTINP1		;YES.
	SETONE DT1TM,(A)	;NO. SAY HE NEEDS TIME THEN
DTINP1:	LSH A,SDTE		;TO FIND THE EPT REGION
	SETZM DTEEPW(A)		;FORCE SECONDARY PROTOCOL
	LSH A,-SDTE		;RESTORE A
	CALL SETRGN		;GO FIND THE REGIONS
	SUBI D,COMDAT		;POINT TO FIXED PART OF -11'S REGION
	MOVEI C,COMBAS		;GET -10'S FIXED REGION
	EXCH D,C		;REVERSE MEANINGS OF REGISTERS
	CAME A,MSTRDT		;IS THIS THE MASTER?
	JRST [	CALL DING11	;NO. JUST RING BELL
		JRST DTINI1]	;AND PROCEED WITH INIT
	SETZM DTEFLG		;CLEAR FLAG WORD
	MOVEI B,DTEEMP		;ENTER SECONDARY COMMAND
	MOVEM B,DTECMD		;TO THE COMMAND WORD
	CALL DING11		;GO DING HIM
	MOVEI B,MONPRO		;TIME TO ENTER PROTOCOL
	CALL NEWTIM		;GET TIME IN FUTURE
DTINI2:	SKIPN DTEFLG		;GOT IT YET?
	JRST [	CALL CHKTIM	;IS TIME UP YET?
		JRST DTINI2	;NO. GO WAIT SOME MORE
		SETONE DTRLD,(A) ;YES. HE DIDN'T MAKE IT
		AOS LOAD11	;JUST IN CASE
		RET]		;AND DONE
DTINI1:	MOVEM A,DTNUMB		;SAVE DTE NUMBER
	MOVEI A,1		;TENIND
	STOR A,CMTEN,(D)	;SAY FIRST BLOCK IS FOR A TEN
	SETZRO CMTEN,(C)	;HE IS NOT
	MOVEI A,CVERSN		;CURRENT COMMUNICATIONS VERSION
	STOR A,CMVER,(D)	;STORE IT
	STOR A,CMVER,(C)	;FOR THE -11 ALSO
	MOVEI A,PVERSN		;PROTOCOL VERSION
	STOR A,CPVER,(C)
	STOR A,CPVER,(D)	;STORE THIS AS WELL
	MOVEI A,2		;EACH -11 ADDRESSES TWO PROCESSORS
	STOR A,CMNPR,(C)
	MOVEI A,DTEN+1		;NUMBER OF PROCESSORS
	STOR A,CMNPR,(D)	;STORE THESE
	SKIPGE B,PROVER		;DOING INIT?
	JRST DTINI7		;NO.
	MOVEI A,COMSIZ/COMRGN	;INTEGRAL SIZE OF A REGION
	CAIE B,.VN20F		;RSX20F PROTOCOL?
	MOVEI A,2		;NO. MCB HEADER IS ALWAYS 2
	STOR A,CMSIZ,(C)
	MOVEI A,2		;HEADER IN 10'S AREA IS 2
	STOR A,CMSIZ,(D)	;REMEMBER THE SIZE
DTINI7:	MOVE A,DTNUMB		;GET DTE NUMBER
	AOS A			;GET OFFSET INDEX
	STOR A,CMNAM,(C)	;HIS NUMBER
	SETZRO CMNAM,(D)	;MY NUMBER IS ZERO
	MOVEI B,COMBAS		;FIRST REGION
DTINI3:	JE CMLNK,(B),[	SETZRO CMLNK,(C)
			SUBI C,COMBAS ;OFFSET FOR -11
			STOR C,CMLNK,(B) ;LINK IT IN TO ACTIVE LIST
			JRST DTINI4] ;AND DONE
	LOAD B,CMLNK,(B)	;GET THE LINK
	ADDI B,COMBAS		;MAKE IT ABSOLUTE
	CAME B,C		;IS THIS THE ONE WE WANT?
	JRST DTINI3		;NO, GO CHECK IT
	; ..
;DTINIT ...

;NOW INIT THE PER PROCESSOR REGION OF EACH COM REGION

DTINI4:	MOVE A,DTNUMB
	CALL SETRGN		;GO FIND REGIONS AGAIN
	EXCH C,D		;REVERSE REGS AGAIN
	SETZM CMCLR1(C)
	SETZM CMCLR2(C)		;CLEAR DYNAMIC WORDS IN -11'S REGION
	SETZM CMCLR1(D)
	SETZM CMCLR2(D)		;CLEAR TEN DYNAMIC WORDS
	MOVEI A,1		;TENIND WORD
	STOR A,CMPRO,(C)	;TELL -11 HE IS CONNECTED TO A -10
	STOR A,CMDTE,(C)
	STOR A,CMDTE,(D)	;A DTE CONNECTS THESE TWO
	STOR A,CMTST,(D)	;SET VALID EXAMINE
	STOR A,CMSZ,(C)
	STOR A,CMSZ,(D)		;TO THE REGIONS
	MOVE A,DTNUMB		;GET DTE NUMBER
	STOR A,CMDTN,(C)	;TO HIS REGION
	STOR A,CMDTN,(D)	;AND TO MINE
	AOS A			;INDEX
	STOR A,CMPNM,(D)	;HIS NAME
	SETZRO CMPNM,(C)	;AND MY NAME IN HIS REGION
	SETZRO CMPPT,(C)	;HIS POINTER TO ME
	SUBI C,COMBAS+COMDAT	;HIS RELATIVE OFFSET IN COMM REGION
	STOR C,CMPPT,(D)	;MAKE MY REGION POINT TO HIM
	ADDI C,COMBAS+COMDAT	;RESTORE POINTER
	SKIPGE B,PROVER		;NEED TO DO MORE INITING?
	JRST DTINI5		;NO. ALL DONE FOR NOW
	STOR B,CMVRR,(D)	;YES. STORE PROTOCOL VERSION NUMBER
	STOR B,CMVRR,(C)	; IN BOTH REGIONS
	CAIE B,.VN20F		;DOING RSX20F?
	JRST DTINI5		;NO. ALL DONE WITH COMM REGION
	MOVEI A,1		;YES. GET A ONE
	STOR A,CMQP,(D)		;USING THE QUEUED PROTOCOL
	STOR A,CMQP,(C)		;FOR HIS AS WELL
	; ..
;NOW SET UP THE EPT FOR THIS DTE/-11 AND DO THE PROTOCOL
;TRANSITION

DTINI5:	MOVEM D,PROVER		;SAVE COMM REGION POINTER
	MOVE D,DTNUMB		;GET DTE NUMBER
	LSH D,SDTE		;GET TO THE EPT OFFSET
	MOVEI A,COMBUF+DTEN-1	;HIS EXAMINE REGION
	SUB A,DTNUMB		;WHERE IT REALLY IS
	MOVEI B,IEXSIZ+2	;GET INITIAL EXAMINE SIZE
	ADD B,DTNUMB		;ADD IN DTE NUMBER
	MOVEM A,DTEERW(D)	;EXAMINE RELOCATION WORD
	SUBI C,COMDAT		;STORE DEPOSIT RELOCATION
	MOVEM C,DTEDRW(D)	;STORE DEPOSIT RELOCATION
	ADDI C,COMDAT		;GET BACK COMM REGION POINTER
	MOVEM B,DTEEPW(D)	;STORE EXAMINE PROTECTION WORD
	MOVEI B,COMSIZ		;SIZE OF A SINGLE REGION
	MOVEM B,DTEDPW(D)	;STORE AS THE DEPOSIT PROTECTION
	MOVE A,DTNUMB		;THE DTE NUMBER
	MOVE B,DTETRP(A)	;GET TRAP INSTRUCTION
	MOVEM B,DTEINT(D)	;TO THE EPT
	MOVE D,PROVER		;RESTORE COMM REGION POINTER
	LOAD B,CMVRR,(C)	;GET PROTOCOL VERSION TO USE
	CAIE B,.VN20F		;WANT RSX20F?
	JRST DTINMC		;NO. GO DO OTHER
;HERE TO INIT RSX20F PROTOCOL FOR THIS DTE AND THIS -11

	SETZM DTEIND(A)		;CLEAR ANY RESIDUAL INDIRECT INFO
	SKIPE DTBFWD(A)		;HAVE BUFFERS YET?
	JRST DTIN10		;YES. USE THEM THEN
	MOVE A,[.RESP1,,BUFSIZ*2] ;NO. GET SOME SPACE THEN
	MOVX B,<RS%SE0+.RESGP>	;FROM THE GENERAL POOL
	CALL ASGRES		;GET THE SPACE
	 JRST [	MOVE A,DTNUMB	;FAILED. GET BACK DTE NUMBER
		CAMN A,MSTRDT	;IS THIS THE MASTER?
		BUG (NORSXF)
		SETONE DTRLD,(A) ;NO. SET RELOAD BIT
		AOS LOAD11	;SAY A SICK -11 ABOUNDS
		RET]		;AND DONE
	MOVE B,DTNUMB		;GOT IT. GET BACK DTE NUMBER
	HRLI A,BUFSIZ(A)	;FORM BUFFER WORD
	MOVEM A,DTBFWD(B)	;STORE IT
	MOVE A,B		;GET DTE NUMBER
DTIN10:	SETZM DTEFLG		;SET UP TO LEAVE MONITOR MODE
	MOVEI B,DTEEPP+1	;ENTER PRIMARY AND RESET COMM REGION
	MOVEM B,DTECMD		;THE COMMAND TO MONFE
	CALL DING11		;GO DING HIM
	CAME A,MSTRDT		;IS THIS THE MASTER?
	JRST DTINI6		;NO. SKIP PROTOCOL TRANSITION THEN
	MOVEI B,PRIPRO		;TIME TO DO IT
	CALL NEWTIM		;WHEN TIME IS UP
	SKIPN DTEFLG		;WAIT FOR THE 11 TO ACKNOWLEDGE
	JRST [	CALL CHKTIM	;TIME UP YET?
		JRST .-1	;NO. GO WAIT
		SETONE DTRLD,(A) ;YES. HE BLEW IT
		AOS LOAD11	;JUST IN CASE
		RET]		;AND DONE
	SETOM FEFLG		;PRIMARY PROTOCL NOW AVAILABLE
DTINI6:	CALL CLRBEL		;CLEAR OUT RESIDUAL DOORBELLS
	CALL DTEON		;TURN ON PROTOCOL

;NOW THAT THE PROTOCOL EXISTS, QUERY THE FRONT END ON THE STATE
;OF THE CTY

	CALL DTESKD		;START UP SCHEDULER IF NECESSARY
	PUSH P,A		;SAVE DTE NUMBER
	CALL LINFRQ		;GO GET THE LINE FREQUENCY
	CAIN A,^D60		;60 HZ?
	SETZ A,			;YES. REMEMBER AS A 0
	EXCH A,0(P)		;SAVE LINE FREQUENCY, RESTORE DTE NO
	SETZ C,			;DIRECT
	MOVE B,[.DFLCI,,.FEDLS]	;GIVE LINE COUNT
	MOVEI D,NTTFE-1		;THE NUMBER OF FE LINES
	SKIPE 0(P)		;60 HZ?
	TRO D,(1B2)		;NO. SET 50 HZ BIT
	POP P,0(P)		;CLEAN UP STACK
	CALL DTEQ		;DO IT
	 JFCL			;WILL GO
	RET			;AND DONE
;HERE TO INIT THE DTE AND THE -11 FOR MCB PROTOCOL. AT THIS POINT:
;	A/ DTE #
;	C/ POINTER TO -11'S COMM REGION
;	D/ POINTER TO -10'S COMM REGION
;	DTNUMB IS A STKVAR WITH THE DTE NUMBER IN IT

DTINMC:	SETONE <CMTST,CMINI>,(D) ;SET MY INI BIT
	MOVE B,CNDO(A)		;GET PROTOTYPE CONO
	IORI B,DTEPIE!DTEPI0	;TURN ON PI0 ONLY
	XCT B			; SO -11 CAN EXAMINE ITS REGION
	CALL DING11		;GO RING -11'S BELL
	MOVE B,[CONSO DTE0,DTETDB]
	LSH A,^D26		;POSOITION DTE NUMBER
	ADD B,A			;MAKE PROPER WORD
	MOVEM B,PROVER		;SAVE IT
	MOVE A,DTNUMB		;RESTORE DTE NUMBER
	MOVEI B,MCINI0		;TIMEOUT FOR FIRST PHASE
	CALL NEWTIM		;GET ABSOLUTE TIME
DTINM1:	XCT PROVER		;SEE A DOORBELL YET?
	JRST [	CALL CHKTIM	;TIME UP YET?
		JRST DTINM1	;NO. KEEP POLLING
		JRST DTINM3]	;AND GO WRAP UP
	JE CMINI,(C),DTINM3	;SEE IF IT DID IT RIGHT
	CALL CLRBEL		;CLEAR DOORBELL
	SETZRO CMINI,(D)	;CLEAR INI BIT
	CALL DING11		;RING 11'S BELL AGAIN
	MOVEI B,MCINI1		;TIME FOR THIS PHASE
	CALL NEWTIM		;ABSOLUTE TIME
DTINM2:	XCT PROVER		;SEE A BELL YET?
	JRST [	CALL CHKTIM	;NO. TIME UP YET?
		JRST DTINM2	;NO. KEEP POLLING
		JRST DTINM3]	;GO WARP UP
	JN CMINI,(C),DTINM3	;MAKE SURE IT DID IT RIGHT
	CALL DTEON		;GO TURN PROTOCOL ON
	CALLRET DTESKD		;AND START THE PROTOCOL

;INIT FAILED. KILL OFF DTE

DTINM3:	SETONE DTRLD,(A)	;SET RELOAD
	SETZRO DTERL,(A)	;NO LONGER RUNNING A PROTOCOL
	CALLRET DTREST		;AND RESET THE DTE
;TIMING ROUTINES USED BY PROTOCOL INIT CODE
;COMPUTE TIME IN FUTRURE.
;	B/ INCREMENT

NEWTIM:	PUSH P,A		;SAVE DTE #
	PUSH P,B		;SAVE INCREMENT
	CALL GETMST		;GET NOW
	POP P,B			;GET BAC INCREMENT
	ADD B,A			;TIME IN FUTURE
	POP P,A			;DTE #
	RET			;DONE

;CHECK IF TIME HAS ELAPSED.
;	B/ ABSOLUTE TIME
;RETURNS:	+1/ TIME NOT UP
;		+2 TIME UP

CHKTIM:	SAVEAC <A>		;SAVE DTE #
	PUSH P,B		;SAVE TIME
	CALL GETMST		;GET NOW
	POP P,B			;GET BACK TIME
	CAMLE B,A		;TIME UP?
	RET			;NO
	RETSKP			;YES
;DTE INTERRUPT SERVICE. THIS CODE IS ENTERED WHENEVER ANY FLAVOR
;OF DTE INTERRUPT IS GENERATED. THERE IS A SEPARATE ENTRY ROUTINE
;FOR EACH DTE.

;ROUTINE TO SAVE THE AC'S ON A DTE INTERRUPT

	RESCD			;MUST BE RESIDENT
SVDTAC::MOVEM P,DTEACB+P	;GET A WORK REGISTER
	MOVEI P,DTEACB		;BLT ARG
	BLT P,DTEACB+P-1	;SAVE REST OF ARGS
	MOVE P,DTESTK		;GET LOCAL STACK
	JRST @SVDTRJ		;RETURN TO INTERRUPT VECTOR

;DISMISS A DTE INTERRUPT

DTEDN1:	JUMPE P4,DTEDNE		;IF NO MORE, GO DISMISS
	MOVEI C,0(P4)		;PACKET SIZE
	MOVE A,DTEDTE		;GET DTE NUMBER
	JRST DOFNC3		;GO DO THIS FUNCTION
DTEDNE:	MOVSI P,DTEACB		;TO DO BLT
	BLT P,P-1		;DO ALL BUT P
	MOVE P,DTEACB+P		;RESTORE P
	XJEN DTETRA		;RESTORE STATE OF MACHINE

;INTERRUPT ON NON-EX OR RELOADING DTE. TURN OFF THE DTE

DTEPRG:	CALL DTREST		;GO RESET THIS DTE
	JRST DTEDNE		;AND GO DISMISS IT

;ROUTINE USED BY DTINIT TO TURN ON DTE PROTOCOL RACE FREE
;	A/ DTE #

DTEON:	NOSKD1			;AVOID RACES WITH SCHEDULER
	SETONE DTERL,(A)	;SAY NOW RUNNING A PROTOCOL
	CALL DTPII		;TURN ON DTE PI'S
	OKSKD1			;ALLOW SCHEDULING AGAIN
	RET			;AND DONE
;COMMON INTERRUPT ROUTINE. ENTERS WITH
;	A/ DTE NUMBER WHICH CAUSED INTERRUPT
;	P/ POINTS TO LOCAL DTE INTERRUPT STACK
;	F/ RESULT OF CONI DTEN,
;
;THIS ROUTINE PROCESSES ALL DTE INTERRUPTS

INTDTE::JE DTERL,(A),DTEPRG	;IF NON-EX, FORGET IT
	JN DTRLD,(A),DTEPRG	;IF RELOADING THE -11, FORGET THIS INTERRUPT
	TXNE F,DTEPF		;-11 LOST POWER?
	JRST POW11		;YES. GO DO SOMETHING ABOUT IT
	TXNE F,DTEEDN		;-11 DONE?
	JRST [	CALL TO11DN	;CALL AS A SUBROUTINE
		JRST DTEDNE]	;GO DISMISS THE INTERRUPT
	TXNE F,DTETDN		;TO 10 DONE?
	JRST TO10DN		;YES. GO MAKE SURE WE WERE TRANSFERRING
	TXNE F,DTETDB		;-10 DOORBELL INTERRUPT
	JRST DINGME		;YES. I WAS DINGED
	TXNE F,DTEEER		;TO -11 ERROR TERMINATION
	JRST TO11ER		;YES. GO TRY AGAIN THEN
	TXNE F,DTETER		;TO 10 ERROR?
	JRST TO10ER		;YES. BAD NEWS
	JRST DTEDNE		;GO DISMISS THE INTERRUPT

TO10DN:	STKVAR<OSTATE>		;WORD TO SAVE OLD STATE
	MOVEM A,DTEDTE		;SAVE DTE NUMBER
	MOVE B,CNDO(A)		;PROTOTYPE CONO
	IORI B,DTETDN		;SET TO CLEAR THIS BIT
	XCT B			;CLEAR IT
	LOAD B,DTEST,(A)	;GET STATUS OF THE DTE
	MOVEM B,OSTATE		;SAVE THE STATE
	TXZE B,DTET10!DTET1F	;RECEIVING ANY FLAVOR OF MESSAGE?
	JRST DODMSG		;YES. GO DO THE MESSAGE THEN
	BUG(DTETIP,<<A,D>>)
	JRST DTEDNE		;GO DISMISS THIS INTERRUPT
;PROCESS TO -10 DONE. FIRST DETERMINE WHICH PROTOCOL IS IN USE...

DODMSG:	STOR B,DTEST,(A)	;NEW STATUS
	CALL SETRGN		;GO GET COMM REGION POINTERS
	LOAD B,CMVRR,(C)	;GET PROTOCOL IN USE ON THIS DTE
	MOVE B,DN10VC(B)	;GET ADDRESS OF PROCESSING ROUTINE
	JRST 0(B)		;GO DO IT

;TRANSFER VECTOR FOR TO -10 DONE

DN10VC:	DN10RS			;FOR RSX20F PROTOCOL
	DN10MC			;FOR MCB PROTOCOL

;CODE TO PROCESS TO -10 DONE FOR RSX20F PROTOCOL
;AT THIS POINT:
;	A/ DTE NUMBER
;	C AND D POINT TO COMM REGIONS

DN10RS:	LOAD B,DTEBC,(A)	;GET RESIDUE COUNT
	SETZ P5,		;ASSUME NO HEADER ON MESSAGE
	JUMPN B,[ CALL DOFRGM	;START THIS FRAGMENT
		  JRST DODMS1]	;AND MERGE THE CODES
	SETZRO CMTOT,(C)	;CLEAR INTRANSIT BIT
	LOAD C,DTEB1,(A)	;GET COUNT OF COMPLETED REQUEST
	LOAD D,DTEBF,(A)	;THE BUFFER WE USED
DODMS1:	XCT [	HRRZ D,DTBFWD(A)
		HLRZ D,DTBFWD(A)](D) ;PICK UP THE BUFFER BASE ADDRESS
	HRLI D,(<POINT ^D8,0>)	;MAKE IT A BYTE POINTER
	JN INCNT,(A),[		;HAVE A RESIDUAL FUNCTION COUNT?
		LOAD P3,INCNT,(A) ;YES. GET IT
		JRST OLDFC2]	;GO DO IT
	;..
;GET THE FUNCTION AND DEVICE FROM THIS INITIAL FRAGMENT

DOFNC3:	SETO P5,		;PROCESSING HEADER
	CAIGE C,12		;VALID PACKET?
	JRST [	BUG(DTEP2S)
		JRST DTEDNE]	;NO. IGNORE IT
	ILDB B,D		;SECOND BYTE
	ILDB P3,D		;GET COUNT
	LSH P3,10		;THE FIRST BYTE
	IORI P3,0(B)		;MAKE COUNT FIELD
	ILDB P1,D		;LAST EIGHT BITS OF THE FUNCTION
	ILDB B,D		;FIRST 8 BITS OF THE FUNCTION
	LSH B,10		;TO FORM FULL CODE
	IOR P1,B		;GET FUNCTION CODE
	PUSH P,P1		;SAVE CODE
	TRZ P1,1B20		;CLEAR INDIRECT BIT
	STOR P1,DT1FC,(A)	;SAVE IT
	ILDB P1,D		;GET DEVICE CODE
	ILDB B,D
	LSH B,10
	IOR P1,B		;FORM FULL DEVICE CODE
	STOR P1,DT1DV,(A)	;SAVE THIS
	REPEAT 2,<ILDB B,D>	;SKIP THE SPARE
	POP P,P1		;GET BACK FUNCTION
	TRZE P1,1B20		;INDIRECT?
	JRST [	SETONE DT1ID,(A) ;YES. REMEMBER THIS
		LOAD B,DTEST,(A) ;GET STATE
		CAIN C,12	;MUST BE TWO BYTES LEFT
		TXNE B,DTET10!DTET1F ;IS IT QUIET?
		JRST [	BUG(DTEIDP,<<A,D>>)
			JRST DINGER]
		ILDB B,D	;GET COUNT
		STOR B,INCNT,(A) ;SAVE THIS TOO
		ILDB B,D	;GET LINE
		STOR B,INUNT,(A); SAVE IT
		SETONE INVLD,(A); SAY UNIT IS VALID
		JRST DTEDNE]	;AND DONE WITH THE REQUEST
	SETZRO INVLD,(A)	;UNIT IN INDIRECT WORD IN INVALID
OLDFC2:	CAILE P3,0(C)		;FUNCTION FULLY WITHIN PACKET?
	JRST [	SETZ P4,	;NO. NO LOCAL RESIDUAL COUNT
		SUBI P3,0(C)	;FIND HOW MANY IN NEXT PACKET
		STOR P3,INCNT,(A) ;SAVE IT
		JRST OLDFC1]	;GO DO IT
	SETZRO INCNT,(A)	;NO NEXT RESIDUAL
	EXCH P3,C
	SUBI P3,0(C)		;FIND LOCAL RESIDUAL
	MOVEI P4,0(P3)		;NEXT FUNCTION IS HERE
	; ..
OLDFC1:	SKIPE P5		;NEED TO REMOVE HEADER?
	SUBI C,10		;BYTES IN HEADER
	JUMPLE C,DTEDN1		;IF NO BYTES, WE ARE DONE
	LOAD B,DT1FC,(A)	;GET OPERATIVE FUNCTION CODE
	CAIL B,MINFNC		;LEGAL FUNCTION?
	CAILE B,MAXFNC		;STILL LEGAL?
	JRST [	BUG (DTEIFR,<<A,D>>)
		JRST DINGER]	;NO. KILL THE FE THEN
	JRST @FNCTBL-MINFNC(B)	;YES. GO DO IT THEN

NOOP:	BUG(DTEUIF,<<A,D>>)
	JRST DINGER		;AND ZAP THE FE

TAKLC:	CALL TAKLC2		;CALL PROCESSING ROUTINE
	JRST DTEDN1		;ALL DONE

TAKLC2:	STKVAR <BYTC,BYTP,SAVOFS,SAVTYP>;-11 HAS SENT LINE CHARACTERS
	TRNE C,1		;AN EVEN NUMBER OF BYTES?
	BUG(DTEODD)
	LOAD B,DT1DV,(A)	;GET DEVICE FOR THIS OPERATION
	MOVEM B,SAVTYP		;SAVE DEVICE TYPE
	CAIN B,.FECTY		;IS IT THE CTY?
	JRST [	SETZM SAVOFS
		JRST ISCTY]
	CAIE B,.FEDLS		;IS IT "TTY"?
	JRST [	BUG(DTETTY,<<A,D>>)
		JRST DINGER]
	IMULI A,DTENL		;YES. GET LINE OFFSET
	MOVEM A,SAVOFS		;SAVE IT FOR LATER
ISCTY:	MOVEM C,BYTC		;SAVE COUNT OF BYTES
	MOVEM D,BYTP		;AND THE BYTE POINTER
TAKLC1:	SOS BYTC		;MUST BE AT LEAST TWO BYTES HERE
	MOVE D,BYTP		;JUST IN CASE
	SOSGE BYTC		;THIS MAKES TWO
	RET			;ALL DONE
	ILDB A,BYTP		;GET BYTE
	ILDB B,BYTP		;GET LINE NUMBER
	ADD B,SAVOFS		;MAKE IT A "REAL" LINE NUMBER
	MOVE C,SAVTYP		;TYPE
	CALL DTESTO		;STORE IN BIGBUF
	JRST TAKLC1		;DO ALL BYTES

TAKDS:	LOAD B,DT1DV,(A)	;GET THE DEVICE
	CAIL B,MINDEV		;A REASONABLE DEVICE?
	CAILE B,MAXDEV		;STILL?
	JRST DMPBFR		;NO. FLUSH THE REQUEST
	SKIPE P1,DTEDTV(B)	;A KNOWN DEVICE?
	SKIPN P1,DTVSD(P1)	;YES. THIS DEVICE HAVE STRING DATA?
	JRST DMPBFR		;NO. FORGET IT
	CALL GETUNT		;FIND APPROPRIATE UNIT NUMBER
	HRLI A,0(C)		;THE COUNT
	LOAD C,DT1DV,(A)	;GET THE DEVICE
	MOVSS A			;PUT ARGS IN PROPER ORDER
	CALL 0(P1)		;GO DO DEVICE STUFF
	JRST DTEDN1		;ALL DONE
;MORE FUNCTIONS,ETC.

;COMMON ROUTINE USED BY TAKDS AND TAKSTS TO FIND UNIT. MAY BE
;STASHED AWAY IN DTEIND IF PACKET IS INDIRECT OR IN CURRENT 
;PACKET

GETUNT:	JN INVLD,(A),[
		LOAD B,INUNT,(A) ;GET IT FROM INDIRECT WORD
		RET]		;AND DONE
	ILDB B,D		;NOT INDIRECT. GET IT FROM CURRENT
	ILDB B,D		;IS THE SECOND BYTE
	SUBI C,2		;TWO FEWER BYTES
	RET			;AND DONE
;-11 IS PROVIDING TIME OF DAY

TAKTOD:	CAIGE C,2		;AT LEAST TWO MORE BYTES?
	JRST DNTIME		;NO. MUST NOT BE A TIME THEN
	ILDB P1,D		;AND ANOTHER
	ILDB B,D		;GET ONE BYTE
	SUBI C,2		;TOOK TWO OF THEM
	JUMPE P1,DNTIME		;IF ZERO,NO TIME IN THE -11
	CAIGE C,10		;ENOUGH BYTES
	JRST [	BUG(DTEDAT)
		JRST DNTIME]	;DONT BELIEVE IT
	CALL GTTFLD		;GET YEAR FIELD
	HRLM P1,TAD11		;STORE YEAR
	ILDB P1,D		;MONTH
	HRRM P1,TAD11		;TO MEMORY
	ILDB P1,D		;DAY OF MONTH
	HRLM P1,TAD11+1		;TO MEMORY
	ILDB P1,D		;DAY OF WEEK
	HRRM P1,TAD11+1		;TO MEMORY
	MOVX C,IC%DSA!IC%UTZ	;IDCNV BITS
	ILDB P1,D		;GET DST FLAG & TIME ZONE
	TRZE P1,1B28		;DST FLAG ON?
	TXO C,IC%ADS		;YES - USE DST THEN
	STOR P1,IC%TMZ,C	;STORE TIME ZONE
	MOVEM C,TAD11+2		;TO MEMORY
	CALL GTTFLD		;GET SECONDS
	LSH P1,1		;*2
	HRRM P1,TAD11+2		;TO MEMORY
	JRST DTEDN1		;ALL FINISHED

DNTIME:	SETOM TAD11		;NONE GIVEN
DMPBFR:	JUMPLE C,DTEDN1
	IBP C,D			;ADJUST BYTE POINTER
	MOVE D,C		;MOVE IT TO CORRECT REGISTER
	JRST DTEDN1		;AND RETURN

GTTFLD:	ILDB P1,D		;GET NEXT TIME/DATE FIELD
	ILDB C,D		;IN 2 BYTES
	LSH P1,10		;SLIDE FIRST PART OVER
	IOR P1,C		;FORM -11 WORD
	RET			;AND RETURN

SNDTOD:	SETONE DT1TM,(A)	;SAY -11 WANTS TIME OF DAY
	JRST DMPBFR		;MAKE SURE ALL IS OK
;MORE FUNCTIONS

;LINE HUNG UP OR DIALED UP

HANGUP:	TDZA P1,P1		;CLEAR P1
DIALUP:	MOVEI P1,1		;DIAL UP
	CAIGE C,2		;ENOUGH BYTES LEFT?
	JRST [	BUG(DTECAR,<<A,D>>)
		JRST DINGER]
	LOAD P3,DT1DV,(A)	;GET DEVICE
	IMULI A,DTENL		;BIAS THE LINE NUMBER
ALLLNE:	ILDB B,D		;GET LINE NUMBER
	ILDB P2,D		;THROW AWAY UPPER PART OF WORD
	PUSH P,A		;SAVE BASE LINE NUMBER
	ADDI B,0(A)		;LINE NUMBER IN B
	PUSH P,C
	PUSH P,D
	MOVEI A,0(P3)		;DEVICE CODE
	XCT [	CALL TTYHGU
		CALL TTYDLU](P1) ;CALL PROPER ROUTINE
	POP P,D
	POP P,C
	POP P,A			;GET BACK BASE LINE NUMBER
	SOS C			;DECREMENT COUNT
	SOJG C,ALLLNE		;DO ALL LINES
	JRST DTEDN1		;AND DONE

;LINE BUFFERS EMPTY

EMPTY:	CALL EMPTY2		;GO DO PROCESSING
	JRST DMPBFR		;ALL DONE. MAKE SURE BUFFERS ALIGN
EMPTY2:	STKVAR <CNTSV,DTESV,PTRSV>
	MOVEM A,DTESV
	MOVEM C,CNTSV
	MOVEM D,PTRSV
	LOAD D,DT1DV,(A)	;GET DEVICE -11 IS ACK-ING
	CAIL D,MINDEV		;A REASONABLE DEVICE?
	CAILE D,MAXDEV		;MAYBE, STILL SO?
	JRST LINEA1		;NO
	SKIPE P1,DTEDTV(D)	;A KNOWN DEVICE?
	SKIPN P1,DTVACK(P1)	;THIS DEVICE WANT AN ACK?
	JRST EMPTY3		;NO. SKIP THE PACKET
EMPTY1:	MOVE A,DTESV		;GET DTE
	LOAD A,DT1DV,(A)	;GET FUNCTION DEVICE
	ILDB B,PTRSV		;GET LINE NUMBER
	ILDB C,PTRSV		;THROW AWAY UPPER HALF
	CALL 0(P1)		;GO DO THE POST
	SOS CNTSV		;THE DUMMY BYTE
	SOSLE CNTSV		;MORE LINES?
	JRST EMPTY1		;YES
EMPTY3:	MOVE C,CNTSV		;GET COUNT
	MOVE D,PTRSV		;RESTORE BYTE POINTER
	RET			;END OF FUNCTION

	; ..
;MORE FUNCTIONS....

;TAKE LINE SPEED FROM -11. DONE ON -10 RELOAD

TAKSPD:	CAIGE C,6		;ENOUGH BYTES?
	JRST DMPBFR		;NO. IGNORE IT THEN
	SUBI C,5		;YES. WE WILL USE FIVE OF THEM
	PUSH P,C		;SAVE RESIDUE COUNT
	CALL GETUNT		;GO FIND UNIT NUMBER
	LOAD A,DT1DV,(A)	;PICK UP DEVICE FIELD
	CALL GTTFLD		;GET INPUT SPEED
	MOVSI P2,0(P1)		;SAVE IT
	CALL GTTFLD		;GET OUTPUT SPEED
	HRRI P2,0(P1)		;FORM SPEED WORD
	ILDB C,D		;GET REMOTE INDICATOR
	PUSH P,D		;SAVE BP
	MOVE D,P2		;ARG FOR TTYSRV
	CALL TTSPST		;GO SET IT UP
	POP P,D
	POP P,C			;RESTORE IMPORTANT PARAMETERS
	JRST DMPBFR		;AND DONE
;MORE FUNCTIONSS

;-11 IS SENDING ITS RELOAD REGISTER INFORMATION:

TAKRLW:	CAIGE C,2		;MUST BE A WORD OF INFORMATION
	JRST DMPBFR		;IGNORE IT
	ILDB B,D		;GET LOW 8 BITS
	ILDB P1,D		;GET HIGH 8 BITS
	LSH P1,10		;ADJUST IT
	IORI P1,0(B)		;FORM SWITCH WORD
	TRZ P1,(1B2)		;IGNORE RETRY BIT
	PUSH P,C
	PUSH P,D		;SAVE REGISTERS
	CALL SETRGN		;FIND REGIONS
	STOR P1,CMRLF,(C)	;SAVE IN MY REGION
	POP P,D			;RESTORE REGISTERS
	POP P,C
	SUBI C,2		;TOOK 2 BYTES
	JRST DMPBFR		;GO ALIGN BUFFERS

;ROUTINE TO ACK ALL UNITS OF ALL DEVICES

TAKACK:	MOVSI P1,MINDEV-MAXDEV+.FECTY
	HRRI P1,.FECTY+1	;START BEYOND THE CTY
	PUSH P,D		;SAVE SP
	PUSH P,C		;SAVE COUNTER
TKACK1:	SKIPE C,DTEDTV(P1)	;THIS DEVICE EXIST?
	SKIPN C,DTVACK(C)	;YES. WANT AN ACK?
	JRST TKACK2		;NO
	MOVE A,DTEDTE		;GET DTE FOR THIS FUNCTION
	SETO B,			;SAY TO ACK THEM ALL
	CALL 0(C)		;GO DO IT
TKACK2:	AOBJN P1,TKACK1		;GO DO ALL DEVICES
	POP P,C
	POP P,D
	MOVE A,DBUGSW		;GET RUNNING STATE
	CAIN A,2		;DEBUGGING SOME STUFF?
	JRST DMPBFR		;YEP. SKIP MESSAGE THEN
	AOS JB0FLG
	MOVEI A,1
	IORM 1,UPFLAG		;SAY WE NEED MESSAGE
	JRST DMPBFR		;GO ALIGN BUFFERS
;MORE FUNCTIONS...

;CODE TO SAVE KLINIK DATA BASE SENT BY THE -11

TAKKLI:	CAILE C,KLIMAX		;WILL IT FIT?
	JRST [	BUG(KLIOVF,<<C,D>>)
		JRST DTEDNE]	;AND IGNORE DATA
	MOVEM C,KLIDTA		;SAVE COUNT
	MOVE A,[POINT ^D8,KLIDTA+1] ;GET POINTER TO BUFFER
TAKKL1:	ILDB B,D		;GET NEXT BYTE
	IDPB B,A		;SAVE IT
	SOJG C,TAKKL1		;MOVE ALL BYTES
	JRST DTEDNE		;AND DONE
;MORE FUNCTIONS
;-11 IS ENDING LINE ALLOCATION INFORMATION

LINEAL:	CALL LINEA2		;GO DO PROCESSING
	JRST DMPBFR		;ALL DONE. MAKE SURE BUFFERS ALIGN

LINEA2:	STKVAR <CNTSV,DTESV,PTRSV>
	MOVEM C,CNTSV		;SAVE COUNT
	MOVEM A,DTESV		;SAVE DTE #
	MOVEM D,PTRSV		;SAVE POINTER
	LOAD D,DT1DV,(A)	;GET DEVICE CODE
	CAIG D,MAXDEV		;A KNOWN DEVICE?
	CAIGE D,MINDEV		;?
LINEA1:	JRST [	BUG(DTEDEV,<<A,D>>)
		JRST DINGER]	;ERROR
	SKIPE P1,DTEDTV(D)	;A KNOWN DEVICE?
	SKIPN P1,DTVTLA(P1)	;YES. CAN SET LINE ALLOCATION?
	JRST EMPTY3		;NO. GIVE IT UP
	CALLRET EMPTY1		;GO DO COMMON PROCESSING

;-11 IS SENDING ID OF THE CTY

TAKCTY:	ILDB B,D		;GET LINE NUMBER
	CALL IDCTY		;IDENTIFY IT TO TELETYPE SERVICE
	SUBI C,1		;TOOK ONE BYTE
	JRST DMPBFR		;GO ALIGN BUFFERS

;ROUTINE TO HANDLE SENDING OF DEVICE STATUS

TAKSTD:	CALL GETUNT		;GET THE UNIT
	STOR B,INUNT,(A)	;SAVE UNIT FOR SYSERR
	JN DTSTI,(A),[	SETZRO DTSTI,(A) ;CLEAR SPLIT INDICATOR
			MOVE B,D ;MOVE POINTER
			JRST TAKSTF]	;AND GO
	LOAD A,DT1DV,(A)	;GET DEVICE
	CAIL A,MINDEV		;A REASONABLE DEVICE?
	CAILE A,MAXDEV		;STILL?
TAKSTE:	JRST SEEERR		;UNKNOWN, SEE IF SYSERR REQUESTED
	SKIPE A,DTEDTV(A)	;A KNOWN DEVICE?
	SKIPN A,DTVTLS(A)	;YES. WANT DEVICE STATUS?
	JRST TAKSTE		;NO
	PUSH P,C		;SAVE COUNT
	PUSH P,D		;AND STRING POINTER
	CALL 0(A)		;DISPATCH OFF
	POP P,D			;RESTORE POINTER
	POP P,C			;AND COUNT
SEEERR:	ILDB B,D		;GET SOFTWARE STATUS
	ILDB B,D		;LOW 8 BITS
	SUBI C,2		;COUNT DOWN THOSE BYTES
	TXNN B,.DVFLG		;ERROR LOGGING REQUESTED?
	JRST DMPBFR		;GO ALIGN BUFFERS
;CODE TO MAKE FIRST PASS AT SYSERR ENTRY. THIS CODE WILL QUEUE
;UP ALL OF THE DEVICE DEPENDENT ERROR DATA, AND WILL STORE
;THE DEVICE CODE AND THE WORD COUNT OF THE ERROR DATA. IT WILL
;ALSO SCHEDULE A JOB 0 SUBROUTINE TO COMPLETE THE BLOCK

	ADDI C,2		;GET BACK THE SOFTWARE STATUS
	MOVNI B,2		;NUMBER OF BYTES TO RECOVER
	IBP B,D			;ADJUST THE BYTE POINTER
TAKSTF:	PUSH P,C		;SAVE BYTE COUNT
	PUSH P,B		;SAVE BYTE POINTER
	ADDI C,3		;CALCULATE WORDS IN ERROR REPORT
	LSH C,-2		;""
	PUSH P,C		;SAVE WORD COUNT
	MOVEI A,FE%LEN(C)	;WORDS TO ALLOCATE
	MOVEI B,FE%SIZ(C)	;SIZE OF HEADER
	CALL ALCSEB		;GET THEM
	 JRST SEEER1		;NONE THERE. PUNT
	MOVE B,DTEDTE		;GET DTE NUMBER
	MOVEM B,FE%DTE+SEBDAT(A) ;SAVE DTE NUMBER IN THE PACKET
	LOAD C,INUNT,(B)	;GET UNIT
	LOAD B,DT1DV,(B)	;GET DEVICE CODE
	HRLI B,0(C)		;MOVE UNIT TO LH
	MOVEM B,FE%DEV+SEBDAT(A);SAVE DEVICE CODE
	POP P,C			;WORD COUNT FOR ERROR STUFF
	MOVNI D,0(C)
	HRLM D,FE%PTR+SEBDAT(A)	;SAVE COUNT OF WORDS
	POP P,D			;GET DATA STRING
	POP P,C			;AND BYTE COUNT
	MOVE B,[POINT ^D8,FE%INF+SEBDAT(A)] ;POINTER
	MOVEM C,FE%BYT+SEBDAT(A) ;STORE # OF -11 BYTES
SEEER3:	ILDB P1,D		;ERROR BYTE
	IDPB P1,B		;SAVE IT
	SOJG C,SEEER3		;DO ALL BYTES
	MOVE B,[-2,,[		;INSERT EVENT CODE AND RECALL
		SEBPTR 0,SBTEVC,SEC%FE ;EVENT CODE
		SEBPTR 0,SBTFNA,SEEER2]] ;RECALL
	MOVE P1,D		;SAVE SP
	MOVE P2,A		;SAVE POINTER
	CALL SEBCPY		;DO COPY
	 JFCL
	MOVE A,P2		;GET BACK POINTER
	CALL QUESEB		;NOW QUEUE IT UP
	MOVE D,P1
	CALL CHKFRG		;SEE IF MORE TO COME
	JRST DTEDN1		;ALL DONE

SEEER1:	POP P,0(P)		;CLEAN UP STACK
	POP P,D			;SP
	POP P,C			;BYTE COUNT
	CALL CHKFRG		;SEE IF MORE TO DO
	JRST DMPBFR		;GO ALIGN BUFFERS
;COLLECTION OF ROUTINES TO DO ERROR PROCESSING.

TO11ER:

TO10ER:	BUG (DTEERR,<<A,D>,<F,D>>)
	JRST DINGER		;GO RELOAD THE MACHINE

POW11:	CALL DTEPF1		;TELL -11 ABOUT THE POWER FAIL
	JRST DTEPRG		;GO SHUT OFF THIS -11

;ROUTINE TO REQUEST A RELOAD OF THIS MACHINE

LOADME::MOVE A,MSTRDT		;THE MASTER -11
	CALL SETRGN		;GO FIND REGIONS
	SETONE CML11,(C)	;SET MY RELOAD INDICATOR
	CALLRET DING11		;GO TELL HIM TO DO IT

;ROUTINE CALLED FROM SCHED TO TELL MASTER -11 ABOUT A POWER FAIL
;INTERRUPT

DTEPWF::MOVE A,MSTRDT		;GET MASTER -11
DTEPF1:	CALL SETRGN		;FIND COMM REGIONS
	SETONE CMPWF,(C)	;SET OUR POWER-FAIL INDICATOR
	CALLRET DING11		;AND TELL THE -11

;ROUTINE TO SEE IF STATUS PACKKET WAS FRAGMENTED

CHKFRG:	MOVE A,DTEDTE		;GET DTE NUMBER
	MOVE B,DTESTS(A)	;GET STATUS
	TXNN B,DTET10!DTET1F	;NOW ACTIVE?
	RET			;NO
	SETONE DTSTI,(A)	;REMEMBER NEXT PART TO DO LOGGING
	RET			;AND DONE
;CODE TO PROCESS TO -10 DONE FROM AN MCB FRONT END TRANSFER
;	A/ DTE NUMBER
;	C AND D POINT TO COMM REGIONS

DN10MC:
   IFN DEBUG,<			;DEBUG CODE TO CHECK TRANSFER
	LSH A,SDTE		;GET TO EPT REGION
	LOAD B,CMTBP,(C)	;GET COMPUTED BP
	CAME B,DTETBP(A)	;MATCH?
	JRST [	LSH A,-SDTE	;RESTORE DTE #
		BUG (DTETBE,<<A,D>>)]
	LSH A,-SDTE		;YES. RESTORE DTE NUMBER
   >				;END OF IFN DEBUG
	JN DTEBC,(A),DTEDNE	;IF MORE TO DO, GO WAIT.
	MOVE B,DTEIND(A)	;GET BLOCK ADDRESS
	CALL NSPQ		;GO QUEUE IT UP
	JRST DTEDNE		;AND DONE
;-10 HAS RECEIVED A TO 10 DOORBELL. MUST FIGURE OUT WHAT THE -11
;WANTS AND HOW TO DO IT

DINGME:	CALL SETRGN		;GO FIND THE COMM REGIONS
	JN <CMINI,CML11>,(D),DINGER ;WANT RELOAD OR REINIT?
DINGM1:	LOAD B,CMVRR,(C)	;GET PROTOCOL TYPE
	CAIE B,.VN20F		;IS THIS THE RSX20F FRONT END?
	JRST DINGM2		;NO. DON'T CHECK FOR INDIRECT THEN
	JN DT1ID,(A),INDRCT	;YES, COMPLETING AN INDIRECT?
DINGM2:	LOAD P1,CM0IC,(C)	;MY TO 10 COUNTER
	LOAD P2,CM0IC,(D)	;HIS TO 10 COUNTER
	CAMN P2,P1		;DIFFERENT?
	JRST [	CALL CLRBEL	;CLEAR BELL
		JRST DTEDNE]	;GO AWAY
	CAIE P2,1(P1)		;WITHIN ONE OF ME?
	JRST [	CAIN P2,0	;DID HIS WRAP AROUND?
		CAIE P1,377	;YES. IS MINE AT MAX VALUE?
		JRST DINGM3	;NO. ERROR
		JRST .+1]	;YES. ALL IS WELL
	STOR P2,CM0IC,(C)	;MAKE COUNTS THE SAME
INDRC1:	MOVX B,DTET10!DTET1F	;TO 10 BITS
	TDNE B,DTESTS(A)	;IS THERE A TO 10 GOING?
	JRST DINGM4		;YES. ERROR
	SETONE CMTOT,(C)	;SET IN TRANSIT BIT
	CALL CLRBEL		;CLEAR DOORBELL
	LOAD B,CMQCT,(D)	;GET QUEUE COUNT
	SKIPG B			;IS IT A VALID COUNT
	JRST DINGM5		;NO. ERROR
	CALL DOFRGM		;START TRANSFER IN PROPER PROTOCOL
	JRST DTEDNE		;AND DONE

;COMPLETING AN INDIRECT FOR RSX20F PROTOCOL ONLY

INDRCT:	JE CMIP,(D),[
		LOAD P1,CM0IC,(C) ;MY TO 10 COUNT
		LOAD P2,CM0IC,(D) ;HIS TO 10 COUNT
		CAIE P1,0(P2)	;COUNTS THE SAME?
		JRST DINGM6	;NO. ERROR
		CALL CLRBEL	;YES. CLEAR EXTRANEOUS BELL
		JRST DTEDNE]	;GO DISMISS THE INTERRUPT
	SETZRO DT1ID,(A)	;CLEAR EXPECTING INDIRECT
	LOAD B,INCNT,(A)	;GET COUNT FROM HEADER
	OPSTR <CAME B,>,CMQCT,(D) ;SAME AS DATA NOW BEING SENT?
	JRST [	BUG (INDCNT)
		JRST DINGER]	;AND DO A RELOAD
	JRST INDRC1		;GO DO THE REQUEST
;ERROR ROUTINES FOR DOORBELL SERVICE

DINGER:	SKIPE FEDBSW##		;YES. WANT TO SUPPRESS RELOADS?
	JRST DTEDNE		;YES. IGNORE CONDITION
	CAME A,MSTRDT		;IS THIS THE MASTER?
	CALL [	CALL DTREST 	;NO. CLEAR IT
		SETZRO DTERL,(A) ;AND SAY NOT RUNNING A PROTOCOL
		CALLRET CLRDTE] ;AND DONE
	SETONE DTRLD,(A) 	;YES. SET RELOAD FLAG
	AOS LOAD11		;TELL JOB 0 OF RELOAD
	AOS JB0FLG		;SCHEDULE JOB 0
	JRST DTEDNE		;AND GO DISMISS INTERRUPT

;TO -10 COUNTS ARE WRONG

DINGM3:	BUG(DTECDM,<<A,D>>)
	JRST DINGER		;AND GO RELOAD

;TO -10 REQUEST FROM FE WHILE ONE IS IN PROGRESS

DINGM4:	BUG (DTEDIN,<<A,D>>)
	JRST DINGER

;INVALID Q COUNT FROM -11

DINGM5:	BUG (DTEDME,<<A,D>>)
	JRST DINGER

;INCORRECT INDIRECT SET UP FROM FE

DINGM6:	BUG (DTEPNR,<<A,D>>)
	JRST DINGER
;ROUTINE TO PROCESS A TO 11 DONE INTERRUPT

TO11DN:	MOVE B,CNDO(A)		;CONO WORD
	IORI B,DTEEDN		;TO CLEAR 11 DONE
	XCT B			;CLEAR THE BIT
	CALL SETRGN
	LOAD B,CMVRR,(C)	;GET PROTOCOL IN USE
	MOVE B,DN11TR(B)	;GET ROUTINE TO PROCESS THIS
	JRST 0(B)		;GO TO IT

;PROCESS RSX20F TO -11 DONE

DN11X:	LOAD B,DTEST,(A)	;GET STATE OF DTE
	TXZE B,DTE11		;DOING TO 11?
	JRST DN11		;YES. GO HANDLE IT
	TXZE B,DTE11I		;DOING INDIRECT?
	JRST DN11I		;YES
	RET			;ALL DONE

DN11I:	TXO B,DTE11		;DOING REGULAR 11
	STOR B,DTEST,(A)	;NEW STATE
	HRRZ B,DTEQS(A)		;GET QUEUE PACKET
	LOAD D,QCNT,(B)		;GET BYTE SIZE
	CAILE D,MAXINP		;TOO BIG FOR PROTOCOL?
	MOVEI D,MAXINP		;YES. FRAGMENT IT THEN
	STOR D,CMQCT,(C)	;TO MY REGION
	LSH A,SDTE			;*4
	JN QMODE,(B),[		;FORCE BYTE MODE?
		LOAD B,QPNTR,(B) ;YES. GET BYTE POINTER
		JRST NOTWRD]	;AND GO DO IT
	LOAD B,QPNTR,(B)		;GET BYTE POINTER
	TLNN B,100000		;EVEN # OF BYTES IN FIRST WORD?
	TRNE D,1		;YES. EVEN # OF BYTES IN MESSAGE?
	JRST NOTWRD		;NO. SEND IN BYTE MODE THEN
	LDB D,[POINT 6,B,11]	;GET BYTE SIZE
	CAIN D,10		;8 BITS?
	JRST [	MOVEI D,^D16	;YES. DO IT FULL WORD THEN
		DPB D,[POINT 6,B,11]
		SETONE CMFWD,(C) ;TELL -11 IT IS FULL WORD
		JRST .+1]
NOTWRD:	MOVEM B,DTEEBP(A)	;SET UP BYTE POINTER
	LSH A,-SDTE		;RESTORE A
	SETONE CMIP,(C)		;TELL -11 ALL IS OKAY
	CALL DING11		;GO DING -11
	RET			;ALL DONE

DN11:	STOR B,DTEST,(A)	;NEW STATE
	SETZRO CMIP,(C)		;NOT DOING INDIRECT ANYMORE
	HRRZ B,DTEQS(A)		;DEQUEUE THE PACKET
	CALL TSTSGL		;IS THIS A SINGLE PACKET GROUP?
	JRST DNSNGL		;YES. GO DO SPECIAL POSTING
	LOAD D,QCNT,(B)		;SEE IF IT WAS INDIRECT
	JUMPE D,DEQDTE		;NO. GO ON TO THE DEQUEUE LOGIC
	CAIG D,MAXINP		;YES. DID WE SEND IT ALL?
	JRST DEQDTE		;YES. GO ON
	;..
;INDIRECT REQUEST MUST BE PARTITIONED. DO NEXT PART

	SUBI D,MAXINP		;SAY SENT ONE SECTION
	STOR D,QCNT,(B)		;ABD STASH AWAY NEW COUNT
	MOVEI D,MAXINP		;COUNT OF BYTES SENT
	LOAD C,QPNTR,(B)	;GET BYTE POINTER
	IBP D,C			;ADJUST IT
	STOR D,QPNTR,(B)	;NEW BYTE POINTER
	CALL DTESKD		;GO DO NEXT PART
	RET			;AND DONE

;DEQUEUE COMPLETED REQUEST,POST IT, AND SCHEDULE NEXT REQUEST

DEQDTE:	LOAD C,QLINK,(B)	;GET NEXT GUY
	HRRM C,DTEQS(A)		;NEW HEAD
	SKIPN C			;HAVE A HEAD?
	SETZM DTEQS(A)		;NO. CLEAR THE WORD
	LOAD C,QINT,(B)		;INTERRUPT GUY
	PUSH P,C		;SAVE INTERRUPT
	LOAD C,QDEV,(B)		;DEVICE CODE
	PUSH P,C		;SAVE IT
	LOAD C,QCOD,(B)		;UNIQUE CODE
	PUSH P,C		;SAVE THIS AS WELL
	LOAD C,QLIN,(B)		;UNIT
	PUSH P,C		;SAVE IT
	PUSH P,A		;SAVE DTE NUMBER
	LSH A,SDTE		;FIND EPT OFFSET FOR THIS DTE
	SETZM DTEEBP(A)		;CLEAR TO -11 POINTER
	MOVE A,B
	CALL RELNOD		;FREE THE NODE
	POP P,A			;DTE NUMBER
MSTSKD:	OPSTR <SKIPE>,DTERL,(A)	;MAKE SURE DTE IS ACTIVE
	CALL DTESKD		;START DTE AGAIN
	POP P,B			;UNIT
	POP P,A			;CODE
	POP P,C			;DEVICE CODE
	POP P,D			;ADDRESS
	SKIPE D			;HAVE ONE?
	CALL 0(D)		;YES. GO HANDLE IT
	RET			;ALL DONE


;TRANSFER VECTOR FOR TO -11 DONE

DN11TR:	DN11X			;RSX20F PROTOCOL
	DN11MC			;MCB PROTOCOL
;ROUTINE TO POST A SINGLE CHARACTER DONE

DNSNGL:	LDB P1,[POINT 6,0(B),17] ;GET COUNT OF ENTRIES
	LOAD C,QLINK,(B)	;GET Q LINK
	HRRM C,DTEQS(A)		;NEW HEADER
	SKIPN C			;Q NOW EMPTY?
	SETZM DTEQS(A)		;YES
	SETZM 0(B)		;CLEAR ALL FLAGS
	MOVEI P2,SNGHDR(B)	;FIRST CHARACTER
	CALL DTESKD		;REACTIVATE THE DTE
	HRLI P2,(POINT ^D16,)	;MAKE A BYTE POINTER
SNGPST:	ILDB B,P2		;GET AN ENTRY
	LSH B,-^D8		;LINE NUMBER ONLY
	SETZ A,			;NO CODE
	MOVEI C,.FEDLS		;THE DSL
	CALL TTYINT		;GO DO THE POST
	SOJG P1,SNGPST		;DO ALL
	RET			;AND DONE

;TEST IF PACKET POINTED TO BY B IS A SINGLE PACKET GROUP.
;INPUT B/ POINTER
;RETURNS: +1 IS A SINGLE GROUP
;	+2 IS NOT

TSTSGL:	MOVE D,0(B)		;GET FLAGS
	TLNE D,(1B0)		;IS IT?
	TLNN D,(1B1)		;MAYVE
	RETSKP			;NO
	RET			;YES
;ROUTINE TO PROCESS A TO -11 DONE FOR A FE RUNNING MCB PROTOCOL

DN11MC:	SAVEQ			;GET WORK REGS
	HRRZ B,DTEQS(A)		;GET PACKET WE JUST COMPLETED
	LOAD Q1,DTEST,(A)	;GET CURRENT STATE OF THE DTE
	TXZN Q1,DTE11		;DONE WITH DATA TRANSFER?
	RET			;NO. IGNORE THE INTERRUPT THEN
	STOR Q1,DTEST,(A)	;YES. SAVE NEW STATE
	JRST DEQDTE		;AND GO FINISH UP THIS REQUEST
;ROUTINE TO START A TO 10 TRANSFER. ACCEPTS:
;	A/DTE NUMBER
;	B/ BYTES LEFT IN QUEUE (FOR CONSOLE FRONT END ONLY)
;RETURNS +1 WITH
;	A/DTE NUMBER
;	B/CLOBBERED
;	C/OLD COUNT FROM DTEB1
;	D/BUFFER POINTER BIT FOR LAST OPERATION

DOFRGM:	SAVEP			;PRESERVE THESE
	PUSH P,B		;SAVE INPUT
	CALL SETRGN		;GO FIND HIS REGION
	POP P,B
	LOAD P5,CMVRR,(C)	;GET PROTOCOL TYPE
	JRST @DOFRTR(P5)	;GO HANDLE PROPER PROTOCOL

;CODE FOR RSX20F PROTOCOL

DOFRRS:	LOAD P5,CMFWD,(D)	;GET WORD/BYTE INDICATOR
	LOAD C,DTEBF,(A)	;GET CURRENT BUFFER BIT
	MOVE D,C		;SAVE FOR CALLER
	TRC C,1			;NEXT BUFFER
	STOR C,DTEBF,(A)	;STORE THIS AS CURRENT BUFFER
	XCT [	HRRZ P4,DTBFWD(A)
		HLRZ P4,DTBFWD(A)](C) ;PICK UP BUFFER BASE
	HRLI P4,(<POINT ^D8,0>)	;MAKE IT A POINTER
	SKIPE P5		;DOING BYTE MODE?
	HRLI P4,(<POINT ^D16,0>) ;NO. GET WORD POINTER THEN
	LOAD C,DTEB1,(A)	;GET PREVIOUS COUNT
	CAIG B,BYTBUF		;ROOM IN A BUFFER FOR THIS MESSAGE?
	JRST [	SETZRO DTEBC,(A) ;YES. NO PENDING OPERATION THEN
		STOR B,DTEB1,(A) ;NCURRENT COUNT
		SKIPE P5	;BYTE TRANSFER?
		LSH B,-1	;NO. CALCULATE 16 BIT COUNT
		MOVNI B,0(B)	;GET NEG WORD COUNT
		ANDI B,7777	;ONLY 12 BITS FOR THE DTE
		IORI B,1B23	;SET I BIT TO INFORM 11
		MOVEI P2,DTET10	;DOING A TO 10 TRANSFER
		JRST SET1]	;AND GO DO IT
	MOVEI P2,DTET1F		;DOING A FRAGMENTED MESSAGE
	SUBI B,BYTBUF		;FIND RESIDUE
	STOR B,DTEBC,(A)	;SAVE IT FOR LATER
	MOVNI B,BYTBUF		;NUMBER OF BYTES
	SKIPE P5		;BYTE MODE?
	ASH B,-1		;NO. GET WORD COUNT THEN
	ANDI B,7777		;ONLY WANT 12 BITS
	MOVEI P1,BYTBUF
	STOR P1,DTEB1,(A)	;REMEMBER THIS COUNT
	; ..
	; ..
;READY TO START THE TO -10 TRNASFER

SET1:	LSH A,SDTE		;FIND DTE REGION
	MOVEM P4,DTETBP(A)	;STORE APPROPRIATE BYTE POINTER
	LSH A,-SDTE		;RESTORE DTE NUMBER
SET2:	IORM P2,DTESTS(A)	;INSERT STATUS WORD
	MOVE P1,DATO(A)		;DATAO WORD
	IORI P1,B		;WHERE DATA LIVES
	XCT P1			;DO TRANSFER
	RET			;AND DONE
;TRANSFER VECTOR FOR DOFRGM

DOFRTR:	IFIW!DOFRRS		;FOR RSX20F
	IFIW!DOFRMC		;FOR MC PROTOCOL

;CODE TO HANDLE TO -10 TRANSFER FOR MCB PROTOCOL

DOFRMC:	LOAD P5,DTEBC,(A)	;GET RESIDUAL COUNT
	JUMPE P5,DOFMCI		;GO GET A FREE BLOCK
	LOAD B,CMQCT,(D)	;GET PIECEMEAL COUNTER
	LOAD P3,CMTMD,(D)	;AND GET MODE OF THIS TRANSFER
	CAMLE B,P5		;REASONABLE TRANSFER?
	JRST [	BUG (DTEMCC,<<A,D>>)
		JRST DINGER]	;AND RELOAD DN20
	SUB P5,B		;COMPUTE NEW RESIDUAL COUNT
	STOR P5,DTEBC,(A)	;STASH IT
	CAIE P3,.TMBYT		;BYTE MODE TRANSFER?
	LSH B,-1		;NO. HALVE NUMBER THEN
   IFN DEBUG,<			;SPECIAL CODE TO CHECK DTE TRANSFER
	MOVE P2,B		;COPY COUNT
	LSH A,SDTE		;GET TO EPT REGION
	ADJBP P2,DTETBP(A)	;COMPUTE FINAL BYTE POINTER
	STOR P2,CMTBP,(C)	;SAVE IT
	LSH A,-SDTE		;RESTORE DTE NUMBER
   >				;END OF IFN DEBUG
	MOVNI B,0(B)		;GET NEG OF COUNT
	ANDI B,7777		;MAKE IT 12 BITS
	IORI B,1B23		;SET I BIT
	MOVEI P2,DTET10		;SAY DOING TO -10 TRANSFER
	JRST SET2		;AND GO DO THE TRANSFER

;ROUTINE TO START A NEW TRANSFER

DOFMCI:	PUSH P,A		;SAVE DTE NUMBER
	LOAD B,CMPCT,(D)	;GET COUNT OF ENTIRE MESSAGE
	STOR B,DTEBC,(A)	;SAVE STARTING COUNT
	CALL NSPSPC		;GO GET A BLOCK FOR MCB TRANSFER
				; A= DTE #, B=BYTES REQUIRED
	 JRST [	POP P,A		;RESTORE DTE NUMBER
		SETONE DTBLK,(A) ;SAY THIS DTE IS BLOCKED FOR FREE SPACE
;**;[1925] Change 1830 lines at DOFMCI: +7L	JGZ	19-AUG-81
;**;[1830] Insert 1 line at DOFMCI: +7L	DAD	3-FEB-81
		SETZRO DTEBC,(A) ;[1830] ZERO THE BYTE COUNT
		RET]		;AND GIVE UP
	MOVE P1,A		;SAVE ADDRESS
	POP P,A			;GET BACK DTE NUMBER
	MOVEM P1,DTEIND(A)	;SAVE STARTING ADDRESS
	CALL SETRGN		;FIND REGIONS AGAIN
	LOAD B,CMTMD,(D)	;GET MODE OF THESE TRANSFERS
	HRLI P1,(<POINT ^D8,>)	;ASSUME BYTE MODE
	CAIE B,.TMBYT		;IS IT?
	HRLI P1,(<POINT ^D16,>)	;NO. MAKE IT WORDS THEN
	LSH A,SDTE		;FIND PROPER DTE GROUP
	MOVEM P1,DTETBP(A)	;STORE INTO THE EPT
	LSH A,-SDTE		;RESTORE DTE NUMBER
	JRST DOFRMC		;AND GO DO IT
;ROUTINE USED BY TTYSRV TO QUEUE UP A SINGLE CHARACTER OUTPUT
;REQUEST. THESE REQUESTS ARE HANDLED SPECIALLY IN THAT THEY ARE
;PACKED TOGETHER IN A SPECIAL PACKET.
;INPUT IS:
;	B/ FUNCTION,,DEVICE
;	C/ UNIT,,
;	D/ BYTE

DTSNGL::CALL DTSNG0		;DO WORK
	 JRST DTSNG3		;COULDN'T DO IT
	RETSKP			;SUCCESS

;WORKER ROUTINE

DTSNG0:	SAVEP			;GET SOME WORK REGS
	SE0ENT			;ENTER SEC 0 HERE
	MOVE A,MSTRDT		;TO THE MASTER -11
	JE DTERL,(A),R		;IF NOT RUNNING, GIVE UP FOR NOW
	MOVEI P3,SNGPK1		;ADDRESS
	MOVE P4,SNGPK1		;LOOK AT THIS ONE
	TXNN P4,SNGACT		;INACTIVE?
	TXNE P4,SNGAVL		;YES, THIS PACKET AHVE SPACE IN IT?
	JRST DTSNG1		;NO. TRY OTHERS
	JRST DTSNG6		;GO DO COMMON CODE

DTSNG1:	MOVE P4,SNGPK2		;GET FLAGS
	MOVEI P3,SNGPK2
	TXNN P4,SNGACT		;INACTIVE?
	TXNE P4,SNGAVL		;THIS ONE HAVE ROOM?
	JRST [	SE1CAL		;RETRUN IN SEC1 IF NECESSARY
		RET]
DTSNG6:	CALL DTSNG2		;GO ADD BYTE
	SE1CAL			;RETURN IN SE1 IF NECESSARY
	RETSKP			;DONE
	; ..
;DTSNGL...

;WORKER ROUTINE TO ADD BYTE TO SINGLE PACKET

DTSNG2:	TXOE P4,SNGONQ		;ON THE QUEUE YET?
	JRST DTSNG4		;YES. GO ADD THE DATUM
	TXO P4,3B1		;SAY IS A SINGLE PACKET GROUP
	HLRZ P1,DTEQS(A)	;NO. MUST ADD IT
	HRLM P3,DTEQS(A)	;ADD IT TO THE TAIL
	SKIPN P1		;EMPTY QUEUE?
	JRST [	HRRM P3,DTEQS(A) ;YES. MAKE IT THE HEAD ALSO
		JRST DTSNG5]
	STOR P3,QLINK,(P1)	;NO. LINK THIS ONE IN
DTSNG5:	SETZRO QLINK,(P3)	;THIS ONE DOESN'T LINK
	DMOVE P1,[BYTE (^D16) 10,.DFHLC
		BYTE (^D16) .FEDLS,0]
	DMOVEM P1,1(P3)
DTSNG4:	MOVSI P1,(2B15)		;INCREASE Q COUNT
	ADDM P1,1(P3)		;DO IT
	LDB P1,[POINT 6,P4,17]	;GET COUNT OF ENTRIES IN QUEUE
	IDIVI P1,2		;ENTRIES PER -10 WORD
	ADDI P3,SNGHDR(P1)	;WORD TO PUT IT IN
	MOVEI B,0(B)		;DEVICE
	CAIN B,.FECTY		;IS THIS THE CTY?
	MOVS C,CTYUNT		;YES. GET REAL NAME
	LSH C,-^D10		;POSITION LINE NUMBER
	IORI C,0(D)		;MERGE IN BYTE
	XCT [	DPB C,[POINT ^D16,0(P3),15]
		DPB C,[POINT ^D16,0(P3),31]](P2)
	LDB P2,[POINT 6,P4,17]	;GET RESIDENT COUNT
	AOS P2			;INCREASE IT
	CAIL P2,MAXSGL		;FULL?
	TXO P4,SNGAVL		;YES. NO MORE THEN
	DPB P2,[POINT 6,P4,17]	;PUT BACK THE COUNT
	SUBI P3,SNGHDR(P1)	;BACK TO TOP OF PACKET
	HLLM P4,0(P3)		;SET UP NEW FLAGS
	MOVX B,DTE11!DTE11I	;ACTIVE STATUS
	TDNN B,DTESTS(A)	;IS IT ACTIVE?
	CALL DTESKD		;NO. GO START IT
	RET			;AND DONE

;COULD NOT PUT ENTRY IN EITHER SINGLE PACKET. USE CONVENTIONAL
;MECAHNISM

DTSNG3:	MOVSI A,TTYINT		;THE INTERRUPT LOCATION
	CALLRET DTEQ		;DO IT
;THIS IS THE DTE REQUEST QUEUER. FOR RSX20F PROTOCOL ACCEPTS:
;	F/DRIVER UNIQUE CODE
;	A/DRIVER INT LOC,,DTE NUMBER
;	B/DTE FUNCTION CODE,,FE DEVICE CODE
;	C/UNIT NUMBER,,BYTE COUNT OR ZERO
;		BIT 18 OF C IS A ONE IF INDIRECT DATA MUST BE SENT
;		IN BYTE MODE. IF 0, THEN DTESRV DECIDES HOW TO PACKAGE
;		AND SEND THE BYTES
;	D/INDIRECT BYTE POINTER (IF RH OF C NE 0) OR LOCAL DATUM
;	  IF LOCAL DATUM SPECIFIED (I.E. RH OF C EQ 0) THEN
;	  IF LH OF C =0, DATUM IS 16 BITS. IF LINE NUMBER
;	  IS NON-ZERO, THEN DATUM IS 8 BITS.

;AND FOR MCB PROTOCOL ACCEPTS:
;	F/ DRIVER UNIQUE CODE
;	A/ DRIVER INT LOC,,DTE NUMBER
;	B/ BYTE POINTER TO NSP DATA (WITH OR WITHOUT HEADER)
;	C/ COUNT OF BYTES IN DATA POINTED TO BE B
;
;	RETURNS:
;	+1 IF NO PACKETS AND CALLED FROM SCHEDULER. REQUEST NOT
;	   QUEUED.
;	+2 REQUEST QUEUED
;
;MAY BE CALLED FROM PI OR NON-PI LEVEL .
	; ..
	; ..
;NOW FOR THE CODE OF DTEQ

RQTAD1::			;ALTERNATE ENTRYPOINT FOR REQUEST TIME AND DATE 11
	MOVSI B,.DFRTD		;GET TIME/DATE FUNCTION
	MOVE A,MSTRDT		;THE MASTER -11
	SETZM C			;NO UNIT - SEND DIRECT
DCNMSO::
DTEQ::	SE0ENT			;ENTER SECTION 0
	CALL DTEQ12		;CALL SUBROUTINE
	SKIPA
	AOS 0(P)		;PLAN FOR SKIP RETURN
	SE1CAL			;CLEAR FLAGS
	RET			;AND RETURN

DTEQ12:	JE DTERL,(A),DTEOFF	;DTE IS NOT RUNNING. CHECK OUT WHAT TO DO
	STKVAR <SAVF,SAVA,SAVB,SAVC,SAVD,PISTAT,PROVER> ;SAVE REGS HERE
	MOVEM A,SAVA		;SAVE ALL ARGS
	HRRZS A			;ISOLATE DTE NUMBER
	CAIL A,DTEN		;A KNOWN DTE?
	BUG (INVDTE)
	CAMN A,MSTRDT		;IS THIS THE MASTER?
	SKIPE FEFLG		;YES. PRIMARY PROTOCOL AVAILABLE?
	SKIPA			;ALL SET 
	RETSKP			;NO PROTOCOL INIT. IGNORE REQUEST
	MOVEM B,SAVB
	MOVEM C,SAVC
	MOVEM D,SAVD
	MOVEM F,SAVF		;SAVE UNIQUE CODE AS WELL
	CALL SETRGN		;GO GET COMM REGION POINTERS
	LOAD C,CMVRR,(C)	;GET PROTOCOL VERSION
	MOVEM C,PROVER		;SAVE IT FOR LATER
	SETZM PISTAT		;ASSUME PI IS ON
	CONSO PI,1B<DLSCHN+^D28> ; IS IT?
	SETOM PISTAT		;NO. REMEMBER THIS
	CONSO PI,1B<DLSCHN+^D20> ;AT DTE PI LEVEL?
;**;Revamp and add code starting at HAVNOD: -8L	JGZ	4-SEP-80
	SKIPE INSKED		;[1780] FROM SCHEDULER?
	JRST DTEQ14		;[1780] YES, CAN'T BLOCK
	SKIPN NSKED		;[1780] NO. ARE WE NOSKED?
	SKIPN FORKX		;[1780] IS THIS FORK 0?
	 JRST [			;[1780] YES
DTEQ14:		CALL ASGNDI	;[1780] YES. CANT BLOCK THEN
		 RET		;[1780] NONE THERE. FOO
		JRST HAVNOD]	;[1780] GO INLINE WITH BUFFER
	CALL ASGNOD		;GET A REQUEST NODE
	 JFCL			;WILL NOT HAPPEN IF NON PI
HAVNOD:	MOVEI D,0(A)		;MOVE ADDRESS
	HLRZ B,SAVA		;INT LOC
	STOR B,QINT,(D)		;TO THE REQUEST
	SETZRO QMODE,(D)	;ASSUME FREE CHOICE ON INDIRECT
	HRRZ B,SAVC		;COUNT OR DATUM
	STOR B,QCNT,(D)		;STORE COUNT
	TXZE B,DTBYTM		;FORCE BYTE MODE?
	JRST [	SETONE QMODE,(D) ;YES
		JRST .+1]	;PROCEED
	MOVE C,PROVER		;GET PROTOCOL VERSION NUMBER
	CAIE C,.VN20F		;IS THIS RSX20F PROTOCOL?
	JRST [	MOVE C,SAVB	;NO. GET NSP HEADER INFORMATION
		STOR C,QPNTR,(D) ;STORE IT
		JRST DTEQ13]	;AND CONTINUE
	HLRZ C,SAVB		;THE FUNCTION CODE
	SKIPE B			;AN INDIRECT INDICATOR?
	TRO C,1B20		;YES. MARK IT AS SUCH
	STOR C,QFNC,(D)		;AND THE FUNCTION
	HLRZ C,SAVC		;UNIT NUMBER
	STOR C,QLIN,(D)		;TO THE PACKET
	HRRZ B,SAVB		;DEVICE CODE
	STOR B,QDEV,(D)		;TO REQUEST
	MOVE B,SAVD		;BYTE POINTER OR DATUM
	STOR B,QPNTR,(D)	;STORE POINTER OR DATUM
DTEQ13:	MOVE B,SAVF		;GET UNIQUE CODE
	STOR B,QCOD,(D)		;PUT IN THE PACKET
	HRRZ A,SAVA		;DTE NUMBER
	SKIPN PISTAT		;PI OFF BY CALLER?
	CONSZ PI,1B<DLSCHN+^D20> ;AT DTE PI LEVEL?
	JRST DTEQ1		;YES
	NOSKD1			;PROTECT THE DATA STRUCTURES
	CHNOFF DLSCHN		;AND AGAIN
DTEQ1:	HLRZ B,DTEQS(A)		;GET TAIL
	HRLM D,DTEQS(A)		;MAKE THIS THE TAIL
	SKIPN B			;WAS Q EMPTY?
	JRST [	HRRM D,DTEQS(A)	;YES
		JRST OCUPID]	;AND GO INLINE
	STOR D,QLINK,(B)	;NO. ADD THIS ONE
OCUPID:	SETZRO QLINK,(D)	;THIS ONE HAS NO LINK
	LOAD B,DTEST,(A)	;GET STATUS OF THIS DTE
	TXNN B,DTE11!DTE11I	;IS TO 11 IDLE?
	CALL DTESKD		;GO START UP THE DTE
	SKIPN PISTAT		;PI OFF BY CALLER?
	CONSZ PI,1B<DLSCHN+^D20> ;AT DTE PI?
	RETSKP			;YES. JUST RETURN
	CHNON DLSCHN		;TURN ON THE DTE AGAIN
	OKSKD1			;AND THE SCHEDULER
	RETSKP			;AND RETURN
;DTEQ CONTINUED. DTE IS NOT RUNNING. SEE IF WE SHOULD BLOCK

DTEOFF:	HRRZ CX,A		;GET DET #
	CAME CX,MSTRDT		;IS THIS THE MASTER?
	RET			;NO. GIVE UP NOW THEN
	SKIPN INSKED		;IN THE SCHEDULER?
	SKIPE NSKED		;OR NOSKED?
	RET			;YES. GIVE UP THEN
	MOVE CX,RLDFRK		;GET FORK ID OF RELOAD FORK
	CAME CX,FORKX		;IS THIS IT?
	CONSZ PI,1B<DLSCHN+^D20> ;AT DTE INTERRUPT LEVEL?
	RET			;YES. GIVE UP

;CAN BLOCK THE PROCESS. DO IT

	PUSH P,A		;SAVE ARG
	MOVEI A,RLDTST		;WAIT FOR MASTER TO BE RELOADED
	MDISMS			;DO IT
	POP P,A			;GET BACK ARG
	JRST DTEQ12		;AND TRY AGAIN

;SCHEDULER TEST FOR ABOVE

	RESCD
RLDTST:	MOVE A,MSTRDT		;GET MASTER DTE NUMBER
	OPSTR <SKIPE>,DTERL,(A)	;NOW RUNNING?
	ADDI 4,1		;YES.
	JRST 0(4)		;AND DONE
;ROUTINE TO START A TO 11 OPERATION FROM THE TOP OF THE DRIVER
;QUEUE
;ACCEPTS A/ DTE NUMBER


;TRANSFER VECTOR FOR PROTOCOL TYPES

SKDVEC:	SKVER1			;ROUTINE FOR RSX20F PROTOCOL
	SKVER2			;ROUTINE FOR MCB DECNET PROTOCOL

DTESKD:	SKIPN DTEQS(A)		;A REQUEST?
	RET			;NO. ALL DONE THEN
	JN DTRLD,(A),R		;IF RELOADING -11, DON'T DO ANYTHING
	CALL SETRGN		;GO FIND MY COMM REGION TO THIS -11
	LOAD D,CMVRR,(C)	;GET PROTOCOL VERSION NUMBER
	MOVE D,SKDVEC(D)	;GET ROUTINE TO DO THIS PROCESSING
	HRRZ B,DTEQS(A)		;MAKE SURE STILL A REQUEST THERE
	JUMPN B,0(D)		;IF STILL HERE, DO IT
	RET			;IF GONE, JUST RETURN
;CODE TO PROCESS PROTOCOL VERSION 1 PACKETS (RSX20F)
;	A/ DTE NUMBER
;	B/ PACKET

SKVER1:	CALL TSTSGL		;IS IT A SINGLE CHARACTER GROUP?
	JRST [	MOVX C,DTE11	;TO -11 STATUS
		IORM C,DTESTS(A) ;SET IT
		MOVX C,SNGACT	;GET ACTIVE BIT
		IORM C,0(B)	;SAY SO
		CALL SETRGN
		MOVEI B,1(B)	;THE DATA
		EXCH B,C
		LDB D,[POINT ^D16,0(C),15] ;BYTES
		JRST DTSKDM]	;GO DO IT
	JE QFNC,(B),DEQDTE	;IF FLUSHED, POST ONLY
	MOVEI C,0(A)		;DTE NUMBER
	IMULI C,PKTSIZ		;SIZE OF QUEUE PACKET
	ADDI C,PKTADR		;GET BASE ADDRESS OF THIS PACKET
	LOAD D,QDEV,(B)		;DEVICE CODE
	STOR D,HDDEV,(C)	;TO THE QUEUE
	LOAD D,QFNC,(B)		;THE FUNCTION
	STOR D,HDFNC,(C)	;TO THE QUEUE
	SETZRO HDSPR,(C)	;ZERO THE SPARE
	LOAD D,QCNT,(B)		;GET THE COUNT
	JUMPN D,[CAILE D,MAXINP	;CAN WE SEND IT ALL?
		MOVEI D,MAXINP	;NO. SEND MAX NUMBER
		STOR D,HDDAT,(C) ;PUT SIZE IN PACKET
		LOAD D,DTEST,(A) ;DTE STATE
		TXO D,DTE11I	;DOING INDIRECT
		STOR D,DTEST,(A);NEW STATE
		SETZRO HDLIN,(C) ;CLEAR OUT LINE NUMBER FIELD
		 JRST STOREG]	;GO STORE IN MY REGION
	LOAD D,QPNTR,(B)	;GET DATUM
	STOR D,HDDT1,(C)	;STORE IN PACKET
	LOAD D,DTEST,(A)	;DTE STATE
	TXO D,DTE11		;REGULAR 11
	STOR D,DTEST,(A)	;NEW STATE

	; ..
	; ..
STOREG:	MOVEI D,12		;INCLUDE DATUM
	STOR D,HDCNT,(C)	;TO THE PACKET
	LOAD D,QLIN,(B)		;UNIT
	JUMPE D,STORG1		;IF NO LINE GIVEN,ALLOW FOR 16 BIT  DATUM
	STOR D,HDLIN,(C)	;TO THE QUEUE
STORG1:	PUSH P,C		;SAVE QUEUE POINTER
	CALL SETRGN		;GET MY COMM REGION
	MOVE B,C		;MOVE MY COMM REGION POINTER
	POP P,C			;RESTORE Q POINTER
	MOVEI D,12		;THE COUNT OF THIS ONE
DTSKDM:	HRLI C,(<POINT ^D8,0>)	;POINTER
	SETZRO CMFWD,(B)	;DOING BYTE MODE
DTSTRT:	STOR D,CMQCT,(B)	;STORE THE COUNT
	LOAD D,CM1IC,(B)	;TO -11 COUNT
	AOS D
	STOR D,CM1IC,(B)	;UP IT
	LSH A,SDTE			;*4
	MOVEM C,DTEEBP(A)	;STORE POINTER
	LSH A,-SDTE		;/4
	CALL DING11		;GO START THE -11
	RET			;AND DONE
;ROUTINE TO HANDLE PROTOCOL VERSION 2 PACKETS (MCB)
;	A/ DTE NUMBER
;	B/ PACKET
;	C/ COMM REGION POINTER

SKVER2:	SAVEQ			;SAVE REGS
	LOAD Q3,QPNTR,(B)	;GET POINTER
	LDB Q1,[POINT 6,Q3,11]	;GET BYTE SIZE
	MOVEI Q2,.TMBYT		;ASSUME BYTE
	CAIN Q1,^D16		;A WORD POINTER?
	MOVEI Q2,.TMWRD		;YES. DO WORD MODE THEN
	CAIE Q1,^D8		;EIGHT BITS?
	JRST SKVR22		;NO. ALL SET THEN
   REPEAT 0,<			;UNIMPLEMENTED MODE
	LOAD Q1,QCNT,(B)	;YES. GET THE CURRENT COUNT
	TRNE Q1,1		;IS IT AN EVEN NUMBER OF BYTES?
	JRST SKVR22		;NO. DO BYTE MODE THEN
	MOVEI Q2,.TMBWD		;YES. DO BYTES IN WORD MODE
	MOVEI Q1,^D16		;MAKE IT 16 BIT BYTE POINTER
	DPB Q1,[POINT 6,Q3,11]	; BY CHANGING BYTE POINTER WORD
	STOR Q3,QPNTR,(B)	;IN THE DATA PACKET
   >				;END OF REPEAT 0
SKVR22:	STOR Q2,CMTMD,(C)	;PUT IN MODE OF THE TRANSFER
	MOVX D,DTE11		;SAY REGULAR TRANSFER IN PROGRESS
	IORM D,DTESTS(A)	;""
	LOAD D,QCNT,(B)		;GET Q COUNT
	CAIN Q2,.TMWRD		;WORD MODE?
	LSH D,1			;YES. COMPUTE # OF 8 BIT BYTE THEN
	STOR D,CMPCT,(C)	;STORE COUNT OF THIS TRANSFER
	MOVE B,Q3		;BYTE POINTER TO B
	EXCH B,C		;FIX UP REGS
	JRST DTSTRT		;AND GO START THE DTE
;SPECIAL ROUTINES TO RING -11'S DOORBELL ,TO MANIPULATE THE
;PI CAPABILITY, TO RESET THE DTE, AND TO FINE COMM REGION POINTERS

;RING -11'S DOORBELL
;	A/ DTE NUMBER
;CLOBBERS B

DING11:	MOVE B,CNDO(A)
	IORI B,DTEEDB		;THE -11'S BELL
	XCT B
	RET			;AND DONE

;CLEAR DOORBELL

CLRBEL:	MOVE B,CNDO(A)
	IORI B,DTETDB		;DOORBELL BIT
	XCT B			;CLEAR IT
	RET			;AND DONE

;ROUTINE TO RESET A DTE. TURNS OFF ITS INTS. ANY CONDITIONS
;ACCEPTS:	A/ DTE #

DTREST:	MOVE B,CNDO(A)		;GET PROTOTYE CONO
	IORI B,DTEPIE!DTETDB!DTETDN!DTEEDN
	XCT B			;CLEAR ALL CONDITIONS
	PUSH P,A		;SAVE DTE ARG
	HRRZS A			;ISOLATE DTE NUMBER
	LSH A,SDTE		;FIND DTE EPT REGION
	SETZM DTETBP(A)		;CLEAR LATENT POINTER
	SETZM DTEEBP(A)		;AND THIS ONE ALSO
	CALLRET PA1		;AND DONE

;ROUTINE TO INIT INT STATE OF A DTE
;ACCEPTS:	A/ DTE #

DTPII:	CALL DTREST		;FIRST RESET IT
	MOVE B,CNDO(A)		;GET PROTOTYPE CONO
	IORI B,LDTEPI		;GET PI ASSIGNMENT
	XCT B			;SET IT
	RET			;AND DONE

;ROUTINE TO SET UP COMM REGION POINTERS. ACCEPTS:
;	A/ DTE NUMBER
;RETURNS:
;	C/ POINTER TO -10'S PER PROCESS REGION
;	D/ POINTER TO -11'S PER PROCESS REGION

SETRGN:	MOVEI C,0(A)		;THE DTE NUMBER
	IMULI C,COMRGN		;SIZE OF A PER PROCESS REGION
	ADDI C,COMBAS+COMDAT	;BASE OF -10'S REGION TO THE -11
	MOVNI D,2(A)		;NOW FIND THE -11'S
	HRRZ D,COMBUF+DTEN+1(D)	;GET VALUE FROM POINTER
	ADDI D,COMBAS+COMDAT	;MAKE IT ABSOLUTE POINTER TO -11'S REGION
	RET			;AND DONE
;ROUTINE TO FLUSH ALL OUTPUT REQUEUST FOR A GIVEN TTY UNIT.
;ACCEPTS:	A/DTE #
;		B/DEVICE
;		C/UNIT,,0
;RETURNS:	+1 WITH OUTPUT REQUESTS FLUSHED
;CLOBBERS ALL TEMP REGISTERS EXCEPT A,B,C
;MUST BE NOINT AND CHNOFF ON THE DTE CHANNEL

	RESCD			;IS RESIDENT
DTEFLA::TDZA D,D		;ENTRY TO FLUSH ALL
DTEFLO::MOVEI D,1		;ENTRY TO FLUSH ONLY DATA
	STKVAR <SVDTN,SVLIN,SVDEV,SVD>
	MOVEM D,SVD		;SAVE ENTRY FLAG
	SE0ENT
	MOVEM A,SVDTN		;SAVE DTE NUMBER
	MOVEM B,SVDEV		;SAVE DEVICE CODE
	MOVSM C,SVLIN		;SAVE LINE NUMBER (FROM LH)
	HRLI A,DTEQS(A)		;INITIAL PREVIOUS
	HRRZ C,DTEQS(A)		;TOP ITEM
	JUMPE C,SKPPK1		;IF EMPTY, JUST WRAP UP
CHKPKT:	MOVE B,C		;MOVE POINTER
	CALL TSTSGL		;IS THIS A SINGLE BYTE GROUP?
	 JRST SKPPKT		;YES. SKIP IT
	LOAD B,QDEV,(C)		;DEVICE CODE
	CAME B,SVDEV		;SAME DEVICE?
	JRST SKPPKT		;NO. SKIP IT
	LOAD B,QLIN,(C)		;LINE NUMBER
	CAME B,SVLIN		;SAME LINE?
	JRST SKPPKT		;NO. GO TO NEXT
	LOAD B,QINT,(C)		;GET INTERRUPT ADDRESS
	CAIE B,TTYINT		;IS IT TTYINT?
	SKIPN SVD		;NO. FLUSH ALL?
	SKIPA			;YES. FLUSH THIS PACKET
	JRST SKPPKT		;NO. LEAVE IT
	SETZRO QFNC,(C)		;YES. MARK IT AS FLUSHED
	SETZRO QCOD,(C)		;AND PREVENT ACCOUTNING
SKPPKT:	HRL A,C			;ESTABLISH NEW PREVIOUS
	LOAD C,QLINK,(C)	;GET LINK
	JUMPN C,CHKPKT		;GO LOOK AT IT
SKPPK1:	MOVE A,SVDTN		;RESTORE DTE NUMBER
	MOVE B,SVDEV		;RESTORE DEVICE
	MOVS C,SVLIN		;RESTORE LINE (TO LH)
	SE1CAL			;ENTER SEC1 FOR RETURN
	RET			;AND DONE
;ROUTINE CALLED FROM APRSRV TO WAIT FOR ALL DTE'S
;TO COMPLETE TRANSFERS.MUST BE CALLED PIOFF AND NOT
;FROM INTERRUPT LEVEL

;**;[2607] Change one line at DTEINA: +0L	JGZ	3-APR-82
DTEINA::SAVEAC <Q1>		;[2607] GET A WORK REG
	MOVSI Q1,-DTEN		;LOOK AT THEM ALL
DTENA0:	JE DTERL,(Q1),DTENA1	;IF NOT RUNNING, SKIP IT
	MOVX A,DTET10!DTET1F	;SEE IF TO -10 IN PROGRESS
	TDNN A,DTESTS(Q1)	;IS IT?
	JRST DTENA2		;NO. CHECK ON TO -11
	MOVE B,CNDO(Q1)		;YES. GET A CONO WORD
	TXO B,<<CONSO 0>-<CONO 0>+DTETDN+DTETER> ;GET CONSO WORD
	XCT B			;DONE YET?
	JRST .-1		;NO. WAIT FOR IT THEN
DTENA2:	MOVX A,DTE11!DTE11I	;SEE IF ANY TO -11 IN PROGRESS
	TDNN A,DTESTS(Q1)	;IS IT?
	JRST DTENA1		;NO. GO TO NEXT DTE THEN
	MOVE B,CNDO(Q1)		;YES. GET CONO WORD
	TXO B,<<CONSO 0>-<CONO 0>+DTEEDN+DTEEER>
	MOVX A,^D100000		;# OF POLLS
	XCT B			;WAIT FOR COMPLETTION
	SOJGE A,.-1		;WAIT, BUT NOT FOREVER
DTENA1:	AOBJN Q1,DTENA0		;DO ALL OF THEM
	CALLRET DTPAUS		;PAUSE ALL DTE ACIVIITY

;ROUTINE TO REQUEST PAUSE OF ALL DTE ACTIVITY. MAY BE CALLED
;FROM ANY LEVEL

DTPAUS::MOVEI A,[SETZM DTEEPW(B)
		RET]		;ROUTINE TO EXECUTE
	JRST DTACT0		;GO TO WORKER ROUTINE

;ROUTINE TO REACTIVATE FE'S. THIS CODE MERELY TURNS ON
;VALID EXAMINE FOR ALL ACTIVE DEVICES.

DTEACT::MOVEI A,[MOVEI C,IEXSIZ+2(A) ;GET EXAMINE SIZE
		MOVEM C,DTEEPW(B) ;STORE CORRECT VALUE
		RET]
;**;[2607] Change one line at DTACT0: +0L	JGZ	3-APR-82
DTACT0:	SAVEAC <Q1,Q2>		;[2607] GET A WORK REG
	SKIPN PROFLG		;DOING PRIMARY PROTOCOL?
	RET			;NO. DON'T DO ANYTHING THEN
	MOVE Q2,A		;SAVE SUBROUTINE ADDRESS
	MOVSI Q1,-DTEN		;POLL ALL DEVICES
DTEAC0:	HRRZ A,Q1		;GET DTE NUMBER
	JE DTERL,(A),DTEAC1	;IF NOT ACTIVE, SKIP IT
	SKIPE SVVEXM		;NOW IN FORCED SECONDARY PROTOCOL?
	CAME A,MSTRDT		;YES. IS THIS THE MASTER -11?
	SKIPA B,A		;NO. COPY DTE NUMBER AND PROCEED
	JRST DTEAC1		;YES. SKIP IT THEN
	LSH B,SDTE		;GET EPT INDEX
	CALL 0(Q2)		;DO ROUTINE
	CALL DING11		;MAKE FE SEE IT
DTEAC1:	AOBJN Q1,DTEAC0		;LOOK AT ALL FE
	RET			;DONE

;SPECIAL ROUTINE TO INHIBIT "CONTINUED" MESSAGE

DTICON::MOVX A,1B0		;GET "FIRST-TIME" BIT
	ANDCAM A,UPFLAG		;NOT FIRST-TIME ANYMORE
	RET			;DONE
;THESE ROUTINES ALLOCATE AND DEALLOCATE REQUEST NODES
;ASGNOD   ACCEPTS NO ARGS. RETURNS:
;	+2 WITH A/ADDRESS OF NODE
;THIS MAY BLOCK IF NO NODES ARE AVAILABLE BUT IS GUARNATEED TO
;ALWAYS HAVE A NODE IF CALLED FROM PI LEVEL.
;ASGNDI IS THE ENTRY FOR PI LEVEL (NON DTE LEVEL). IF NO NODES
;ARE AVAILABLE, THIS WILL NOT BLOCK AND RETURN +1

;RELNOD  RELEASES A NODE
;ACCEPTS: A/THE NODE ADDRESS
;RETURNS +1 ALWAYS

	RESCD			;MUST BE RESIDENT
ASGNOD:	TDZA A,A		;ENTRY FLAG
ASGNDI:	SETO A,			;THIS ENTRY FLAG
	PUSH P,A		;SAVE A
	PUSH P,B		;SAVE B
ASGND1:	PIOFF			;PREVENT ALL INTS
	SKIPN A,COMH		;HAVE A NODE?
	JRST BLKNOD		;NO. GO WAIT
	HRRZ B,0(A)		;GET LINK TO NEXT
	HRRZM B,COMH		;MAKE NEW LINK
	SETZM 0(A)		;CLEAR HEADER
	PION			;ALLOW INTS AGAIN
PIASG:	POP P,B			;RESTORE B
	POP P,0(P)		;THROW AWAY FLAG
	RETSKP			;GOOD RETURN

BLKNOD:	PION			;ALLOW INTS AGAIN
	SKIPE -1(P)		;PI ENTRY?
	JRST [	POP P,B		;YES. GIVE UP
		POP P,A		;CLEAN UP THE STACK
		RET]		;AND DONE
	MOVEI A,SPCTST		;SCHEDULER TEST ROUTINE
	MDISMS			;WAIT HERE FOR A NODE
	JRST ASGND1		;GO TRY IT AGAIN

SPCTST::SKIPN COMH		;SCHEDULER TEST FOR NODE AVAILABLE
	JRST 0(4)		;NONE YET
	JRST 1(4)		;GOT ONE

RELNOD:	PUSH P,B		;GET WORK REG
	HRRZ B,COMH		; TOP OF QUEUE
	MOVEM B,0(A)		;MAKE LINK TO THIS NEW HEAD
	HRRZM A,COMH		;NEW HEAD
	POP P,B			;RESTORE WORK REG
	RET			;AND DONE
;THIS ROUTINE IS CALLED TO DEQUEUE AND POST ALL REQUESTS FOR
;A GIVEN DTE
;ACCEPTS:	A/ DTE #

CLRDTE:	JN DTERL,(A),R		;IF NOW ACITVE, IGNORE REQUEST
	ASUBR <DTENM>		;SAVE DTE NUMBER
CLRDT1:	SKIPN B,DTEQS(A)	;HAVE ANY REQUESTS?
	RET			;NO. ALL DONE
	HRRZS B			;YES. GET THE REQUEST
	HRRZS A			;GET DTE # ONLY
	CAMN A,MSTRDT		;IS THIS THE MASTER?
	JRST [	CALL TSTSGL	;SINGLE CHAR PACKET?
		 SKIPA		;IT IS
		JRST .+1	;NOT
		CALL DNSNGL	;HANDLE IT
		JRST CLRDT2]	;GO ON
	CALL DEQDTE		;AND DEQUEUE THIS REQUEST
CLRDT2:	MOVE A,DTENM		;GET BACK DTE NUMBER
	JRST CLRDT1		;AND GO GET NEXT ONE

;ENTRY TO ABOVE FOR NON-INTERRUPT CODE

CLRDT0:	NOSKED
	CHNOFF DLSCHN		;TURN OFF MACHINE
	CALL CLRDTE		;PROCESS QUEUES
	CHNON DLSCHN
	OKSKED			;TURN ON MACHINE
	RET			;AND DONE

;SPECIAL ENTRY FOR THE SCHEDULER

CLRDTF:	CHNOFF DLSCHN		;TURN OFF CHANNEL
	SETZRO DTERL,(A)	;MAKE IT DO IT
	CALL CLRDTE		;CLEAR OUT THE ENTRIES
	SETONE DTERL,(A)	;RESTORE BIT
	CHNON DLSCHN		;RESTORE CHANNEL
	RET			;AND DONE
;ROUTINE CALLED FROM APRSRV TO SEE IF A DTE CAUSED AN I/O
;PAGE FAIL.
;ACCEPTS:	A/ PAGE NUMBER OF FAULT
;RETURNS:	+1 NOT A DTE
;		+2 A DTE CAUSED IT. DTE IS SHUT OFF

DTEIOP::ACVAR <IOFLAD>		;PLACE TO SAVE PAGE NUMBER
	MOVEM A,IOFLAD		;SAVE PAGE NUMBER OF FAULT
	MOVSI D,-DTEN		;LOOP OVER ALL DTE'S
IOPLOP:	HRRZ A,D		;GET DTE NUMBER
;	JE DTERL,(A),IOPNXT	;IF NOT RUNNING, SKIP IT
	CAMN A,MSTRDT		;IS IT THE MASTER?
	JRST IOPNXT		;YES. CAN'T BE IT THEN
	LSH A,SDTE		;FIND DTE'S EPT
	LOAD B,VPGNO,DTEEBP(A)	;GET PAGE NUMBER OF TO -11 TRANSFER
	CAME B,IOFLAD		;IS IT THE OFFENDING PAGE?
	JRST IOPNXT		;NO

;FOUND A DTE THAT CAUSED IT

	LSH A,-SDTE		;GET BACK DTE NUMBER
	SETZRO DTERL,(A)	;NO LONGER RUNNING
	CALL DTREST		;TURN OFF THE DTE
	CALL CLRDTE		;GET RID OF ITS BLOCKS
	SETONE DTRLD,(A)	;AND SAY IT NEEDS RELOADING
	BUG (DTEPGF,<<A,D>>)
	AOS LOAD11		;SAY AN -11 DIED
	AOS JB0FLG		;MAKE JOB 0 SEE IT ASAP
	RETSKP			;AND DONE

;NOT THIS ONE. LOOK AT THE NEXT ONE

IOPNXT:	AOBJN D,IOPLOP		;DO THEM ALL
	RET			;DIDN'T FIND AN OFFENDING DTE
;**;[2607] Add one line at IOPNXT: +2L	JGZ	3-APR-82
	ENDAV.			;[2607] END ACVAR
;THIS ROUTINE PERFORMS LOST INTERRUPT POLLING FOR THE DTE20 DEVICES.
;IT IS STARTED PERIODICALLY TO LOOK FOR ANY ANAMOLOUS CONDITIONS
;ON THE DTE'S.

DTECHK::SKIPN FEFLG		;IN SECONDARY PROTOCOL?
	JRST DTCHK2		;NO, DON'T POLL THEN
	SAVEQ			;SAVE PERMANENT REGS
	STKVAR <PRCONI>		;PROTOTYPE CONI
	MOVSI A,-DTEN		;NUMBER OF DTE'S IN CONFIGURATION
	MOVE B,[CONI DTE0,D]	;THE CONI
	MOVEM B,PRCONI		;SAVE IT
DTPOL1:	JE DTERL,(A),DTPOL2	;DONT POLL NON-EX DEVICE
	HRRZ B,A		;GET DTE NUMBER
	JN DTRLD,(A),[	CAMN B,MSTRDT ;IS THIS THE MASTER?
			CALL CLRDTF ;YES. KEEP EVERYBODY MOVING
			JRST DTPL11] ;AND GO ON
	CAMN B,MSTRDT		;IS THIS THE MASTER?
	JRST [	XCT PRCONI	;YES. GET CONI BITS
		TXNE D,DTEPF	;POWER FAILING?
		JRST DTPOL2	;YES. DON'T POLL IT NOW THEM
		SKIPE FEDBSW##	;NO. WANT RELOADS?
		JRST DTPL10	;NO. DON'T LOOK THEN
		JRST .+1]	;YES. POLL IT
	CALL SETRGN		;GO FIND APPROPRIATE COMM REGIONS
	SUBI D,COMDAT		;GET POINTER TO -11'S OWNED AREA
	LOAD B,CMKAC,(D)	;GET HIS KEEP ALIVE COUNTER
	LOAD D,CMKAK,(C)	;GET MY COPY OF LAST ONE
	CAME B,D		;SAME?
	JRST DTPOL9		;NO. ALL IS OK
	JE DTKAC,(A),[		;IF FIRST TIME,LET HIM GO
		SETONE DTKAC,(A) ;BUT REMEMBER THIS TRANSGRESSION
		JRST DTPL10]	;AND GO ON
	HRRZ B,A		;ISOLATE DTE NUMBER
	CAME B,MSTRDT		;IS THIS THE MASTER?
	JRST [	CALL DTREST	;NO. RESET THE DTE
		CALL CLRDTF	;CLEAR OUT THE QUEUE NOW
		SETZRO DTERL,(A) ;AND TURN OFF PROTOCOL
		JRST .+1]	;AND MAKE RELOAD FORK RUN
	SETONE DTRLD,(A)	;NOT FIRST TIME. HE IS SICK
	AOS LOAD11		;TELL JOB 0 OF THE FIND
	AOS JB0FLG		;AND MAKE JOB 0 RUN NOW
DTPL11:	PUSH P,A		;SAVE DTE NUMBER
	MOVEI A,0(A)		;GET NUMBER ONLY
	MOVE B,CTYLNO		;GET # OF THE CTY
	CAMN A,MSTRDT		;IS THIS THE MASTER -11?
	JRST [	PUSH P,B	;YES. SAVE LINE NUMBER
		CALL STADYN	;POINT TO DYNAMIC DATA
		 SKIPA		;NOT ACTIVE. SHOULDN'T HAPPEN
		CALL [	CALL TTSOBE ;SEE IF BUFFER NOW EMPTY
			CALL TTCOBF ;NO. CLEAR IT
			RET]	;AND PROCEED
		POP P,B		;RESTORE LINE NUMBER
		JRST .+1]
	POP P,A			;RESTORE DTE #
	JRST DTPOL2		;FORGET ABOUT IT FOR NOW
DTPOL9:	STOR B,CMKAK,(C)	;KEEP THIS COPY FOR NEXT TIME
	SETZRO DTKAC,(A)	;IT PASSED THE TEST
	;..
;DTECHK...

;NOW LOOK AT ITS STATE
DTPL10:	CHNOFF DLSCHN		;PREVENT STATE CHANGES
	XCT PRCONI		;LOOK AT THE DTE STATE
	TRNE D,DLSCHN		;CHANNEL ASSIGNED?
	JRST DTCHK1		;YES. GO ON
	CALL DTPII		;GO SET UP PI STUFF
	HRRZ B,A		;ISOLATE DTE NUMBER
	BUG(DTELPI,<<B,D>>)
DTCHK1:
   REPEAT 0,<LOAD B,DTEST,(A)	;GET DEVICE'S STATE
	TXNN B,DTE11!DTE11I	;SENDING TO -11?
	JRST DTPOL3		;NO. GO ON
	CALL SETRGN		;FIND THE COMM REGIONS
	MOVE B,D		;MOVE HIS POINTER
	XCT PRCONI		;GET STATE OF DTE NOW
	LOAD Q1,CM1IC,(B)	;HIS TO 11 COUNT
	LOAD C,CM1IC,(C)	;MY TO 11 COUNT
	CAMN C,Q1		;SAME?
	JRST DTPOL4		;YES. GO SEE IF TRANSFER IS OK
	TXNE D,DTEEDB		;IS -11 DOORBELL UP?
	JRST DTPOL3		;YES. ASSUME IT WILL FIND IT
	CALL DING11		;RING IT AGAIN
	BUG(DTELDB)
	JRST DTPOL3		;GO TO NEXT

DTPOL4:	LOAD D,CMVRR,(B)	;GET PROTOCOL VERSION
	CAIN D,.VN20F		;RSX20F?
	JRST DTPOL3		;YES. DONE WITH POLLING THEN
	JN CMTOT,(B),DTPOL3	;IF IN TRANSIT, OK.
	XCT PRCONI		;GET DEVICE STATE AGAIN
	TXNE D,DTEEDN		;NOT IN TRANSIT. IS FLAG UP?
	JRST DTPOL3		;YES. ASSUME WE WILL SEE THE INTERRUPT
	BUG(DT11DN)
	PUSH P,A		;SAVE DTE POINTER
	CALL TO11DN		;GO FAKE THE INTERRUPT
	POP P,A			;RESTORE POINTER
   >				;END OF REPEAT 0

DTPOL3:	JN DTBLK,(A),[	SETZRO DTBLK,(A) ;CLEAR INDICATOR
			PUSH P,A	;SAVE AOBJN WORD
			MOVEI A,0(A)	;GET DTE NUMBER ONLY
			CALL DOFRGM ;IF BLOCKED. TRY NOW
			POP P,A	;RESTORE AOBJN POINTER
			JRST .+1] ;AND GO ON
	CHNON DLSCHN		;REENABLE CHANNEL
DTPOL2:	MOVX B,4B11		;NEXT DTE
	ADDM B,PRCONI		;NEXT DTE FOR THE CONI
	AOBJN A,DTPOL1		;DO ALL DTE'S
DTCHK2:	MOVEI A,^D5000		;NEXT CHECK IN 5 SECS
	MOVEM A,DTETIM		;TO THE TIME CELL
	RET			;AND DONE
;ROUTINE CALLED FORM JOB 0 TO SEE IF ANY DTE'S NEED ATTENTION

	SWAPCD			;PART OF JOB 0
DTEPOL::SKIPN A,LODFRK		;HAVE A FORK NOW?
	JRST DTPOL8		;NO
	RFSTS			;YES. GET ITS STATUS
	HLRZS A			;ONLY LH PLEASE
	CAIE A,2		;HALTED?
	CAIN A,3		;OR AN ERROR?
	SKIPA A,LODFRK		;YES
	JRST DTPOL8		;NO. GO ON
	KFORK			;KILL IT
	SETZM LODFRK		;AND THE HANDLE
	SETOM RLDFRK		;NO RELOAD FORK NOW
DTPOL8:	SKIPE LOAD11		;-11'S TO LOAD?
	SKIPE LODFRK		;YES. A FORK TO DO IT?
	JRST DTPOL7		;DON'T CREATE ANOTHER
	MOVX A,1B1		;SET CAPABILITIES TO WHEEL
	SETZ B,			;NO START ADDRESS
	CFORK			;GET ONE
	 JRST DTPOL7		;FAILED WAIT TILL NEXT TIME
	MOVEM A,LODFRK		;THE ID
	MOVEI B,RELOAD		;START ADDRESS
	MSFRK			;START IT IN MONITOR MODE
DTPOL7:	SKIPN LOAD11		;ALL -11'S DONE RELOADING?
	SKIPN A,UPFLAG		;DO WE NEED A CONTINUE MESSAGE?
	JRST DTPL87		;NO . GO ON THEN
	TRZN A,1		;WANT A MESSAGE?
	JRST DTPL87		;NO
	JUMPGE A,[MOVSI A,(1B0)	;IS FIRST TIME
		MOVEM A,UPFLAG	;NEXT TIME WILL DO IT
		JRST DTPL87]	;AND DONE
	MOVEM A,UPFLAG
	SETO A,			;SEND TO ALL
	HRROI B,[ASCIZ /
[DECsystem-20 continued]
/]
	TTMSG			;TELL THE WORLD
DTPL87:	SKIPE B,TAD11		;HAVE A TIME?
	CAMN B,[-1]		;?
	JRST DTPL88		;NO . GO ON
	DMOVE C,TAD11+1		;YES. GET REST OF IT
	IDCNV			;GET INTERNAL FORMAT
	 JRST DTPL89		;TIME IS BAD. INFORM HIM
	PUSH P,B		;SAVE THE TIME
	CALL LGTAD		;GET SYSTEM'S TIME
	POP P,B			;GET -11'S TIME
	MOVE D,DBUGSW		;GET THIS SWITCH
	CAME A,[-1]		;HAVE A TIME YET?
	CAIE D,2		;YES. ARE WE DEBUGGING ALSO?
	SKIPA			;NO. MUST CHECK THE TIME THEN
	JRST DTPL88		;YES. SKIP SETTING IT
	CAMLE A,B		;NO. NEED TO SET THE TIME?
	JRST DTPL89		;NO. SKIP SETTING IT
	MOVE A,B		;GET THE TIME
	STAD			;AND SET IT
	 JFCL
	JRST DTPL88		;GO DO REST
DTPL89:	MOVE A,MSTRDT		;TELL MASTER HE IS WRONG
	SETONE DT1TM,(A)	;TELL HIM NOW
DTPL88:	SETOM TAD11		;NO TIME
	SKIPE TO11TM		;TIME PACKET AVAILABLE?
	RET			;NO. NO SENSE LOOKING THEN
	SAVEPQ			;YES. SAVE ALL REGS
DTPOL6:	MOVE A,MSTRDT		;GET MASTER -11
	JE DT1TM,(A),DTPOL5	;-11 WANT TIME?
	SETZRO DT1TM,(A)	;SAY HE GOT IT
	;..
;DTEPOL...

;-11 WANTS TIME OF DAY AND PACKET IS FREE

	SETOM TO11TM		;IN USE
	SETO B,			;GET CURRENT LOCAL TIME
	SETZ D,			;SAY TO USE LOCAL TIME ZONE
	ODCNV			;""
	HLRZ A,B		;GET YEAR
	DPB A,[POINT ^D16,TO11TM,31] ;STORE YEAR
	MOVE P1,[POINT ^D8,TO11TM+1] ;WHERE REST IS GOING
	IDPB B,P1		;STORE MONTH
	HLRZ A,C		;GET DAY OF MONTH
	IDPB A,P1		;STORE IT
	IDPB C,P1		;DAY OF WEEK
	LOAD C,IC%TMZ,D		;GET TIMEZONE
	TXNE D,IC%ADS		;DST IN EFFECT?
	TRO C,1B28		;YES - SET FLAG
	IDPB C,P1		;STORE INDICATOR
	LSH D,-1		;DIVIDE SECONDS BY 2
	DPB D,[POINT ^D16,TO11TM+2,15];SECONDS SINCE MIDNIGHT
	MOVSI A,TM1DON		;POSTING ROUTINE
	HRR A,MSTRDT		;DTE NUMBER
	MOVSI B,.DFHTD		;HERE IS TIME FUNCTION
	MOVEI C,^D10		;NUMBER OF BYTES IN MESSAGE
	MOVE D,[POINT ^D8,TO11TM] ;BYTE POINTER
	CALL DTEQ		;Q THE REQUEST
	 JFCL			;WILL GO
DTPOL5:	RET			;AND DONE

	RESCD			;MUST BE RESIDENT
;ROUTINE TO POST TIME SENT TO -11

TM1DON:	SETZM TO11TM		;SAY TIME PACKET IS FREE
	RET			;AND DONE

;ROUTINE CALLED FROM STAD JSYS TO ARRANGE FOR TIME TO BE SENT TO
;ALL 11'S.

	SWAPCD			;IS SWAPPABLE
DTTIME::MOVSI A,-DTEN		;FORM AOBJN WORD
DTTIM2:	JE DTERL,(A),DTTIM1	;IF NOT EXISTANT, DON'T DO IT
	SETONE DT1TM,(A)	;SAY HE NEEDS THE TIME
DTTIM1:	AOBJN A,DTTIM2		;DO ALL DTE'S
	RET			;AND DONE
;ROUTINE CALLED BY JOB 0 TO COMPLETE A SYSERR PACKET.
;ARGS ARE:
;	1/ POINTER TO PACKET
;RETURNS +1 ALWAYS WITH REMAINDER OF INFO FILLED IN
;CALLS DEVICE DEPENDENT ROUTINES TO GET THE OWNING FORK. CALL IS
;	CALL DEVICE-DEPENDENT-ROUTINE
;WITH:
;	B/ UNIT,,DEVICE
;RETURNS:
;	+1/NO OWNING PROCESS (AT LEAST, NOT NOW)
;	+2/SUCCESS WITH 1=OWNING PROCESS ID

	SWAPCD			;IS SWAPPABLE

SEEER2:	HRRZ B,FE%DEV+SEBDAT(A)	;GET DEVICE CODE
	CAIL B,MINDEV		;A KNOWN DEVICE?
	CAILE B,MAXDEV		;?
	JRST SEEER6		;UNKNOWN
	SKIPE C,DTEDTV(B)	;HAVE A TRANSFER VECTOR?
	SKIPN C,DTVSER(C)	;THIS DEVICE PREPARED?
SEEER6:	JRST [	MOVSI C,(1B0)	;UNKNOWN BIT
		IORM C,FE%DEV+SEBDAT(A) ;SET IT
		JRST SEEER4]	;GO SAY NO FORK,,JOB
	PUSH P,A		;SAVE BLOCK
	CALL 0(C)		;GET INFORMATION
	 JRST [	POP P,A		;CLEAN UP THE STACK
		JRST SEEER4]	;AND ASSUME UNKNOWN
	MOVE B,A		;FORK #
	POP P,A			;BLOCK
	CAIN B,-1		;UNASSIGNED?
	JRST [	HRLS B		;YES. PROPOGATE THE -1
		MOVEM B,FE%FJB+SEBDAT(A) ;SAY IS UNASSIGNED
		JRST SEEER5]	;AND GO WRAP UP
	HLRZ C,FKJOB(B)		;GET JOB #
	HRLI C,0(B)		;FORK
	MOVEM C,FE%FJB+SEBDAT(A);STORE IN BLOCK
	MOVE B,JOBDIR(C)	;GET DIRS
	HRLI B,USRLH		;SET UP A USER NUMBER
	MOVEM B,FE%DIR+SEBDAT(A);TO THE BLOCK
	MOVE B,JOBPNM(C)	;GET NAME
	MOVEM B,FE%NAM+SEBDAT(A);TO THE BLOCK
SEEER5:	MOVEI B,FE%INF		;START OF ERROR WORDS
	HRRM B,FE%PTR+SEBDAT(A);TO THE BLOCK
	SETZM FE%ID+SEBDAT(A)	;NO VERSION NUMBER YET
	RET			;AND DONE

SEEER4:	MOVE C,[-2,,-2]		;UNASSIGNED
	MOVEM C,FE%FJB+SEBDAT(A);SAY SO
	JRST SEEER5		;GO FINSISH THE SETUP
;THIS CODE IS A COLLECTION OF SUBROUTINES USED TO RELOAD AN -11.

;ROUTINE TO INITIATE ROM BOOT AND OPTIONALLY DUMP OR LOAD THE -11
;ACCEPTS:	A/FLAGS,, DTE #
;FLAGS ARE: GRONK/DON'T GRONK ROM
;		B/ COROUTINE ADDRESS FOR DUMPING
;		  IF B=0, NO DUMP
;		C/ COROUTINE ADDRESS TO GET NEXT PAGE TO LOAD
;		 IF C=0 NO LOAD WILL BE DONE
;		D/ ERROR ROUTINE IF LOAD OR DUMP FAILED (FOR UNLOCKING PAGES)

;RETURNS:	+1 FAILED. A CONTAINS THE CODE FOR THE FAILURE
;				-1 MEANS NO SUCH DTE
;		+2 SUCCESS. DUMP IS TAKEN AND BOOT IS ACTIVATED
;NOTE: THIS ROUTINE MUST HAVE RESET THE DTE AND INTERLOCKED THE
;BOOT LOCK
;NOTE SOME MORE: THE COROUTINES ARE CALLED WITH THE Q REGISTERS
;INTACT. THAT IS, Q1,Q2, AND Q3 WILL HAVE WHAT THE CALLER OF
;RMGRNK PUT IN THEM. THIS IS USEFUL FOR PASSING ARGS TO THE COROUTINES

;COROUTINES WORK AS FOLLOWS:
;RETURNS	+1 IF NO MORE TO DO. AC1=0 SAYS NO EXTRA DOORBELL
;		+2 MORE TO DO. IF LOADING, AC1 CONTAINS BYTE POINTER
;			TO NEXT CHUNK OF CORE TO LOAD
;			AND AC2 CONTAINS A ZERO IF NO DOORBELL
;			WANTED AFTER BYTE POINTER IS SET UP. IF DUMPING,
;			AC1 CONTAINS COUNT OF BYTES TO DUMP, AND
;			AC2 CONTAINS BYTE POINTER.

	SWAPCD			;IS SWAPPABLE
;**;[1739] Add several lines before RMGRNK: +0L	JGZ	11-JUN-80
RMGRNC:	CALL RMGRNK		;[1739]DO ACTUAL WORK
	 JRST [	CAMN	T1,[-1]	;[1739]-1 IS SPECIAL
		 RET		;[1739]JUST RETURN ON IT
		JFFO T1,RMGLIT	;[1739]WHICH ERROR BIT IS SET?
		SKIPA		;[1739]NO ERROR BITS SET
	       RMGLIT: CAILE T2,NBOTER ;[1739]MORE ERROR TYPES THAN KNOWN?
		MOVEI T2,NBOTER ;[1739]YES, SET ERROR TO BE MOST GENERAL
		MOVE T1,BOTERR(T2) ;[1739]GET ERROR CODE
		RET]		;[1739]BAD RETURN
	RETSKP			;[1739]GOOD RETURN

BOTERR:	BOTX06			;[1739]ERROR CODES ADDED TO MONSYM
	BOTX07
	BOTX08
	BOTX09
	BOTX10
	BOTX11
	BOTX12
	BOTX13
	BOTX14
	BOTX15
	BOTX16
	BOTX17
	BOTX18			;[1739]GENERAL BOOT ERROR CODE
NBOTER==.-BOTERR-1		;[1739]NUMBER IN TABLE

RMGRNK:	SAVEP			;GET PERM REGISTERS
	MOVEI P1,3		;MAX TRIES
	SETZ P2,		;NO ERRORS YET
	ASUBR <RMDTE,RMJFN,RMCORT,RMERR>
	TXNN A,RM%ROM		;WANT TO GRONK ROM?
	JRST RMWAT1		;NO. SEE ABOUT DUMPING THEN
RMGRN1:	HRRZ A,RMDTE		;GET DTE NUMBER AGAIN
	CALL DTREAL		;GO VERIFY DTE EXISTS
	 JRST [	SETOM T1	;NO SUCH DTE
		RET ]		;RETURN FAILURE
	MOVE B,DATO(A)		;GET DATAO WORD
	IORI B,C		;DATA IS IN C
	SETZM C			;CLEAR BYTE COUNT REG
	XCT B			;DO IT
	MOVE B,CNDO(A)		;GET PROTOTYPE CONO
	IORI B,DTEPIE		;FIRST, TURN OFF PI0 TO RESET THE DTE
	XCT B			;""
	IORI B,DTESER!DTEPIE!DTEPI0 ;THE RELOAD INDICATOR AND PI
	XCT B			;SET THE RELOAD INDICATOR
	MOVEI B,PWRDN1		;TIME TO COMPLETE POWER-FAIL
	ADD B,TODCLK		;ABSOLUTE TIME WHEN IT IS OVER
	CAML B,TODCLK		;READY?
	JRST .-1		;NO. KEEP WAITING

;ROM SHOULD BE READY FOR US NOW

	MOVE B,CNDO(A)		;GET A CONO WORD AGAIN
	IORI B,DTECER		;CLEAR RELOAD BIT
	XCT B			;TURN OFF RELOAD
	; ..
	; ..
;NOW PUT A MAGIC NUMBER IN BYTE COUNT REGISTER SO ROM CAN FIND US

	MOVE B,A		;GET DTE NUMBER
	LSH B,SDTE		;GET TO EPT OFFSET
	SETZM DTETBP(B)		;CLEAR TO -10 BYTE POINTER WORD
	MOVE B,DATO(A)		;GET A DATAO WORD
	IORI B,C		;MAGIC NUMBER WILL BE IN C
	MOVEI C,MAG11N		;THE MAGIC NUMBER
	XCT B			;DO IT
	CALL DING11		;AND RING -11'S DOORBELL
	MOVE P3,[CONSO DTE0,DTEEDB] ;TEST WORD
	LSH A,^D26		;POSITION DTE #
	ADD P3,A		;GET PROPER I/O WORD
	HRRZ A,RMDTE		;RESTORE A
	MOVEI B,ROMTIM		;TIME FOR ROM TO MAKE IT
	ADD B,TODCLK		;ABSOLUTE TIME
RMWAT0:	XCT P3			;IS DOORBELL STILL UP?
	JRST RMWAT1		;NO. ROM RESPONDED
	CAML B,TODCLK		;IS TIME UP YET?
	JRST RMWAT0		;NO. TRY AGAIN
	TXO P2,.R1RMF		;NO ROM RESPONSE
RMTRY:	MOVX A,RM%ROM		;MAKE SURE WE CAN RETRY
	TDNE A,RMDTE		;CAN WE REGRONK ROM?
	SOJG P1,RMGRN1		;YES, GO TRY AGAIN
RMTRY1:	HRRZ A,RMDTE		;ERROR-- GET BACK DTE #
	CALL DTREST		;RESET DTE PI0 ENABLE
	MOVE A,P2		;GET ERROR INIDCATION
	RET			;AND RETURN FAILURE
;ROM IS PROPERLY INITIALIZED HERE. TRY DOING THE BOOT

RMWAT1:	SETZ P4,		;INIT COROUTINE COUNTER
RMWAT2:	SKIPN B,RMJFN		;A DUMP ROUTINE GIVEN?
	JRST RMLOAD		;NO. DON'T DO THE DUMP THEN
	MOVEI A,0(P4)		;ARG TO COROUTINE
	CALL 0(B)		;CALL THE DUMP COROUTINE
	 JRST [	SETZM RMJFN	;DON'T DO DUMP ON RETRY
		CALL CHKBEL	;SEE IF A BELL IS NEEDED
		JRST RMLOAD]	;AND GO SEE ABOUT LOADING

;COROUTINE RETURNED WITH:
;		A/ COUNT OF WORDS TO DUMP
;		B/ BYTE POINTER TO USE

	MOVE C,A		;PUT COUNT INTO C
	HRRZ A,RMDTE		;GET DTE NUMBER
	CALL DODUMP		;TRY DUMPING THIS BUNCH
	 JRST [	TXO P2,.R1DPF	;DUMP ABORTED
		TDO P2,A	;ADD IN BITS FROM DODUMP
		SETO A,		;SAY FAILURE IS FROM THE DUMP
		SKIPE B,RMERR	;WANT ERROR POSTING?
		CALL 0(B)	;YES. DO IT
		SKIPN RMCORT	;WANT TO LOAD IT TOO?
		JRST RMTRY1	;NO. ERROR OUT NOW THEN
		SETZM RMJFN	;DON'T TRY DUMP AGAIN
		JRST RMTRY]	;AND TRY, TRY AGAIN
	AOJA P4,RMWAT2		;GO DO NEXT PIECE OF DUMP


;ROUTINE CALLED BY DUMP AND LOAD CODE TO SEE IF A BELL IS NEEDED
;AFTER COMPLETION.
;ACCEPTS:	A/ 0 => NO BELL
;		RMDTE CONTAINS DTE NUMBER

CHKBEL:	JUMPE A,R		;IF NO BELL NEEDED, RETURN
	HRRZ A,RMDTE		;GET DTE NUMBER
	CALLRET DING11		;AND GO RING THE BELL
;-11 IS NOW DUMPED. SEE IF A LOAD IMAGE IS NEEDED

RMLOAD:	SETZ P4,		;ARG TO COROUTINE
RMLOD0:	SKIPN B,RMCORT		;HAVE A ROUTINE TO DO?
	RETSKP			;NO. RETURN
	HRRZ A,RMDTE		;GET DTE NUMBER
	MOVE C,CNDO(A)		;GET A CONO WORD
	IORI C,DTEEDN		;GET TEST BITS
	XCT C			;TURN OFF TEST BITS
	MOVE A,P4		;TELL COROUTINE WHICH CALL THIS IS
	CALL 0(B)		;GO GET NEXT PAGE
				;RETURNS A=EXEC VIRT ADDRESS
				; B=0 IF NO DOORBELL AFTER SETUP
	 JRST [	CALL CHKBEL	;SEE IF BELL IS NEEDED
		RETSKP]		;AND DONE
	MOVE C,A		;SAVE POINTER
	HRRZ A,RMDTE		;GET DTE NUMBER AGAIN
	LSH A,SDTE		;FIND THE EPT
	MOVEM C,DTEEBP(A)	;PUT CORRECT BYTE POINTER IN EPT
	HRRZ A,RMDTE		;DTE AGAIN
	SKIPE B			;WANT A DOORBELL AFTER SETUP
	CALL DING11		;GO START TRANSFER
	MOVEI B,BUTTIM		;TIME FOR THE PAGE TO CLEAR
	ADD B,TODCLK		;WHEN IT MUST BE DONE
	MOVE P3,CNDO(A)		;GET A CONO WORD
	TXO P3,<<CONSO 0>-<CONO 0>+DTEEDN+DTEEER> ;MAKE IT A CONSO WORD
RMDNL1:	XCT P3			;DONE YET?
	JRST [	CAML B,TODCLK	;NO. TIME UP?
		JRST RMDNL1	;NO. KEEP WAITING
		CALL CLR11B	;YES. CLEAR BYTE POINTER
		TXO P2,.R1BSF	;ERROR CODE
		JRST RMLERR]	;AND GIVE ERROR
	TXZ P3,DTEEDN		;FINISHED. SEE IF SUCCESSFUL
	CALL CLR11B		;CLEAR BYTE POINTER
	XCT P3			;WAS IT AN ERROR
	AOJA P4,RMLOD0		;NO, GO SEE IF MORE LOAD WANTED
	TXO P2,.R111E		;SAY ERROR
RMLERR:	SETZ A,			;SAY ERROR OCCURRED ON LOAD
	SKIPE B,RMERR		;WANT ERROR NOTICE?
	CALL 0(B)		;YES. DO IT
	JRST RMTRY		;GO TRY WHOLE THING AGAIN

;LOCAL ROUTINE TO CLEAR TO -11 BYTE POINTER IN THE EPT.

CLR11B:	SAVEAC <A>		;SAVE ALL REGS
	HRRZ A,RMDTE		;GET DTE #
	LSH A,SDTE		;COMPUTE EPT REGION FOR THIS DTE
	SETZM DTEEBP(A)		;ZERO THE BYTE POINTER
	RET			;AND DONE
;PROCESS RUN BY JOB 0 TO RELOAD THE MASTER -11.

	SWAPCD			;IS SWAPPABLE

RELOAD:	MOVE P,UPP		;GET PROPER STACK
	MCENTR			;ENTER MONITOR CONTEXT
	MOVE A,FORKX		;GET OUR FORK HANDLE
	MOVEM A,RLDFRK		;AND REMEMBER IT FOR LATER
	MOVX A,RLDPRI		;GET SPECIAL PRIORITY WORD FOR RELOAD
	MOVEM A,JOBBIT		;FOR REMAINDER OF RELOAD
RELOD2:	MOVE A,MSTRDT		;GET ID OF MASTER
	JN DTRLD,(A),RELOD1	;FOUND ONE
	MOVSI A,-DTEN		;NOW CHECK ALL OF THE OTHERS AS WELL
RELOD3:	JE DTRLD,(A),RELOD4	;THIS ONE NEED ATTENTION?
	HRRZ B,A		;YES, GET DTE # ONLY
	CAMN B,MSTRDT		;DID THE MASTER DIE AGAIN?
	JRST RELOD1		;YES. GO DO IT NOW
	PUSH P,A		;NO.
	BUG (DN20ST,<<B,D>>)
	LSH B,SDTE		;GET EPT OFFSET
	SETZM DTEEPW(B)		;CLEAR "VALID EXAMINE"
	CALL CLRDT0		;CLEAR OUT THE QUEUES
	CALL RELODR		;INFORM APPROPRIATE MONITOR ROUTINES
	POP P,A			;GET BACK REG
	SETZRO <DTRLD,DTKAC>,(A) ;TURN OFF ATTENTION BITS
RELOD4:	AOBJN A,RELOD3		;SCAN THEM ALL
	SETZM LOAD11		;ALL DONE
	AOS JB0FLG		;MAKE JOB 0 SEE HALTED STATE ASAP
	HALTF			;NONE LEFT. ALL DONE
;RELOAD MASTER -11. REGISTER USAGE AS FOLLOWS:
;	Q1/ OFN,,JFN OF DUMP FILE (PASSED TO RELODD BY RMGRNK)
;	Q2/ -11 ERROR WORDS RETURNED BY RELODD IF DUMP SUCCEEDED
;	Q3/ CUMULATIVE ERROR REGISTER
;	P5/ RETRY COUNT

RELOD1:	SETZRO DTERL,(A)	;BE SURE NOT RUNNING A PROTOCOL
	CALL CLRDT0		;FLUSH SCHEDULING QUEUE
	SETZB Q3,Q2		;CLEAR STATUS AND ERROR WORDS
	MOVE A,MSTRDT		;GET BACK DTE #
	MOVEI P5,3		;MAX TRIES
	CALL FNDFIL		;GO GET JFN AND OFN FOR THE DUMP FILE
	 JRST [	TXO Q3,.R1DPF	;THE DUMP WON'T BE DONE
		SETZ P1,	;NO JFN
		JRST .+1]	;GO INLINE
	HRR Q1,P1		;Q1 NOW HAS OFN,,JFN

;READY TO GRONK THE ROM.

RELODA:	MOVEI B,RELODD		;DUMP COROUTINE
	CAIN P5,3		;IS THIS THE FIRST TIME?
	SKIPN P1		;HAVE A JFN FOR DUMPING?
	SETZ B,			;NO. DON'T DO THE DUMP THEN
	MOVEI C,RELODL		;ADDRESS OF LOAD ROUTINE
	MOVEI D,RELODE		;ERROR ADDRESS
	TXO A,RM%ROM		;MUST DO ROM BOOT
	SETZM DTECMD		;CLEAR SECONDARY PROTOCOL COMMAND WORD
	CALL RMGRNK		;GO GRONK THE ROM
RELODF:	 JRST [	MOVE Q3,A	;SAVE ERROR FLAGS
		SOJG P5,RELODA	;TRY AGAIN, MAYBE
		MOVE A,MSTRDT	;THE DTE NUMBER
		CALL RELOD7	;GO DO SYSERR
		AOS JB0FLG	;MAKE JOB 0 RUN NOW
		MOVEI A,^D1000
		DISMS		;WAIT HERE FOR IT TO RUN AND DO SYSERR
		AOS SHLTW	;AND STOP SYSTEM
		HALTF]		;DONE
	; ..
	; ..
;RELOAD OF THE -11 IS NOW IN PROGRESS. DO PROTOCOL INIT

	MOVE A,MSTRDT		;THE -11 NUMBER
	CALL KILPAG		;GO PURGE THE BUFFER PAGE
	MOVSI D,(<CONSO DTE0,>) ;GET A CONSO WORD
	MOVE A,MSTRDT		;THE -11 NUMBER
	LSH A,^D26		;PSOITION IT
	ADD D,A			;THE WORD
	MOVE A,MSTRDT		;DTE # AGAIN
	IORI D,DTETDB		;SET UP TO WAIT FOR A DOORBELL
	MOVEI B,DRBTIM		;TIME TO WAIT FOR RELOAD TO COMPLETE
	ADD B,TODCLK		;WHEN WAIT IS UP
RELD11:	XCT D			;WAIT
	JRST [	CAML B,TODCLK	;WAIT SOME MORE?
		JRST RELD11	;YES
		TXO Q3,.R1NRL	;NO RELOAD
		SOJG P5,RELODA	;SEE IF WE SHOULD TRY AGAIN
		MOVE A,Q3	;FLAGS
		JRST RELODF]	;NO. FAIL!!!!!!
	CALL DTREST		;GO RESET THE DTE
	MOVEI B,.VN20F		; FOR RSX20F PROTOCOL
	CALL DTINIT		;GO INIT THE COMM REGIONS
	CALL RELOD7		;GO DO SYSERR
	MOVE A,MSTRDT		;RECOVER DTE NUMBER
	JN DTRLD,(A),RELOD2	;IF WANTS RELOAD AGAIN, GO DO IT NOW
	CALL RELODR		;INFORM REST OF MONITOR
	MOVX A,GJ%OLD!GJ%SHT!GJ%PHY
	HRROI B,SETSPD
	SETZ C,			;C/OFFSET IN ENTRY VECTOR
	CALL RUNDII		;GO SET DEFAULT SPEEDS AGAIN
	 JFCL			;CAN'T HELP IT
	SKIPN C,KLIDTA		;HAVE ANY KLINIK DATA?
	JRST RELOD2		;NO,GO WRAP UP
	HRRZ A,MSTRDT		;YES. GET I.D. OF MASTER
	MOVSI B,.DFKLS		;GET FUNCTION TO SEND KLINIK DATA
	MOVE D,[POINT ^D8,KLIDTA+1] ;GET KLINIK DATA BASE POINTER
	CALL DTEQ		;GO SEND THE KLINIK DATA
	 JFCL			;WILL GO
	JRST RELOD2		;AND GO WRAP UP
;ROUTINE OF RELOAD TO INFORM APPROPRIATE MONITOR DRIVERS OF THIS RELOAD.
;	A/ DTE #

RELODR:	HRRZS A			;GET DTE #
	ASUBR <DTENBR>		;SAVE DTE NUMBER
	CALL SETRGN		;FIND COMM REGIONS
	LOAD B,CMVRR,(C)	;GET PROTOCOL VERSION #
	CAIE B,.VN20F		;RSX20F PROTOCOL?
	CALLRET DEDMCB		;NO. INFORM NSP OF DEAD FRONT-END
	MOVSI P5,MINDEV-MAXDEV+.FECTY ;TO SEARCH DTEDTV
	HRRI P5,.FECTY+1	;START AFTER CTY
RLODR1:	MOVE A,DTENBR		;GET DTE #
	SKIPE B,DTEDTV(P5)	;THIS DEVICE EXIST?
	SKIPN B,DTVRLD(B)	;YES. WANT TO KNOW ABOUT RELOADS?
	SKIPA			;NO
	CALL 0(B)		;YES. TELL HIM
	AOBJN P5,RLODR1		;DO ALL DEVICES
	RET			;AND DONE
;COROUTINES OF RMGRNK TO DO LOADING OF -11


;COROUTINE TO LOAD BOOTSTRAP

RELODL:	JUMPG A,[CALL UNLPAG	;IF NOT FIRST TIME, UNLOCK PAGE
		CALLRET RTRUE]	;AND GET A FINAL BELL
	CALL LOKPAG		;GO LOCK DOWN BOOT PAGE
	MOVE B,[DTERBT,,DTERBT+1]
	SETZM DTERBT		;SET UP TO CLEAR REBOOT PAGE
	BLT B,DTERBT+1_PGSFT-1	;ZAP THE WHOLE PAGE
	MOVE A,MSTRDT		;GET DTE NUMBER
	CALL CLRBEL		;TURN OFF TO -10 DOORBELL
	CALL SETRGN		;FIND COMM REGIONS
	DMOVE A,[12700,,0	; MOVE #0,R0
		137,,173034]	; JMP 173034 (A MAGIC ADDRESS)
	LOAD C,CMRLF,(C)	;GET RELOAD FLAGS
	TXZ C,7			;TURN OFF RELOAD -10 FLAGS
				; AND SWITCH REGISTER REQUEST
	HRRI A,4(C)		;TO THE BOOT PROGRAM
				; AND TURN ON NO -10 REBOOT BIT
	DMOVEM A,DTERBT		;TO THE PAGE
	TXNE A,DSK11		;IS THIS AN RP REBOOT?
	JRST [	MOVE B,[DSKRBT,,DTERBT] ;YES. MOVE PORT CONTENTION
				; CODE IN FIRST
		BLT B,DTERBT+DSKPSZ-1 ;MOVE IT ALL
		HRRM A,DTERBT	;STICK IN THE UNIT STUFF
		JRST .+1]	;ALL READY TO GO
	MOVE A,[POINT ^D18,DTERBT] ;GET POINTER TO BOOT CODE
	SETO B,			;AND RING DOORBELL AFTER SETUP
	RETSKP			;AND GO BOOT IT

;ROUTINE TO LOCK DOWN DTERBT

LOKPAG:	NOINT			;NO INTERRUPTS WITH LOCK LOCKED
	LOCK BTLOCK		;LOCK THE BOOT PAGE
	MOVEI A,DTERBT		;THE PAGE
	MOVES 0(A)		;CREATE IT
	CALL FPTA
	CALL MLKPG		;AND LOCK IT
	RET			;DONE

;ROUTINE TO UNLOCK DTERBT

UNLPAG:	MOVEI A,DTERBT		;ADDRESS OF THE PAGE
	CALL FPTA		;GET ID
	CALL MULKPG		;GO DO IT
;DN20'S WON'T LOAD WITH THE FOLLOWING LINE
;	CALL KILPAG		;CLEAN UP ADDRESS SPACE
	UNLOCK BTLOCK		;NO LONGER OWN PAGE
	OKINT			;PERMIT INTERRUPTS AGAIN
	RET			;RETURN

;ERROR ROUTINE

RELODE:	CALL UNLPAG		;FREE THE PAGE
	RET			;AND DONE
;COROUTINE TO PERFORM THE DUMP OF THE MASTER -11
;ARGS:	Q1/ OFN,,JFN OF THE DUMP FILE
;	A/PAGE NUMBER

RELODD:	ASUBR <PAGENO>		;THE ARG TO THIS COROUTINE
	JUMPE A,[CALL LOKPAG	;IF FIRST TIME, LOCK DOWN PAGE
		JRST RELDD1]	;AND GO PROVIDE ARGS

;NOT THE FIRST TIME. DTERBT CONTAINS GOOD DATA, AND A CONTAINS PAGE NUMBER

	CAIN A,1		;IS THIS THE FIRST 1 K OF -11 MEMEORY?
	MOVE Q2,DTERBT		;YES. GET CODE FOR SYSERR
	NOINT
	CALL ASGPAG		;GET A WORK PAGE FOR THIS
	 JRST [	OKINT		;FAILED. ALLOW INTS AGAIN
		JRST RELODE]	;AND GIVE ERROR
	PUSH P,A		;SAVE CORE ADDRESS
	HLL A,Q1		;OFN OF THE FILE
	HRR A,PAGENO		;PAGE NUMBER OF THE FILE
	SOS A			;PAGE NUMBER FOR THE DUMP FILE
	MOVE B,0(P)		;THE TEMP PAGE WE JUST GOT
	TXO B,PA%WT!PA%RD	;NEED ACCESS
	CALL SETMPG		;MAP THE FILE TO THE PAGE
	MOVSI B,DTERBT		;WHERE THE DATA IS
	HRR B,0(P)		;THE DESTINATION
	POP P,A			;AGAIN
	BLT B,777(A)		;MOVE THE DATA
	CALL RELPAG		;RELEASE AND UNMAP THE PAGE
	OKINT			;ALLOW INTS AGAIN
	MOVE A,PAGENO		;THE PAGE NUMBER
	CAIL A,^D28		;DONE ALL OF CORE?
	JRST RELODC		;YES. GO CLOSE FILE
RELDD1:	MOVEI A,2000		;COUNT OF BYTES
	MOVE B,[POINT ^D18,DTERBT] ;WHERE TO DO NEXT DUMP
	RETSKP			;GO DO IT

;DUMP IS DONE. CLOSE FILE

RELODC:	HRRZ A,Q1		;THE JFN
	TXO A,1B0		;DON'T RELEASE THE JFN
	CLOSF			;CLOSE IT
	 JFCL
	CALL UNLPAG		;GO UNMAP THE PAGE
	CALLRET RFALSE		;AND SAY NO BELL NEEDED
;ROUTINE TO GET JFN AND OFN FOR THE DUMP FILE
;INPUT:	A/ DTE NUMBER
;RETURNS: +1 /FAILURE. CONDITION BIT ON IN Q3
;	  +2/ SUCCESS. P1/THE JFN  Q1/ OFN,,

FNDFIL:	SAVET			;SAVE TEMPS
	HRROI B,DTERBT		;WHERE TO FORM THE NAME
	MOVEI D,"0"(A)		;FIRST BYTE IS -11 NUMBER
	SETZ C,			;TERMINATE ON NULL
	HRROI A,[ASCIZ /<SYSTEM>/] ;PUT FILE IN SYSTEM
	SIN			;COPY STIRNG
	IDPB D,B		;PUT IN -11 NUMBER
	HRROI A,[ASCIZ /DUMP11.BIN;P770000/]
	SIN			;COPY REST OF NAME
	IDPB C,B		;TIE IT OFF
	MOVX A,GJ%FOU!GJ%PHY!GJ%SHT ;GTJFN BITS
	HRROI B,DTERBT		;THE ADDRESS OF THE FILE PAGE
	GTJFN			;GET A JFN
	 JRST [	TXO Q3,.R1GTF	;GTJFN FAILED
		RET]		;AND GIVE UP
	MOVEI P1,0(A)		;SAVE JFN
	HRLI A,.FBBYV		;SET UP TO CHANGE BYTE SIZE
	MOVX B,7777B11		;SET RETENTION AND BYTE SIZE
	MOVX C,0044B11		;SET RETENTION TO INFINITE
	CHFDB			;CHANGE IT
	ERJMP FNDFL1		;FAILED. PUNT IT
	HRLI A,.FBSIZ		;EOF POINTER
	SETO B,			;CHANGE WHOLE WORD
	MOVEI C,^D28*^D512	;SET TO 28 PAGES
	CHFDB			;DO IT
	ERJMP FNDFL1		;FAILED. PUNT IT
FNDFL1:	MOVE B,[440000+OF%WR]	;OPEN CONDITIONS
	MOVEI A,0(P1)		;GET JFN AGAIN
	OPENF			;OPEN THE FILE
	 JRST [	TXO Q3,.R1OPF	;OPENF FAILED
		RET]		;GIVE IT UP
	HRLZS A			;JFN TO LH
	CALL JFNOFN		;GET THE OFN
	 JRST [TXO Q3,.R1OPF	;OPENF FAILED
		RET]
	MOVE Q1,A		;SAVE THE OFN
	RETSKP			;MADE IT
;THIS ROUTINE PERFORMS THE ACTUAL DUMP OF THE -11. INPUT IS:
;	A/ DTE NUMBER
;	B/ BYTE POINTER TO USE FOR THE DUMP
;	C/ FLAGS AND COUNT OF WORDS TO DUMP
;		COUNT IS RIGHTMOST 12 BITS (DTEBYC)
;		FLAGS:	DTETI (SET "I" BIT ON TRANSFER)
;RETURNS:
;	+1/ FAILED. CONDITION SET IN A
;	+2/ SUCCESS

DODUMP:	SAVEPQ			;SAVE ALL REGS
	MOVE D,[CONSO DTE0,DTETDN!DTETER] ;DTE CONDITIONS
	MOVE P3,DATO(A)		;GET A DATAO FOR THIS DTE
	MOVE Q3,CNDO(A)		;GET A CONO WORD
	IORI Q3,DTETDN		;TO SET UP PROPER STATE
	IORI P3,A		;ARG WILL GO IN A
	LSH A,^D26		;POSITION DTE NUMBER
	ADD D,A			;FORM HARDWARE TEST WORD
	LSH A,-^D26+SDTE	;FORM EPT INDEX
	MOVEM B,DTETBP(A)	;PUT BYTE POINTER IN EPT
	XCT Q3			;TURN OFF ALL TO -10 INDICATORS

;GO GET THE CORE

	MOVE B,C		;COPY BYTE COUNT AND "I" BIT
	MOVN A,C		;GET NEG OF COUNT
	ANDI A,DTEBYC		;ONLY 12 BITS
	TXNE B,DTETI		;WANT "I" BIT SET ?
	TXO A,DTETI		;YES, SET "I" BIT
	XCT P3			;DO THE DATAO
	MOVEI B,T10TIM		;TIME FOR IT TO COMPLETE
	ADD B,TODCLK		;WHEN WAIT IS UP
DOPAG1:	XCT D			;WAIT FOR IT TO COMPLETE
	JRST [	CAML B,TODCLK	;WAIT SOME MORE?
		JRST DOPAG1	;YES. GO DO IT
		SETZ A,		;NO. ASSUMED IT WON'T FINISH
		XCT P3		;ABORT TRANSFER
		JRST DMPERR]	;AND GO MARK ERROR
	TXZ D,DTETER		;SEE IF IT WAS ERROR OR NORMAL DONE
	XCT D			;""
	JRST DMPERR		;WAS AN ERROR. BAD NEWS
	TXO D,DTETER		;RESTORE THIS
	XCT Q3			;TURN OFF DONE FLAGS
	RETSKP			;DUMP IS DONE

;ERROR DOING THE DUMP

DMPERR:	XCT Q3			;RESET THE DTE
	MOVX A,.R110E		;RETURN ERROR
	RET			;DONE
;ROUTINE TO MAKE SYSERR ENTRY FOR -11 RELOAD. INPUT IS:
;	A/ DTE NUMBER
;	P1/ JFN
;	P3/ RETRY COUNT
;	Q2/ -11 ERROR WORDS
;	Q3/ STATUS

RELOD7:	TRVAR <DTNOM,SYBLK,ER11,<FILESP,^D20>> ;FOR SYSERR INFO
	MOVEM Q2,ER11		;SAVE -11 ERROR WORDS
	MOVEM A,DTNOM		;SAVE DTE NUMBER
	MOVEI A,R1%LEN		;SIZE OF PACKET
	MOVEI B,R1%SIZ		;LENGHT (INCLUDING STIRNGS)
	CALL ALCSEB		;ALLOCATE A BLOCK
	 JRST [	MOVE A,DTNOM
		RET]		;DONE
	MOVEM A,SYBLK		;SAVE BLOCK
	MOVEI B,3		;MAX TRIES
	SUBM B,P5		;NUMBER OF TRIES
	IOR P5,Q3		;FORM FINAL STATUS WORD
	MOVE B,[-4,,[		;TO DO THE COPIES
		SEBPTR 0,SBTEVC,SEC%11 ;CODE
		SEBPTR R1%NUM,SBTWD,DTNOM ;-11 NUMBER
		SEBPTR R1%STS,SBTWD,P5 ;STATUS
		SEBPTR R1%ERW,SBTWD,ER11]] ;-11 ERROR WORDS
	MOVE A,SYBLK		;BLOCK ADDRESS
	CALL SEBCPY		;COPY THE DATA
	 JFCL
	TXNE Q3,.R1DPF		;DID THE DUMP SUCCEED?
	JRST RELOD9		;NO. GO ON
	MOVEI B,0(P1)		;YES. GET JFN
	HRROI A,FILESP		;A BUFFER FOR THE FILE NAME
	MOVE C,[11110,,10011]	;JFNS BITS
	JFNS			;GET THE NAME
	MOVE A,SYBLK		;SYSERR BLOCK
	MOVE B,[-1,,[
		SEBPTR R1%FNM,SBTSTR,FILESP]] ;COPY STRING
	CALL SEBCPY		;DO IT
	 JFCL
RELOD9:	MOVE A,SYBLK		;GET SYSERR BLOCK
	CALL QUESEB		;QUEUE IT UP
	 JFCL			;?
	RET			;AND DONE
;CODE TO DO THE RP REBOOT OF THE -11. THIS INCLUDES THE PORT
;CONTENTION LOGIC AND THE BOOT CODE

DSKRBT:	12700,,0		;MOV #0,R0
	12704,,176700		;MOV #RPEXP,R4
	12703,,176710		;MOV #RPEXP+10,R3
	12713,,40		;MOV #40,@R3
	10005,,305		;MOV R0,R5
				; SWAB R5
	42705,,177770		;BIC #177770,R5
	110513,,12701		;MOVB R5,@R3
	2,,12714		;MOV#2,R1
	23,,32714		;MOV #23,@R4
	4000,,1771		;BIT #DVA,@R4
				; BEQ 10$
	5301,,1371		;DEC R1
				; BNE 20$
	137,,173034		;JUMP 173034
DSKPSZ==.-DSKRBT

;ROUTINE TO CHECK IF A DTE EXISTS
;ACCEPTS:	A/ DTE NUMBER
;RETURNS:	+1 DOESN'T EXIST
;		+2 EXISTS

DTREAL:	JN DTERL,(A),RSKP	;IF NOW ACTIVE, IT EXISTS
	CALL DTREST		;PUT IT IN A KNOWN STATE
	MOVE B,CNDO(A)		;GET A CONO WORD
	IORI B,DTEPIE+DTEPI0	;ENABLE PI 0 ONLY
	XCT B			;GO SET THEM
	TXC B,<<CONSO 0>-<CONO 0>> ;CHANGE CONO INTO A CONSO
	XCT B			;SEE IF BITS ARE ON
	RET			;NO. DEVICE DOESN'T EXIST
	CALL DTREST		;YES. RESET DEVICE
	RETSKP			;AND SAY IT EXISTS
; BOOT JSYS - PERFORMS BOOTSTRAP FUNCTIONS FOR ADJACENT COMPUTERS


; TABLE OF DISPATCH ADDRESSES

BOOTTB:	BTROM			;  0 ACTIVATE ROM
	BTLDS			;  1 LOAD SECONDARY BOOTSTRAP PROGRAM
	BTLOD			;  2 LOAD MEMORY
	BTDMP			;  3 DUMP MEMORY
	BTIPR			;  4 INITIALIZE PROTOCOL
	BTTPR			;  5 TERMINATE PROTOCOL
	BTSTS			;  6 RETURN STATUS
	BTBEL			;  7 WAIT FOR TO-10 DOORBELL
	BTRMP			; 10 READ MOP MESSAGE
   REPEAT 3,<
	[RETBAD (ARGX02)]>	; 11-13 ARE ILLEGAL
	BTCLI			; 14 (.BTCLI) CONVERT LINE ID TO PORT NUMBER
	BTCPN			; 15 (.BTCPN) CONVERT PORT NUMBER TO LINE ID

	BOOTLN==.-BOOTTB


.BOOT::	MCENT			;MONITOR CONTEXT ENTRY
	MOVE T1,CAPENB		;GET ENABLED CAPABILITIES
	TXNN T1,SC%WHL!SC%OPR!SC%MNT ;WHEEL, OPERATOR, OR MAINTENANCE ?
	ITERR (CAPX1)		;NO, GIVE ERROR

; VALIDATE DTE-20 NUMBER

	UMOVE Q1,2		;GET ADDRESS OF USER'S ARGUMENT BLOCK
	UMOVE Q2,.BTDTE(Q1)	;GET DTE-20 NUMBER FROM USER
	UMOVE T1,1		;GET FUNCTION CODE FROM USER
	CAIN T1,.BTCLI		;SPECIAL CASE - DON'T CHECK DTE NUMBER
	JRST BOOT1		;YES - SKIP VALIDATION
	CAIL Q2,DTEN		;VALID DTE-20 SPECIFIED ?
	ITERR (BOTX01)		;NO, GIVE ERROR

; DISPATCH TO PROCESSING ROUTINE BASED ON REQUESTED FUNCTION

BOOT1:	CAIL T1,.BTROM		;CHECK RANGE OF GIVEN
	CAIL T1,BOOTLN		; FUNCTION CODE
	ITERR (ARGX02)		;INVALID FUNCTION CODE
	MOVE T1,BOOTTB(T1)	;GET ADDRESS OF PROCESSING ROUTINE
	CALL (T1)		;DISPATCH TO APPROPRIATE ROUTINE
	 ITERR()		;ERROR
	MRETNG			;SUCCESS, RETURN TO USER

; COMMON ERROR ROUTINE TO STORE FAILURE STATUS IN ARG BLOCK AND RETURN
; ACCEPTS IN T1/ ERROR STATUS

BTERR:	CAMN T1,[-1]		;NO SUCH DTE20 ?
	JRST [	MOVX T1,BOTX01	;YUP, GET CORRECT ERROR CODE
		RET ]		;AND DONE
	UMOVEM T1,.BTERR(Q1)	;SAVE ERROR STATUS
	RET			;GIVE FAIL RETURN
; ROUTINE TO ACTIVATE (GRONK) THE ROM

BTROM:	CAIGE Q2,DTEN		;VALID DTE-20 SPECIFIED ?
	SKIPGE Q2		;??
	RETBAD (BOTX01)		;NO, GIVE ERROR
	MOVE T1,Q2		;GET DTE-20 NUMBER
	TXO T1,RM%ROM		;INDICATE THAT ROM SHOULD BE GRONKED
	SETZB T2,T3		;DON'T DUMP, DON'T LOAD
;**;[1739] Change one line at BTROM: +6L	JGZ	11-JUN-80
	CALL RMGRNC		;[1739]GO GRONK THE ROM
	 JRST BTERR		;FAILED, RETURN ERROR STATUS
	RETSKP			;SUCCESS, GIVE GOOD RETURN


; ROUTINE TO ACTIVATE (GRONK) THE ROM AND LOAD A SECONDARY BOOTSTRAP

BTLDS:	CAIGE Q2,DTEN		;VALID DTE-20 SPECIFIED ?
	SKIPGE Q2		;??
	RETBAD (BOTX01)		;NO, GIVE ERROR
	MOVE T1,Q2		;GET NUMBER OF DTE-20
	TXO T1,RM%ROM		;NOTE THAT ROM SHOULD BE ACTIVATED
	SETZM T2		;NO DUMP WANTED
	MOVE T3,[LODSEC]	;ADR OF COROUTINE TO LOAD SECONDARY BOOT
	MOVE T4,[RELODE]	;ADDRESS OF ERROR COROUTINE
;**;[1739] Change one line at BTLDS: +8L	JGZ	11-JUN-80
	CALL RMGRNC		;[1739]INITIATE LOAD OF SECONADRY BOOTSTRAP
	 JRST BTERR		;FAILED, RETURN ERROR STATUS
	RETSKP			;SUCCESS, GIVE GOOD RETURN

; COROUTINE TO PERFORM LOADING OF SECONDARY BOOTSTRAP

LODSEC:	JUMPG T1,LDSEC2		;IF SECOND CALL, GO UNLOCK PAGE AND RETURN
	CALL LOKPAG		;LOCK THE PAGE TO HOLD THE DATA TO TRANSFER
	CALL CLRRBT		;ZERO THE BOOT PAGE
	MOVEI T1,200		;NUMBER OF WORDS TO TRANSFER IS MAXIMUM SIZE
				; OF SECONDARY BOOTSTRAP
	UMOVE T2,.BTSEC(Q1)	;GET SOURCE ADDRESS OF DATA IN USER SPACE
	MOVE T3,[DTERBT]	;GET ADDRESS OF BOOT PAGE (DESTINATION)
	CALL BLTUM1		;COPY BOOTSTRAP INTO MONITOR SPACE
	MOVE T1,Q2		;GET DTE-20 NUMBER
	CALL CLRBEL		;TURN OFF THE TO -10 DOORBELL
	SETOM T2		;NOTE THAT A DOORBELL IS REQUESTED
	MOVE T1,[POINT ^D16,DTERBT] ;GET BYTE POINTER TO SECONDARY BOOT PGM
	RETSKP			;RETURN TO CALLER

; HERE ON SECOND ENTRY AFTER DATA HAS BEEN TRANSFERRED

LDSEC2:	CALL UNLPAG		;DONE WITH BOOT PAGE
	CALLRET RTRUE		;RETURN AND REQUEST FINAL DOORBELL
; ROUTINE TO LOAD MEMORY OF AN ADJACENT COMPUTER HAVING LOADED A BOOTSTRAP

CNTBYT==2			;NUMBER OF COUNT BYTES PRECEDING DATA BYTES

BTLOD:	CAIGE Q2,DTEN		;VALID DTE-20 SPECIFIED ?
	SKIPGE Q2		;??
	RETBAD (BOTX01)		;NO, GIVE ERROR
	UMOVE T2,.BTCNT(Q1)	;GET TOTAL NUMBER OF DATA BYTES TO TRANSFER
	JUMPLE T2,[RETBAD (BOTX04)] ;COUNT MUST BE POSITIVE
	HRLM T2,Q2		;SAVE NUMBER OF BYTES REMAINING TO LOAD
	UMOVE T1,.BTFLG(Q1)	;GET FLAGS FROM USER SPACE
	TXNE T1,BT%BEL		;USER WANT DOORBELL ?
	TXO Q1,BT%BEL		;YES, NOTE REQUEST
	UMOVE T1,.BTLPT(Q1)	;GET POINTER TO DATA BYTES IN USER SPACE
	MOVEM T1,Q3		;SAVE BYTE POINTER TO DATA

; VALIDATE THE USER'S BYTE POINTER

	LDB T2,[POINT 6,T1,11]	;GET SIZE OF BYTES
	CAIE T2,^D8		;ONLY 8-BIT BYTES PERMITTED
	RETBAD (BOTX02)		;INVALID BYTE SIZE SPECIFIED

; DETERMINE THE NUMBER OF DATA BYTES PER PAGE

	MOVEI T1,^D36		;GET NUMBER OF BITS/WORD
	IDIV T1,T2		;COMPUTE NUMBER OF BYTES/WORD
	IMULI T1,PGSIZ		;FORM TOTAL NUMBER OF BYTES/PAGE
	SUBI T1,CNTBYT		;COMPUTE NUMBER OF DATA BYTES/PAGE
	HRRM T1,Q1		;SAVE # OF DATA BYTES/PAGE

; SET UP TO DO THE TRANSFER

	HRRZ T1,Q2		;GET NUMBER OF DTE-20
	SETZM T2		;NO DUMP WANTED
	MOVEI T3,LODRTN		;ADR OF COROUTINE TO LOAD DATA
	MOVEI T4,RELODE		;ADDRESS OF ERROR COROUTINE
;**;[1739] Change one line at BTLOD: +32L	JGZ	11-JUN-80
	CALL RMGRNC		;[1739]INITIATE LOAD OF SECONADRY BOOTSTRAP
	 JRST BTERR		;FAILED, RETURN ERROR STATUS
	RETSKP			;SUCCESS, GIVE GOOD RETURN
; COROUTINE TO PERFORM LOADING OF AN ADJACENT COMPUTER'S MEMORY
;
;ACCEPTS IN Q1/	FLAGS,,NUMBER OF DATA BYTES PER PAGE
;			FLAGS: BT%BEL IF DOORBELL WANTED
;	    Q2/	# OF BYTES LEFT TO LOAD,,DTE-20 NUMBER
;	    Q3/	BYTE POINTER TO NEXT BYTE INTO USER'S ADDRESS SPACE

LODRTN:	HLRZ T1,Q2		;GET NUMBER OF BYTES LEFT TO DO
	JUMPLE T1,LDRTN2	;IF DONE ALL BYTES, UNLOCK BOOT PAGE AND RETURN
	CALL LOKPAG		;LOCK THE BOOT PAGE
	CALL CLRRBT		;ZERO THE BOOT PAGE
	HLRZ T1,Q2		;GET NUMBER OF BYTES LEFT TO DO
	HRRZ T2,Q1		;ASSUME AN ENTIRE PAGE OF BYTES LEFT TO DO
	CAIGE T1,(Q1)		;LESS THAN A PAGE OF DATA BYTES LEFT ?
	HLRZ T2,Q2		;YES, GET JUST THE NUMBER LEFT TO LOAD
	SUB T1,T2		;COMPUTE BYTES REMAINING AFTER THIS LOAD
	HRL Q2,T1		;SAVE NEW NUMBER OF BYTES LEFT TO DO

; STORE THE NUMBER OF DATA BYTES TO TRANSFER AS THE FIRST TWO BYTES

	MOVE T4,[POINT 8,DTERBT] ;SET UP DESTINATION POINTER
	IDPB T2,T4		;STORE LOW ORDER BYTE OF COUNT
	LDB T3,[POINT 8,T2,27]	;GET HIGH ORDER BYTE OF COUNT
	IDPB T3,T4		;STORE HIGH ORDER BYTE OF COUNT

; GET THE DATA BYTES FROM THE USER (T2 NOW HAS NUMBER OF BYTES TO LOAD)

USRD10:	XCTBU [ILDB T3,Q3]	;GET NEXT BYTE FROM THE USER
	IDPB T3,T4		;STORE NEXT DATA BYTE TO LOAD
	SOJG T2,USRD10		;LOOP FOR ALL BYTES TO LOAD

; NOW SET UP FLAGS AND POINTER TO DATA AND RETURN

	HRRZ T1,Q2		;GET NUMBER OF DTE-20
	CALL CLRBEL		;TURN OFF THE TO -10 DOORBELL
	SETZM T2		;ASSUME NO TO -11 DOORBELL WANTED
	TXNE Q1,BT%BEL		;USER WANT A TO -11 DORRBELL ?
	SETOM T2		;YES, NOTE THAT A DOORBELL IS REQUESTED
	MOVE T1,[POINT 8,DTERBT] ;GET BYTE POINTER TO DATA
	RETSKP			;RETURN AND DO TRANSFER

; HERE WHEN ALL DATA HAS BEEN LOADED - UNLOCK THE BOOT PAGE AND RETURN

LDRTN2:	CALL UNLPAG		;UNLOCK THE BOOT PAGE
	CALLRET RFALSE		;RETURN (NO DDORBELL)
; ROUTINE TO DUMP AN ADJACENT COMPUTER'S MEMORY

BTDMP:	STKVAR <BTDBLK,BTDERR>
	CAIGE Q2,DTEN		;VALID DTE-20 SPECIFIED ?
	SKIPGE Q2		;??
	RETBAD (BOTX01)		;NO, GIVE ERROR
	MOVEM Q1,BTDBLK		;SAVE ADDRESS OF USER ARG BLOCK
	UMOVE T2,.BTCNT(Q1)	;GET TOTAL NUMBER OF DATA BYTES TO TRANSFER
	HRLM T2,Q2		;SAVE NUMBER OF BYTES REMAINING TO DUMP
	UMOVE T1,.BTDPT(Q1)	;GET POINTER TO DATA BYTES IN USER SPACE
	MOVEM T1,Q3		;SAVE BYTE POINTER TO DATA

; DETERMINE THE NUMBER OF DATA BYTES PER PAGE

	LDB T2,[POINT 6,T1,11]	;GET SIZE OF BYTES
	MOVEI T1,^D36		;GET NUMBER OF BITS/WORD
	IDIV T1,T2		;COMPUTE NUMBER OF BYTES/WORD
	IMULI T1,PGSIZ		;FORM TOTAL NUMBER OF BYTES/PAGE
	HRRZM T1,Q1		;SAVE # OF DATA BYTES/PAGE

; SET UP TO DO THE TRANSFER

	SETZM BTDERR		;INITIALIZE ERROR FLAG
	HRRZ T1,Q2		;GET NUMBER OF DTE-20
	MOVE T2,[DMPRTN]	;GET ADDRESS OF DUMP COROUTINE
	SETZM T3		;NO LOAD ROUTINE NEEDED
	MOVE T4,[RELODE]	;ADDRESS OF ERROR COROUTINE
;**;[1739] Change one line at BTDMP: +25L	JGZ	11-JUN-80
	CALL RMGRNC		;[1739]INITIATE DUMP
	 MOVEM T1,BTDERR	;SAVE ERROR STATUS
	MOVE Q1,BTDBLK		;GET ADDRESS OF USER ARG BLOCK AGAIN
	UMOVEM Q3,.BTDPT(Q1)	;STORE UPDATE POINTER INTO USER SPACE
	HLRZ T1,Q2		;GET # OF BYTES LEFT TO DUMP
	UMOVEM T1,.BTCNT(Q1)	;STORE UPDATED COUNT IN USER SPACE
	SKIPE T1,BTDERR		;DID AN ERROR OCCUR ON THE DUMP ?
	JRST BTERR		;YES, GO STORE ERROR CODE AND RETURN
	RETSKP			;SUCCESS, GIVE GOOD RETURN
; COROUTINE TO PERFORM DUMPING OF AN ADJACENT COMPUTER'S MEMORY
;
;ACCEPTS IN Q1/	# OF BYTES DUMPED ON LAST CALL,,NUMBER OF DATA BYTES PER PAGE
;	    Q2/	# OF BYTES LEFT TO DUMP,,DTE-20 NUMBER
;	    Q3/	BYTE POINTER TO NEXT BYTE INTO USER'S ADDRESS SPACE

DMPRTN:	STKVAR <DMPNUM>
	MOVEM T1,DMPNUM		;SAVE NUMBER OF THIS CALL
	SKIPN DMPNUM		;FIRST TIME HERE ?
	JRST DMPRT1		;YES, SKIP RETURNING BYTES TO USER

; RETURN DUMPED BYTES TO USER PROGRAM

	HLRZ T4,Q1		;GET # OF BYTES DUMPED LAST TIME
	MOVE T3,[POINT 8,DTERBT] ;GET BYTE POINTER
	LDB T1,[POINT 6,Q3,11]	;GET SIZE OF USER'S BYTE POINTER
	DPB T1,[POINT 6,T3,11]	;FORM BYTE POINTER FOR CORRECT SIZE BYTES
DMPRT0:	ILDB T1,T3		;GET A DUMPED BYTE
	XCTBU [IDPB T1,Q3]	;STORE BYTE INTO USER SPACE
	SOJG T4,DMPRT0		;LOOP OVER ALL BYTES TO DUMP

DMPRT1:	SKIPE DMPNUM		;IS THIS THE FIRST CALL ?
	JRST DMPRT2		;NO, DO NOT INITIALIZE BOOT PAGE
	CALL LOKPAG		;YES, LOCK THE BOOT PAGE
	CALL CLRRBT		;ZERO THE BOOT PAGE

DMPRT2:	HLRZ T2,Q2		;GET NUMBER OF BYTES LEFT TO DO
	JUMPLE T2,DMPRT3	;IF DONE ALL BYTES, UNLOCK BOOT PAGE AND RETURN
	HLRZ T1,Q2		;GET NUMBER OF BYTES LEFT TO DO
	HRRZ T2,Q1		;ASSUME AN ENTIRE PAGE OF BYTES LEFT TO DO
	CAIGE T1,(Q1)		;LESS THAN A PAGE OF DATA BYTES LEFT ?
	HLRZ T2,Q2		;YES, GET JUST THE NUMBER LEFT TO DUMP
	HRLM T2,Q1		;SAVE # OF BYTES TO BE DUMPED THIS PASS
	SUB T1,T2		;COMPUTE BYTES REMAINING AFTER THIS DUMP
	HRL Q2,T1		;SAVE NEW NUMBER OF BYTES LEFT TO DO

;SET UP TO DO THE NEXT DUMP

	MOVE T1,T2		;GET # OF BYTES TO DUMP
	MOVE T2,[POINT 8,DTERBT] ;GET POINTER TO WHERE DUMPED BYTES GO
	LDB T3,[POINT 6,Q3,11]	;GET SIZE OF USER'S BYTE POINTER
	DPB T3,[POINT 6,T2,11]	;FORM BYTE POINTER FOR CORRECT SIZE BYTES
	RETSKP			;REQUEST NEXT SET OF BYTES TO BE DUMPED

; HERE AFTER FINAL SET OF BYTES HAS BEEN DUMPED

DMPRT3:	CALL UNLPAG		;UNLOCK THE BOOT PAGE
	CALLRET RFALSE		;NO EXTRA DOORBELL NEEDED
; ROUTINE TO WAIT FOR A TO-10 DOORBELL

BTBEL:	SE0ENT			;ENTER SECTION 0
	HRLZ T1,Q2		;GET DTE-20 NUMBER
	HRRI T1,DBWAIT		;GET SCHEDULER TEST ROUTINE ADDRESS
	MDISMS			;WAIT FOR DOORBELL TO COME ON
	MOVE T1,Q2		;GET DTE-20 NUMBER
	LSH T1,^D26		;POSITION DTE-20 NUMBER
	ADD T1,[CONO DTE0,DTETDB] ;FORM INSTRUCTION TO TURN OFF DOORBELL
	XCT T1			;TURN OFF TO-20 DOORBELL
	RETSKP			;DOORBELL WAS ON, RETURN

; SCHEDULER TEST TO WAIT FOR A DOORBELL FROM A DTE-20
; ACCEPTS IN T1/ DTE-20 NUMBER

	RESCD
DBWAIT:	LSH T1,^D26		;POSITION DTE-20 NUMBER
	ADD T1,[CONSO DTE0,DTETDB] ;FORM TEST INSTRUCTION
	XCT T1			;IS DOORBELL ON YET ?
	JRST 0(4)		;NO, WAIT SOME MORE
	JRST 1(4)		;YES, RETURN SUCCESS
	SWAPCD


; ROUTINE TO PURGE THE DTE BUFFER PAGE (DTERBT)
;
;ACCEPTS IN T1/	DTE #

KILPAG:	SAVET
	MOVEI T2,DTERBT		;GET ADDRESS OF BUFFER PAGE
	SETZ T1,		;DELETE THE PAGE
	CALLRET SETMPG		;...
; ROUTINE TO READ A MOP MESSAGE FROM AN ADJACENT COMPUTER
;
; PROTOCOL:		BYTE COUNT (2 BYTES, INCLUDING BYTE COUNT)
;			MOP MESSAGE
;	ONLY 8-BIT BYTES ARE PERMITTED.  A SECONDARY BOOTSTRAP CAPABLE OF
;	ADHERING TO THIS PROTOCOL MUST HAVE BEEN LOADED INTO THE ADJACENT
;	COMPUTER PRIOR TO PERFORMING THIS FUNCTION.


BTRMP:	CAIGE Q2,DTEN		;VALID DTE-20 SPECIFIED ?
	SKIPGE Q2		;??
	RETBAD (BOTX01)		;NO, GIVE ERROR
	SE0ENT			;ENTER SECTION 0
	MOVE T1,Q2		;GET DTE-20 NUMBER
	MOVEI T2,RCVMOP		;ADDRESS OF DUMP COROUTINE
	MOVEI T3,0		;NO LOADING DESIRED
	MOVEI T4,RELODE		;ADDRESS OF ERROR COROUTINE
;**;[1739] Change one line at BTRMP: +8L	JGZ	11-JUN-80
	CALL RMGRNC		;[1739]INITIATE THE TRANSFER
	 JRST BTERR		;FAILED, RETURN ERROR STATUS

; THE MESSAGE HAS BEEN TRANSFERRED TO MONITOR VIRTUAL ADDRESS SPACE.
; RETURN THE MESSAGE TO THE USER (Q3 CONTAINS THE # OF BYTES TRANSFERRED).

	UMOVE T1,.BTMPT(Q1)	;GET DESTINATION BYTE POINTER TO USER SPACE
	UMOVE T2,.BTCNT(Q1)	;GET MAX BYTE COUNT USER WILL ACCEPT
	CAML T2,Q3		;WAS LESS ACTUALLY TRANSFERRED ?
	MOVE T2,Q3		;YES, USE SMALLER BYTE COUNT
	UMOVEM T2,.BTCNT(Q1)	;STORE UPDATED BYTE COUNT IN USER SPACE
	MOVE T4,[POINT 8,DTERBT,15] ;GET BYTE POINTER TO SOURCE
	JUMPE T2,BTRM20		;IF DONE, RETURN

; LOOP TO RETURN THE MESSAGE TO THE USER

BTRM10:	ILDB T3,T4		;GET BYTE FROM MESSAGE
	XCTBU [IDPB T3,T1]	;STORE BYTE INTO USER SPACE
	SOJG T2,BTRM10		;LOOP OVER ENTIRE MESSAGE

BTRM20:	UMOVEM T1,.BTMPT(Q1)	;STORE UPDATED BYTE POINTER
	RETSKP			;RETURN SUCCESS
; COROUTINE TO RECEIVE MOP MESSAGES

RCVMOP:	JUMPN T1,RCVM10		;IF NOT FIRST CALL, GO READ MSG OR RETURN

; THIS IS THE INITIAL CALL - SET UP TO READ THE BYTE COUNT

	CALL LOKPAG		;LOCK THE BOOT PAGE
	CALL CLRRBT		;ZERO THE BOOT PAGE
	MOVEI T1,2		;BYTE COUNT IS FIRST TWO BYTES
	MOVE T2,[POINT 8,DTERBT] ;GET BYTE POINTER
	RETSKP			;RETURN TO READ FIRST TWO BYTES

; HERE ON SECOND CALL - SET UP TO READ THE ACTUAL MOP MESSAGE

RCVM10:	CAIE T1,1		;IS THIS THE SECOND CALL ?
	JRST RCVM20		;NO, GO UNLOCK THE BOOT PAGE AND RETURN
	LDB Q3,[POINT 8,DTERBT,7] ;YES, GET LOW ORDER BYTE OF BYTE COUNT
	LDB T1,[POINT 8,DTERBT,15] ;GET HIGH ORDER BYTE OF BYTE COUNT
	DPB T1,[POINT 8,Q3,27]	;FORM COMPLETE BYTE COUNT
	MOVE T1,Q3		;GET BYTE COUNT
	CAILE T1,PGSIZ*4-2	;MAX MESSAGE SIZE IS ONE PAGE-COUNT (2 BYTES)
	MOVEI T1,PGSIZ*4-2	;MESSAGE TOO LARGE, JUST GET ONE PAGE
	TXO T1,DTETI		;REQUEST "I" BIT ALSO
	MOVE T2,[POINT 8,DTERBT,15] ;START MESSAGE AT THIRD BYTE IN FIRST WORD
	RETSKP			;RETURN AND TRANSFER DATA BYTES

; HERE ON THIRD CALL - ENTIRE MESSAGE HAS BEEN TRANSFERRED

RCVM20:	CALL UNLPAG		;UNLOCK THE BOOT PAGE
	UMOVE T2,.BTFLG(Q1)	;GET FLAGS FROM USER
	SETZM T1		;ASSUME NO DOORBELL WANTED
	TXNE T2,BT%BEL		;USER ASK FOR A DOORBELL ?
	SETOM T1		;YES, REQUEST A DOORBELL
	RET			;RETURN, TRANSFER COMPLETED
; ROUTINE TO TERMINATE PROTOCOL ON A DTE-20

BTTPR:	CAIGE Q2,DTEN		;VALID DTE-20 SPECIFIED ?
	SKIPGE Q2		;??
	RETBAD (BOTX01)		;NO, GIVE ERROR
	CAMN Q2,MSTRDT		;IS THIS THE MASTER -11?
	RETBAD (BOTX01)		;YES. ILLEGAL TO STOP IT
	LOAD T1,DTERL,(Q2)	;GET CURRENT PROTOCOL STATE
	PUSH P,T1		;SAVE IT
	SETZRO DTERL,(Q2)	;NOTE THAT THIS DTE NOT RUNNING A PROTOCOL
	MOVE T1,Q2		;GET DTE-20 NUMBER
	CALL DTREST		;GO TURN OF INTERRUPTS FOR THIS DTE
	POP P,T1		;GET PREVIOUS PROTOCOL STATE
	JUMPE T1,RSKP		;IF NOT IN PROTOCOL, DONE
	SETONE DTRLD,(Q2)	;WAS. NEED RELOAD ATTENTION THEN
	AOS LOAD11		;SAY HAVE A FE THAT NEEDS ATTENTION
	AOS JB0FLG		;AND MAKE JOB 0 DO IT
	RETSKP			;RETURN
				;FALL INTO ROUTINE TO RETURN DTE20 STATUS

; ROUTINE TO RETURN STATUS OF A DTE-20

BTSTS:	CAIGE Q2,DTEN		;VALID DTE-20 SPECIFIED ?
	SKIPGE Q2		;??
	RETBAD (BOTX01)		;NO, GIVE ERROR
	MOVE T1,Q2		;GET DTE-20 NUMBER
	CALL CHKDTE		;SEE IF THIS DTE IS RUNNING SOME PROTOCOL
	 JRST [	SETOM T1	;NO PROTOCOL RUNNING
		JRST BTST1 ]	;GO RETURN THAT STATUS TO USER

; DETERMINE WHICH PROTOCOL IS RUNNING IN THE SPECIFIED DTE

	MOVE T1,Q2		;GET DTE-20 NUMBER
	CALL SETRGN		;GET ADDRESS OF COMM REGIONS
	LOAD T1,CMVRR,(T3)	;GET VERSION OF RUNNING PROTOCOL

; HERE TO RETURN STATUS TO USER (STATUS IS IN T1)

BTST1:	UMOVEM T1,.BTCOD(Q1)	;RETURN STATUS TO USER
	RETSKP			;RETURN SUCCESS

; ROUTINE TO ZERO THE BOOT PAGE

CLRRBT:	MOVE T2,[DTERBT,,DTERBT+1] ;SET UP TO CLEAR BOOT PAGE
	SETZM DTERBT		;CLEAR FIRST WORD OF PAGE
	BLT T2,DTERBT+PGSIZ-1	;INITIALIZE PAGE TO HOLD BOOT PROGRAM DATA
	RET			;RETURN
; ROUTINE TO INITIALIZE THE PROTOCOL ON A SPECIFIED DTE-20

BTIPR:	CAIGE Q2,DTEN		;VALID DTE-20 SPECIFIED ?
	SKIPGE Q2		;??
	RETBAD (BOTX01)		;NO, GIVE ERROR
	UMOVE Q3,.BTPRV(Q1)	;GET PROTOCOL VERSION NUMBER
	MOVE T1,Q3		;COPY PROTOCOL VERSION NUMBER
	CALL CHKPRO		;VALIDATE THE PROTOCOL SPECIFIED
	 RETBAD ()		;INVALID PROTOCOL SPECIFIED
	MOVE T1,Q2		;GET DTE-20 NUMBER
	CALL DTREAL		;IS THIS DTE EXISTANT?
	 RETBAD (BOTX01)	;NO. CAN'T INIT IT THEN
	JN <DTERL,DTRLD>,(T1),[RETBAD (BOTX01)] ;MUST BE INACTIVE ALSO
	MOVE T2,Q3		;GET PROTOCOL VERSION NUMBER
	NOINT			;INHIBIT PROCESS INTERRUPTS
	PUSH P,JOBBIT		;SAVE FORK'S PRIORITY WORD
	MOVX T3,BOTPRI		;GET SPECIAL PRIORITY WORD
	MOVEM T3,JOBBIT		;""
	CALL DTINIT		;INITIALIZE COMM REGIONS AND PROTOCOL
	POP P,JOBBIT		;RESTORE PRIORITY WORD
	JN DTRLD,(Q2),[SETZRO DTRLD,(Q2)
			OKINT	;INTS ALLOWED NOW
			RETBAD (BOTX05)] ;IT DIDN'T. INFORM CALLER
	MOVE T1,Q2		;DID PROTOCOL INIT
	CAIN Q3,.VNMCB		;DOING MCB PROTOCOL?
	CALL NODINI		;YES. SEND INIT MESSAGE THEN
	OKINT			;ALLOW INTS NOW
	RETSKP			;GIVE SUCCESS RETURN
;ROUTINE TO CONVERT LINE-ID TO PORT NUMBER

BTCLI:	UMOVE T4,.BTLID(Q1)	;GET POINTER TO LINE-ID STRING
	TLC T4,-1		;SEE IF POINTER IS -1,,ADR TYPE
	TLCN T4,-1		;??
	HRLI T4,(POINT 7,)	;MAKE INTO AN ASCII POINTER
	SETZ T2,		;WHERE WE WILL BUILD STRING
	MOVE T3,[POINT 7,2]	;POINT TO  IT
	XCTBU [	ILDB T1,T4]	;GET FIRST CHARACTER OF STRING
	IDPB T1,T3		;AND STUFF
	XCTBU [	ILDB T1,T4]	;GET SECOND CHARACTER OF STRING
	IDPB T1,T3		;AND STUFF
	XCTBU [	ILDB T1,T4]	;GET THIRD CHARACTER OF STRING
	IDPB T1,T3		;AND STUFF
	XCTBU [	ILDB T1,T4]	;GET FOURTH CHARACTER OF STRING
	IDPB T1,T3		;AND STUFF
	CAMN T2,[ASCIZ/DTE_/]	;ASKING FOR A DTE?
	JRST BTCNUM		;YES GET THE NUMBER
	XCTBU [	ILDB T1,T4]	;GET FIFTH CHARACTER OF STRING
	IDPB T1,T3		;AND STUFF
	CAME T2,[ASCIZ/DTE20/]	;"DTE20_" IS ALSO ACCEPTIBLE
	RETBAD(BOTX01)		;NUMBER OUT OF RANGE
	XCTBU [	ILDB T1,T4]	;GET SIXTH CHARACTER OF STRING
	CAIE T1,"_"		;IS THE THE "DTE20_" STRING
	RETBAD(BOTX01)		;NUMBER OUT OF RANGE
BTCNUM:	XCTBU [	ILDB T1,T4]	;GET LAST CHARACTER OF STRING
	SUBI T1,60		;MAKE INTO A NUMBER
	CAIL T1,DTEN		;CHECK FOR OUT OF RANGE
	RETBAD(BOTX01)		;NUMBER OUT OF RANGE
	XCTBU [	ILDB T2,T4]	;STRING SHOULD END WITH NULL
	UMOVEM T1,.BTPRT(Q1)	;GIVE USER THE NUMBER
	RETSKP			;SUCCESS RETURN
;ROUTINE TO CONVERT PORT NUMBER TO LINE-ID

BTCPN:	CAIGE Q2,DTEN		;VALID DTE-20 SPECIFIED ?
	SKIPGE Q2		;??
	RETBAD (BOTX01)		;NO, GIVE ERROR
	UMOVE T3,.BTLID(Q1)	;GET USER'S POINTER FOR WHERE TO PUT STRING
	TLC T3,-1		;SEE IF POINTER IS -1,,ADR TYPE
	TLCN T3,-1		;??
	HRLI T3,(POINT 7,)	;MAKE INTO AN ASCII POINTER
	MOVEI T2,"D"		;PUT THE STRING "DTE_" IN USER SPACE
	XCTBU [	IDPB T2,T3]
	MOVEI T2,"T"
	XCTBU [	IDPB T2,T3]
	MOVEI T2,"E"
	XCTBU [	IDPB T2,T3]
	MOVEI T2,"_"
	XCTBU [	IDPB T2,T3]
	MOVE T4,Q2		;GET THE DTE NUMBER
	ADDI T4,60		;MAKE NUMBER INTO AN ASCII QUANTITY
	XCTBU [	IDPB T4,T3]	;SAVE THE DTE NUMBER
	SETZ T4,		;END WITH A NULL
	XCTBU [	IDPB T4,T3]	;PUT NULL INTO USER SPACE
	UMOVEM T3,.BTLID(Q1)	;SAVE UPDATED POINTER
	RETSKP

;CHKPRO - ROUTINE TO VALIDATE A PROTOCOL VERSION NUMBER
;
;ACCEPTS IN T1/	PROTOCOL VERSION NUMBER TO CHECK
;		CALL CHKPRO
;RETURNS: +1	 INVALID PROTOCOL SPECIFIED, ERROR CODE IN T1
;	  +2	VALID PROTOCOL GIVEN

CHKPRO:	MOVSI T4,-PRVSIZ	;SET UP TO LOOP THROUGH PROTOCOL TABLE
CHKPR1:	CAMN T1,PRVTAB(T4)	;FOUND VALID PROTOCOL ?
	RETSKP			;YES, GIVE SUCCESS RETURN
	AOBJN T4,CHKPR1		;NO, LOOP THROUGH REMAINDER OF TABLE
	RETBAD (BOTX03)		;INVALID PROTOCOL VERSION NUMBER

PRVTAB:	.VN20F			;RSX20F PROTOCOL
	MCPRON			;DECNET NETWORK SERVICES PROTOCOL
				;ASSEMBLE ONLY IF HAVE DECNET SUPPORT

	PRVSIZ==.-PRVTAB


	RESCD

;KEEP ALIVE INSTRUCTION USED BY SCHED TO DO KEEP ALIVE FUNCTION
;FOR THE 11

KEPALV::AOS COMBUF+DTEN+1+KPALIV	;BUMP KEEP ALIVE COUNTER

	TNXEND
	END