Google
 

Trailing-Edge - PDP-10 Archives - BB-W661B-BM_1984 - tools/pad.mac
There is 1 other file named pad.mac in the archive. Click here to see a list.
	TITLE	PAD	PROTOTYPE PACKET ASSEMBLY/DISASSEMBLY FACILITY
;
;
;                      COPYRIGHT (C) 1982, 1983
;                    DIGITAL EQUIPMENT CORPORATION
;
;     THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY  BE  USED
;     AND COPIED ONLY IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE
;     AND WITH THE INCLUSION OF THE ABOVE COPYRIGHT NOTICE.   THIS
;     SOFTWARE  OR ANY OTHER COPIES THEREOF MAY NOT BE PROVIDED OR
;     OTHERWISE MADE AVAILABLE TO ANY OTHER PERSON.  NO  TITLE  TO
;     AND OWNERSHIP OF THE SOFTWARE IS HEREBY TRANSFERRED.
;
;     THE INFORMATION  IN  THIS  SOFTWARE  IS  SUBJECT  TO  CHANGE
;     WITHOUT  NOTICE  AND SHOULD NOT BE CONSTRUED AS A COMMITMENT
;     BY DIGITAL EQUIPMENT CORPORATION.
;
;     DIGITAL ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY
;     OF  ITS  SOFTWARE  ON  EQUIPMENT  WHICH  IS  NOT SUPPLIED BY
;     DIGITAL.
;
	PAGE
	REPEAT	0,<

	TABLE OF CONTENS
	=================

DEFINITIONS.................................................PAGE 1-X
MACROS......................................................PAGE 1-X
SYMBOLS.....................................................PAGE 1-X
MAIN INITIALIZATION AND TERMINATION CODE....................PAGE 1-X
CMDTAB	COMMAND TABLE.......................................PAGE 1-X
THE SIMPLE COMMANDS - EXIT, HELP............................PAGE 1-X
CONNECT	COMMAND PROCESSING..................................PAGE 1-X
CONTINUE COMMAND PROCESSING.................................PAGE 1-X
DEFINE	COMMAND PROCESSING..................................PAGE 1-X
DISABLE COMMAND PROCESSING..................................PAGE 1-X
DISCONNECT COMMAND PROCESSING...............................PAGE 1-X
ENABLE COMMAND PROCESSING...................................PAGE 1-X
FULL DUPLEX COMMAND PROCESSING..............................PAGE 1-X
HALF DUPLEX COMMAND PROCESSING..............................PAGE 1-X
ID	COMMAND PROCESSING..................................PAGE 1-X
INSERT	COMMAND PROCESSING..................................PAGE 1-X
MAIL	COMMAND PROCESSING..................................PAGE 1-X
SET	COMMAND PROCESSING..................................PAGE 1-X
STATUS COMMAND PROCESSING...................................PAGE 1-X
TERMINAL COMMAND PROCESSING.................................PAGE 1-X
TEST	COMMAND.............................................PAGE 1-X
NETWORK	COMMAND PROCESSING..................................PAGE 1-X
PADDING	COMMAND PROCESSING..................................PAGE 1-X
PAGE	COMMAND PROCESSING..................................PAGE 1-X
PUSH COMMAND................................................PAGE 1-X
X25NET	NETWORK ACCESS SUBROUTINES..........................PAGE 1-X
X25ERR NETWORK ERROR ROUTINES...............................PAGE 1-X
X25STT	NETWORK STATE TRANSITION TABLE......................PAGE 1-X
X25STR	NETWORK STATE TRANSITION ROUTINES...................PAGE 1-X
X25INT	GENERAL NETWORK INTERRUPT ENTRY.....................PAGE 1-X
X25INT	NETWORK INTERRUPT PROCESSING ROUTINES...............PAGE 1-X
X25INT	QUALIFIED (CONTROL) DATA PROCESSING ROUTINE.........PAGE 1-X
TTYXXX	GENERAL TERMINAL ROUTINES OPEN,CLOSE,ECT............PAGE 1-X
TTYFRK	TTY FORK INITIALIZATION,CONTROL AND TERMINA.........PAGE 1-X
TTYFRK	TERMINAL INPUT FORK.................................PAGE 1-X
TTYFRK	IDLE TIMER SUPPORT..................................PAGE 1-X
TTYFRK	TERMINAL FORK ECHO PROCESSING ROUTINES..............PAGE 1-X
XXXXXX	GENERAL SUBROUTINES.................................PAGE 1-X
INTXXX	INTERRUPT INITIALIZATION AND CONTROL ROUTIN.........PAGE 1-X
INTXXX	INTERRUPT SAVEAC,DEBREAK AND WAIT CODE..............PAGE 1-X
TIMER	SERVICE ............................................PAGE 1-X
TIMER	TIMER INTERRUPT CODE................................PAGE 1-X
INTXX2	INTERRUPT SAVEAC,DEBREAK CODE.......................PAGE 1-X
INTDAT	INTERRUPT LEVTAB,,CHNTAB AND DATA...................PAGE 1-X
DATA BASE...................................................PAGE 1-X
>
	PAGE
	SUBTTL	DEFINITIONS
	SEARCH	MONSYM,MACSYM

	SALL				;SUPPRESS MACRO EXPANSIONS

;VERSION INFORMATION
	PADVER==1			;MAJOR VERSION NUMBER
	PADMIN==0			;MINOR VERSION NUMBER
	PADEDT==0			;EDIT LEVEL
	PADWHO==0			;WHO LAST PATCHED

	%PAD==<BYTE (3)PADWHO(9)PADVER(6)PADMIN(18)PADEDT>

;STORE VERSION NUMBER IN JOBVER
	LOC	137
.JBVER::EXP	%PAD
	RELOC	0


;	AC's

	F=0
	S1=1				;SCRATCH AC'S
	S2=2
	T1=3				;TEMP-AC'S
	T2=4
	T3=5
	T4=6
	Q1=7				;
	Q2=10
	Q3=11
	P1=12				;PERMANET AC'S
	P2=13
	P3=14
	P4=15
	CX=16				;SPECIAL AC
	P=17				;PDL-P

	PAGE
	SUBTTL	MACROS

	OPDEF	CONFRM	[PUSHJ P,CMDCNF]	;COMND CONFIRN FUNCTION
	OPDEF	PARSE	[PUSHJ P,CMDCMD]	;MAKE THE COMND CALL

	OPDEF	XPSOUT	[PUSHJ P,.PSOUT]	;TERMINAL I/O ROUTINES
	OPDEF	XBOUT	[PUSHJ P,.BOUT]		;
	OPDEF	XSOUT	[PUSHJ P,.SOUT]		;

	DEFINE	NOISE ($TEXT),<		;;MACRO TO DO COMND GUIDEWORD CALL
	XLIST
	MOVEI	S2,[ASCIZ/$TEXT/]
	PUSHJ	P,CMDNOS
	LIST
>
	DEFINE BIS (XX,YY)<
	XLIST
	JRST	[ MOVE	CX,[ XX ]
		  ORM	CX,YY
		  JRST .+1 ]
	LIST
>
	DEFINE BIC (XX,YY)<
	XLIST
	JRST	[ MOVE	CX,[ XX ]
		  ANDCAM  CX,YY
		  JRST .+1 ]
	LIST
>

	DEFINE SETT<
	XLIST
	SETZM	0
	LIST
>
	DEFINE SETF<
	XLIST
	SETOM	0
	LIST
>
	DEFINE SKIPF<
	XLIST
	SKIPN	0
	LIST
>
	DEFINE SKIPT<
	XLIST
	SKIPE	0
	LIST
>
	DEFINE RET<
	XLIST
	POPJ	P,
	LIST
>
	DEFINE RETSKP <
	XLIST
IFDEF ..RSKP,<	JRST	..RSKP>
IFNDEF ..RSKP,<	JRST	[
..RSKP:	AOS	(P)
	POPJ	P, ]
>
	LIST
>
	DEFINE	RETF<
	XLIST
IFDEF ..RETF,< JRST ..RETF 
>
IFNDEF ..RETF,< JRST [
	..RETF: SETOM	0
		  POPJ	P, ] >
	LIST
>
	DEFINE	RETT<
	XLIST
IFDEF ..RETT,< JRST ..RETT
>
IFNDEF ..RETT,< JRST [
	..RETT: SETZM	0
		  POPJ	P, ] >
	LIST
>
	DEFINE	SETERR (CODE)<
	XLIST
	MOVEI	0,CODE
	LIST
>
	DEFINE ERRT20 <
	XLIST
IFDEF ..ET20,< PUSHJ P,..ET20>
IFNDEF ..ET20 ,< PUSHJ P,[
;;
;;	ERROR PRINTOUT.
;;	PRINTS OUT LAST TOPS20 ERROR,USED BY ERR MACRO'S
;;
..ET20:	PUSH	P,S1			;;SAVE SCRATCH AND TEMS
	PUSH	P,S2
	PUSH	P,T1
	PUSH	P,T2
	HRROI	S1,[ASCIZ/ LAST TOPS-20 ERROR: /]
	PSOUT
	MOVE	S1,[.PRIOU]		;;ALLWAYS OUR TTY
	MOVE	S2,[.FHSLF,,-1]		;;CURRENT FORK,LAST ERROR
	SETZB	T1,T2
	ERSTR				;;PRINT ERROR
	JFCL				;;IGNORE
	JFCL				;;THIS TOO
	HRROI	S1,[ASCIZ/
/]
	PSOUT
	POP	P,T2			;;UNSAVE SCRATCH AND TEMPS
	POP	P,T1
	POP	P,S2
	POP	P,S1
	POPJ	P, ] >
	LIST
>

	DEFINE ERROR (ADR,$TEXT)<
	XLIST
	JRST	[ HRROI	S1,[ASCIZ/$TEXT
/]
		  PSOUT
	IFN ADR,< JRST ADR ] >
	IFE ADR,< JRST .+1 ]>
	LIST
>
	DEFINE ERR (ADR,$TEXT)<
	XLIST
	JRST	[ HRROI	S1,[ASCIZ/$TEXT
/]
		  PSOUT
		  ERRT20
	IFN ADR,< JRST ADR ] >
	IFE ADR,< JRST .+1 ]>
	LIST
>
	DEFINE ERRJMP (ADR,$TEXT)<
	XLIST
	ERJMP	[ HRROI S1,[ASCIZ/$TEXT
/]
		PSOUT
		ERRT20
	IFN ADR,< JRST ADR ] >
	IFE ADR,< JRST .+1 ] >
	LIST
>
	DEFINE ERRNET (ADR,$TEXT)<
	XLIST
	JRST	[ HRROI	S1,[ASCIZ/$TEXT
/]
		  PSOUT
		  PUSHJ	P,NETPRS
	IFN ADR,< JRST ADR ] >
	IFE ADR,< JRST .+1 ]>
	LIST
>
	DEFINE	TMSG ($TEXT)<
	XLIST
	JRST	[ HRROI	S1,[ASCIZ/$TEXT
/]
		  PSOUT
		  JRST	.+1 ]
	LIST
>
	DEFINE	TMSX ($TEXT)<
	XLIST
	JRST	[ HRROI	S1,[ASCIZ\$TEXT\]
		  PSOUT
		  JRST	.+1 ]
	LIST
>
	DEFINE DOUT ( $LOC ) <
	XLIST
	MOVE	S2,$LOC
	IFDEF ..DOUT,< PUSHJ P,..DOUT>
	IFNDEF ..DOUT, <
	PUSHJ	P,[
..DOUT:	MOVE	S1,[.PRIOU]
	MOVEI	T1,^D10
	NOUT
	ERRJMP	,<
?NOUT Failed to output decimal number>
	RET ] >
	LIST
>
	DEFINE OOUT ( $LOC ) <
	XLIST
	MOVE	S2,$LOC
	IFDEF ..OOUT,< PUSHJ P,..OOUT>
	IFNDEF ..OOUT, <
	PUSHJ	P,[
..OOUT:	MOVE	S1,[.PRIOU]
	MOVEI	T1,^D8
	NOUT
	ERRJMP	,<
?NOUT Failed to output decimal number>
	RET ] >
	LIST
>
	DEFINE	LOCK (XX),<
	XLIST
	AOSE	XX
	LIST
>
	DEFINE UNLOCK (XX),<
	XLIST
	SETOM	XX
	LIST
>
	PAGE
	SUBTTL	SYMBOLS
;
;
;	SPECIAL SYMBOLS USED FOR X25GAL
;
	.XSTMO== ^D 30000		;GENERAL PORT TIME OUT
	.XSCHK==1000			;CHECK TIME
	XC%SUC==0			;GENERAL SUCCESS CODE
;
;	X25 PORT STATES
;
	XS%UND==0			;UNDEFINED
	XS%OPN==1			;OPEN
	XS%CAG==2			;CALLING
	XS%LSN==3			;LISTENING
	XS%CAD==4			;CALLED
	XS%RUN==5			;RUNNING
	XS%SYN==6			;SYNCHRONIZING
	XS%UNS==7			;UNSYNCHRONIZED
	XS%CLG==10			;CLEARING
	XS%CLD==11			;CLEARED
	XS%ERR==12			;ERROR
	XS%NCM==13			;NO COMMUNICATION

;
;	ERROR CODES AS RETURN BY GATWAY ACCESS ROUTINES
;
	XS%RSS==1B18			;RESET SEEN
	XS%VSK==1B19			;VERSION SKREW
	XS%BTS==1B20			;BUFFER TOO SHORT
	XS%BTL==1B21			;BUFFER TOO LONG
	XS%SDL==1B22			;SOURCE DTE SUBADDR. TOO LONG.
	XS%DDL==1B23			;DEST. DTE SUBADDR. TOO LONG
	XS%NIC==1B24			;NO INTR. CONFIRMATION REQUESTED
	XS%AIC==1B25			;AWAITING INTR. CONFIRMATION
	XS%NDN==1B26			;NO DESTIGNATION
	XS%INA==1B27			;ILLEGAL NETWORK ACCESS CODE
	XC%DFT==1B28			;DATA FIELD TRUNCATION
	XS%FFT==1B29			;FACILITIES FIELD TRUNCATION
	XS%UNN==1B30			;UNDEFINED NETWORK NAME
	XS%NIN==1B31			;NO INTERRUPT TO READ
	XS%NDA==1B32			;NO DATA TO READ
	XS%PER==1B33			;PROCEDURE ERROR
	XS%IAR==1B34			;INSUFFICIENT ACCESS RESOURCES
	XS%IGR==1B35			;INSUFFICIENT GATEWAY RESOURCES

;
;	ERROR STATUS FIELD AS RETURNED BY X%RPS
;
	XE%VSK==1B26			;VERSION SKREWED
	XE%DDL==1B27			;DESTIGNATION DTE ADDR. TOO LONG
	XE%SDL==1B28			;SOURCE DTE ADDR. TOO LONG.
	XE%FFT==1B29			;FACILITIES FIELD TRUNCATION
	XE%DFT==1B30			;DATA FIELD TRUNCATION
	XE%NCM==1B31			;NO COMM. WITH GATEWAY
	XE%UNN==1B32			;UNDEFINED NETWORK NAME
	XE%UCN==1B33			;UNDEFINED CIRCUIT NAME
	XE%INU==1B34			;CIRCUIT IN USE (RESERVED)
	XE%IGR==1B35			;INSUFFICIENT RECOURCES (GATWAY)
	XE%UNK==0			;UNKNOWN ERROR

;
;	BIT AS RETURNED BY X%RPS INTERRUPT-DATA BIT MASK
;
	XM%IIP==400000			;INCOMMING INTERRUPT CONFIRM PENDING
	XM%OIP==200000			;OUTGOING  INTERRUPT CONFIRM PENDING
	XM%IDA==100000			;INCOMMING DATA AVAILABLE
	XM%IIA== 40000			;INCOMMING INTERRUPT DATA AVAILABLE
	XM%MSK==740000			;MASK FOR ALL DATA
;
;	BITS AS RETURNED BY X%RDM
;
	XS%MOR==1B0			;MORE DATA AVAILABLE
	XS%QDA==1B1			;QUALIFIED DATA FLAG

;
;	LOCAL PORTF FLAGS
;
	XP%OPN==1B0			;PORT OPEN,PORT # ASSIGNED
	XP%RAD==1B1			;READ ACCEPT DATA HAS BEEN DONE
;
;	TEMINAL CHARACTER SET DEFINITION
;
	TC%BRK==1B0			;THIS IS A TERMINATION CHARACTER
	TC%DSC==1B1			;THIS IS A DICONNECT CHARACTER
	TC%FLG==1B2			;FLAG TYPE CHARACTER (^)
;
;	BITS IN TTYSTS
;
	TY%ERR==1B0			;ERROR IN TTY FORK SEEN
	TY%DIP==1B18			;DELETE IN PROGRESS
	TY%BRK==1B19			;TTY TASK REQUESTS BREAK
	TY%PWT==1B20			;TERMINAL IN PAGE WAIT
;
;	TERMINAL TYPE DEFINITIONS
;
	.TTYHC==0			;TERMINAL TYPE IS HARD-COPY
	.TTY52==1			;TERMINAL TYPE IS A VT52
	.TTYXX==2			;TERMINAL TYPE IS A VT100
;
;	INTERRUPT CHANNELS
;
	CH%X25==0			;CHANNEL 1 USED BY X25
	CH.X25==1B0
	CH%TMR==1			;CHANNEL 1 USED BY TIMER
	CH.TMR==1B1

	PAGE
;
;	SPECIAL DATA FOR TERMINAL ECHO PROCESSING
;
TTXCR:	XWD	1,[ BYTE (7)12,0,0,0]			;HARDCOPY
	XWD	2,[ BYTE (7)33,113,0]			;VT52
	XWD	3,[ BYTE (7)33,133,113,0 ]		;VT100

TTXCU:	XWD	5,[ BYTE (7)130,130,130,12,15,0 ]	;HARDCOPY
	XWD	2,[ BYTE (7)33,113,0 ]			;VT52
	XWD	3,[ BYTE (7)33,133,113,0 ]		;VT100

TTXDEL:	XWD	1,[ BYTE (7)57,0,0,0,0 ]		;HARDCOPY
	XWD	5,[ BYTE (7)33,104,40,33,104,0 ]	;VT52
	XWD	7,[ BYTE (7)33,133,104,40,33,133,104,0 ];VT100

	PAGE
	SUBTTL	MAIN INITIALIZATION AND TERMINATION CODE
;
;
;
START:	RESET				;RESET THE WORLD
	MOVE	P,[ IOWD PDLSZ,PDL ]	;SET UP PDL
	SETZM	PORTF			;NO PORT YET
	SETZM	PORTL			;SET PORT STATE UNDEFINED
	SETZM	TTYFRK			;NO TTY FORK YET
	setzm	ttysts			;no tty status yet
	setzm	porte			;and no port error yet
	CALL	INTON			;SET UP AND ENABLE INTERRUPTS
	CALL	TTYINI			;INITIALIZE TTY TASK
	AOSG	PADINI			;SAY INITIALIZATION DONE
	CALL	HERALD			;PRINT HEADER LINE
					;
CMDRST:	MOVEI	S2,[FLDDB. .CMINI]	;INITIALIZATION FUNCTION
	PARSE				;GO DO IT
	SKIPT				;DONE
	ERR	EXIT,<?COMND Failed to initialize command parsing>
	MOVEM	P,CMDSVP		;SAVE STACK FOR REPARSING
					;
CMDLOP:	SETT				;START OFF WITH OK
	MOVE	P,CMDSVP		;RESTORE THE STACK
	MOVEI	S2,[FLDDB. (.CMKEY,,CMDTAB)]	;POINT TO COMMAND TABLE
	PARSE					;READ IT
	SKIPT				;SUCCESS?
	JRST	CMDERX			;NO-COMPLAIN
	MOVE	S2,0(S2)		;GET ADDRESS OF ROUTINE
	CALL	0(S2)			;CALL IT
	SKIPF				;ERROR SEEN?
	JRST	CMDRST			;NO-GET A NEW COMMAND
	MOVEI	T1,.PRIIN		;GET READY
	CFIBF				;CLEAR INPUT BUFFER
	JRST	CMDRST			;AND GO START OVER
;
;	HERE ON ILLEGAL COMMAND, COMPLAIN ABOUT
;
CMDERX:	TMSX	<
? UNDEFINED COMMAND ">
	MOVE	S1,CMDBLK+.CMBFP	;GET POINTER TO COMMAND
;	CALL	BKTRM			;BAK UP OVER TERMINATOR
	PSOUT				;AND OUTPUT ERROR COMMAND
	TMSX	<"
>
	MOVEI	T1,.PRIIN		;GET READY
	CFIBF				;CLEAR INPUT BUFFER
	JRST	CMDRST			;AND RESTART COMMAND
;
;	ALL FATAL ERROR ENDS UP HERE
;
EXIT:	MOVE	S1,PORTF		;GET LOCAL PORT STATUS
	TXNE	S1,XP%OPN		;PORT OPEND YET?
	CALL	NETTPA			;YES-THEN CLEARE IT FIRST
	CALL	INTOFF			;TURN OFF ALL INTERRUPTS
	SKIPE	TTYFRK			;TTY FORK GOING?
	CALL	TTYKIL			;YES-THEN KILL IT FIRST
	move	s1,[ .fhslf ]		;get our fork handle
	clzff				;and close all
	JRST	START			;ALLOW RESTART

	PAGE
	SUBTTL	CMDTAB	COMMAND TABLE
;
;	COMMAND TABLE
;
	DEFINE	AA (X,Y),<		;;MACRO FOR COMMAND TABLES
	XLIST
	XWD	[ASCIZ/X/],Y
	LIST
>
;
CMDTAB:	CMDMAX,,CMDMAX			;HEADER
	AA	CONNECT,CMDCON		;CONNECT COMMAND
	AA	CONTINUE,CMDCNT		;CONTINUE COMMAND
	AA	DEBUG,CMDDBG		;SPECIAL DEBUG COMMAND
	AA	DEFINE,CMDDEF		;DEFINE COMMAND
	AA	DISABLE,CMDDSA		;GENERAL DISABLE COMMAND
	AA	DISCONNECT,CMDDIS	;DISCONNECT COMMAND
	AA	ENABLE,CMDENA		;GENERAL ENABLE COMMAND
	AA	EXIT,CMDXIT		;EXIT COMMAND
	AA	FULL,CMDFUL		;FULL DUPLEX COMMAND
	AA	HALF,CMDHLF		;HALF DUPLEX COMMAND
	AA	HELP,CMDHLP		;HELP COMMAND
	AA	ID,CMDID		;IDENTIFICATION COMMAND
	AA	INSERT,CMDINS		;INSERT COMMAND
	AA	MAIL,CMDMS		;MAIL COMMAND
	AA	NETWORK,CMDNET		;NETWORK COMMAND
	AA	PADDING,CMDPDD		;PADDING COMMAND
	AA	PAGE-SIZE,CMDPAG	;PAGE-SIZE COMMAND
	AA	PUSH,CMDPSH		;PUSH COMMAND
	AA	SET,CMDSET		;SET COMMAND
	AA	STATUS,CMDSTS		;STATUS COMMAND
	AA	TERMINAL,CMDTTY		;TERMINAL COMMAND
	AA	TEST,CMDTST		;TETS MODE
	CMDMAX==.-CMDTAB-1		;NUMBER OF COMMANDS

	PAGE
	SUBTTL	THE SIMPLE COMMANDS - EXIT, HELP



;EXIT FROM PROGRAM.  "EXIT" COMMAND.


CMDXIT:	NOISE	(FROM PROGRAM)	;DO GUIDEWORDS
	CONFRM			;THEN CONFIRM THE COMMAND
	CALL	TTYREM		;MAKE SURE,TERMINAL IS RESET
	MOVE	S1,PORTF	;GET LOCAL PORT STATUS
	TXNE	S1,XP%OPN	;PORT OPEND YET?
	CALL	NETTPA		;YES-THEN CLEARE IT FIRST
	CALL	INTOFF		;TURN OFF ALL INTERRUPTS
	SKIPE	TTYFRK		;TTY FORK GOING?
	CALL	TTYKIL		;YES-THEN KILL IT FIRST
	tmsg	< PAD SESSION STATISTICS:
>
	TMSX	<	Bytes sent >
	DOUT	POROCT			;OUTPUT BYTES SENT
	TMSX	<		Blocks sent >
	DOUT	POROBL			;AND BLOCKS SENT
	TMSG	< >
	TMSX	<	Bytes received >
	DOUT	PORICT			;OUTPUT BYTES RECEIVED
	TMSX	<	Blocks received >
	DOUT	PORIBL			;AND BLOCKS RECEIVED
	TMSG	< >
	TMSX	<	Elapsed time	>
	TMSG	< >

	HALTF			;STOP PROGRAM
	JRST	START		;AND ALLOW RESTART



;THE "HELP" COMMAND.


CMDHLP:	NOISE	(WITH COMMANDS)	;DO GUIDEWORDS
	CONFRM			;CONFIRM THE LINE
	HRROI	S1,HLPTXT	;POINT TO HELP MESSAGE
	PSOUT			;TYPE IT
	RET			;AND RETURN

	PAGE
	XLIST
;
HLPTXT:	ASCIZ\
BASIC COMMANDS:
	Connect	DTE-number<subaddress>	To request connection to a host comp.
	ID Password			To set the password for host connection
	ID <cr>				To cancel use of password for host conn.
	Network				To define the name of the local gateway.
	Continue			To return to data transfer mode.
	Disconnect			To request a disconnect from host comp.
	Status				To get current PAD status.
	Mail				Not yet implemented
	Terminal			To specify terminal identifier.
	Full duplex			To specify remote (host) echo.
	Half duplex			To specify local  ( PAD) echo.
	Reset				To reinitialize parameters.
ADVANCED NETWORK COMMANDS:
	Define Break character		To define the character to be used as
					break.
	Enable Padding			To provide local padding based on
					terminal identifier.
	Disable Padding			To disable padding.
	Padding Carrage-return #	To specify number of padding on <CR>
	Padding	Line-feed #		To specify number of padding on <lf>
	Padding Form-feed #		To specify number of padding on <HT>
	Enable Folding			To begin a new line if print line
					exceeds line width.
	Disable Folding			To disable line wraparound feature.
	Enable Echo			To enable local echo.
	Disable Echo			To disable local echo mode.
	Insert Line-feed on Input	Insert <LF> after <CR>.
			 on Output
			 on Both
			 on Echo only
			 None
	Enable Flow-control		PAD will send XON/XOFF to flow control
					terminal input to a computer.
	Disable Flow-control		To remove flow-control feature.
	Enable TFlow-control		PAD will respond to XON/XOFF send by
					the terminal.
	Disable TFlow-contraol		To remove tflow-control feature.
	Page-size line-width page-length To specify terminal line-width and
					page size.
	Enable Wait on-end-of-page	To stop output from host an wait for
					a XON if page-lenght number of lines.
	TEST COMMANDS:
	Test Echo			PAD will echo chracters transmitted
					from terminal for testing purpose.
	Debug				TRACE Port status and message type
\				;end of help-text

;
;
	LIST
	PAGE
	SUBTTL	CONNECT	COMMAND PROCESSING
;
;
CMDCON:	NOISE	< to DTE number >	;GIVE A HELP
	MOVEI	S2,[ FLDDB. (.CMFLD,,,< the DTE number to connect to, >)]
	PARSE				;PARSE IT
	SKIPT				;SUCCESS?
	ERROR RETE,<DTE number not confirmed>
	CALL	DTENUM			;COPY THIS NUMBER
	SKIPT				;SUCCESS?
	ERROR	RETE,<?Illegal DTE number specified>
	CAIG	S2,^D 15		;TOO LONG?
	SKIPN	S2			;OR TOO SHORT
	ERROR	RETE,<?DTE number missing or DTE number too long>
					;
	NOISE	< Subaddress >		;GIVE A HELP
	SETZM	DTESNR			;SAY NO SUBADDRESS YET
	SKIPT				;WE GOT IT
	JRST	CMDCO0			;NO-NOT NEEDED THEN
	MOVEI	S2,[ FLDDB. (.CMNUM,,^D10,<
the subaddress of the DTE you want to go to>,<0>)]
	PARSE				;PARSE IT
	SKIPT				;SUCCESS?
	JRST	CMDCO0			;NO-SO FORGET ABOUT
	MOVE	S1,[ POINT 7,DTESNR ]	;WHERE THE SUB-DTE NUMBER GOES
	MOVEI	T1,^D10			;IN DECIMAL
	NOUT				;AND PUT IT IN
	ERRJMP	RETE,<?NOUT failed to convert SUB-DTE number>
					;
CMDCO0:	CONFRM				;CONFIRM THE LINE

	PAGE
;
;
;	CREATE A X29 LINK HERE
;
	PIOFF				;TURN OFF FOR NICE OUTPUT
	CALL	NETOPN			;TRY TO OPEN NETWORK
	SKIPT				;SUCCESS
	ERROR	EXIT,<?Can't open network for this DTE >
	CALL	TTYFGO			;START TTY TASK GOING
	PION				;TURN SYSTEM BACK ON
	MOVEI	S1,.XSTMO		;PORT TIME OUT
	MOVEI	S2, XS%RUN		;AND WAIT FOR RUN
	CALL	$WAIT			;WAIT FOR
	SKIPF				;ANY ERROR SHOWED UP?
	JRST	[ CALL  TTYSEM		;SET TERMINAL MODE AS NEEDED
		  JRST	CMDCOL	]	;AND GO WAIT, ALL DONE HERE
					;
	SKIPE	PORTE			;PORT FLAGS ERROR
	ERROR	EXIT,<?Fatal Port error, aborting connection>
	ERROR	EXIT,<?Fatal Port did not respond in time, aborting connection>
;
;	Here after succesfully opened port to remote site
;
CMDCOL:	MOVEI	S1,.XSCHK		;GET CHECK OUT TIME
	DISMS				;AND WAIT FOR
	SKIPE	PORTE			;ERROR FROM NETWORK?
	JRST	CMDCO1			;YES-COMPLAIN ABOUT
	SKIPGE	T1,TTYSTS		;FORK CRASHED BY ERROR
	JRST	CMDCO2			;YES-COMPLAIN
	TXNE	T1,TY%BRK		;REQUESTED BREAK?
	JRST	CMDCO3			;YES-DO SO
	CALL	TTYCHK			;CHECK TERMINAL FORK
	SKIPF				;ALL OK?
	JRST	CMDCOL			;ALL NICE-LOOP ONCE MORE
	JRST	CMDCO2			;NO-TELL USER ABOUT TRUBLE

	PAGE
;
;	HERE IF NETWORK FLAGS PROBLEMS
;
CMDCO1:	CALL	TTYREM			;RESET OUR TERMINAL
	ERROR	EXIT,<?Fatal Port error, aborting connection >
;
;	HERE IF TERMINAL TASK NEEDS ATTENSION, BREAK OR ERROR TERMINATION
;
CMDCO2:	CALL	TTYREM			;RESET TERMINAL
	ERROR	,<?Terminal task aborted abnormaly,restarting TTY task>
	JRST	CMDCNX			;JOIN CONTINUE CODE TO RESTART
					;TTY FORK
;
;	HERE IF TTY TASK REQUESTS BREAK
;
CMDCO3:	CALL	TTYREM			;RESET TERMINAL
	JRST	CMDRST			;AND RESTART COMMAND PRC.

	PAGE
	SUBTTL	CONTINUE COMMAND PROCESSING
;
;	CONTINUE ( with current host)
;
CMDCNT:	NOISE	(with current host)	;GIVE A HELP
	CONFRM				;AND TERMINATE COMMAND
CMDCNX:	MOVE	S2,PORTS		;GET CURRENT PORT STATE
	CAIN	S2,XS%RUN		;PORT RUNNING?
	JRST	[ CALL	TTYSEM		;YES-SET TERMINAL MODE
		 CALL	TTYFGO		;AND CONTINUE TTY TASK
		  JRST	CMDCOL	]	;JOIN CONNECT CODE
	TMSX	<
?Cant continue because port is not running,port state is >
	HRRZ	S1,PORTS		;GET PORT STATE
	MOVE	S1,NETSTT(S1)		;AND ITS TRANSLATEION
	PSOUT				;OUTPUT IT
	TMSX	<
>
	RETF				;AND ERROR RETURN

	PAGE

;
;	DEBUG COMMAND:
;	THE DEBUG COMMAND CURRENTLY IS LIMITED TO TURN ON THE
;	TRACE SWITCH TO TRACE ALL RECEIVED MESSAGE TYPES AND
;	ANY STATE CHANGE.
;
CMDDBG:	NOISE	(PAD )
	CONFRM				;TERMINATE COMMAND
	SETOM	TRACE			;TURN ON TRACE SWITCH
	HRROI	S1,[ASCIZ/ TRACE switch turned on
/]
	PSOUT
	RETT				;ALL DONE, RETURN


	PAGE
	SUBTTL	DEFINE	COMMAND PROCESSING
;
;	DEFINE (break character) character
;
CMDDEF:
CMDBRK:	NOISE	(break character)	;GIVE A HELP
	SKIPT				;
	JRST	[ MOVEI	T1,.TICCY	;DEFAULT TO ^Y
		  MOVEM	T1,TTYBRC	;AND SET IT
		  RETT ]		;ALL DONE HERE
	MOVE	S1,[ .PRIIN ]		;DESIGNATOR
	BIN				;AND GET RESPONSE
	PUSH	P,S2			;SAVE IT OVER
	CONFRM				;TERMINATE COMMAND
	POP	P,S2			;AND GET IT BACK
	ANDI	S2,177			;ONLY 7 BITS WE WANT
	SKIPN	S2			;NULL?
	MOVEI	S2,.TICCY		;YES-DEFAULT TO ^Y
	MOVE	T1,CHRTAB(S2)		;GET TYPE OF CHARACTER
	TXNN	T1,TC%FLG		;FLAG TYPE CHRACTER?
	ERROR	RETE,<Not a legal break character>
	MOVEM	S2,TTYBRC		;AND SAVE IT AWAY
	TMSX	< Break character set to ^>
	ADDI	S2,100			;MAKE IT PRINTABLE
	MOVE	S1,[ .PRIOU ]		;OUTPUT DESIGNATOR
	BOUT				;AND OUTPUT IT
	TMSX	<
>
	RETT				;ALL DONE, RETURN

	PAGE
	SUBTTL	DISABLE COMMAND PROCESSING
;
;	DISABLE FLOW-CONTROL
;	       FOLDING
;              LOCAL-ECHO
;              PADDING
;              TFLOW-CONTROL
;              WAIT
;
CMDDSA:	MOVEI	S2,[ FLDDB. (.CMKEY,,DSATAB)]	;
	PARSE					;PARSE IT
	SKIPT				;SUCCESS?
	ERROR	RETE,<?Not confirmed>
	MOVE	S2,0(S2)		;GET PROCESSOR
	JRST	0(S2)			;AND GO TO
;
;
DSATAB:	DSASIZ,,DSASIZ
	AA	FLOW-CONTROL,DSAFLC	;FLOW-CONTROL
	AA	FOLDING,DSAFOL		;FOLDING ON
	AA	LOCAL-ECHO,DSALOE	;LOCAL ECHO MODE
	AA	PADDING,DSAPDD		;PADDING
	AA	TFLOW-CONTROL,DSATFL	;TFLOW-CONTROL
	AA	WAIT,DSAWOP		;WAIT-ON END OF PAGE
	DSASIZ=.-DSATAB-1

	PAGE
;
;	DISABLE FLOW-CONTROL COMMAND PROCESSING
;
DSAFLC:	CONFRM				;
	ERROR	RETE,<?COMMAND NOT YET IMPLEMENTED>
;
;	DISABLE	FOLDING COMMAND PROCESSING
;
DSAFOL:	CONFRM
	SETZM	TTYFLD			;DISABLE FOLDING
	RETT				;ALL DONE, RETURN
;
;	DISABLE LOCAL ECHO MODE
;
DSALOE:	NOISE	(local echo mode)	;GIVE A HELP
	CONFRM				;TERMINATE COMMAND
	SETZM	PAD2			;TURN OFF ECHO MODE
	RETT				;ALL DONE, RETURN
;
;	DISABLE PADDING
;
DSAPDD:	NOISE	(on local echo)
	CONFRM				;TERMINATE COMMAND
	SETZM	TTYPAD			;TURN PADDING OFF
	RETT				;ALL DONE RETURN

	PAGE
;
;	DISABLE TFLOW COMMAND PROCESSING
;
DSATFL:	CONFRM
	ERROR	RETE,<?Command not yet implemented>
;
;	HERE ON DISABLE WAIT-ON-END-OF-PAGE COMMAND PROCESSING
;
DSAWOP:	NOISE	(end-of-page-mode)
	CONFRM
	SETZM	TTYPMO			;TURN OFF PAGE MODE
	RETT				;ALL DOEN,RETURN

	PAGE
	SUBTTL	DISCONNECT COMMAND PROCESSING
;
;	DISCONNECT
;
CMDDIS:	NOISE	(from current host)	;GIVE A HELP
	CONFRM				;TERMINATE COMMAND
	MOVE	S2,PORTS		;GET CURRENT PORT STATE
	CAIN	S2,XS%RUN		;PORT RUNNING?
	JRST	CMDDI2			;YES-GO DISCONNECT
	TMSX	<
?Cant disconnect because port is not running,port state is >
	HRRZ	S1,PORTS		;GET PORT STATE
	MOVE	S1,NETSTT(S1)		;AND ITS TRANSLATEION
	PSOUT				;OUTPUT IT
	TMSX	<
>
	RETF				;AND RETURN FALSE
					;
CMDDI2:	MOVE	T1,PORT			;GET PORT WE'RE ON
	MOVEM	T1,MRGBLK		;AND SET IT
	SETZM	MRGBLK+1		;NO ERROR CODE YET
	SETZM	MRGBLK+2		;NO CLEARE CAUSE
	SETZM	MRGBLK+3		;NO USER GROUP NAME
	SETZM	MRGBLK+4		;NO FACILITIES
	SETZM	MRGBLK+5		;AND NO USER DATA
					;
	MOVEI	S1,MRGBLK		;GET BLOCK ADDRESS
	CALL	X%CSC			;AND CLEARE PORT
	HRRZ	T1,MRGBLK+1		;GET RETURN-CODE
	CAIN	T1,XC%SUC		;SUCCESS?
	RETT				;YES-ALL DONE HERE
	CALL	NETEPR			;NO-PRINT ERROR CODE
	RETF				;AND ERROR RETURN

	PAGE
	SUBTTL	ENABLE COMMAND PROCESSING
;
;	ENABLE FLOW-CONTROL
;	       FOLDING
;              LOCAL-ECHO
;              PADDING
;              TFLOW-CONTROL
;              WAIT
;
CMDENA:	MOVEI	S2,[ FLDDB. (.CMKEY,,ENATAB)]	;
	PARSE					;PARSE IT
	SKIPT				;SUCCESS?
	ERROR	RETE,<?Not confirmed>
	MOVE	S2,0(S2)		;GET PROCESSOR
	JRST	0(S2)			;AND GO TO
;
;
ENATAB:	ENASIZ,,ENASIZ
	AA	FLOW-CONTROL,ENAFLC	;FLOW-CONTROL
	AA	FOLDING,ENAFOL		;FOLDING ON
	AA	LOCAL-ECHO,ENALOE	;LOCAL ECHO MODE
	AA	PADDING,ENAPDD		;PADDING
	AA	TFLOW-CONTROL,ENATFL	;TFLOW-CONTROL
	AA	WAIT,ENAWOP		;WAIT-ON END OF PAGE
	ENASIZ=.-ENATAB-1

	PAGE
;
;	ENABLE FLOW-CONTROL COMMAND PROCESSING
;
ENAFLC:	CONFRM				;
	ERROR	RETE,<?COMMAND NOT YET IMPLEMENTED>
;
;	ENABLE	FOLDING COMMAND PROCESSING
;
ENAFOL:	CONFRM
	SETOM	TTYFLD			;ENABLE FOLDING
	RETT				;ALL DONE,RETURN
;
;	ENABLE LOCAL ECHO COMMAND PROCESSING
;
ENALOE:	NOISE	(for half duplex operation)
	CONFRM
	MOVEI	T1,1			;GET LOCAL ECHO MODE
	MOVEM	T1,PAD2			;AND SET IT
	RETT				;ALL DONE-RETURN
;
;	ENABLE PADDING (ON CHRACTER) xxx yyy
;
ENAPDD:	NOISE	(on local echo)
	CONFRM				;TERMINATE COMMAND
	SETOM	TTYPAD			;AND ENABLE PADDING
	RETT				;ALL DONE, RETURN
;
;	ENABLE TFLOW COMMAND PROCESSING
;
ENATFL:	CONFRM
	ERROR	RETE,<?Command not yet implemented>
;
;	HERE ON WAIT-ON-END-OF-PAGE COMMAND PROCESSING
;
ENAWOP:	NOISE	(on-end-of-page)
	CONFRM
	ERROR	RETE,<Command not implemented yet>
;	SETOM	TTYPMO			;ENABLE PAGE MODE
	RETT				;ALL DONE, RETURN

	PAGE
	SUBTTL	FULL DUPLEX COMMAND PROCESSING
;
;	FULL DUPLEX (terminal mode)
;
CMDFUL:	NOISE	(Duplex terminal mode)	;
	CONFRM				;TERMINATE COMMAND
	SETZM	PAD2			;FLAG NO LOCAL ECHO NEEDED
	RETT				;AND DONE RETURN

	PAGE
	SUBTTL	HALF DUPLEX COMMAND PROCESSING
;
;	HALF DUPLEX (terminal mode)
;
CMDHLF:	NOISE	(Duplex terminal mode)	;
	CONFRM				;TERMINATE COMMAND
	MOVEI	T1,1			;GET LOCAL ECHO
	MOVEM	T1,PAD2			;INDICATION AND STORE IT
	RETT				;ALL DONE RETURN

	PAGE
	SUBTTL	ID	COMMAND PROCESSING
;
;	ID	<PASSWORD STRING>
;
CMDID:	NOISE	(for connection is)	;GIVE HIM A HELP
	SKIPT				;
	JRST	[ SETZM	NETPSW		;NO-PASSWORD CLEAR IT
		  RETT	]		;
	MOVEI	S2,[ FLDDB. (.CMFLD,,,<Password string>)]
	PARSE				;PARSE IT
	SKIPT				;SUCCESS?
	ERROR	RETE,<?Not confirmed>
	CONFRM				;TERMINATE COMMAND
	MOVE	S1,[ POINT 7,NETPSW ]	;GET WHERE TO STORE IT
	MOVE	S2,CMDBLK+.CMABP	;AND ATM. BUFFER PNTR.
	SETZM	T1			;TERMINATE ON ZERO
	MOVEI	T2,NETPSZ		;OR ON MAX. PSW SIZE.
	SOUT				;COPY PSW STRING
	ERRJMP	RETE,<?SOUT failed to copy password string>
	RETT				;ALL DONE RETURN


	PAGE
	SUBTTL	INSERT	COMMAND PROCESSING
;
;	INSERT	(LF AFTER) INPUT
;			   OUTPUT
;			   BOTH
;			   ECHO
;
CMDINS:	NOISE	(Line feed after CR on)	;GIVE A HELP
	MOVEI	S2,[ FLDDB. (.CMKEY,,INSTAB)]
	PARSE				;PARSE IT
	SKIPT				;SUCCESS?
	ERROR	RETE,<?Not confirmed>
	MOVE	S2,0(S2)		;GET DISPATCH
	JRST	0(S2)			;AND PROCESS IT
;
;
INSTAB:	INSSIZ,,INSSIZ
	AA	BOTH,INSBO		;AFTER CR ON BOTH
	AA	ECHO,INSEHO		;AFTER CR ON ECHO
	AA	INPUT,INSIN		;AFTER CR ON INPUT
	AA	NONE,INSNO		;AFTER CR ON NONE
	AA	OUTPUT,INSOU		;AFTER CR ON OUTPUT
	INSSIZ==.-INSTAB-1
;
;	DUMMY COMMAND NOT NEEDED YET
;
INSBO:
INSOU:
INSIN:	ERROR	RETE,<Command not yet implemented>
;
;	HERE ON INSERT LF AFTER CR ON NONE
;
INSNO:	CONFRM				;TERMINATE COMMAND
	SETZM	PAD13			;AND SET PAD PARAM
	RETT				;ALL DONE,RETURN
;
;	HERE ON INSERT LF AFTER CR ON ECHO
;
INSEHO:	CONFRM				;TERMINATE COMMAND
	MOVEI	T1,4			;GET PAD13 VALUE FOR
	MOVEM	T1,PAD13		;AND SET IT
	RETT				;ALL DONE RETURN

	PAGE
	SUBTTL	MAIL	COMMAND PROCESSING
CMDMS:	ERROR	RETS,<%Command not yet implemented>

	PAGE
	SUBTTL	SET	COMMAND PROCESSING
;
;	SET IDLE-TIMER (to value ) xxx (1/20 of a second)
;
CMDSET:	MOVEI	S2,[ FLDDB. (.CMKEY,,SETTAB)]
	PARSE				;PARSE IT
	SKIPT				;SUCCESS?
	ERROR	RETE,<Not confirmed>
	MOVE	S2,0(S2)		;GET DISPATCH
	JRST	0(S2)			;AND GO PROCESS IT
;
;	SET COMMAND TABLE
;
SETTAB:	SETSIZ,,SETSIZ
	AA	IDLE-TIMER,SETIDL	;SET IDLE TIMER
	SETSIZ==.-SETTAB-1
;
;
;	SET IDLE-TIMER (to value) xxx (1/20 of a second)
;
SETIDL:	NOISE	(to value)		;GET A HELP
	SKIPT				;SUCCESS
	JRST	[ SETZM	PAD4		;SET TO NO IDLE TIMER
		  RETT ]		;ALL DONE, RETURN
	MOVEI	S2,[ FLDDB.(.CMNUM,,^D10,< 1/20 of a second>)]
	PARSE				;PARSE IT
	SKIPT				;SUCCESS?
	ERROR	RETE,<Not confirmed>
	CAILE	S2,^D 255		;IN RANGE?
	ERROR	RETE,<?Max value for idle timer is 255. >
	MOVEM	S2,PAD4			;SET NEW VALUE
	CONFRM				;TERMINATE COMMAND
	RETT				;ALL DONE,RETURN

	PAGE
	SUBTTL	STATUS COMMAND PROCESSING
;
;	STATUS :
;	CURRENT	TERMINAL TYPE IS: XXXXXXXX
;	MODE:	YYYY		BREAK CHARACTER X
;	LOCAL ECHO XXXXXXX
;	PORT STATE XXXXXXXX	DTE NUMBER XXXXXXXXXXXX
;	IDLE TIMER XXXXXXXXX
;	NETWORK	XXXXXXX		PASSWORD XXXXXXXXX
;	LINE FOLDING XXXXXX	PADDING	XXXXXXXXX
;	INSERT LF AFTER CR ON YYYYYY
;	WAIT	YYYYYYYYY
;	BYTES SENT XXXXX	BLOCK SENT XXXXXXX
;	BYTES RECEIVED XXXXX	BLOCK RECEIVED XXXXXXX
;	ELAPSED TIME XXXX:XXXX.XX
;
CMDSTS:	NOISE	(of PAD)		;GET A HELP
	CONFRM				;AND TERMINATE COMMAND
	TMSG	< >
	CALL	HERALD			;TYPE OUT VERSION
	TMSG	<	PAD STATUS:>
	TMSX	<	Terminal Type: >
	MOVE	T1,TTYTYP		;GET TERMINAL TYPE
	CAIN	T1,.TTYHC		;HARDCOPY?
	TMSX	< Hardcopy Terminal>
	CAIN	T1,.TTY52		;DISPLAY VT52?
	TMSX	< Display VT52 >
	CAIN	T1,.TTYXX		;DISPLAY VT100?
	TMSX	< Display VT100 >
	TMSX	<	Break chracter is >
	MOVE	S1,[ .PRIOU ]		;
	MOVEI	S2,136			;GET FLAG
	BOUT				;AND OUTPUT IT
	MOVE	S2,TTYBRC		;GET BREAK CHARACTER
	ADDI	S2,100			;MAKE IT PRINTABLE
	BOUT				;AND OUTPUT IT
	TMSG	< >
	TMSX	<	Terminal local echo >
	HRROI	S1,[ASCIZ/Enabled/]
	SKIPN	PAD2			;REALY ENABLED?
	HRROI	S1,[ASCIZ/Disabled/]
	PSOUT				;AND OUTPUT IT
	TMSG	< >
	TMSX	<	Idle timer >
	SKIPN	PAD4			;IDLE TIMER ENABLED?
	JRST	[ TMSX	<not enabled>
		 JRST	CMDST1 ]
	 TMSX	<set to >
	 DOUT	PAD4
	 TMSX	< units of 1/20 sec. >
CMDST1:	JFCL
	TMSG	< >
	TMSX	<	Port state : >
	HRRZ	S1,PORTS		;GET PORT STATE
	MOVE	S1,NETSTT(S1)		;GET TRANSLATION
	PSOUT				;AND OUTPUT IT
	MOVE	T1,PORTS		;ET IT BACK
	CAIE	T1,XS%RUN		;RUNNING?
	JRST	CMDST2			;NO-JUMP OVER
					;
	TMSX	< DTE number is >
	HRROI	S1,DTENBR		;GET DTE-NUMBER
	PSOUT				;AND PRINT IT
	TMSX	<(>
	SKIPN	DTESNR			;SUBNUMBER SPEC.
	JRST	[ HRROI	S1,[ASCIZ/0/]	;NO-DEFAULT TO ZERO
		  JRST	.+2 ]		;AND SKIP.
	HRROI	S1,DTESNR		;GET SUB-NUMBER
	PSOUT				;OUTPUT IT
	TMSX	<)>			;TERMINATE
					;
CMDST2:	TMSG	< >
	TMSX	<	Network name >
	HRROI	S1,NETNAM		;GET NAME STRING
	SKIPN	NETNAM			;ZERO NAME?
	HRROI	S1,[ASCIZ/No Network name/]
	PSOUT				;OUTPUT IT
	TMSX	<	Password >
	HRROI	S1,NETPSW		;GET PASSWORD-STRING
	SKIPN	NETPSW			;NULL
	HRROI	S1,[ASCIZ/No Password/]
	PSOUT				;AND OUTPUT IT
	TMSG	< >
	TMSX	<	Line folding >
	HRROI	S1,[ASCIZ/Enabled/]
	SKIPN	TTYFLD			;ENABLED?
	HRROI	S1,[ASCIZ/Disabled/]	;N0-DISABLED
	PSOUT				;AND SENT IT OUT
	TMSX	<	Padding >
	HRROI	S1,[ASCIZ/Enabled/]
	SKIPN	TTYPAD			;ENABLED?
	HRROI	S1,[ASCIZ/Disabled/]	;N0-DISABLED
	PSOUT				;AND SENT IT OUT
	TMSG	< >
	TMSX	<	Page size >
	DOUT	TTYPSZ
	TMSX	<	Line width >
	DOUT	PAD10
	TMSG	< >
	TMSX	<	Wait >
	HRROI	S1,[ASCIZ/on-end-of-page/]
	SKIPN	TTYPMO			;ENABLED?
	HRROI	S1,[ASCIZ/on-end-of-page Disabled/]
	PSOUT				;AND SENT IT OUT
	TMSG	< >
	TMSX	<	Insert LF after CR on >
	MOVE	T1,PAD13		;GET PARAMETER
	CAIN	T1,0			;NONE?
	HRROI	S1,[ASCIZ/None/]
	CAIN	T1,1			;OUTPOUT
	HRROI	S1,[ASCIZ/Output/]
	CAIN	T1,2			;INPUT?
	HRROI	S1,[ASCIZ/Input/]
	CAIN	T1,3			;BOTH
	HRROI	S1,[ASCIZ/Both/]
	CAIN	T1,4			;ECHO?
	HRROI	S1,[ASCIZ/Echo/]
	CAILE	T1,4			;IN RANGE?
	HRROI	S1,[ASCIZ/Unknown PAD13 value/]
	PSOUT				;PRINT IT
	TMSG	< >
	TMSX	<	Bytes sent >
	DOUT	POROCT			;OUTPUT BYTES SENT
	TMSX	<	Blocks sent >
	DOUT	POROBL			;AND BLOCKS SENT
	TMSG	< >
	TMSX	<	Bytes received >
	DOUT	PORICT			;OUTPUT BYTES RECEIVED
	TMSX	<	Blocks received >
	DOUT	PORIBL			;AND BLOCKS RECEIVED
	TMSG	< >
	TMSX	<	Elapsed time	>
	TMSG	< >
	TMSG	<	End status report >
	RETT

	PAGE
	SUBTTL	TERMINAL COMMAND PROCESSING
;
;	TERMINAL MODE (IS)...TYPE OF TERMINAL..
;
;
CMDTTY:	NOISE	(mode is)			;GIVE A HELP
	SKIPT				;SUCCESS?
	ERROR	RETE,<?Not confirmed>	;
	MOVEI	S2,[ FLDDB. (.CMKEY,,TTTAB)]
	PARSE				;GET TYPE OF TERMINAL
	SKIPT				;SUCCESS?
	ERROR	RETE,<?Not confirmed>	
	HRRZ	S2,0(S2)		;GET TYPE CODE
	MOVEM	S2,TTYTYP		;AND SET IT
	CONFRM				;AND CONFIRM
	RETT				;RETURN DONE
;
;
TTTAB:	TTTSIZ,,TTTSIZ
	AA	LA120,.TTYHC		;HARDCOPY
	AA	LA30,.TTYHC		;HARDCOPY
	AA	LA34,.TTYHC		;HRADCOPY
	AA	LA36,.TTYHC		;HARDCOPY
	AA	VT100,.TTYXX		;VT100
	AA	VT52,.TTY52		;VT52
	TTTSIZ=.-TTTAB-1


	PAGE
	SUBTTL	TEST	COMMAND
;
;	HERE ON TERMINAL TEST MODE COMMAND
;	START TERMINAL TASK IN DEBUG MODE,NORMAL BREAK WILL TERMINATE
;	TEST MODE.
;
CMDTST:	NOISE	(Terminal echo mode)
	CONFRM				;
	SETOM	TTYDEB			;TURN ON DEBUG FLAG
	MOVE	T1,1			;GET LOCAL ECHO MODE
	EXCH	T1,PAD2			;AND TURN ON ECHO MODE
	PUSH	P,T1			;AND SAVE IT
	CALL	TTYFGO			;START "TASK" GOING
	CALL	TTYSEM			;SET APPROPIATE MODE FOR
	CALL	TTYINP			;AND START IT GOING
	CALL	TTYREM			;RESET TO NORMAL MODE
	POP	P,T1			;GET BACK ECHO MODE
	EXCH	T1,PAD2			;AND RESET MODE
	SKIPG	TTYSTS			;ERROR FLAG SET?
	ERROR	,<?TTYTSK flags error>
	SETZM	TTYDEB			;TURN OFF DEBUG FLAG
	RET				;ALL DONE

	PAGE
	SUBTTL	NETWORK	COMMAND PROCESSING
;
;	NETWORK (name of the X25 gateway)
;
CMDNET:	NOISE	(name of the X25 gateway)
	MOVEI	S2,[ FLDDB. (.CMFLD,,,<name string>)]
	PARSE				;PARSE IT
	SKIPT				;SUCCESS?
	ERROR	RETE,<?Not confirmed>
	CONFRM				;TERMINATE COMMAND
	MOVE	S1,[ POINT 7,NETNAM ]	;GET WHERE TO STORE IT
	MOVE	S2,CMDBLK+.CMABP	;AND ATM. BUFFER PNTR.
	SETZM	T1			;TERMINATE ON ZERO
	MOVEI	T2,NETNMZ		;OR ON MAX. PSW SIZE.
	SOUT				;COPY NAME STRING
	ERRJMP	RETE,<?SOUT failed to copy network name string>
	RETT				;ALL DONE RETURN


	PAGE
	SUBTTL	PADDING	COMMAND PROCESSING
;
;	PADDING (ON CHRACTER) xxx yyy
;
CMDPDD:	NOISE	(on character)
	SKIPT				;SUCCESS
	ERROR	RETE,<?Not confirmed>
	MOVEI	S2,[ FLDDB. (.CMKEY,,PDDTAB)]
	PARSE				;PARSE IT
	SKIPT				;SUCCESS?
	ERROR	RETE,<?Not confirmed>
	MOVE	S2,0(S2)		;GET PROCESSOR
	JRST	0(S2)			;AND GO TO
;
;
PDDTAB:	PDDSIZ,,PDDSIZ
	AA	CARRAGE-RETURN,PDDCRP	;CARRAGE RETURN
	AA	FORM-FEET,PDDFFT	;FORM-FEET
	AA	LINE-FEED,PDDLFP	;LINE-FEED
	PDDSIZ==.-PDDTAB-1		;
;
;	HERE ON PADDING ON CARRAGE-RETURN
;
PDDCRP:	MOVEI	S2,[ FLDDB. (.CMNUM,,^D10,<number of padding characters>)]
	PARSE				;PARSE IT
	SKIPT				;SUCCESS?
	ERROR	RETE,<?Not confirmed>
	SKIPE	S2			;IN RANGE?
	CAILE	S2,^D255		;
	ERROR	RETE,<?Not confirmed,must be in range of 1 to 255>
	CONFRM				;TERMINATE
	MOVEM	S2,PAD9			;AND SET PAD-PARAM FOR.
	RETT				;AND DONE RETURN
;
;	HERE ON PADDING ON FORM-FEET
;
PDDFFT:	MOVEI	S2,[ FLDDB. (.CMNUM,,^D10,<number of padding characters>)]
	PARSE				;PARSE IT
	SKIPT				;SUCCESS?
	ERROR	RETE,<?Not confirmed>
	SKIPE	S2			;IN RANGE?
	CAILE	S2,^D255		;
	ERROR	RETE,<?Not confirmed,must be in range of 1 to 255>
	CONFRM				;TERMINATE
	RETT				;AND DONE RETURN
;
;	HERE ON PADDING ON LINE-FEET
;
PDDLFP:	MOVEI	S2,[ FLDDB. (.CMKEY,,^D10,<number of padding characters>)]
	PARSE				;PARSE IT
	SKIPT				;SUCCESS?
	ERROR	RETE,<?Not confirmed>
	SKIPE	S2			;IN RANGE?
	CAILE	S2,^D255		;
	ERROR	RETE,<?Not confirmed,must be in range of 1 to 255>
	CONFRM				;TERMINATE
	MOVEM	S2,PAD14		;AND SET PAD-PARAM FOR.
	RETT				;AND DONE RETURN

	PAGE
	SUBTTL	PAGE	COMMAND PROCESSING
;
;	PAGE-SIZE (lines per page) xxx (line width) yyyy
;
CMDPAG:	NOISE	(lines per page)	;GIVE A HELP
	SKIPT				;SUCCESS?
	RET				;NO-FORGET IT
	MOVEI	S2,[ FLDDB.(.CMNUM,,^D10)]
	PARSE				;PARSE IT
	SKIPT				;SUCCESS?
	ERROR	RETE,<Not confirmed>
	CAILE	S2,255			;IN RANGE
	ERROR	RETE,<Page size must be in range of 1 to 255>
	MOVEM	S2,TTYPSZ		;AND SET IT
	NOISE	(line width)		;MORE HELP
	SKIPT				;SUCCESS
	RETT				;NO-FORGET IT
	MOVEI	S2,[ FLDDB.(.CMNUM,,^D10)]
	PARSE				;PARSE IT
	SKIPT				;SUCCESS?
	ERROR	RETE,<Not confirmed>
	SKIPE	S2			;IN RANGE
	CAILE	S2,255			;
	ERROR	RETE,<Line width must be in range of 1 to 255>
	MOVEM	S2,PAD10		;AND SET IT
	RETT				;ALL DONE, RETURN

	PAGE
	SUBTTL	PUSH COMMAND

;	PUSH COMMAND TO PUSH TO A NEW EXEC IN AN INFERIOR FORK

CMDPSH:	NOISE	(COMMAND LEVEL)		;DO GUIDEWORDS
	CONFRM				;CONFIRM THE COMMAND
	HRROI	S2,[ASCIZ/SYSTEM:EXEC.EXE/] 	;FILENAME FOR EXEC
	MOVX	S1,GJ%PHY!GJ%OLD!GJ%SHT		;GTJFN BITS
	GTJFN				;GET A HANDLE ON THE FILE
	 ERRJMP	CMDPSE,<?Can't push exec >
	MOVEM	S1,CMDJFX			;SAVE JFN TO IT
	MOVX	S1,CR%CAP		;PRESERVE OUR CAPABILITIES
	CFORK				;BUILD A FORK
	 ERRJMP	CMDPSE,<?Cant create subfork >
	MOVEM	S1,CMDFRK		;SAVE FORK HANDLE
	MOVSS	S1			;HANDLE TO LEFT HALF
	HRR	S1,CMDJFX		;JFN TO RIGHT
	GET				;GET THE FILE
	 ERRJMP	CMDPSE,<?Can't get SYSTEM:EXEC.EXE >
	MOVE	S1,CMDFRK		;FETCH FORK HANDLE
	SETZ	S2,			;NORMAL START
	SFRKV				;START THE FORK UP
	 ERRJMP	CMDPSE,<?Can't start subfork going >
	WFORK				;WAIT FOR IT TO COME BACK
	 ERRJMP	CMDPSE,<?WFORK failed >
	KFORK				;IS DONE, SO KILL IT
	 ERRJMP	CMDPSE,<?KFORK failed to kill fork>
	SETZM	CMDFRK			;NO MORE FORK
	RET				; AND COMMAND IS FINISHED

CMDPSE:	RET				;ALL ERRORS COMMING HERE

	PAGE
	SUBTTL	X25NET	NETWORK ACCESS SUBROUTINES
;
;	OPEN NETWORK
;
NETOPN:	TMSX	< Calling DTE Number >
	HRROI	S1,DTENBR		;WHERE DTE # IS STORED
	PSOUT				;AND TELL USER
	TMSX	<(>			;START SUBBADDRESS
	SKIPN	DTESNR			;SUBADDRESS SPECIFIED?
	JRST	[ HRROI	S1,[ASCIZ/0/]	;NO-GIVE ONE
		  JRST .+2 ]		;
	HRROI	S1,DTESNR		;GET SUBADDRESS
	PSOUT
	TMSX	<)>			;AND TERMINATE IT
	TMSX	< at Network >		;AND TELL HIM
	SKIPN	NETNAM			;NETWORK NAME GIVEN?
	ERROR	RETE,<
?No NETWORK name specified>
	HRROI	S1,NETNAM		;THE NETWORK NAME TO
	PSOUT				;
					;
	HRLZI	T1,CH%X25		;INTERRUPT CHANNEL
	HRRI	T1,PORTBLK		;AND THE PORT-BLOCK
	MOVEM	T1,MRGBLK		;SET IT UP
	SETZM	MRGBLK+1		;INIT THIS
	MOVE	T1,[POINT 7,NETNAM ]	;
	MOVEM	T1,MRGBLK+2		;NAME OF NETWORK
	SKIPN	NETPSW			;PASSWORD SPECIFIED?
	JRST	[ SETZM	MRGBLK+3	;TRY WITH NO PASSWORD
		  JRST .+3 ]		;AND SKIP OVER
	MOVE	T1,[POINT 7,NETPSW ]	;
	MOVEM	T1,MRGBLK+3		;PASSWORD
	MOVE	T1,[POINT 7,DTENBR ]
	MOVEM	T1,MRGBLK+4		;DTE CALL NUMBER
	SKIPN	DTESNR			;SUB-DTE NUMBER GIVEN
	JRST	[ SETZM	T1		;NO-TRY WITHOUT IT
		  JRST .+2 ]		;SKIP OVER
	MOVE	T1,[POINT 7,DTESNR ]
	MOVEM	T1,MRGBLK+5		;DTE-SUB-NUMBER
	SETZM	MRGBLK+6		;USER GROUP NAME
	SETZM	MRGBLK+7		;FACILITIES
	HRLZI	T1,USRDSZ		;SIZE OF BUFFER
	HRRI	T1,USRDAT		;AND ITS ADDRESS
	MOVEM	T1,MRGBLK+10		;SET IT UP
	BIS	XP%OPN,PORTF		;ASSUME SUCCESS

	MOVEI	S1,MRGBLK		;SET UP BLOCK
	CALL	X%ISC##			;AND DO IT
	HRRZ	T1,MRGBLK		;GET PORT NUMBER
	MOVEM	T1,PORT			;AND SAVE IT
	MOVE	T1,MRGBLK+1		;GET RETURN CODE
	CAIE	T1,XC%SUC		;SUCCESS
	JRST	NETOP5			;NO-ERROR SEEN
	TMSX  <[OK]
>
	RETT				;ALL DONE HERE
					;
NETOP5:	TMSX	<[FAILED]
>
	CALL	NETEPR			;PRINT ERROR
	BIC	XP%OPN,PORTF		;NO OPEN PORT YET
	SETZM	PORTL			;NO DEFINED PORT STATUS YET
	SETZM	PORTS			;
	RETF				;RETURN ERROR

;
;	TERMINATE PORT ACCESS ROUTINE
;
NETTPA:	MOVE	S1,PORT			;GET OUR PORT IN USE
	MOVEM	S1,MRGBLK		;SET IT UP
	SETZM	MRGBLK+1		;CLEARE RET. STATUS
	MOVEI	S1,MRGBLK		;GET BLOCK ADDRESS
	CALL	X%TPA##			;AND CLEARE THE PORT
	MOVE	S1,MRGBLK+1		;GET RETURN CODE
	SKIPN	S1			;SUCCESS?
	RETT				;ALL DONE
	ERROR	RETE,<%Could not terminate port access because port was not allocated>

;
;	SEND INTERRUPT MESSAGE ROUTINE
;	USED BY THE TTY TASK TO GET TO REMOTE SERVER
;
NETSIM:	MOVE	T1,PORT			;GET PORT WE ARE ON
	MOVEM	T1,TRGBLK+0		;AND SET IT
	SETZM	TRGBLK+1		;NO RETURN CODE YET
	SETZM	TRGBLK+2		;NO INTERRUPT DATA
	MOVEI	S1,TRGBLK		;GET OUR ARG. BLOCK
	CALL	X%SIM##			;SEND IT OF
	HRRZ	T1,TRGBLK+1		;GET RETURN CODE
	CAIN	T1,XC%SUC		;SUCCESS?
	RETT				;YES-ALL DONE
	CALL	NETEPR			;TYPE OUT ERROR
	RETF				;AND ERROR RETURN

	PAGE
;
;	NETSND	ROUTINE TO SENT OUT A DATA BUFFER OVER THE
;	NETWORK
;	ENTER	T1<== BYTE POINTER TO DATA BUFFER
;		T2<== NUMBER OF DATA BYTES IN BUFFER
;
NETSND:	MOVEM	T1,TRGBLK+3		;SET BUFFER ADDRESS
	MOVEM	T2,TRGBLK+2		;SET #OF BYTES TO SEND
	ADDM	T2,POROCT		;UPDATE BYTE SENT CNT.
	AOS	POROBL			;AND PORT BLOCK SENT
	MOVE	T1,PORT			;GET OUR PORT #
	MOVEM	T1,TRGBLK		;AND SET IT
	SETZM	TRGBLK+1		;NO RETURN CODE YET
	MOVEI	S1,TRGBLK		;GET OUR TRGBLK
	SKIPN	TTYDEB			;SKIP IT IF DEBUG
	CALL	X%SDM##			;SEND IT OFF
	MOVE	T1,TRGBLK+1		;GET RETURN CODE
	CAIE	T1,XC%SUC		;SUCCESS
	RETF				;NO-TELL CALLER ABOUT
	RETT				;ALL DONE,RETURN

	PAGE
;
;	ROUTINE CHECK NEW PORT STATUS
;	NOTE:	ALSO CALLED AT INTR. LEVEL WITH S1 TO T4 SAVED
;	        SETS PORTE ERROR FLAG IF ANY ERROR OCCURED
;		SUCH AS ILLEGAL STATE TRANSITION OR ERROR
;		RETURNED FROM X%RPS CALL.
;
NETSTU:	MOVE	T1,PORT			;GET OUR PORT
	MOVEM	T1,IRGBLK		;SET IT UP
	SETZM	IRGBLK+1		;NO CODE YET
	MOVEI	S1,IRGBLK		;GET OUR ARG-BLK
	CALL	X%RPS##			;GO GET STATUS
	MOVE	T1,IRGBLK+1		;GET RET. CODE
	CAIE	T1,XC%SUC		;DONE WITH
	SETOM	PORTE			;NO-SAY ERROR AT INT. LEVEL
	MOVE	T1,PORTS		;GET LAST STATUS SEEN SO FAR
	DMOVE	T1,IRGBLK+2		;GET PORT STATE
	DMOVEM	T1,PORTS		;AND INTR. MASK
					;
	HRRZ	T1,PORTS		;GET NEW STATUS
	MOVE	T2,PORTL		;GET LAST PORT STATE
	IMULI	T2,^D12			;FIND RIGHT ENTRY
	ADD	T2,T1			;INTO PORT TABLE
	CALL	@NETSTB(T2)		;CALL APPROPIATE ROUTINE
	SKIPF				; ANY ERROR SEEN
	RETT				;NO-GO DISMISS INTERRUPT
	SETOM	PORTE			;YES-FLAG ERROR AT INTERRUPT
	RETF

	PAGE
	SUBTTL	X25ERR NETWORK ERROR ROUTINES
;
;	NETWORK STATUS PRINTOUT ROUTINE
;
NETPRS:	TMSX	< Port in use Port # >
	DOUT	PORT				;OUTPUT PORT NUMBER
	TMSX	<
 Port state transition from >
	HRRZ	S1,PORTL			;GET PREVIOUS STATE
	MOVE	S1,NETSTT(S1)			;TRANSLATION
	PSOUT
	TMSX	<(>
	HRRZ	S1,PORTL			;FOR NICE OUTPUT
	DOUT	S1				;OUTPUT DECIMAL STATE TOO
	TMSX	<) TO >
	HRRZ	S1,PORTS			;GET NEW STATE
	MOVE	S1,NETSTT(S1)			;AND TRANSLATION
	PSOUT
	TMSX	<(>
	HRRZ	S1,PORTS			;FOR NICE OUTPUT TOO
	DOUT	S1
	TMSX	<)
 Port error status >
	HLRZ	S1,PORTS			;GET ERROR BIT
	OOUT	S1				;AND OUTPUT IT TOO
	TMSX	<
>
	ERRT20					;PRINT ALSO LAST T20 ERROR
	RET					;ALL DONE HERE

	PAGE

;
;	ROUTINE TO PRINT ERROR EXPLANATION
;	ENTER T1<== ERROR CODE (0,,ERROR BIT'S)
;
NETEPR:	JFFO	T1,.+1			;CONVERT ERROR CODE
	SUBI	T2,^D18			;
	MOVE	S1,NETETB(T2)		;GET ADDRESS OF
	SKIPL	S1			;FOUND ERROR CODE?
	HRROI	S1,[ASCIZ/%No Error explanation available for this error code
/]
	PSOUT
	RET
;
;
;
NETETB:	-1,,[ASCIZ/%Successful
/]
	-1,,[ASCIZ/%PSI Gateway software are not compatible,Version skrew
/]
	-1,,[ASCIZ/%Buffer too short
/]
	-1,,[ASCIZ/%Buffer too long
/]
	-1,,[ASCIZ/%Source DTE Subaddress too long
/]
	-1,,[ASCIZ/%Destignation DTE address to loong
/]
	-1,,[ASCIZ/%No interrupt confirmation required
/]
	-1,,[ASCIZ/%Awaiting interrupt confirmation
/]
	-1,,[ASCIZ/%No DTE address specified, or no destignation
/]
	-1,,[ASCIZ/%No Password or Password not valied
/]
	-1,,[ASCIZ/%Data-field truncation,field was to loong
/]
	-1,,[ASCIZ/%Facilities data field truncated
/]
	-1,,[ASCIZ/%Unknown Network name specified
/]
	-1,,[ASCIZ/%No interrupt to read
/]
	-1,,[ASCIZ/%No data to read
/]
	-1,,[ASCIZ/%X25 Port failed, procedure error
/]
	-1,,[ASCIZ/%No more circuit available
/]
	-1,,[ASCIZ/%Insufficient gateway recources
/]

	PAGE
;
;	PORT STATE TRANSLATION TABLE
;
NETSTT:	-1,,[ASCIZ/Undefined/]
	-1,,[ASCIZ/Opening/]
	-1,,[ASCIZ/Calling/]
	-1,,[ASCIZ/Listening/]
	-1,,[ASCIZ/Called/]
	-1,,[ASCIZ/Running/]
	-1,,[ASCIZ/Synchronizing/]
	-1,,[ASCIZ/Unsynchronized/]
	-1,,[ASCIZ/Clearing/]
	-1,,[ASCIZ/Cleared/]
	-1,,[ASCIZ/Error/]
	-1,,[ASCIZ/No communication/]

	PAGE
	SUBTTL	X25STT	NETWORK STATE TRANSITION TABLE

;
;	MACRO TO DEFINE STATE TRANSITION TABLE
;
	DEFINE S ( $LBX,%LBL ) <
	XLIST
	IFG ZZZZ , < SS(^D11,$NTUDF) >
	ZZ==0
	ZZZZ==ZZZZ+1
%LBL:
	LIST
>
	DEFINE SS( X,Y ) <
	XLIST
	ZZZ=X-ZZ
	REPEAT ZZZ , < EXP $NTUDF >
		EXP	Y
	ZZ=X+1
	LIST
>
	DEFINE STATE ( XX )<
	XLIST
	MOVEI	S1,XX
	MOVEM	S1,PORTL
	LIST
>

	ZZ==0
	ZZZZ==0

NETSTB:				;DEFINE STATE TRANSITTION TABLE HERE

	S ( $UND )				;UDEFINED STATE
	SS (XS%UND,$NTNSC)
	SS (XS%CAG,$NT02)
	SS (XS%RUN,$NT05)
	SS (XS%ERR,$NTERR)
	S ( $OPN )				;OPEN
	S ( $CAG )				;CALLING
	SS (XS%CAG,$NTNSC)
	SS (XS%RUN,$NT25)
	SS (XS%CLD,$NT29)
	SS (XS%ERR,$NTERR)
	S ( $LSN )				;LISTENING
	SS (XS%LSN,$NTNSC)
	SS (XS%ERR,$NTERR)
	S ( $CAD )				;CALLED
	SS (XS%CAD,$NTNSC)
	SS (XS%ERR,$NTERR)
	S ( $RUN )				;RUNNING
	SS (XS%RUN,$NTNSC)
	SS (XS%SYN,$NT56)
	SS (XS%UNS,$NT57)
	SS (XS%CLG,$NT58)
	SS (XS%CLD,$NT59)
	SS (XS%ERR,$NTERR)
	S ( $SYN )				;SYNCHRONIZING
	SS (XS%RUN,$NT65)
	SS (XS%SYN,$NTNSC)
	SS (XS%CLG,$NT68)
	SS (XS%CLD,$NT69)
	SS (XS%ERR,$NTERR)
	S ( $UNS )				;UNSYNCHRONIZED
	SS (XS%RUN,$NT75)
	SS (XS%UNS,$NTNSC)
	SS (XS%CLG,$NT78)
	SS (XS%CLD,$NT79)
	SS (XS%ERR,$NTERR)
	S ( $CLG )				;CLEARING
	SS (XS%CLG,$NTNSC)
	SS (XS%ERR,$NTERR)
	S ( $CLD )				;CLEARED
	SS (XS%CAG,$NT92)
	SS (XS%CLD,$NTNSC)
	SS (XS%ERR,$NTERR)
	S ( $ERR )				;ERROR
	S ( $NCM )				;NO COMMUNICATION
	SS (^D11,$NTUDF)

	PAGE
	SUBTTL	X25STR	NETWORK STATE TRANSITION ROUTINES
;
;
;*******************************************************************
;	HERE AT INTERRUPT LEVEL 1 WITH REGISTERS SAVES
;	S1 TO T4. ANY OTHER USED REGISTER MUST BE SAVED
;*******************************************************************
;
;	HERE IF PORT STATUS HAS NOT CHNAGED
;
$NTNSC:
	SKIPE	TRACE
	ERRNET	,<%Port interrupted but Port status has not changed>
	RETT
;
;	HERE IF PORT CHANGED INTO AN ILLEGAL STATE
;
$NTUDF:	ERRNET	,<?Port status changed into a not defined state>
	STATE	XS%NCM
	RETF
;
;	HERE IF PORT CHANGES FROM ANY STATE INTO ERROR
;
$NTERR:	ERRNET	,<?Port status changed into error state>
	STATE	XS%ERR
	RETF
;
;
;	HERE IF PORT CHANGED FROM UNDEFINED INTO CALLING
;
$NT02:	TMSX	< [Calling]...>
	STATE	XS%CAG
	RETT
;
;	HERE IF PORT STATE CHANGED FROM CALLING TO RUNNING,
;	OR DIRECTLY INTO RUNNING, ( MAY BE WE ARE TO SLOW)
;	REMOTE PARTNER ACCEPTED OUR CALL
;
$NT05:
$NT25:	TMSX	<...[Running]
%X29 Communication established
>
	STATE	XS%RUN
	RETT
;
;	HERE IF PORT STATE CHANGED FROM CALLING TO CLEARED
;	REMOTE SITE ABORTED THIS CALL
;
$NT29:	TMSX	<...[Failed]
%Remote partner refused connection
>
	STATE	XS%CLD
	RETF
;
;	RESET VIRTUAL CIRUIT NOT YET CONFIRMED
;
$NT56:
	SKIPE	TRACE
	ERRNET	,<%Port status changed, waiting for PPSN to confirm RVC request>
	STATE	XS%SYN
	RETT
;
;	PPSN NEEDS TO HAVE A RESET VIRTUAL CIRCUIT FROM US
;
$NT57:
	SKIPE	TRACE
	ERRNET	,<Port status changed, PPSN requests RVC operation>
	STATE	XS%UNS
;	CALL	NETRVC				;RESET VIRTUAL CIRCUIT
	RETT

;
;	CLEARE SWITCHED CIRCUIT IN PROGRESS
;
$NT58:
	SKIPE	TRACE
	ERRNET	,<Port status changed, CSC operation in progress>
	STATE	XS%CLG
	RETT

;
;	PPSN HAS CLEARED CIRCUIT AND LOCAL DTE CONFIRMED IT
;
$NT59:
	ERRNET	,<%Port status changed,Link disconnected by remote site>
	STATE	XS%CLD
	RETF
;
;	PREVIOUS REQUEST FOR RESET VIRTUAL CIRCUIT IS CONFIRMED BY PPSN
;
$NT65:
	SKIPE	TRACE
	ERRNET	,<%Port status changed, PPSN confirmed previous RVC operation>
	STATE	XS%RUN
	RETT

;
;	CLEARE SWITCH CIRCUIT IN PROGRESS
;
$NT68:
	SKIPE	TRACE
	ERRNET	,<Port status changed, CSC operation in progress>
	STATE	XS%CLG
	RETT

;
;	PPSN CLEARED THE CIRCUIT AND LOCAL DTE CONFIRMED IT
;
$NT69:
	SKIPE	TRACE
	ERRNET	,<%Port status changed, PPSN reset ack. by RVC in progress>
	STATE	XS%CLD
	RETT
;
;	PRIVIOUS RESET RQ. FROM PPSN HAS BEEN ACK BY A RESET VIRTUAL CIRC.
;
$NT75:
	SKIPE	TRACE
	ERRNET	,<%Port status changed,PPSN reset rq. are confirmed by RVC operation>
	STATE	XS%RUN
	RETT
;
;	CLEARE SWITCHED CIRCUIT IN PROGRESS
;
$NT78:
	SKIPE	TRACE
	ERRNET	,<%Port status changed, PPSN has cleared circuit, PSI confirm in progress>
	STATE	XS%CLG
	RETT
;
;	PPSN HAS CLEARED CIRCUIT AND LOCAL DTE CONFIRMS THE CLEARE
;
$NT79:
	SKIPE	TRACE
	ERRNET	,<%Port status changed,PPSN cleared circuit and PSI confirm in progress>
	STATE	XS%CLD
	RETT
;
;	HERE IF PORT STATE CHANGED FROM CLEARED TO CALLING
;	RESTARTING AN CLEARED PORT
$NT92:	SKIPE	TRACE
	ERRNET	,<%Port status changed from cleared to calling>
	STATE	XS%CLD
	RETT


	PAGE
	SUBTTL	X25INT	GENERAL NETWORK INTERRUPT ENTRY
;
;	NETINT	GOT DATA AVAILABLE FROM NETWORK HERE
;
NETINT:	SAVCH1				;SAVE AWAY AC'S WE NEED
	CALL	NETSTU			;GET PORT STATUS
	SKIPT				;ANY ERROR SEEN?
	RET				;YES-DISMISS,ERRORS WILL BE PROCESSED
					;IN MAIN LINE CODE
	MOVE	T4,PORTM		;GET PORT I/D MASK
	TLNN	T4,XM%MSK		;ANYTHING TO DO HERE
	RET				;NO-JUST RETURN,DUMMY INTERRUPT
	TLNE	T4,XM%IIP		;INCOMMING INTERRUPT?
	CALL	NETIIP			;YES-GO PROCESS IT
	TLNE	T4,XM%OIP		;WAITING FOR INTER. CONFIRMATION?
	CALL	NETOIP			;YES-GO PROCESS IT.
	TLNE	T4,XM%IDA		;INCOMMING DATA AVAILABLE?
	CALL	NETIDA			;YES-GO PROCESS IT
	TLNE	T4,XM%IIA		;INCOMMING INTERRUPT DATA AVAILABLE?
	CALL	NETIIA			;YES-GO PROCESS IT
	SKIPT				;ANY ERROR SEEN?
	SETOM	PORTE			;YES-TELL THE WORLD ABOUT
	RET				;AND ALL DONE

	PAGE
	SUBTTL	X25INT	NETWORK INTERRUPT PROCESSING ROUTINES
;
;	HERE IF INCOMMING INTERRUPT NEEDS TO BE CONFIRMED
;	WILL BE DONE AUTOMATICALY ON THE NEXY READ DATA
;
NETIIP:	RET
;
;	HERE IF OUTGOING INTERRUPT HAS BEEN TRANSMITTED BUT NOT
;	CONFIRMED YET.
;
NETOIP:
	SKIPE	TRACE
	TMSG <%Port mask data:Outgoing interrupt confirm pending>
	RET

	PAGE
;
;	HERE IF INCOMMING DATA IS AVAILABLE TO READ
;
NETIDA:	MOVE	T1,PORTF		;GET OUR PORT FLAGS
	TXNE	T1,XP%RAD		;READ ACCEPT DATA ALREADY DONE
	JRST	NETID0			;YES-MUST BE DATA MESSAGE THEN
;
;	HERE AFTER INITIALIZATION CIRCUIT HAS BEEN DONE,
;	READ ACCEPT DATA RETURND FROM CONNECT ACCEPT ON REMOTE
;
	MOVE	T1,PORT			;GET OUR PORT WE ARE ON
	MOVEM	T1,IRGBLK		;AND SET IT
	SETZM	IRGBLK+1		;CLEARE RETURN CODE
	MOVE	T1,[POINT 7,REMCUG ]	;WHERE TO STORE REMOTE C.USR. GROUP
	MOVEM	T1,IRGBLK+2		;SET IT UP
	HRLZI	T1,REMFAZ		;SIZE OF REMOTE FAC. BUFFER
	HRRI	T1,REMBFR		;AND THE BUFFER
	MOVEM	T1,IRGBLK+3		;
	HRRZ	T1,PORTM		;GET BUFFER SIZE
	HRRI	T1,REMBFR		;AND THE BUFFER
	MOVEM	T1,IRGBLK+4		;
	MOVEI	S1,IRGBLK		;SET BLOCK TO USE
	CALL	X%RAD##			;READ ACCEPT DATA
	HRRZ	T1,IRGBLK+1		;GET RETURN CODE
	TXZ	T1,XS%NDA		;IGNORE NO DATA AVAILABLE
	CAIE	T1,XC%SUC		;SUCCESSFULL?
	JRST	[ CALL	NETEPR		;NO-PRINT ERROR EXPLANTATION
		  RETF	]		;AND ERROR RET.
	BIS	XP%RAD,PORTF		;YES-FLAG RAD DONE
	MOVE	T2,IRGBLK+2		;GET FLAGS,,DATA SIZE
	HRRZ	T3,T2			;AND DATA SIZE FOR ACCOUNTING
	AOS	PORIBL			;COUNT FOR ONE BLOCK
	ADDM	T3,PORICT		;AND NUMBER OF BYTES RECEIVED
	TXNE	T2,XS%QDA		;QUALIFIED?
	CALL	NETQDI			;YES-PROCESS IT
	HRRZ	T1,IRGBLK+1		;GET FLAGS AGAIN
	TXNE	T1,XS%NDA		;NO MORE DATA?
	RETT				;YES-ALL DONE HERE
					;NO-FALL INTO NETID0 TO READ
					;REAST OF DATA
;
;	HERE TO READ NORMAL DATA MESSAGES
;
NETID0:	MOVE	T1,PORT			;GET PORT WE ARE ON
	MOVEM	T1,IRGBLK		;AND SET IT
	SETZM	IRGBLK+1		;CLEARE OUT RETURN CODE
	MOVEI	T1,REMBFZ		;SIZE OF BUFFER
	MOVEM	T1,IRGBLK+2		;AND SET IT UP
	MOVE	T1,[POINT 8,REMBFR ]	;DATA BUFFER TO USE
	MOVEM	T1,IRGBLK+3		;SET IT UP
	MOVEI	S1,IRGBLK		;SET UP IRGBLK TO USE
	PUSH	P,0
	CALL	X%RDM##			;READ DATA MESSAGE
	POP	P,0
					;
	HRRZ	T1,IRGBLK+1		;GET RETURN CODE
	TXZ	T1,XS%NDA		;IGNORE THIS
	CAIE	T1,XC%SUC		;SUCCESFULL?
	JRST	[ CALL NETEPR		;PRINT ERROR CODE
		  RETF    ]		;TELL THE WORLD ERROR SEEN
	HRRZ	T1,IRGBLK+1		;GET RETURN CODE AGAIN
	TXNE	T1,XS%NDA		;NO MORE DATA AVAILABLE
	RET				;YES-ALL DONE HERE
	MOVE	T2,IRGBLK+2		;GET FLAGS,,SIZE OF DATA
	HRRZ	T3,T2			;AND DATA SIZE FOR ACCOUNTING
	AOS	PORIBL			;COUNT FOR ONE BLOCK
	ADDM	T3,PORICT		;AND NUMBER OF BYTES RECEIVED
	TXNE	T2,XS%QDA		;QUALIFIED DATA?
	JRST	[ CALL	NETQDI		;YES-PROCESS IT
		  JRST NETID0 ]		;AND RETURN
	HRRZ	T1,IRGBLK+2		;GET NUMBER OF BYTES WE GOT
	SKIPE	TRACE
	TMSG	<%NET	Network normal data message received>
	CALL	TTYNOU			;AND SEND IT OUT
	JRST	NETID0			;GO PROCESS THEM ALL

	PAGE
	SUBTTL	X25INT	QUALIFIED (CONTROL) DATA PROCESSING ROUTINES
;
;	HERE TO PROCESS PAD CONTROL MESSAGES
;
NETQDI:	MOVE	T4,[ POINT 8,REMBFR]	;GET BUFFER
	ILDB	T1,T4			;GET CONTROL BYTE
	TRZE	T1,360			;PAD CONTROL MESSAGE?
	JFCL				;NO-PROCEED ANYWAY
	JRST	@PADMST(T1)		;AND GO PROCESS IT
;
PADMST:	EXP	NETPIP			;PARAMETER INDICATION PAD MESSAGE
	EXP	NETICP			;INVITATION TO CLEAR PAD MESSAGE
	EXP	NETSPM			;SET PAD MESSAGE
	EXP	NETIBP			;INDICATION OF BREAK PAD
	EXP	NETRPM			;READ PAD MESSAGE
	EXP	NETEPM			;ERROR PAD MESSAGE
	EXP	NETSRP			;SET AND READ PAD MESSAGE
	EXP	NETUDF			;**UNDEFINED CODE**

NETUDF:	SKIPE	TRACE
	TMSG	<%NET	Undefined Control message received,message ignored>
	RET				;AND RETURN

	PAGE
;
;	PAD CONRTOL PROCESSING ROUTINES
;
NETPIP:	SKIPE	TRACE
	TMSG	<%NET	Parameter indicating PAD Message received>
	RET
;
;	HERE IF REMOTE REQUEST US TO CLEARE SWITCHED CIRCUIT,
;
NETICP:	SKIPE	TRACE
	TMSG	<%NET	Invitation to clear PAD message received>
	MOVE	T1,PORT			;GET PORT WE ARE ON
	MOVEM	T1,IRGBLK+0		;AND SET IT
	SETZM	IRGBLK+1		;NO RETURN CODE YET
	SETZM	IRGBLK+2		;NO CLEARE REASON
	SETZM	IRGBLK+3		;NO USER GROUP
	SETZM	IRGBLK+4		;NO FACILITIES
	SETZM	IRGBLK+5		;NO CLEARE DATA
					;
	MOVEI	S1,IRGBLK		;GET ADDRESS OF IRGBLK
	CALL	X%CSC##			;AND CLEARE SWITCHED CIRCUIT
	HRRZ	T1,IRGBLK+1		;GET RETURN CODE
	CAIN	T1,XC%SUC		;SUCCESSFULL?
	RET				;YES-ALL DONE
	CALL	NETEPR			;DO ERROR PRINT OUT
	SETOM	PORTE			;AND TELL THE WORLD ERROR
	RET
;
;	REMOTE COMMES HERE TO SET OUR PAD PARAMETERS
;
NETSPM:	HRRZ	T3,IRGBLK+2		;GET #OF BYTES WE GOT
	SOS	T3			;THE ONE WE HAVE ALREADY
NETSP1:	ILDB	T1,T4			;GET PARAM #
	ILDB	T2,T4			;AND PARAM VALUE
	ANDI	T2,177			;LIMIT IT TO SEVEN BIT
	ANDI	T1,177			;THIS ONE TOO
	SKIPE	TRACE
	CALL	NETSP3			;TRACE MESSAGE IF NEEDED
	CAILE	T1,PADMAX		;LEGAL PARAMETER
	JRST	NETSP2			;NO-FORGET ABOUT
	MOVEM	T2,PADPRM(T1)		;YES-SET IT
NETSP2:	SOJG	T3,NETSP1		;LOOP FOR ALL DONE
	RET
;
NETSP3:	TMSX	<%NET	Set PAD Parameter msg received >
	DOUT	T1
	TMSX	<:>
	DOUT	T2
	TMSG	< >
	RET

	PAGE
;
;	HERE ON INDICATION OF PAD BREAK RECEIVED
;
NETIBP:	SKIPE	TRACE
	TMSG	<%NET	Indication of break PAD message received>
	RET

;	HERE ON READ PAD PARAMETER MESSAGE
;
NETRPM:	SKIPE	TRACE
	TMSG	<%NET	Read PAD parameter message received>
	RET
;
;	HERE IF REMOTE SEND US AN ERROR MESSAGE
;	TYPE IT OUT AND CONTINUE
;
NETEPM:	ILDB	T1,T4			;GET ERROR TYPE BYTE
	ILDB	T2,T4			;AND INVALID MESSAGE CODE
	ANDI	T1,3			;CLEARE UNUSED CODE
	MOVE	S1,NETEPT(T1)		;GET MESSAGE
	PSOUT				;AND OUTPUT IT
	TMSX	< CODE: >
	DOUT	T2			;OUTPUT CODE TOO
	TMSX	<
>
	RET				;ALL DONE-RETURN
;
;	PAD ERROR MESSAGE TABLE
;
NETEPT:	-1,,[ASCIZ/
?Received PAD message contained less then eight bits/]
	-1,,[ASCIZ/
?Unrecognozed message code in received PAD message/]
	-1,,[ASCIZ/
?Parameter field of received PAD message was incorrect/]
	-1,,[ASCIZ/
?Received PAD message did not have an integral number of octes/]

NETSRP:	RET

	PAGE
;
;	HERE IF INCOMMING INTERRUPT DATA IS AVAILABLE TO BE
;	PROCESSED.
;
NETIIA:
	SKIPE	TRACE
	TMSG <%Port mask data:Incomming interrupt data available>
	RET

	PAGE
	SUBTTL	TTYXXX	GENERAL TERMINAL ROUTINES OPEN,CLOSE,ECT.

;
;	TTYNOU	NETWORK TO TERMINAL OUTPUT ROUTINE
;		CALLED WITH T1 NUMBER OF CHARACTERS TO OUTPUT.
;		THIS ROUTINE OUTPUTS CHARACTER BY CHARACTER
;		FROM NETWORK RECEIVER BUFFER TO THE TERMINAL.
;		DEPENDING ON THE TERMINAL LINE WIDTH AN AUTO-
;		CR-LF IS INSERTED.
;		IF PAGE MODE ENABLED, PWAIT WILL BE CALLED TO
;		STOP OUTPUT TO THE TERMINAL UNTIL ^Q REENABLES
;		OUTPUT TO THE TERMINAL.
;
TTYNOU:	MOVE	S1,[ .PRIOU]		;OUTPUT DESIGNATOR
	MOVE	T2,[ POINT 8,REMBFR ]	;AND INPUT POINTER
	MOVE	T3,TTYPSZ		;PAGE SIZE
	MOVE	T4,PAD10		;AND LINE WIDTH
	SKIPGE	T1			;MAY BE NEGATIVE TOO
	MOVNS	T1			;SO MAKE IT A POS. NUMBER
	SKIPN	T1			;ANYTHING IN BUFFER?
	RET				;NO-JUST RETURN
					;
TTYOU1:	ILDB	S2,T2			;GET A BYTE
	ANDI	S2,177			;ONLY 7 BITS WE WANT
	BOUT				;AND SENT IT OFF
	SKIPN	TTYFLD			;LINE FOLDING ENABLED?
	JRST	TTYOU2			;NO-JUMP OVER
	AOS	TTYHCT			;COUNT HORIZONTAL
	CAIN	S2,15			;-CR-
	SETZM	TTYHCT			;YES-RESET HORIZONTAL
	CAMGE	T4,TTYHCT		;TIME FOR AUTO-CR-LF?
	JRST	[ PUSH	P,S2		;YES-DO SO
		  MOVEI	S2,15		;GET A CR
		  BOUT			;AND SENT IT OUT
		  MOVEI	S2,12		;AND A LF TOO
		  BOUT			;AND SENT IT
		  SETZM	TTYHCT		;SET TO NEW LINE
		  POP	P,S2		;GET BACK SAVED CHARACTER
		  JRST	.+1 ]		;RETURN TO MAIN-LINE CODE
TTYOU2:	SKIPN	TTYPMO			;PAGE MODE ENABLED?
	JRST	TTYOU3			;NO-JUMP OVER
	CAIN	S2,12			;-LF-?
	AOS	TTYLCT			;YES-COUNT IT
	CAMG	T3,TTYLCT		;TIME TO STOP OUTPUT?
	CALL	PWAIT			;YES-DO SO
					;
TTYOU3:	SOJG	T1,TTYOU1		;LOOP UNTIL ALL DONE
	RET				;AND RETURN
;
;	ROUTINE TO SET TERMINAL MODE TO: NO ECHO
;					 BINARY DATA MODE
;					BYPASS CTRL-C PROCESSING
;
TTYSEM:	MOVE	S1,[ .PRIIN ]		;FOR OUR TERMINAL
	RFMOD				;READ ITS MODE
	MOVEM	S2,TTYSFM		;SAVE THIS MODE
	TXO	S2,TT%WAK		;WAKE ON ALL
	TXZ	S2,TT%ECO!TT%DAM	;NO ECHO AND BINARY
	TXZ	S2,TT%PGM		;AND TURN OFF PAGE MODE
	SFMOD				;SET NEW MODE
	STPAR				;AND ALSO HERE
	MOVE	S1,[ .FHSLF ]		;GET OUR FORK
	RPCAP				;CAPABILITIES
	TXO	T1,SC%CTC		;ALLOW ^C TRAPPING
	EPCAP				;SET NEW CAPABILITIES
	MOVE	S1,[ .FHJOB ]		;SET TTY INT. MASK FOR WHOLE JOB
	MOVE	S2,TTYMSK		;GET MASK OF INTERRUPTS
	STIW				;AND SET IT
	RET				;ALL DONE,RETURN

;
;	ROUTINE TO RESET TERMINAL DATA MODE
;	ECHO AND CONTR-C PROCESSING
;
TTYREM:	MOVE	S1,[ .PRIOU ]		;GET OUR TRMINAL
	MOVE	S2,TTYSFM		;GET BACK OLD MODE
	SFMOD				;SET IT
	STPAR				;AND ALSO HERE
	MOVE	S1,[ .FHJOB]		;FOR WHOLE JOB
	SETOM	S2			;ANABLE THEM ALL
	STIW				;ANY CHARACTER
	RET				;ALL DONE. RETURN

	PAGE
	SUBTTL	TTYFRK	TTY FORK INITIALIZATION,CONTROL AND TERMINATION ROUTINES
;
;	INITIALIZE TTY-FORK HERE
;
TTYINI:	MOVE	S1,[ CR%MAP ]		;SAME MAP
	SETZM	S2			;
	CFORK				;CREATE THIS FORK
	ERR	EXIT,<?Cant create fork for TTY read in>
	MOVEM	S1,TTYFRK		;SAVE OUR FORK HANDLE
	MOVE	S1,[ .PRIOU ]		;OUR TERMINAL
	GTTYP				;GET IT'S TYPE
	SETOM	T2			;ASSUME NO TYPE FOUND YET
	CAIG	S2,.TTIDL		;ANY KIND OF HARDCOPY
	JRST	[ MOVEI	T2,.TTYHC	;YES-SAY HARDCOPY THEN
		  MOVEI	T1,^D 66	;PAGE SIZE
		  MOVEI	T3,^D 72	;LINE WIDTH
		  JRST .+1 ]		;ALL SET NOW
	CAIN	S2,.TTV52		;OR A VT52
	JRST	[ MOVEI	T2,.TTY52	;YES-SAY SO
		  MOVEI	T1,^D 24	;PAGE SIZE
		  MOVEI	T3,^D 80	;LINE WIDTH
		  JRST .+1 ]		;ALL SET HERE
	CAIN	S2,.TT100		;OR A VT100
	JRST	[ MOVEI	T2,.TTYXX	;YES-SAY SO
		  MOVEI	T1,^D 24	;PAGE SIZE
		  MOVEI	T3,^D 80	;LINE WIDTH
		  JRST .+1 ]		;ALL SET HERE
	SKIPGE	T2			;FOUND TYPE OF TTY
	JRST	[ MOVEI	T2,.TTYHC	;NO-SET TO HARDCOPY
		  MOVEI	T1,^D 66	;PAGE SIZE
		  MOVEI	T3,^D 72	;LINE WIDTH
		  JRST .+1 ]		;ALL SET HERE
	MOVEM	T2,TTYTYP		;AND SET UP OUR TYPE
	MOVEM	T1,TTYPSZ		;SET PAGE SIZE
	MOVEM	T3,PAD10		;AND LINE WIDTH
					;
	CAIN	T2,.TTYHC		;ANY KIND OF HARD COPY?
	JRST	[ MOVEI	T1,3		;YES-GET FILLER
		  MOVEM	T1,PAD9		;AND SET IT
		  MOVEM	T1,PAD14	;ALSO FOR LF
		  SETOM	TTYPAD		;AND ENABLE PADDING
		  JRST	TTYII2 ]	;AND DONE HERE
	SETZM	PAD9			;NO FILLER FOR DISPLAY
	SETZM	PAD14			;ALSO NOT FOR LF
	SETZM	TTYPAD			;AND TURN OFF PADDING
TTYII2:	MOVEI	T1,1			;GET LOCAL ECHO FLAG
	MOVEM	T1,PAD2			;FOR DEFAULT, TURN IT ON
	MOVEI	T1,4			;GET LF AFTER CR ON ECHO
	MOVEM	T1,PAD13		;FOR DEFAULT, TURN IT ON
	RET				;ALL DONE
;
;	START TTY-FORK GOING
;
TTYFGO:	MOVE	T1,TTYBRC		;GET BREAK CHARACTER
	MOVE	S1,[ 1B0 ]		;GET A HI. BIT
	MOVNS	T1			;GET LEFT SHIFT BITS
	LSH	S1,(T1)			;GET IT IN POSITION
	TXO	S1,1B<.TICTI>		;ALLOW INPUT IN GENERAL
	MOVEM	S1,TTYMSK		;AND SET INTERRUPT MASK
	MOVE	S1,TTYFRK		;GET HANDLE FOR
	MOVEI	S2,TTYINP		;WHERE TO START
	SKIPE	TTYDEB			;ALL DONE IF DEBUG
	RET				;
	SFORK				;AND START IT
	RFORK				;AND LET HIM RUN
	RET
;
;	FREZE	TTY FORK
;
TTYFRZ:	MOVE	S1,TTYFRK		;TTY FORK HANDLE
	FFORK				;FREZE HIM
	RET				;AND RETURN
;
;	RESUME TTY FORK HERE
;
TTYRES:	MOVE	S1,TTYFRK		;TTY FORK HANDLE
	RFORK				;AND START HIM
	RET
;
;	KILL TTY TASK HERE
;
TTYKIL:	MOVE	S1,TTYFRK		;GET TTY FORK HANDLE
	KFORK				;KILL HIM
	SETZM	TTYFRK			;NO TTY FORK ANYMORE
	RET
;
;	TTYCHK	CHECK STATE OF TTY TASK AND RETURN FALSE IF
;		ANY TRUBLE.
;
TTYCHK:	MOVE	S1,TTYFRK		;GET TERMINAL TSK FORK HANDLE
	RFSTS				;GET TTY FORK STATUS
	TXNE	S1,RF%FRZ		;STILL RUNNING?
	RETF				;NO ERROR
	HLRZ	S2,S1			;GET STATUS
	CAIN	S2,.RFRUN		;FORK STILL RUNNING?
	  RETT				;YES
	CAIN	S2,.RFIO		;IN IO WAIT
	  RETT				;IS OK
	CAIN	S2,.RFSLP		;SLEEPING
	  RETT	
	CAIN	S2,.RFFPT		;FORCED TERMINATION?
	  RETT	
	RETF				;NO-MUST BE ERROR THEN

	PAGE

;
;	PWAIT	THIS CODE IS CALLED AT NETWORK INTERRUPT LEVEL
;		TO STOP OUTPUT TO THE TERMINAL ON PAGE WAIT.
;		PWAKE IS USED BY THE TTYFRK TO TAKE US OUT OF
;		THE WAIT STATE.
;		INTERRUPTS FROM NETWORK ARE DISABLED UNTIL WE
;		RETURN TO DISSMIS THIS INTERRUPT.
;
PWAIT:	PUSH	P,S1			;SAVE THIS ONE
	BIS	TY%PWT,TTYSTS		;SAY WAITING FOR PAGE ON
	MOVE	S1,[ POINT 7,[ BYTE (7)7 ]];GET A BELL
	PSOUT				;AND SEND IT OFF
PWAIT0:	MOVEI	S1,^D 300		; 300 MS WAIT TO CHECK
	DISMS				;CHR----
	MOVE	CX,TTYSTS		;GET TERMINAL STATUS
	TXNE	CX,TY%ERR!TY%BRK	;TERMINAL IN TRUBLE OR BREAK?
	JRST	PWAIT1			;YES-GO WAKE UP
	CALL	TTYCHK			;CHECK FOR OTHER PROBLEMS
	SKIPT				;ALL OK?
	JRST	PWAIT1			;NO-WAKE IT UP
	TXNE	CX,TY%PWT		;STILL WAITING FOR PAGE ON
	JRST	PWAIT0			;YES-GO WAIT SOME MORE
					;
PWAIT1:	SETZM	TTYLCT			;RESET LINE COUNTER
	PSOUT
	POP	P,S1			;GET IT BACK
	POPJ	P,			;RESUME MAIN FORK NETWORK INTERRUPT
					;EXECUTION.

	PAGE
	SUBTTL	TTYFRK	TERMINAL INPUT FORK
;
;	TTY READ INPUT FROM TERMINAL FORK
;
TTYINP:	SKIPN	TTYDEB			;IF DEBUG,NO TTYPDL NEEDED
	MOVE	P,TTYPDL		;GET A PDL FOR THIS TASK
	SETZM	TTYSTS			;NO ERROR STATUS YET
	UNLOCK	PORTO			;AND MAKE SURE LOCK IS FREE
	SKIPN	S1,PAD4			;GET IDLE TIMER
	JRST	TTYIN0			;ZERO MEANS NO TIMER TO SET
	IMULI	S1,^D50			;IM MS
	MOVEI	T1,TTYTMO		;AND DISPATCH ADDRESS
	MOVEM	T1,TMRDSP		;
	CALL	TMRGO			;AND START IT
					;
TTYIN0:	SETZM	Q3			;NO "MORE" FLAG YET
	MOVEI	Q2,TTYBFZ		;MAX INPUT WE HANDLE
	MOVE	Q1,[ POINT 7,TTYBUF]	;AND BUFFER
	MOVEM	Q1,TTYRDP		;SAVE AS NEW "READ-POINTER"
	SETZM	TTYRDC			;AND "READ-COUNTER"
TTYIN1:	MOVE	S1,[ .PRIIN ]		;PRIM. INPUT
	MOVEM	Q1,TTYQ1		;MAKE LAST PNTR VIS. FOR IDLE TIMER
	MOVEM	Q2,TTYQ2		;MAKE COUNT VISIEBLE FOR IDLE TIMER
	BIN				;GET A BYTE
	ANDI	S2,177			;NO PARITY,7 BIT ONLY
	CAMN	S2,TTYBRC		;BREAK LINE CHARACTER?
	JRST	TTYIN7			;YES-BREAK IT
	SKIPE	PAD2			;LOCAL ECHO ENABLED?
	CALL	TTYEHO			;YES-DO ECHOING IF NEEDED
	JRST	[ IDPB	S2,Q1		;PUT CHARACTER IN BUFFER
		  SOJLE	Q2,TTYIN2 	;JUMP IF NO MORE SPACE LEFT OVER
		  JRST .+1 ]		;CONTINUE
	CALL	TTYTRM			;CHECK FOR BREAK CHARACTER
	JRST	TTYIN1			;WASN'T A BREAK, GO ON
					;YES-SEND OUT BUFFER
TTYIN2:	MOVNS	Q2			;COMPUTE NUMBER OF
	ADDI	Q2,TTYBFZ		;BYTES IN BUFFER
	JUMPLE	Q2,TTYIN0		;IF NOTHING, JUST START OVER
;
;	WE HAVE SOME DATA READY, SEND IT OUT OVER THE NETWORK
;
	LOCK	PORTO			;LOCK PORT OUTPUT
	JRST	[ MOVEI	S1,^D500	;COULN'T GET IT,WAIT FOR
		  DISMS			;
		  JRST	.-1 ]		;AND TRY ONCE MORE
	MOVE	T1,TTYRDP		;GET BUFFER TO SENT
	MOVE	T2,Q2			;AND NUMBER OF DATA BYTES IN
	SUB	T2,TTYRDC		;EXCLUDE BYTES END ALREADY
	CALL	NETSND			;SEND OUT THIS BUFFER
	SKIPT				;SUCCESS?
	JRST	[ CALL	NETEPR		;NO-PRINT OUT ERROR
		  UNLOCK PORTO		;UNLOCK OUR PORT
		  SETOM	TTYSTS		;SAY PROBLEM IN TTY FORK
		  JRST	TTYIN8 ]	;STOP FORK,SO SUPERIOUR WILL SEE ERROR
	UNLOCK	PORTO			;UNLOCK OUR PORT
	JRST	TTYIN0 			;NO- GO FOR MORE INPUT
;
;	HERE IF LINE BREAK SEEN,STOP FORKF PAD7 SAYS SO
;
TTYIN7:	MOVE	T1,PAD7			;GET BREAK ACTION CODE
	CAIN	T1,1			;INTERRUPT?
	JRST	[ CALL	NETSIM		;YES-SEND IT OUT
		  SKIPF			;ERROR SEEN?
		  JRST  TTYIN0	 	;NO-CONTINUE TTY TASK
		  TMSG	<%Pls retype break after short wait time>
		  JRST	TTYIN0 ]	;AND CONTINUE TTY-FORK
	CAIN	T1,8			;BREAK LINK
	JFCL				;**BREAK ANYWAY
				;****DISCARD REMBUF,SEND INETRRUPT MSG.
				;****AND A INDICATION OF BREAK PAD-MESSAGE(Q)
	BIS	TY%BRK,TTYSTS		;FLAG BREAK
	JRST	TTYIN9			;AND LET SUPERIOUR PICK US UP

TTYIN8:	TMSX	<
? FATAL Error, X25 failed to send data to remote..breaking
>
	SETOM	TTYSTS			;TELL THE WORLD ERROR IN TTY TSK
	JRST	TTYIN9			;LET SUPERIOUR PICK IT UP

TTYIN9:	CALL	TMRSTP			;STOP IDLE TIMER
	TMSX	<
>
	SKIPE	TTYDEB			;DEBUG FLAG ON?
	RETT				;YES-JUST RETURN TO CMDLOP
	HALTF				;NO-STOP FORK,SUPERIOUR WILL PICK UP
	JRST TTYINP 			;FOR CONTINUE TTY TASK

	PAGE
	SUBTTL	TTYFRK	IDLE TIMER SUPPORT
;
;	IDLE TIMER SUPPORT,CHECK BUFFER AND SENT IT OFF IF NOT EMTY
;	NOTE:	TTYTMO RUNNS IN A DIFFERENT CONEXT THAN TTYTSK
;		SO REGISTES FROM TTYFRK WILL NOT BE SEEN HERE
;		THE OUTPUT OF TTYBUFF WILL BE FRAGMENTED BY THIS
;		ROUTINE AND DONE FROM TTYRDP TO TTYQ2, THE CURRENT
;		TTYBUF POINTER FOR WRITE IN.
;
TTYTMO:	MOVN	T2,TTYQ2		;COMPUTE NUMBER OF
	ADDI	T2,TTYBFZ		;BYTES IN BUFFER
	MOVE	T3,T2			;HOLD IT FOR LATER
	SUB	T2,TTYRDC		;AND EXCLUDE BYTES SENT ALREADY
	JUMPLE	T2,TTYTMX		;IF NOTHING, JUST START OVER
;
;	WE HAVE SOME DATA READY, SEND IT OUT OVER THE NETWORK
;
	LOCK	PORTO			;LOCK PORT OUTPUT
	JRST	TTYTMX			;CAN'T GET IT,FORGET ABOUT
	MOVEM	T3,TTYRDC		;SET NEW RDC COUNT
	MOVE	T3,TTYQ1		;GET CURRENT POINTER
	MOVEM	T3,TTYRDP		;AND SAVE IT AS NEW "READ-POINTER"
	MOVE	T1,TTYRDP		;GET DATA BUFFER
	CALL	NETSND			;AND SENT IT OUT
	SKIPT				;SUCCESS?
	JRST	[ CALL	NETEPR		;NO-PRINT OUT ERROR
		  UNLOCK PORTO		;UNLOCK OUR PORT
		  SETOM	TTYSTS		;SAY PROBLEM IN TTY FORK
		  JRST	TTYTMX ]	;AND RETURN FOR NOW
	UNLOCK	PORTO			;UNLOCK OUR PORT
					;
TTYTMX:	SKIPN	S1,PAD4			;GET IDLE TIMER
	RET				;ZERO MEANS NO IDLE TIME TO SET
	IMULI	S1,^D50			;IM MS
	CALL	TMRGO			;AND START IT
	RET				;AND DISMISS INTERRUPT


	PAGE
	SUBTTL	TTYFRK	TERMINAL FORK ECHO PROCESSING ROUTINES
;
;	TERMINAL TERMINATION  CHARACTER DETECTION ROUTINE
;	ENTER WITH	S2<== CHARACTER <LEFT JUSTIFIED>
;	RETURN	.+1	NOT A BREAK CHARACTER
;		.+2	BREAK CHARACTER
;	USES REGISTER T1
;
TTYTRM:	SKIPE	TTYSCM			;SINGLE CHARACTER MODE?
	RETSKP				;YES-ALWAYS SEES A TERMINATION
	MOVE	T1,S2			;GET THE CHARACTER
	MOVE	T1,CHRTAB(T1)		;GET CHARACTER TYPE
	TXNE	T1,TC%BRK		;IS IT A TERM. CHARACTER
	RETSKP				;YES-SAY SO
	RET				;NO-JUST RETURN
;
;	TERMINAL ECHO ROUTINE
;
TTYEHO:	SKIPE	TTYDEB			;IF DEBUG,NEED TO SAVE P's
	SAVEP				;SAVE P REGISTERS
	MOVE	T2,TTYSTS		;GET TERMINAL STATUS
	TXNE	T2,TY%DIP		;DELETE IN PROGRESS?
	CALL	TTYDEX			;YES-FINISH UP
	HRRZ	T1,CHRTAB(S2)		;GET ONLY RIGHT HALF OFF
	PUSHJ	P,(T1)			;CALL APPROPIATE PROCESSING ROUTINE
	RET				;STORE CHARACTER,PAS IT UPWARD
	RETSKP				;DON'T STORE IT
;
;	HERE ON NORMAL CHARACTER, NOTHING SPECIAL TO DO
;
TTYCHR:	XBOUT				;OUTPUT CHARACTER
	RET				;JUST RETURN
;
;	HERE ON <ESC>, BECAUSE OF DISPLAY ESCAPE SEQUENCES, WE WON'T
;	ECHO THIS CHRACTER EITHER FLAGGED NOR UNFLAGGED.
;
TTYESC:	RET				;SEND IT OFF, NO ECHO
;
;	HERE ON A <LF>
;	ECHO <LF> FOR LF AND PASS CHRARACTER TO NETWORK
;	DO PADDING IF NEEDED
;
TTYCLF:	XBOUT				;OUTPUT IT
	SKIPN	TTYPAD			;PADDING ENABLED
	RET				;NO-PASS CHARACTER ONTO NETWRK.
	MOVE	T1,PAD14		;GET <LF> PADDING
	JRST	TTYPAX			;AND DO PADDING
;
;	HERE ON <CR>,DO PADDING IF ENABLED
;
TTYCCR:	XBOUT				;OUTPUT IT
	SKIPN	T1,PAD13		;ANY LF AFTER CR TO INSERT?
	JRST	TTYCC1			;NO-JUMP OVER
	TRNN	T1,4			;LF AFTER CR ON ECHO?
	JRST	TTYCC1			;NO-GO ON
	MOVEI	S2,12			;GET A LF TOO
	XBOUT				;OUTPUT IT
					;
TTYCC1:	MOVEI	S2,15			;GET BACK <CR> TO PASS ON
	SKIPN	TTYPAD			;PADDING ENABLED?
	RET				;NO-DONE AND STORE CHARACTER
	MOVE	T1,PAD9			;YES-GET PADDING
					;
TTYPAX:	PUSH	P,S2			;SAVE IT FOR A SECOND
	MOVE	S1,[ .PRIOU]		;OUTPUT DESIGNATOR
	SETZM	S2			;AND GET <NULL>
	SOJLE	T1,.+3			;JUMP IF ALL DONE
	BOUT				;OUTPUT FILLER
	JRST	.-2			;AND LOOP FOR DONE
	POP	P,S2			;RESTORE CHARACTER
	RET				;ALL DONE HERE
;
;	HERE ON A ^R TO PROCESS,CHARACTER WILL BE NOT STORED IN
;	OUTPUT BUFFER
;
TTYCR:	MOVE	T1,TTYTYP		;GET TERMINAL TYPE
	MOVEI	S2,15			;GET A CR
	XBOUT				;AND SEND IT
	HRRO	S1,TTXCR(T1)		;GET <CR,LF> OR EQUIVALENT
	PSOUT				;GO NEXT LINE, BYPASS OUTPUT ROUTINE
	MOVE	S1,[ .PRIOU ]		;GET OUTPUT DESIGNATOR
	MOVE	S2,[ POINT 7,TTYBUF]	;START AT BEGINNING
	MOVE	T1,Q2			;GET BUFFER COUNTER
	SUBI	T1,TTYBFZ		;GET #OF BYTES IN BUFFER
	JUMPE	T1,TTYCR0		;IGNORE 0 BUFFER
	XSOUT				;AND SEND IT OUT
TTYCR0:	RETSKP				;DONT SEND OF THIS CHARACTER

;
;	HERE ON A ^U CHRACTER <DELETE LINE >
;
TTYCU:	CAIL	Q2,TTYBFZ		;ANYTHING LEFT IN BUFFER?
	JRST	[ MOVE	S1,[ .PRIOU ]	;NO
		  MOVEI	S2,7		;GET A BELL
		  BOUT			;AND SEND IT, BYPASS OUTPUT ROUTINE
		  JRST  .+1 ]		;FALL BACK IN MAIL LINE
	SETZM	Q3			;NO MORE FLAGS HERE
	MOVEI	Q2,TTYBFZ		;RESET BUFFER COUNTER
	MOVE	Q1,[ POINT 7,TTYBUF ]	;AND BUFFER POINTER
	MOVE	T1,TTYTYP		;GET TERMINAL TYPE
	CAIE	T1,.TTYHC		;SKIP IT IF HARDCOPY
	JRST	[ MOVEI	S2,15		;GET A CR,WILL RESET LINE WIDTH
		  XBOUT			;AND OUTPUT IT
		  HRRO	S1,TTXCU(T1)	;AND GET <LINE DELETE> EQUIVQLENT
		  PSOUT			;SEND IT OUT, BYPASS
		  JRST	TTYCU1 ]		;AND DON'T STORE CHARACTER
	HRRO	S1,TTXCU(T1)		;GET <LINE DELETE> EQUIVALENT
	XPSOUT				;AND OUTPUT IT
TTYCU1:	MOVEI	S2,15			;GET A <CR>
	RET				;AND GO SEND IT OFF
;
;	HERE ON A DELETE CHARACTER
;
TTYDEL:	MOVN	T1,Q2			;GET CURRENT BUFFER SIZE
	ADDI	T1,TTYBFZ		;
	SKIPN	T1			;SOMTHING TO DELETE?
	JRST	[ MOVE	S1,[ .PRIOU ]	;NO
		  MOVEI	S2,7		;GET A BELL
		  BOUT			;AND SEND IT, BYPASS OUTPUT ROUTINE
		  RETSKP ]		;ALL DONE,RET
	MOVE	T1,TTYTYP		;GET OUR TERMINAL TYPE WE'R ON
	CAIE	T1,.TTYHC		;HARD-COPY TYPE?
	JRST	[ HRRO  S1,TTXDEL(T1)	;NO-MUST BE DISPLAY THEN
		  PSOUT			;AND SEND IT OFF,BYPASS NORMAL OUTPUT
		  SOS	TTYHCT		;ADJUST HORIZONTAL LINE COUNTER
		  JRST  TTYDE1 ]	;BACK IN LINE CODE
	MOVE	T4,TTYSTS		;GET OUR STATUS WORD
	TXNE	T4,TY%DIP		;DELETE IN PROGRESS
	JRST	TTYDE0			;NO-JUMP OVER
					;
	BIS	TY%DIP,TTYSTS		;SAY DELETE IN PROGRESS
	HRROI	S1,[ASCIZ\/\]		;GET TERMINATOR
	XPSOUT				;AND OUTPUT IT
					;
TTYDE0:	MOVE	S1,[ .PRIOU ]		;GET OUTPUT DESIGNATOR
	LDB	S2,Q1			;AND LAST BYTE
	XBOUT				;AND OUTPUT IT
TTYDE1:	SETOM	T3			;GET A MINUS 1
	ADJBP	T3,Q1			;BACKUP OUR POINTER
	MOVE	Q1,T3			;UPDATE OUR POINTER FROM
	AOS	Q2			;AND ADJUST COUNTER TO
	RETSKP				;ALL DONE-DONT SEND THIS CHARACTER
;
;	HERE IF TY%DIP IS SET UP CHECK WE NEED TO TERMINATE
;	DELETE SEQUENCE.
;
TTYDEX:	CAIN	S2,177			;ANOTHER DELETE CHARACTER
	RET				;YES-LET TTYDEL HANDEL IT
					;
	HRROI	S1,[ASCIZ\/\]		;GET TERMINATOR
	XPSOUT				;AND OUTPUT IT
	BIC	TY%DIP,TTYSTS		;CLEARE DELETE IN PROGRESS
	RET				;ALL DONE NOW

	PAGE
;
;	HERE ON ^Q TO PROCESS, DEPENDING ON BIT TY%PWT IN TTYSTS
;	THIS CHARACTER RESUMES TERMINAL OUTPUT AT NETWORK INTERRUPT
;	LEVEL BY TURNING OFF TY%PWT OTHERWISE THIS CHARRACTER IS
;	JUST PASSED THRU.
;
TTYCQ:	SKIPN	TTYPMO			;PAGE MODE ENABED?
	JRST	TTYCHR			;NO-JUST NORMAL CHARACTER PROCESSING
	MOVE	CX,TTYSTS		;GET TERMINAL STATUS
	TXNN	CX,TY%PWT		;IN PAGE WAIT?
	RET				;NO-JUST PASS IT THRU
	BIC	TY%PWT,TTYSTS		;YES-RESUME MAIN CODE
;	RET				;AND SEND IT OFF
	movei	s2,40
	retskp

	PAGE
;
;	SPECIAL OUTPUT ROUTINES (USED BY TERMINAL FORK)
;	XBOUT	SAME AS BOUT,OUTPUTS CHARACTER IN S2,
;		USES S1.
;
.BOUT:	CALL	TTYXXX			;OUTPUT IT
	RET				;JUST RETURN
;
;	XPSOUT	SAME AS PSOUT, OUTPUTS STRING (POINTER) IN S1
;
.PSOUT:	PUSH	P,T1			;SAVE IT
	PUSH	P,S2			;AND THIS ONE TOO
	MOVE	T1,[ POINT 7,0 ]	;GET A BYTE POINTER
	HRR	T1,S1			;FROM INPUT
					;
.PSOU1:	ILDB	S2,T1			;GET A BYTE
	SKIPN	S2			;TERMINATOR?
	JRST	.PSOU2			;YES-STOP IT
	CALL	TTYXXX			;OUTPUT IT
	JRST	.PSOU1			;LOOP UNTIL DONE
.PSOU2:	POP	P,S2			;RESTORE REGISTERS
	POP	P,T1			;GET IT BACK
	RET				;JUST RETURN
;
;	XSOUT	ALMOST SAME AS SOUT JSYS
;
.SOUT:	PUSH	P,T1			;SAVE IT
	PUSH	P,T2			;AND THIS ONE TOO
	PUSH	P,S2			;ALSO THIS ONE
	SKIPG	T1			;GET BYTE COUNT
	MOVNS	T1			;ALLWAYS POSITIVE
	MOVE	T2,[ POINT 7,0 ]	;AND A BYTE POINTER
	HRR	T2,S2			;FOR THE DATA
					;
.SOUT1:	ILDB	S2,T2			;GET A BYTE
	CALL	TTYXXX			;OUTPUT IT
	SOJG	T1,.SOUT1		;UNTIL ALL DONE
	POP	P,S2			;RESTORE REGISTERS
	POP	P,T2			;
	POP	P,T1			;
	RET				;AND ALL DONE

	PAGE
;
;	TTYXXX	ROUTINE TO CHECK FOR FLAGGED CHARACTER AND FLAG IT
;		IF NEEDED AND OUTPUT CHARACTERS TO THE TERMINAL.
;		ALSO MAINTAIN HORIZONTAL COUNTER AND RESET VERTICAL
;		COUNTER IF CHARACTER IS A TERMINATION TYPE CHARACTER.
;		THIS ROUTINE ONLY IS CALLED IN CHARACTER ECHOING
;
TTYXXX:	PUSH	P,S2			;SAVE OUR CHARACTER
	PUSH	P,T1			;SAVE A REGISTER
	MOVE	T1,CHRTAB(S2)		;GET TYPE OF CHARACTER
	TXNE	T1,TC%FLG		;FLAG TYPE CHARACTER?
	JRST	[ PUSH	P,S2		;SAVE IT A SECOND
		  AOS	TTYHCT		;EXTRA COUNT FOR THIS ONE
		  MOVE	S1,[.PRIOU ]	;OUTPUT DESIGNATOR
		  MOVEI	S2,136		;GET A FLAG "^"
		  BOUT			;AND SEND IT OFF
		  POP	P,S2		;GET CHARACTER BACK
		  ADDI	S2,100		;MAKE IT PRINTABLE
		  JRST .+1 ]		;AND BACK TO MAIN-LINE
	TXNE	T1,TC%BRK		;BREAK TYPE CHARACTER
	JRST	[ SETZM	TTYHCT		;YES-RESET HORIZONTAL
		  SETZM	TTYLCT		;AND VERTICAL COUNTERS
		  JRST .+2 ]		;FALL INTO MAIN-LINE
	AOS	TTYHCT			;COUNT IT
	MOVE	S1,[ .PRIOU ]		;OUTPUT DESIGNATOR
	BOUT				;AND OUTPUT CHARACTER IN S2
					;
	SKIPN	TTYFLD			;PADDING ENABLED?
	JRST	TTYXX3			;NO-SKIP IT
	SKIPG	T1,PAD10		;YES-GET LINE WIDTH
	JRST	TTYXX3			;FORGET ABOUT ZERO LINE WIDTH
	CAMLE	T1,TTYHCT		;TIME FOR AUTO CRLF?
	JRST	TTYXX3			;NO-SKIP IT
	HRROI	S1,[ BYTE (7)15,12,0 ]	;YES-GET IT
	XPSOUT				;AND SEND IT OFF
					;
TTYXX3:	POP	P,T1			;RETORE REGISTER
	POP	P,S2			;GET BACK ORIGIN CHARACTER WE HAD
	RET				;ALL DONE-RETURN

	PAGE
	SUBTTL	XXXXXX	GENERAL SUBROUTINES
;
;
;	CMDNOS - ROUTINE TO HANDLE GUIDEWORD STRINGS.
;	  S2/	ADDRESS OF ASCIZ GUIDEWORD STRING
;		CALL	CMDNOS	OR USE NOISE MACRO
;	RETURNS  +1:	ALWAYS


CMDNOS:	HRROM	S2,NOIBLK+.CMDAT	;SAVE AS DATA
	MOVEI	S2,NOIBLK		;POINT TO BLOCK
	MOVEI	S1,CMDBLK		;AND COMMAND STATE BLOCK
	COMND				;PARSE THE FUNCTION
	 ERRJMP	RETE,<?COMND failed parsing command>
	TXNN	S1,CM%NOP+CM%EOC	;DID IT PARSE?
	RETT				;YES, RETURN SUCCESSFULLY
	RETF				;NO, COMPLAIN
;
;
;	CMDCNF - ROUTINE TO HANDLE LINE CONFIRMATION FUNCTION.
;		CALL	CMDCNF	OR USE CONFRM MACRO
;	RETURNS  +1:	ALWAYS
;
;	CMDCMD - CENTRAL ROUTINE TO PERFORM COMND JSYS CALL.
;	  S2/	ADDRESS OF COMND DESCRIPRTOR BLOCK TO USE
;		CALL	CMDCMD	OR USE PARSE MACRO
;	RETURNS  +1:	ALWAYS, UNLESS NOPARSE WHICH GENERATES ERROR
;
;
CMDCNF:	MOVEI	S2,[FLDDB. (.CMCFM)]	;GET CONFIRM FUNCTION
CMDCMD:	MOVEI	S1,CMDBLK	;POINT TO OUR (ONLY) COMMAND BLOCK
	COMND			;PARSE THE FUNCTION
	 ERRJMP	RETE,<?COMND failed parsing command>
	TXNN	S1,CM%NOP	;DID IT PARSE?
	RETT			;YES, RETURN SUCCESSFULLY
	RETF			;NO, COMPLAIN

	PAGE
;
;	DTENBR	COPY DTE ADDRESS FROM COMND ATOM BUFFER INTO
;		DTENBR STRING AS USED BY THE  NETOPN ROUTINE.
;		CHECK VALIDITY OF DTE NUMBER AND RETURN FALSE
;		IF ANY NON-NUMERIC CHRACTER SEEN.
;	USES S1,T1,T2
;	RETURNS +1 FALSE OR
;		CHARACTER COUNT IN S2
;
DTENUM:	MOVE	T1,[ POINT 7,DTENBR]	;GET DEST. ADDRSS
	MOVE	T2,CMDBLK+.CMABP	;AND SOURCE
	SETZM	S2			;NO COUNT YET
					;
DTENU0:	ILDB	S1,T2			;GET A BYTE
	SKIPN	S1			; ZERO TERMINATOR?
	JRST	DTENU1			;YES-TERMINATE
	CAIN	S1,15			; <CR> TERMINATOR
	JRST	DTENU1			;YES-TERMINATE
	CAIN	S1,33			;<ESC> TERMINATOR?
	JRST	DTENU1			;YES-TERMINATE
	CAIL	S1,60			;IN NUMBER RANGE?
	CAILE	S1,71			;
	RETF				;NO-ERROR RETURN
	IDPB	S1,T1			;YES-PUT IN DESTIGNATEION
	AOS	S2			;AND COUNT IT
	JRST	DTENU0			;GO-LOOP FOR MORE
					;
DTENU1:	SETZM	S1			;GET A ZERO
	IDPB	S1,T1			;AND PUT IT IN
	RETT				;OK-ALL DONE RETURN
	
	PAGE
;
;	TIME OF DAY ROUTINE,
;	RETURNS S1 <== TIME OF DAY IN MS
;
TODCLK:	PUSH	P,S2			;SAVE THIS ONE
	TIME				;GET TIME
	POP	P,S2			;
	RET				;DONE S1 HAS TIME
;
;	SPECIAL RETURNS NEEDED
;
;	SAME AS RETF MACRO
;
RETE:	SETOM	0
	RET
;
;	SAME AS RETT MACRO
;
RETS:	SETZM	0
	RET

;
;	SAVE PERMANENT REGISTER
;	CALLED JSP CX,.SAVEP
;
	DEFINE	SAVEP<
	XLIST
	JSP	CX,.SAVEP
	LIST
>
;
.SAVEP:	ADJSP	P,4			;MAKE SPACE ON STACK
	DMOVEM	P1,-3(P)		;SAVE P1,P2
	DMOVEM	P3,-1(P)		;SAVE P2,P3
	PUSHJ	P,(CX)			;CALL BACK CALLER
	SKIPA				;NORMAL RETURN
	AOS	-4(P)			;MAKE SKIP RETURN
	DMOVE	P3,-1(P)		;GET BACK SAVED REGISTER
	DMOVE	P1,-3(P)
	ADJSP	P,-4			;CLEAN UP STACK
	POPJ	P,			;AND DO THE RETURN

	PAGE
;
;	TITLE LINE AND VERSION PRINTOUT,
;	USED AT INITIAL STARTUP FOR USER HELLO AND INFO
;
HERALD:	TMSX	< PAD X29 Packet assembler/disassembler Version >
	MOVEI	S1,PADVER
	OOUT	S1			;TELL VERSION NUMBER
	TMSX	<.>
	MOVEI	S1,PADWHO
	OOUT	S1			;SUBVERSION
	TMSX	<(>
	MOVEI	S1,PADEDT
	OOUT	S1			;EDIT
	TMSG	<)>
	RET				;ALL DONE,RETURN

	PAGE
	SUBTTL	INTXXX	INTERRUPT INITIALIZATION AND CONTROL ROUTINES
;
;	INITIALIZE INTERRUPT SYSTEM
;
INTON:	MOVE	S1,[ .FHSLF ]		;OUR PROCESS
	MOVE	S2,[ LEVTAB,,CHNTAB ]	;INT-TABLES
	SIR				;SET SOFT. TABLE INT. ADDR.
	MOVE	S2,[ CH.X25!CH.TMR ]	;CHANNEL
	MOVEM	S2,INTMSK		;SET UP MASK FOR INTOFF
	AIC				;ACTIVATE IT
	EIR				;AND ENABLE SYSTEM
	RET				;ALL DONE
;
;	TURN OFF INTERRUPTS,CLEARE PENDING INTERRUPTS AND CLEARE
;	DEACTIVATE ALL OPENED CHANNELS.
;
INTOFF:	MOVE	S1,[ .FHSLF ]		;OUR PROCESS
	DIR				;TURN INT. SYSTEM OFF
	CIS				;CLEARE PENDING INTS.
	MOVE	S2,INTMSK		;GET ENABLED CHANNELS
	DIC				;AND TUN HIM OFF TOO
	RET				;ALL DONE

;
;	ROUTINE TO TEMP. TURN ON/OFF INTERRUPT SYSTEM
;
	DEFINE PION<
	XLIST
	PUSHJ	P,.PION
	LIST
>
.PION:	MOVE	S1,[ .FHSLF ]		;OUR FORK
	EIR
	POPJ	P,

	DEFINE PIOFF<
	XLIST
	PUSHJ	P,.PIOFF
	LIST
>
.PIOFF:	MOVE	S1,[ .FHSLF ]		;OUR FORK
	DIR
	POPJ	P,

	PAGE
	SUBTTL	INTXXX	INTERRUPT SAVEAC,DEBREAK AND WAIT CODE
;
;	INTERRUPT AC SAVE ROUNTINE
;
;	ASSUMES INRRUPT AT PRIORITY 1
;	CALLED BY SAVCH1
;
	DEFINE	SAVCH1 <
	XLIST
	JSR	SAVCH1
	LIST
>
SAVCH1:	Z				;SAVE RET PC HERE
	ADJSP	P,7			;MAKE SOME ROOM
	MOVEM	0,-6(P)			;SAVE FLAG REGISTER
	DMOVEM	S1,-5(P)		;AND SAVE REGISTERS
	DMOVEM	T1,-3(P)		;
	DMOVEM	T3,-1(P)		;
	PUSH	P,CX			;THIS ONE TOO
	MOVE	CX,SAVCH1		;GET WHERE WE CALLED FROM
	PUSHJ	P,(CX)			;RECALL CALLER
	SKIPA
	AOS -7(P)
	POP	P,CX			;UNSAVE REGISTERS
	DMOVE	T3,-1(P)		;UNSAVE REGISTERS
	DMOVE	T1,-3(P)		;
	DMOVE	S1,-5(P)		;
	MOVE	0,-6(P)			;
	ADJSP	P,-7			;CLEARE UP STACK
					;FALL INTO DEBREAK CODE
;
;	INTERRUPT DISMISS CODE
;	ASSUMES PRIORITY LEVEL 1 INTERRUPT
;
$DEBRK:	AOS	INTCNT			;SHOW WE GOT AN INTERRUPT
	PUSH	P,S1			;GET A REGISTER
	HRRZ	S1,PC1			;GET INTERRUPT PC
	CAIE	S1,$WAIT2+1		;SITTING IN THE WAIT CALL?
	JRST	$DEBR0			;NO-JUST RETURN
	MOVE	S1,[ 1B5 ]		;GET USER MODE
	IORM	S1,PC1			;AND TURN IT ON
$DEBR0:	POP	P,S1			;UNSAVE REGISTER
	DEBRK				;AND DISMISS

;
;	HIBER SIMULATION ROUTINE AND WAIT CODE
;
;	ENTER WITH S1<== TIME TO WAIT IN MS.
;		   S2<== STATE CODE TO WAIT FOR
;
;	RETURNS FALSE IF TIME OUT OR ANY ERROR
;	RETURNS TRUE  IF STATE CHANGED AS REQIRED
;
$WAIT:	MOVE	T1,S2			;GET WAIT STATE CODE
	SETZM	TMRDSP			;AND NO TIMER DISPATCH
	CALL	TMRGO			;START TIMER GOING
					;
$WAIT1:	SKIPE	PORTE			;ANY ERROR AT INTRRUPT LEVEL SEEN?
	RETF				;YES-RETURN ERROR
	HRRZ	T2,PORTS		;GET NEW PORT STATE
	CAIN	T2,XS%ERR		;WE GOT IN TRUBLE?
	RETF				;YES-ERROR RET.
	CAMN	T2,T1			;STATE WE WAIT FOR
	JRST	$WAIT3			;YES-RETURN OK
$WAIT2:	WAIT				;WAIT FOR SOMTHING HAPPENS
	SKIPE	TMROUT			;TIME OUT?
	RETF				;YES-FLAG ERROR
	SKIPL	TTYSTS			;TTY TASK TERMINATED?
	JRST	$WAIT1			;NO-GO BACK TO WAIT
	RETF				;YES-SAY SO
;
;	HERE IF DONE,TIMER HAS'NT EXPIRED AND NO ERROR
;
$WAIT3:	CALL	TMRSTP			;STOP TIMER NOW
	RETT				;AND ALL DONE

	PAGE
	SUBTTL	TIMER SERVICE 
;
;	ROUTINE TO START TIMER GOING
;
TMRGO:	SETZM	TMROUT			;NO TIME OUT YET
	PUSH	P,T1			;SAVE THIS GUY
	PUSH	P,S1			;SAVE TIME
	MOVE	S1,[ .FHSLF,,.TIMAL ]	;GET FUNCTION
	SETZM	S2			;
	SETZM	T1			;
	TIMER				;CLEARE PENDING TIMERS
	ERR	EXIT,<?Could not cleare timer for this job>
	MOVE	S1,[ .FHSLF,,.TIMEL ]	;FUNCTION,,OUR FORK
	POP	P,S2			;GET BACK WAIT TIME
	MOVEI	T1,CH%TMR		;AND GET CHANNEL WE ARE ON
	TIMER				;START IT GOING
	ERR	EXIT,<?Could not start timer going>
	POP	P,T1			;CLEAN UP STACK
	RET				;ALL DONE,RETURN
;
;	STOP TIMER
;
TMRSTP:	SETZM	TMRDSP			;CLEARE OUT DISPATCH
	PUSH	P,T1			;SAVE THIS ONE
	MOVE	S1,[ .FHSLF,,.TIMAL ]	;GET FUNCTION
	SETZM	S2			;
	SETZM	T1			;
	TIMER				;CLEARE PENDING TIMERS
	ERR	EXIT,<?Could not cleare timer for this job>
	POP	P,T1			;CLEANE UP STACK
	SETZM	TMROUT			;NO TIME OUT
	RET				;AND RETURN

	PAGE
	SUBTTL	TIMER	TIMER INTERRUPT CODE
;
;	ALL TIMER INTERRUPTS COMMES HERE
;
TMRINT:	PUSH	P,S1			;GET A REGISTER
	HRRZ	S1,PC2			;GET INTERRUPT PC
	MOVE	S1,-1(S1)		;GET INSTRUCTION
	CAME	S1,[ WAIT ]		;SITTING IN A WAIT JSYS?
	JRST	TMRIN0			;NO-JUST RETURN
	MOVE	S1,[ 1B5 ]		;GET USER MODE
	IORM	S1,PC2			;AND TURN IT ON
TMRIN0:	POP	P,S1			;UNSAVE REGISTER
	SETOM	TMROUT			;TELL THE WORLD,TIME OUT
	SKIPN	TMRDSP			;DISPATCH SPECIFIED?
	DEBRK				;NO-BREAK INTERRUPT
	SAVCH2				;SAVE REGISTERS
	JRST	@TMRDSP			;YES-GO TO

	PAGE
	SUBTTL	INTXX2	INTERRUPT SAVEAC,DEBREAK CODE
;
;	INTERRUPT AC SAVE ROUNTINE
;
;	ASSUMES INRRUPT AT PRIORITY 2
;	CALLED BY SAVCH2
;
	DEFINE	SAVCH2 <
	XLIST
	JSR	SAVCH2
	LIST
>
SAVCH2:	Z				;SAVE RET PC HERE
	ADJSP	P,7			;MAKE SOME ROOM
	MOVEM	0,-6(P)			;SAVE FLAG REGISTER
	DMOVEM	S1,-5(P)		;AND SAVE REGISTERS
	DMOVEM	T1,-3(P)		;
	DMOVEM	T3,-1(P)		;
	PUSH	P,CX			;THIS ONE TOO
	MOVE	CX,SAVCH2		;GET WHERE WE CALLED FROM
	PUSHJ	P,(CX)			;RECALL CALLER
	SKIPA
	AOS -7(P)
	POP	P,CX			;UNSAVE REGISTERS
	DMOVE	T3,-1(P)		;UNSAVE REGISTERS
	DMOVE	T1,-3(P)		;
	DMOVE	S1,-5(P)		;
	MOVE	0,-6(P)			;
	ADJSP	P,-7			;CLEARE UP STACK
	AOS	INTCNT			;SHOW WE GOT AN INTERRUPT
	DEBRK				;AND DISMISS INTERRUPT

	PAGE
	SUBTTL	INTDAT	INTERRUPT LEVTAB,,CHNTAB AND DATA
;
INTCNT:	Z				;COUNT INTERRUPTS DURING WAIT
INTMSK:	Z				;STORE INTERRUPT CHANNEL MASK HERE
LEVTAB:	PC1				;WHERE TO SAVE PC
	PC2
	PC3
;
PC1:	Z				;SAVE PC FOR CHANNEL ONE HERE
PC2:	Z
PC3:	Z
;
	DEFINE CHN (X,Y,ZA) <
	XLIST
	ZZZ=X-ZZ
	REPEAT ZZZ , < 0
>
	ZZ=X+1
	IFN Y, < Y,,ZA
>
	LIST
>
	ZZ==0
CHNTAB:
	CHN	(CH%X25,1,NETINT)
	CHN	(CH%TMR,2,TMRINT)
	CHN	(^D35)

	PAGE
	SUBTTL	DATA BASE
;
;
;
TRACE:	Z				;DEBUG/TRACE FLAG
PADINI:	-1				;PAD INITIALIZATION FLAG
	PDLSZ= ^D200
PDL:	BLOCK	PDLSZ
	TTYPDZ= ^D 50
TTYPDL:	IOWD	TTYPDZ,TTYPD
TTYPD:	BLOCK	TTYPDZ
;
	CMDLEN== ^D 128			;COMMAND STRING MAX. SIZE
CMDBLK:	0,,CMDLOP			;ADDRESS OF REPARSE ROUTINE
	.PRIIN,,.PRIOU			;INPUT,,OUTPUT JFNS
	-1,,[ASCIZ/PAD>/]		;CONTROL-R POINTER
	-1,,CMDBUF			;POINTER TO TEXT BUFFER
	-1,,CMDBUF			;POINTER TO CURRENT POSITION
	CMDLEN				;NUMBER OF CHARS IN BUFFER
	0				;NUMBER OF UNPARSED CHARACTERS
	-1,,CMDATM			;POINTER TO ATOM BUFFER
	CMDLEN				;NUMBER OF CHARACTERS IN BUFFER
	EXP	CMDJFN			;POINTER TO GTJFN BLOCK

CMDJFX:	GJ%OLD				;FLAGS,,GENERATION NUMBER
	.PRIIN,,.PRIOU			;INPUT,,OUTPUT JFNS
	BLOCK	20			;NO DEFAULTS

NOIBLK:	FLDDB.	(.CMNOI)		;BLOCK FOR NOISE FUNCTION
;
CMDSVP:	BLOCK	1			;STORAGE OF STACK
CMDBUF:	BLOCK	CMDLEN/5+1		;BUFFER FOR COMMAND JSYS
CMDATM:	BLOCK	CMDLEN/5+1		;BUFFER FOR ATOM BUFFER
CMDFRK:	Z				;FORK HANDLE FOR PUSH CMD.
CMDJFN:	Z				;AND JFN FOR EXEC.
;
DTENBR:	BLOCK	5			;BUFFER FOR DTE# READIN
DTESNR:	BLOCK	5			;BUFFER FOR SUB-DTE NUMBER

	NETNMZ==64
NETNAM:	ASCIZ/TRANSPAC/			;NETWORK NAME
	BLOCK	<NETNMZ-8>/5+1
	NETPSZ==64
NETPSW:	ASCIZ/TRNSP/			;PASSWORD
	BLOCK	<NETPSZ-5>/5+1
;
	USRDSZ==^D 4
					;PROTOCOLL IDENTIFIER FIELD <4 BYTES>
USRDAT:	BYTE	(8)1,0,0,0		; X.29 REQUEST
					;CALL DATA FIELD <UP TO 12 BYTE>
;
MRGBLK:	BLOCK	^D 10			;ARGUMENT BLOCK FOR X25GAL
IRGBLK:	BLOCK	^D 10			;ARGUMENT BLOCK FOR X25GAL
TRGBLK:	BLOCK	^D 10			;ARGUMENT BLOCK FOR X25GAL
;
PORTO:	Z				;PORT OUTPUT LOCK
PORTI:	Z				;PORT INPUT LOCK
PORTF:	Z				;PORT OPEN FLAG
PORTL:	Z				;LAST PORT STATUS FOR STATE TABLE
PORTS:	Z				;CURRENT PORT STATUS
PORTM:	Z				;CURRENT PORT FLAG
PORTE:	Z				;FLAG ERROR SEEN AT INTR. LEVEL
PORT:	Z				;PORT NUMBER IS SAVED HERE
POROCT:	Z				;PORT OUTPUT BYTE COUNT
POROBL:	Z				;PORT OUTPUT BLOCK COUNT
PORICT:	Z				;PORT INPUT BYTE COUNT
PORIBL:	Z				;PORT INPUT BLOCK COUNT
	PCKSZ==^D 100			;PACKET SIZE USED
PORTBLK:BLOCK ^D 155+PCKSZ		;PORT DATA BUFER
;
REMCUG:	BLOCK 20			;REMOTE USER GROUP BUFFER
	REMFAZ==^D 64
REMFAC:	BLOCK	<REMFAZ/4>+1		;REMOTE FACILITIES BUFFER
	REMBFZ==^D 200
REMBFR:	BLOCK	<REMBFZ/4>+1		;REMOTE DATA BUFFER
;
;
TTYDEB:	Z				;TTY-TASK DEBUG FLAG
TTYFRK:	Z				;TTY FORK PROCESS HANDLE
TTYSFM:	Z				;SAVE OLD TERMINAL SFMOD HERE
TTYSTS:	Z				;TERMINAL FORK STSTUS
TTYSCM:	Z				;SINGLE BREAK CHRACTER FLAG
TTYMSK:	Z				;MASK FOR TERMINAL INTERRUPT PRC.
TTYHCT:	Z				;HORIZONTAL CHARACTER COUNT
TTYLCT:	Z				;VERTICAL LINE COUNT
TTYBRC:	.TICCY				;LINE BREAK CHARACTER
TTYTYP:	Z				;TERMINAL TYPE IDENTIFIER
TTYQ1:	Z				;COPY OF TTYFRK Q1 REGISTER
TTYQ2:	Z				;COPY OF TTYFRK Q2 REGISTER
TTYRDP:	Z				;'READ POINTER" FOR TTYBUF
TTYRDC:	Z				;"READ COUNTER" FOR TTYBUF
	TTYBFZ==^D 128
TTYBUF:	BLOCK	<TTYBFZ>+1		;TERMINAL INPUT BUFFER
					;
TMROUT:	Z				;TIMER RUNNED OUT FLAG
TMRDSP:	Z				;TIMER DISPATCH ADDRESS

	PAGE
;
;	SPECIAL PAD PARAMETERS NOT YET IN PAD PARAM BLOCK
;
TTYFLD:	Z				;TERMINAL FOLDING ENABLED
TTYPAD:	Z				;TERMINAL PADDING ENABLED FLAG
TTYPSZ:	Z				;TERMINAL PAGE SIZE
TTYPMO:	Z				;TERMINAL WAIT AT END OF PAGE
;
;	PAD PARAMETER BLOCK
;
PADPRM:	Z
PAD1:	Z				;PAD RECALL CHARACTER
PAD2:	Z				;PAD ECHO MODE
PAD3:	Z				;PAD DATA FORWARDING
PAD4:	^D 50				;PAD IDLE TIMER DELAY
PAD5:	Z				;PAD ANCILLARY DEVICE CONTROL
PAD6:	Z				;PAD CNTRL. OF PAD CONTROL SIGNALS
PAD7:	Z				;PAD BREAK ACTION
PAD8:	Z				;PAD DISCARD OUTPUT
PAD9:	Z				;PAD PADDING AFTER CR
PAD10:	Z				;PAD LINE FOLDING
PAD11:	Z				;PAD LINE SPEED
	PADMAX==.-PAD1			;*** NATIONAL PARAMETERS
PAD12:	Z				;PAD FLOW CONTROL
PAD13:	Z				;PAD LF INSERTION AFTER CR
PAD14:	Z				;PADDING AFTER LINE-FEED
PAD15:	Z				;PAD EDITING
PAD16:	Z				;PAD LINE DELETE
PAD17:	Z				;PAD LINE DISPLAY

	PADMXX==.-PAD1

	PAGE
;
;	TERMINAL CHARACTER SET TABLE
;	USED FRO LOCAL ECHOING AND BREAK DETECTION
;
CHRTAB:	TC%BRK!TC%FLG ! TTYCHR		;CONTROL-@
	TC%BRK!TC%FLG ! TTYCHR		;CONTROL-A
	TC%BRK!TC%FLG ! TTYCHR		;CONTROL-B
	TC%BRK!TC%FLG ! TTYCHR		;CONTROL-C
	TC%BRK!TC%FLG ! TTYCHR		;CONTROL-D
	TC%BRK!TC%FLG ! TTYCHR		;CONTROL-E
	TC%BRK!TC%FLG ! TTYCHR		;CONTROL-F
	TC%BRK!TC%FLG ! TTYCHR		;CONTROL-G
	TC%BRK!TC%FLG ! TTYCHR		;CONTROL-H
	TC%BRK!TC%FLG ! TTYCHR		;CONTROL-I
		TC%BRK! TTYCLF		;<LF>
	TC%BRK!TC%FLG ! TTYCHR		;CONTROL-K
	TC%BRK!TC%FLG ! TTYCHR		;CONTROL-L
		TC%BRK! TTYCCR		;<CR>
	TC%BRK!TC%FLG ! TTYCHR		;CONTROL-N
	TC%BRK!TC%FLG ! TTYCHR		;CONTROL-O
	TC%BRK!TC%FLG ! TTYCHR		;CONTROL-P
		TC%BRK! TTYCQ		;CONTROL-Q
		    0 ! TTYCR		;CONTROL-R
		TC%BRK! TTYCHR		;CONTROL-S
		TC%BRK! TTYCHR		;CONTROL-T
		    0 !  TTYCU		;CONTROL-U
	TC%BRK!TC%FLG ! TTYCHR		;CONTROL-V
	TC%BRK!TC%FLG ! TTYCHR		;CONTROL-W
	TC%BRK!TC%FLG ! TTYCHR		;CONTROL-X
	TC%BRK!TC%FLG ! TTYCHR		;CONTROL-Y
	TC%BRK!TC%FLG ! TTYCHR		;CONTROL-Z
		TC%BRK ! TTYESC		;<ESC>
	TC%BRK!TC%FLG ! TTYCHR		;CONTROL-\
	TC%BRK!TC%FLG ! TTYCHR		;CONTROL-]
	TC%BRK!TC%FLG ! TTYCHR		;CONTROL-^
		TC%BRK ! TTYCHR		;CONTROL-
		    0 ! TTYCHR		;<SP>
		    0 ! TTYCHR		;!
		    0 ! TTYCHR		;"
		    0 ! TTYCHR		;#
		    0 ! TTYCHR		;$
		    0 ! TTYCHR		;%
		    0 ! TTYCHR		;&
		    0 ! TTYCHR		;'
		    0 ! TTYCHR		;(
		    0 ! TTYCHR		;)
		    0 ! TTYCHR		;*
		    0 ! TTYCHR		;+
		    0 ! TTYCHR		;,
		    0 ! TTYCHR		;-
		    0 ! TTYCHR		;.
		    0 ! TTYCHR		;/
		    0 ! TTYCHR		;0
		    0 ! TTYCHR		;1
		    0 ! TTYCHR		;2
		    0 ! TTYCHR		;3
		    0 ! TTYCHR		;4
		    0 ! TTYCHR		;5
		    0 ! TTYCHR		;6
		    0 ! TTYCHR		;7
		    0 ! TTYCHR		;8
		    0 ! TTYCHR		;9
		    0 ! TTYCHR		;:
		    0 ! TTYCHR		;;
		    0 ! TTYCHR		;<
		    0 ! TTYCHR		;=
		    0 ! TTYCHR		;>
		TC%BRK! TTYCHR		;?
		    0 ! TTYCHR		;@
		    0 ! TTYCHR		;A
		    0 ! TTYCHR		;B
		    0 ! TTYCHR		;C
		    0 ! TTYCHR		;D
		    0 ! TTYCHR		;E
		    0 ! TTYCHR		;F
		    0 ! TTYCHR		;G
		    0 ! TTYCHR		;H
		    0 ! TTYCHR		;I
		    0 ! TTYCHR		;J
		    0 ! TTYCHR		;K
		    0 ! TTYCHR		;L
		    0 ! TTYCHR		;M
		    0 ! TTYCHR		;N
		    0 ! TTYCHR		;O
		    0 ! TTYCHR		;P
		    0 ! TTYCHR		;Q
		    0 ! TTYCHR		;R
		    0 ! TTYCHR		;S
		    0 ! TTYCHR		;T
		    0 ! TTYCHR		;U
		    0 ! TTYCHR		;V
		    0 ! TTYCHR		;W
		    0 ! TTYCHR		;X
		    0 ! TTYCHR		;Y
		    0 ! TTYCHR		;Z
		    0 ! TTYCHR		;[
		    0 ! TTYCHR		;\
		    0 ! TTYCHR		;]
		    0 ! TTYCHR		;^
		    0 ! TTYCHR		;_
		    0 ! TTYCHR		;/
		    0 ! TTYCHR		;a
		    0 ! TTYCHR		;b
		    0 ! TTYCHR		;c
		    0 ! TTYCHR		;d
		    0 ! TTYCHR		;e
		    0 ! TTYCHR		;f
		    0 ! TTYCHR		;g
		    0 ! TTYCHR		;h
		    0 ! TTYCHR		;i
		    0 ! TTYCHR		;j
		    0 ! TTYCHR		;k
		    0 ! TTYCHR		;l
		    0 ! TTYCHR		;m
		    0 ! TTYCHR		;n
		    0 ! TTYCHR		;o
		    0 ! TTYCHR		;p
		    0 ! TTYCHR		;q
		    0 ! TTYCHR		;r
		    0 ! TTYCHR		;s
		    0 ! TTYCHR		;t
		    0 ! TTYCHR		;u
		    0 ! TTYCHR		;v
		    0 ! TTYCHR		;w
		    0 ! TTYCHR		;x
		    0 ! TTYCHR		;y
		    0 ! TTYCHR		;z
		    0 ! TTYCHR		;{
		    0 ! TTYCHR		;}
		    0 ! TTYCHR		;|
		    0 ! TTYCHR		;~
		    0 ! TTYDEL		;<del>


	END	START