Google
 

Trailing-Edge - PDP-10 Archives - dec-10-omona-u-mc9 - comnet.mac
There are 6 other files named comnet.mac in the archive. Click here to see a list.
TITLE COMNET - COMMON COMMUNICATION AREA FOR NETWORKS - V050
SUBTTL	D. TODD/EJW		15 FEB 77
	SEARCH F,S,NETPRM
	$RELOC
	$HIGH
;*** COPYRIGHT 1974,1975,1976,1977 DIGITAL EQUIPMENT CORP., MAYNARD, MASS. ***
XP	VCOMNET,050	;PUT VERSION NUMBER IN GLOB AND LOADER MAP

COMNET::ENTRY	COMNET	;LOAD IF IN LIBRARY SEARCH MODE

;SYMBOLS RELEVENT TO NETWORKS THAT MAY BE CHANGED BY MONGEN DIALOG
IFNDEF M.XTL,<XP M.XTL,0>
XP	M.TLTL,M.TLTL+M.XTL		;COUNT THE DA28 LINES


IFN M.NET,<IFE FTNET,<
	PRINX	FTNET MUST ME ASSEMBLED AS FTNET==-1 FOR NETWORKS
	M.NET==0		;FORCE NETWORKS OFF
>>;END IFE FTNET IFN FTNET
IFE FTNET,<END>		;IF FTNET==0 THEN NO NETWORK SOFTWARE

IFE M.NET,<
	END		;DO NOT LOAD NETSER
>;END IFE M.NET

IFNDEF M.DTA, <M.DTA==0>
IFNDEF DTAN, <DTAN==0>
IFNDEF M.DTB, <M.DTB==0>
IFNDEF DTBN, <DTBN==0>
XP DTCN,MD.DTC

IFNDEF M.TM10,<XP M.TM10,0>
IFNDEF M.TC10,<XP M.TC10,0>
IFNDEF M.TX01,<XP M.TX01,0>
IFNDEF M.TM02,<XP M.TM02,0>
XP TAPN,M.TM10+M.TC10+M.TX01+M.TM02

DEFINE	MTXADD(CHN)<
IFDEF M.MT'CHN,<MTXN==MTXN+M.MT'CHN>>

MTXN==0
ZZ==-1
REPEAT	TAPN,<MTXADD(\<ZZ==ZZ+1>)>


IFNDEF NTTYPL,<NTTYPL==^D16>	;NUMBER OF TTYS/BUFFER
IFNDEF NBPBFL,<XP NBPBFL,^D8*4>
IFN M.RJOB,<IFE FTTSK,<
IF1,<	PRINTX TASK TO TASK REQUIRES FTTSK==-1>
IF1,<	PRINTX TASKS WILL NOT BE ALLOWED>
	XP M.RJOB,0	;REMOVE REMOTE PROCESSES
>>
IFE M.RJOB,<
	NDEVTS==:0		;NO TSKSER LOADED
	TSKCNM==:CPOPJ##
	TSKDSC==:CPOPJ##
	CHKTSK==:CPOPJ##
	RMVTSK==:CPOPJ##
	TSKCNT==:CPOPJ##
>
IFN M.RJOB,<EXTERNAL	TSKSER>		;LOAD TSKSER


IFNDEF M.RPTP,<M.RPTP==0>
IFNDEF M.RPTR,<M.RPTR==0>
IFNDEF M.RMTA,<M.RMTA==0>
IFNDEF M.RPLT,<M.RPLT==0>
IFNDEF M.RDX,<M.RDX==0>

;		REMOTE DATA ENTRY SERVICE SYMBOLS
IFN M.RDX,<IFE FTRDX,<
IF1,<	PRINTX REMOTE DATA ENTRY SERVICE REQUIRES FTRDX==-1>
IF1,<	PRINTX REMOTE DATA ENTRY WILL NOT BE LOADED>
	XP	M.RDX,0	;NO REMOTE DATA ENTRY SERVICE
>>
IFE M.RDX,<		;DEFINE DUMMY ENTRY WHEN RDXSER NOT LOADED
>
IFN M.RDX,<EXTERNAL RDXSER>	;LOAD RDXSER
SUBTTL NETDDB PROTOTYPE DEVICE DATA BLOCK FOR NETWORKS
	$LOW
NETDDB::
	PHASE	0
	SIXBIT	//		;(0)  DEVNAM
	XWD	6*HUNGST,0	;(1)  DEVCHR
	Z			;(2)  DEVIOS
	XWD	0,NETDSP	;(3)  DEVSER
	Z			;(4)  DEVMOD
	Z			;(5)  DEVLOG
	0			;(6)  DEVBUF
	XWD	R,0		;(7)  DEVIAD
	XWD	R,0		;(10) DEVOAD
	0			;(11) DEVSTS
	XWD	DEPLEN,0	;(12) DEVSTA
	0			;(13) DEVXTR
	0			;(14) DEVEVM
	0			;(15) DEVPSI
	0			;(16) DEVESE
	0			;(17) DEVHCW
	0			;(20) DEVJOB
	0			;DEVFIL
	0			;DEVEXT
	0			;DEVPPN
	PHASE	DEVLLD+1	;END OF LONG DDB
				;DEFINE IN S. AND ALWAYS BE CURRENT
DEVNET::!Z;XWD	0,0		;DEVNET NDT,NDB
NETXLA::!Z;BYTE	(8)0(14)0(14)0	;RSN,SLA,DLA
NETDRQ::!Z;XWD	0,0		;LAST MSG#SENT,DATA REQUEST COUNT
NETSTS::!Z;BYTE	(8)0(12)0(16)0	;FLAGS,RLN,DVT
	XP	NT.DSC,(1B0)	;RECEIVED A DISCONNECT FOR THIS DDB
NETDEV::XWD	0,0		;DEVICE DEPENDENT DATA POINTER
NETLEN==:.			;     LENGTH
	DEPHASE
	$HIGH
;BYTE POINTER TO THE NETDDB
NETRSN::POINT	8,NETXLA(F),7	;     REASON BYTE
NETSLA::POINT	14,NETXLA(F),21	;     SOURCE LINK ADDRESS
NETDLA::POINT	14,NETXLA(F),35	;     DESTINATION LINK ADDRESS
NETRLN::POINT	12,NETSTS(F),19	;     LOGICAL RECORD LENGTH
NETDVT::POINT	16,NETSTS(F),35 ;     DEVICE ATTRIBUTE BITS (SEE NETPRM)
	$HIGH
SUBTTL NETDDB DISPATCH TABLE
	POPJ	P,0		;DEVOP.UUO
	JSP	T4,DSPOBJ	;(-3) RETURN BUFFER SIZE
	JRST	NETINI##	;(-2) DEVICE INITIALIZATION
	JSP	T4,DSPOBJ	;(-1) HUNG DEVICE
NETDSP::JSP	T4,DSPOBJ	;(0)  RELEASE DEVICE
	JSP	T4,DSPOBJ	;(1)  CLOSE
	JSP	T4,DSPOBJ	;(2)  OUTPUT
	JSP	T4,DSPOBJ	;(3)  INPUT
	JSP	T4,DSPOBJ	;(4)  ENTER
	JSP	T4,DSPOBJ	;(5)  LOOKUP
	JSP	T4,DSPOBJ	;(6)  DUMP MODE OUTPUT
	JSP	T4,DSPOBJ	;(7)  DUMP MODE INPUT
	JSP	T4,DSPOBJ	;(10) USETO
	JSP	T4,DSPOBJ	;(11) USETI
	JSP	T4,DSPOBJ	;(12) UGETF UUO
	JSP	T4,DSPOBJ	;(13) RENAME UUO
	JSP	T4,DSPOBJ	;(14) CLOSE INPUT
	JSP	T4,DSPOBJ	;(15) UTPCLR UUO
	JSP	T4,DSPOBJ	;(16) MTAPE UUO

;DISPATCH ON THE OBJECT TYPE
DSPOBJ:	SUBI	T4,NETDSP+1	;RELOCATE THE ENTRY
	MOVSI	T1,DVCNET	;GET THE NETWORK DEVICE BIT
	TDNN	T1,DEVCHR(F)	;IS THIS A NETWORK DEVICE?
	STOPCD	CPOPJ##,DEBUG,DFU,;++DEVICE UNRECONIZED
	HLRZ	W,DEVNET(F)	;GET THE NDT POINTER
	LDB	T1,NDTOBJ	;GET THE -11 DEVICE TYPE
	ROT	T1,-1		;DIVIDE BY 2
	HLRZ	T2,OBJDSP(T1)	;GET THE EVEN ENTRY
	SKIPGE	T1		;WAS IT EVEN?
	HRRZ	T2,OBJDSP(T1)	;NO, GET THE ODD ENTRY
	JUMPE	T2,CPOPJ##	;NOT IMPLEMENTED
	ADDI	T4,(T2)		;POINT TO THE DISPATCH ENTRY
	PJRST	(T4)		;GO TO DEVICE DEPENDENT ROUTINE
IF2,<IFNDEF NDEVTT,<NDEVTT==0>>	;IF ROUTINE NOT LOADED
IF2,<IFNDEF NDEVTY,<NDEVTY==0>>	;IF ROUTINE NOT LOADED
IF2,<IFNDEF NDEVCD,<NDEVCD==0>>	;IF ROUTINE NOT LOADED
IF2,<IFNDEF NDEVLP,<NDEVLP==0>>	;IF ROUTINE NOT LOADED
IF2,<IFNDEF NDEVPR,<NDEVPR==0>>	;IF ROUTINE NOT LOADED
IF2,<IFNDEF NDEVPP,<NDEVPP==0>>	;IF ROUTINE NOT LOADED
IF2,<IFNDEF NDEVPL,<NDEVPL==0>>	;IF ROUTINE NOT LOADED
IF2,<IFNDEF NDEVMT,<NDEVMT==0>>	;IF ROUTINE NOT LOADED
IF2,<IFNDEF NDEVDT,<NDEVDT==0>>	;IF ROUTINE NOT LOADED
IF2,<IFNDEF NDEVTS,<NDEVTS==0>>	;IF ROUTINE NOT LOADED
IF2,<IFNDEF NDEVRX,<NDEVRX==0>>	;IF ROUTINE NOT LOADED
OBJDSP:				;NETWORK SUPPORTED DEVICE TABLE
	XWD	NDEVTT,NDEVTY	;(0)TTY CTL	(1)TTY USER
	XWD	NDEVCD,NDEVLP	;(2)CARD READER	(3)LINE PRINTER
	XWD	NDEVPR,NDEVPP	;(4)PAPER READ	(5)PAPER TAPE PUNCH
	XWD	NDEVPL,NDEVMT	;(6)PLOTTER	(7)MAG TAPE
	XWD	NDEVDT,NDEVTS	;(10)DECTAPE	(11)TASK(JOB)
	XWD	NDEVRX,0	;(12)RMT DATA	(13)0
SUBTTL	NETWORK DISPATCH CONTROL BLOCK (NDP)

;AN NDP IS ASSOCIATED WITH EACH NETWORK DEVICE TO ALLOW THE
;NCL ROUTINES TO COMMUNICATE TO THE DEVICE SERVICE CODE.
;IT LOOKS MUCH LIKE THE STANDARD DEVICE SERVICE DISPATCH TABLES.

NETNDP:	PHASE	0
NDPIDT::!0			;CALL WHEN DATA RECEIVED FROM DN87
NDPIST::!0			;CALL WHEN STATUS MESSAGE RECEIVED FROM DN87
NDPODN::!0			;CALL WHEN MESSAGE HAS BEEN SENT TO DN87
	DEPHASE
SUBTTL PCB PROTOCOL CONTOL BLOCK
	$LOW
NETPCB::
	PHASE	0
PCBBLK::!Z;	BYTE	(1)0(5)0(4)0(8)0(18)0	;#MSG,FLAG,CONV,MSG#,QUEUE LINK
	XP	PCB.NM,(1B0)	;NUMBERED MESSGE
	XP	PCB.UR,(1B1)	;USER DATA MESSAGE
	XP	PCB.TY,(1B2)	;TTY PCB-DO NOT DELETE
	XP	PCB.OF,(1B3)	;DESTINATION OFF LINE
	XP	PCB.UN,PCB.NM!PCB.UR  ;SPECIAL PROCESSING NEEDED AFTER -11 GETS MESSAGE
	XP	PCV.NC,0	;NO CONVERSION BYTE SIZE CONVERTED
	XP	PCV.LC,1	;LINE COMPRESSION (LPT ONLY)
	XP	PCV.BN,2	;BINARY CONVERSION 12 BIT BYTES
PCBDDB::!				;(1) DDB,0
PCBNDB::!Z;	XWD	0,0		;(1) 0,NDB POINTER
PCBIAD::!;	POINT	8		;(2) INPUT PROTOCOL ADDRESS
PCBOAD::!Z;	POINT	8,0		;(2) OUTPUT PROTOCOL ADDRESS
PCBICT::!;	XWD	0,0		;(3) BYTE COUNT
PCBOCT::!Z;	XWD	0,0		;(3) BYTE COUNT
PCBOA2::!Z;	POINT	8,0		;(4) DATA ADDRESS OR 0
PCBOC2::!Z;	XWD	0,0		;(5) BYTE COUNT
PCBLEN==:.				;LENGTH
	DEPHASE
	RELOC	NETPCB			;RECLAIM SPACE
	$HIGH
;BYTE POINTERS
PCBPCV::POINT	4,PCBBLK(U),9		;CONVERSION TYPE
PCBMSN::POINT	8,PCBBLK(U),17		;MESSAGE NUMBER






	$LOW
;LAT LINK ADDRESS TABLE
LATLEN==:M.CONN			;LENGTH OF TABLE(MAX CONNECTS)

;	(LT)	;FLAGS
	XP	LAT.TY,400000	;THIS IS A LDB POINTER
;	(RT)	;POINTER TO A DDB FOR DEVICES OR A LDB POINTER
NETLAT::XWD	0,NETDDB		;POINT TO THE DDB (EXEC PROCESS)
	BLOCK	LATLEN-1		;REST OF THE TABLE

	$LOW
STANAM::SYSNDE
;THIS DATA BLOCK MUST BE REFERENCED BY AC "W"
	$LOW
NETNDB::
	PHASE	0			;PROTOTYPE NDB FOR LOCAL SYSTEM
NDBNNM::!XWD	OURNNM,0		;(0)  NNM,NEXT NDB
NDBSID::!XWD	SYSDAT##,CONFIG##	;(1)  SYSTEM CREATION DATE,NAME
NDBSNM::!BYTE	(18)STANAM(2)0(8)0(8)0	;(2)  STATION NAME,LAST PROC, LAST REC
NDBMNM::!BYTE	(4)0(8)0(8)0(8)0(8)0	;(3) LAST ACKED,LAST SENT,LAST ASSGN
NDBFEK::!EXP	<(NDB.ST!NDB.SK!NDB.CF!NDB.NB!NDB.TP)>  ;(4)  FLAGS,FEK
	XP	NDB.ST,(1B0)	;START SEQUENCE SENT
	XP	NDB.SK,(1B1)	;STACK RECEIVED
	XP	NDB.CF,(1B2)	;CONFIGURATION
	XP	NDB.NB,(1B3)	;MY NEIGHBORS HAVE CHANGED
	XP	NDB.TP,(1B4)	;TOPOLOGY SEARCH FLAG FOR NEIGHBORS MSG.
NDBCLR::!				;FIRST WORD TO CLEAR
NDBQUE::!XWD	0,0			;(5)  INPUT QUEUE,,OUTPUT QUEUE
NDBCTL::!BYTE	(10)0(8)0(9)0(9)0	;(6)  MML,FLAGS,BACKWARD,FORWARD ACTIVE TTY LINKAGE
NDBATQ==:NDBCTL				;     SPECIAL NAME FOR TTY LINKAGE
NDBTOP::!BLOCK	^D8			;(7)  TOPOLOGY TABLE
SCBSTS::!				;(10)STATUS IN LEFT HALF
;BITS IN SCBSTS:

XP .RMSUI,100			;IDLE

SCBOPR::!BLOCK	1			;(11)LDB OF OPR, OR 0 IF NONE
SCBCTL::!BLOCK	1			;(12)HWD JOB,,ADR OF STATION CONTROL DEVICE
SCBRQB::!BLOCK	1			;(13) TIMER,MESSAGE ADDRESS FOR REQUEST BOOT
SCBTTY::!BLOCK	1			;(14) COUNT OF TTYS TO CONNECT
SCBNBP::!BLOCK	1			;(15) POINTER TO THE CURRENT NBP
SCBDEV::!BYTE	(9)1,0,M.CDR,M.LPT,M.PTR,M.PTP,M.PLT,MTXN,M.DTA+M.DTB,M.RJOB,0
NDBLEN==:.				;LENGTH
	DEPHASE
	$HIGH
;BYTE POINTERS
NDBMML::POINT	10,NDBCTL(W),9		;DDCMP MAX MESSAGE LENGTH
NDBRFL::POINT	8,NDBCTL(W),17		;STATUS FLAGS

;	MESSAGE NUMBER RELEVANT TO OUTPUT MESSAGES
NDBLAR::POINT	8,NDBMNM(W),11		;LAST ACK RECEIVED
NDBLAP::POINT	8,NDBMNM(W),19		;LAST OUTPUT MESSAGE# ACK'ED
NDBLMS::POINT	8,NDBMNM(W),27		;LAST MESSAGE SENT
NDBLMA::POINT	8,NDBMNM(W),35		;LAST MESSAGE NUMBER ASSIGNED
NDBLAS::POINT	8,NDBFEK(W),17		;LAST ACK SENT

;	MESSAGE NUMBERS RELEVANT IN INPUT MESSAGES
NDBLMR::POINT	8,NDBSNM(W),35		;LAST INPUT MESSAGE RECEIVED
NDBNCA::
NDBLMP::POINT	8,NDBSNM(W),27		;LAST MESSAGE PROCESSED
					;THIS IS THE NCA ON OUTPUT

;	POINTERS TO THE SCBDEV TABLE
ZZ==0
NETDVN::SIXBIT	/MCRTTYCDRLPTPTRPTPPLTMTADTATSKRDACDP/
NETTRN::BYTE	(6).TYMCR/.TYEST,.TYTTY/.TYEST,.TYCDR/.TYEST,.TYLPT/.TYEST,.TYPTR/.TYEST,.TYPTP/.TYEST
	BYTE	(6).TYPLT/.TYEST,.TYMTA/.TYEST,.TYDTA/.TYEST,.TYTSK/.TYEST,.TYRDA/.TYEST,.TYCDP/.TYEST
NETCNF::
	REPEAT OBJ.MX+1,<
ZZZ==ZZ/4		;WORD OFFSET
ZZZZ==<<<ZZ-<ZZZ*4>>*9>+8>
	POINT	9,SCBDEV+ZZZ(W),ZZZZ
ZZ==ZZ+1
>;END OF REPEAT OBJ.MX
SUBTTL NETWORK IDLE/BUSY ROUTINES
	$HIGH
NETRTY::XWD	-M.RTTY,NETOFS##	;POINTER TO THE REMOTE TTY'S
				;IS USED FOR RING HEADER FOR OUTPUT ACTIVE TTYS

;SUBROUTINES NTYSET/NTYCLR - SET AND CLEAR A BIT IN THE TTY SERVICE TABLE
;CALL	MOVE	U,LDB
;	PUSHJ	P,NTYSET/NTYCLR
;RETURN	CPOPJ

;HERE TO SET A TTY OUTPUT ACTIVE
NTYSET::PUSHJ	P,NTYCOM	;SET UP REGISTERS
	JUMPN	T3,NTYRET	;ALREADY DONE SO EXIT
	HRRZ	T1,NDBATQ(W)	;FETCH RING HEADER
	JUMPE	T1,NTYST1	;NIL POINTER REQUIRES SPECIAL PROCESSING
	LDB	T2,LDPBLB##	;FETCH THE LINK TO THE
				;PRECEEDING TTY IN THE RING
	DPB	T4,LDPBLB##	;AND INSERT THE NEW TTY IN THIS LINKAGE
	DPB	T2,LDPALB##
	HRRZ	T1,LINTAB##-1(T2) ;CONVERT LINK TO POINTER
	LDB	T2,LDPBLF##	;AND THEN INSERT NEW TTY IN THE FOWARD LINKAGE
	DPB	T4,LDPBLF##
	DPB	T2,LDPALF##
	JRST	NTYRET		;RETURN

NTYST1:	HRRM	U,NDBATQ(W)	;INITIALIZE THE HEADER FOR THE RING
	DPB	T4,LDPALF##	;AND LINK THE TTY TO ITSELF
	DPB	T4,LDPALB##
	JRST	NTYRET		;DONE
;HERE TO SET A TTY OUTPUT INACTIVE
NTYCLR::PUSHJ	P,NTYCOM	;SET UP REGISTERS
	JUMPE	T3,NTYRET	;ALL DONE IF NOT ACTIVE
	LDB	T3,LDPALF##	;GET THE FORWARD POINTER
	LDB	T4,LDPALB##	;AND THE BACKWARD LINKAGE
	HRRZ	T1,LINTAB##-1(T4) ;LOCATE THE PRECEEDING TTY
	DPB	T3,LDPBLF##	;AND LINK AROUND THE INACTIVE ONE
	HRRZ	T1,LINTAB##-1(T3) ;LOCATE THE NEXT TTY
	DPB	T4,LDPBLB##	;AND LINK ARROUND THE INACTIVE ONE
	HRRZ	T2,U		;MAKE A COPY OF THE POINTER, LH=0
	HLRM	T2,LDBREM##+2(U) ;AND SET THE NIL LINKAGE
	CAIN	T2,(T1)		;IF THE RING IS EMPTY NOW,
	HLRM	T2,NDBATQ(W)	;ELSE ZERO THE RING HEADER
	HRRZ	T2,NDBATQ(W)	;HAVE WE JUST DELINKED THE NEXT TTY
	CAIN	T2,(U)		; NTYBSY WILL CHECK?
	HRRM	T1,NDBATQ(W)	;YES, ADVANCE THE RING
NTYRET:	CONO	PI,PION##	;REENABLE INTERRUPTS,
	PJRST	WPOPJ##		; RESTORE W, AND RETURN

;HERE TO SET UP REGISTERS FOR NTYSET/NTYCLR
NTYCOM:	EXCH	W,(P)		;WE WANT TO PRESERVE W AFTER RETURN FROM CALLER
	PUSH	P,W		;REPLACE RETURN ADDRESS
	HLRZ	W,LDBREM##(U)	;LOCATE NDB FOR TTY
	JUMPN	W,NTYCO1	;CONTINUE BELOW IF IT'S CONNECTED
	POP	P,W		;POP RETURN ADDRESS FROM STACK
				;SO WE RETURN TO CALLER'S CALLER
	PJRST	WPOPJ##		;RESTORE W AND RETURN TO CALLER'S CALLER

NTYCO1:	LDB	T4,LDPLNO##	;FETCH UNIT NUMBER FOR THIS TTY
	AOS	T4		;MAKE IT INTO A LINK VALUE
	CONO	PI,PIOFF##	;TURN INTERRUPTS OFF FOR THE DURATION
	HRRZ	T3,LDBREM##+2(U) ;FETCH ACTIVE RING LINKAGES FOR THIS TTY
	POPJ	P,		;AND CONTINUE
;SUBROUTINE NTYBSY - RETURN NEXT NETWORK TTY NEEDING SERVICE
;CALL:
;	MOVEI	W,<NDB NEEDING SERVICE>
;	PUSHJ	P,NTYBSY
;RETURN	CPOPJ		;NO TTY NEEDS SERVICE
;	CPOPJ1		;W=NDB, U=LDB OF TTY NEEDING SERVICE

NTYBSY::CONO	PI,PIOFF##	;TURN INTERRUPTS OFF FOR THE DURATION
	HRRZ	T4,NDBATQ(W)	;FETCH POINTER TO NEXT TTY IN RING FOR THIS NODE
	HRRZI	U,(T4)		;AND MAKE A SECOND COPY
	PJUMPE	U,ONPOPJ##	;EXIT IF NO NEXT TTY


				;SEARCH LOOP
NTYBS0:	LDB	T1,LDPALF##	;FETCH TO LINK TO TTY AFTER NEXT ONE
	HRRZ	T1,LINTAB##-1(T1) ;CONVERT LINK TO POINTER
	HRRZ	T2,LDBREM##(U)	;IF NEXT TTY IS IDLE, SKIP OVER IT
	TRNN	T2,LRRIDL##
	JRST	NTYBS2

	TRNE	T2,LRRNOT##	;IF TTY IS NOT ACTIVE FOR DATA OUTPUT ONLY
	JRST	NTYBS1		;SUCCESS

	LDB	T2,LDPDRQ##	;IF OUTSTANDING DATA REQUESTS,
	JUMPN	T2,NTYBS1	;SUCCESS

	MOVEI	T2,LRRTTW##	;SET WAITING FOR DATA REQUEST BIT
	IORM	T2,LDBREM##(U)
	MOVEI	T2,LRRTTO##	;AND CLEAR ACTIVE OUTPUT BIT
	ANDCAM	T2,LDBREM##(U)

NTYBS2:				;THIS TTY LOST SO TRY NEXT ONE
	HRRZ	U,T1		;COPY POINTER TO NEXT ONE
	CAIE	T1,(T4)		;IF ANOTHER TTY TO TRY, LOOP
	JRST	NTYBS0

				;FAILURE EXIT
	SETZ	U,		;RETURN NIL LDB POINTER

	PJRST	ONPOPJ##	;ENABLE INTERRUPTS AND RETURN

NTYBS1:				;SUCCESS EXIT
	HRRM	T1,NDBATQ(W)	;ADVANCE THE RING HEADER POINTER
	CONO	PI,PION##	;RESTORE INTERRUPTS
	LDB	T1,LDPLNO##	;FETCH THE UNIT NUMBER OF THE WINNING TTY
	MOVE	U,LINTAB##(T1)	;AND FETCH THE LINE TABLE ENTRY
	JRST	CPOPJ1		;SKIP RETURN FOR EXIT
SUBTTL COMMON BUFFER POOL FOR NETWORK TTY'S
	$LOW
XP	NBPLEN,PCBLEN+<NBPBFL/4>+^D10
	DEFINE	TTYBUF<
X0.==.				;;ORIGIN OF THE BUFFER POOL
	BLOCK	PCBLEN		;;ALLOCATE SPACE FOR THE PDC
X1.==.				;;ORIGIN FOR THE DATA BUFFER
	BLOCK	NBPBFL/4+14	;;SIZE OF THE DATA BUFFER
	RELOC	X0.+PCBBLK
	EXP	<(PCB.NM!PCB.TY)>
	RELOC	X0.+PCBOAD
	POINT	8,X1.
	RELOC	X0.+NBPLEN
>
NBPTTY:
NBPSIZ==<<M.RTTY/NTTYPL>+1>
REPEAT NBPSIZ,<
	TTYBUF
>;END OF REPEAT

	$HIGH
;SUBROUTINE GETNBP - GET A TTY BUFFER FROM THE POOL
;CALL	MOVEI	W,NDB
;	PUSHJ	P,GETNBP
;RETURN	CPOPJ			;NO BUFFER AVAILABLE
;	CPOPJ1		;U=PCB OF THE BUFFER

NBPPTR::XWD	-NBPSIZ,NBPTTY		;POINTER TO THE FREE POOL
GETNBP::SKIPN	U,NBPLST		;GET THE LAST REFERENCE
	MOVE	U,NBPPTR		;GET THE START OF THE POOL
GETNB1:	SKIPN	PCBNDB(U)		;IS THIS BUFFER AVAILABLE?
	JRST	[HRRZM	W,PCBNDB(U)	;YES, SET IT BUSY
		HLLZS	PCBBLK(U)	;CLEAR ANY LINK POINTERS
		MOVEM	U,NBPLST	;SAVE THE LAST POINTER
		ANDI	U,-1		;CLEAR THE JUNK
		JRST	CPOPJ1##]	;GOOD RETURN
	ADD	U,[XWD 1,NBPLEN]	;POINT TO THE NEXT ENTRY
	SKIPL	U			;AT THE END OF THE POOL?
	MOVE	U,NBPPTR		;RELOAD THE POINTER
	CAMN	U,NBPLST		;ALL THE WAY AROUND?
	POPJ	P,			;YES, EXIT
	JRST	GETNB1			;CONTINUE SCAN

	$LOW
NBPLST:	Z				;LAST REFERENCE TO THE TTY POOL
SUBTTL NDT NETWORK DEVICE TABLE

;PROTOTYPE NDT TO DEFINE REMOTE DEVICE CHARACTERISTICS WITHIN THE NETWORK
;THIS DTA BLOCK MUST BE REFERENCED BY AC"W"
	$HIGH
NETNDT::
	PHASE	0
NDTNAM::!Z;	XWD	0,0		;(0) GENERIC DEVICE NAMES
NDTMOD::!Z;	0			;(1) SEE DEVMOD IN THE DDB
NDTATR::!Z;	XWD	0,0		;(2) OBJECT TYPE,DEVICE ATTRIBUTES
NDTCHR::!Z;	BYTE	(6)0(12)0(18)0	;(3) TYPE BUFFER SIZE
NDTNDP::!Z;	DEVNDP(T1)		;(4) INDIRECT POINTER TO NDP
NDTLEN==:.				;LENGTH OF THE NDT
	DEPHASE
	RELOC	NETNDT			;REMOVE THE SPACE


;BYTE POINTER TO THE NDT BLOCK
NDTTYP::POINT	6,NDTCHR(W),5		;-10 DEVTYP BYTE
NDTBFZ::POINT	12,NDTCHR(W),17		;-10 BUFFER SIZE
NDTDVT::POINT	16,NDTATR(W),35		;-11 DEVICE ATTRIBUTES
NDTOBJ::POINT	8,NDTATR(W),17		;-11 DEVICE TYPE CODE
NDTDCM::POINT	10,NDTATR(W),9		;NETWORK DEVICE MODES
	DEFINE NDT(XDEV,XIDEV,BUFSZ,CHR,DCM,DVT)<
	ZZ.==ZZ.+1
	BYTE	(18)<(SIXBIT /XDEV/)>,<(SIXBIT /XIDEV/)>
	XWD	CHR,XDEV'MOD
	BYTE	(10)DCM(8)OBJ.'XIDEV(2)0(16)DVT
	BYTE	(6)<.TY'XDEV/.TYEST>(12)BUFSZ(18)0
	XDEV'NDP##(T1)
>
	ZZ.==0				;COUNT THE NDT'S

NDTTBL=:.			;START OF NDT TABLE
;DEFINE THE REMOTE LINE PRINTERS
IFG M.RLPT,<
	EXTERNAL	NDEVLP,NETLPT
LPTMOD==1_A+1_AL+1_I	;LEGAL -10 MODES
	NDT	(LPT,LP,33,<DVOUT!DVLPT>,<DCM.CP!DCM.AS>,0)
>

;DEFINE THE REMOTE CARD READERS
IFG M.RCDR,<
	EXTERNAL	NDEVCD,NETCDR
CDRMOD==1_A+1_AL+1_I+1_IB+1_B
	NDT	(CDR,CD,34,<DVIN!DVCDR>,<DCM.DI>,0)
>

;DEFINE THE REMOTE PAPER TAPE READERS
IFG M.RPTR,<
	EXTERNAL	NDEVPR,NETPTR
PTRMOD==1_B+1_AL+1_I+1_IB+1_A
	NDT	(PTR,PR,41,<DVIN!DVPTR>,<DCM.AS!DCM.IM>,0)
>

;DEFINE THE REMOTE PAPER TAPE PUNCHES
IFG M.RPTP,<
	EXTERNAL	NDEVPP,NETPTP
PTPMOD==1_B+1_AL+1_I+1_IB+1_A
	NDT	(PTP,PP,41,<DVOUT!DVPTP>,<DCM.AS!DCM.IM>,0)

>
;DEFINE THE REMOTE MAG TAPES
IFG M.RPLT,<
	EXTERNAL	NDEVPL,NETPLT
PLTMOD==1_A+1_AL+1_I+1_IB+1_B		;PLOTTER LEGAL MODES
	NDT	(PLT,PL,44,<DVOUT>,<DCM.AS!DCM.IM>,0)
>
IFG M.RMTA,<
	EXTERNAL	NDEVMT,NETMTA
MTAMOD==1_A
	NDT	(MTA,MT,103,<DVIN!DVOUT!DVMTA!DVLNG>,<DCM.AS!DCM.IM>,0)
>

;DEFINE REMOTE TASKS
IFG M.RJOB,<
	EXTERNAL	NDEVTS,NETTSK
TSKMOD==1_B+1_I+1_IB+1_A+1_AL
	NDT	(TSK,TK,101,<DVIN!DVOUT!DVLNG!DVDIR>,<DCM.AS!DCM.IM>,0)
>

;DEFINE REMOTE DATA ENTRY DEVICES
IFN M.RDX,<
	EXTERNAL	NDEVRX,NETRDX
RDAMOD==1_A+1_AL
	NDT	(RDA,RD,101,<DVIN!DVOUT>,<DCM.AS>,0)
>
NDTPTR::XWD	-ZZ.,NDTTBL		;POINTER TO SEARCH THE NDT TABLE
	$LOW
IFN M.RJOB,<
SUBTTL TASK TABLES
TSKTBL::			;ORIGIN OF THE TASK TABLE
	PHASE	0
TSKNAM::!Z			;(0) TASK NAME
TSKEXT::!Z			;(1) EXTENSION,0
TSKPPN::!Z			;(2) PPN
TSKDDB::!Z			;(3) XWD DDB,LAT
TSKLEN==:.			;LENGTH OF THE TASK ENTRY
	DEPHASE
	RELOC	TSKTBL		;SAVE SPACE

	BLOCK	TSKLEN*M.RJOB	;FOR THE ENTRIES
	$HIGH
TSKPTR::XWD	-M.RJOB,TSKTBL	;POINTER TO THE TASK TABLE
>	;END IFN M.RJOB
SUBTTL FEK FRONT END KONTROLLER DATA BLOCKS
	$LOW
;DEFINE THE OFFSETS
IFNDEF DAETBL,<DAETBL==^D10>	;SIZE OF DAEMON ERROR TABLE
	PHASE	0
FEKBLK::!Z;	XWD	0,0		;(0) FLAGS, LINK TO NEXT FEK
	XP	FK.ONL,(1B0)	;ONLINE SAME AS NOT DOWN
				;MUST BE THE SIGN BIT
	XP	FK.NID,(1B1)	;NODE ID HAS BEEN SENT
FEKONC::!Z;	PUSHJ	P,0		;(1) CALLED AT ONCE ONLY
FEKRDD::!Z;	PUSHJ	P,		;(2) INPUT ROUTINE
FEKIAD::!Z;	XWD	0,0		;(3) POINTER TO THE PCB
FEKBSI::!Z;	-1			;(4) INPUT BUSY FLAG
FEKWRT::!Z;	PUSHJ	P,0		;(5) OUTPUT ROUTINE
FEKOAD::!Z;	XWD	0,0		;(6) POINTER TO THE PDB
FEKBSO::!Z;	-1			;(7) OUTPUT BUSY
FEKSEC::!Z;	PUSHJ	P,		;(10) CALLED ONCE A SECOND
FEKMXL::!Z;	Z			;(11) MAX RECORD LENGTH
FEKUNI::!Z;	Z			;(12) RESERVED FOR D??INT OWN USE
FEKERR::!Z;	XWD	-DAETBL,.+1	;(13) ERROR REPORT TABLE
		BLOCK	DAETBL
FEKLEN==:.		;LENGTH OF FEK
	DEPHASE
	RELOC	.-FEKLEN
;FLAGS DEFINE IN THE LEFT HALF OF "J" ON CALL TO FEKINT
;TO PROCESS THE INTERRUPT
	XP	FI.IN,(1B1)	;=1 IF INTERRUPT ON INPUT
	XP	FI.OUT,(1B2)	;=1 IF INTERRUPT ON OUTPUT
	XP	FI.IOD,(1B3)	;=1 IF IO DONE SET (SEE 1B1,1B2 FOR DIRECTION)
	XP	FI.IND,FI.IN!FI.IOD
	XP	FI.OUD,FI.OUT!FI.IOD
	XP	FI.IMP,(1B4)	;=1 IMPROPER MODE
	XP	FI.DVR,(1B5)	;=1 DEVICE ERROR
	XP	FI.BTL,(1B6)	;=1 BLOCK TO LARGE
	XP	FI.DAT,(1B7)	;=1 DATA ERROR
	XP	FI.DWN,(1B10)	;=KONTROLLER WENT DOWN (REMOVE ALL QUEUES)
	XP	FI.DAE,(1B11)	;=1 DAEMON ERROR REPORT CALL
SUBTTL MACRO TO GENERATE FEK'S
	DEFINE FEKGEN(NAM,NM)<
IF2, <
	IFNDEF NAM'ONC,<EXTERNAL NAM'ONC>
	IFNDEF NAM'RDD,<EXTERNAL NAM'RDD>
	IFNDEF NAM'WRT,<EXTERNAL NAM'WRT>
	IFNDEF NAM'SEC,<EXTERNAL NAM'SEC>
>;END OF IF2
	IFB	<NM>,<
NAM'FEK::
>;IFB	NM
	IFNB	<NM>,<
NM'FEK::
>;IFNB	NM
	XWD	0,0		;;(0) FEKBLK
	.LINK	FEKLNK,.-1	;;   LINK PSEUDO OP
	PUSHJ	P,NAM'ONC	;;(1)  FEKONC
	PUSHJ	P,NAM'RDD	;;(2)  FEKRDD
	XWD	0,0		;;(3)  FEKIAD
	-1			;;(4)  FEKBSI
	PUSHJ	P,NAM'WRT	;;(5)  FEKWRT
	XWD	0,0		;;(6)  FEKOAD
	-1			;;(7)  FEKBSO
	PUSHJ	P,NAM'SEC	;;(10) FEKSEC
	Z			;;(11) FEKMXL
	Z			;;(12) FEKUNI
	XWD	-DAETBL,.+1	;;(13) FEKERR
	BLOCK	DAETBL
	>;END OF FEKGEN
SUBTTL	DAS85 FEK

IFNDEF M.DC75,<M.DC75=0>
IFN M.DC75,<EXTERN	D85INT>
	DEFINE	FEK85(P),<
	IFN	M.'P'D85,<
	FEKGEN	(D85,D8'P)
	>;IFN	M.'P'D85
	>	;DEFINE	FEK85
Z==-1
REPEAT 8,<	FEK85	\<Z==Z+1>>

IFNDEF M.D87S,<M.D87S=0>
IFN M.D87S,<EXTERN	D8SINT>
DEFINE	FEK8S(P),<
	IFN M.'P'D8S,<
	FEKGEN	(D8S,DS'P)
	>;IFN	M.'P'D8S
>	;DEFINE FEK8S
Z==-1
REPEAT	4,<	FEK8S	\<Z==Z+1>>
SUBTTL	DTE20 INTERFACE

;DEFINE OFFSETS INTO THE DTK (DTE20 KONTROL BLOCK)

DTKARC==:0			;SEMAPHORE FOR ACK RACE CONDITION. NORMALLY -1,
				; THIS IS USED BY UUO LEVEL CODE TO LOCK INTERRUPT
				; CODE FROM SENDING AN ACK WHILE IT'S SENDING SEVERAL
				; FRAGMENTS OF AN NCL MESSAGE

DTKUNI==:1			;RH: DTE20 UNIT NUMBER ASSOCIATED WITH THIS
				; DTK AND FEK

DTKIBP==:2			;BYTE POINTER USED BY INPUT CODE TO IMPLEMENT
				; A GATHER READ OPERATION WHERE THE -11 SENDS
				; SEVERAL MESSAGES DESTINED TO BECOME A SINGLE
				; NCL MESSAGE


DEFINE DTKGEN(DTE)<
DS'DTE'DTK:	EXP	-1		;;(0) DTKARC
	EXP	DTE		;;(1) DTKUNI
	EXP	0		;;(2) DTKIBP
>

DEFINE	DTKDEF(DTE)<
    IFN M.'DTE'D8S,<DTKGEN(DTE)>>

ZZ==-1				;NOW TO GENERATE ALL DTK'S
REPEAT	4,<	DTKDEF	\<ZZ==ZZ+1>>


;GENERATE TABLE TO MAP FROM DTE # TO FEK ADDRESS

$HIGH
DEFINE	DTEDEF(DTE),<
    IFN M.'DTE'D8S,<
	DS'DTE'DTK,,DS'DTE'FEK	;;THEN WE HAVE A REAL FEK
;>	EXP	0		;;ELSE NOT A NETWORK FE, NO FEK
>

Z==-1
DTEFEK::REPEAT	4,<	DTEDEF	\<Z==Z+1>>
	$LIT
CNTEND::END