Google
 

Trailing-Edge - PDP-10 Archives - BB-5255D-BM - 4-sources/netser.mac
There are 13 other files named netser.mac in the archive. Click here to see a list.
;<4.ARPA-UTILITIES>NETSER.MAC.8,  4-Jan-80 09:47:17, EDIT BY R.ACE
;UPDATE COPYRIGHT DATES
;<4.ARPA-UTILITIES>NETSER.MAC.7, 11-Oct-79 11:39:13, Edit by LCAMPBELL
; Update version and edit numbers for release 4
;<4.ARPA-UTILITIES>NETSER.MAC.6,  9-Jan-79 13:56:37, Edit by LCAMPBELL
; Update copyright notice
;<LCAMPBELL>NETSER.MAC.3,  6-Oct-78 09:07:11, Edit by LCAMPBELL
;<LCAMPBELL>NETSER.MAC.2,  5-Oct-78 21:39:21, Edit by LCAMPBELL
; Use GTNCP instead of GDSTS to get foreign host and socket
;<3-CLEMENTS>NETSER.MAC.5, 20-Aug-78 23:09:06, EDIT BY CLEMENTS
;<3-CLEMENTS>NETSER.MAC.4, 18-Aug-78 14:20:19, EDIT BY CLEMENTS
;<3-CLEMENTS>NETSER.MAC.1, 13-Aug-78 22:47:38, EDIT BY CLEMENTS
; CHANGE FOR LONG HOST NUMBERS
;<3.ARPA-UTILITIES>NETSER.MAC.5, 14-Nov-77 10:22:17, EDIT BY CROSSLAND
;CORRECT COPYRIGHT NOTICE
;<3.ARPA-UTILITIES>NETSER.MAC.4, 26-Oct-77 02:40:19, EDIT BY CROSSLAND
;UPDATE COPYRIGHT FOR RELEASE 3
;<3.ARPA-UTILITIES>NETSER.MAC.3,  5-Oct-77 00:11:08, EDIT BY CROSSLAND
;REMOVE CONDITIONAL AROUND NTELNET SOCKET
;<A-SOURCES>NETSER.MAC.3, 20-Dec-76 13:30:54, EDIT BY CLEMENTS
;<A-SOURCES>NETSER.MAC.2, 17-Dec-76 12:06:55, EDIT BY CLEMENTS
;<2MURPHY>NETSER.MAC.41, 20-Sep-76 15:53:25, EDIT BY MURPHY
;<SOURCES>NETSER.FAI;56    20-May-76 14:33:10    EDIT BY CLEMENTS
; Increase scale factor on timeouts in CRPROC by a factor of 2
;<SOURCES>NETSER.FAI;55    12-May-76 11:15:31    EDIT BY ROSENBERG
; Invent and use "NOKILL" to prevent interference while cleaning up
;<TOMLINSON>NETSER.FAI;1    10-APR-74 23:14:22	EDIT BY TOMLINSON
; ADDED LOGGER FOR SOCKET 23
;<SOURCES>NETSER.FAI;51    16-JAN-73 12:35:03	EDIT BY TOMLINSON
;<TOMLINSON>NETSER.FAI;1     8-JAN-73 15:46:43	EDIT BY TOMLINSON
; CHANGED SOCKET NUMBERS
;<TOMLINSON>NETSER.FAI;7    12-JUL-72 16:09:16	EDIT BY TOMLINSON


;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 Digital Equipment Corporation, Maynard, Mass.


	TITLE NETSER
	SEARCH MONSYM,MACSYM
	SALL
	.DIRECT FLBLST
	.REQUIRE SYS:MACREL

VWHO==0			;LAST EDITED BY DEC
VMAJOR==4		;MAJOR VERSION #
VMINOR==0		;REVISION #
VEDIT==6		;EDIT NUMBER

	LOC	<.JBVER==137>
VERSIO:	<VWHO>B2+<VMAJOR>B11+<VMINOR>B17+VEDIT ;VERSIONS FOR TYPEOUT
	RELOC
;ROUTINE MECHANICS

	COMMENT \
STACK FRAME PICTURE

		..
		ARG N-1
		ARG N
		NARGS+1,,NARGS+1
		RETURN PC
	FREG -)	SAVED FREG
		SAVED AC'S
		LOCAL STORAGE
	P -)	LAST WORD OF LOCAL STORAGE
\

DEFINE ROUTINE (NAME,ACARG,STKARG,LOCALS,REGS,%EXIT)<
NAME:
	PUSH P,FREG		;;PRESERVE FREG
	MOVE FREG,P		;;SETUP FREG FOR THIS ROUTINE
	.NAC==0			;;COUNT PRESERVED ACS
	IRP REGS,<
	  PUSH P,P1+.NAC	;;PRESERVE AN AC
	  REGS==P1+.NAC		;;DEFINE LOCAL SYMBOL
	  .NAC=.NAC+1>
	IFG .NAC-NPAC,<PRINTX NAME - TOO MANY AC LOCALS>
	.NSTK==.NAC		;;ACCOUNT SPACE USED SO FAR
	.NLOC==0		;;COUNT LOCAL STORAGE
	IRP LOCALS,<
	.DOLOC (LOCALS)>
	.DOEX (\.NLOC,\.NAC,<ACARG>,<STKARG>,<LOCALS>,<REGS>,%EXIT) ;;DEFINE ENDR
	IFG .NLOC,<ADD P,[.NLOC,,.NLOC]> ;;ALLOCATE SPACE FOR LOCALS
	DEFINE EXIT <%EXIT>	;;DEFINE EXIT TAG
	CNTARG (<ACARG>,.NACA)	;;COUNT ACARGS
	CNTARG (<STKARG>,.NSTKA) ;;COUNT STKARGS
	IFG .NACA-NACA,<PRINTX NAME - TOO MANY AC ARGS>
	.LOC==3+.NACA+.NSTKA	;;LOC OF FIRST ARG
	..A==J1			;;FIRST AC FOR AC ARGS
	IRP ACARG,<
	  .LOC=.LOC-1
	  ACARG==..A		;;DEFINE LOCAL SYMBOL FOR AC
	  MOVE ACARG,-.LOC(FREG) ;;PUT VALUE IN AC
	  ..A=..A+1>
	IRP STKARG,<
	  .LOC=.LOC-1
	  .DEFSA (STKARG,\.LOC)> ;;DEFINE SYMBOL
   >

DEFINE CNTARG (ARGS,SYM)<
	SYM==0
	IRP ARGS,<
	  SYM=SYM+1>>

DEFINE .DEFSA (NAM,LOC)<
  DEFINE NAM <-^O'LOC(FREG)>>

  DEFINE .DOLOC (ARG)<
	.DOLC2 (ARG)>		;;PEEL OFF ANGLEBRACKETS IF ANY

DEFINE .DOLC2 (NAM,SIZ)<
    IFB <SIZ>,<.DOLC1 NAM,1>
    IFNB <SIZ>,<.DOLC1 NAM,SIZ>>

  DEFINE .DOLC1 (NAM,SIZ)<
	.NS0==.NSTK+1		;;FIRST WORD OF THIS LOCAL
	.NSTK=.NSTK+SIZ
	.NLOC=.NLOC+SIZ
	.DEFNM (NAM,\.NS0)>

  DEFINE .DEFNM (NAM,LOC)<
	DEFINE NAM <^O'LOC(FREG)>>

  DEFINE .DOEX (NLOC,NAC,ACSYM,STKSYM,LOCSYM,REGSYM,TAG)<
    DEFINE ENDR <
TAG:	IFG NLOC,<SUB P,[NLOC,,NLOC]> ;;REMOVE LOCAL STORAGE
	JRST .POP'NAC		;;POP PRESERVED ACS AND RETURN
	.PURG <ACSYM>		;;PURGE SYMBOLS
	.PURG <STKSYM>
	.PURG <LOCSYM>
	.PURG <REGSYM>
   >>				;;END 2 DEFINES

DEFINE .PURG (SYMS)<
   IRP SYMS,<
	.PURG1 SYMS>>

  DEFINE .PURG1 (SYM)<
	.PURG2 SYM>		;;REMOVE ANGLEBRACKETS IF PAIR

  DEFINE .PURG2 (SYM,JUNK)<
	PURGE SYM,SYM>

DEFINE SKIPRT <
	AOS -1(FREG)>

DEFINE RETURN <-1(FREG)>

DEFINE SCALL (NAME,ARGS)<
	.NARG==0
	IRP ARGS,<
	PUSH P,ARGS
	.NARG==.NARG+1>
	PUSH P,[.NARG+1,,.NARG+1] ;;RECORD SPACE USED
	PUSHJ P,NAME
   >
;STRUCTURE

;TASKZ

DEFSTR TZPTRS,0,35,36
DEFSTR PRMBIT,1,0,1
DEFSTR USRTSK,1,1,1
DEFSTR TTYBIT,1,2,1
DEFSTR BSYBIT,1,3,1
DEFSTR LSKT,1,35,32
DEFSTR TSKNAM,2,35,36
DEFSTR TJFN,3,5,6
DEFSTR LIFTIM,3,11,6
DEFSTR PROCNT,3,17,6
DEFSTR FORKSA,3,35,18

;PROCZ

DEFSTR PZPTRS,0,35,36
DEFSTR FORK,1,17,18
DEFSTR TASKP,1,35,18
DEFSTR KILTIM,2,35,36
DEFSTR FAILRE,3,17,18
DEFSTR BSYJFN,3,18,1
DEFSTR NOKILL,3,19,1

; ACCUMULATORS

VREG=1
J1=1			;JSYS AND ROUTINE ARGUMENTS
J2=2
J3=3
J4=4
 NACA==4			;;MAX AC ARGS
T1=5
T2=6
T3=7
T4=10

P1==11
 NPAC==4			;;MAX PRESERVED ACS
FREG=15
CX=16
P=17

; PARAMETERS

LSNG==3
PNDG==2
RFCR==4
OPND==7
PDL=200000
LPDL==2000
NFREE==1000
NBLKS==^D100
ITMSIZ==4

; GLOBAL VARIABLES

DEFINE INTEGER (XX)<
	IRP XX,<
XX:	BLOCK 1>>

INTEGER <FRELST,TASKS,PRLST,TTYJFN,SKTCNT,DTACHF,RETPC1,RETPC2>
INTEGER <SUMFLG,WATLCK,FREBLK>
INTEGER <PRIVF>		;0 FOR SYSTEM, NON-0 FOR PRIVATE TESTING
FRESTO:	BLOCK ITMSIZ*NFREE
BLKSTO:	BLOCK NBLKS*^D30

;COMMON EXIT SEQUENCE

.POP5:	POP P,P1+4
.POP4:	POP P,P1+3
.POP3:	POP P,P1+2
.POP2:	POP P,P1+1
.POP1:	POP P,P1
.POP0:
.EXIT:	POP P,FREG
	POP P,CX		;POP RETURN
	SUB P,0(P)		;RESTORE STACK FOR CALLER
	JRST 0(CX)
SETINT:	ROUTINE(SETINT)
	MOVEI 1,400000
	MOVE 2,[XWD LEVTB0,CHNTB0]
	SIR
	EIR
	MOVE 2,[1B19+1B1]
	AIC
	MOVE 1,[XWD 23,1]
	ATI
	SETOM WATLCK
	ENDR

WATINT:	ROUTINE(WATINT)
	MOVEI 1,^D10000
	AOSN WATLCK
	DISMS
WATCON:	SETOM WATLCK
	ENDR

INTINT:	MOVMS WATLCK
	SKIPE WATLCK
	DEBRK
	MOVE 1,[XWD 10000,WATCON]
	MOVEM 1,RETPC2
	DEBRK

SUMINT:	SETOM SUMFLG
	PUSH P,1
	PUSH P,2
	MOVEI 1,400000
	MOVEI 2,1B19
	IIC
	POP P,2
	POP P,1
	DEBRK

LEVTB0:	RETPC1
	RETPC2
	0

CHNTB0:	0
	XWD 1,SUMINT
	REPEAT ^D17,<0>
	XWD 2,INTINT
	REPEAT ^D36-^D19-1,<0>

SCNTSK:	ROUTINE(SCNTSK,,,<<STRING,20>,BEGSTR>,TASK)
	SKIPN SUMFLG
	 JRST NOSUM
	MOVEI 1,STRING
	HRLI 1,(<POINT 7,0>)
	MOVEM 1,BEGSTR
	HRROI 2,[ASCIZ /SUMMARY
/]
	SETZ 3,
	SOUT
	HRRZ TASK,TASKS
SLOOP:	CAIN TASK,TASKS
	 JRST ESUM
	HRROI 2,[ASCIZ /               /]
	SETZ 3,
	SOUT
	LOAD 3,TSKNAM,(TASK)
	MOVEI T2,7
LP11:	SETZ 2,
	ROTC 2,6
	ADDI 2,40
	IDPB 2,1
	SOJG T2,LP11
	LOAD 2,PROCNT,(TASK)
	MOVE 3,[1B2+3B17+^D10]
	NOUT
	 JFCL
	HRROI 2,[ASCIZ / ACTIVE PROCESSES
/]
	SETZ 3,
	SOUT
	HRRZ TASK,0(TASK)
	JRST SLOOP

ESUM:	SCALL LOGMESSAGE,BEGSTR
	SETZM SUMFLG
NOSUM:	HRRZ TASK,TASKS
LOOP1:	CAIN TASK,TASKS
	 JRST EXIT
	SCALL EXTASK,TASK
	HRRZ TASK,0(TASK)
	JRST LOOP1
	ENDR
SCNPRC:	ROUTINE(SCNPRC,,,<<STRING,20>>,<PROCES,NOW>)
	TIME
	MOVEM 1,NOW
	HRRZ PROCES,PRLST
LOOP2:	CAIN PROCES,PRLST
	 JRST EXIT
	LOAD 1,FORK,(PROCES)
	RFSTS
	HRRZ T2,1
	LDB T1,[POINT 6,1,17]
	CAIE T1,3
	 JRST NODEAD
	SETZRO KILTIM,(PROCES)
	MOVEI 1,STRING
	HRLI 1,(<POINT 7,0>)
	STOR 1,FAILRE,(PROCES)
	HRROI 2,[ASCIZ /FORK DIED CHAN /]
	SETZ 3,
	SOUT
	MOVE 2,T2
	MOVEI 3,12
	NOUT
	 JFCL
NODEAD:	CAMGE NOW,2(PROCES)
	 JRST ELOOP2
	MOVE 1,PROCES
	HRRZ PROCES,0(PROCES)
	SCALL KLPROC,<J1>
	JRST LOOP2

ELOOP2:	HRRZ PROCES,0(PROCES)
	JRST LOOP2
	ENDR

MAPFRK:	ROUTINE(MAPFRK,FKH)
	HRLZ 2,1
	HRLZI 1,400000
	HRLZI 3,160000
	MOVEI T1,777
MAPLP:	CAIN T1,677
	 MOVE T1,TOPPAG
	HRR 1,T1
	HRR 2,T1
	PMAP
	SOJGE T1,MAPLP
	ENDR

FILEMESSAGE:
	ROUTINE(FILEMESSAGE,JFN,MSG)
	DOBE
	SETO 2,
	MOVSI 3,45240
	ODTIM
	MOVEI 2," "
	BOUT
	BOUT
	MOVE 2,MSG
	SETZ 3,
	SOUT
	HRROI 2,[ASCIZ /
/]
	SETZ 3,
	SOUT
	ENDR
LOGMESSAGE:
	ROUTINE(LOGMESSAGE,,MSG,JFN)
	SCALL FILEMESSAGE,<TTYJFN,MSG>
	MOVE 1,[400001,,1]
	HRROI 2,[ASCIZ /SYSTEM:NETSER.LOG/]
	GTJFN
	 JRST [	TMSG <
?NETSER: CAN'T WRITE SYSTEM:NETSER.LOG BECAUSE >
		JSERR
		JRST EXIT]
	MOVEM 1,JFN
	MOVE 2,[XWD 70000,20000]
	OPENF
	 JRST RLJF
	SCALL FILEMESSAGE,<1,MSG>
	CLOSF
	 JFCL
	JRST EXIT

RLJF:	MOVE 1,JFN
	RLJFN
	 JFCL
	TMSG <
?NETSER: CAN'T WRITE SYSTEM:NETSER.LOG BECAUSE >
	ENDR

SGNON:	ROUTINE(SGNON,,<NAME,FHOST,FSKT,LFORK>,<<STRING,24>,BEGSTR>)
	MOVEI 1,STRING
	HRLI 1,(<POINT 7,0>)
	MOVEM 1,BEGSTR
	MOVE T1,[POINT 6,NAME]
	MOVEI T2,6
LOOP3:	ILDB T3,T1
	ADDI T3,40
	IDPB T3,1
	SOJG T2,LOOP3
	MOVEI T1," "
	IDPB T1,1
	IDPB T1,1
	MOVE 2,FHOST
	MOVEI 3,10
	MOVE T1,1		; SAVE DESTINATION
	CVHST			; CONVERT HOST NUMBER TO STRING
	 JRST [	MOVE 1,T1
		NOUT		; OR TO NUMBER
		 MOVE 1,T1	; RESTORE DESTINATION
		JRST .+1]
	MOVEI T1,"-"
	IDPB T1,1
	MOVE 2,FSKT
	NOUT
	 JFCL
	HRROI 2,[ASCIZ / FORK /]
	SETZ 3,
	SOUT
	MOVE 2,LFORK
	ANDI 2,177777
	MOVEI 3,^D10
	NOUT
	 JFCL
	SCALL LOGMESSAGE,BEGSTR
	ENDR
SGNOFF:	ROUTINE(SGNOFF,,<NAME,LFORK,FAILF,CPUTIM>,<<STRING,24>,BEGSTR>)
	MOVEI 1,STRING
	HRLI 1,(<POINT 7,0>)
	MOVEM 1,BEGSTR
	MOVE T1,[POINT 6,NAME]
	MOVEI T2,6
LOOP4:	ILDB T3,T1
	ADDI T3,40
	IDPB T3,1
	SOJG T2,LOOP4
	HRROI 2,[ASCIZ / FORK /]
	SETZ 3,
	SOUT
	MOVE 2,LFORK
	ANDI 2,177777
	MOVEI 3,^D10
	NOUT
	 JFCL
	HRROI 2,[ASCIZ / USED /]
	SETZ 3,
	SOUT
	MOVE 2,CPUTIM
	MOVE 3,[024100040200]
	FLOUT
	 JFCL
	MOVEI T1," "
	IDPB T1,1
	SKIPN 2,FAILF
	 MOVEI 2,[ASCIZ /SUCCESSFUL COMPLETION./]
	HRLI 2,(<POINT 7,0>)
	SETZ 3,
	SOUT
	SCALL LOGMESSAGE,BEGSTR
	ENDR

LINK:	ROUTINE(LINK,<ITEM,BASE>)
	HLRZ T1,0(BASE)
	HRLM T1,0(ITEM)
	HRRM BASE,0(ITEM)
	HRRM ITEM,0(T1)
	HRLM ITEM,0(BASE)
	ENDR

UNLINK:	ROUTINE(UNLINK,ITEM)
	HRRZ T1,0(ITEM)
	HLRZ T2,0(ITEM)
	HRLM T2,0(T1)
	HRRM T1,0(T2)
	HRRM ITEM,0(ITEM)
	HRLM ITEM,0(ITEM)
	ENDR
GETITM:	ROUTINE(GETITM)
	HRRZ VREG,FRELST
	CAIN VREG,FRELST
	 JRST EXIT
	SCALL UNLINK,VREG
	SKIPRT
	ENDR

RELEAS:	ROUTINE(RELEAS,ITEM)
	SCALL LINK,<ITEM,[FRELST]>
	ENDR

GETBLK:	ROUTINE(GETBLK)
	MOVEI VREG,^D25
	ADD VREG,FREBLK
	CAIL VREG,BLKSTO+NBLKS*^D25
	 JRST EXIT
	EXCH VREG,FREBLK
	SKIPRT
	ENDR

CRTASK:	ROUTINE(CRTASK,,<NAM,SKT,FRK,TIM,PRM,UTSK,TTYF>)
	SCALL GETITM
	 JRST EXIT
	MOVE T1,SKT
	STOR T1,LSKT,(VREG)
	MOVE T1,NAM
	STOR T1,TSKNAM,(VREG)
	MOVE T1,FRK
	STOR T1,FORKSA,(VREG)
	MOVE T1,TIM
	IDIVI T1,^D10
	STOR T1,LIFTIM,(VREG)
	MOVE T1,PRM
	STOR T1,PRMBIT,(VREG)
	MOVE T1,UTSK
	STOR T1,USRTSK,(VREG)
	MOVE T1,TTYF
	STOR T1,TTYBIT,(VREG)
	SETZ T1,
	STOR T1,TJFN,(VREG)
	STOR T1,BSYBIT,(VREG)
	STOR T1,PROCNT,(VREG)
	SCALL LINK,<VREG,[TASKS]>
	SKIPRT
	ENDR
CRPROC:	ROUTINE(CRPROC,,TSK,<<ACS,20>>,PROCES)
	SCALL GETITM
	 JRST EXIT
	MOVEM VREG,PROCES
	MOVSI 1,200000
	CFORK
	 JRST [	SCALL RELEASE,PROCES
		JRST EXIT]
	STOR 1,FORK,(PROCES)
	SETZI T1,
	STOR T1,NOKILL,(PROCES)
	SCALL MAPFRK,1
	MOVE T1,TSK
	STOR T1,TASKP,(PROCES)
	LOAD T2,LIFTIM,(T1)
	IMULI T2,^D20000
	TIME
	ADD T2,1
	STOR T2,KILTIM,(PROCES)
	MOVEI T2,[ASCIZ /TIMED-OUT/]
	STOR T2,FAILRE,(PROCES)
	MOVEI T2,1
	STOR T2,BSYBIT,(T1)
	STOR T2,BSYJFN,(PROCES)
	LOAD T2,PROCNT,(T1)
	AOS T2
	STOR T2,PROCNT,(T1)
	MOVEM PROCES,1+ACS
	MOVE T2,[XWD -LPDL,PDL-1]
	MOVEM T2,P+ACS
	LOAD 1,FORK,(PROCES)
	MOVEI 2,ACS
	SFACS
	LOAD 2,FORKSA,(T1)
	LOAD T2,USRTSK,(T1)
	SKIPE T2
	MOVEI 2,DOUSRT
	SFORK
	SCALL LINK,<PROCES,[PRLST]>
	SKIPRT
	ENDR
KLPROC:	ROUTINE(KLPROC,PROC,,CPUTIM,<TASK,PROCES>)
	MOVE PROCES,PROC
	LOAD TASK,TASKP,(PROCES)
	LOAD 1,FORK,(PROCES)
	FFORK
	LOAD 2,NOKILL,(PROCES)
	JUMPN 2,[	RFORK
			JRST EXIT]
	RUNTM
	FSC 1,233
	FSC 2,233
	FDVR 1,2
	MOVEM 1,CPUTIM
	LOAD 1,FORK,(PROCES)
	KFORK
	LOAD T1,FAILRE,(PROCES)
	SCALL SGNOFF,<2(TASK),1,T1,CPUTIM>
	LOAD T1,PROCNT,(TASK)
	SOS T1
	STOR T1,PROCNT,(TASK)
	LOAD T1,BSYJFN,(PROCES)
	JUMPE T1,KLPR1
	SETZ T1,
	STOR T1,BSYBIT,(TASK)
	LOAD J1,TJFN,TASK
	SCALL CLRJFN,<J1>
	SETZ T1,
	STOR T1,TJFN,(TASK)
KLPR1:	SCALL UNLINK,PROCES
	SCALL RELEASE,VREG
	ENDR
PNDGP:	ROUTINE(PNDGP,,SKT,)
	SKIPN PRIVF		;PRIVATE?
	JRST PNDGP1		;NO
	MOVEI 3,400
	IORM 3,SKT
PNDGP1:	MOVEI T1,0		;SCAN NET TABLE INDEXES, START AT 0
LOOP5:	MOVEI 1,.GTNIX		;GET INFO BASED ON INDEX
	MOVE 2,T1		;THIS IS THE INDEX
	MOVEI 3,T2		;RETURN ANSWER HERE
	HRROI 4,.NCFSM		;ONE WORD, CONNECTION FSM
	GTNCP			;SEE WHAT STATE IT'S IN
	 JRST EXIT		;MUST HAVE TRIED THEM ALL
	CAIE T2,PNDG		;IS IT PENDING?
	 JRST ELOOP5		;NO.
	MOVEI 3,T2		;YES. GET THE LOCAL SOCKET NUMBER
	HRROI 4,.NCLSK		; ..
	GTNCP
	 JRST EXIT		;SHOULDN'T FAIL HERE
	CAME T2,SKT
	 JRST ELOOP5
	AOSA RETURN
ELOOP5:	AOJA T1,LOOP5		;TRY ANOTHER CONNECTION
	ENDR
MKICPF:	ROUTINE(MKICPF,,SOCKET,<<STRING,24>>)
	MOVEI 1,STRING
	HRLI 1,(<POINT 7,0>)
	HRROI 2,[ASCIZ /NET:/]
	SETZ 3,
	SOUT
	MOVE 2,SOCKET
	SKIPE PRIVF		;PRIVATE?
	 TRO 2,400
	MOVEI 3,10
	NOUT
	 JRST EXIT
	HRROI 2,[BYTE (7) <"V">&37,"#",".",0]
	SETZ 3,
	SOUT
	MOVSI 1,400001
	HRROI 2,STRING
	GTJFN
	 JRST MKIX1
	MOVEM 1,SOCKET
	MOVE 2,[XWD 400000,100000]
	OPENF
	 JRST [	MOVE 1,SOCKET
		RLJFN
		 JFCL
		JRST MKIX1]
	MOVSI 3,777700+^D19
	MOVEI 2,24
	MTOPR
	SKIPRT
	JRST EXIT

MKIX1:	ENDR
EXTASK:	ROUTINE(EXTASK,TSK,,<FHST,FSKT>,<TASK,PROCESS>)
	MOVE TASK,TSK
	LOAD T1,BSYBIT,(TASK)
	JUMPN T1,EXIT
	LOAD 1,TJFN,(TASK)
	JUMPN 1,CHECK
	LOAD T2,PRMBIT,(TASK)
	JUMPN T2,GJFN
	LOAD T1,LSKT,(TASK)
	SCALL PNDGP,T1
	 JRST EXIT		; NO PENDING RFC, EXIT
GJFN:	LOAD T1,LSKT,(TASK)
	SCALL MKICPF,<T1>
	 JRST EXIT
	STOR VREG,TJFN,(TASK)
CHECK:	PUSH P,1		;save JFN
	MOVE 2,1		;put in right AC
	MOVEI 1,.GTNJF		;we are handing you a JFN
	MOVEI 3,T1		;where to put results
	MOVE 4,[-4,,.NCFHS]	;-count,,first index to get
	GTNCP			;get foreign host in T1, foreign socket in T3
	 JRST [	POP P,1		;adjust stack
		JRST DIED]	;connection went away ??
	JUMPE T1,DIED
	MOVEM T1,FHST
	MOVEM T3,FSKT
	POP P,1			;restore JFN
	MOVE T1,T4
	CAIE T1,RFCR
	 JRST NOTRFC
	SCALL CRPROC,TASK
	 JRST EXIT
	MOVEM VREG,PROCES
	LOAD T1,FORK,(PROCES)
	SCALL SGNON,<2(TASK),FHST,FSKT,T1>
	JRST EXIT

NOTRFC:	LOAD T2,PRMBIT,(TASK)
	CAIN T1,LSNG
	 JUMPN T2,EXIT
DIED:	LOAD J1,TJFN,(TASK)
	SCALL CLRJFN,<J1>
	SETZ T1,
	STOR T1,TJFN,(TASK)
	ENDR

CLRJFN:	ROUTINE(CLRJFN,JFN)
	JUMPLE JFN,EXIT
	MOVEM JFN,T1
	CLOSF
	 MOVE JFN,T1
	RLJFN
	 JFCL
	ENDR

GETSKT:	ROUTINE(GETSKT)
	AOS VREG,SKTCNT
	ANDI VREG,177
	LSH VREG,1
	ENDR
INITTASKS:
	ROUTINE(INITTASKS,,THINGS,,RTHING)
	MOVE RTHING,THINGS
LOOP6:	MOVE T1,0(RTHING)
	SCALL CRTASK,<0(T1),1(T1),2(T1),3(T1),4(T1),[0],[0]>
	 JFCL
	AOBJN RTHING,LOOP6
	ENDR

IUSRT:	ROUTINE(IUSRT,,,<JFN,USRF,TTYF,LSNF,SKT,NAM,<STRING,^D10>>,<BLK>)
	HRROI 2,[ASCIZ /SYSTEM:NETSER.USER-TASKS/]
	MOVSI 1,100001
	GTJFN
	 JRST EXIT		; NO TASKS
	MOVEM 1,JFN
	MOVE 2,[XWD 70000,200000]
	OPENF
	 JRST [	MOVE 1,JFN
		RLJFN
		 JFCL
		JRST EXIT]
LP16:	SCALL GETBLK
	 JRST FULL
	MOVEM VREG,BLK
	SETZM 5(BLK)
	MOVEI 2,6(BLK)
	HRLI 2,(<POINT 7,0>)
	MOVE 1,JFN
	MOVEI 3,^D99
	MOVEI 4,","
	MOVEM 2,0(BLK)
	SIN
	JUMPE 3,ILLFMT
	SETZ T3,
	DPB T3,2
	MOVEM 2,1(BLK)
	SIN
	DPB T3,2
	JUMPE 3,ILLFMT
	MOVEM 2,2(BLK)
	MOVEI T2,NAM
	HRLI T2,440600
	MOVEI T1,6
	SETZM NAM
NMLP:	BIN
	JUMPE 2,ILLFMT
	CAIN 2,","
	 JRST ENMLP
	SOJL T1,ILLFMT
	SUBI 2,40
	CAIL 2,100
	SUBI 2,40
	IDPB 2,T2
	JRST NMLP

ENMLP:	MOVE 2,2(BLK)
	SIN
	DPB T3,2
	JUMPE 3,ILLFMT
	SETOM USRF
	SETZM TTYF
	SETZM LSNF
FLGLP:	BIN
	JUMPE 2,ILLFMT
	CAIN 2,","
	 JRST EFLGLP
	CAIN 2,"T"
	 SETOM TTYF
	CAIN 2,"L"
	 SETOM LSNF
	CAIN 2,"S"
	 SETZM USRF
	CAIN 2,"W"
	 JRST [	MOVEI T1,400000
		JRST SETMOD]
	CAIN 2,"O"
	 JRST [	MOVEI T1,200000
		JRST SETMOD]
	CAIE 2,"C"
	 JRST FLGLP
	MOVEI T1,100000
SETMOD:	IORM T1,5(BLK)
	JRST FLGLP

EFLGLP:	MOVEI 3,10
	NIN
	 JRST ILLFMT
	MOVEM 2,SKT
	MOVEI 3,^D10
	NIN
	 JRST ILLFMT
	MOVEM 2,3(BLK)
	NIN
	 JRST ILLFMT
	MOVEM 2,4(BLK)
	MOVE 1,1(BLK)
	MOVEI 3,^D10
	NIN
	 JRST SACT
	TLNE 2,-1
	 JRST SACT
	TLO 2,500000
	MOVEM 2,1(BLK)
SACT:	SKIPN USRF
	 JRST SYSTSK
	MOVEI 1,STRING
	HRLI 1,(<POINT 7,0>)
	HRROI 2,[ASCIZ /NET:/]
	SETZ 3,
	SOUT
	MOVE 2,0(BLK)
	MOVEI 3,^D41
	MOVEI 4,">"
	SOUT
	MOVE 2,SKT
	MOVEI 3,10
	NOUT
	 JFCL
	MOVEI 2,"."
	IDPB 2,1
	SETZ 2,
	IDPB 2,1
	HRROI 2,STRING
	MOVSI 1,1
	GTJFN
	 JRST ILLFMT
	CVSKT
	 JRST ILLFMT
	IORI 2,1
	MOVEM 2,SKT
	RLJFN
	 JFCL
SYSTSK:	SCALL CRTASK,<NAM,SKT,BLK,[^D10],LSNF,[1],TTYF>
	 JRST FULL
	MOVE 1,JFN
	BKJFN
	 JFCL
EOLLP:	BIN
	JUMPE 2,EOF6
	CAIN 2,12
	 JRST [	BIN
		JUMPE 2,EOF6
		BKJFN
		 JFCL
		JRST LP16]
	JRST EOLLP

ILLFMT:	HRROI VREG,[ASCIZ /ILLEGAL USER TASK FILE FORMAT/]
	JRST EOF1

FULL:	HRROI VREG,[ASCIZ /NO ROOM FOR ALL TASKS/]
	JRST EOF1

EOF6:	SETZ VREG,
EOF1:	EXCH VREG,JFN
	CLOSF
	 JFCL
	MOVE VREG,JFN
	ENDR
FNDSKT:	ROUTINE(FNDSKT,,<LCL,FHST,FSKT>,<<VALUS,.NCFSM-.NCFHS+1>>)
	MOVEI T1,0		;INDEX FOR SCANNING MONITOR TABLES
LOOP7:	MOVEI 1,.GTNIX		; JSYS ARG IS AN INDEX
	MOVEI 2,(T1)		; THIS IS THE INDEX
	MOVEI 3,VALUS		; ANSWER HERE, PLEASE
	MOVSI 4,-.NCFSM-.NCFHS+1 ; NUMBER OF VALUES WE WANT
	HRRI 4,.NCFHS		; STARTING HERE
	GTNCP			; GET THE INFO
	 JRST EXIT		; NO SUCH INDEX
	MOVEI 1,VALUS
	MOVE 1,.NCFSM-.NCFHS(1)
	CAIE 1,RFCR		; IS IT A RFCR STATE SOCKET?
	 JRST ELOOP7		; IGNORE ALL NOT RFCR
	MOVEI 1,VALUS
	MOVE 1,.NCLSK-.NCFHS(1)
	CAME 1,LCL		; RIGHT LOCAL SOCKET?
	 JRST ELOOP7
	MOVEI 1,VALUS
	MOVE 1,.NCFHS-.NCFHS(1)
	CAME 1,FHST		; RIGHT FOREIGN HOST?
	 JRST ELOOP7
	MOVEI 1,VALUS
	MOVE 1,.NCFSK-.NCFHS(1)
	CAME 1,FSKT		; RIGHT FOREIGN SOCKET?
	 JRST ELOOP7
	HRRZ VREG,T1		;ALL MATCHES. RETURN THE INDEX.
	SKIPRT			; SUCCESS
	JRST EXIT

ELOOP7:	AOJA T1,LOOP7		; TRY ANOTHER INDEX
	ENDR
DOICP:	ROUTINE(DOICP,,<IJFN,LCLSKT,TSK,PROC>,<SJFN,RJFN,SYSSKT,FSKT,FHST,<STRING,24>,STSN,BALN>,<FAILF,PROCES>)
	MOVE PROCES,PROC
	SETZB FAILF,SJFN
	SETZM RJFN
	MOVE 1,IJFN
	CVSKT
	 JRST FAIL8
	IORI 2,1
	MOVEM 2,SYSSKT
	MOVE 2,1		;put JFN in right AC
	MOVEI 1,.GTNJF		;we're handing you a JFN
	MOVEI 3,T1		;where to put data
	MOVE 4,[-3,,.NCFHS]	;how many,,where to start
	GTNCP			;get foreign host, foreign socket
	 JRST FAIL8		;boo... hiss...
	MOVEM T1,FHST
	MOVEM T3,FSKT
	SCALL FNDSKT,<SYSSKT,FHST,FSKT>
	 JRST FAIL8		; ABANDONED
	MOVEM VREG,SYSSKT
	MOVEI 1,STRING
	HRLI 1,(<POINT 7,0>)
	HRROI 2,[ASCIZ /NET:/]
	SETZ 3,
	SOUT
	MOVE 2,LCLSKT
	MOVEI 3,8
	NOUT
	 JRST FAIL8
	MOVEI 2,"."
	IDPB 2,1
	MOVE 2,FHST
	NOUT
	 JRST FAIL8
	MOVEI T1,"-"
	IDPB T1,1
	MOVE 2,FSKT
	ADDI 2,2
	NOUT
	 JRST FAIL8
	HRROI 2,[ASCIZ /;T/]
	SETZ 3,
	SOUT
	MOVSI 1,1
	HRROI 2,STRING
	GTJFN
	 JRST FAIL8
	MOVEM 1,SJFN
	MOVSI 1,1
	HRROI 2,STRING
	GTJFN
	 JRST FAIL8
	MOVEM 1,RJFN
	CVSKT			; GET LOCAL SOCKET FOR CONNECTIONS
	 JRST FAIL8
	MOVEM 2,LCLSKT
	MOVE 1,IJFN
	MOVEI 2,20
	MTOPR			; ACCEPT CONNECTION
	MOVEI FAILF,[ASCIZ /BIT ALLOC NOT REC'VD/]
	STOR FAILF,FAILRE,(PROCES)
WATLP:	MOVEI 1,.GTNJF		;ARG IS A JFN
	MOVE 2,IJFN		;THIS ONE
	MOVEI 3,T2		;ANSWER HERE, PLEASE
	HRROI 4,.NCBAL		;BIT ALLOCATION, PLEASE
	GTNCP
	 JRST FAIL8
	CAIGE T2,^D32
	 JRST [	MOVEI 1,^D500
		DISMS
		JRST WATLP]
	MOVEI FAILF,[ASCIZ /MESSAGE ALLOC NOT REC'VD/]
	STOR FAILF,FAILRE,(PROCES)
WATLP2:	MOVEI 1,.GTNJF
	MOVE 2,IJFN
	MOVEI 3,T2
	HRROI 4,.NCMSG		; GET THE MESSAGE ALLOCATION
	GTNCP
	 JRST FAIL8
	SKIPA
;	CAIGE T2,1
	 JRST [	MOVEI 1,^D500
		DISMS
		JRST WATLP2]
	MOVEI FAILF,[ASCIZ /TIMED-OUT/]
	STOR FAILF,FAILRE,(PROCES)
	MOVE 1,IJFN
	MOVE 2,LCLSKT
	BOUT
	CLOSF
	 JFCL
	MOVEI T1,1
	STOR T1,NOKILL,(PROCES)
	SETZB T1,IJFN
	SETZRO BSYJFN,(PROCES)
	MOVE T2,TSK
	STOR T1,TJFN,(T2)
	STOR T1,BSYBIT,(T2)
	STOR T1,NOKILL,(PROCES)
	MOVE 1,SJFN
	MOVE 2,[XWD 103000,100000]
	MOVEI FAILF,[ASCIZ /CAN'T OPEN SEND/]
	STOR FAILF,FAILRE,(PROCES)
	OPENF
	 JRST FAIL18
	MOVE 1,RJFN
	MOVE 2,[XWD 100000,200000]
	MOVEI FAILF,[ASCIZ /CAN'T OPEN RECV/]
	STOR FAILF,FAILRE,(PROCES)
	OPENF
	 JRST FAIL18
	MOVE VREG+1,SJFN
	SKIPRT
	JRST EXIT

FAIL8:	SCALL CLRJFN,<IJFN>
	MOVE T2,TSK
	SETZ T1,
	STOR T1,BSYJFN,(PROCES)
	STOR T1,TJFN,(T2)
	STOR T1,BSYBIT,(T2)
FAIL18:	SCALL CLRJFN,<SJFN>
	SCALL CLRJFN,<RJFN>
	SKIPN VREG,FAILF
	MOVEI VREG,[ASCIZ /ICP FAILED/]
	ENDR

DOLGC:	ROUTINE(DOLGC,,<KPROCS,NEWNVF>,<SJFN,RJFN,PTY>,<PROCES,TASK>)
	MOVE PROCES,KPROCS
	LOAD TASK,TASKP,(PROCES)
	SCALL GETSKT
	LOAD T1,TJFN,(TASK)
	SCALL DOICP,<T1,VREG,TASK,PROCES>
	 JRST [	STOR 1,FAILRE,(PROCES)
		JRST ENDD9]
	MOVEM 1,RJFN
	MOVEM 2,SJFN
	MOVEI T1,[ASCIZ /TIMED-OUT AFTER ICP/]
	STOR T1,FAILRE,(PROCES)
	SKIPE NEWNVF		; NEW STYLE NVT?
	 HRLI 1,(1B2)		; YES, SET BIT2
	ATNVT
	 JRST SORRY
	MOVEM 1,PTY
	MOVSI 1,100001
	HRROI 2,[ASCIZ /SYSTEM:NETWORK-LOGINMESSAGE/]
	GTJFN
	 JRST NOMSG
	MOVEM 1,SJFN
	MOVE 2,[XWD 70000,200000]
	OPENF
	 JRST [	MOVE 1,SJFN
		RLJFN
		 JFCL
		JRST NOMSG]
MSGLP:	MOVE 1,SJFN
	BIN
	JUMPE 2,EMSGLP
	MOVE 1,PTY
	BOUT
	JRST MSGLP

EMSGLP:	CLOSF
	 JFCL
NOMSG:	MOVE 1,PTY
	MOVEI 2,3
	STI
	SETZRO FAILRE,(PROCES)
	JRST ENDD9

SORRY:	MOVE 1,SJFN
	HRROI 2,[ASCIZ /
SORRY, ALL NETWORK TERMINALS ARE IN USE.  PLEASE TRY AGAIN LATER.
/]
	SETZ 3,
	SOUT
	CLOSF
	 JFCL
	MOVE 1,RJFN
	CLOSF
	 JFCL
	MOVEI T1,[ASCIZ /ATNVT FAILURE/]
	STOR T1,FAILRE,(PROCES)
ENDD9:	SETZRO KILTIM,(PROCES)
	HALTF
	ENDR

DOLOG:	ROUTINE(DOLOG,,,,)
	SCALL DOLGC,<1,[0]>
	ENDR

DONLG:	ROUTINE(DONLG)
	SCALL DOLGC,<1,[-1]>
	ENDR
DODATE:	ROUTINE(DODATE,,,<SJFN,RJFN>,PROCES)
	MOVEM 1,PROCES
	SCALL GETSKT
	LOAD T1,TASKP,(PROCES)
	LOAD T2,TJFN,(T1)
	SCALL DOICP,<T2,VREG,T1,PROCES>
	 JRST FAIL10
	MOVEI T1,[ASCIZ /TIMED-OUT AFTER ICP/]
	STOR T1,FAILRE,(PROCES)
	MOVEM VREG,RJFN
	MOVEM VREG+1,SJFN
	MOVE 1,VREG+1
	SETO 2,
	MOVSI 3,322060
	ODTIM
	MOVEI 2,15
	BOUT
	MOVEI 2,12
	BOUT
	SCALL CLRJFN,<RJFN>
	SCALL CLRJFN,<SJFN>
	SETZ VREG,
FAIL10:	STOR VREG,FAILRE,(PROCES)
	SETZRO KILTIM,(PROCES)
	HALTF
	ENDR
DOECHO:	ROUTINE(DOECHO,,,<SJFN,RJFN>,<PROCES,TASK>)
	MOVEM 1,PROCES
	SCALL GETSKT
	LOAD TASK,TASKP,(PROCES)
	LOAD T2,TJFN,(TASK)
	SCALL DOICP,<T2,VREG,TASK,PROCES>
	 JRST FAIL11
	MOVEM VREG,RJFN
	MOVEM VREG+1,SJFN
	HRLOI T1,377777
	STOR T1,KILTIM,(PROCES)
LOOP11:	MOVE 1,RJFN
	BIN
	JUMPE 2,[GTSTS
		TLNE 2,1000
		 JRST EOF11
		SETZ 2,
		JRST .+1]
	MOVE 1,SJFN
	BOUT
	JRST LOOP11

EOF11:	SCALL CLRJFN,<RJFN>
	SCALL CLRJFN,<SJFN>
	SETZRO FAILRE,(PROCES)
	JRST ENDD11

FAIL11:	STOR VREG,FAILRE,(PROCES)
ENDD11:	SETZRO KILTIM,(PROCES)
	HALTF
	ENDR
CMPSTR:	ROUTINE(CMPSTR,,<ST1,ST2>)
LOOP13:	ILDB T1,ST1
	ILDB T2,ST2
	CAME T2,T1
	 JRST EXIT
	JUMPN T1,LOOP13
	SKIPRT
	ENDR

STRIN:	ROUTINE(STRIN,JFN,<PTR,MAX>)
	MOVE 2,PTR
	MOVE 3,MAX
	MOVEI 4,":"
	SIN
	SETZ T1,
	DPB T1,2
	ENDR
DOSUBSYS:	ROUTINE(DOSUBSYS,,<FILE,NAME,DRTEXT>,<IFILE,SJFN,RJFN,SUBFRK,DRFILE>,<PROCES,TASK,FAILF>)
	MOVEM 1,PROCES
	LOAD TASK,TASKP,(PROCES)
	SCALL GETSKT
	LOAD T1,TJFN,(TASK)
	SCALL DOICP,<T1,VREG,TASK,PROCES>
	 JRST FAIL15
	MOVEM VREG,RJFN
	MOVEM VREG+1,SJFN
	MOVEI T1,[ASCIZ /TIMED-OUT AFTER ICP/]
	STOR T1,FAILRE,(PROCES)
	TIME
	ADDI 1,^D60000
	STOR 1,KILTIM,(PROCES)
	SETOM DRFILE
	SKIPN DRTEXT
	 JRST RUNSUB
	LOAD 1,FORK,(PROCES)
	ANDI 1,177777
	MOVEI FAILF,[ASCIZ /NO DRIVER FILE/]
	HRLI 1,400001
	HRROI 2,[ASCIZ /SYSTEM:NETSER-DRIVERFILE/]
	GTJFN
	 JRST CANT
	MOVEM 1,DRFILE
	MOVE 2,[XWD 70000,100000]
	OPENF
	 JRST [	MOVE 1,DRFILE
		RLJFN
		 JFCL
		 JRST CANT]
	MOVE T1,DRTEXT
	HRLI T1,(<POINT 7,0>)
L1:	ILDB 2,T1
	JUMPE 2,L1E
	CAIN 2,"?"
	 JRST [	ILDB 2,T1
		CAIN 2,"?"
		 JRST .+1
		ANDI 2,37
		JRST .+1]
	BOUT
	JRST L1

L1E:	HRLI 1,400000
	CLOSF
	 HALT
	HRRZS 1
	MOVE 2,[XWD 70000,200000]
	OPENF
	 HALT
RUNSUB:	MOVEI FAILF,[ASCIZ /NO INTERMEDIATE FILE/]
	LOAD 1,FORK,(PROCES)
	ANDI 1,177777
	HRLI 1,400001
	HRROI 2,[ASCIZ /SYSTEM:NETSER-INTERMEDIATE/]
	GTJFN
	 JRST CANT1
	MOVEM 1,IFILE
	MOVE 2,[XWD 70000,100000]
	OPENF
	 JRST [	MOVE 1,IFILE
		RLJFN
		 JFCL
		JRST CANT1]
	MOVSI 1,(1B1)
	MOVEI FAILF,[ASCIZ /NO FORKS/]
	CFORK
	 JRST CANT2
	MOVEM 1,SUBFRK
	MOVEI FAILF,[ASCIZ /SUBSYS NOT FOUND/]
	MOVSI 1,100001
	HRRO 2,FILE
	GTJFN
	 JRST CANT2
	HRL 1,SUBFRK
	GET
	MOVE 1,SUBFRK
	MOVE 2,IFILE
	HRL 2,DRFILE
	SKIPGE 2
	HRLI 2,377777
	SPJFN
	SETZ 2,
	SFRKV
	WFORK
	KFORK
	SKIPG 1,DRFILE
	 JRST NODRF
	DELF
	 JFCL
	CLOSF
	 JFCL
NODRF:	MOVE 1,IFILE
	HRLI 1,400000
	CLOSF
	 HALT
	HRRZS 1
	MOVE 2,[XWD 70000,200000]
	OPENF
	 HALT
CPYL15:	MOVE 1,IFILE
	BIN
	JUMPE 2,[GTSTS
		TLNE 2,1000
		 JRST EOF15
		SETZ 2,
		JRST CPYL15]
	MOVE 1,SJFN
	BOUT
	JRST CPYL15

EOF15:	MOVE 1,IFILE
	DELF
	 JFCL
	CLOSF
	 JFCL
	SETZRO FAILRE,(PROCES)
	JRST ENDD15

CANT2:	MOVE 1,IFILE
	CLOSF
	 JFCL
CANT1:	SKIPL 1,DRFILE
	CLOSF
	 JFCL
CANT:	MOVE 1,SJFN
	HRROI 2,[ASCIZ /
SORRY, /]
	SETZ 3,
	SOUT
	HRRO 2,NAME
	SOUT
	HRROI 2,[ASCIZ / IS NOT AVAILABLE BECAUSE /]
	SOUT
	HRRO 2,FAILF
	SOUT
	STOR FAILF,FAILRE,(PROCES)
ENDD15:	MOVE 1,RJFN
	CLOSF
	 JFCL
	MOVE 1,SJFN
	CLOSF
	 JFCL
	JRST END215

FAIL15:	STOR VREG,FAILRE,(PROCES)
END215:	SETZRO KILTIM,(PROCES)
	HALTF
	ENDR
DOSYSTAT:
	ROUTINE(DOSYSTAT)
	SCALL DOSUBSYS,<[[ASCIZ /SYSTEM:EXEC.EXE/]],[[ASCIZ /SYSTAT/]],[[ASCIZ /SYSTAT?JPOP?J/]]>
	ENDR

XEFACT:	ROUTINE(XEFACT,,<CONNECT,CPU,ACCOUNT>,<<FACTBLK,40>>)
	ENDR

DOUSRT:	ROUTINE(DOUSRT,,,<SJFN,RJFN,FORKH,CUTOFF,TTYF,<FACS,20>,<FACT,20>,<CHNTAB,^D36>,<LEVTAB,3>,INTPC,ST1>,<BLK,PROCES>)
	MOVEM 1,PROCES
	MOVSI T1,1+CHNTAB
	HRRI T1,CHNTAB
	SETZM CHNTAB
	BLT T1,^D35+CHNTAB
	MOVEI T1,INTPC
	MOVEM T1,LEVTAB
	MOVSI T1,1
	HRRI T1,FKTRM
	MOVEM T1,^D19+CHNTAB
	MOVEI 1,400000
	MOVSI 2,LEVTAB
	HRRI 2,CHNTAB
	SIR
	EIR
	MOVEI 2,1B19
	AIC
	SCALL GETSKT
	LOAD T1,TASKP,(PROCES)
	LOAD T2,TJFN,(T1)
	SCALL DOICP,<T2,VREG,T1,PROCES>
	 JRST FAIL16
	MOVEI T1,[ASCIZ /COULD NOT GET FILE/]
	STOR T1,FAILRE,(PROCES)
	MOVEM VREG,RJFN
	MOVEM VREG+1,SJFN
	MOVE 2,1		;put JFN in right AC
	MOVEI 1,.GTNJF		;we're handing you a JFN
	MOVEI 3,T1		;where to put data
	MOVE 4,[3,,.NCFHS]	;-count,,where to start
	GTNCP			;get the data
	 JRST FAIL16
	MOVEM T1,1+FACS		;foreign host
	MOVEM T3,2+FACS		;foreign socket
	LOAD T1,TASKP,(PROCES)
	LOAD BLK,FORKSA,(T1)
	LOAD T2,TTYBIT,(T1)
	MOVEM T2,TTYF
	MOVE 2,0(BLK)
	MOVSI 1,100001
	GTJFN
	 JRST NAV
	MOVEM 1,FORKH
	SETZ 1,
	CFORK
	 JRST [	MOVE 1,FORKH
		RLJFN
		 JFCL
		JRST NAV1]
	EXCH 1,FORKH
	HRL 1,FORKH
	GET
	HRLOI T1,377777
	STOR T1,KILTIM,(PROCES)
	MOVE 1,FORKH
	MOVSI 3,200000
	HRR 3,5(BLK)
	MOVE 2,3
	EPCAP
	SKIPN TTYF		; NEEDS TO RUN WITH A TTY?
	 JRST NOTTY
	MOVE 1,RJFN
	MOVE 2,SJFN
	ATNVT
	 JRST NAV0
	MOVEM 1,TTYF
	ASND
	 JFCL
	MOVE 1,TTYF
	MOVE 2,[XWD 52531,515125]
	MOVE 3,[XWD 252525,653000]
	SFCOC
	MOVE 2,[XWD 401002,4010]
	MOVE 4,2
	MOVE 3,[XWD 20040,100200]
	STABS
	MOVE 2,[XWD 60510,175120]
	SFMOD
	MOVE 2,TTYF
	HRL 2,2
	JRST SETPJF

NOTTY:	HRLZ 2,RJFN
	HRR 2,SJFN
SETPJF:	MOVE 1,FORKH
	SPJFN
	SKIPN 1,TTYF
	MOVE 1,SJFN
	SETO 2,			;LOCAL HOST
	MOVEI 3,10
	CVHST
	 JRST [	MOVE 1,SJFN
		NOUT		; OR TO NUMBER
		 MOVE 1,SJFN	; RESTORE DESTINATION
		JRST .+1]
	MOVEI 2,40		;SEPARATE WITH SPACE
	BOUT
	MOVE 2,2(BLK)
	MOVEI 3,0
	SOUT
	HRROI 2,[BYTE (7)15,12,0]
	SOUT
	TIME
	ADD 1,4(BLK)
	MOVEM 1,CUTOFF
	MOVE 1,FORKH
	MOVEI 2,FACS
	SFACS
	MOVEI 2,0
	SFRKV
WLP:	MOVEI 1,^D10000
	DISMS
EWLP:	MOVE 1,FORKH
	RFSTS
	HLRZ T1,1
	CAIN T1,2
	 JRST [	SETZ VREG,
		JRST DONE]
	CAIN T1,3
	 JRST [	MOVEI VREG,[ASCIZ /TASK CRASHED./]
		JRST DONE]
	MOVE 1,FORKH
	RUNTM
	CAML 1,2(BLK)
	 JRST [	MOVEI VREG,[ASCIZ /CPU ALLOTMENT EXCEEDED/]
		JRST DONE]
	TIME
	CAML 1,CUTOFF
	 JRST [	MOVEI VREG,[ASCIZ /CONNECT TIME EXCEEDED/]
		JRST DONE]
	JRST WLP

FKTRM:	MOVEM T1,ST1
	HRRZ T1,INTPC
	CAIG T1,EWLP
	CAIGE T1,WLP
	 JRST FKTRMX
	MOVE 1,[XWD 10000,EWLP]
	MOVEM T1,INTPC
FKTRMX:	MOVE T1,ST1
	DEBRK

NAV0:	MOVE 1,FORKH
	KFORK
	HRROI 2,[ASCIZ /NETWORK TERMINAL/]
	JRST NAVC

NAV1:	HRROI 2,[ASCIZ /FORKS/]
	JRST NAVC

NAV:	MOVE 2,0(BLK)
NAVC:	MOVE 1,SJFN
	SETZ 3,
	SOUT
	HRROI 2,[ASCIZ / NOT AVAILABLE.
/]
	SOUT
	MOVEI VREG,[ASCIZ /TASK NOT AVAILABLE/]
	JRST FINISH

DONE:	STOR VREG,FAILRE,(PROCES)
	TIME
	SUB VREG,CUTOFF
	ADD VREG,4(BLK)
	MOVEM VREG,J4
	MOVE J1,FORKH
	RUNTM
	SCALL XEFACT,<J4,J1,1(BLK)>
	MOVE 1,FORKH
	KFORK
	JRST FINI1
FINISH:	STOR VREG,FAILRE,(PROCES)
FINI1:	SKIPE 1,TTYF
	 JRST [	DOBE
		RELD
		 JFCL
		JRST FAI116]
	SCALL CLRJFN,<RJFN>
	SCALL CLRJFN,<SJFN>
	JRST FAI116

FAIL16:	STOR VREG,FAILRE,(PROCES)
FAI116:	SETZRO KILTIM,(PROCES)
	HALTF
	ENDR
; MAIN PROGRAM

START:	TDZA 1,1
REENT:	MOVNI 1,1
	MOVEM 1,DTACHF
	MOVE P,[XWD -LPDL,PDL-1]
	MOVE FREG,P
MLOOP:	RESET
	MOVEI 1,400000
	RPCAP
	IORI 3,600000
	EPCAP
	MOVE 1,LOGDES
	MOVEM 1,TTYJFN
	MOVEI 1,400000
	MOVE 2,[XWD 400000,400000]
	SKIPE DTACHF
	 SPJFN
	SETZ J1,
	SKIPE PRIVF		;PRIVATE?
	MOVEI J1,20		;YES
	MOVEM J1,SKTCNT
	GTAD
	JUMPL 1,[MOVEI 1,^D10000
		DISMS
		JRST .-1]
	MOVE 1,[SIXBIT /NETRDY/]
	SYSGT
	JUMPGE 1,[MOVEI 1,^D10000
		DISMS
		JRST .-2]
	SCALL LOGMESSAGE,<<[POINT 7,[ASCIZ \NETSER IN OPERATION\]]>>
	MOVE T1,[XWD TASKS,TASKS]
	MOVEM T1,TASKS
	MOVE T1,[XWD PRLST,PRLST]
	MOVEM T1,PRLST
	MOVE T1,[XWD FRELST,FRELST]
	MOVEM T1,FRELST
	MOVEI P1,FRESTO
IFRELP:	SCALL RELEASE,P1
	ADDI P1,ITMSIZ
	CAIGE P1,FRESTO+NFREE*ITMSIZ
	 JRST IFRELP
	MOVEI T1,BLKSTO
	MOVEM T1,FREBLK
	SCALL INITTASKS,<<[XWD -NTASKS,TSKTAB]>>
	SCALL IUSRT		; INIT USER TASKS
	SCALL SETINT

MLP1:	MOVE 1,[SIXBIT /NETRDY/]
	SYSGT
	JUMPGE 1,IMPDED
	SCALL SCNTSK
	SCALL SCNPRC
	SCALL WATINT
	JRST MLP1

IMPDED:	SCALL LOGMESSAGE,<<[POINT 7,[ASCIZ /IMP DOWN -- NETSER RESTART/]]>>
	MOVEI 1,^D30000
	DISMS
	JRST MLOOP
;TASK INITIALIZATION TABLE
;BLOCK:
;	SIXBIT NAME
;	SOCKET
;	START ADDRESS
;	TIME
;	PRMBIT

TSKTAB:	Z [SIXBIT /LOGGER/
		1
		DOLOG
		^D10
		1]
	Z [SIXBIT /NLOGER/
		^D23
		DONLG
		^D10
		1]
	Z [SIXBIT /DATE/
		15
		DODATE
		^D10
		1]
	Z [SIXBIT /ECHO/
		7
		DOECHO
		^D10
		0]
	Z [SIXBIT /SYSTAT/
		13
		DOSYST
		^D10
		0]
NTASKS==.-TSKTAB

LOGDES:	377777

;LITERALS XLISTED
	XLIST
	LIT
	LIST

	VAR
TOPPAG:	./1000
	END START