perm filename SYSSER.MID[S,NET]2 blob sn#697651 filedate 1983-01-28 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00004 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	X FCS FULTWX ECHOFF TERMID CORBEG TERSTR PDL COREND
C00004 00003	SYSSER CPYHST 1DIGTP NOTTIP
C00006 00004	GETTXT SUICID ...LIT SVRRTS ERRTNS ERRHAN ERRINS HSTTAB HSTSIX
C00008 ENDMK
C⊗;
;X FCS FULTWX ECHOFF TERMID CORBEG TERSTR PDL COREND

TITLE SYSSER
SUBTTL Definitions

; Mark Crispin, SU-AI, September 1978

; Assembly switches

IFNDEF SVRSKT,SVRSKT==13		; default listen socket
IFNDEF PDLLEN,PDLLEN==50		; stack length

; AC definitions.  0→3 are used by NETWRK

X=4 ? A=5 ? B=6 ? P=17

; SAIL system bit definitions

FCS==   000020,,			; full character set mode
FULTWX==000004,,			; no echo

ECHOFF:	001400,,(FULTWX)		; echo off TTYSET command word
TERMID:	'TERMID				; for spies to see where we are
CORBEG==.				; start of initialized core storage
TERSTR:	BLOCK 10.			; console location string
PDL:	BLOCK PDLLEN			; stack
COREND==.-1				; end of initialized storage
;SYSSER CPYHST 1DIGTP NOTTIP

SUBTTL Initialize the world

SYSSER:	JFCL
	RESET
	MOVE ['SYSSER]
	SETNAM
	SETZM CORBEG
	MOVE [CORBEG,,CORBEG+1]
	BLT COREND
	MOVE P,[PDL(-PDLLEN)]
	MOVEI [DEBREAK ? JRST SUICID]
	MOVEM JOBAPR
	CLKINT 2.*60.*60.		; must die if around too long
	OUTSTR [ASCIZ/SYSSER started
/]

; Listen for a connection on our socket

	MOVEI SVRSKT
	MOVEM LSNSKT
	PUSHJ P,LISTEN

; Set up terminal id for interested spies

	MOVEI TERMID
	MOVEM JOBVER

; Log the connection

	OUTSTR [ASCIZ/Connected to /]
	PUSHJ P,MAPHST			; map in host table
	MOVE HOST
	PUSHJ P,HSTNUM			; get HDB
	 JFCL				; sorry about errors
	MOVEI A,(1)			; host name
	HRLI A,440700
	SKIPA X,[440700,,TERSTR]
CPYHST:	 IDPB B,X
	ILDB B,A
	JUMPN B,CPYHST
	HLRZ A,1			; pointer to system name
	MOVE B,(A)			; get system name
	MOVE A,FSOCKT			; and ICP socket
	CAMN B,[ASCII/TIP/]		; on a TIP?
	 TRNE A,177774			; just paranoia; make sure a TIP port
	  JRST NOTTIP
	MOVEI B,"#
	IDPB B,X
	LSH A,-16.
	IDIVI A,8.			; ports are octal
	JUMPE A,1DIGTP
	ADDI A,"0 ? IDPB A,X
1DIGTP:	ADDI B,"0 ? IDPB B,X
NOTTIP:	PUSHJ P,SETANM			; set our job name
	PUSHJ P,UNMHST			; map out the host table
	OUTSTR TERSTR
	OUTSTR [ASCIZ/
/]
;GETTXT SUICID ...LIT SVRRTS ERRTNS ERRHAN ERRINS HSTTAB HSTSIX

SUBTTL WHO over a PTY

; Get a PTY, set it up, and log it in

	PTYGET A
	 JRST SUICID
	MOVSI (A)
	IORM ECHOFF
	MOVSI B,(FCS)
	PTSETL A			; set initial bits
	HRROI ECHOFF
	TTYSET				; echo off
	MOVEI B,5			; LOGIN
	PTJOBX A
	 JRST SUICID

; Send command down PTY's throat

	MOVEI B,[ASCIZ/WHO
/]
	PTWRS7 A			; send prelude
	PTRD1W A			; eat line feed from the PTY

; Get WHO output from PTY

GETTXT:	PTRD1W A
	CAIN B,"↑			; start of ↑C saying dat's it?
	 JRST [	PTRD1W A
		CAIE B,"C		; is it really ↑C?
		 JRST [	MOVEI "↑	; oops!
			PUSHJ P,NETOCH
			JRST .+1]
		PUSHJ P,NETSND		; yes it was, force buffer out
		PUSHJ P,CLOSER
		JRST SUICID]
	MOVEI (B)
	PUSHJ P,NETOCH			; send character to user
	JRST GETTXT

SUICID:	RESET ? EXIT

...LIT:	CONSTANTS

; Wonderful network routines

SVRRTS==-1				; include server routines
ERRTNS==-1				; include error routines
ERRHAN==-1				; include automagic error handling
ERRINS==<JRST SUICID>			; error instruction
HSTTAB==-1				; include host table magic
HSTSIX==-1				; and alias name kludge

.INSRT NETWRK

END SYSSER