Google
 

Trailing-Edge - PDP-10 Archives - BB-X116A-BB_1984 - fal.mac
There are 26 other files named fal.mac in the archive. Click here to see a list.
	TITLE	FAL	NFT File Access Listener module
	SUBTTL	Robert Houk/RDH

	SEARCH	JOBDAT,MACTEN,UUOSYM	;STANDARD DEFINITIONS
	SEARCH	NFTDEF			;NFT-WIDE DEFINTIONS
	SEARCH	SWIL			;SWIL PACKAGE DEFINITIONS

	SALL				;PRETTY LISTINGS
	.DIREC	FLBLST			;PRETTIER LISTINGS

	TWOSEG	400000			;NICE PURE CODE

Copyright (C) Digital Equipment Corporation 1984.

	COMMENT	\

FAL  --  NFT "File Access Listener" module

Copyright (C) 1984
Digital Equipment Corporation, Maynard, Massachusetts, U.S.A.

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.

\
	SUBTTL	Revision history

;INITIAL VERSION CREATED FROM NIK 25-MAR-80
	SUBTTL	External linkages

;TO NFT EXECUTIVE

EXTERN	ERRMSG			;ERROR MESSAGE PROCESSOR


;TO NFT/SCAN INTERFACE

EXTERN	CLRFIL,	CLRALL		;CLEAR FOR NEW SPECS
EXTERN	CLRSTK,	MEMSTK,	APLSTK	;STICKY DEFAULT PROCESSORS
EXTERN	INX,	OUX		;ALLOCATE FSB'S
	SUBTTL	Definitions

;FEATURE TESTS

ND	FTUTXT,-1		;DEFAULT INCLUDE SUPPORT FOR USERS.TXT



;I/O CHANNELS INTERNALLY DEDICATED

	UTX==10			;FOR READING USERS.TXT



;RANDOM

ND	$NTFAL,IO.DCN		;DEFAULT NET TYPE (IO.ANF OR IO.DCN)
ND	$NTPPN,<377777,,377777>	;DEFAULT ACCESS PPN
	SUBTTL	Command base table

	DEFINE	CMNDS,<

CM	NETPPN,NPP,<Set default "NETPPN">
CM	REJECT,REJ,<Reject specified incoming connects>
CM	START,FGO,<Start FALling>

IFN FT$NIP,<
CM	NIP,FALNIP,<Enter NIP mode>
>

IFN FT$TSC,<
CM	TSC,FALTSC,<Enter TSC mode>
>

> ;END OF COMMANDS MACRO


;NOW BUILD THE FAL COMMAND BASE TABLE

DOCMND(FAL)
	SUBTTL	Commands - FAL: File Access Listener

;FAL command processor
;
;	FAL <EOL>

FAL::	PUSHJ	P,FAL0		;DO FAL-STARTUP STUFF
	 JFCL			;DUH?
	PUSHJ	P,.CLEOL##	;EAT REST OF COMMAND LINE
	JRST	.POPJ1##	;WE ARE NOW READY TO FAL AWAY


;FAL STARTUP

FAL0:	SETZM	BZFAL		;CLEAR OUT AND INITIALIZE IMPURE DATA
	MOVE	T1,[BZFAL,,BZFAL+1]  ;BLT POINTER TO
	BLT	T1,EZFAL	;CLEAN OUT DATA AREAS
	MOVEI	T1,FALBAS	;SELECT FAL COMMAND BASE
	MOVEM	T1,CMDBAS##	;AS THE NEW COMMAND BASE

;SELECT FAL MODE JOB PARAMETERS

	PUSHJ	P,FALINI	;SET FAL PARAMETERS (DSKFUL ERROR, ETC.)
	 JFCL			;NOT USED

;INITIALIZE USERS.TXT FOR "USERID" NAME TO PPN TRANSLATION

IFN FTUTXT,<			;IF TRANSLATING NAMES TO PPNS, THEN
	PUSHJ	P,UTXINI	;INITIALIZE USERS.TXT TRANSLATION BUFFER
	 WARN	UTX,<Couldn't initialize USERS.TXT name<=>ppn translation>
> ;END IFN FTUTXT

	JRST	.POPJ1##	;FAL INITIALIZED
	SUBTTL	Commands - NIP: Re/Enter NIP mode operation

IFN FT$NIP,<

;NIP command processor
;
;	NIP <eol>

FALNIP:	PUSHJ	P,FALXIT	;RESTORE PRE-FAL STATE
	 JFCL			;NOT USED
	PJRST	NIP##		;AND SWITCH TO NIP MODE

> ;END IFN FT$NIP
	SUBTTL	Commands - TSC: Re/Enter TSC mode operation

IFN FT$TSC,<

;TSC command processor
;
;	TSC <eol>

FALTSC:	PUSHJ	P,FALXIT	;RESTORE PRE-FAL STATE
	 JFCL			;NOT USED
	PJRST	TSC##		;AND SWITCH TO TSC MODE

> ;END IFN FT$TSC
	SUBTTL	Commands - NETPPN: Set default "userid" ppn

;NETPPN command processor
;
;	NETPPN <ppn>

NPP:	JUMPLE	CH,[SETZ T1,		;SO CLEAR THE PPN
		JRST	NPP09]		;AND SET NO DEFAULT USER
	PUSHJ	P,.REEAT##	;MAY BE AN IMPORTANT CHARACTER
	PUSHJ	P,.FILIN##	;PARSE THE "PPN" (YEAH, IT REQUIRES [])
	SKIPE	T1,F.BLK##+.FXDIR  ;GET SPECIFIED PPN (IF ANY)
	AOSE	F.BLK##+.FXDIM	;MAKE SURE IT IS NON-WILD
	ERROR	NPP,<NETPPN command requires a non-wildcarded ppn>
NPP09:	MOVEM	T1,NETPPN	;SET DEFAULT NETWORK PPN
	PUSHJ	P,.CLEOL##	;EAT REST OF COMMAND LINE
	JRST	.POPJ1##	;THAT'S ALL FOR THE NETPPN COMMAND



;NONPP - Routine to check for and disallow NETPPN access

NONPP1:	MOVE	M0,.IOPPN(CI)	;GET ACCESSING PPN
	CAME	M0,NETPPN	;IS IT NETPPN?
	JRST	.POPJ1##	;NO, NO PROBLEM
	MOVEI	M0,$EFPRT	;YES, DISALLOW WITH A "PRIVILEGE VIOLATION"
	POPJ	P,		;AND TELL CALLER TO FLICK THIS REQUEST IN
	SUBTTL	Commands - REJECT: Specify incoming connect restraints

;REJECT command processor
;
;	REJECT <file-spec-list>
;
;Although the parser will syntactically accept full file specifications,
;most fields (e.g., file name) are semantically useless, and are ignored.

REJ:	JUMPLE	CH,ERRNIF##	;EOL HERE IS JUNK
	PUSHJ	P,REJC		;PARSE THE REST OF THE COMMAND
	 JRST	REJ70		;ERROR, FREE UP JUNKED FILE SPEC BLOCKS
	PUSHJ	P,REJD		;CHECK OUT/DEFAULT THE REJECT SPECS
	 JRST	REJ70		;ERROR, CLEAN UP THE MESS

;REMEMBER REJECT SETTINGS FOR FUTURE REFERENCE

	DMOVE	T1,SIFIR##	;GET FILE SPEC LIST
	DMOVEM	T1,REJFIR	;AND STASH THEM AWAY
	SETZM	SIFIR##		;DON'T LET ANYONE ELSE DEALLOCATE THEM!
	MOVE	T1,.JBFF	;GET CURRENT JOBFF
	MOVEM	T1,CMDFF##	;SET FOR WORLD TO SEE
	MOVEM	T1,SAVFF##	;AND THE UNIVERSE TOO
	HRLM	T1,.JBSA	;AND EVEN THE GODS THEMSELVES

;ALL FOR NOW

	JRST	.POPJ1##	;RETURN HAPPILY


;REJECT COMMAND-LEVEL ERROR

REJ70:	PUSHJ	P,FRESB##	;FREE UP ANY DANGLING FILE SPEC BLOCKS
	 JFCL			;HO HUM
	POPJ	P,		;PROPAGATE ERROR RETURN
;REJECT COMMAND PARSER

REJC:	SETZM	SIFIR##		;CLEAR OUT THE OLD DATA BASE
	PUSHJ	P,.REEAT##	;WANT .TSCAN TO SEE CURRENT CHARACTER!
	MOVE	T1,[REJTL,,REJTS]  ;.TSCAN BLOCK
	PUSHJ	P,.TSCAN##	;READ A COMMAND LINE
;	PUSHJ	P,CLRFIL	;CLEAR FILE ANSWERS BEFORE SWITCH.INI
;	MOVE	T1,[REJOL,,REJOS]  ;.OSCAN BLOCK
;	PUSHJ	P,.OSCAN##	;CHECK SWITCH.INI

;RETURN WITH FILE SPEC BLOCKS

	JRST	.POPJ1##	;HAPPY



;REJECT COMMAND DEFAULTER

REJD:	SKIPN	P1,SIFIR##	;ADDRESS OF FIRST FILE SPEC BLOCK
	 JRST	ERRNIF##	;MUST HAVE AN ARGUMENT

REJD10:	MOVE	T1,P1		;ADDRESS OF CURRENT FILE SPEC BLOCK
	MOVEI	T2,.FXMAX	;AND ITS LENGTH
;	PUSHJ	P,DOOSDF##	;APPLY SWITCH.INI DEFAULTS
	SKIPE	.FXNOD(P1)	;GOT A NODE SPEC?
	JRST	REJD13		;YES
	SKIPN	.FXDIR(P1)	;NO, THEN A DIRECTORY ("PPN") IS REQUIRED
	ERROR	RNP,<REJECT command requires at least node or ppn>
	JRST	REJD19		;NOTHING FURTHER TO DO

REJD13:	SKIPE	.FXDIR(P1)	;GOT A PPN AS WELL AS A NODE?
	JRST	REJD19		;YES, NOTHING MORE TO DO
	MOVE	T1,[377777,,777777]  ;NO, DEFAULT TO "[*,*]"
	SETZ	T2,		;FULL WILD MASK FOR "[*,*]"
	DMOVEM	T1,.FXDIR(P1)	;REJECT ALL PPN'S FROM SPECIFIED NODE
	MOVX	T1,FX.WDR	;THE WILDCARDS-IN-DIRECTORY FLAG
	IORM	T1,.FXFLD(P1)	;SET THAT ALSO

;LOOP FOR ALL FILE SPECS

REJD19:	ADDI	P1,.FXMAX	;ADVANCE TO NEXT FILE SPEC BLOCK
	CAMG	P1,SILAS##	;DONE THEM ALL YET?
	JRST	REJD10		;NO
	JRST	.POPJ1##	;YES, ALL DONE HERE THEN
;"REJECT" TSCAN PARAMETER BLOCK

	REJSWL==<REJSWN==<REJSWD==<REJSWM==<REJSWP==0>>>>  ;NO REJECT SWITCHES

REJTS:	EXP	FXVRSN		;PROTOCOL VERSION WORD
	IOWD	REJSWL,REJSWN	;IOWD POINTER FOR SWITCH NAMES
	XWD	REJSWD,REJSWM	;DEFAULT TABLE,,PROCESSOR TABLE
	XWD	0,REJSWP	;<FUTURE>,,STORAGE POINTERS
	SIXBIT	/FAL/		;HELP
	XWD	CLRALL,CLRFIL	;CLEAR ALL,,CLEAR FILE
	XWD	INX,OUX		;ALLOC INPUT AREA,,ALLOC OUTPUT AREA
	XWD	MEMSTK,APLSTK	;MEMORIZE STICKY,,APPLY STICKY
	XWD	CLRSTK,0	;CLEAR STICKY,,FLAGS
	Z			;<FUTURE>,,SWITCH VALUE STORAGE RTN

	REJTL==.-REJTS



;"REJECT" OSCAN BLOCK

REJOS:	EXP	FXVRSN		;PROTOCOL VERSION WORD
	IOWD	REJSWL,REJSWN	;IOWD POINTER FOR SWITCH NAMES
	XWD	REJSWD,REJSWM	;DEFAULT TABLE,,PROCESSOR TABLE
	XWD	0,REJSWP	;<FUTURE>,,STORAGE POINTERS
	SIXBIT	/FAL/		;HELP
	XWD	REJOSL,REJOSN	;OPTIONS NAME(S)

	REJOL==.-REJOS

REJOSN:	SIXBIT	\REJECT\
	SIXBIT	\FAL\
	SIXBIT	\NFT\

	REJOSL==.-REJOSN
	SUBTTL	Commands - START: Enter passive FAL receive mode

;START command processor
;
;	START ["ANF" ! "DECNET"]

FGO:	PUSHJ	P,FGOC		;READ REST OF "START" COMMAND
	 POPJ	P,		;OOPS
	PUSHJ	P,FGOD		;SETUP FAL PROCESSING DEFAULTS
	 POPJ	P,		;SOMETHING DOESN'T MESH

FGO030:	PUSHJ	P,FALL		;ENTER MAIN FAL "LOOP"
	 JFCL			;***
	STOPCD	<FALL returned???>



FGOC:	MOVX	T1,$NTFAL	;GET DEFAULT NET TYPE
	JUMPL	CH,FGOC12	;IF EOL, THEN DEFAULT NET TYPE
	PUSHJ	P,.SIXSC##	;READ IN NET TYPE
	MOVE	T2,NM		;PLACE USER SPEC FOR .LKNAM
	MOVE	T1,[IOWD 2,[FLTAB: 'ANF   '  ;THE POSSIBILITIES
				   'DECNET']];END OF POSSIBILITIES
	PUSHJ	P,.LKNAM##	;MATCH NET TYPE
	 ERROR	UNT,<Unknown network type; specify "ANF" or "DECNET">
	SUBI	T1,FLTAB	;MAKE INTO INDEX
	MOVE	T1,[EXP IO.ANF,IO.DCN](T1)  ;TRANSLATE INTO CDB JARGON
FGOC12:	MOVEM	T1,FALTYP	;SAVE FOR FALLI
	MOVE	T1,[$NTPPN]	;DEFAULT NETPPN
	SKIPN	NETPPN		;HAS OPERATOR SPECIFIED A NETPPN?
	MOVEM	T1,NETPPN	;NO, SUPPLY PROGRAM DEFAULT NETPPN
	PUSHJ	P,.CLEOL##	;EAT REST OF COMMAND
	JRST	.POPJ1##	;SUCCESSFUL RETURN FOR NOW



FGOD:	SETOM	S.MOAN##	;WANT WARNINGS
	JRST	.POPJ1##	;NOTHING HERE YET EITHER
	SUBTTL	FAL initialization - FALINI set FAL job parameters

;FALINI  --  INITIALIZE FAL JOB RUNTIME PARAMETERS
;Call is:
;
;	PUSHJ	P,FALINI
;	 error return
;	normal return
;
;FALINI sets up FAL's runtime job parameters so that FAL stands a chance
;of working:
;
;	1)	Set program name to "FAL-10" 'cuz it looks purty
;
;	2)	DSKFUL ERROR so that error codes returned to FAL rather
;		than stopping the job and barfing on the "user"
;
;	3)	LOCATE 0 so that batch/etc. submissions via QUEUE. UUO
;		work right (else batch jobs end up on a DN87's "processor"
;		queue! Amusing, but...)
;
;	4)	SPOOL ALL so that randoms from remote places can't tie up
;		real lineprinters or whatever. This is somewhat dubious,
;		but since DAP doesn't give the user choice of real or
;		spooled, this is the most "practical" choice . . .
;
;The error return is not exercised.
;
;Uses T1, T2.

FALINI:	MOVE	T1,.JBFF	;REMEMBER FAL'S JOBFF VALUE
	MOVEM	T1,FJBFF	;FOR FUTURE USE

;SET PROGRAM NAME TO "FAL-10"

	HRROI	T1,.GTPRG	;GETTAB ARG TO
	GETTAB	T1,		;READ PROGRAM NAME
	 MOVSI	T1,'NFT'	;FAILED??? IN THIS DAY AND AGE???
	MOVEM	T1,FGTPRG	;REMEMBER PROGRAM NAME
	MOVE	T2,['FAL-10']	;TENTATIVE NAME
	SETNAM	T2,		;DECLARE MORE MEANINGFUL PROGRAM NAME

;CONTINUED ON NEXT PAGE
;CONTINUED FROM PREVIOUS PAGE

;SET DSKFUL ERROR SO GET ERRORS WE CAN RETURN TO REMOTE ACCESSOR

	HRLOI	T1,.STDFL	;ARGUMENT TO SETUUO TO
	SETUUO	T1,		;READ DSKFUL ERROR/PAUSE
	 MOVEI	T1,.DFERR	;DEFAULT TO ERROR
	MOVEM	T1,FSTDFL	;REMEMBER ORIGINAL SETTING
	MOVE	T1,[.STDFL,,.DFERR]  ;ARGUMENT TO SETUUO TO
	SETUUO	T1,		;SET DSKFUL ERROR
	 WARN	DFL,<Can't set DSKFUL ERROR>

;LOCATE TO CENTRAL HOST SO BATCH JOB SUBMISSION A LA QUEUE. UUO WORKS

	MOVSI	T1,'OPR'	;USE NAME "OPR" TO
	WHERE	T1,UU.PHY	;FIND OUT WHERE WE ARE "LOCATE"D
	 SETZ	T1,		;DUH? NO NETWORKS???
	MOVEM	T1,FLOCAT	;REMEMBER ORIGINAL SETTING
	SETZ	T1,		;0 = CENTRAL HOST
	LOCATE	T1,		;PUT US THERE TO NOT CONFUSE GALAXY
	 WARN	LCS,<Can't LOCATE to central site>

;SET SPOOL ALL (IT'S A COP OUT, BUT DAP DOESN'T GIVE US PROPER CONTROL!)

	HRROI	T1,.GTSPL	;GETTAB ARG POINTER TO
	GETTAB	T1,		;READ JOB'S SPOOLING SETTING
	 MOVEI	T1,JS.PAL	;DUH? ASSUME SPOOL ALL
	MOVEM	T1,FGTSPL	;REMEMBER IT
	MOVE	T1,[.STSPL,,JS.PAL]  ;SETUUO ARGUMENT TO
	SETUUO	T1,		;SET SPOOL ALL
	 WARN	SPL,<Can't SET SPOOL ALL>

	JRST	.POPJ1##	;SUCCESSFUL RETURN BY DEFINITION
;FALXIT  --  EXIT FAL AND RETURN TO WHATEVER
;Call is:
;
;	PUSHJ	P,FALXIT
;	 error return
;	normal return
;
;FALXIT undoes FALINI, restoring the job's "state" . . .
;
;The error return is not used.
;
;Uses T1, T2.

FALXIT:	MOVSI	T1,.STSPL	;SETUUO FUNCTION SET SPOOL
	HRR	T1,FGTSPL	;RETRIEVE JOB'S ORIGINAL SPOOLING PARMS
	SETUUO	T1,		;SET SPOOL TO ORIGINAL SPECS
	 JFCL			;HOHUM
	MOVE	T1,FLOCAT	;RETRIEVE JOB'S ORIGINAL LOCATE VALUE
	LOCATE	T1,		;AND PUT IT BACK
	 JFCL			;HOHUM
	MOVSI	T1,.STDFL	;SETUUO FUNCTION SET DSKFUL
	HRR	T1,FSTDFL	;RETRIEVE JOB'S ORIGINAL DSKFUL VALUE
	SETUUO	T1,		;SET DSKFUL TO ORIGINAL SPEC
	 JFCL			;HOHUM
	MOVE	T1,FGTPRG	;RETRIEVE JOB'S ORIGINAL NAME
	SETNAM	T1,		;AND PUT IT BACK
	MOVE	T1,FJBFF	;RETRIEVE JOB'S ORIGINAL JOBFF
	MOVEM	T1,.JBFF	;AND PUT IT BACK
	MOVEM	T1,CMDFF##	;TELL REST OF WORLD TOO
	MOVEM	T1,SAVFF##	;TELL REST OF UNIVERSE ALSO
	HRLM	T1,.JBSA	;*** FINALLY TELL EVEN THE GODS . . .
	JRST	.POPJ1##	;BACK WHERE WE STARTED!
	SUBTTL	FAL initialization - UTXINI initialize USERS.TXT buffer

;UTXINI  --  INITIALIZE USERS.TXT BUFFER
;Call is:
;
;	PUSHJ	P,UTXINI
;	return
;
;On return, UTXCTR and UTXPTR are the byte counter and pointer to the
;USERS.TXT name to ppn translation buffer, or 0 if no translation is to
;be performed.
;
;*** This routine needs much smartening . . .
;
;Uses T1 - T4, P1 - P4.

IFN FTUTXT,<

UTXINI:	OPEN	UTX,[.IODMP	;DUMP MODE I/O HERE FOR CONVENIENCE
		  'SYS   '	;FROM DEVICE SYS:
		  0,,0]		;WITH NO RING HEADERS
	 JRST	 UTXIE0		;NO, BOMB IT OUT
	MOVE	P1,.JBFF	;ADDRESS OF START OF BUFFER AREA
	MOVEI	T1,.RBSIZ+1(P1)	;END ADDRESS OF LOOKUP BLOCK
	CORE	T1,		;ALLOCATE MEMORY FOR LOOKUP BLOCK
	 JRST	UTXIE5		;CAN'T EVEN GET A LOOKUP BLOCK???
	MOVEI	T1,.RBSIZ+1	;EXTENDED LOOKUP BLOCK LENGTH
	MOVEM	T1,.RBCNT(P1)	;SET IN THE LOOKUP BLOCK
	SETZM	.RBPPN(P1)	;NO EXPLICIT PATH
	DMOVE	T1,[EXP 'USERS ','TXT   ']  ;USERS.TXT
	DMOVEM	T1,.RBNAM(P1)	;SET IN THE LOOKUP BLOCK
	LOOKUP	UTX,(P1)	;SEE IF THE FILE IS AVAILABLE
	 JRST	UTXIEL		;NO, BOMB IT OUT
	MOVE	P2,.RBSIZ(P1)	;SIZE OF FILE (DATA WORDS WRITTEN)
	MOVE	T1,P1		;ADDRESS OF START OF BUFFER
	ADDI	T1,-1(P2)	;ADDRESS OF END OF BUFFER
	CORE	T1,		;MAKE SURE THE BUFFER WILL FIT
	 JRST	UTXIE5		;NO, BOMB IT OUT
	MOVN	T1,P2		;IOWDS WANT NEGATIVE LENGTH
	HRLZ	T1,T1		; IN THE LEFT HALF
	HRRI	T1,-1(P1)	;AND ADDRESS-1 IN THE RIGHT HALF
	SETZ	T2,		;TERMINATE THE I/O LIST
	IN	UTX,T1		;READ IN USERS.TXT
	CAIA			;BINGO!
	 JRST	UTXIE6		;NO, BOMB IT OUT
	RELEAS	UTX,		;WE ARE DONE WITH THE FILE NOW
	HRLI	P1,(POINT 7,)	;BYTE POINTER TO USERS.TXT BUFFER
	MOVEM	P1,UTXPTR	;REMEMBER USERS.TXT BUFFER POINTER
	IMULI	P2,5		;BYTE COUNTER FOR USERS.TXT BUFFER
	MOVE	P3,P1		;BYTE POINTER TO WRITE USERS.TXT

;CONTINUED ON NEXT PAGE
;CONTINUED FROM PREVIOUS PAGE

;STILL IFN FTUTXT

;USERS.TXT contains ASCII ppn<=>name correspondences of the form
;"dev:[p,pn],name" (this format is defined by the MS mail proggie).
;Internally, they will be compressed to just "[p,pn]name<LF>" form.

UTXIN2:	PUSHJ	P,UTXGT1	;GET ONE USERS.TXT CHARACTER
	 JRST	UTXIN9		;DONE, REMEMBER IT
	CAIE	T1,"["		;START OF PPN YET?
	JRST	UTXIN2		;NO, SKIP REST OF DEVICE PORTION
UTXIN3:	PUSHJ	P,UTXPT1	;YES, SAVE START OF PPN FIELD
	 JRST	UTXIE7		;NO, BOMB OUT
	PUSHJ	P,UTXGT1	;GET NEXT USERS.TXT CHARACTER
	 JRST	UTXIN9		;DONE
	CAIE	T1,"]"		;END OF PPN PART YET?
	JRST	UTXIN3		;NO, STILL PPN, SAVE IT
	PUSHJ	P,UTXPT1	;YES, CAP OFF PPN
	 JRST	UTXIE7		;BOMB IT OUT
	PUSHJ	P,UTXGT1	;NEXT INPUT CHARACTER
	 JRST	UTXIN9		;DONE
	CAIE	T1,","		;SHOULD BE A COMMA
	JRST	UTXIN2		;NO, JUST RESTART, JUNKING THIS ENTRY . . .
UTXIN5:	PUSHJ	P,UTXGT1	;GET NAME CHARACTER
	 JRST	UTXIN9		;DONE
	PUSHJ	P,UTXPT1	;AND SAVE IT TOO
	 JRST	UTXIE7		;DOMB IT OUT
	CAIE	T1,.CHLFD	;END OF PPN<=>NAME ENTRY?
	JRST	UTXIN5		;NO, FINISH OFF NAME
	JRST	UTXIN2		;YES, DO NEXT ENTRY

;Here when completed successfully

UTXIN9:	MOVEI	T1,.CHLFD	;A <LF> CHARACTER
	PUSHJ	P,UTXPT1	;ENSURE USERS.TXT BUFFER ENDS WITH A <LF>
	 JRST	UTXIE7		;HOW INCONVENIENT A PLACE TO BOMB
	TDZA	T1,T1		;A NULL CHARACTER
	IDPB	T1,P3		;STASH ANOTHER NULL
	TXNE	P3,74B5		;BYTE POINTER FILLED UP A WORD YET?
	JRST	.-2		;NO, ZERO-FILL THE WORD
	MOVEI	P1,1(P3)	;END ADDRESS+1 OF USERS.TXT BUFFER
	MOVE	T2,.JBFF	;START ADDRESS OF USERS.TXT BUFFER
	SUBM	P1,T2		;T2:=COUNT OF WORDS IN BUFFER
	IMULI	T2,5		;T2:=COUNT OF BYTES IN BUFFER
	MOVEM	T2,UTXCTR	;SAVE BYTE COUNTER FOR UTXPTR
	MOVEM	P1,.JBFF	;MARK THAT WE NOW OWN USERS.TXT BUFFER
	MOVEM	P1,CMDFF##	;TELL REST OF WORLD TOO
	MOVEM	P1,SAVFF##	;TELL REST OF THE UNIVERSE ALSO
	HRLM	P1,.JBSA	;*** FINALLY, TELL EVEN THE GODS . . .
	JRST	.POPJ1##	;HAPPY
;STILL IFN FTUTXT

;Here when error setting up USERS.TXT

UTXIEL:	HRRZ	T1,.RBEXT(P1)	;RETRIEVE LOOKUP ERROR CODE
	CAIN	T1,ERPRT%	;PROTECTION FAILURE?
	JRST	UTXIE1		;YES
	CAIN	T1,ERTRN%	;RIB/DIRECTORY ERROR?
	JRST	UTXIE2		;YES
	CAIE	T1,ERFNF%	;FILE NOT FOUND?
	JRST	UTXIE3		;RANDOM ERROR
	INFRM	UTM,<No SYS:USERS.TXT file, no names <=> ppn translation will be performed>
	AOS	(P)		;TAKE HAPPY (ALBEIT FAILED IN THIS CASE) RETURN
	PJRST	UTXINE		;BLAST AWAY THE I/O CHANNEL

UTXIE0:	ERROR	UT0,<Can't OPEN device SYS: for SYS:USERS.TXT>,,,UTXINE
UTXIE1:	ERROR	UT1,<Protection failure reading file SYS:USERS.TXT>,,,UTXINE
UTXIE2:	ERROR	UT2,<RIB error reading file SYS:USERS.TXT>,,,UTXINE
UTXIE3:	ERROR	UT3,<Can't LOOKUP file SYS:USERS.TXT>,,,UTXINE
UTXIE5:	ERROR	UT5,<Can't get memory to read SYS:USERS.TXT>,,,UTXINE
UTXIE6:	ERROR	UT6,<Can't read file SYS:USERS.TXT>,,,UTXINE
UTXIE7:	ERROR	UT7,<Format error reading SYS:USERS.TXT>,,,UTXINE

UTXINE:	RELEAS	UTX,		;STOMP ON I/O CHANNEL
	SETZM	UTXPTR		;MARK NO USERS.TXT BUFFER
	MOVE	T1,.JBFF	;START OF BUFFER
	CORE	T1,		;DEALLOCATE NOW-USELESS BUFFER
	 JFCL			;HO HUM
	POPJ	P,		;AND THAT IS THAT
;STILL IFN FTUTXT

;UTXGT1 - GET ONE USERS.TXT CHARACTER

UTXGT1:	SOJL	P2,.POPJ##	;ERROR IF NO MORE
	ILDB	T1,P1		;NEXT INPUT CHARACTER
	JUMPE	T1,UTXGT1	;SUPPRESS NULLS
	CAIN	T1,.CHCRT	;<CR>?
	JRST	UTXGT1		;YES, JUST RETURN THE <LF>
	CAIE	T1," "		;SPACE?
	CAIN	T1,.CHTAB	; OR TAB?
	JRST	UTXGT1		;YES, SUPPRESS
	CAIE	T1,";"		;COMMENT?
	CAIN	T1,"!"		; ALTERNATE COMMENT?
	JRST	UTXGT3		;YES, EAT IT UP
	CAIL	T1,"a"		;LOWERCASE ALPHA?
	CAILE	T1,"z"		; . . .
	JRST	.POPJ1##	;NO, RETURN VALID CHARACTER
	SUBI	T1,"a"-"A"	;SHIFT TO UPPERCASE ALPHA
	JRST	.POPJ1##	;AND RETURN IT

UTXGT3:	SOJL	P2,.POPJ##	;ERROR IF NO MORE
	ILDB	T1,P1		;NEXT CHARACTER
	CAIN	T1,.CHLFD	;END OF LINE (COMMENT) YET?
	JRST	UTXGT3		;NO, KEEP EATING
	JRST	.POPJ1##	;YES, RETURN END OF LINE



;UTXPT1  --  WRITE ONE USERS.TXT CHARACTER

UTXPT1:	IDPB	T1,P3		;STASH VALID CHARACTER
	JRST	.POPJ1##	;ALL DONE!

> ;END IFN FTUTXT
	SUBTTL	Main FAL processing loop

FALL:	PUSHJ	P,FALLI		;INITIALIZE A FAL JOB PROCESS
	 JRST	FALL70		;CHECK OUR ERROR
	JRST	FALL		;LOOP HERE FOR NOW


;HERE ON ERROR FROM FALLI

FALL70:	CAIE	M0,$EFUID	;DID WE REJECT THE USER ID?
	CAIN	M0,$EFUAC	;DID WE REJECT THE USER ACCOUNT DATA?
	JRST	FALL77		;YES, RETRY IMMEDIATELY
	CAIN	M0,$EINLA	;DID LINK "TERMINATE" NORMALLY?
	JRST	FALL77		;YES, RETRY IMMEDIATELY
	CAIN	M0,$EFNNS	;GOT ANY NETWORK SOFTWARE?
	STOPCD	<No network software, aborting FAL>
	CAIN	M0,$EFPRV	;PRIVILEGE VIOLATION?
	STOPCD	<Insufficient privileges, aborting FAL>

;LINK TERMINATED ABNORMALLY - USE SLIDING WAIT INTERVAL TO ALLOW
;THE WORLD TO CALM DOWN

	SKIPN	T1,FALSLP	;GET THE SLEEPER VALUE
	MOVEI	T1,1		;NONE, START WITH 1
	LSH	T1,1		;DOUBLE THE INTERVAL
	CAILE	T1,^D64		;TIME GOTTEN TOO BIG?
	MOVEI	T1,^D64		;YES, PEG AT ABOUT ONE MINUTE WAITS
	MOVEM	T1,FALSLP	;SAVE FOR NEXT TIME
	SLEEP	T1,		;WAIT A BIT FOR THE WORLD TO SETTLE DOWN
	JRST	FALL		;NOW TRY AGAIN

FALL77:	JRST	FALL		;JUST TRY AGAIN IMMEDIATELY
;INITIALIZE ONE FAL JOB PROCESS

FALLI:	MOVE	P1,FALTYP	;SELECT EITHER ANF (IO.ANF) OR DECNET (IO.DCN)
	PUSHJ	P,FALJB		;FIRE UP A SINGLE FAL JOB STREAM
	 SKIPA	P1,M0		;SAVE ERROR CODE FROM FALJB
	SETZ	P1,		;FLAG NO ERROR
FALLI2:	SKIPN	T2,CI		;PRIMARY CDB ADDRESS
	JRST	FALLI4		;NONE?
	SKIPN	T1,.IOXSZ(T2)	;SIZE OF CDB ALLOCATED
	MOVE	T1,.IOSIZ(T2)	;SIZE OF CDB ALLOCATED
	PUSHJ	P,.MMFWD##	;DEALLOCATE THE CDB
	 STOPCD			;CAN'T FAIL
FALLI4:	SKIPN	T2,CO		;SLAVE CDB ADDRESS
	JRST	FALLI6		;NONE
	SKIPN	T1,.IOXSZ(T2)	;SIZE OF CDB ALLOCATED
	MOVE	T1,.IOSIZ(T2)	;SZIE OF CDB ALLOCATED
	PUSHJ	P,.MMFWD##	;DEALLOCATE THE CDB
	 STOPCD			;CAN'T FAIL

FALLI6:	RESET			;CLEAN UP THE WORLD

	JUMPE	P1,.POPJ1##	;RETURN HAPPILY IF SUCCESSFUL
	MOVE	M0,P1		;RESTORE ERROR CODE TO STATUS REGISTER
	POPJ	P,		;AND PROPAGATE FALJB'S ERROR
	SUBTTL	FAL "JOB" process

;STARTUP A FAL PROCESS

FALJB:	SETZB	CI,CO		;NO CDB'S ALLOCATED YET

;ALLOCATE AND INITIALIZE PRIMARY CDB FOR THE NETWORK-BASED LINK

	MOVEI	T2,FALIV	;FAL'S INIT STUFF
	PUSHJ	P,.IOINA##	;ALLOCATE AND INITIALIZE PRIMARY CDB
	 JRST	ERRCDI##	;DUH?
	MOVE	CI,T1		;REMEMBER PRIMARY CDB ADDRESS

;FROM HERE ON FAL OPERATES IN A "NATIVE" MODE RE THE I/O PACKAGE, FREELY
;USING T1 - P4, AND IO AS THE I/O CDB INDEX.
;
;THIS SAVES OODLES OF AC PUSHING/SHOVING/POPPING!

	MOVE	IO,CI		;SELECT THE PRIMARY CDB
	IORM	P1,.IOCCF(IO)	;SELECT REQUESTED NETWORK PROTOCOL

;SETUP THE DESTINATION (THAT'S US) PROCESS DESCRIPTOR BLOCK

FALOBJ:!MOVX	T3,<0,,21>	;GENERIC FAL FORMAT/OBJECT TYPE
	MOVEM	T3,.IONDF(IO)	;SET IN THE CDB
	SETZM	.IONDP(IO)	;NO PPN SPECIFIED
	SETZM	.IONDN(IO)	;NOR ANY SPECIFIC PROCESS NAME

;SETUP THE SOURCE (REMOTE NFT/ETC.) PROCESS DESCRIPTOR BLOCK

	MOVX	T3,<0,,-1>	;GENERIC ANYTHING FORMAT/OBJECT TYPE
	MOVEM	T3,.IONSF(IO)	;SOURCE FORMAT/OBJECT (DON'T CARE)
	SETZM	.IONSP(IO)	;SOURCE PPN (DON'T CARE)
	SETZM	.IONSN(IO)	;SOURCE NAME (DON'T CARE)

;NO OTHER RESTRICTIONS EITHER

	SETZM	.IONUS(IO)	;USER ID (DON'T CARE)
	SETZM	.IONPW(IO)	;USER PASSWORD (DON'T CARE)
	SETZM	.IONAC(IO)	;USER ACCOUNT STRING (DON'T CARE)
	SETZM	.IONUD(IO)	;USER DATA (DON'T CARE)

;TELL MONITOR WHAT WE'RE UP TO

FALJ20:	SETZ	T2,		;ANY NODE OK
	PUSHJ	P,NTNIP1##	;INITIALIZE A PASSIVE NETWORK CHANNEL
	 POPJ	P,		;OOPS - NETWORK NOT BEING COOPERATIVE

;NOW WAIT FOR SOMEONE, SOMEWHERE, SOMETIME, . . .

FALJ30:	PUSHJ	P,NTNCW1##	;WAIT FOR A RECEIVED CONNECT INITIATE
	 POPJ	P,		;HMMM - A RECALCITRANT NOTWORK

;WE HAVE A CONNECT, SEE IF WE ARE WILLING TO CONSIDER IT

FALJ32:	MOVX	T1,%CNSTS	;GETTAB POINTER TO
	GETTAB	T1,		;READ THE SYSTEM "STATES" FLAGS
	 SETZ	T1,		;DUH?
	TXNE	T1,ST%NRT!ST%NLG;DEBUGGING/ETC?
	JRST	FALJR0		;YES, REJECT "ABORT BY DIALOG PROCESS"
	MOVX	T1,%NSKTM	;GETTAB POINTER TO
	GETTAB	T1,		;READ THE KSYS TIMER VALUE
	 SETZ	T1,		;DUH?
	JUMPL	T1,FALJR1	;REJECT "NODE SHUTTING DOWN"
	XMOVEI	P1,.IONUS(IO)	;ADDRESS OF USER ID STRING
	HLRZ	T1,@P1		;GET USER ID STRING LENGTH (IF ANY)
	LDB	T2,[POINT 8,.IONUS+1(IO),7]  ;*** PEEK AT FIRST BYTE
	CAIN	T2,0		;*** ANYTHING THERE?
	SETZ	T1,		;*** NO - VAX SENDS 4 NULLS!!!!!
	JUMPE	T1,[SKIPN T1,NETPPN	;FETCH DEFAULT USER NETPPN
		JRST	FALJR2		;NONE, REJECT USERID
		MOVEM	T1,.IOPPN(IO)	;SET DEFAULT "ON-BEHALF-OF" PPN
		DMOVE	T1,[EXP 'NETWOR', 'K USER']  ;FAKE UP A USER NAME
		DMOVEM	T1,.IOQ6N(IO)	;SET DEFAULT USER NAME TOO
		SETZM	.IOACT(IO)	;WITH NO ACCOUNT STRING
		JRST	FALJ34]		;AND ALLOW THE NETWORK CONNECTION
	PUSHJ	P,F8BUP		;CONVERT 8-BIT USERID STRING INTO PPN
	 JRST	FALJR4		;CAN'T MAKE A PPN, JUNK USER ID
	MOVEM	T1,.IOPPN(IO)	;SET "ON-BEHALF-OF" PPN
FALJ34:	PUSHJ	P,FALCR1	;SEE IF NODE/PPN REJECTED BY COMMAND
	 JRST	FALJR2		;YES, REJECT USERID
	XMOVEI	P1,.IONAC(IO)	;ADDRESS OF USER ACCOUNT STRING
	XMOVEI	T1,.IOACT(IO)	;WHERE TO STORE ASCIZ STRING
	PUSHJ	P,F8BAZ		;COPY AND ASCIZIZE STRING
	 JRST	FALJR4		;JUNK ACCOUNT STRING
	XMOVEI	P1,.IONPW(IO)	;ADDRESS OF USER ID PASSWORD
	PUSHJ	P,F8B6B		;CONVERT 8-BIT STRING INTO 6-BIT WORD
	 JRST	FALJR4		;JUNK PASSWORD STRING

;VERIFY THE USERID/PASSWORD/ACCOUNT

FALJ37:	MOVE	T2,.IOPPN(IO)	;RETRIEVE COPY OF ACCESSING PPN
	CAMN	T2,NETPPN	;IS THIS THE DEFAULT USER PPN?
	JRST	FALJ40		;YES, THEN IT WORKS.
	MOVE	T3,T1		;POSITION PASSWORD IN T3
	MOVEI	T2,.QUMAE	;ACCESS VALIDATION
	PUSHJ	P,QUEOP1##	;ASK ACTDAE IF USER IS A GOOD GUY
	 SKIPA	T2,M0		;CAN'T VALIDATE USERID/ETC.
	JRST	FALJ40		;USERID/ETC OK, USER NAME/ETC SETUP
	JSP	T4,.CDISP##	;DISPATCH BASED ON ERROR
		FALJR2,,$EQILP	;ILLEGAL PPN/USERID
		FALJR2,,$EQIPW	;INVALID PASSWORD
		FALJR3,,$EQIVA	;INVALID ACCOUNT STRING
		0		;NO OTHERS RETURN AN ERROR

;HERE WHEN CAN'T VALIDATE USERID/ETC., REJECT UNLESS DEBUGGING

FALJ3A:	CAIN	M0,$EQCNR	;"COMPONET NOT RUNNING"? (I.E., NO ACTDAE)
	ERROR	ANR,<ACTDAE not running, can't validate USERID/etc.>,,,FALJR4
	CAIE	M0,$EQPRA	;LACKING PRIVILEGES TO DO ACCOUNTING?
	ERROR	QUF,<QUEUE. UUO failed for FALJ40>,,,FALJR4
	MOVE	T1,.MYPPN##	;GET MY JOB'S PPN
	CAME	T1,.PPFFA##	;AM I [OPR]?
	SKIPN	.JBDDT		;NO, ALLOW IF DEBUGGING
	JRST	FALJR4		;CALL FUNNY USERID/ETC ERROR
	INFRM	UAR,<Can't validate USERID/PASSWORD/ACCOUNT, continuing for DDT>,,,FALJ40
;VALID USER ID, ACCEPT NETWORK CONNECTION

FALJ40:	SETZB	T2,T3		;NO OPTIONAL CONNECT CONFIRM DATA
	PUSHJ	P,NTNCA1##	;SEND A CONNECT ACCEPT MESSAGE
	 POPJ	P,		;BUTTS

;BUILD BUFFERS FOR FURTHER "REAL" COMMUNICATIONS

FALJ45:	PUSHJ	P,NTINI1##	;BUILD BUFFERS ETC.
	 POPJ	P,		;BUTTS

;EXCHANGE CONFIGURATION MESSAGES WITH THE REMOTE DAP PROCESS

FALJ50:	PUSHJ	P,DPICM1##	;EXCHANGE CONFIGURATION MESSAGES
	 ERROR	FCM,<Error exchanging CONFIG messages with node >,.TSIXN,.ION6M(IO)
	SETZM	FALSLP		;GOOD CONNECT, RESET WAIT INTERVAL
	PJRST	FJOB00		;ENTER FAL JOB MAIN LOOP
;SEE IF INCOMING CONNECT REQUEST IS REJECTED BY OPERATOR COMMAND

FALCR1:	SKIPN	P1,REJFIR	;GOT A REJECTION LIST?
	JRST	.POPJ1##	;NO, INCOMING CONNECT OK BY US

;LOOP CHECKING AGAINST THE REJECTION LIST, SPEC BY SPEC

FALCR2:	SKIPN	T1,.FXNOD(P1)	;GET REJECTED NODE SPEC
	JRST	FALCR5		;NO NODE, JUST CHECK THE PPN
	XOR	T1,.ION6M(IO)	;COMPARE AGAINST CONNECTING NODE
	TDNE	T1,.FXNOM(P1)	;DOES THIS NODE MATCH THE REJECTION?
	JRST	FALCR9		;NO, SKIP TO NEXT SPEC THEN
FALCR5:	MOVE	T2,.FXDIR(P1)	;GET REJECTED PPN SPEC
	XOR	T2,.IOPPN(IO)	;COMPARE AGAINST CONNECTING USERID
	TDNN	T2,.FXDIM(P1)	;DOES THIS PPN MATCH THE REJECTION?
	POPJ	P,		;YES, USERID REJECTED
FALCR9:	ADDI	P1,.FXMAX	;DOESN'T MATCH THIS REJECTION SPEC, ADVANCE
	CAMG	P1,REJLAS	;ANY MORE SPECS TO CHECK?
	JRST	FALCR2		;YES
	JRST	.POPJ1##	;NO, INCOMING CONNECT NOT REJECTED HERE
;CONNECT REJECTS COME HERE

FALJR0:	MOVEI	T3,^D09		;REJECT "BY DIALOGE PROCESS"
	JRST	FALRJ1		;COMMON CODE

FALJR1:	MOVEI	T3,^D03		;REJECT "NODE SHUTTING DOWN"
	JRST	FALRJ1		;COMMON CODE

FALJR2:	MOVEI	T3,^D34		;REJECT "INVALID PPN/PASSWORD"
	JRST	FALRJ1		;COMMON CODE

FALJR3:	MOVEI	T3,^D36		;REJECT "INVALID ACCOUNT STRING"
	JRST	FALRJ1		;COMMON CODE

FALJR4:	MOVEI	T3,^D43		;REJECT GENERAL IMAGE FIELD FORMAT ERROR
	JRST	FALRJ1		;COMMON CODE


;ALL CONNECT REJECTS COME THROUGH HERE

FALRJ1:	SETZ	T2,		;NO OPTIONAL DISCONNECT DATA
	PUSHJ	P,NTNCR1##	;REJECT THE CONNECT
	 JFCL			;DUH???
	MOVEI	M0,$EFUID	;DECLARE THIS TERMINATION "USERID"
	POPJ	P,		;END OF THIS ACCESS
;TOP-LEVEL OR MAIN FAL "JOB" PROCESS IDLE LOOP - WAIT FOR SOMETHING TO DO

FJOB00:	MOVE	IO,CI		;SELECT PRIMARY CDB
	PUSHJ	P,RDMSG1##	;START UP FIRST DAP MESSAGE
	 JRST	.POPJ1##	;ASSUME ALL DONE

;WE HAVE SOMETHING TO DO, INITIALIZE THE SLAVE CDB AND GO DO IT

	JUMPN	CO,FJOB03	;JUST RESET SLAVE IF ALREADY ALLOCATED
	MOVEI	T2,FALIV	;FAL'S INIT STUFF
	PUSHJ	P,.IOINA##	;ALLOCATE AND INITIALIZE SLAVE CDB
	 JRST	ERRCDO##	;DUH?
	MOVE	CO,T1		;REMEMBER SLAVE CDB ADDRESS
	JRST	FJOB07		;CLEAR OUT COMMUNICATIONS AREAS

;HERE WHEN ALREADY HAVE A SLAVE CDB, AS AFTER AN ACCESS COMPLETE, WITH
;MORE ACCESS MESSAGES COMING UP

FJOB03:	MOVE	IO,CO		;SELECT SLAVE CDB
	SKIPN	.IOCHN(IO)	;GOT AN I/O CHANNEL?
	SKIPE	.IONCH(IO)	;OR A NETWORK CHANNEL?
	CAIA			;YES???
	JRST	FJOB05		;NO
	INFRM	ASS,<Aborting stale slave CDB I/O>
	PUSHJ	P,IOABO1##	;ABORT WHATEVER IS THERE
	 JFCL			;HOHUM
FJOB05:	MOVE	T1,CO		;ADDRESS OF SLAVE CDB
	MOVEI	T2,FALIV	;FAL'S INIT STUFF
	PUSHJ	P,.IOINI##	;[RE-]INITIALIZE SLAVE CDB
				; IN PARTICULAR, CLEAR OUT OLD .IOFSB
				; AND RESET .IOXFF
	 JRST	ERRCDO##	;DUH?

;SETUP THE CDB FOR SLAVE USAGE BY REST OF FAL

FJOB07:	MOVX	T2,IO.SLV	;THE "SLAVE" BIT
	IORM	T2,.IOCCF(CO)	;MARK THE SLAVE CDB (E.G., FOR QUEOP)

;SET "ON-BEHALF-OF" STUFF IN THE SLAVE CDB (WHERE IT REALLY COUNTS)

	MOVE	T1,.IOPPN(CI)	;"ON-BEHALF-OF" PPN
	MOVEM	T1,.IOPPN(CO)	;COPY IT INTO THE SLAVE CDB
	MOVSI	T1,.IOACT(CI)	;"ON-BEHALF-OF" ACCOUNT STRING
	HRRI	T1,.IOACT(CO)	;WHERE WE WANT IT
	BLT	T1,.IOACT+7(CO)	;LEAVE IT FOR FILOP ETC. TO FIND
	DMOVE	T1,.IOQ6N(CI)	;"ON-BEHALF-OF" USER NAME
	DMOVEM	T1,.IOQ6N(CO)	;LEAVE IT FOR QUEOP ETC.

;CLEAR OUT INTERNAL "JOB" DATA BASE

;CLEAR OUT DAP COMMUNICATIONS REGION FOR A FRESH START

	MOVE	IO,CI		;REFRESH CDB ADDRESS (JUST IN CASE)
	MOVEI	T2,$DHACS	;ACCESS MESSAGE
	PUSHJ	P,RDCLR1##	;CLEAR OUT DAP MESSAGE AREA
	 STOPCD			;CAN'T HAPPEN
	MOVEI	T2,$DHATR	;MAIN ATTRIBUTES MESSAGE
	PUSHJ	P,RDCLR1##	;CLEAR OUT DAP MESSAGE AREA
	 STOPCD			;CAN'T HAPPEN
	MOVEI	T2,$DHALC	;ALLOCATION ATTRIBUTES MESSAGE
	PUSHJ	P,RDCLR1##	;CLEAR OUT DAP MESSAGE AREA
	 STOPCD			;CAN'T HAPPEN
	MOVEI	T2,$DHTIM	;DATE/TIME ATTRIBUTES MESSAGE
	PUSHJ	P,RDCLR1##	;CLEAR OUT DAP MESSAGE AREA
	 STOPCD			;CAN'T HAPPEN
	MOVEI	T2,$DHPRT	;PROTECTION ATTRIBUTES MESSAGE
	PUSHJ	P,RDCLR1##	;CLEAR OUT DAP MESSAGE AREA
	 STOPCD			;CAN'T HAPPEN
	SKIPG	T2,.IODIM(IO)	;GET PENDING DAP MESSAGE CODE
	STOPCD	<No DAP message pending in FJOB07>
	JRST	FJOB12		;DISPATCH ON DAP MESSAGE TYPE

;START UP NEW DAP INPUT MESSAGE

FJOB10:	PUSHJ	P,RDMSG1##	;GET A DAP MESSAGE HEADER
	 JSP	T4,FERNT	;ERROR (MAYBE DISCONNECT)

;HERE WITH DAP MESSAGE CODE IN T2

FJOB12:	JSP	T4,.CDISP##	;DISPATCH ON RECEIVED MESSAGE TYPE
		FJOB17,,$DHSTS	;STATUS (HUH?)
		FJOB20,,$DHATR	;MAIN ATTRIBUTES
		FJOB20,,$DHALC	;ALLOCATION ATTRIBUTES
		FJOB20,,$DHTIM	;DATE/TIME ATTRIBUTES
		FJOB20,,$DHPRT	;PROTECTION ATTRIBUTES
		FJOB30,,$DHUSR	;USER ID
		FJOB50,,$DHACS	;FILE ACCESS
		FJOB90,,$DHACM	;ACCESS COMPLETE
		0		;END OF TABLE
	JSP	T4,FEROS	;DAP MESSAGE RECEIVED OUT OF SEQUENCE


;RECEIVED STATUS - SHOULDN'T USUALLY HAPPEN!

FJOB17:	PUSHJ	P,RDSTS1##	;READ IN REST OF STATUS
	 POPJ	P,		;NET DIED
	CAIE	M0,$EGOIP	;"OPERATION IN PROGRESS"?
	CAIN	M0,$EGAOK	;"A-OK"?
	JRST	FJOB10		;YES, JUST EAT IT

;***

	PUSHJ	P,ERMSX1##	;TYPE OUT STATUS MESSAGE
	 JRST	FJOB10		;KEEP ON CRUSIN'
	JRST	FJOB10		;KEEP ON CRUSIN'


;RECEIVED SOME FLAVOR OF FILE ATTRIBUTES

FJOB20:	PUSHJ	P,RDDAP1##	;READ IN THE REST OF THE DAP MESSAGE
	 JSP	T4,FERDP	;DAP ERROR
	JRST	FJOB10		;LOOP BACK FOR MORE


;RECEIVED USERID MESSAGE

FJOB30:	PUSHJ	P,RDDAP1##	;READ IN USERID MESSAGE
	 JSP	T4,FERDP	;DAP ERROR
	JRST	FJOB10		;*** IGNORE IT FOR NOW


;RECEIVED FILE ACCESS MESSAGE - TIME TO GO DO SOMETHING USEFUL!

FJOB50:	PUSHJ	P,RDDAP1##	;READ IN THE ACCESS REQUEST
	 JSP	T4,FERDP	;DAP ERROR

;ALL ACCESS MESSAGES HAVE FILESPEC, SO READ IN AND SET THE SLAVE CDB
;WITH THE FILE SPEC(S) BLOCK(S)

	PUSHJ	P,FALIF0	;PARSE THE ACCESS MESSAGE FILE SPEC
	 PJRST	[MOVEI	T1,40000+$DSSYN	;DAP "FILE SPEC SYNTAX ERROR"
		SETZ	T2,		;NO SECONDARY STATUS
		SETZB	T3,T4		;NOTHING
		PUSHJ	P,FXSTS1	;SEND DAP ERROR STATUS TO REMOTE
		 POPJ	P,		;NET DIED?
		JRST	FJOB00]		;LOOP BACK TO IDLE STATE
FJOB54:	SKIPN	T1,.IOXFF(CO)	;OUTPUT AREA
	STOPCD	<No "extra" space in slave CDB in FJOB54>
	ADDI	T1,.FXMAX	;LENGTH OF FILE SPEC BLOCK
	CAML	T1,.IOXSZ(CO)	;ROOM FOR THIS FSB?
	STOPCD	<No room in slave CDB for FSB in FJOB54>
	EXCH	T1,.IOXFF(CO)	;ALLOCATE ONE FSB FROM "EXTRA" SPACE
	ADD	T1,CO		;CALCULATE REAL MEMORY ADDRESS
	SKIPN	.IOFSB(CO)	;THIS THE FIRST FILE SPEC?
	MOVEM	T1,.IOFSB(CO)	;YES
	MOVEM	T1,.IOFSL(CO)	;IT IS ALSO THE LAST FILE SPEC
	SKIPN	.IOFSB(CI)	;DUPLICATE FSB POINTERS
	MOVEM	T1,.IOFSB(CI)	; IN PRIMARY CDB
	MOVEM	T1,.IOFSL(CI)	;  FOR EASE OF ACCESS
	MOVEI	T2,.FXMAX	;LENGTH OF FILE SPEC BLOCK
	PUSHJ	P,.GTSPC##	;COPY OVER THE FILE SPEC
	MOVE	T3,.IOPPN(IO)	;ACCESSING ("ON-BEHALF-OF") PPN
	SETO	T4,		;NON-WILD
	SKIPN	.FXDIR(T1)	;DID FILESPEC HAVE AN EXPLICIT DIRECTORY?
	DMOVEM	T3,.FXDIR(T1)	;NO, USE ACCESSOR AS DIRECTORY
	LDB	T2,[POINTR .FXMOD(T1),FX.TRM]  ;GET SPEC TERMINATION
	JUMPE	T2,FJOB59	;DISPATCH ON ACCESS REQUEST

;RECEIVED A FILE EXPRESSION (E.G., A 'OR' B), MORE FILE SPECS COMING

	PUSHJ	P,FALIF1	;READ IN NEXT FILE SPEC
	 POPJ	P,		;NICE TRY
	JRST	FJOB54		;ACCUMULATE FSB'S
FJOB59:	PUSHJ	P,FAJA01	;VERIFY AND SETUP ATTRIBUTES/ET AL
	 STOPCD	<FAJA failed in FJOB59>
	MOVD1	T2,AFC		;ACCESS FUNCTION REQUESTED
	JSP	T4,.CDISP##	;DISPATCH ON FUNCTION
		FRED00,,$DVARD	;OPEN FILE (FOR READ)
		FWRT00,,$DVAWR	;OPEN FILE (FOR WRITE)
		FREN00,,$DVARN	;RENAME
		FDEL00,,$DVADL	;DELETE
		FDIR00,,$DVADR	;DIRECTORY LIST
		FSUB00,,$DVASB	;SUBMIT AS COMMAND FILE
		FEXE00,,$DVAEC	;EXECUTE COMMAND FILE
		0		;NO MORE
	STOPCD	<Unknown ACCESS message function in FJOB59>
;HERE ON ACCESS COMPLETE

FJOB90:	MOVE	IO,CI		;RESET PRIMARY CDB ADDRESS
	PUSHJ	P,RDDAP1##	;READ IN ACCESS COMPLETE
	 JSP	T4,FERNT	;NET ERROR?
	MOVD	T1,A2F		;GET ACCOMP FUNCTION
	CAIE	T1,$DVACL	;ACCOMP(CLOSE)?
	STOPCD	<Access complete not ACCOMP(CLOSE) in FJOB90>
FJOB93:	MOVE	IO,CI		;RESET PRIMARY CDB ADDRESS
	PUSHJ	P,XDARS1##	;SEND ACCOMP(RESPONSE)
	 JSP	T4,FEXNT	;NET ERROR?
FJOB95:
;***
;***	JRST	.POPJ1##	;SHUT DOWN LINK NOW (DCPNSP LEAVES US DANGLING)
;***

	JRST	FJOB00		;BACK TO PROCESS NEXT ACCESS COMMAND
	SUBTTL	File read access

FRED00:

;FILE-LEVEL STARTUP
;
;LOOP FINDING INPUT FILES

FRDF00:	PUSHJ	P,FIFIL1	;FIND NEXT POSSIBLY-WILD INPUT FILE
	  POPJ	P,		;(0) NET DIED OR OTHER FATAL ERROR
	 JRST	FRDZ90		;(1) INPUT FILE STREAM EXHAUSTED
	MOVE	T1,.IOIOC(CO)	;(2) CONTINUE WITH RETURNED FILE
	MOVE	T2,.IOIOC(CI)	;PRIMARY CDB I/O CONTROL
	TXNN	T1,IC.RFM	;RESULTANT FILE RECORD-FORMATTED?
	TXZA	T1,IC.RSI	;NO
	TXOA	T1,IC.RSI	;YES
	TXZA	T2,IC.RSI	;NO
	TXO	T2,IC.RSI	;YES
	MOVEM	T1,.IOIOC(CO)	;SET SLAVE FILE I/O CONTROL
	MOVEM	T2,.IOIOC(CI)	;AND PRIMARY FLAGS TOO

;RETURN FILE INFORMATION TO REMOTE ACCESSOR (E.G., NFT)

FRDF20:	MOVE	IO,CI		;RE-SELECT PRIMARY CDB

;FIRST HANDLE ANY NAME MESSAGES NEEDED BY WILDCARDING

	PUSHJ	P,FANTY1	;SEND NAME MESSAGES
	 POPJ	P,		;CAN'T HAPPEN

;NOW HANDLE FILE ATTRIBUTES

FRDF22:	PUSHJ	P,FFAD01	;TRANSLATE FILE ATTRIBUTES INTO DAP BLOCK
	 STOPCD	<FFAD failed in FRDF22>
	MOVD	P1,ADS		;RESTORE ACCESS DISPLAY FIELD
	FJUMPN	P1,ADS,FRDF25	;GO IF ANYTHING SET
	TFO	P1,DMA		;DEFAULT TO MAIN ATTRIBUTES
FRDF25:	PUSHJ	P,FXAT01	;SEND ATTRIBUTES MESSAGES
	 STOPCD	<FXAT failed in FRDF20>

;CONTINUED ON NEXT PAGE
;CONTINUED FROM PREVIOUS PAGE

;GO UNLESS GO/NOGO REQUESTED
;
;END OF FILE INFORMATION - HANDLE GO/NOGO IF SPECIFIED

FRDG00:	PUSHJ	P,XDACK1##	;SEND AN ACK AFTER ALL ATTR/ET AL
	 STOPCD	<XDACK failed in FRDG00>
	PUSHJ	P,XDFLS1##	;NOW FLUSH OUT ALL MESSAGES TO THE REMOTE
	 STOPCD	<XDFLS1 failed in FRDG00>
	MOVD	T1,AOP		;GET ACCESS OPTIONS
	TFNN	T1,GNG		;DID REMOTE SPECIFY GO/NOGO?
	JRST	FRDI00		;NO, INITIALIZE FOR I/O

;WAIT FOR REMOTE TO MAKE UP ITS MIND

FRDG10:	PUSHJ	P,RDMSG1##	;GET REMOTE'S GO/NOGO DECISION
	 POPJ	P,		;NET MUST HAVE DIED
FRDG11:	JSP	T4,.CDISP##	;DISPATCH BASED ON REMOTE'S DECISION
		FRDG20,,$DHSTS	;STATUS - SHOULDN'T HAPPEN
		FRDG30,,$DHCNT	;CONTINUE - RESPONSE FOR GO/NOGO
		FRDI90,,$DHACM	;ACCESS COMPLETE
		0		;NONE OTHER
	STOPCD	<Unknown GO/NOGO response from remote at FRDG10>


;RECEIVED STATUS

FRDG20:	PUSHJ	P,RDSTS1##	;READ IN REST OF STATUS
	 POPJ	P,		;SHOULDN'T HAPPEN
	STOPCD	<STATUS received in FRDG20>


;RECEIVED CONTINUE

FRDG30:	PUSHJ	P,RDDAP1##	;READ IN REST OF CONTINUE MESSAGE
	 POPJ	P,		;SHOULDN'T HAPPEN
	MOVD1	T1,C2F		;CONTINUE FUNCTION CODE
	CAIN	T1,$DVCSK	;SKIP THIS FILE?
	JRST	FRDZ20		;YES, ADVANCE TO THE NEXT FILE
	CAIN	T1,$DVCRS	;RESUME PROCESSING?
	JRST	FRDI00		;YES, INITIALIZE FOR I/O
	STOPCD	<Unknown or illegal CONTINUE function in FRDG30>
;INITIALIZE FOR I/O
;
;LOOP ON CONTROL MESSAGES

FRDI00:	MOVE	IO,CI		;SELECT PRIMARY CDB
	PUSHJ	P,RDMSG1##	;START UP NEXT INPUT MESSAGE
	 POPJ	P,		;NET DIED
FRDI01:	JSP	T4,.CDISP##	;DISPATCH ON MESSAGE CODE
		FRDI10,,$DHCTL	;CONTROL
		FRDI90,,$DHACM	;ACCOMP?
		0		;NONE OTHERS
	STOPCD	<Received message not CONTROL nor ACCOMP in FRDT40>


;RECEIVED CONTROL MESSAGE

FRDI10:	PUSHJ	P,RDDAP1##	;READ IN THE CONTROL MESSAGE
	 POPJ	P,		;ERROR
	MOVD1	T2,CFC		;CONTROL FUNCTION CODE
FRDI11:	JSP	T4,.CDISP##	;DISPATCH ON CONTROL CODE
		FRDI20,,$DVCON	;CONTROL(CONNECT), INITIALIZE I/O STREAM
		FRDI30,,$DVCGT	;CONTROL(GET), READ RECORD/FILE
		0		;NO OTHERS SUPPORTED
	STOPCD	<CONTROL neither (CONNECT) nor (GET) in FRDI10>


;HERE FOR CONTROL(CONNECT)

FRDI20:	MOVX	T1,IO.DCC	;THE DAP CONTROL(CONNECT) FLAG
	TDNE	T1,.IOCCF(IO)	;FIRST ONE?
	STOPCD	<Multiple CONTROL(CONNECT)s in FRDI20>
	IORM	T1,.IOCCF(IO)	;YES, FLAG I/O NOW ACTIVE
	PUSHJ	P,XDACK1##	;SEND AN ACK FOR THE CONTROL(CONNECT)
	 STOPCD	<XDACK failed in FRDI20>
	PUSHJ	P,XDFLS1##	;FORCE IT OUT NOW
	 STOPCD	<XDFLS failed in FRDI20>
	JRST	FRDI00		;BACK TO STATE DISPATCH


;HERE FOR CONTROL(GET)

FRDI30:	MOVE	T1,.IOCCF(IO)	;GET CHANNEL CONTROL FLAGS
	TXNN	T1,IO.DCC	;HAVE WE SEEN A CONTROL(CONNECT)?
	STOPCD	<No CONTROL(CONNECT) before CONTROL(GET) in FRDI30>
	MOVD1	T2,RAC		;RECORD ACCESS CONTROL
	CAIN	T2,$DVCSF	;SEQUENTIAL FILE ACCESS?
	JRST	FRDL00		;JUST START FILE TRANSFER LOOP
	STOPCD	<Not Sequential-File-Access for CONTROL(GET) in FRDI30>
;HERE ON ACCOMP RATHER THAN CONTROL MESSAGE

FRDI90:	PUSHJ	P,RDCLR1##	;CLEAR OUT POSSIBLY-STALE FIELDS (LIKE AFO)
	 STOPCD			;CAN'T HAPPEN
	SETOM	.IDCKS(IO)	;'CUZ ACCOMP HAS NO MENU!!
	PUSHJ	P,RDDAP1##	;READ IN ACCOMP MESSAGE
	 POPJ	P,		;NET DIED
	SKIPL	T1,.IDCKS(IO)	;DID ACCOMP INCLUDE A CRC VALUE?
	CAMN	T1,.IODOK(IO)	;YES, DOES IT MATCH OUR CALCULATION?
	JRST	FRDI93		;NO CRC, OR CRC MATCHES, ALL IS WELL
	MOVD	T2,AOP		;GET ORIGINAL FILE ACCESS OPTIONS
	TFNN	T2,ACK		;DID USER REQUEST CHECKSUMMING?
	JRST	FRDI93		;NO, THEN NOT A REAL ERROR
	MOVX	T2,IO.DCC	;THE "OPEN FOR I/O" FLAG
	TDNN	T2,.IOCCF(IO)	;IS FILE OPENED FOR I/O?
;***	JUMPE	T1,FRDI93	;IGNORE IF 0 (ASSUME REALLY A "BLANK" CRC)
	JRST	FRDI93		;*** VAX HAS TAKEN TO SENDING A CRC OF 177777
				;*** FOR FILE FOR WHICH NO READ WAS PERFORMED
				;*** AS IN "SUBMIT/REMOTE 10::FILE.CTL"
	MOVEI	T1,50000+$DSCKE	;DAP FILE TRANSFER CHECKSUM (CRC) ERROR STATUS
	SETZ	T2,		;NO SECONDARY STATUS
	SETZB	T3,T4		;NOTHING ELSE EITHER
	PUSHJ	P,FXSTS1	;SEND A STATUS MESSAGE
	 POPJ	P,		;NET DIED?
	JRST	FRDI00		;BACK TO FILE-OPEN IDLE LOOP FOR ANOTHER ACCOMP

;FILE DATA IS OK (AS BEST AS WE CAN TELL), CLOSE OFF THE FILE

FRDI93:	MOVX	T2,IO.DCC	;THE "FILE IS OPEN FOR I/O" BIT
	ANDCAM	T2,.IOCCF(IO)	;NOTE NO MORE I/O
	PUSHJ	P,FACL01	;CHECK FOR ACCOMP-TIME CLOSE OPTIONS
	 JRST	[PUSHJ	P,FOFI01	;SEND ERROR STATUS TO REMOTE
		 POPJ	P,		;NET DIED?
		JRST	FRDI00]		;BACK TO FILE-OPEN IDLE LOOP
FRDI95:	MOVD1	T2,A2F		;ACCOMP FUNCTION
	JSP	T4,.CDISP##	;DISPATCH ON MESSAGE TYPE
		FRDI97,,$DVAES	;END OF STREAM (DON'T CLOSE THE FILE)
		FRDZ00,,$DVACL	;CLOSE FILE (MIGHT IMPLY SKIP)
		FRDZ20,,$DVASK	;CLOSE AND SKIP FILE
		FRDZ30,,$DVACB	;CLOSE AND RENAME CURRENT FILE
		FRDZ50,,$DVAKL	;KILL/RESET CURRENT FILE
		FRDZ80,,$DVATR	;TERMINATE/ABORT ACCESS REQUEST
		0		;NONE OTHERS LEGAL
	STOPCD	<Unknown or illegal ACCOMP function in FRDI90>


;HERE ON ACCOMP(EOS) - JUST MARK THE FILE NOT I/O-ACTIVE

FRDI97:	PUSHJ	P,XDARS1##	;SEND THE ACCOMP(RESPONSE)
	 POPJ	P,		;NET DIED
	JRST	FRDI00		;BACK INTO OPEN-BUT-NOT-I/O-ACTIVE IDLE LOOP
;LOOP READING FILE IN SEQUENTIAL FILE TRANSFER MODE
;
;HERE TO READ THE JUST-FOUND FILE

FRDL00:	XMOVEI	T1,.IOOIN##	;NET-LEVEL I/O INIT ROUTINE
	MOVEM	T1,.IOOSR(CI)	;FORCE PRIMARY TO RE-INIT OUTPUT ROUTINES
	MOVEI	T1,177777	;DAP CRC POLYNOMIAL "SEED"
	MOVEM	T1,.IODOK(CI)	;IN CASE FIRST .IOISR FAILS, AND THEN CLOSES
				; INPUT WITH CRC - SINCE OTHERWISE THE CRC
				; WON'T GET INITIALIZED UNTIL .IOOSR CALLED
	MOVE	T1,.IOIOC(CI)	;GET PRIMARY CDB I/O CONTROL
	TXNN	T1,IC.RSI	;RECORD-STRUCTURED I/O?
	JRST	FRDL10		;NO, BYTE I/O, GO START IT UP
	MOVE	T1,.IORSZ(CI)	;GET PRIMARY RECORD SIZE
	CAIG	T1,0		;GOT A RECORD SIZE?
	MOVEI	T1,1234		;NO, HALLUCINATE ONE THEN
	MOVEM	T1,RSIFT3	;SAVE FOR ISR CALLS
	ADDI	T1,3		;*** 8-BIT BYTES
	LSH	T1,-2		;*** 8-BIT BYTES
	PUSHJ	P,.MMGWD##	;ALLOCATE A RECORD-BUFFER
	 POPJ	P,		;NO MEMORY
	DMOVEM	T1,RSIFFA	;SAVE THE PAIR
	HRLI	T2,(POINT 8,)	;CONCOCT A RECORD-BUFFER BYTE POINTER
	MOVEM	T2,RSIFT4	;SAVE FOR ISR CALLS
	JRST	FRDL20		;GO START RECORD I/O
;LOOP READING BYTES FROM THE SLAVE FILE, WRITING TO THE REMOTE

FRDL10:	MOVE	T1,CO		;INPUT (SLAVE) CDB
	PUSHJ	P,@.IOISR(T1)	;READ NEXT INPUT BYTE
	 JRST	FRDL30		;MAYBE EOF, TELL REMOTE IN ANY CASE
FRDL15:	MOVE	T1,CI		;OUTPUT (PRIMARY) CDB
	PUSHJ	P,@.IOOSR(T1)	;WRITE CURRENT BYTE TO THE REMOTE
	 JRST	FRDL60		;MAYBE ACCOMP
	JRST	FRDL10		;LOOP BACK FOR MORE



;LOOP READING RECORDS FROM THE SLAVE FILE, WRITING TO THE REMOTE

FRDL20:	MOVE	T1,CO		;INPUT (SLAVE) CDB
	SETO	T2,		;NO PARTICULAR RECORD ADDRESS
	DMOVE	T3,RSIFT3	;RECORD BUFFER COUNTER AND POINTER
	PUSHJ	P,@.IOISR(T1)	;READ NEXT INPUT RECORD
	 JRST	FRDL30		;MAYBE EOF, TELL REMOTE IN ANY CASE
FRDL25:	MOVE	T1,CI		;OUTPUT (PRIMARY) CDB
	PUSHJ	P,@.IOOSR(T1)	;WRITE CURRENT RECORD TO THE REMOTE
	 JRST	FRDL60		;MAYBE ACCOMP
	JRST	FRDL20		;LOOP BACK FOR MORE
;HERE ON EXCEPTION RETURN FROM INPUT BYTE

FRDL30:	MOVE	IO,CI		;SELECT PRIMARY CDB
	PUSH	P,M0		;HANG ONTO ERROR/EXCEPTION CODE
	PUSHJ	P,@.IOOSS(IO)	;CALL NETWORK OUTPUT SHUTDOWN ROUTINE
	 JFCL			;HO HUM
	POP	P,M0		;RETRIEVE ERROR/EXCEPTION CODE
	CAIE	M0,$EIEOF	;EOF ON INPUT (SLAVE) FILE?
	JRST	FRDL33		;NO, I/O EXCEPTION/ERROR
FRDL31:	MOVEI	T1,50000+$DSEOF	;DAP I/O-LEVEL EOF STATUS
	SETZ	T2,		;NO SECONDARY STATUS
	SETZB	T3,T4		;NOR ANYTHING ELSE
	PUSHJ	P,FXSTS1	;SEND DAP STATUS TO REMOTE
	 POPJ	P,		;NET DIED
	JRST	FRDI00		;WAIT FOR ACCOMP

;ERROR READING INPUT (SLAVE) FILE

FRDL33:	MOVE	T2,M0		;POSITION ERROR CODE
	MOVEI	T4,DS2EI##	;DAP STATUS TO I/O STATUS TRANSLATION TABLE
	PUSHJ	P,FFIND1	;CONVERT TO DAP I/O STATUS CODE
	 SKIPA	T1,$DSRER	;GENERIC READ ERROR, $E???? AS SECONDARY STATUS
	SETZ	T2,		;KNOWN ERROR, NO SECONDARY STATUS
	ADDI	T1,50000	;DAP I/O LEVEL ERROR STATUS
	SETZB	T3,T4		;NOTHING ELSE EITHER
	PUSHJ	P,FXSTS1	;SEND DAP STATUS
	 POPJ	P,		;NET DIED

;ERROR-STATE IDLE LOOP - WAIT FOR CONTINUE OR ABORT

FRDL40:	PUSHJ	P,RDMSG1##	;START NEW INPUT MESSAGE FROM REMOTE
	 POPJ	P,		;NET DIED
FRDL41:	JSP	T4,.CDISP##	;DISPATCH ON MESSAGE TYPE
		FRDL50,,$DHCNT	;CONTINUE
		FRDI90,,$DHACM	;ACCOMP
		0		;THAT'S IT
	STOPCD	<Unknown/illegal DAP message in FRDL40>

;HERE ON "CONTINUE" AFTER INPUT ERROR

FRDL50:	PUSHJ	P,RDDAP1##	;READ IN REST OF CONTINUE MESSAGE
	 POPJ	P,		;NET DIED
	MOVD1	T2,C2F		;GET CONTINUE "FUNCTION" TYPE
	JUMPE	T2,FRDL54	;IF NULL, ASSUME IGNORE ERROR
	JSP	T4,.CDISP##	;DISPATCH ON CONTINUE TYPE
		FRDL53,,$DVCTA	;TRY AGAIN
		FRDL54,,$DVCSK	;SKIP AND IGNORE ERROR
		0		;THAT'S ALL
	STOPCD	<Unknown/illegal CONTINUE function in FRDL50>

FRDL53:	TDZA	T2,T2		;TRY AGAIN
FRDL54:	MOVEI	T2,1		;IGNORE AND RESUME
	STOPCD	<Error-continuation not yet written in FRDL54>


;"EXCEPTION" WRITING OUTPUT FILE

FRDL60:	MOVE	IO,CI		;SELECT PRIMARY CDB
	CAIE	M0,$EINMP	;INPUT MESSAGE PENDING?
	JRST	FRDL63		;NO, NET ERROR?
	PUSHJ	P,RDMSG1##	;START UP DAP MESSAGE
	 POPJ	P,		;HMMMM
	CAIE	T2,$DHACM	;ACCESS COMPLETE?
	STOPCD	<Received DAP message not ACCOMP in FRDL60>
	JRST	FRDI90		;GO PROCESS ACCOMP

FRDL63:	POPJ	P,		;NET DIED? JUST ABORT THE JOB
;END OF FILE ACCESS

FRDZ00:	MOVE	T1,.IOCCF(CI)	;GET PRIMARY CHANNEL CONTROL FLAGS
	MOVE	T2,.IOIOM(CO)	;GET SLAVE I/O MODE CONTROL
	TXNN	T1,IO.DCC	;WAS A CONTROL(CONNECT) SEEN?
	TXNE	T2,IM.CXX	;NO, ANY CLOSE-TIME OPTIONS?
	JRST	FRDZ10		;NORMAL FILE CLOSE PROCESSING
	JRST	FRDZ20		;"SKIP" FILE CLOSE PROCESSING

;NORMAL CLOSE FILE

FRDZ10:	MOVE	IO,CO		;SELECT SLAVE CDB
	PUSHJ	P,IOCLO1##	;CLOSE THE INPUT FILE
	 SKIPA	T2,M0		;BUTTS - SOMETHING FAILED IN THE CLOSE
	JRST	FRDZ60		;END OF THIS FILE, BACK FOR THE NEXT ONE
FRDZ17:	MOVEI	T4,DS2EF##	;DAP STATUS TO FILE STATUS TABLE ADDRESS
	PUSHJ	P,FFIND1	;SEE IF KNOWN ERROR
	 SKIPA	T1,[$DSCCF]	;CANNOT CLOSE FILE, $E???? AS SECONDARY STATUS
	SETZ	T2,		;KNOWN ERROR, NO SECONDARY STATUS
	ADDI	T1,70000	;"CLOSE-TIME" ERROR
	SETZB	T3,T4		;NOTHING ELSE EITHER
	MOVE	IO,CI		;SELECT PRIMARY CDB
	PUSHJ	P,FXSTS1	;SEND ERROR STATUS TO REMOTE
	 POPJ	P,		;NET DIED
	JRST	FRDI00		;BACK TO FILE-IS-OPEN IDLE LOOP


;SKIP CURRENT FILE

FRDZ20:	MOVE	IO,CO		;SELECT SLAVE CDB
	MOVX	P1,IM.SAD	;THE SUPPRESS-ACCESS-DATE FLAG
	AND	P1,.IOIOM(IO)	;MAKE A COPY OF THE CURRENT SETTING
	MOVX	T1,IM.SAD	;THE BIT AGAIN
	IORM	T1,.IOIOM(IO)	;SUPPRESS THE ACCESS DATE
	PUSHJ	P,IOCLO0##	;CLOSE CURRENT INPUT FILE
	 TDZA	T1,T1		;OOPS
	SETO	T1,		;GOOD
	MOVX	T2,IM.SAD	;THE BIT YET AGAIN
	TDNN	T2,P1		;WAS IT SET BEFORE?
	ANDCAM	T2,.IOIOM(IO)	;NO, CLEAR IT OUT NOW
	JUMPL	T1,FRDZ60	;NOW ADVANCE TO NEXT FILE
	JRST	FRDZ17		;OOPS, ERROR, INFORM REMOTE
;RENAME CURRENT FILE

FRDZ30:	PUSHJ	P,FRDCB1	;READ IN NEW ATTRIBUTES/NAME MESSAGES
	 JRST	[CAIE	M0,$ECAUR	;ABORTED AT [REMOTE] USER'S REQUEST?
		POPJ	P,		;NO, LINK BLOWN AWAY
		CAIE	T2,$DVATR	;ACCOMP(TERMINATE)?
		STOPCD	<Unknown/illegal ACCOMP message in FWRZ30>
		PJRST	FRDZ80]		;YES, SEND ACCOMP(RESPONSE), GO IDLE
	SKIPN	.IOFS3(CO)	;*** DID WE RECEIVE A FILE SPEC?
	JRST	FRDZ10		;*** NO, JUST CLOSE THE FILE NORMALLY
	PUSHJ	P,FRDCE1	;DO THE REQUESTED RENAME OPERATION
	 JRST	FRDZ17		;OOPS - RENAME FAILED, INFORM THE REMOTE
	JRST	FRDZ60		;FILE CLOSED (BY IOFRN), SEE WHAT NEXT


;KILL/RESET CURRENT FILE

FRDZ50:	MOVE	IO,CO		;POINT TO SLAVE CDB
	PUSHJ	P,IOABO1##	;ABORT CURRENT FILE
	 STOPCD	<IOABO failed in FRDZ50>
;	JRST	FRDZ60		;ADVANCE TO THE NEXT FILE (IF ANY)


;COMMON FILE-CLOSE, TRY FOR NEXT INPUT FILE

FRDZ60:	SKIPN	T1,RSIFFA	;GOT ANY RECORD-BUFFER LEFT OVER?
	JRST	FRDZ62		;NOPE
	MOVE	T2,RSIFFA+1	;YUP
	PUSHJ	P,.MMFWD##	;FREE UP RECORD BUFFER
	 JFCL			;HO HUM
	SETZM	RSIFFA		;NO LONGER HAVE A RECORD BUFFER
FRDZ62:	SKIPN	.WLDFL##	;*** WILDCARDED FILE ACCESS?
	JRST	FRDZ90		;*** NO, ACCESS IS COMPLETE
	JRST	FRDF00		;TRY FOR ANOTHER FILE


;TERMINATE ACCESS

FRDZ80:	MOVE	IO,CO		;SELECT SLAVE CDB
	PUSHJ	P,IOABO1##	;ABORT THE CURRENT READ
	 JFCL			;HO HUM

;ACCESS IS COMPLETED

FRDZ90:	MOVE	IO,CO		;SELECT SLAVE CDB
	PUSHJ	P,IORLS1##	;WE ARE DONE WITH FILE-LEVEL OPERATIONS
	 JFCL			;DON'T CARE
	JRST	FJOB93		;SEND ACCOMP(RESPONSE)
	SUBTTL	File read access - Subroutines -- RENAME option

;FRDCB - read in new name/attributes on ACCOMP(RENAME)

FRDCB1:	PUSHJ	P,FRENA1	;READ IN NEW ATTRIBUTES AND NAME
	 JRST	[CAIN	M0,$ECAUR	;RECEIVED AN ACCOMP BEFORE NAME MSG?
		CAIN	T2,$DVATR	;ACCOMP(TERMINATE)?
		POPJ	P,		;LET CALLER DEAL WITH IT
		CAIE	T2,$DVACE	;MUST BE ACCOMP(CHANGE-END)
		STOPCD	<ACCOMP not CHANGE-END in FRDCB1>
					;NO NAME MESSAGE, NO FILE SPEC, NOTHING
					;FOR SCWILD TO PLAY WITH. FOR THE TIME
					;BEING, JUST IGNORE THE ACCOMP(RENAME)
					;AND CLOSE THE FILE NORMALLY (YEAH, IF
					;ONLY A PROTECTION WAS SENT, IT IS LOST)
		JRST	.POPJ1##]	;QUIT FOR NOW
	MOVE	T1,.IOFS3(CO)	;ADDRESS OF "OUTPUT" FILE SPEC BLOCK
	DMOVE	T2,.FXCTL(T1)	;GET FSB CONTROL FLAGS
	TXOE	T3,FX.SCE	;SOMEONE SLIP IN /SCERROR CONTROL?
	JRST	FRDCB3		;YES, BIZARRE, ALLOW IT THEN
	MOVEI	T4,SCENEV##	;GET /SCERROR:NEVER VALUE
	DPB	T4,[POINTR T2,FX.SCE]  ;AND SET IN CONTROL WORD
				; TO ALLOW WILDCARD READ, BUT SPECIFIC
				; FILENAME RENAME OPERATION (WHICH IS
				; THE USUAL CASE FOR ACCOMP(RENAME)...)
	DMOVEM	T2,.FXCTL(T1)	;SET VALUES IN FILE SPEC BLOCK
FRDCB3:	PUSHJ	P,RDMSG1##	;MUST NOW HAVE ACCOMP(CHANGE-END)
	 POPJ	P,		;NET DIED?
	CAIE	T2,$DHACM	;LOOKING AT AN ACCOMP?
	STOPCD	<Not ACCOMP after ACCOMP(CHANGE-BEGIN) in FRDCB1>
	PUSHJ	P,RDCLR1##	;CLEAR OUT DAP AREA
	 STOPCD			;CAN'T HAPPEN
	PUSHJ	P,RDDAP1##	;PARSE THE ACCOMP
	 POPJ	P,		;BAD NEWS
	MOVD1	T2,A2F		;GET THE ACCOMP FUNCTION
	CAIN	T2,$DVATR	;ACCOMP(TERMINATE)?
	JRST	[MOVEI	M0,$ECAUR	;YES, FLAG ABORT AT USER'S REQUEST
		POPJ	P,]		;AND BREAK OFF THE OPERATION
	CAIE	T2,$DVACE	;MUST BE "CHANGE-END"
	STOPCD	<ACCOMP not ACCOMP(CHANGE-END) in FRDCB1>
	JRST	.POPJ1##	;READY FOR THE RENAME!


;FRDCE - Do the actual RENAME operation as setup by FRDCB

FRDCE1:	MOVE	IO,CO		;POINT TO SLAVE CDB
	PUSHJ	P,IOFRN1##	;DO THE REQUESTED RENAME OPERATION
	 TDZA	P1,P1		;ERROR
	SETO	P1,		;SUCCESS
	MOVNI	T1,.FXMAX	;LENGTH OF FSB
	ADDM	T1,.IOXFF(CO)	;DEALLOCATE THE "ANCILLIARY" FSB FROM FRENA1
	SETZM	.IOFS3(CO)	;REMOVE POINTER TO DEALLOCATED FSB
	SETZM	.IOCU3(CO)	; AND THE OTHER ONE TOO
	JUMPL	P1,.POPJ1##	;TRY FOR A SUCCESS RETURN
	POPJ	P,		;NOPE, TAKE ERROR RETURN
	SUBTTL	File write access

FWRT00:

;FILE-LEVEL STARTUP
;
;CREATE THE OUTPUT FILE

FWRF00:	MOVE	IO,CO		;ADDRESS OF SLAVE CDB
	PUSHJ	P,FOFIL1	;GO CREATE THE SLAVE OUTPUT FILE
	  POPJ	P,		;(0) NET DIED
	 JRST	FWRZ50		;(1) ERROR, ABORT FILE, SEND ACCOMP(RESPONSE)
	MOVE	T1,.IOIOC(CO)	;(2) CONTINUE WITH NEWLY-CREATED FILE
	MOVE	T2,.IOIOC(CI)	;PRIMARY CDB I/O CONTROL
	TXNN	T1,IC.RFM	;RESULTANT FILE RECORD-FORMATTED?
	TXZA	T1,IC.RSI	;NO
	TXOA	T1,IC.RSI	;YES
	TXZA	T2,IC.RSI	;NO
	TXO	T2,IC.RSI	;YES
	MOVEM	T1,.IOIOC(CO)	;SET SLAVE FILE I/O CONTROL
	MOVEM	T2,.IOIOC(CI)	;AND PRIMARY FLAGS TOO
	MOVE	T1,.IOCCF(CO)	;SLAVE CHANNEL CONTROL FLAGS
	MOVE	T2,.IODCH(CO)	;GET FILE CHARACTERISTICS
	TXNN	T1,IO.NET	;IS THIS A NETWORKED (NON-LOCAL) FILE?
	TXNN	T2,IC.SPL	;THAT IS SPOOLED?
	JRST	FWRF20		;NOT A LOCAL SPOOLED FILE, NO NONSENSE
	PUSHJ	P,NONPP1	;DISALLOW NETPPN FROM USING THE LPT/ETC.
	 JRST	[PUSHJ	P,FOFI01	;SEND ERROR STATUS TO REMOTE
		 POPJ	P,		;NET DIED?
		JRST	FJOB95]		;BACK TO IDLE STATE
	PUSHJ	P,FWSP01	;GO WAVE OUR HANDS IN A FRENZIED FASHION
	 JRST	FWRZ50		;SO MUCH FOR THAT, BACK TO IDLE STATE

;RETURN FILE INFORMATION TO REMOTE ACCESSOR (E.G., NFT)

FWRF20:	MOVE	IO,CI		;RE-SELECT PRIMARY CDB
FWRF22:	PUSHJ	P,FFAD01	;TRANSLATE FILE ATTRIBUTES INTO DAP BLOCK
	 STOPCD	<FFAD failed in FWRF20>
	MOVD	P1,ADS		;RESTORE ACCESS DISPLAY FIELD
	FJUMPN	P1,ADS,FWRF25	;GO IF ANYTHING SET
	TFO	P1,DMA		;DEFAULT TO MAIN ATTRIBUTES
FWRF25:	PUSHJ	P,FXAT01	;SEND ATTRIBUTES MESSAGES
	 STOPCD	<FXAT failed in FWRF20>

;CONTINUED ON NEXT PAGE
;CONTINUED FROM PREVIOUS PAGE

;GO UNLESS GO/NOGO REQUESTED
;
;END OF FILE INFORMATION - HANDLE GO/NOGO IF SPECIFIED

FWRG00:	PUSHJ	P,XDACK1##	;SEND AN ACK AFTER ALL ATTR/ET AL
	 STOPCD	<XDACK failed in FWRG00>
	PUSHJ	P,XDFLS1##	;NOW FLUSH OUT ALL MESSAGES TO THE REMOTE
	 STOPCD	<XDFLS1 failed in FWRG00>
	MOVD	T1,AOP		;GET ACCESS OPTIONS
	TFNN	T1,GNG		;DID REMOTE SPECIFY GO/NOGO?
	JRST	FWRI00		;NO, INITIALIZE FOR I/O

;WAIT FOR REMOTE TO MAKE UP ITS MIND

FWRG10:	PUSHJ	P,RDMSG1##	;GET REMOTE'S GO/NOGO DECISION
	 POPJ	P,		;NET MUST HAVE DIED
FWRG11:	JSP	T4,.CDISP##	;DISPATCH BASED ON REMOTE'S DECISION
		FWRG20,,$DHSTS	;STATUS - SHOULDN'T HAPPEN
		FWRG30,,$DHCNT	;CONTINUE - RESPONSE FOR GO/NOGO
		FWRI90,,$DHACM	;ACCESS COMPLETE
		0		;NONE OTHER
	STOPCD	<Unknown GO/NOGO response from remote at FWRG10>


;RECEIVED STATUS

FWRG20:	PUSHJ	P,RDSTS1##	;READ IN REST OF STATUS
	 STOPCD			;SHOULDN'T HAPPEN
	STOPCD	<STATUS received in FWRG20>


;RECEIVED CONTINUE

FWRG30:	PUSHJ	P,RDDAP1##	;READ IN REST OF CONTINUE MESSAGE
	 STOPCD			;SHOULDN'T HAPPEN
	MOVD1	T1,C2F		;CONTINUE FUNCTION CODE
	CAIN	T1,$DVCSK	;SKIP THIS FILE?
	JRST	FWRZ50		;YES, ABORT THE CREATE (IF POSSIBLE)
	CAIN	T1,$DVCRS	;RESUME PROCESSING?
	JRST	FWRI00		;YES, INITIALIZE FOR I/O
	STOPCD	<Unknown or illegal CONTINUE function in FWRG30>
;INITIALIZE FOR I/O
;
;LOOP ON CONTROL MESSAGES

FWRI00:	MOVE	IO,CI		;SELECT PRIMARY CDB
	PUSHJ	P,RDMSG1##	;START UP NEXT INPUT MESSAGE
	 POPJ	P,		;NET DIED
FWRI01:	JSP	T4,.CDISP##	;DISPATCH ON MESSAGE CODE
		FWRI10,,$DHCTL	;CONTROL
		FWRI90,,$DHACM	;ACCOMP?
		0		;NONE OTHERS
	STOPCD	<Received message not CONTROL nor ACCOMP in FWRT40>


;RECEIVED CONTROL MESSAGE

FWRI10:	PUSHJ	P,RDDAP1##	;READ IN THE CONTROL MESSAGE
	 POPJ	P,		;ERROR
	MOVD1	T2,CFC		;CONTROL FUNCTION CODE
FWRI11:	JSP	T4,.CDISP##	;DISPATCH ON CONTROL CODE
		FWRI20,,$DVCON	;CONTROL(CONNECT), INITIALIZE I/O STREAM
		FWRI30,,$DVCPT	;CONTROL(PUT), WRITE RECORD/FILE
		0		;NO OTHERS SUPPORTED
	STOPCD	<CONTROL neither (CONNECT) nor (PUT) in FWRI10>


;HERE FOR CONTROL(CONNECT)

FWRI20:	MOVX	T1,IO.DCC	;THE DAP CONTROL(CONNECT) FLAG
	TDNE	T1,.IOCCF(IO)	;FIRST ONE?
	STOPCD	<Multiple CONTROL(CONNECT)s in FWRI20>
	IORM	T1,.IOCCF(IO)	;YES, FLAG I/O NOW ACTIVE
	PUSHJ	P,XDACK1##	;SEND AN ACK FOR THE CONTROL(CONNECT)
	 STOPCD	<XDACK failed in FWRI20>
	PUSHJ	P,XDFLS1##	;FORCE IT OUT NOW
	 STOPCD	<XDFLS failed in FWRI20>
	JRST	FWRI00		;BACK TO STATE DISPATCH


;HERE FOR CONTROL(PUT)

FWRI30:	MOVE	T1,.IOCCF(IO)	;GET CHANNEL CONTROL FLAGS
	TXNN	T1,IO.DCC	;HAVE WE SEEN A CONTROL(CONNECT)?
	STOPCD	<No CONTROL(CONNECT) before CONTROL(PUT) in FWRI30>
	MOVD1	T2,RAC		;RECORD ACCESS CONTROL
	CAIN	T2,$DVCSF	;SEQUENTIAL FILE ACCESS?
	JRST	FWRL00		;JUST START FILE TRANSFER LOOP
	STOPCD	<Not Sequential-File-Access for CONTROL(PUT) in FWRI30>
;HERE ON ACCOMP RATHER THAN CONTROL MESSAGE

FWRI90:	PUSHJ	P,RDCLR1##	;CLEAR OUT DAP REGION
	 STOPCD			;CAN'T HAPPEN
	SETOM	.IDCKS(IO)	;'CUZ ACCOMP HAS NO MENU!!
	PUSHJ	P,RDDAP1##	;READ IN ACCOMP MESSAGE
	 POPJ	P,		;NET DIED
	SKIPL	T1,.IDCKS(IO)	;DID ACCOMP INCLUDE A CRC VALUE?
	CAMN	T1,.IODIK(IO)	;YES, DOES IT MATCH OUR CALCULATION?
	JRST	FWRI93		;NO CRC, OR CRC MATCHES, ALL IS WELL
	MOVD	T2,AOP		;GET ORIGINAL FILE ACCESS OPTIONS
	TFNN	T2,ACK		;DID USER REQUEST CHECKSUMMING?
	JRST	FWRI93		;NO, THEN NOT A REAL ERROR
	MOVX	T2,IO.DCC	;THE "OPEN FOR I/O" FLAG
	TDNN	T2,.IOCCF(IO)	;IS FILE OPENED FOR I/O?
	JUMPE	T1,FWRI93	;IGNORE IF 0 (ASSUME REALLY A "BLANK" CRC)
	MOVEI	T1,50000+$DSCKE	;DAP FILE TRANSFER CHECKSUM (CRC) ERROR STATUS
	SETZ	T2,		;NO SECONDARY STATUS
	SETZB	T3,T4		;NOTHING ELSE EITHER
	PUSHJ	P,FXSTS1	;SEND A STATUS MESSAGE
	 POPJ	P,		;NET DIED?
	JRST	FWRI00		;BACK TO FILE-OPEN IDLE LOOP FOR ANOTHER ACCOMP

;FILE DATA IS OK (AS BEST AS WE CAN TELL), CLOSE OFF THE FILE

FWRI93:	MOVX	T2,IO.DCC	;THE "FILE IS OPEN FOR I/O" BIT
	ANDCAM	T2,.IOCCF(IO)	;NOTE NO MORE I/O
	PUSHJ	P,FACL01	;CHECK FOR ACCOMP-TIME CLOSE OPTIONS
	 JRST	[PUSHJ	P,FOFI01	;SEND ERROR STATUS TO REMOTE
		 POPJ	P,		;NET DIED?
		JRST	FWRI00]		;BACK TO FILE-OPEN IDLE LOOP
FWRI95:	MOVD1	T2,A2F		;ACCOMP FUNCTION
	JSP	T4,.CDISP##	;DISPATCH ON MESSAGE TYPE
		FWRI97,,$DVAES	;END OF STREAM (DON'T CLOSE THE FILE)
		FWRZ00,,$DVACL	;CLOSE FILE
		FWRZ30,,$DVACB	;CLOSE AND RENAME CURRENT FILE
		FWRZ50,,$DVAKL	;KILL/RESET CURRENT FILE
		FWRZ50,,$DVATR	;TERMINATE/ABORT CURRENT ACCESS
		0		;NONE OTHERS LEGAL
	STOPCD	<Unknown or illegal ACCOMP function in FWRI90>


;HERE ON ACCOMP(EOS) - JUST MARK THE FILE NOT I/O-ACTIVE

FWRI97:	PUSHJ	P,XDARS1##	;SEND THE ACCOMP(RESPONSE)
	 POPJ	P,		;NET DIED
	JRST	FWRI00		;BACK INTO OPEN-BUT-NOT-I/O-ACTIVE IDLE LOOP
;LOOP WRITING FILE IN SEQUENTIAL FILE TRANSFER MODE
;
;HERE TO WRITE THE NEWLY-CREATED FILE

FWRL00:	XMOVEI	T1,.IOIIN##	;INPUT INITIALIZATION ADDRESS
	MOVEM	T1,.IOISR(CI)	;FORCE INPUT INITIALIZATION
	MOVE	T1,.IOIOC(CI)	;GET PRIMARY CDB I/O CONTROL
	TXNN	T1,IC.RSI	;RECORD-STRUCTURED I/O?
	JRST	FWRL10		;NO, BYTE I/O, GO START IT UP
	MOVE	T1,.IORSZ(CI)	;GET PRIMARY RECORD SIZE
	CAIG	T1,0		;GOT A RECORD SIZE?
	MOVEI	T1,1234		;NO, HALLUCINATE ONE THEN
	MOVEM	T1,RSIFT3	;SAVE FOR ISR CALLS
	ADDI	T1,3		;*** 8-BIT BYTES
	LSH	T1,-2		;*** 8-BIT BYTES
	PUSHJ	P,.MMGWD##	;ALLOCATE A RECORD-BUFFER
	 POPJ	P,		;NO MEMORY
	DMOVEM	T1,RSIFFA	;SAVE THE PAIR
	HRLI	T2,(POINT 8,)	;CONCOCT A RECORD-BUFFER BYTE POINTER
	MOVEM	T2,RSIFT4	;SAVE FOR ISR CALLS
	JRST	FWRL20		;START UP RECORD I/O
;LOOP READING BYTES FROM THE REMOTE, WRITING TO THE SLAVE FILE

FWRL10:	MOVE	T1,CI		;INPUT (PRIMARY) CDB
	PUSHJ	P,@.IOISR(T1)	;READ NEXT INPUT BYTE
	 JRST	FWRL30		;MAYBE ACCOMP
FWRL15:	MOVE	T1,CO		;OUTPUT (SLAVE) CDB
	PUSHJ	P,@.IOOSR(T1)	;WRITE CURRENT BYTE TO THE SLAVE FILE
	 JRST	FWRL60		;ERROR, TELL REMOTE
	JRST	FWRL10		;LOOP BACK FOR MORE


;LOOP READING RECORDS FROM THE REMOTE, WRITING TO THE SLAVE FILE

FWRL20:	MOVE	T1,CI		;INPUT (PRIMARY) CDB
	SETO	T2,		;NO PARTICULAR RECORD ADDRESS
	DMOVE	T3,RSIFT3	;RECORD BUFFER COUNTER AND POINTER
	PUSHJ	P,@.IOISR(T1)	;READ NEXT INPUT RECORD
	 JRST	FWRL30		;MAYBE ACCOMP
FWRL25:	MOVE	T1,CO		;OUTPUT (SLAVE) CDB
	PUSHJ	P,@.IOOSR(T1)	;WRITE CURRENT RECORD TO THE SLAVE FILE
	 JRST	FWRL60		;ERROR, TELL REMOTE
	JRST	FWRL10		;LOOP BACK FOR MORE
;HERE ON EXCEPTION RETURN FROM INPUT BYTE

FWRL30:	MOVE	IO,CI		;SELECT PRIMARY CDB
	CAIE	M0,$EINMP	;INPUT MESSAGE PENDING?
	STOPCD	<Error from input byte in FWRL10>
	PUSHJ	P,RDMSG1##	;START UP DAP MESSAGE
	 POPJ	P,		;HMMMM
	CAIE	T2,$DHACM	;ACCESS COMPLETE?
	STOPCD	<Received DAP message not DATA nor ACCOMP in FWRL10>
	JRST	FWRI90		;GO HANDLE ACCOMP


;ERROR WRITING SLAVE OUTPUT FILE

FWRL60:	MOVE	IO,CI		;SELECT PRIMARY CDB
	MOVE	T2,M0		;POSITION RETURNED ERROR STATUS
	MOVEI	T4,DS2EI##	;DAP STATUS TO I/O STATUS TRANSLATION TABLE
	PUSHJ	P,FFIND1	;TRANSLATE TO DAP STATUS
	 SKIPA	T1,[$DSWER]	;GENERIC WRITE ERROR, $E???? AS SECONDARY STATUS
	SETZ	T2,		;KNOWN ERROR, NO SECONDARY STATUS
	ADDI	T1,50000	;DAP I/O LEVEL ERROR
	SETZB	T3,T4		;NOTHING ELSE EITHER
	PUSHJ	P,FXSTS1	;SEND ERROR STATUS TO REMOTE
	 POPJ	P,		;NET DIED
	PUSHJ	P,RDEAT1##	;EAT REST OF ANY CURRENT INPUT MESSAGE
	 POPJ	P,		;NET DIED

;ERROR STATE IDLE LOOP - WAIT FOR CONTINUE OR ABORT
;*** REALLY NEEDS INTERRUPT LEVEL MESSAGES!!!

FWRL70:	PUSHJ	P,RDMSG1##	;START NEXT DAP INPUT MESSAGE
	 POPJ	P,		;NET DIED
FWRL71:	JSP	T4,.CDISP##	;DISPATCH ON DAP MESSAGE TYPE
		FWRL74,,$DHDAT	;DATA
		FWRL80,,$DHCNT	;CONTINUE
		FWRI90,,$DHACM	;ACCOMP
		0		;NONE OTHERS
	STOPCD	<Unknown/illegal DAP message type in FWRL70>

;HERE ON DATA MESSAGE - EAT IT UP

FWRL74:	PUSHJ	P,RDDAT1##	;FIRE UP THE DATA MESSAGE
	 POPJ	P,		;NET DIED
	PUSHJ	P,RDEAT1##	;EAT THE DATA MESSAGE (UPDATING THE CRC)
	 POPJ	P,		;NET DIED
	JRST	FWRL70		;LOOP WAITING FOR CONTINUE


;HERE ON "CONTINUE" MESSAGE

FWRL80:	PUSHJ	P,RDDAP1##	;READ IN CONTINUE MESSAGE
	 POPJ	P,		;NET DIED
	MOVD1	T2,C2F		;CONTINUE TYPE
FWRL81:	JSP	T4,.CDISP##	;DISPATCH ON CONTINUATION TYPE
		FWRL83,,$DVCTA	;TRY AGAIN
		FWRL84,,$DVCSK	;SKIP AND IGNORE
		FWRL90,,$DVCAB	;ABORT FILE
		0		;NONE OTHERS
	STOPCD	<Unknown/illegal continue type in FWRL81>

;HERE TO TRY TO CONTINUE THE I/O

FWRL83:	TDZA	T2,T2		;TRY AGAIN
FWRL84:	MOVEI	T2,1		;SKIP AND IGNORE
	STOPCD	<Error continuation not yet written in FWRL84>


;HERE TO ABORT FURTHER I/O - WAIT FOR ACCOMP OF SOME FLAVOR

FWRL90:	PUSHJ	P,RDMSG1##	;START UP NEXT DAP INPUT MESSAGE
	 POPJ	P,		;NET DIED
FWRL91:	JSP	T4,.CDISP##	;DISPATCH ON RECEIVED MESSAGE TYPE
		FWRL94,,$DHDAT	;DATA
		FWRI90,,$DHACM	;ACCOMP
		0		;NONE OTHERS
	STOPCD	<Unknown/illegal message type in FWRL90>

;HERE ON DATA MESSAGE, JUST EAT IT UP

FWRL94:	PUSHJ	P,RDDAT1##	;FIRE UP THE DATA MESSAGE
	 POPJ	P,		;NET DIED
	PUSHJ	P,RDEAT1##	;EAT THE DATA (UPDATING THE CRC)
	 POPJ	P,		;NET DIED
	JRST	FWRL90		;LOOP WAITING FOR ACCOMP
;END OF FILE ACCESS
;
;FILE IS DONE, CLOSE OUTPUT FILE

FWRZ00:
FWRZ10:	MOVE	IO,CO		;SELECT SLAVE CDB
	PUSHJ	P,IOCLO0##	;CLOSE THE OUTPUT FILE
	 CAIA			;ERROR
	JRST	FWRZ90		;CAP OFF WITH ACCOMP
FWRZ17:	PUSHJ	P,FOFI01	;SEND ERROR STATUS TO REMOTE
	 POPJ	P,		;NET MUST HAVE DIED
	JRST	FWRI00		;BACK TO IDLE LOOP WITH OUTPUT FILE STILL OPEN


;RENAME CURRENT FILE

FWRZ30:	PUSHJ	P,FRDCB1	;READ IN NEW ATTRIBUTES/NAME MESSAGES
	 JRST	[CAIE	M0,$ECAUR	;ABORTED AT [REMOTE] USER'S REQUEST?
		POPJ	P,		;NO, LINK BLOWN AWAY
		CAIE	T2,$DVATR	;ACCOMP(TERMINATE)?
		STOPCD	<Unknown/illegal ACCOMP message in FWRZ30>
		PJRST	FWRZ80]		;YES, SEND ACCOMP(RESPONSE), GO IDLE
	SKIPN	.IOFS3(CO)	;*** DID WE RECEIVE A FILE SPEC?
	JRST	FWRZ10		;*** NO, JUST CLOSE THE FILE NORMALLY
	PUSHJ	P,FRDCE1	;DO THE REQUESTED RENAME OPERATION
	 JRST	FWRZ17		;OOPS - RENAME FAILED, INFORM THE REMOTE
	JRST	FWRZ90		;FILE CLOSED (BY IOFRN), SEND ACCOMP(RESPONSE)


;ABORT THE CURRENT FILE

FWRZ50:


;TERMINATE ACCESS (SAME AS ABORT FOR THE WRITE-CASE)

FWRZ80:	MOVE	IO,CO		;POINT TO SLAVE CDB
	PUSHJ	P,IOABO1##	;ABORT THE CURRENT FILE, IF POSSIBLE
	 STOPCD	<IOABO failed in FWRZ50>

;ACCESS IS COMPLETED

FWRZ90:	SKIPN	T1,RSIFFA	;GOT A RECORD BUFFER?
	JRST	FWRZ92		;NOPE
	MOVE	T2,RSIFFA+1	;YUP
	PUSHJ	P,.MMFWD##	;FREE IT UP
	 JFCL			;SHOULDN'T AUGHTA HAPPEN!
	SETZM	RSIFFA		;NO LONGER HAVE A RECORD BUFFER
FWRZ92:	MOVE	IO,CO		;SELECT SLAVE CDB
	PUSHJ	P,IORLS1##	;WE ARE DONE WITH FILE-LEVEL OPERATIONS
	 JFCL			;DON'T CARE
	JRST	FJOB93		;SEND ACCOMP(RESPONSE)
;FWSP01  --  HERE TO PROCESS A "SPOOLED" FILE
;
;Here if the created file is a local "spooled" file. In order to do it
;"right" FAL must go through some pretty amazing gyrations so that, comme
;par example, the remote user's name appears on the (e.g.,) printer banner.
;
;For this to work requires monitor version 70155 or later, previous
;monitors will not properly set up ppn, account string, and user name
;(as set here by the SPPRM.).

FWSP01:	SETO	T2,		;FLAG "SPOOLED" NONSENSE TO QUEOP
	PUSHJ	P,QUEOP0##	;AND LET QUEOP FIGURE IT ALL OUT
	 WARN	FWQ,<QUEOP to set spooling parameters didn't>
	JRST	.POPJ1##	;THAT TURNED OUT TO BE PRETTY EASY AFTER ALL...
;A stillborn method of handling the spooling stuff . . . included mostly
;for the reader's amusement . . .

REPEAT	0,<			;FOR PRE-70155 MONITORS, THIS ALMOST WORKS
	MOVE	P4,.IODCH(IO)	;STASH A COPY OF REAL SPOOLED CHARACTERISTICS
	HLRZ	T2,.I1DEV(IO)	;GET "REAL" DEVICE NAME
	MOVEI	T4,FWSPTQ	;TABLE OF DEVICE-TO-QUEUE CORRESPONDENCE
	PUSHJ	P,.CFIND##	;MATCH THE DEVICE TO A QUEUE
	 JRST	.POPJ1##	;FORGET IT
	MOVE	P3,T1		;SAVE THE QUEUE CODE FOR AWHILE
	LDB	T1,[POINTR .I1DEV(IO),<^O777700>]  ;NOMINAL NODE FIELD
	LDB	T2,[POINTR .I1DEV(IO),<^O000077>]  ;NOMINAL UNIT FIELD
	JUMPN	T2,FWSP06	;IF UNIT THEN NODE MUST PRECEDE
	JUMPN	T1,FWSP03	;NO UNIT, THEN ONLY ONE OF NODE OR UNIT

;HERE IF JUST GENERIC DEVICE (E.G., "LPT:")

	SETZB	T1,T2		;IF BLANK THEN NEITHER NODE NOR UNIT
	JRST	FWSP09		;SET NODE AND UNIT INFO

;HERE IF JUST NODE OR UNIT (E.G., "LPT1:" OR "LPT22:")

FWSP03:	TRNN	T1,000077	;ONE IF BY UNIT, TWO IF BY NODE
	JRST	FWSP05		;REALLY MEANT ONLY UNIT . . .
	LSHC	T1,-3		;LOW ORDER DIGIT OF NODE
	LSH	T1,-3		;STRIP OFF SIXBIT CHARACTER JUNK
	LSHC	T1,3		;RECOMBINE THE TWO-DIGIT NODE NUMBER
	ANDI	T1,77		;AND JUST THE TWO-DIGIT NODE NUMBER
	SETZ	T2,		;NO UNIT INFO
	JRST	FWSP09		;SET NODE AND UNIT INFO

;HERE IF BOTH NODE AND UNIT (E.G., "LPT221:")

FWSP05:	EXCH	T1,T2		;REPOSITION UNIT NUMBER, NULL NODE NUMBER
	LSH	T2,-6		;RIGHT-JUSTIFY UNIT NUMBER
FWSP06:	MOVEI	M0,-'0'(T2)	;SAVE UNIT NUMBER IN M0
	LSHC	T1,-3		;LOW ORDER DIGIT OF NODE
	LSH	T1,-3		;STRIP OFF SIXBIT JUNK
	LSHC	T1,3		;RECOMBINE THE TWO DIGIT NODE NUMBER
	ANDI	T1,77		;AND JUST THE TWO-DIGIT NODE NUMBER
	MOVE	T2,M0		;RETRIEVE THE UNIT NUMBER
	HRLI	T2,.QBUPH	;AND NOTE IT IS A PHYSICAL UNIT REQUEST
FWSP09:	MOVEM	T1,.IOQND(IO)	;SET /DESTINATION NODE NUMBER
	MOVEM	T2,.IOQUN(IO)	;SET /UNIT NUMBER, IF ANY

;NOW SET "JOB NAME" FROM USER-SPECIFIED FILE NAME (IF ANY)

FWSP10:	MOVE	T1,.I1LKP+.RBNAM(IO)  ;GET ENTER'ED FILE NAME
	MOVEM	T1,.IOQ6J(IO)	;AND SET THAT AS THE QUEUE REQUEST NAME

;CONTINUED ON NEXT PAGE
;STILL IN REPEAT 0

;CONTINUED FROM PREVIOUS PAGE

;ABORT THE AS-SPECIFIED-BY-USER FILE

FWSP30:	PUSHJ	P,IOABO0##	;ABORT THE FILE
	 JFCL			;CAN'T HAPPEN

;NOW SETUP OUR VERY OWN IMITATION SPOOL FILE SPL:FALnnn.SPL

FWSP40:	MOVE	P1,.IOFSB(IO)	;ADDRESS OF FILE SPEC BLOCK FOR OUTPUT
	SETO	T2,		;NON-WILD MASK
	MOVSI	T1,'SPL'	;DEVICE IS SYSTEM-SPOOL
	DMOVEM	T1,.FXDEV(P1)	;SET IN FILE SPEC BLOCK
	XMOVEI	T3,[ASCIZ\SPL\]	;ASCII STRING DEVICE NAME
	MOVEM	T3,.FSDEV(P1)	;SET IN FILE SPEC BLOCK
	SETZM	.FXDIR(P1)	;NO DIRECTORY
	SETZM	.FXDIR(P1)	; . . .
	SETZM	.FSDIR(P1)	; . . .
	MOVE	T1,['FAL001']	;FILE NAME
	DMOVEM	T1,.FXNAM(P1)	;SET IN FILE SPEC BLOCK
	XMOVEI	T3,[ASCIZ\FAL001\]  ;ASCII STRING FILE NAME
	MOVEM	T3,.FSNAM(P1)	;SET IN FILE SPEC BLOCK
	HRLOI	T1,'SPL'	;DEFAULT FILE TYPE
	MOVEM	T1,.FXEXT(P1)	;SET IN FILE SPEC BLOCK
	XMOVEI	T3,[ASCIZ\SPL\]	;ASCII STRING FILE TYPE
	MOVEM	T3,.FSEXT(P1)	;SET IN FILE SPEC BLOCK
	MOVX	T1,FX.SUP	;ALSO SPECIFY /ERSUPERSEDE
	IORM	T1,.FXMOD(P1)	;IN THE FILE SPEC BLOCK
	IORM	T1,.FXMOM(P1)	;AND MAKE IT STICKY TOO!

;NOW CREATE THE FILE, LOOPING ON THE 'nnn' UNTIL A FILE IS CREATED

FWSP50:	MOVX	T1,IM.UNQ	;THE CREATE-UNIQUE-NAME FLAG
	IORM	T1,.IOIOM(IO)	;TELL IOPOU . . .
	SETZ	T2,		;NO INPUT FILE FROM WHICH TO WILDCARD
	PUSHJ	P,IOPOU0##	;CREATE OUTPUT FILE
	 PJRST	[PUSHJ	P,FOFI01	;PROCESS UNEXPECTED FILE ERROR
		  POPJ	P,		;ERROR RETURN
		POPJ	P,]		;DIFFERENT ERROR RETURN

;FAKE SPOOL FILE ALL SET UP!

FWSP60:	MOVEM	P4,.IODCH(IO)	;RETURN FAKE SPOOL CHARACTERISTICS
	MOVEM	P3,FQUFNC	;*** SET SPOOLED FLAG
	JRST	.POPJ1##	;SUCCESSFUL INTERCEPTED RETURN
;STILL IN REPEAT 0

;TABLE OF DEVICE TYPE TO QUEUE CORRESPONDENCE

FWSPTQ:	.QUPRT,,'LPT'		;LINEPRINTERS
	.QUCDP,,'CDP'		;CARD PUNCH
	.QUPTP,,'PTP'		;PAPER TAPE PUNCH
	.QUPLT,,'PLT'		;PLOTTER
	0			;THAT'S ALL

> ;END OF REPEAT 0 FOR PRE-70155 MONITORS
	SUBTTL	File rename access

FREN00:	MOVE	IO,CI		;ADDRESS OF PRIMARY CDB

;READ IN SECONDARY NAME MESSAGE (NEW FILE SPECIFICATION)

FREN02:	PUSHJ	P,FRENA1	;READ IN ALL THE ANCILLIARY STUFF
	 JRST	[CAIE	M0,$ECAUR	;ABORTED AT [REMOTE] USER'S REQUEST?
		POPJ	P,		;NO, LINK BLOWN AWAY
		CAIN	T2,$DVATR	;YES, MUST BE ACCOMP(TERMINATE)
		PJRST	FJOB93		;SEND ACCOMP(RESPONSE), GO IDLE
		STOPCD	<Illegal/unknown ACCOMP message in FREN02>
		]

;LOOP FINDING FILES

FREN10:	PUSHJ	P,FIFIL1	;FIND NEXT POSSIBLY-WILD INPUT FILE
	  POPJ	P,		;(0) NET DIED OR OTHER FATAL ERROR
	 JRST	FREN90		;(1) INPUT FILE STREAM EXHAUSTED
				;(2) CONTINUE WITH RETURNED FILE

;RETURN FILE INFORMATION TO REMOTE ACCESSOR (E.G., NFT)

FREN20:	MOVE	IO,CI		;RE-SELECT PRIMARY CDB
	MOVD	T1,AOP		;ACCESS OPTIONS FIELD
	MOVD	P1,ADS		;ACCESS DISPLAY FIELD
	TFNN	T1,GNG		;IF NOT GO/NOGO
	FJUMPE	P1,ADS,FREN50	;AND NO DISPLAY THEN ALL DONE HERE

;HERE IF NEED TO SEND NAME/ATTRIBUTES

FREN22:	PUSHJ	P,FANTY1	;HANDLE ANY NAME MESSAGES DUE TO WILDCARDING
	 POPJ	P,		;NET DIED
	MOVD	P1,ADS		;RETRIEVE ACCESS DISPLAY FIELD AGAIN
	FJUMPE	P1,ADS,FREN29	;CAP OFF WITH ACK IF NO DISPLAY REQUESTED
	PUSHJ	P,FFAD01	;TRANSLATE FILE ATTRIBUTES INTO DAP BLOCK
	 STOPCD	<FFAD failed in FREN20>
	MOVD	P1,ADS		;RESTORE ACCESS DISPLAY FIELD
	PUSHJ	P,FXAT01	;SEND ATTRIBUTES MESSAGES
	 STOPCD	<FXAT failed in FREN20>
FREN29:	PUSHJ	P,FX7ACK	;CAP OFF FILE NAME/ATTRIBUTES
	 POPJ	P,		;NET DIED?


;END OF FILE INFORMATION - HANDLE GO/NOGO IF SPECIFIED

FREN40:	MOVD	T1,AOP		;GET ACCESS OPTIONS
	TFNN	T1,GNG		;DID REMOTE SPECIFY GO/NOGO?
	JRST	FREN50		;NO, JUST RENAME THE FILE
	PUSHJ	P,XDFLS1##	;YES, FLUSH OUT ATTR/ET AL TO REMOTE
	 STOPCD	<XDFLS1 failed in FREN40>

;NOW WAIT FOR REMOTE TO MAKE UP ITS MIND

FREN41:	PUSHJ	P,RDMSG1##	;GET REMOTE'S GO/NOGO DECISION
	 POPJ	P,		;NET MUST HAVE DIED
FREN42:	JSP	T4,.CDISP##	;DISPATCH BASED ON REMOTE'S DECISION
		FREN43,,$DHSTS	;STATUS - SHOULDN'T HAPPEN
		FREN45,,$DHCNT	;CONTINUE - RESPONSE FOR GO/NOGO (OBSOLETE)
		FREN48,,$DHACM	;ACCESS COMPLETE - RESPONSE FOR GO/NOGO
		0		;NONE OTHER
	STOPCD	<Unknown GO/NOGO response from remote at FREN42>


;RECEIVED STATUS

FREN43:	PUSHJ	P,RDSTS1##	;READ IN REST OF STATUS
	 STOPCD			;SHOULDN'T HAPPEN
	STOPCD	<STATUS received in FREN40>


;RECEIVED CONTINUE

FREN45:	PUSHJ	P,RDDAP1##	;READ IN REST OF CONTINUE MESSAGE
	 STOPCD			;SHOULDN'T HAPPEN
	MOVD1	T1,C2F		;CONTINUE FUNCTION CODE
	CAIN	T1,$DVCSK	;SKIP THIS FILE?
	JRST	FREN70		;YES, KEEP THIS FILE
	CAIN	T1,$DVCRS	;RESUME PROCESSING?
	JRST	FREN50		;YES, RENAME THIS FILE
	STOPCD	<Unknown or illegal CONTINUE function in FREN45>


;RECEIVED ACCOMP

FREN48:	PUSHJ	P,RDCLR1##	;CLEAR OUT DAP AREA
	 STOPCD			;CAN'T HAPPEN
	PUSHJ	P,RDDAP1##	;READ IN REST OF ACCESS COMPLETE
	 STOPCD			;SHOULDN'T HAPPEN
	MOVD1	T1,A2F		;GET ACCESS COMPLETE FUNCTION
	CAIN	T1,$DVACL	;NORMAL FUNCTION TERMINATION?
	JRST	FREN50		;YES, RENAME THE FILE
	CAIN	T1,$DVASK	;WANT TO SKIP THIS FILE?
	JRST	FREN70		;YES, DON'T RENAME THE FILE
	CAIN	T1,$DVATR	;WANT TO TERMINATE/ABORT THIS ACCESS?
	JRST	FREN90		;YES
	STOPCD	<Unknown ACCOMP function in FREN48>


;HERE TO RENAME THE CURRENT FILE

FREN50:	MOVE	IO,CO		;SELECT SLAVE CDB
	PUSHJ	P,IOFRN1##	;RENAME CURRENT FILE
	 CAIA			;ERROR RETURN
	JRST	FREN60		;TIME FOR SECOND ATTRIBUTES/NAME

;HERE WHEN RENAME FAILS (NOTE NAME/ATTR ALREADY SENT . . .)

	PUSHJ	P,FOFI01	;SEND ERROR STATUS TO REMOTE
	 JRST	FREN90		;NET DIED?
	JRST	FREN10		;TRY FOR NEXT FILE


;NOW SEND RESULTANT NAME/ATTRIBUTES

FREN60:	MOVE	IO,CI		;SELECT PRIMARY CDB AGAIN
	MOVD	T1,AOP		;ACCESS OPTIONS FIELD
	MOVD	P1,ADS		;ACCESS DISPLAY FIELD
	TFNN	T1,GNG		;IF NOT GO/NOGO
	FJUMPE	P1,ADS,FREN10	;AND NO DISPLAY THEN ALL DONE HERE

;HERE IF NEED TO SEND SECOND SET OF NAME/ATTRIBUTES


FREN62:	PUSHJ	P,FANTY1	;HANDLE ANY NAME MESSAGES DUE TO WILDCARDING
	 POPJ	P,		;NET DIED
	MOVD	P1,ADS		;RETRIEVE ACCESS DISPLAY FIELD AGAIN
	FJUMPE	P1,ADS,FREN69	;CAP OFF WITH ACK IF NO DISPLAY REQUESTED
	PUSHJ	P,FFAD01	;TRANSLATE FILE ATTRIBUTES INTO DAP BLOCK
	 STOPCD	<FFAD failed in FREN60>
	MOVD	P1,ADS		;RESTORE ACCESS DISPLAY FIELD
	PUSHJ	P,FXAT01	;SEND ATTRIBUTES MESSAGES
	 STOPCD	<FXAT failed in FREN60>

FREN69:	PUSHJ	P,FX7ACK	;CAP OFF FILE NAME/ATTRIBUTES
	 POPJ	P,		;NET DIED?

	JRST	FREN10		;TRY FOR ANOTHER FILE


;SKIP CURRENT FILE, ADVANCE TO NEXT INPUT FILE

FREN70:	MOVE	IO,CO		;POINT TO SLAVE CDB
	MOVX	T1,IM.SAD	;THE SUPPRESS-ACCESS-DATE-UPDATE BIT
	IORM	T1,.IOIOM(IO)	;PRETEND NOT TO HAVE ACCESSED CURRENT FILE
	PUSHJ	P,IOCLO1##	;TOSS THE CURRENT FILE
	 JFCL			;DON'T CARE
	MOVX	T1,IM.SAD	;THE BIT AGAIN
	ANDCAM	T1,.IOIOM(IO)	;CLEAR BACK OUT OF THE CDB
	JRST	FREN10		;TRY FOR ANOTHER FILE


;ALL FILES PROCESSED, ACCESS IS COMPLETED

FREN90:	MOVE	IO,CO		;SELECT SLAVE CDB
	PUSHJ	P,IORLS1##	;WE ARE DONE WITH FILE-LEVEL OPERATIONS
	 JFCL			;DON'T CARE
	JRST	FJOB93		;SEND ACCOMP(RESPONSE)
;RENAME-class helper subroutines

;FRENA - Read in the "ancilliary" messages that follow the ACCESS(RENAME)
;
;Also used by ACCOMP(RENAME)

FRENA1:	PUSHJ	P,RDMSG1##	;START THE NEXT MESSAGE IN
	 POPJ	P,		;NET DIED?
	JSP	T4,.CDISP##	;DISPATCH BASED ON MESSAGE TYPE
		FRENA4,,$DHATR	;MAIN ATTRIBUTES, SLURP IT UP
		FRENA4,,$DHALC	;ALLOCATION ATTRUBUTES
		FRENA4,,$DHTIM	;DATE/TIME ATTRIBUTES
		FRENA4,,$DHPRT	;PROTECTION ATTRIBUTES
		FRENA5,,$DHNAM	;NAME
		FRENA9,,$DHACM	;ACCOMP
		0		;NONE OTHERS


;RECEIVED ATTRIBUTES OF SOME FLAVOR, JUST SLURP THEM UP

FRENA4:	PUSHJ	P,RDDAP1##	;READ IN THE ATTRIBUTES MESSAGE
	 JSP	T4,FERDP	;ERROR IN ATTRIBUTES MESSAGE
	JRST	FRENA1		;LOOP WAITING FOR NAME MESSAGE


;RECEIVED NAME MESSAGE

FRENA5:	PUSHJ	P,RDDAP1##	;READ IN THE NAME MESSAGE BODY
	 POPJ	P,		;NET DIED?
	MOVD	T1,NTY		;NAME TYPE FIELD
	TFNN	T1,NFS		;CONTAIN A FILE SPECIFICATION?
	STOPCD	<Not a file spec NAME message in FRENA5>
	PUSHJ	P,DPRNN1##	;PARSE THE RECEIVED NAME FILE SPEC
	 STOPCD	<DPRNN failed in FRENA5>
	SKIPN	T1,.IOXFF(CO)	;SLAVE FREE SPACE
	STOPCD	<No "extra" space in slave CDB in FREN02>
	ADDI	T1,.FXMAX	;SIZE OF FILE SPEC BLOCK
	CAML	T1,.IOXSZ(CO)	;ROOM FOR TERTIARY FILE SPEC BLOCK?
	STOPCD	<No room in slave CDB for tertiary FSB in FREN02>
	EXCH	T1,.IOXFF(CO)	;ALLOCATE ONE FSB FROM "EXTRA" SPACE
	ADD	T1,CO		;RELOCATE FSB ADDRESS INTO MEMORY
	MOVEM	T1,.IOFS3(CO)	;SET "OUTPUT" FILE SPEC BLOCK ADDRESS
	MOVEM	T1,.IOFS3(CI)	;SET PRIMARY TOO, JUST ON G.P.S
	MOVEI	T2,.FXMAX	;SIZE OF FILE SPEC BLOCK
	PUSHJ	P,.GTSPC##	;COPY OVER THE FILE SPEC BLOCK

;NOW COPY OVER ANY "NEW" ATTRIBUTES TOO

	MOVE	P3,.IOIOC(CO)	;CURRENT I/O CONTROL
	MOVE	P4,.IOIOM(CO)	;CURRENT I/O MODE FLAGS
	PUSHJ	P,FAJA10	;VERIFY ATTRIBUTES/ET AL
	 POPJ	P,		;OOPS

;THIS TERMINATES THE "ANCILLIARY" MESSAGES, TIME TO DO THE REAL WORK NOW!

	JRST	.POPJ1##	;SUCCESSFUL RETURN


;RECEIVED ACCOMP - REMOTE MUST WANT TO ABORT THE ACCESS

FRENA9:	PUSHJ	P,RDCLR1##	;CLEAR OUT THE DAP DATA
	 STOPCD			;CAN'T HAPPEN
	PUSHJ	P,RDDAP1##	;READ IN THE ACCOMP MESSAGE
	 POPJ	P,		;OH WELL
	MOVD	T2,A2F		;THE ACCOMP FUNCTION CODE
	MOVEI	M0,$ECAUR	;NOTE RECEIVED ACCOMP BEFORE NAME MESSAGE
	POPJ	P,		;LET CALLER FIGURE OUT WHAT TO DO
	SUBTTL	File delete access

FDEL00:

;LOOP FINDING FILES

FDEL10:	PUSHJ	P,FIFIL1	;FIND NEXT POSSIBLY-WILD INPUT FILE
	  POPJ	P,		;(0) NET DIED OR OTHER FATAL ERROR
	 JRST	FDEL90		;(1) INPUT FILE STREAM EXHAUSTED
				;(2) CONTINUE WITH RETURNED FILE

;RETURN FILE INFORMATION TO REMOTE ACCESSOR (E.G., NFT)

FDEL20:	MOVE	IO,CI		;RE-SELECT PRIMARY CDB
	MOVD	T1,AOP		;ACCESS OPTIONS FIELD
	MOVD	P1,ADS		;ACCESS DISPLAY FIELD
	TFNN	T1,GNG		;UNLESS GO/NOGO
	FJUMPE	P1,ADS,FDEL50	;THEN NO NAME/ATTR IF NO DISPLAY

;HERE IF NEED NAME AND/OR ATTRIBUTES MESSAGES

FDEL22:	PUSHJ	P,FANTY1	;SEND WILDCARDED NAMES AS NEEDED
	 POPJ	P,		;NET DIED?
	MOVD	P1,ADS		;RETRIEVE COPY OF ACCESS DISPLAY
	FJUMPE	P1,ADS,FDEL29	;IF NO DISPLAY, CAP OFF NAME WITH AN ACK
	PUSHJ	P,FFAD01	;TRANSLATE FILE ATTRIBUTES INTO DAP BLOCK
	 STOPCD	<FFAD failed in FDEL20>
	MOVD	P1,ADS		;RESTORE ACCESS DISPLAY FIELD
	PUSHJ	P,FXAT01	;SEND ATTRIBUTES MESSAGES
	 STOPCD	<FXAT failed in FDEL20>
FDEL29:	PUSHJ	P,FX7ACK	;CAP OFF NAME/ATTRIBUTES WITH AN ACK
	 POPJ	P,		;NET DIED?


;END OF FILE INFORMATION - HANDLE GO/NOGO IF SPECIFIED

FDEL40:	MOVD	T1,AOP		;GET ACCESS OPTIONS
	TFNN	T1,GNG		;DID REMOTE SPECIFY GO/NOGO?
	JRST	FDEL50		;NO, JUST DELETE THE FILE
	PUSHJ	P,XDFLS1##	;YES, FLUSH OUT ATTR/ET AL TO REMOTE
	 STOPCD	<XDFLS1 failed in FDEL40>

;NOW WAIT FOR REMOTE TO MAKE UP ITS MIND

FDEL41:	PUSHJ	P,RDMSG1##	;GET REMOTE'S GO/NOGO DECISION
	 POPJ	P,		;NET MUST HAVE DIED
FDEL42:	JSP	T4,.CDISP##	;DISPATCH BASED ON REMOTE'S DECISION
		FDEL43,,$DHSTS	;STATUS - SHOULDN'T HAPPEN
		FDEL45,,$DHCNT	;CONTINUE - RESPONSE FOR GO/NOGO (OBSOLETE)
		FDEL48,,$DHACM	;ACCESS COMPLETE - RESPONSE FOR GO/NOGO
		0		;NONE OTHER
	STOPCD	<Unknown GO/NOGO response from remote at FDEL42>


;RECEIVED STATUS

FDEL43:	PUSHJ	P,RDSTS1##	;READ IN REST OF STATUS
	 STOPCD			;SHOULDN'T HAPPEN
	STOPCD	<STATUS received in FDEL40>


;RECEIVED CONTINUE

FDEL45:	PUSHJ	P,RDDAP1##	;READ IN REST OF CONTINUE MESSAGE
	 STOPCD			;SHOULDN'T HAPPEN
	MOVD1	T1,C2F		;CONTINUE FUNCTION CODE
	CAIN	T1,$DVCSK	;SKIP THIS FILE?
	JRST	FDEL70		;YES, KEEP THIS FILE
	CAIN	T1,$DVCRS	;RESUME PROCESSING?
	JRST	FDEL50		;YES, DELETE THIS FILE
	STOPCD	<Unknown or illegal CONTINUE function in FDEL45>


;RECEIVED ACCOMP

FDEL48:	PUSHJ	P,RDCLR1##	;CLEAR OUT STALE DAP FIELDS FIRST
	 STOPCD			;CAN'T HAPPEN
	PUSHJ	P,RDDAP1##	;READ IN REST OF ACCESS COMPLETE
	 STOPCD			;SHOULDN'T HAPPEN
	MOVD1	T1,A2F		;GET ACCESS COMPLETE FUNCTION
	CAIN	T1,$DVACL	;NORMAL FILE TERMINATION?
	JRST	FDEL50		;YES, DELETE THE FILE
	CAIN	T1,$DVASK	;SKIP THIS FILE?
	JRST	FDEL70		;YES, KEEP THIS FILE
	CAIN	T1,$DVATR	;WANT TO TERMINATE/ABORT THIS ACCESS?
	JRST	FDEL90		;YES
	STOPCD	<Unknown ACCOMP function in FDEL48>


;HERE TO DELETE THE CURRENT FILE

FDEL50:	MOVE	IO,CO		;SELECT SLAVE CDB
	PUSHJ	P,IOFDL1##	;DELETE CURRENT FILE
	 CAIA			;ERROR RETURN
	JRST	FDEL10		;TRY FOR ANOTHER FILE

;HERE WHEN DELETE FAILS (NOTE NAME/ATTR ALREADY SENT . . .)

	PUSHJ	P,FOFI01	;SEND ERROR STATUS TO REMOTE
	 JRST	FDEL90		;NET DIED?
	JRST	FDEL10		;TRY FOR NEXT FILE


;SKIP CURRENT FILE, ADVANCE TO NEXT INPUT FILE

FDEL70:	MOVE	IO,CO		;POINT TO SLAVE CDB
	MOVX	T1,IM.SAD	;THE SUPPRESS-ACCESS-DATE-UPDATE BIT
	IORM	T1,.IOIOM(IO)	;PRETEND NOT TO HAVE ACCESSED CURRENT FILE
	PUSHJ	P,IOCLO1##	;TOSS THE CURRENT FILE
	 JFCL			;DON'T CARE
	MOVX	T1,IM.SAD	;THE BIT AGAIN
	ANDCAM	T1,.IOIOM(IO)	;CLEAR BACK OUT OF THE CDB
	JRST	FDEL10		;TRY FOR ANOTHER FILE


;ALL FILES PROCESSED, ACCESS IS COMPLETED

FDEL90:	MOVE	IO,CO		;SELECT SLAVE CDB
	PUSHJ	P,IORLS1##	;WE ARE DONE WITH FILE-LEVEL OPERATIONS
	 JFCL			;DON'T CARE
	JRST	FJOB93		;SEND ACCOMP(RESPONSE)
	SUBTTL	File directory-list access

FDIR00:

;LOOP FINDING FILES

FDIR10:	PUSHJ	P,FIFIL1	;FIND NEXT POSSIBLY-WILD INPUT FILE
	  POPJ	P,		;(0) NET DIED OR OTHER FATAL ERROR
	 JRST	FDIR90		;(1) INPUT FILE STREAM EXHAUSTED
				;(2) CONTINUE WITH RETURNED FILE

;RETURN FILE INFORMATION TO REMOTE ACCESSOR (E.G., NFT)

FDIR20:	MOVE	IO,CI		;RE-SELECT PRIMARY CDB
	PUSHJ	P,FANTY3	;FORCE SENDING OF NAME MESSAGES FOR "DIRECTORY"
	 STOPCD	<FANTY failed in FDIR20>

;COPY OVER AND SEND ANY FILE ATTRIBUTES REQUESTED

FDIR30:	MOVD	P1,ADS		;ACCESS DISPLAY FIELD
	FJUMPE	P1,ADS,FDIR40	;IF NO DISPLAY ALL DONE HERE
	PUSHJ	P,FFAD01	;TRANSLATE FILE ATTRIBUTES INTO DAP BLOCK
	 STOPCD	<FFAD failed in FDIR35>
	MOVD	P1,ADS		;RESTORE ACCESS DISPLAY FIELD
	PUSHJ	P,FXAT01	;SEND ATTRIBUTES MESSAGES
	 STOPCD	<FXAT failed in FDIR35>


;END OF FILE INFORMATION.

FDIR40:				;NO FILE PROCESSING

;ADVANCE TO NEXT INPUT FILE

FDIR70:	MOVE	IO,CO		;POINT TO SLAVE CDB
	PUSHJ	P,IOCLO1##	;TOSS THE CURRENT FILE
	 JFCL			;DON'T CARE
	JRST	FDIR10		;TRY FOR ANOTHER FILE


;ALL FILES PROCESSED, ACCESS IS COMPLETED

FDIR90:	MOVE	IO,CO		;SELECT SLAVE CDB
	PUSHJ	P,IORLS1##	;WE ARE DONE WITH FILE-LEVEL OPERATIONS
	 JFCL			;DON'T CARE
	JRST	FJOB93		;SEND ACCOMP(RESPONSE)
	SUBTTL	File (BATCH) submission access

FSUB00:	STOPCD	<DAP "SUBMIT" operation not supported>

FEXE00:	PUSHJ	P,NONPP1	;DISALLOW NETPPN HERE
	 JRST	[PUSHJ	P,FOFI01	;SEND ERROR STATUS TO REMOTE
		 POPJ	P,		;NET DIED?
		JRST	FJOB95]		;BACK TO IDLE STATE

;LOOP FINDING FILES

FEXE10:	PUSHJ	P,FIFIL1	;FIND NEXT POSSIBLY-WILD INPUT FILE
	  POPJ	P,		;(0) NET DIED OR OTHER FATAL ERROR
	 JRST	FEXE90		;(1) INPUT FILE STREAM EXHAUSTED
				;(2) CONTINUE WITH RETURNED FILE

;RETURN FILE INFORMATION TO REMOTE ACCESSOR (E.G., NFT)

FEXE20:	MOVE	IO,CI		;RE-SELECT PRIMARY CDB
	MOVD	T1,AOP		;ACCESS OPTIONS
	MOVD	P1,ADS		;ACCESS DISPLAY FIELD
	TFNN	T1,GNG		;UNLESS GO/NOGO SPECIFIED
	FJUMPE	P1,ADS,FEXE50	;THEN NO NAMES/ATTRIBUTES IF NO DISPLAY

;HERE WHEN MUST RETURN NAMES AND/OR ATTRIBUTES TO THE REMOTE ACCESSOR

FEXE22:	PUSHJ	P,FANTY1	;SEND BACK RESULTANT WILDCARDED NAMES
	 POPJ	P,		;NET DIED?
	MOVD	P1,ADS		;RETRIEVE ACCESS DISPLAY REQUEST
	FJUMPE	P1,ADS,FEXE29	;IF NO DISPLAY THEN CAP OFF NAMES WITH AN ACK
	PUSHJ	P,FFAD01	;TRANSLATE FILE ATTRIBUTES INTO DAP BLOCK
	 STOPCD	<FFAD failed in FEXE20>
	MOVD	P1,ADS		;RESTORE ACCESS DISPLAY FIELD
	PUSHJ	P,FXAT01	;SEND ATTRIBUTES MESSAGES
	 STOPCD	<FXAT failed in FEXE20>
FEXE29:	PUSHJ	P,FX7ACK	;CAP OFF WITH AN ACK
	 POPJ	P,		;NET DIED?


;END OF FILE INFORMATION - HANDLE GO/NOGO IF SPECIFIED

FEXE40:	MOVD	T1,AOP		;GET ACCESS OPTIONS
	TFNN	T1,GNG		;DID REMOTE SPECIFY GO/NOGO?
	JRST	FEXE50		;NO, JUST SUBMIT THE FILE
	PUSHJ	P,XDFLS1##	;YES, FLUSH OUT ATTR/ET AL TO REMOTE
	 STOPCD	<XDFLS1 failed in FEXE40>

;NOW WAIT FOR REMOTE TO MAKE UP ITS MIND

FEXE41:	PUSHJ	P,RDMSG1##	;GET REMOTE'S GO/NOGO DECISION
	 POPJ	P,		;NET MUST HAVE DIED
FEXE42:	JSP	T4,.CDISP##	;DISPATCH BASED ON REMOTE'S DECISION
		FEXE43,,$DHSTS	;STATUS - SHOULDN'T HAPPEN
		FEXE45,,$DHCNT	;CONTINUE - RESPONSE FOR GO/NOGO (OBSOLETE)
		FEXE48,,$DHACM	;ACCESS COMPLETE - RESPONSE FOR GO/NOGO
		0		;NONE OTHER
	STOPCD	<Unknown GO/NOGO response from remote at FEXE42>


;RECEIVED STATUS

FEXE43:	PUSHJ	P,RDSTS1##	;READ IN REST OF STATUS
	 STOPCD			;SHOULDN'T HAPPEN
	STOPCD	<STATUS received in FEXE40>


;RECEIVED CONTINUE

FEXE45:	PUSHJ	P,RDDAP1##	;READ IN REST OF CONTINUE MESSAGE
	 STOPCD			;SHOULDN'T HAPPEN
	MOVD1	T1,C2F		;CONTINUE FUNCTION CODE
	CAIN	T1,$DVCSK	;SKIP THIS FILE?
	JRST	FEXE70		;YES, KEEP THIS FILE
	CAIN	T1,$DVCRS	;RESUME PROCESSING?
	JRST	FEXE50		;YES, SUBMIT THIS FILE
	STOPCD	<Unknown or illegal CONTINUE function in FEXE45>


;RECEIVED ACCOMP

FEXE48:	PUSHJ	P,RDCLR1##	;CLEAR OUT STALE DAP INFO
	 STOPCD			;CAN'T HAPPEN
	PUSHJ	P,RDDAP1##	;READ IN REST OF ACCESS COMPLETE
	 STOPCD			;SHOULDN'T HAPPEN
	MOVD1	T1,A2F		;GET ACCESS COMPLETE FUNCTION
	CAIN	T1,$DVACL	;NORMAL FILE TERMINATION?
	JRST	FEXE50		;YES, EXECUTE THIS FILE
	CAIN	T1,$DVASK	;SKIP THIS FILE?
	JRST	FEXE70		;YES, LEAVE THE BATCH SYSTEM ALONE
	CAIN	T1,$DVATR	;WANT TO TERMINATE/ABORT THIS ACCESS?
	JRST	FEXE90		;YES
	STOPCD	<Unknown ACCOMP function in FEXE48>


;HERE TO SUBMIT THE CURRENT FILE

FEXE50:	MOVE	IO,CO		;SELECT SLAVE CDB
	PUSHJ	P,IOFSU1##	;SUBMIT THE CURRENT OPEN FILE
	 CAIA			;OOPS - FAILURE
	JRST	FEXE73		;CLOSE THIS ONE AND TRY FOR ANOTHER FILE

;HERE WHEN THE SUBMIT REQUEST FAILS

	PUSHJ	P,FOFI01	;SEND STATUS MESSAGE TO REMOTE
	 JRST	FEXE90		;NET DIED? ABORT ACCESS
	JRST	FEXE73		;TRY FOR ANOTHER FILE


;SKIP CURRENT FILE, ADVANCE TO NEXT INPUT FILE

FEXE70:	MOVE	IO,CO		;POINT TO SLAVE CDB
	MOVX	T1,IM.SAD	;THE SUPPRESS-ACCESS-DATE-UPDATE BIT
	IORM	T1,.IOIOM(IO)	;PRETEND NOT TO HAVE ACCESSED CURRENT FILE
FEXE73:	PUSHJ	P,IOCLO1##	;TOSS THE CURRENT FILE
	 JFCL			;DON'T CARE
	MOVX	T1,IM.SAD	;THE BIT AGAIN
	ANDCAM	T1,.IOIOM(IO)	;CLEAR BACK OUT OF THE CDB
	JRST	FEXE10		;TRY FOR ANOTHER FILE


;ALL FILES PROCESSED, ACCESS IS COMPLETED

FEXE90:	MOVE	IO,CO		;SELECT SLAVE CDB
	PUSHJ	P,IORLS1##	;WE ARE DONE WITH FILE-LEVEL OPERATIONS
	 JFCL			;DON'T CARE
	JRST	FJOB93		;SEND ACCOMP(RESPONSE)
	SUBTTL	General-purpose file-level subroutines

;HELPER TO PARSE FILE FROM ACCESS MESSAGE

FALIF0:	TDZA	T2,T2		;FLAG FIRST TIME IN
FALIF1:	MOVEI	T2,1		;FLAG CONTINUATION READ
	PUSHJ	P,.SAVE4##	;SCAN'S CH AND NM ARE OUR P3 AND P4 !!!
	MOVE	P2,T2		;PROTECT FLAG
	SETZM	.IOXTO(IO)	;USE IOXTO AS COUNTER/FLAG HERE
	XMOVEI	T1,FALIFI	;OUR VERY OWN INPUT TYPER
	PUSHJ	P,.XTYPI##	;INTERCEPT "COMMAND" INPUT
	XMOVEI	T1,FALIFO	;OUR VERY OWN OUTPUT TYPER
	PUSHJ	P,.XTYPO##	;INTERCEPT "COMMAND" OUTPUT
	XMOVEI	T1,FALIFE	;OUR VERY OWN ERROR PROCESSOR
	PUSHJ	P,.XERRT##	;INTERCEPT FATAL SCAN ERRORS
	JUMPG	P2,FALIF3	;JUST CONTINUE IF NOT FIRST TIME
	MOVE	T1,[POINT 7,[0]];A DUMMY STRING
	MOVEM	T1,.IOXTI(IO)	;SET IN CASE .CLRTI NEEDS SOMETHING
	PUSHJ	P,.CLRTI##	;SETUP LOWLEVEL COMMAND INPUT ROUTINES
	MOVE	T1,[POINT 7,.IDFIL(IO)]  ;BYTE POINTER TO FILE SPEC
	MOVEM	T1,.IOXTI(IO)	;SET FOR FALIFI
	ILDB	T1,T1		;PEEK AT FIRST CHARACTER
	JUMPE	T1,.POPJ##	;IF NULL, NO FILESPEC, REJECT IT

;NOW PARSE THE FILE SPEC

FALIF3:	PUSHJ	P,.FILSP##	;LET SCAN DO ITS THING
	 JRST	FALIFE		;ERROR - DIE
	SKIPN	.IOXTO(IO)	;IT BETTER NOT HAVE COMPLAINED
	JRST	.POPJ1##	;RETURN WITH PARSED FILE IN F.BLK
FALIFE:	ERROR	EPN,<Error in parsing received NAME message in FALIF>,FALIFF

FALIFF:	MOVEI	T1,[ASCIZ\
	Bad name string = "\]
	PUSHJ	P,.TSTRG##	;IDENTIFY ERROR STRING
	SKIPA	P1,[POINT 7,.IDFIL(CI)]  ;POINTER TO OFFENDING STRING
	PUSHJ	P,.TFCHR##	;TYPE POSSIBLY-FUNNY CHARACTER
	ILDB	T1,P1		;NEXT CHARACTER
	JUMPN	T1,.-2		;TYPE CHARACTERS UNTIL END OF STRING
	MOVEI	T1,[ASCIZ\" from node \]
	PUSHJ	P,.TSTRG##	;ANOTHER TEXT STRING
	MOVE	T1,.ION6M(IO)	;OFFENDING NODE
	PJRST	.TSIXN##	;FINK ON HIM
;THE "COMMAND" INPUT ROUTINE

FALIFI:	ILDB	CH,.IOXTI(IO)	;GET NEXT CHARACTER FROM NAME STRING
	JUMPN	CH,.POPJ##	;RETURN USEFUL CHARACTER
	MOVEI	CH,.CHLFD	;END OF STRING, RETURN EOL TO SCAN
	POPJ	P,		;TERMINATE SCAN


;THE "COMMAND" OUTPUT ROUTINE

FALIFO:	OUTCHR	T1		;OH WELL
	AOS	.IOXTO(IO)	;COUNT OCCURENCES
	POPJ	P,		;RETURN TO SCAN
;FIFIL  --  FIND NEXT POSSIBLY-WILDCARDED INPUT FILE
;CALL IS:
;
;	PUSHJ	P,FIFIL
;	  fatal return
;	 exhausted return
;	normal return
;
;The "fatal" return is taken when, for example, the network has died,
;or any other fatal processing error has occurred; The "exhausted"
;return is taken when the input file stream is exhausted (i.e., there
;are no more input files); The "normal" return is taken with the next
;(presumably slave) input file setup ready for I/O.
;
;On file access errors the remote (primary CDB) is informed of the
;error automatically, with whatever name/etc. messages are necessary
;being sent as appropriate.
;
;When the "exhausted" return is taken the caller should send an
;ACCOMP(RESPONSE) to the remote.
;
;Uses T1, T2, T3, T4, P1, P2, P3, P4.

FIFIL1:	MOVE	IO,CO		;SELECT SLAVE CDB
	PUSHJ	P,IOPIN1##	;ADVANCE TO NEXT INPUT FILE
	 JRST	FIFI01		;ERROR/EXCEPTION
CPOPJ2:	AOS	(P)		;SUCCESS HERE IS DOUBLE-
CPOPJ1:	AOS	(P)		; SKIP-
CPOPJ0:	POPJ	P,		;  RETURN
;INPUT FILE ACCESS EXCEPTION RETURN - FIGURE OUT WHAT HAPPENED

FIFI01:	CAIN	M0,$EFIXN	;INPUT FILE STREAM EXHAUSTED?
	JRST	.POPJ1##	;YES, TAKE "EXHAUSTED" RETURN
	CAIN	M0,$EFIXE	;INPUT FILE STREAM EXHAUSTED (REDUNDANTLY)?
	STOPCD	<IOPIN returned "redundantly" exhausted in FIFI00>

;RANDOM FILE ACCESS ERROR, CONVERT TO DAPESE AND PUNT TO REMOTE

	MOVE	IO,CI		;SELECT PRIMARY CDB
	PUSH	P,M0		;SAVE THE ERROR CODE
	PUSHJ	P,FANTY1	;SEND ANY NAME MESSAGES AS NEEDED
	 JRST	M0POPJ		;NET DIED - TAKE FATAL ERROR RETURN
	POP	P,T2		;RESTORE FILE ACCESS ERROR CODE
	MOVEI	T4,DS2EF##	;DAP-STATUS-TO-FILE-STATUS-TABLE ADDRESS
	PUSHJ	P,FFIND1	;SEE IF KNOWN ERROR
	 SKIPA	T1,[$DSACC]	;FILE ACCESS ERROR, $E???? AS SECONDARY STATUS
	SETZ	T2,		;KNOWN ERROR,  NO SECONDARY ERROR CODE
	ADDI	T1,40000	;DAP FILE ACCESS ERROR LEVEL
	SETZB	T3,T4		;NOTHING
	PUSHJ	P,FXSTS1	;SEND REMOTE DAP STATUS
	 POPJ	P,		;NET DIED - FATAL ERROR RETURN


;WE NOW WAIT FOR REMOTE TO MAKE UP ITS MIND AS TO ERROR RECOVERY

FIFI20:	PUSHJ	P,RDMSG1##	;START UP NEW DAP INPUT MESSAGE
	 POPJ	P,		;NET DIED

;DISPATCH ON RECEIVED DAP MESSAGE TYPE

FIFI21:	JSP	T4,.CDISP##	;DISPATCH ON DAP MESSAGE TYPE
		FIFI30,,$DHCNT	;CONTINUE
		FIFI40,,$DHACM	;ACCOMP
		0		;NONE OTHERS
	STOPCD	<Unknown/illegal DAP message in FIFI21>


;HERE ON CONTINUE MESSAGE, MUST BE CONTINUATION OF SOME SORT

FIFI30:	PUSHJ	P,RDDAP1##	;READ IN CONTINUE MESSAGE
	 POPJ	P,		;NET DIED?
	MOVD1	T2,C2F		;GET CONTINUE TYPE
	CAIN	T2,$DVCSK	;"SKIP" TO NEXT FILE?
	JRST	FIFIL1		;YES, TRY FOR ANOTHER FILE
	STOPCD	<Unknown/illegal CONTINUE type in FIFI30>


;HERE ON ACCOMP MESSAGE, MAYBE CONTINUATION OR ABORT

FIFI40:	PUSHJ	P,RDCLR1##	;CLEAR OUT DAP REGION
	 STOPCD			;CAN'T HAPPEN
	PUSHJ	P,RDDAP1##	;READ IN ACCOMP MESSAGE
	 POPJ	P,		;NET DIED?
	MOVD1	T2,A2F		;GET ACCOMP TYPE
	JSP	T4,.CDISP##	;DISPATCH ON ACCOMP TYPE
		FIFIL1,,$DVACL	;CLOSE
		FIFIL1,,$DVAKL	;KILL
		FIFIL1,,$DVASK	;SKIP
		CPOPJ1,,$DVATR	;TERMINATE/ABORT
		0		;NONE OTHERS
	STOPCD	<Unknown/illegal ACCOMP type in FIFI40>
;FOFIL  --  CREATE OUTPUT FILE
;CALL IS:
;
;	PUSHJ	P,FOFIL
;	  fatal return
;	 exhausted return
;	normal return
;
;The "fatal" return is taken when, for example, the network has died,
;or any other fatal processing error has occurred; The "exhausted"
;return is taken when the output file create failed and the
;remote has been informed of the error; The "normal" return is taken
;with the slave output file setup ready for I/O.
;
;On file access errors the remote (primary CDB) is informed of the
;error automatically, with whatever name/etc. messages are necessary
;being sent as appropriate.
;
;When the "exhausted" return is taken the caller should return to
;the "pre-ACCESS" state.
;
;Uses T1, T2, T3, T4, P1, P2, P3, P4.

FOFIL1:	MOVE	IO,CO		;SELECT SLAVE CDB
	SETZ	T2,		;NO INPUT FILE FROM WHICH TO WILDCARD
	PUSHJ	P,IOPOU1##	;CREATE OUTPUT FILE
	 JRST	FOFI01		;ERROR/EXCEPTION RETURN
	JRST	CPOPJ2		;DOUBLE-SKIP RETURN FOR SUCCESS


;OUTPUT FILE CREATE ERROR - FIGURE OUT WHAT HAPPENED

FOFI01:	MOVE	IO,CI		;SELECT PRIMARY (REMOTE ACCESSOR) CDB
	MOVE	T2,M0		;POSITION ERROR CODE
	MOVEI	T4,DS2EF##	;DAP-STATUS-TO-FILE-STATUS-TABLE ADDRESS
	PUSHJ	P,FFIND1	;SEE IF KNOWN ERROR
	 SKIPA	T1,[$DSACC]	;FILE ACCESS ERROR, $E???? AS SECONDARY STATUS
	SETZ	T2,		;KNOWN ERROR, NO SECONDARY STATUS
	ADDI	T1,40000	;DAP FILE ACCESS ERROR LEVEL
	SETZB	T3,T4		;NOTHING ELSE
	PUSHJ	P,FXSTS1	;SEND DAP ERROR STATUS TO REMOTE
	 POPJ	P,		;NET DIED
	JRST	CPOPJ1		;SINGLE-SKIP "EXHAUSTED" RETURN
;FAJA  --  VERIFY AND PROCESS RECEIVED ATTIBUTES/ET AL
;CALL IS:
;
;	PUSHJ	P,FAJA
;	 error return
;	normal return
;
;FAJA reads and verifies the received attributes from the remote, and
;based on those attributes, and the access request, sets up the slave
;CDB for subsequent file access operations.
;
;FAJA expects the caller to have set up IO to the primary CDB, and CO
;to point to the slave CDB.
;
;On error return the remote requested an unsupported/illegal/etc.
;attribute/operation/etc., an error code is in M0.
;
;On normal return the slave CDB is ready for file access operations
;on behalf of the remote ACCESS message request.
;
;Uses T1, T2, T3, T4, P1, P2, P3, P4.

FAJA01:	MOVE	P3,FALOVC	;PROTOTYPE I/O CONTROL
	MOVE	P4,FALOVM	;PROTOTYPE I/O MODE CONTROL

;CHECK OUT THE RECEIVED ACCESS MESSAGE

	SKIPN	.IDAFC(IO)	;WAS AN ACCESS FUNCTION RECEIVED?
	STOPCD	<FAJA: No ACCESS function specified>
	MOVD	T1,AOP		;GET ACCESS OPTIONS REQUESTED
	TFZ	T1,<GNG,ACK>	;CLEAR KNOWN/SUPPORTED STUFF
	TFZ	T1,<OKE>	;*** KEEP THE VAX HAPPY
	FJUMPE	T1,AOP,FAJA03	;OK IF NOTHING ELSE LEFT
	STOPCD	<FAJA: Unknown or unsupported AOP flags>
FAJA03:	LDB	T1,[POINT 7,.IDFIL(IO),6]  ;FIRST BYTE OF FILE SPEC
	JUMPN	T1,FAJA04	;ENSURE RECEIVED A FILE SPEC
	STOPCD	<FAJA: No ACCESS filespec>

FAJA04:	MOVD	T1,FAC		;FILE ACCESS REQUESTED
	TFZ	T1,<PUT,GET,DEL,UPD,TRN>  ;CLEAR OK STUFF
	FJUMPE	T1,FAC,FAJA06	;OK IF NOTHING LEFTOVER
	STOPCD	<FAJA: Unknown or unsupported FAC flags>

FAJA06:	MOVD	T1,SHR		;SHARED FILE ACCESS
	TFZ	T1,<GET>	;CLEAR OK STUFF
	FJUMPE	T1,SHR,FAJA07	;OK IF NOTHING LEFT OVER
	STOPCD	<FAJA: Unknown or unsupported SHR flags>

FAJA07:	MOVD	T1,ADS		;ACCESS DISPLAY (RETURN ATTRIBUTES)
	TFZ	T1,<DMA,DAA,DDT,DFP,DNM,DN3>  ;CLEAR OK STUFF
	FJUMPE	T1,ADS,FAJA08	;OK IF NOTHING LEFT OVER
	STOPCD	<FAJA: Unknown or unsupported ADS flags>

FAJA08:	LDB	T1,[POINT 7,.IDPSW(IO),6]  ;FIRST CHAR OF PASSWORD
	JUMPE	T1,FAJA10	;OK IF NO PASSWORD
	STOPCD	<FAJA: ACCESS password specified>

;CHECK OUT MAIN ATTRIBUTES

FAJA10:	MOVD	P1,M02		;MAIN ATTRIBUTES MENU
	SETZ	T4,		;INITIALLY NO DATA TYPE SELECTED
	MOVD1	T2,AFC		;GET ACCESS TYPE (READ, WRITE, ETC)
	CAIN	T2,$DVAWR	;FILE CREATE OPERATION?
	JRST	FAJA15		;YES

;HERE FOR ALL READ-CLASS FILE ACCESS OPERATIONS

FAJA11:	TMNN	P1,DTY		;WAS A DATA-TYPE FIELD SUPPLIED?
	JRST	FAJA12		;NO
	PUSHJ	P,FAJAD1	;YES, PROCESS DATA-TYPE
	 POPJ	P,		;OOPS, ILLEGAL BITS SET
	JUMPN	T4,FAJA13	;GO WITH USER-SUPPLIED DATA-MODE
FAJA12:	TXO	P4,IM.SMD	;NO DATA-MODE, SELECT DEFAULT FROM FILE
FAJA13:	TMNN	P1,BSZ		;GOT A BYTE-SIZE FIELD?
	TDZA	T3,T3		;NO, GET IT FROM INPUT FILE THEN
	MOVD1	T3,BSZ		;YES, SELECT USER-SUPPLIED BYTE SIZE
	JRST	FAJA19		;DONE WITH READ-SPECIFIC

;HERE FOR WRITE-CLASS FILE ACCESS

FAJA15:	TMNN	P1,DTY		;DATA-TYPE GIVEN?
	JRST	FAJA16		;NO
	PUSHJ	P,FAJAD1	;YES, PROCESS USER-SPECIFIED DATA-TYPE
	 POPJ	P,		;ILLEGAL FLAGS
	JUMPN	T4,FAJA17	;GO WITH USER-SPECIFIED DATA-MODE
FAJA16:	MOVD1	T1,FST		;REMOTE FILE SYSTEM TYPE
	CAIN	T1,$DVFF1	;FCS-11?
	JRST	[MOVD	T1,DTY		;GET DATA TYPE FIELD
		TFO	T1,ASC		;ASSERT ASCII DATA TYPE
		MOVDM	T1,DTY		;SET BACK IN MEMORY
		MOVEI	T4,.ICASC	;FLAG ASCII FILE MODE
		JRST	FAJA17]		;CONTINUE ONWARDS
	STOPCD	<FAJA: no data mode specified for file create>
FAJA17:	TMNN	P1,BSZ		;GOT A BYTE SIZE?
	SKIPA	T3,[^D08]	;NO, THEN DAP SAYS 8-BIT BYTES
	MOVD1	T3,BSZ		;YES, GO WITH USER-SPECIFIED BYTE SIZE
FAJA19:	DPB	T4,[POINTR P3,IC.MOD]  ;SET FILE MODE
	CAIE	T3,^D00		;IF NO BYTE SIZE
	CAIN	T3,^D08		;OR 8-BIT BYTES
	CAIE	T4,.ICASC	;AND ASCII FILE MODE
	CAIA			; (NO TO ABOVE)
	MOVEI	T3,^D07		;THEN REALLY WANT 7-BIT BYTES (GRRR!!)
	HRRZM	T3,.IOBSZ(CO)	;SELECT LOGICAL DATA BYTE SIZE
	HRRZM	T3,.IOFSZ(CO)	;SELECT PHYSICAL FRAME BYTE SIZE
	HRRZM	T3,.IOUBS(CO)	;SELECT OVERRIDING BYTE SIZE

;CHECK "FILE ORGANIZATION"

FAJA20:	TMNN	P1,ORG		;FILE ORGANIZATION SET?
	JRST	FAJA22		;NO
	MOVD	T1,ORG		;YES
	CAIE	T1,$DVOSQ	;SEQUENTIAL FILE ORGANIZATION?
	STOPCD	<FAJA: Unknown or unsupported ORG type>

;CHECK RECORD FORMAT

FAJA22:	TMNN	P1,RFM		;RECORD FORMAT SET?
	JRST	FAJA24		;NO
	MOVD	T1,RFM		;YES
	CAIE	T1,$DVFNR	;NO-FORMAT RECORD FORMAT?
	CAIN	T1,$DVFST	;ASCII-STREAM RECORD FORMAT?
	JRST	FAJA24		;YES
	CAIE	T1,$DVFVR	;VARIABLE-LENGTH RECORDS?
	CAIN	T1,$DVFVF	;VARIABLE-WITH-FIXED-HEADER RECORDS?
	JRST	FAJA24		;YES
	CAIN	T1,$DVFFX	;FIXED-LENGTH RECORDS?
	JRST	FAJA24		;YES
	STOPCD	<FAJA: Unknown or unsupported RFM type>

;CHECK RECORD ATTRIBUTES

FAJA24:	TMNN	P1,RAT		;RECORD ATTRIBUTES SET?
	JRST	FAJA26		;NO
	MOVD	T1,RAT		;GET REQUESTED RECORD ATTRIBUTES
	TFZE	T1,MCY		;MACY11-FORMATTING?
	TXO	P3,IC.MCY	;YES, SET IN I/O CONTROL
	TFZE	T1,LSA		;LINE-SEQUENCED ASCII?
	TXO	P3,IC.LSN	;YES, SET IN I/O CONTROL
	TFZ	T1,<ILC,NSB,EFC>;CLEAR OUT IGNORABLE STUFF
	MOVD1	T3,AFC		;GET ACCESS FUNCTION
	CAIN	T3,$DVAWR	;IS THIS A FILE "CREATE"
	TFZ	T1,<CCC,FCC,PRN>;YES, IGNORE CARRIAGE-CONTROL FLAGS
				; (I.E., FAL WILL BE "READING" FROM REMOTE
				;  WHICH ISR SUPPORTS ALL THESE VARIATIONS
				;  WHEREAS ALL OTHER FILE ACCESSES APPEAR
				;  AS "WRITING" TO REMOTE, WHICH OSR DOESN'T
				;  SUPPORT THAT STUFF, SO FLAG IT ERROR)
	FJUMPE	T1,RAT,FAJA26	;ANYTHING LEFT OVER?
	STOPCD	<FAJA: Unknown or unsupported RAT bits>

;CHECK FILE ACCESS OPTIONS

FAJA26:	TMNN	P1,FOP		;FILE ACCESS OPTIONS SET?
	JRST	FAJA40		;NO
	MOVD	T1,FOP		;GET REQUESTED OPTIONS
	TFZE	T1,SUP		;SUPERSEDE FILE?
	PUSHJ	P,[MOVX T3,FX.SUP	;YES, GET /ERSUPERSEDE
		MOVE	T4,.IOFSB(CO)	;ADDRESS OF OUTPUT FILE SPEC BLOCK
		ANDCAM	T3,.FXMOD(T4)	;CLEAR /ERSUPERSEDE
		IORM	T3,.FXMOM(T4)	;AND INDICATE /OKSUPERSEDE
		POPJ	P,]		;CONTINUE
	TFZE	T1,CTG		;CONTIGUOUS ALLOCATION?
	TXO	P4,IM.CTG	;YES
	TFZE	T1,CBT		;CONTIGUOUS BEST TRY?
	TXO	P4,IM.CBT	;YES
;***	TFZE	T1,SCF		;SUBMIT FILE ON CLOSE?
;***	TXO	P4,IM.CSU	;YES
;***	TFZE	T1,SPC		;PRINT FILE ON CLOSE?
;***	TXO	P4,IM.CPR	;YES
;***	TFZE	T1,DLT		;DELETE FILE ON CLOSE?
;***	TXO	P4,IM.CDL	;YES
	TFZ	T1,<SCF,SPC,DLT>;*** HANDLED BY FACL01 INSTEAD
	TFZ	T1,<CIF,SQO,MXV,TEF>  ;IGNORABLE FLAGS
	FJUMPE	T1,FOP,FAJA40	;OK IF NOTHING LEFT OVER
	STOPCD	<FAJA: Unknown or unsupported FOP bits>

;FINISH REST OF MAIN ATTRIBUTES (LENGTH/ALLOCATION/ETC.)

FAJA40:	MOVEM	P3,.IOIOC(CO)	;SET I/O CONTROL
	MOVEM	P4,.IOIOM(CO)	;SET I/O MODE CONTROL
	MOVD1	T3,BLS		;GET RETURNED DAP DATA BLOCK SIZE (IF ANY)
	MOVEM	T3,.IOBLS(CO)	;AND SET FILE PARAMETER
	MOVD1	T3,MRS		;GET RETURNED DAP RECORDSIZE (IF ANY)
	MOVEM	T3,.IORSZ(CO)	;AND SET FILE PARAMETER
	MOVD1	T1,ALQ		;GET RETURNED DAP ALLOCATION ("BLOCKS" - IF ANY)
	IMUL	T1,.IOBLS(CO)	;CONVERT TO DATA BYTES
	MOVEM	T1,.IOALB(CO)	;SET ALLOCATION IN BYTES FILE PARAMETER
	SKIPN	.IOBSZ(CO)	;GOT A BYTE SIZE?
	JRST	FAJA43		;NO (???)
	MOVEI	T2,^D36		;-10 WORD SIZE
	IDIV	T2,.IOBSZ(CO)	;T2:=BYTES PER -10 WORD
	IDIV	T1,T2		;T1:=FILE ALLOCATION IN -10 WORDS
	CAIE	T2,0		;EXACT FIT?
	ADDI	T1,1		;NO, NEED ONE MORE [PARTIAL] WORD
FAJA43:	MOVEM	T1,.IOALW(CO)	;SET ALLOCATION IN WORDS FILE PARAMETER


;HANDLE DATE/TIME ATTRIBUTES

FAJA50:	MOVD	P1,M13		;DATE/TIME ATTRIBUTES MENU
	TMNN	P1,CDT		;GOT A CREATION DATE/TIME?
	TDZA	T1,T1		;NO, THEN BLANK THE FIELD
	MOVD1	T1,CDT		;GET RETURNED LOGICAL CREATION DATE/TIME
	MOVEM	T1,.IOCDT(CO)	;SET FILE PARAMETER
	TMNN	P1,UDT		;GOT UPDATE DATE/TIME?
	TDZA	T1,T1		;NO, THEN BLANK THE FIELD
	MOVD1	T1,UDT		;GET RETURNED UPDATE DATE/TIME
	MOVEM	T1,.IOUDT(CO)	;SET UPDATE TIME FILE PARAMETER
	TMNN	P1,EDT		;GOT EXPIRATION DATE/TIME?
	TDZA	T1,T1		;NO, THEN BLANK THE FIELD
	MOVD1	T1,EDT		;GET RETURNED EXPIRATION DATE/TIME
	MOVEM	T1,.IOEDT(CO)	;SET EXPIRATION DATE/TIME FILE PARAMETER
	TMNN	P1,BDT		;GOT BACKUP DATE/TIME?
	TDZA	T1,T1		;NO, THEN BLANK THE FIELD
	MOVD1	T1,BDT		;GET BACKUP DATE/TIME
	MOVEM	T1,.IOBDT(CO)	;SET BACKUP DATE/TIME FILE PARAMETER
	TMNN	P1,PDT		;GOT PHYSICAL DATE/TIME?
	TDZA	T1,T1		;NO, THEN BLANK THE FIELD
	MOVD1	T1,PDT		;GET RETURNED PHYSICAL CREATION DATE/TIME
	MOVEM	T1,.IOPDT(CO)	;SET PHYSICAL CREATION DATE/TIME FILE PARM
	TMNN	P1,ADT		;GOT ACCESS DATE/TIME?
	TDZA	T1,T1		;NO, THEN BLANK THE FIELD
	MOVD1	T1,ADT		;GET ACCESS DATE/TIME
	MOVEM	T1,.IOADT(CO)	;SET ACCESS DATE/TIME FILE PARAMETER


;HANDLE PROTECTION ATTRIBUTES
;
;FAJA ASSUMES THAT THE PROTECTION FIELDS ARE ALL ONE WORD LONG. AS THIS
;IS NOT REALLY GUARANTEED, CAUSE ASSEMBLY ERROR IF IT EVER CHANGES

	IFN	$DLPSY-1,<PRINTX ?PSY field not one word long in FAJA60>
	IFN	$DLPOW-1,<PRINTX ?POW field not one word long in FAJA60>
	IFN	$DLPGR-1,<PRINTX ?PGR field not one word long in FAJA60>
	IFN	$DLPWL-1,<PRINTX ?PWL field not one word long in FAJA60>

FAJA60:	MOVD	P1,M14		;PROTECTION ATTRIBUTES MENU
	SETZB	T2,T3		;START OFF BLANK
	TMNN	P1,PWL		;GOT A "WORLD" PROTECTION?
	JRST	FAJA62		;NO
	MOVD	T1,PWL		;GET RETURNED "WORLD" PROTECTION
	PUSHJ	P,DPFPXL##	;TRANSLATE INTO TOPS-10 LEVEL-D DISK PROTECTION
FAJA62:	LSHC	T2,-3		;SAVE VALUE SO FAR
	SETZ	T2,		;MAKE ROOM FOR NEW
	TMNN	P1,PGR		;GOT A "GROUP" PROTECTION?
	JRST	FAJA64		;NO
	MOVD	T1,PGR		;GET RETURNED "GROUP" PROTECTION
	PUSHJ	P,DPFPXL##	;TRANSLATE INTO TOPS-10 LEVEL-D DISK PROTECTION
FAJA64:	LSHC	T2,-3		;ACCUMULATE THIS "GROUP" FIELD TOO
	SETZ	T2,		;MAKE ROOM FOR OWNER
	TMNN	P1,POW		;GOT "OWNER" PROTECTION?
	JRST	FAJA66		;NO
	MOVD	T1,POW		;GET RETURNED "OWNER" PROTECTION
	PUSHJ	P,DPFPXO##	;TRANSLATE INTO TOPS-10 LEVEL-D DISK PROTECTION
FAJA66:	LSHC	T2,6		;T2:=NINE-BIT TOPS-10 LEVEL-D DISK PROTECTION
	HRROM	T2,.IOPRT(CO)	;SET FOR FILE SERVICE


;FILE ATTRIBUTES/ETC. ALL SET, READY FOR FILE OPERATIONS

FAJA90:	JRST	.POPJ1##	;SUCCESSFUL RETURN
;FAJAD - HELPER TO FAJA TO PROCESS DATA-TYPE FIELD

FAJAD1:	MOVD	T1,DTY		;GET DATA TYPE FIELD

;FIRST CHECK EXTRANEOUS KRUFT

	TFZE	T1,ZOD		;DID REMOTE REQUEST ZERO-ON-DELETE?
	TXO	P4,IM.ZOD	;YES, FLAG IT

;NOW LOOK FOR A REAL DATA-TYPE

	MOVEI	T4,.ICASC	;ASCII FILE MODE
	TFZE	T1,ASC		;ASCII DATA?
	JRST	FAJAD7		;YES
	MOVEI	T4,.ICBIN	;BINARY FILE MODE
	TFZE	T1,IMG		;IMAGE DATA?
	JRST	FAJAD7		;YES
	SKIPN	T4,T1		;ALL BITS USED UP?
	JRST	.POPJ1##	;YES, NO FILE DATA MODE THEN
	STOPCD	<FAJAD: Unknown or unsupported DTY bits>

FAJAD7:	TXO	P4,IM.CMD	;SET FORCED IC.MOD FLAG
	JUMPE	T1,.POPJ1##	;HAPPY IF NOTHING LEFT OVER
	STOPCD	<FAJAD: Conflicting, unknown, or unsupported DTY bits>
;FANTY  --  HANDLE ANY NAME MESSAGES DUE TO WILDCARDING
;CALL IS:
;
;	PUSHJ	P,FANTY

FANTY1:	MOVE	T1,.IODPV(CI)	;ACCESSOR'S PROTOCOL LEVEL
	CAIGE	T1,007000	;7.0 OR LATER?
	JRST	FANTY3		;NO, DO IT THE GUESS-HOW WAY
	MOVD	T1,ADS		;YES, REMOTE EXPLICITLY CONTROLS NAME MSGS
	TFNN	T1,DN3		;DOES REMOTE WANT 3-PART NAME MESSAGES?
	JRST	.POPJ1##	;NO, NO NAME MESSAGES HERE THEN
	JRST	FANTY5		;YES, FORCE 3-PART NAME MESSAGES

FANTY3:	SKIPN	.WLDFL##	;DOES WILD THINK THERE ARE ANY WILDCARDS?
	JRST	.POPJ1##	;NO, NOTHING TO DO HERE THEN
FANTY5:	PUSHJ	P,FGNTY1	;SEE WHAT NAME MESSAGES NEED TO BE SENT
	 STOPCD	<FGNTY failed in FANTY>
	PUSHJ	P,FXNA01	;SEND NAME MESSAGES (P1 SET FROM ABOVE)
	 STOPCD	<FXNA failed in FANTY>
	JRST	.POPJ1##	;SUCCESSFUL RETURN
REPEAT 0,<

;FCICO  --  SET SLAVE CDB FROM PRIMARY CDB
;CALL IS:
;
;	MOVX	CI,<SRC>
;	MOVX	CO,<DST>
;	PUSHJ	P,FCICO
;	 error return
;	normal return
;
;Where <SRC> is the source CDB address; and <DST> is the destination
;CDB address.
;
;FCICO is used to copy the various file-specific information from the
;primary (remote-driven to FAL) I/O CDB to the slave (FAL-driven on
;behalf of the remote) I/O CDB, usually in preparation for file-level
;operations via the slave CDB.
;
;The error return is not exercised.
;
;On normal return the file information from the <SRC> CDB has been
;copied into the <DST> CDB.
;
;Uses T1, T2, T3, T4.

FCICO:

;FIRST THE GENERIC FILE INFORMATION

FCICO1:	MOVSI	T3,.IOBZC(CI)	;SOURCE ADDRESS
	HRRI	T3,.IOBZC(CO)	;DESTINATION ADDRESS
	BLT	T3,.IOEZC-1(CO)	;COPY OVER GENERIC FILE INFO
	DMOVE	T3,.IOIOC(CI)	;GET PRIMARY I/O AND ERROR CONTROL
	DMOVEM	T3,.IOIOC(CO)	;SET IN THE SLAVE
	MOVE	T3,.IOIOM(CI)	;GET PRIMARY I/O MODE CONTROL
	MOVEM	T3,.IOIOM(CO)	;SET IN THE SLAVE
	MOVE	T3,.IOUBS(CI)	;GET OVER-RIDING BYTE SIZE
	MOVEM	T3,.IOUBS(CO)	;SET IN THE SLAVE

;NOW GET OPERATING-SYSTEM-SPECIFIC JUICIES

FCICO2:	MOVSI	T3,.IOB10(CI)	;SOURCE ADDRESS
	HRRI	T3,.IOB10(CO)	;DESTINATION ADDRESS
	BLT	T3,.IOE10-1(CO)	;COPY OVER TOPS-10 FILE INFO

REPEAT	0,<			;SIGH
FCICO3:	MOVSI	T3,.IOB20(CI)	;SOURCE ADDRESS
	HRRI	T3,.IOB20(CO)	;DESTINATION ADDRESS
	BLT	T3,.IOE20-1(CO)	;COPY OVER TOPS-20 FILE INFO
> ;END REPEAT 0 ;SIGH

	JRST	.POPJ1##	;SUCCESSFUL RETURN
> ;END REPEAT 0
REPEAT	0,<	;NOT NEEDED

;FCOCI  --  SET PRIMARY CDB FROM SLAVE CDB
;CALL IS:
;
;	MOVX	CI,<DST>
;	MOVX	CO,<SRC>
;	PUSHJ	P,FCOCI
;	 error return
;	normal return
;
;Where <SRC> is the source CDB address; and <DST> is the destination
;CDB address.
;
;FCOCI is used to copy the various file-specific information from the
;slave (FAL-driven on behalf of the remote) I/O CDB to the primary
;(remote-driven to FAL) I/O CDB, usually in preparation for returning
;attributes/et al to the remote.
;
;The error return is not exercised.
;
;On normal return the file information from the <SRC> CDB has been
;copied into the <DST> CDB.
;
;Uses T1, T2, T3, T4.

FCOCI:

;FIRST THE GENERIC FILE INFORMATION

FCOCI1:	MOVSI	T3,.IOBZC(CO)	;SOURCE ADDRESS
	HRRI	T3,.IOBZC(CI)	;DESTINATION ADDRESS
	BLT	T3,.IOEZC-1(CI)	;COPY OVER GENERIC FILE INFO
	DMOVE	T3,.IOIOC(CO)	;GET SLAVE I/O AND ERROR CONTROL
	DMOVEM	T3,.IOIOC(CI)	;COPY INTO THE PRIMARY CDB
	MOVE	T3,.IOIOM(CO)	;GET SLAVE I/O MODE CONTROL
	MOVEM	T3,.IOIOM(CI)	;COPY INTO THE PRIMARY CDB

;NOW GET OPERATING-SYSTEM-SPECIFIC JUICIES

FCOCI2:	MOVSI	T3,.IOB10(CO)	;SOURCE ADDRESS
	HRRI	T3,.IOB10(CI)	;DESTINATION ADDRESS
	BLT	T3,.IOE10-1(CI)	;COPY OVER TOPS-10 FILE INFO

REPEAT	0,<			;SIGH
FCOCI3:	MOVSI	T3,.IOB20(CO)	;SOURCE ADDRESS
	HRRI	T3,.IOB20(CI)	;DESTINATION ADDRESS
	BLT	T3,.IOE20-1(CI)	;COPY OVER TOPS-20 FILE INFO
> ;END REPEAT 0 ;SIGH

	JRST	.POPJ1##	;SUCCESSFUL RETURN

> ;END REPEAT 0
;FGNTY  --  DETERMINE NAME MESSAGES TO BE SENT TO REMOTE
;CALL IS:
;
;	PUSHJ	P,FGNTY
;	 error return
;	normal return
;
;FGNTY returns a NTY (see DAP field definitions) mask of the name
;messages (volume/device, directory, file name/type/generation)
;which should be sent to the remote based on a wildcard file access
;request.
;
;CI and IO should both point to the primary CDB, and CO should point
;to the slave CDB.
;
;The error return is not exercised.
;
;On normal return P1/P2 has the resultant NTY mask of name messages
;which should be sent.
;
;Uses T1, T2, T3, T4, P1, P2.

FGNTY1:	MOVDII	P1,NTY,NFN	;ALWAYS RETURN FILENAME NAME MESSAGE
	MOVE	T1,.I1DEV(CO)	;GET CURRENT INPUT DEVICE
	CAME	T1,.I1DEV(CI)	;SAME AS LAST TIME HERE?
	TFO	P1,NVN		;NO, NEED A VOLUME NAME TOO
	MOVEM	T1,.I1DEV(CI)	;SET NEW LAST DEVICE
	MOVE	T2,[-<.PTMAX-.PTPPN-1>,,.PTPPN]  ;PROTOTYPE AOBJN'ER
	MOVE	T3,T2		;NEED TWO OF 'EM
	ADDI	T2,.I1PT2(CO)	;THIS TIMES' PATH
	ADDI	T3,.I1PT2(CI)	;LAST TIMES' PATH
FGNTY3:	MOVE	T1,0(T2)	;CURRENT DIRECTORY
	CAME	T1,0(T3)	;SAME AS LAST TIME?
	TFO	P1,NDN		;NO, NEED DIRECTORY NAME TOO
	MOVEM	T1,0(T3)	;SET NEW LAST DIRECTORY
	JUMPE	T1,.POPJ1##	;EXIT AT END OF DIRECTORY PATH
	AOBJP	T2,.+1		;ADVANCE
	AOBJN	T3,FGNTY3	; TO NEXT DIRECTORY LEVEL
	JRST	.POPJ1##	;SUCCESSFUL RETURN
;FFAD  --  CONVERT FILE ATTRIBUTES INTO DAPESE
;CALL IS:
;
;	PUSHJ	P,FFAD
;	 error return
;	normal return
;
;FFAD sets the DAP attributes/etc. fields in the primary CDB from
;the generic and os-specific file information (excluding names) contained
;in the slave CDB, usually in preparation to shipping the file attributes
;to the remote in response to an ACCESS request.
;
;FFAD expects the caller to have setup both IO and CI to point to the
;primary CDB, and CO to point to the slave CDB. In addition, P1/P2 are
;expected to hold the original remote-specified main attributes menu.
;
;On error return some incompatibility exists (an error code is in M0).
;
;On normal return the DAP attributes are set up and ready to be sent to
;the remote (e.g., via FXAT).
;
;Uses T1, T2, T3, T4, P1, P2, P3, P4.

FFAD01:	MOVE	P3,.IOIOC(CO)	;I/O CONTROL
	MOVE	P4,.IOIOM(CO)	;I/O MODE

;MAIN ATTRIBUTES FIELDS

FFAD10:	MOVD	P1,M02		;PRELOAD WITH REMOTE'S MAIN ATTRIBUTES MENU
	LDB	T1,[POINTR P3,IC.MOD]  ;PICKUP INTERNAL DATA MODE
	SETZB	T3,T4		;INITIALIZE FLAGS
	CAIE	T1,.ICDEF	;NONE (?) - DEFAULT IS ASCII
	CAIN	T1,.ICASC	;7-BIT ASCII?
	TFO	T3,ASC		;YES
	CAIN	T1,.ICAS8	;8-BIT ASCII?
	TFO	T3,ASC		;YES
	CAIN	T1,.ICEBC	;EBCDIC?
	TFO	T3,EBC		;YES
	CAIE	T1,.ICPIM	;PACKED IMAGE?
	CAIN	T1,.ICIMG	;OR NORMAL IMAGE?
	TFO	T3,IMG		;YES
	CAIE	T1,.ICBYT	;BYTE MODE?
	CAIN	T1,.ICBIN	;OR BINARY MODE?
	TFO	T3,IMG		;YES
	TFNN	T3,<ASC,EBC,IMG>;HAS A MODE BEEN SELECTED?
	STOPCD	<No (or unknown) DAP file data mode in FFAD10>
	TXNE	P4,IM.ZOD	;ZERO ON DELETE?
	TFO	T3,ZOD		;YES
	MOVDM	T3,DTY		;SET MAIN ATTR DATA TYPE FIELD

	MOVDII	T3,ORG,$DVOSQ	;ALL FILE ACCESSES ARE SEQUENTIAL
	MOVDM	T3,ORG		;SET MAIN ATTR FILE ORGANIZATION FIELD

	TMO	P1,<DTY,ORG>	;DATATYPE AND ORGANIZATION ARE ALWAYS SENT
	MOVD1	T1,OST		;REMOTE (NFT) OPERATING SYSTEM TYPE
	MOVD	T3,DTY		;RETRIEVE DATA TYPE
	TFNN	T3,ASC		;DEALING IN ASCII CHARACTER DATA?
	JRST	FFAD13		;NO, BINARY

;SELECT RECORD FORMAT AND ATTRIBUTES FOR ASCII DATA

	TMNN	P1,RFM		;DID REMOTE SUPPLY "FORMAT"
	SKIPA	T2,DARFTB##(T1)	;NO, ASCII, GET APPROPRIATE RECORD FORMAT
	MOVD1	T2,RFM		;YES, SELECT REMOTE'S ASCII FORMATTING
	SETZ	T4,		;OTHER HALF OF POTENTIAL WORDS
	TMNN	P1,RAT		;DID REMOTE SUPPLY RECORD ATTRIBUTES?
	SKIPA	T3,DARATB##(T1)	;NO, ASCII, GET APPROPRIATE RECORD ATTRIBUTES
	MOVD	T3,RAT		;YES, SELECT REMOTE'S ASCII RECORD ATTRIBUTES
	TXNE	P3,IC.LSN	;WANT LINE-SEQUENCED ASCII?
	TFO	T3,LSA		;YES, THE POOR DUMB FOOL
	TXNE	P3,IC.CCC	;COBOL CARRIAGE CONTROL?
	TFO	T3,CCC		;YES
	TXNE	P3,IC.FCC	;FORTRAN CARRIAGE CONTROL?
	TFO	T3,FCC		;YES
	JRST	FFAD19		;CONTINUE WITH REST OF MAIN ATTR

;SELECT RECORD FORMAT AND ATTRIBUTES FOR IMAGE (BINARY) DATA

FFAD13:	TMNN	P1,RFM		;DID REMOTE SPECIFY RECORD FORMAT?
	SKIPA	T2,DBRFTB##(T1)	;NO, BINARY, GET APPROPRIATE RECORD FORMAT
	MOVD1	T2,RFM		;YES, USE REMOTE'S FORMAT
	SETZ	T4,		;OTHER HALF OF POTENTIAL WORDS
	TMNN	P1,RAT		;DID REMOTE SPECIFY RECORD ATTRIBUTES?
	SKIPA	T3,DBRATB##(T1)	;NO, BINARY, GET APPROPRIATE RECORD ATTRIBUTES
	MOVD	T3,RAT		;YES, USE REMOTE'S RECORD ATTRIBUTES
FFAD19:	TXNE	P3,IC.MCY	;SLAVE FILE MACY11-PACKED?
	TFO	T3,MCY		;YES
	MOVD1M	T2,RFM		;SET MAIN ATTRIBUTES RECORD FORMAT FIELD
	MOVDM	T3,RAT		;SET MAIN ATTRIBUTES RECORD ATTRIBUTES FIELD
	TMO	P1,<RFM,RAT>	;AND FLAG THEM IN THE MENU TOO

FFAD20:	TMZ	P1,<BLS,MRS,ALQ>;CLEAR IN CASE DON'T HAVE ANYTHING TO SAY
	SKIPN	T3,.IOBSZ(CO)	;GET LOGICAL DATA BYTE SIZE
	STOPCD	<No byte size in FFAD20>
	MOVD	T1,DTY		;***RETRIEVE COPY OF DATA TYPE
	TFNE	T1,ASC		;*** ASCII DATA?
	MOVEI	T3,^D08		;*** YES, TELL NET WE ARE SENDING 8-BIT DATA
	MOVD1M	T3,BSZ		;SET MAIN ATTR BYTE SIZE FIELD
	TMO	P1,BSZ		;AND FLAG IT IN THE MENU TOO

FFAD21:	SKIPN	T3,.IORSZ(CO)	;DO WE HAVE A RECORD SIZE VALUE?
	JRST	FFAD22		;NO
	MOVD1M	T3,MRS		;YES, SET MAIN ATTR RECORD SIZE FIELD
	TMO	P1,MRS		;AND FLAG IT IN THE MENU

FFAD22:	SKIPN	T3,.IOBLS(CO)	;DO WE HAVE A BLOCKSIZE VALUE?
	JRST	FFAD27		;NO
	MOVD1M	T3,BLS		;YES, SET MAIN ATTR BLOCKSIZE FIELD
	TMO	P1,BLS		;AND FLAG IT IN THE MENU

FFAD23:	SKIPN	T1,.IOALB(CO)	;GOT A TOTAL ALLOCATION QUANTITY?
	JRST	FFAD24		;NO
	IDIV	T1,.IOBLS(CO)	;CONVERT TO "BLOCK" ALLOCATION
	CAIE	T2,0		;EXACT FIT?
	ADDI	T1,1		;NO, ALLOW FOR PARTIAL LAST BLOCK
	MOVD1M	T1,ALQ		;SET MAIN ATTR ALLOCATION QUANTITY FIELD
	MOVD1M	T1,HBK		;ALSO CALL IT HIGHEST VIRTUAL BLOCK ALLOCATED
	TMO	P1,<ALQ,HBK>	;AND FLAG THEM IN THE MENU TOO

FFAD24:	SKIPN	T1,.IOLNB(CO)	;GOT A DATA LENGTH QUANTITY?
	JRST	FFAD27		;NO
	IDIV	T1,.IOBLS(CO)	;T1:=LENGTH OF FILE IN BLOCKS
	CAIE	T2,0		;EXACT FIT?
	ADDI	T1,1		;ALLOW FOR TRAILING PARTIAL BLOCK
	MOVD1M	T1,EBK		;SET END-OF-FILE VIRTUAL BLOCK NUMBER
	ADDI	T2,1		;T2:=FIRST FREE BYTE (MAY BE IN NEXT BLOCK)
	MOVD1M	T2,FFB		;SET FIRST FREE BYTE IN END OF FILE BLOCK
	TMO	P1,<EBK,FFB>	;NOTE EOF AND FFB FIELDS PRESENT

FFAD27:	MOVD1	T3,RFM		;RETRIEVE RECORD FORMAT
	CAIE	T3,$DVFVF	;VARIABLE WITH FIXED CONTROL?
	JRST	FFAD28		;NO
	STOPCD	<Record format not supported at FFAD24>

FFAD28:	MOVDII	T3,FOP,<TEF>	;ASSUME TRUNCATE TO EOF ON CLOSE
	TXNE	P4,IM.CTG	;CONTIGUOUS ALLOCATION WANTED?
	TFO	T3,CTG		;FLAG CONTIGUOUS ALLOCATION REQUIRED
	TFNE	T3,CTG		;CONTIGUOUS ALLOCATION REQUIRED?
	TFZ	T3,CBT		;YES, THEN NO "BEST TRY OK"
	MOVE	T1,.IOFSB(CO)	;ADDRESS OF FILE SPEC BLOCK
	MOVE	T1,.FXMOD(T1)	;FILE MODS
	TXNN	T1,FX.SUP	;/ERSUPERSEDE?
	TFO	T3,SUP		;NO, OK TO SUPERSEDE
	MOVDM	T3,FOP		;SET MAIN ATTR FILE ACCESS OPTIONS FIELD
	TMO	P1,FOP		;AND FLAG IT IN THE MENU TOO

FFAD30:	MOVE	T1,.IODCH(CO)	;GET THE SLAVE FILE/DEVICE CHARACTERISTICS
	PUSHJ	P,FFADC1	;CONVERT TO DAP "DEV" CHARACTERISTICS
	 JFCL			;HO HUM
	MOVDM	T2,DEV		;SET DAP FILE/DEVICE CHARACTERISTICS
	TMO	P1,DEV		;SET MAIN ATTR DEV CHAR FIELD

	MOVDM	P1,M02		;SET MAIN ATTRIBUTES MENU FIELD


;ALLOCATION ATTIBUTES

FFAD50:	SETZB	P1,P2		;INIT ALLOCATION ATTR MENU
	MOVD	T3,ALQ		;MAIN ATTR ALLOCATION QUANTITY
	MOVDM	T3,AAL		;COPY INTO ALLOC ATTR ALLOCATION QUANTITY
	MOVD	T3,M02		;MAIN ATTR MENU
	TMNN	T3,ALQ		;AN ALLOCATION QUANTITY?
	TMO	P1,AAL		;YES
	SETZB	T3,T4		;INIT FLAGS
	MOVD	T1,FOP		;MAIN ATTR FILE ACCESS OPTIONS
	TFNE	T1,CBT		;CONTIGUOUS BEST TRY?
	TFO	T3,ACB		;YES, MARK IN ALLOCATION OPTIONS
	TFNE	T1,CTG		;CONTIGUOUS ALLOCATION REQUIRED?
	TFO	T3,ACT		;YES, MARK IN ALLOCATION OPTIONS
	MOVDM	T3,ALP		;SET ALLOC ATTR ALLOCATION OPTIONS FIELD
	TFNE	T3,<ACB,ACT>	;ANYTHING IN OPTIONS?
	TMO	P1,ALP		;YES, MARK IT IN THE MENU
	SKIPN	T3,.I1LKP+.RBPOS(CO)  ;ALLOCATION ADDRESS SUPPLIED?
	JRST	FFAD56		;NO
	MOVD1M	T3,LOC		;SET ALLOC ATTR ALLOCATION ADDRESS FIELD
	MOVDII	T3,ALN,ALB	;THE ALIGN-TO-SPECIFIED-BLOCK BIT
	MOVDM	T3,ALN		;SET ALLOC ATTR ALIGNMENT CONTROL FIELD
	TMO	P1,<ALN,LOC>	;MARK FIELDS PRESENT IN MENU
FFAD56:	MOVDM	P1,M11		;SET ALLOCATION ATTRIBUTES MENU


;DATE/TIME ATTRIBUTES

FFAD70:	SETZB	P1,P2		;INITIALIZE MENU SELECTION
	MOVE	T4,.IODPV(IO)	;CARRY AROUND DAP PROTOCOL VERSION
FFAD71:	SKIPE	T3,.IOCDT(CO)	;DO WE HAVE A CREATION DATE/TIME?
	TMO	P1,CDT		;YES, FLAG THE MENU ACCORDINGLY
	MOVD1M	T3,CDT		;SET DATE/TIME ATTR CREATION FIELD
	SKIPE	T3,.IOUDT(CO)	;DO WE HAVE AN UPDATE DATE/TIME?
	TMO	P1,UDT		;YES, FLAG THE MENU ACCORDINGLY
	MOVD1M	T3,UDT		;SET DATE/TIME ATTR UPDATE FIELD
	SKIPE	T3,.IOEDT(CO)	;DO WE HAVE AN EXPIRATION DATE/TIME?
	TMO	P1,EDT		;YES, FLAG THE MENU TOO
	MOVD1M	T3,EDT		;SET DATE/TIME ATTR EXPIRATION FIELD
FFAD73:	CAIGE	T4,006000	;DAP 6.0 OR LATER?
	JRST	FFAD79		;NO, REST OF FIELDS UNKNOWN
	SKIPE	T3,.IOBDT(CO)	;DO WE HAVE AN BACKUP DATE/TIME?
	TMO	P1,BDT		;YES, FLAG THE MENU
	MOVD1M	T3,BDT		;SET DATE/TIME ATTR BACKUP FIELD
	SKIPE	T3,.IOPDT(CO)	;DO WE HAVE A PHYSICAL CREATE DATE/TIME?
	TMO	P1,PDT		;YES, FLAG THE MENU APPROPRIATELY
	MOVD1M	T3,PDT		;SET DATE/TIME ATTR PHYSICAL CREATE FIELD
	SKIPE	T3,.IOADT(CO)	;DO WE HAVE AN ACCESS DATE/TIME?
	TMO	P1,ADT		;YES, FLAG THE MENU
	MOVD1M	T3,ADT		;SET DATE/TIME ATTR ACCESS FIELD

FFAD79:	MOVDM	P1,M13		;SET DATE/TIME ATTRIBUTES MENU


;PROTECTION ATTRIBUTES
;
;FFAD8? ASSUMES PROTECTION FLAGS FIELDS ARE ONLY ONE WORD LONG. AS THIS
;IS NOT GUARANTEED, AT LEAST CAUSE ASSEMBLY ERROR IF IT EVER CHANGES

	IFN	$DLPSY-1,<PRINTX ?PSY field not one word long in FFAD80>
	IFN	$DLPOW-1,<PRINTX ?POW field not one word long in FFAD80>
	IFN	$DLPGR-1,<PRINTX ?PGR field not one word long in FFAD80>
	IFN	$DLPWL-1,<PRINTX ?PWL field not one word long in FFAD80>

FFAD80:	SETZB	P1,P2		;INITIAL MENU FLAGS
	SKIPN	T3,.IOPRT(CO)	;GET PROTECTION CODE
	JRST	FFAD88		;NONE
	LSHC	T3,-6		;REDUCE TO OWNER PROTECTION
	ANDI	T3,7		;AND ONLY OWNER PROTECTION
	MOVE	T2,FPDPTO##(T3)	;TRANSLATE TO DAPISH PROTECTION FLAGS
	MOVDM	T2,POW		;SET PROTECTION ATTR OWNER FIELD
	LSHC	T3,3		;GET GROUP CODE
	ANDI	T3,7		;AND ONLY THE GROUP CODE
	MOVE	T2,FPDPTB##(T3)	;TRANSLATE TO DAPISH PROTECTION FLAGS
	MOVDM	T2,PGR		;SET PROTECTION ATTR GROUP FIELD
	LSHC	T3,3		;GET WORLD ACCESS FIELD
	ANDI	T3,7		;AND ONLY WORLD ACCESS FIELD
	MOVE	T2,FPDPTB##(T3)	;TRANSLATE TO DAPISH PROTECTION FLAGS
	MOVDM	T2,PWL		;SET PROTECTION ATTR WORLD FIELD
	TMO	P1,<POW,PGR,PWL>;SELECT MENU FIELDS
FFAD88:	MOVDM	P1,M14		;SET PROTECTION ATTRIBUTES MENU FIELD

;ALL DONE CONVERTING FILE ATTRIBUTES TO DAP ATTRIBUTES

	JRST	.POPJ1##
;FFADC - HELPER TO CONVERT .IODCH INTO DAP "DEV" FIELD

FFADC1:	SETZB	T2,T3		;INITIALLY NO FLAGS
	TXZE	T1,IC.REC	;"RECORD-ORIENTED"?
	TFO	T2,REC		;YES
	TXZE	T1,IC.CCL	;CARRIAGE-CONTROL?
	TFO	T2,CCL		;YES
	TXZE	T1,IC.TRM	;TERMINAL?
	TFO	T2,TRM		;YES
	TXZE	T1,IC.MDI	;MULTIPLE DIRECTORIES?
	TFO	T2,MDI		;YES
	TXZE	T1,IC.SDI	;SINGLE-DIRECTORY?
	TFO	T2,SDI		;YES
	TXZE	T1,IC.SQD	;SEQUENTIAL BLOCK ORIENTED?
	TFO	T2,SQD		;YES
	TXZE	T1,IC.NUL	;NUL DEVICE?
	TFO	T2,NUL		;YES
	TXZE	T1,IC.FOD	;FILE-ORIENTED DEVICE?
	TFO	T2,FOD		;YES
	TXZE	T1,IC.DSH	;SHARABLE?
	TFO	T2,DSH		;YES
	TXZE	T1,IC.SPL	;SPOOLED DEVICE?
	TFO	T2,SPL		;YES
	TXZE	T1,IC.MNT	;MOUNTED?
	TFO	T2,MNT		;YES
	TXZE	T1,IC.DMT	;MARKED FOR DISMOUNT?
	TFO	T2,DMT		;YES
	TXZE	T1,IC.ALL	;DEVICE ALLOCATED?
	TFO	T2,ALL		;YES
	TXZE	T1,IC.IDV	;CAN DEVICE DO INPUT?
	TFO	T2,IDV		;YES
	TXZE	T1,IC.ODV	;CAN DEVICE DO OUTPUT?
	TFO	T2,ODV		;YES
	TXZE	T1,IC.SWL	;IS DEVICE SOWTWARE-WRITE-LOCKED?
	TFO	T2,SWL		;YES
	TXZE	T1,IC.AVL	;IS DEVICE AVAILABLE?
	TFO	T2,AVL		;YES
	TXZE	T1,IC.ELG	;ERROR-LOGGING ENABLED?
	TFO	T2,ELG		;YES
	TXZE	T1,IC.MBX	;A MAILBOX?
	TFO	T2,MBX		;YES
	TXZE	T1,IC.RTM	;REAL-TIME DEVICE?
	TFO	T2,RTM		;YES
	TXZE	T1,IC.RAD	;RANDOM-ACCESS?
	TFO	T2,RAD		;YES
	TXZE	T1,IC.DRC	;READ-CHECKING ENABLED?
	TFO	T2,DRC		;YES
	TXZE	T1,IC.DWC	;WRITE-CHECKING ENABLED?
	TFO	T2,DWC		;YES
	TXZE	T1,IC.FRN	;FOREIGN DEVICE?
	TFO	T2,FRN		;YES
	TXZE	T1,IC.NDV	;NETWORK DEVICE?
	TFO	T2,NDV		;YES
	TXZE	T1,IC.GDV	;GENERIC DEVICE?
	TFO	T2,GDV		;YES

	TXZ	T1,IC.CTG	;*** CLEAR OUT THE CONFIG FLAG
	CAIE	T1,0		;*** SHOULD HAVE NOTHING LEFT OVER
	STOPCD	<Leftover .IODCH bits in FFADC>  ;***

	JRST	.POPJ1##	;SUCCESSFUL RETURN
;FACL  --  HANDLE "ACCESS OPTIONS" SPECIFIED AT ACCOMP TIME
;CALL IS:
;
;	PUSHJ	P,FACL01
;	 error return
;	normal return
;
;At this time the error return is unused.
;
;On normal return the slave CDB has been set according to the received
;ACCOMP options (if none, the slave is left set as specifed by the FOP
;field of the originating main attributes message). Only the normal
;"CLOSE" operation is accepted, if the ACCOMP function is "SKIP", "ABORT",
;or the like the ACCOMP options are ignored.

FACL01:	MOVD1	T1,A2F		;GET ACCOMP FUNCTION-TYPE FIELD
	CAIE	T1,$DVACL	;"CLOSE" IS THE ONLY ONE TO TRUST
	JRST	.POPJ1##	;ALL OTHERS (SKIP, ABORT, ETC.) WE IGNORE HERE
	MOVE	T3,.IOIOM(CO)	;GET THE SLAVE I/O MODE CONTROL
	TXZ	T3,IM.CXX	;CLEAR CLOSE OPTIONS
	MOVD	T1,AFO		;GET ACCOMP "FOP" FIELD
	FJUMPN	T1,AFO,FACL03	;USE AFO IF SPECIFIED
	MOVD	T1,FOP		;OTHERWISE USE NORMAL "FOP" FIELD
FACL03:	TFNE	T1,DLT		;DELETE FILE ON CLOSE?
	TXO	T3,IM.CDL	;YES
	TFNE	T1,SPC		;PRINT FILE ON CLOSE?
	TXO	T3,IM.CPR	;YES
	TFNE	T1,SCF		;SUBMIT FILE ON CLOSE?
	TXO	T3,IM.CSU	;YES
	MOVEM	T3,.IOIOM(CO)	;SET UPDATED I/O MODE FOR SLAVE
	TXNN	T3,IM.CPR!IM.CSU;TRYING TO PRINT OR SUBMIT?
	JRST	.POPJ1##	;NO, ALL SET
	PUSHJ	P,NONPP1	;YES, DISALLOW IF NETPPN ACCESS
	 POPJ	P,		;PRINT/SUBMIT DISALLOWED
	JRST	.POPJ1##	;ALL OK
;FXAT  --  SHIP ATTRIBUTES MESSAGES
;CALL IS:
;
;	MOVX	P1,<ADS>
;	PUSHJ	P,FXAT00/FXAT01
;	 error return
;	normal return
;
;Where <ADS> is the "access display list" of attributes desired.
;
;FXAT will ship to the remote accessor various and sundry attributes
;messages as specified by the requested attributes in the "access
;display list" (see the ADS field definition in the DAP ACCESS
;message). The caller must set up the various attributes fields
;before calling FXAT!
;
;On error return the network died (error code in M0).
;
;On normal return all requested attributes messages have been given
;to network service (not guaranteed shipped yet).
;
;Uses T1, T2, T3, T4.

FXAT00:	PUSHJ	P,.SAVE4##	;SAVE THE P'S
FXAT01:

;MAIN ATTRIBUTES

FXAT10:	TFNN	P1,DMA		;REMOTE WANT MAIN ATTRIBUTES?
	JRST	FXAT15		;NO
	MOVEI	T2,$DHATR	;YES
	PUSHJ	P,XDDAP0##	;SEND MAIN ATTRIBUTES
	 POPJ	P,		;ERROR

;KEY DEFINITION ATTRIBUTES

FXAT15:;TFNN	P1,DKD		;REMOTE WANT KEY DEFINITIONS?
;	JRST	FXAT20		;NO
;	MOVEI	T2,$DHKYX	;YES
;	PUSHJ	P,XDDAP0##	;SEND KEY DEFINITION ATTRIBUTES
;	 POPJ	P,		;ERROR

;ALLOCATION ATTRIBUTES

FXAT20:	TFNN	P1,DAA		;REMOTE WANT ALLOCATION?
	JRST	FXAT25		;NO
	MOVEI	T2,$DHALC	;YES
	PUSHJ	P,XDDAP0##	;SEND ALLOCATION ATTRIBUTES
	 POPJ	P,		;ERROR

;SUMMARY ATTRIBUTES

FXAT25:;TFNN	P1,DSA		;REMOTE WANT SUMMARY?
;	JRST	FXAT30		;NO
;	MOVEI	T3,$DHSUM	;YES
;	PUSHJ	P,XDDAP0##	;SEND SUMMARY ATTRIBUTES
;	 POPJ	P,		;ERROR

;DATE/TIME ATTRIBUTES

FXAT30:	TFNN	P1,DDT		;REMOTE WANT DATE/TIME
	JRST	FXAT35		;NO
	MOVEI	T2,$DHTIM	;YES
	PUSHJ	P,XDDAP0##	;SEND DATE/TIME ATTRIBUTES
	 POPJ	P,		;ERROR

;PROTECTION ATTRIBUTES

FXAT35:	TFNN	P1,DFP		;REMOTE WANT PROTECTION?
	JRST	FXAT40		;NO
	MOVEI	T2,$DHPRT	;YES
	PUSHJ	P,XDDAP0##	;SEND PROTECTION ATTRIBUTES
	 POPJ	P,		;ERROR

;ACCESS CONTROL LIST

FXAT40:;TFNN	P1,FAC		;REMOTE WANT ACCESS CONTROL LIST?
;	JRST	FXAT90		;NO
;	MOVEI	T2,$DHACL	;YES
;	PUSHJ	P,XDDAP0##	;SEND ACCESS CONTROL LIST ATTRIBUTES
;	 POPJ	P,		;ERROR

;RESULTANT FILE SPECIFICATION (MUST BE DONE LAST)

FXAT90:	TFNN	P1,DNM		;REMOTE WANT FILE NAME?
	JRST	.POPJ1##	;NO
	MOVDII	P1,NTY,NFS	;YES
	PJRST	FXNA01		;SEND RESULTANT FILE SPEC NAME MESSAGE.
;FXNA  --  SEND NAME MESSAGES
;CALL IS:
;
;	MOVX	P1,<NTY>
;	PUSHJ	P,FXNA00/FXNA01
;	 error return
;	normal return
;
;Where <NTY> is the mask of name messages to be sent.
;
;FXNA sends name messages to the remote, based on the <NTY> mask
;passed by the caller. The name strings used come from the slave
;CDB (.IOFST, etc.).
;
;IO (and CI) have the address of the primary CDB, and CO has the
;address of the slave CDB.
;
;On error return the network died.
;
;On normal return the requested name messages have been sent.
;
;Uses T1, T2, T3, T4, P1, P2, P3, P4.

FXNA01:	XMOVEI	T1,FXNXTO	;TYPER
	PUSHJ	P,.TYOCH##	;SET CHARACTER STUFFER
	MOVE	P3,T1		;REMEMBER PREVIOUS
	MOVE	P4,[POINT 7,.IDNMS(CI)]  ;PROTOTYPE BYTE STUFFER

;VOLUME (DEVICE) NAME

FXNA10:	TFNN	P1,NVN		;NEED A VOLUME NAME?
	JRST	FXNA20		;NO
	MOVEM	P4,.IOXTO(CI)	;YES
	SKIPN	T1,.IOFDV(CO)	;[SLAVE] ADDRESS OF DEVICE NAME STRING
	STOPCD	<No device name string in FXNA10>
	PUSHJ	P,.TSTRG##	;SET IT UP
	PUSHJ	P,.TCOLN##	;AND A ":" TO KEEP DAP HAPPY
	MOVDII	T1,NTY,NVN	;THIS IS A VOLUME NAME
	PUSHJ	P,FXNA90	;SEND NAME MESSAGE
	 JRST	FXNA80		;NET DIED

;DIRECTORY NAME

FXNA20:	TFNN	P1,NDN		;NEED A DIRECTORY NAME?
	JRST	FXNA30		;NO
	MOVEM	P4,.IOXTO(CI)	;YES
	PUSHJ	P,.TLBRK##	;SET "["
	SKIPE	T1,.IOFDR(CO)	;[SLAVE] ADDRESS OF DIRECTORY NAME STRING
	PUSHJ	P,.TSTRG##	;SET DIRECTORY (IF ANY)
	PUSHJ	P,.TRBRK##	;CLOSING "]"
	MOVDII	T1,NTY,NDN	;THIS IS A DIRECTORY NAME
	PUSHJ	P,FXNA90	;SEND NAME MESSAGE
	 JRST	FXNA80		;NET DIED

;FILE (AND EXTENSION (AND GENERATION)) NAME

FXNA30:	TFNN	P1,NFN		;WANT FILE (ETC.) NAME
	JRST	FXNA40		;NO
	MOVEM	P4,.IOXTO(CI)	;YES
	SKIPE	T1,.IOFNM(CO)	;GET FILE NAME (IF ANY)
	PUSHJ	P,.TSTRG##	;SET IT UP
	SKIPN	.IOFEX(CO)	;IF A FILE TYPE,
	SKIPE	.IOFGN(CO)	;OR A GENERATION
	CAIA			;THEN NEED A DOT
	JRST	FXNA33		;ALL DONE (NO .TYPE.GENERATION)
	PUSHJ	P,.TDOT##	;SEPARATE FROM EXTENSION
	SKIPE	T1,.IOFEX(CO)	;GET FILE TYPE (IF ANY)
	PUSHJ	P,.TSTRG##	;SET IT TOO
	SKIPN	.IOFGN(CO)	;GOT A GENERATION TOO?
	JRST	FXNA33		;NO
	PUSHJ	P,.TDOT##	;YES
	MOVE	T1,.IOFGN(CO)	;GENERATION STRING
	PUSHJ	P,.TSTRG##	;SET IT TOO
FXNA33:	MOVDII	T1,NTY,NFN	;FILE NAME
	PUSHJ	P,FXNA90	;SEND NAME MESSAGE
	 JRST	FXNA80		;DIED

;FULL FILE SPECIFICATION

FXNA40:	TFNN	P1,NFS		;WANT FULL FILE SPECIFICATION?
	JRST	FXNA50		;NO
	MOVEM	P4,.IOXTO(CI)	;YES
	MOVE	T1,CO		;SELECT SLAVE CDB FOR FILE NAME STRINGS
	PUSHJ	P,.TOCFL##	;TYPE OUT THE FILE SPECIFICATION STRING
	 STOPCD	<TOCFL failed in FXNA40>
	MOVDII	T1,NTY,NFS	;FILE SPECIFICATION
	PUSHJ	P,FXNA90	;SEND NAME MESSAGE
	 JRST	FXNA80		;DIED

;DONE, RESTORE AND EXIT

FXNA50:	MOVE	T1,P3		;ORIGINAL OUTPUT ROUTINE
	PUSHJ	P,.TYOCH##	;RESTORE ORIGINAL
	JRST	.POPJ1##	;SUCCESSFUL RETURN


;ABORT NAME MESSAGES

FXNA80:	MOVE	T1,P3		;ORIGINAL OUTPUT ROUTINE
	PJRST	.TYOCH##	;RESTORE ORIGINAL


;HELPER TO BUILD CHARACTER STRING

FXNA90:	MOVDM	T1,NTY		;SET NAME TYPE
	SETZ	T1,		;TERMINATING NULL
	MOVE	T2,.IOXTO(CI)	;BYTE STUFFER
	IDPB	T1,T2		;TERMINATE ASCIZ STRING
	TLNE	T2,760000	;ON A WORD BOUNDRY?
	JRST	.-2		;NOT YET
	MOVEI	T2,$DHNAM	;NAME MESSAGE CODE
	PJRST	XDDAP0##	;SEND A NAME MESSAGE
;AUXILIARY HELPERS

FXNXTO:	IDPB	T1,.IOXTO(CI)	;STUFF THIS BYTE VIA THE PRIMARY CDB
	POPJ	P,		;RETURN TO SCAN
;FXSTS  --  SEND DAP STATUS MESSAGE
;CALL IS:
;
;	MOVX	T1,<STS>
;	MOVX	T2,<STV>
;	PUSHJ	P,FXSTS
;	 error return
;	normal return
;
;where <STS> is the 16-bit DAP status value; <STV> is the "secondary"
;status value.
;
;On error return the network died, error code is in M0.
;
;On normal return the specified status information has been encapsulated
;and sent to the remote "active" DAP process.
;
;Uses T1, T2, T3, T4.

FXSTS0:	PUSHJ	P,.SAVE4##	;PRESERVE THE P'S HERE
FXSTS1:	MOVD1M	T1,STC		;SET DAP STATUS CODE (MAJOR STATUS)
	MOVD1M	T2,STV		;SET DAP SECONDARY STATUS VALUE
	SETZB	T1,T2		;ZERO DAP VALUE
	MOVDM	T1,SRA		;CLEAR STATUS RECORD ADDRESS
	MOVDM	T1,SRN		;CLEAR STATUS RECORD NUMBER
	MOVDII	T1,M09,<STC,SRA,SRN,STV>  ;INVISIBLE MENU FOR ALL BUT TEXT
	MOVDM	T1,M09		;SET STATUS [INVISIBLE] MENU FIELD
	MOVEI	T2,$DHSTS	;STATUS MESSAGE TYPE
	PUSHJ	P,XDDAP1##	;SEND A DAP STATUS MESSAGE
	 POPJ	P,		;NET DIED?
	PJRST	XDFLS1##	;FLUSH THE PIPE NOW
;FX7ACK  --  SEND DAP ACK IF PROTOCOL VERSION 7.0 OR LATER
;CALL ISL
;
;	PUSHJ	P,FX7ACK
;	 error return
;	normal return
;
;On error return the network has died.
;
;On normal return an ACK message has been built (but not necessarily
;transmitted) if the remote DAP process supports version 7.0 or later
;protocol.
;
;Uses T1, T2, T3, T4.

FX7ACK:	MOVE	T1,.IODPV(IO)	;GET THE DAP PROTOCOL VERSION
	CAIGE	T1,007000	;VERSION 7.0 OR LATER?
	JRST	.POPJ1##	;NO, JUST IGNORE
	PJRST	XDACK1##	;YES, SEND AN ACK
	SUBTTL	General-purpose non-specific subroutines

;F8BAZ - COPY 8-BIT STRING INTO 7-BIT STRING
;Call is:
;
;	MOVX	T1,<DST>
;	MOVX	P1,<8BP>
;	PUSHJ	P,F8BAZ
;	 error return
;	normal return
;
;Where <DST> is the address for the resultant ASCIZ string; and <8BP>
;is the address of the 8-bit byte string

F8BAZ:	HLRZ	P2,0(P1)	;COUNT OF BYTES FOLLOWING
	JUMPLE	P2,[SETZM 0(T1)		;JUST CLEAR FIRST WORD
		JRST	.POPJ1##]	;AND LET IT GO AT THAT
	HRLI	T1,(POINT 7,)	;BYTE STUFFER
	HRLI	P1,(POINT 8,)	;BYTE SNATCHER
	ADDI	P1,1		;POINT TO 8-BIT BYTE STRING

;LOOP COPYING BYTES

F8BAZ3:	ILDB	T2,P1		;GET NEXT BYTE
	IDPB	T2,T1		;AND STASH IT
	SOJG	P2,F8BAZ3	;LOOP FOR REST OF STRING
	SETZ	T2,		;DONE, A NULL
	IDPB	T2,T1		;TO ASCIZIZE THE STRING
	TLNE	T1,740000	;END OF WORD YET?
	JRST	.-2		;NO, CLEAR OUT REST OF WORD
	JRST	.POPJ1##	;YES, HAPPY
;F8B6B - CONVERT 8-BIT BYTE STRING INTO 6-BIT WORD
;CALL IS:
;
;	MOVX	P1,<8BP>
;	PUSHJ	P,F8B6B
;	 error return
;	normal return
;
;Where <8BP> is the address of the 8-bit byte string.
;
;On successful return the SIXBIT word is in T1.

F8B6B:	SETZ	T1,		;NEED A ZERO'ED T1 IN ANY CASE
	HLRZ	P2,@P1		;GET COUNT OF BYTES FOLLOWING
	JUMPLE	P2,.POPJ1##	;NULL STRING, RETURN NULL WORD
	HRLI	P1,(POINT 8,,32);BYTE SNATCHER
F8B6B2:	MOVE	T2,[POINT 6,T1]	;BYTE STUFFER

;LOOP BUILDING THE SIXBIT NAME

F8B6B3:	ILDB	T3,P1		;FETCH NEXT BYTE
F8B6B5:	CAIN	T3,.CHCNV	;A ^V QUOTE?
	JRST	F8B6B7		;YES, EAT IT
	CAIL	T3,"a"		;LOWER
	CAILE	T3,"z"		; CASE?
	CAIA			;NO
	SUBI	T3,"a"-"A"	;YES, CAPITALIZE IT
	SUBI	T3,"0"-'0'	;SIXBITIFY THIS CHARACTER
	TLNE	T2,770000	;ALREADY GOT A FULL WORD?
	IDPB	T3,T2		;NO, ACCUMULATE ANOTHER SIXBIT CHARACTER
F8B6B7:	SOJG	P2,F8B6B3	;LOOP FOR REST OF STRING
	JRST	.POPJ1##	;RETURN HAPPILY
;F8BUP - CONVERT 8-BIT USERID STRING INTO PPN
;CALL IS:
;
;	MOVX	P1,<8BP>
;	PUSHJ	P,F8BUP
;	 error return
;	normal return
;
;Where <8BP> is the address of the 8-bit byte string.
;
;If the string is a regular ppn it is translated directly into a
;binary-form ppn; If the string is not a direct representation of
;a ppn (i.e., it doesn't start with either a "[" character or an
;octal digit) then the string is treated as a "name" which will
;be matched from SYS:USERS.TXT, and translated accordingly into a
;ppn.
;
;On normal return the ppn is in T1.

F8BUP:	HLRZ	P2,@P1		;GET BYTE COUNT
	JUMPLE	P2,.POPJ1##	;NULL STRING, NULL PPN
	HRLI	P1,(POINT 8,,32);BYTE SNATCHER
	MOVE	T4,P1		;COPY OF USERID STRING POINTER
	ILDB	T1,T4		;COPY OF FIRST USERID CHARACTER
	CAIE	T1,"<"		;> (MATCH ANGLE BRACKETS)
	CAIN	T1,"["		;LEADING "NOISE" CHARACTER?
	SOSA	P2		;YEAH, DISCOUNT THE "[" (OR WHATEVER)
	JRST	F8BUP5		;NO, TREAT USERID STRING AS IS
	IBP	P1		;SKIP LEADING NOISE CHARACTER
	MOVE	T4,P2		;REMAINING USERID STRING LENGTH
	ADJBP	T4,P1		;POINT TO LAST USERID CHARACTER
	LDB	T2,T4		;COPY OF LAST USERID CHARACTER
	CAIN	T2,2(T1)	;MATCHING TERMINATOR?
	SOS	P2		;YES, DISCOUNT TRAILING NOISE CHARACTER
F8BUP5:

IFN FTUTXT,<
	PUSHJ	P,F8BUN		;SEE IF NAME<=>PPN TRANSLATION APPLICABLE
	 POPJ	P,		;ERROR, NO SUCH NAME
> ;END IFN FTUTXT

;EXTRACT PROJECT NUMBER FIRST

	SETZ	T1,		;INITIALIZE T1
	PUSHJ	P,F8XOC		;EXTRACT THE OCTAL NUMBER
	JUMPE	T2,.POPJ##	;NULL IS ERROR HERE
	HRLZ	T1,T2		;POSITION PROJECT NUMBER
	CAIN	T3,","		;BETTER BE COMMA SEPARATOR
	CAIG	P2,0		;WITH MORE CHARACTERS LEFT TO COME
	POPJ	P,		;NO! JUNK FORMAT PPN

;NOW READ IN THE PROGRAMMER NUMBER

	PUSHJ	P,F8XOC		;EXTRACT THE OCTAL PROGRAMMER
	JUMPE	T2,.POPJ##	;NULL IS ERROR HERE
	HRR	T1,T2		;POSITION PROGRAMMER
	JRST	.POPJ1##	;RETURN WITH PPN IN T1
;EXTRACT OCTAL NUMBER (HELPER FOR F8BUP)

F8XOC:	SETZ	T2,		;INITIALIZE NUMBER
F8XOC3:	ILDB	T3,P1		;NEXT BYTE
	CAIL	T3,"0"		;OCTAL
	CAILE	T3,"7"		; DIGIT?
	SOJA	P2,.POPJ##	;NO, END OF NUMBER
	ASH	T2,3		;MAKE ROOM AND
	ADDI	T2,-"0"(T3)	;ADD IN THIS OCTADE
	SOJG	P2,F8XOC3	;LOOP FOR MORE DIGITS
	SETO	T3,		;OOPS, RAN OUT, TERMINATE SCAN
	POPJ	P,		;RETURN
;F8BUN - TRANSLATE USERID NAME STRING INTO PPN STRING FROM USERS.TXT
;CALL IS:
;
;	MOVX	P1,<PTR>
;	MOVX	P2,<CTR>
;	PUSHJ	P,P8BUN
;	 error return
;	normal return
;
;Where <PTR> is the input byte pointer (presumed 8 bits, but not required);
;and <CTR> is the count of valid <PTR> bytes.
;
;On error return no name match could be found.
;
;On normal return, either the <PTR> string was not a name (in which case
;treat as ppn string) or the <PTR> string matched a name from USERS.TXT.
;In either case, P1/P2 contain a byte pointer and counter to a ppn string.
;
;Uses T1 - T4, P1 - P4

IFN FTUTXT,<
F8BUN:	DMOVE	T3,P1		;SAVE COPY OF ORIGINAL USER-ID STRING POINTER
	PUSHJ	P,TSAV14##	;NEED SOME SCRATCH SPACE
	PUSHJ	P,F8BUNC	;READ FIRST USERID CHARACTER
	 POPJ	P,		;THIS CAN'T HAPPEN . . .
	CAIL	T1,"0"		;OCTAL
	CAILE	T1,"7"		; DIGIT???
	JRST	F8BUN1		;NO, LOOK FOR A NAME STRING MATCH
	MOVE	P1,-T3(P)	;YES, PPN, RESTORE ORIGINAL <PTR>
	MOVE	P2,-T4(P)	;AND <CTR> FOR CALLER
	JRST	.POPJ1##	;PROCESS USERID<=>PPN
;STILL IFN FTUTXT

;HERE TO TRANSLATE NAME FROM USERS.TXT INTO CORRESPONDING PPN STRING

F8BUN1:	MOVE	P3,UTXPTR	;BYTE POINTER TO USERS.TXT
	MOVE	P4,UTXCTR	;COUNT OF VALID BYTES IN USERS.TXT
F8BUN2:	DMOVE	T3,P3		;SAVE COPY OF THIS USERS.TXT ENTRY
	MOVE	P1,-T3(P)	;FRESH POINTER AND
	MOVE	P2,-T4(P)	; COUNTER FOR USERID STRING
F8BUN3:	PUSHJ	P,F8BUNU	;READ NEXT CHARACTER FROM USERS.TXT
	 JRST	.POPJ##		;EXHAUSTED, NO MATCH, ERROR RETURN
	CAIE	T2,"]"		;END OF PPN PART OF "[P,PN]NAME" PAIR?
	JRST	F8BUN3		;NOT YET, KEEP GOING

;Note that UTXINI "compresses" USERS.TXT from "str:[p,pn],name<CR><LF>"
;entries into "[p,pn]name<LF>" entries . . .

F8BUN5:	PUSHJ	P,F8BUNU	;ANOTHER CHARACTER FROM USERS.TXT
	 JRST	.POPJ##		;EXHAUSTED, NO MATCH (<LF> GUARANTEED AT END)
	PUSHJ	P,F8BUNC	;ANOTHER CHARACTER FROM USERID
	 JRST	[CAIE	T2,.CHLFD	;DONE, AT END OF USERS.TXT NAME TOO?
		JRST	F8BUN7		;NO, SKIP NAME, CHECK NEXT ENTRY
		JRST	F8BUN9]		;YES, THEN THIS IS A MATCH
	CAIN	T2,.CHLFD	;STILL IN USERS.TXT NAME?
	JRST	F8BUN2		;NO, NO MATCH, CHECK NEXT NAME
	CAMN	T1,T2		;NAME CHARACTERS MATCH?
	JRST	F8BUN5		;YES, CHECK REST OF NAME
F8BUN7:	PUSHJ	P,F8BUNU	;NO, EAT THIS USERS.TXT NAME
	 JRST	.POPJ##		;DONE, NO MATCH AT ALL
	CAIE	T2,.CHLFD	;END OF USERS.TXT NAME ENTRY?
	JRST	F8BUN7		;NO, KEEP EATING
	JRST	F8BUN2		;CHECK NEXT USERS.TXT NAME ENTRY

;Here on successful match, return USERS.TXT ppn string in lieu of USERID

F8BUN9:	DMOVE	P1,T3		;USERS.TXT PPN STRING
	IBP	P1		;SKIP THE "[" CHARACTER
	JRST	.POPJ1##	;RETURN TO PROCESS PPN
;STILL IFN FTUTXT

;HELPERS FOR F8BUN

;F8BUNC  --  RETURN ONE USERID CHARACTER

F8BUNC:	SOJL	P2,.POPJ##	;ERROR RETURN IF NO MORE CHARACTERS
	ILDB	T1,P1		;NEXT USERID CHARACTER
	ANDI	T1,177		;MAKE 7-BIT ASCII
	JUMPE	T1,F8BUNC	;SUPPRESS NULLS
	CAIE	T1," "		;COMPRESS SPACES
	CAIN	T1,.CHTAB	; AND TABS
	JRST	F8BUNC		; . . .
	CAIL	T1,"a"		;LOWER CASE ALPHA?
	CAILE	T1,"z"		; . . .
	JRST	.POPJ1##	;NO, SUCCESSFUL RETURN WITH CHARACTER IN T1
	SUBI	T1,"a"-"A"	;YES, SHIFT TO UPPER CASE
	JRST	.POPJ1##	;AND RETURN



;F8BUNU  --  RETURN ONE USERS.TXT CHARACTER

F8BUNU:	SOJL	P4,.POPJ##	;ERROR IF NO MORE CHARACTERS LEFT
	ILDB	T2,P3		;FETCH NEXT CHARACTER
	JUMPN	T2,.POPJ1##	;RETURN CHARACTER
	JRST	F8BUNU		;EAT NULLS

> ;END IFN FTUTXT
;FFIND  --  FIND A SWAPPED CONTROL CODE IN A TABLE
;Call is:
;
;	MOVX	T2,<CODE>
;	MOVEI	T4,<TABL>
;	PUSHJ	P,FFIND
;	 ERROR RETURN
;	NORMAL RETURN
;
;Where <TABL> is a table a la CFIND (codes in right half of words,
;return value in left half of words, table terminated by a 0 word)
;and <CODE> is the code to match.
;
;On error return, <CODE> was not in the table.
;
;On normal return, T4 will point to the table entry that matched, and
;T1 will contain the matching value for <CODE>.
;
;Uses acs T1, T4.

FFIND1:	MOVE	T1,(T4)		;GET FIRST TABLE ENTRY
	JRST	FFIND4		;AND START LOOKING THERE
FFIND2:	SKIPN	T1,(T4)		;END OF TABLE YET?
	POPJ	P,		;YES, TAKE ERROR RETURN
FFIND4:	MOVS	T1,T1		;CODE TO MATCH IS IN LH
	CAIE	T2,(T1)		;CODES MATCH?
	AOJA	T4,FFIND2	;NO, SEARCH REST OF TABLE
	HRRZ	T1,(T4)		;GET RETURN VALUE
	JRST	.POPJ1##	;SUCCESSFUL RETURN
;FAL ERRORS

FEROS:	ERROR	FDS,<FAL DAP message received out of sequence>

FERDP:	ERROR	FDR,<FAL DAP receive error>

FEXDP:	ERROR	FDX,<FAL DAP transmit error>

FERNT:	ERROR	FNR,<FAL network receive error>

FEXNT:	ERROR	FNX,<FAL network transmit error>



M0POPJ:	POP	P,M0		;ADJUST STACK
	POPJ	P,		;PROPAGATE ERROR RETURN
	SUBTTL	CDB initialization vectors

;"FAL" INPUT (PRIMARY) CDB INITIALIZATION VECTOR

FALIV:	EXP	10		;COUNT OF WORDS FOLLOWING
	'NS',,102030		;VERSION WORD
	600			;"EXTRA" SIZE TO ALLOCATE
				; (ENOUGH FOR NETWORK BUFFERS)
	0			;DEFAULT BUFFERING
	0			;MAXIMUM BUFFERING
FALIVC:	0			;I/O CONTROL (DEFAULT = ASCII MODE)
FALIVE:	0			;I/O ERROR CONTROL
FALIVM:	IM.DQA			;I/O MODE
	0			;RETURN FILE PARAMETERS



;"FAL" OUTPUT (SLAVE) CDB INITIALIZATION VECTOR

FALOV:	EXP	10		;COUNT OF WORDS FOLLOWING
	'NS',,102030		;VERSION WORD
	600			;"EXTRA" SIZE TO ALLOCATE
				; (COUPLA FSB'S, 2 128(10)-WORD DISK BUFFERS)
	0			;DEFAULT BUFFERING
	0			;MAXIMUM BUFFERING
FALOVC:	0			;I/O CONTROL (DEFAULT = ASCII MODE)
FALOVE:	0			;I/O ERROR CONTROL
FALOVM:	IM.DQA			;I/O MODE
	0			;RETURN FILE PARAMETERS
	SUBTTL	Impure data

	XLIST			;THE LITERALS
	LIT			;THE LITERALS
	LIST			;EVERYTHING AFTER THE LITERALS


	RELOC			;DOWN TO THE LOWSEG

FJBFF:	BLOCK	1		;JOB/PROGRAM JOBFF
FGTPRG:	BLOCK	1		;JOB/PROGRAM NAME
FSTDFL:	BLOCK	1		;JOB/PROGRAM DSKFUL SETTING
FLOCAT:	BLOCK	1		;JOB/PROGRAM "LOCATE" LOCATION
FGTSPL:	BLOCK	1		;JOB/PROGRAM SPOOLING FLAGS

BZFAL:				;START OF TO-BE-ZEROED ON FAL STARTUP

IFN FTUTXT,<
UTXPTR:	BLOCK	1		;BYTE POINTER TO USERS.TXT BUFFER
UTXCTR:	BLOCK	1		;BYTE COUNTER TO ACCOMPANY UTXPTR
> ;END IFN FTUTXT

NETPPN:	BLOCK	1		;DEFAULT NETWORK PPN FOR BLANK USERID

REJFIR:	BLOCK	1		;FIRST "REJECT"ION SPEC
REJLAS:	BLOCK	1		;LAST "REJECT"ION SPEC

FALTYP:	BLOCK	1		;NETWORK TYPE (IO.ANF OR IO.DCN)
FALSLP:	BLOCK	1		;SLEEP INTERVAL IN FALL70

RSIFFA:	BLOCK	2		;ALLOCATION POINTER TO RECORD BUFFER
RSIFT3:	BLOCK	1		;RECORD LENGTH (ISR CALL)
RSIFT4:	BLOCK	1		;RECORD BUFFER (ISR CALL)

EZFAL:				;END OF TO-BE-ZEROED ON FAL STARTUP
	END