Google
 

Trailing-Edge - PDP-10 Archives - BB-F493Z-DD_1986 - 10,7/conv10.mac
There is 1 other file named conv10.mac in the archive. Click here to see a list.
TITLE CONV10 - USAGE FORMAT TO FACT FORMAT CONVERSION PROGRAM - V1(10)
	SUBTTL	BAHUIZENGA/BAH     13-JAN-81


	SEARCH	GLXMAC,ORNMAC
	SALL


	PROLOG	(CONV10)





;COPYRIGHT (c) DIGITAL EQUIPMENT CORPORATION 1980,1981,1984,1986. ALL RIGHTS RESERVED
;
;
;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.




CV.VER==1		;MAJOR VERSION NUMBER
CV.MIN==0		;MINOR VERSION NUMBER
CV.EDT==10		;EDIT NUMBER
CV.WHO==0		;CUSTOMER/SWS EDIT CODE

%%.CVN==<VRSN. (CV.)>
	LOC	137
	EXP	%%.CVN
	RELOC


COPYRIGHT (c) DIGITAL EQUIPMENT CORPORATION 1980,1986. ALL RIGHTS RESERVED.
\;END COPYRIGHT MACRO
	SUBTTL	EDIT HISTORY


;1)	CONVERT CONV20 TO TAKE TOPS10 USAGE FILES AND PRODUCE TOPS10
;	SUPPORTED FACT FILES.
;2)	GALAXY'S S%DATI ROUTINE WAS FIXED TO RETURN THE UDT IN S2 INSTEAD OF S1.
;3)	MOUNT/DISMOUNT PPN MESSED UP BY BAD INSTRUCTION.
;4)	ACTDAE 1(34) NOW PROVIDES DEVICE FOR MAGTAPE/DECTAPE MOUNTS,
;	INCLUDE IT IN FACT RECORDS.
;5)	MANY PROBLEMS WITH CONVERSION TYPES.
;6)	USE A MACRO TO GENERATE BYTE POINTERS SO ITS EASIER TO CHANGE THEM.
;7)	WORD 11 OF SPRINT,MOUNT/DISMOUNT, AND DECTAPE FILE CLOBBERED.
;10)	INCOMPATABLE CHANGE IN OPRPAR.REL, FORCE LOADING IN THE LOW SEGMENT

	SUBTTL	GENERAL DEFINITIONS

CNVLNG==100			;LENGTH OF PUSHJDOWN LIST
CNVPDL:	BLOCK CNVLNG		;PUSH DOWN LIST

PBSIZ==1000			;PARSER BLOCK SIZE (REQUIRED 1P)

CNVIB:	$BUILD	(IB.SZ)		;INITIALIZATION BLOCK FOR GLXLIB
$SET	(IB.PRG,,%%.MOD)	;PROGRAM NAME
$SET	(IB.OUT,,T%TTY)		;TEXT OUTPUT TO TTY
$SET	(IB.FLG,IT.OCT,1)	;OPEN COMMAND TERMINAL
	$EOB

USGFD:	$BUILD	(FDXSIZ)	;INPUT FILE DESCRIPTOR (FD)
$SET	(.FDLEN,FD.LEN,FDXSIZ)	;LENGTH OF FD
	$EOB

FCTFD:	$BUILD	(FDXSIZ)	;OUTPUT FILE DESCRIPTR (FD)
$SET	(.FDLEN,FD.LEN,FDXSIZ)	;LENGTH OF FD
	$EOB

USGFOB:	$BUILD	(FOB.SZ)	;INPUT FILE OPEN BLOCK (FOB)
$SET	(FOB.FD,,USGFD)		;FILE DESCRIPTOR BLOCK ADDRESS
$SET	(FOB.CW,FB.LSN,1)	;IGNORE LINE SEQUENCE NUMBERS
$SET	(FOB.CW,FB.BSZ,7)	;BYTE SIZE OF FILE
	$EOB

FCTFOB:	$BUILD	(FOB.SZ)	;OUTPUT FILE OPEN BLOCK (FOB)
$SET	(FOB.FD,,FCTFD)		;FILE DESCRIPTOR BLOCK ADDRESS
$SET	(FOB.CW,FB.BSZ,^D36)	;BYTE SIZE OF FILE
	$EOB
	SUBTTL	USAGE FILE ENTRY FORMATS

;*********************************
	RADIX	10
;*********************************

;LENGTH OF FIELDS TO BE PICKED UP IN A USAGE FILE RECORD

LENTYP==4			;ENTRY TYPE LENGTH
LENSEQ==1			;RECORD SEQUENCE LENGTH
LENJOB==4			;JOB # LENGTH
LENLIN==4			;LINE # LENGTH
LENDTM==14			;DATE/TIME LENGTH
LENRUN==9			;RUNTIME LENGTH
LENSTR==6			;FILE STRUCTURE NAME LENGTH
LENPRJ==6			;PROJECT NUMBER LENGTH
LENPRG==6			;PROGRAMMER NUMBER LENGTH
LENDRD==8			;DISK READS LENGTH
LENDWR==8			;DISK WRITES LENGTH
LENCTI==11			;CORE-TIME INTEGRAL
LENNOD==6			;NODE LENGTH
LENQNM==2			;QUEUE NAME LENGTH (FACT FILE USES ONLY THE
				; FIRST TWO CHARACTERS OF THE QUEUE NAME)
LENDEV==6			;DEVICE NAME LENGTH
LENSSQ==6			;SEQUENCE NUMBER LENGTH
LENUNT==6			;INPUT/OUTPUT UNITS LENGTH
LENALC==10			;ALLOCATED DISK BLOCKS LENGTH
LENADU==10			;ACTUAL DISK USAGE LENGTH
LENPPN==12			;PROJECT PROGRAMMER NUMBER
LENQTF==6			;QUOTA IN (FCFS) LENGTH
LENQTO==6			;LOGGED-OUT QUOTA LENGTH
LENCPU==4			;CPU SERIAL NUMBER LENGTH
LENCON==7			;CONNECT TIME LENGTH

;*********************************
	RADIX	8
;*********************************
;BYTE POINTERS TO EACH FIELD THAT WILL BE CONVERTED TO FACT FILE.

DEFINE	CHRPOS(POSIT,LDBFLG),<
	POSN==^D'POSIT-1	;;MAKE RELATIVE TO CHARACTER POSITION 0
	WRDN==POSN/5		;;WORD OFFSET INTO USEBLK
	BYTN==POSN-<WRDN*5>	;;AND BYTE WITHIN WORD
	IFIDN <LDBFLG><L>,<BYTN==BYTN+1> ;;BUMP IF "LDB" INSTEAD OF "ILDB" FORM
	IFE BYTN,<POINT 7,USEBLK+WRDN> ;;FOR FIRST BYTE OR WORD
	IFN BYTN,<POINT 7,USEBLK+WRDN,<BYTN*7>-1>  ;;FOR REMAINING BYTES
>

;HEADER OF ALL USAGE RECORDS - FIRST 20 CHARACTERS (4 WORDS)

USGTYP:	CHRPOS	(1)		;ENTRY TYPE USED FOR BINARY CONVERSIONS
USGSEQ:	CHRPOS	(6,L)		;RECORD SEQUENCE NUMBER (LDB FORMAT)

;ENTRY HEADER RECORD - IS ALWAYS THE FIRST RECORD OF ALL ENTRIES

USGJOB:	CHRPOS	(21)		;JOB NUMBER
USGLDT:	CHRPOS	(25)		;DATE/TIME ENTRY WAS MADE
USGDES:	CHRPOS	(39,L)		;TERMINAL DESIGNATOR (LDB FORMAT)
USGLIN:	CHRPOS	(40)		;LINE NUMBER
USGNOD:	CHRPOS	(80)		;NODE NAME (USED TO GET STATION NUMBER)

;USER IDENTFICATION RECORD

USGPRJ:	CHRPOS	(21)		;PROJECT NUMBER
USGPRG:	CHRPOS	(27)		;PROGRAMMER NUMBER

;SESSION RECORD #1

USGRUN:	CHRPOS	(60)		;USER'S RUNTIME
USGBDT:	CHRPOS	(69)		;DATE/TIME USER BEGAN SESSION

;SESSION RECORD #2 (TOPS10 ONLY)

USGDRD:	CHRPOS	(21)		;DISK READS
USGDWR:	CHRPOS	(29)		;DISK WRITES
USGCTI:	CHRPOS	(37)		;CORE-TIME INTEGRAL

;INPUT AND OUTPUT SPOOLER RECORDS (THE INFORMATION NEEDED FOR BOTH FACT FILE
;	ENTRIES OCCUR IN THE SAME CHARACTER POSITIONS OF THE USAGE FILE INPUT
;	AND OUTPUT SPOOLER ENTRIES.)

USGIRU:	CHRPOS	(60)		;SPOOLER RUNTIME
USGICT:	CHRPOS	(69)		;SPOOLER CORE-TIME INTEGRAL
USGIDR:	CHRPOS	(80)		;SPOOLER DISK READS
USGIDW:	CHRPOS	(88)		;SPOOLER DISK WRITES
USGIQN:	CHRPOS	(102)		;QUEUE NAME
USGIDV:	CHRPOS	(105)		;DEVICE NAME
USGISN:	CHRPOS	(111)		;SEQUENCE NUMBER
USGICD:	CHRPOS	(117)		;CARDS READ/PAGES PRINTED/FEET PUNCHED...
;DISK USAGE DIRECTORY RECORD

USGALL:	CHRPOS	(24)		;TOTAL ALLOCATED DISK BLOCKS
USGADU:	CHRPOS	(34)		;TOTAL ACTUAL DISK BLOCKS USED
USGFSN:	CHRPOS	(49)		;FILE STRUCTURE NAME
USGDIR:	CHRPOS	(55)		;PROJECT PROGRAMMER NUMBER
USGQTF:	CHRPOS	(101)		;QUOTA IN (FCFS)
USGQTO:	CHRPOS	(107)		;LOGGED-OUT QUOTA

;RESTART AND ENTRY HEADER RECORDS

USGCPN:	CHRPOS	(108)		;CPU0 SERIAL NUMBER
USGCP1:	CHRPOS	(112)		;CPU1
USGCP2:	CHRPOS	(116)		;CPU2
USGCP3:	CHRPOS	(120)		;CPU3
USGCP4:	CHRPOS	(124)		;CPU4
USGCP5:	CHRPOS	(128)		;CPU5

;FILE STRUCTURE MOUNT RECORD

USGSTR:	CHRPOS	(60)		;FILE STRUCTURE NAME
USGFDT:	CHRPOS	(148)		;MOUNT DATE/TIME (TIME SERVICED)

;MAGTAPE AND DECTAPE MOUNT RECORDS

USGMDT:	CHRPOS	(161)		;TAPE MOUNT DATE/TIME (TIME SERVICED)
USGMDV:	CHRPOS	(249)		;MAGTAPE DEVICE NAME
USGDDV:	CHRPOS	(199)		;DECTAPE DEVICE NAME

;USER DECTAPE FILE COMMAND RECORD

USGDRT:	CHRPOS	(60)		;OMOUNT RUNTIME
USGDCT:	CHRPOS	(69)		;OMOUNT CORE-TIME INTEGRAL
USGDDR:	CHRPOS	(80)		;OMOUNT DISK READS
USGDDW:	CHRPOS	(88)		;OMOUNT DISK WRITES
USGDSC:	CHRPOS	(158)		;SCHEDULED DATE/TIME
USGDSE:	CHRPOS	(172)		;SERVICED DATA/TIME
USGDCO:	CHRPOS	(186)		;CONNECT TIME
	SUBTTL	FACT FILE ENTRY FORMATS


;HEADER BLOCK DEFINITIONS (FIRST THREE WORDS OF EVERY ENTRY)
	DEFSTR	HDRTYP,FACTBL,8,9	;TYPE CODE
	DEFSTR	HDRJOB,FACTBL,17,9	;JOB #
	DEFSTR	HDRLIN,FACTBL,29,12	;LINE #
	DEFSTR	HDRCNT,FACTBL,35,6	;WORD COUNT OF ENTRY
	DEFSTR	HDRPRJ,FACTBL+1,17,18	;PROJECT NUMBER
	DEFSTR	HDRPOG,FACTBL+1,35,18	;PROGRAMMER NUMBER
	DEFSTR	HDRPPN,FACTBL+1,35,36	;PROJECT-PROGRAMMER #
	DEFSTR	HDRDTM,FACTBL+2,35,36	;DATE/TIME

;LOGIN DEFINITIONS
;	LOGIN ENTRY IS JUST THE FIRST THREE WORDS OF THE HEADER BLOCK

;LOGOUT DEFINITIONS
	DEFSTR	LGORUN,FACTBL+3,35,36	;RUNTIME IN MILLISECONDS
	DEFSTR	LGOCTI,FACTBL+4,35,36	;CORE-TIME INTEGRAL IN KILO-CORE-TICKS
	DEFSTR	LGODRD,FACTBL+5,35,36	;DISK READS
	DEFSTR	LGODWR,FACTBL+6,35,36	;DISK WRITES

;CHECKPOINT ENTRY DEFINITION IS THE FOLLOWING CONCANTENATED WITH A LOGOUT ENTRY
	DEFSTR	CHKPGM,FACTBL+7,35,36	;SIXBIT PROGRAM NAME (ALWAYS ZERO)

;INPUT AND OUTPUT SPOOLER DEFINITIONS

	DEFSTR	IOSQUE,FACTBL+3,11,12	;QUEUE IN SIXBIT - FIRST TWO CHARACTERS
					; OF QUEUE NAME IN THE USAGE FILE
	DEFSTR	IOSSTA,FACTBL+3,17,6	;STATION NUMBER
	DEFSTR	IOSAPR,FACTBL+3,35,18	;APR SERIAL NUMBER
	DEFSTR	IOSRUN,FACTBL+4,35,36	;RUNTIME
	DEFSTR	IOSCTI,FACTBL+5,35,36	;CORE-TIME INTEGRAL IN 100*(KILO-CORE-SECONDS)
	DEFSTR	IOSDRD,FACTBL+6,35,36	;DISK READS
	DEFSTR	IOSDWR,FACTBL+7,35,36	;DISK WRITES
	DEFSTR	IOSDEV,FACTBL+10,35,36	;PHYSICAL DEVICE IN SIXBIT
	DEFSTR	IOSSEQ,FACTBL+11,35,36	;SEQUENCE NUMBER
	DEFSTR	IOSUNT,FACTBL+12,35,36	;UNITS INPUT OR OUTPUT

;**********************************************************************
;***** N O T E ********* In the case of a SPRINT  FACT file entry, the 
;***********************     following flag will always be on.
;**********************************************************************

	DEFSTR	INPCOM,FACTBL+12,0,1	;BATCH INPUT REQUEST CREATED IF 1

;**********************************************************************
;***** N O T E ********* In the case of mount entries and file command
;***********************     entries, the following flag will always be on.
;**********************************************************************

	DEFSTR	MNTCOM,FACTBL+12,17,1	;REQUEST SUCCESSFUL IF 1
;SPACE ENTRY DEFINITIONS

	DEFSTR	DSKSTR,FACTBL+3,35,36	;FILE STRUCTURE NAME IN SIXBIT
	DEFSTR	DSKUFD,FACTBL+4,35,36	;UFD STATUS WORD - ALWAYS ZERO
	DEFSTR	DSKFCS,FACTBL+5,35,36	;FCFS QUOTA
	DEFSTR	DSKLGO,FACTBL+6,35,36	;LOGGED-OUT QUOTA
	DEFSTR	DSKRSV,FACTBL+7,35,36	;RESERVED QUOTA - ALWAYS ZERO
	DEFSTR	DSKALC,FACTBL+10,35,36	;ALLOCATED BLOCKS
	DEFSTR	DSKREM,FACTBL+11,35,36	;BLOCKS REMAINING FOR USER'S FCFS
	DEFSTR	DSKOUT,FACTBL+12,35,36	;'IN', 'OUT', OR 'RECOMP' - ALWAYS 'OUT'
	SUBTTL	TOP LEVEL ROUTINE

CONV10:	RESET
	MOVE	P,[-CNVLNG,,CNVPDL]	;SET UP STACK POINTER
	MOVEI	S1,IB.SZ	;SIZE OF INITIALIZATION BLOCK (IB)
	MOVEI	S2,CNVIB	;ADDRESS OF THE IB
	$CALL	I%INIT		;INITIALZE THE WORLD
	SETZB	S1,S1		;NO ARGUMENTS
	$CALL	P$INIT##	;INITIIALIZE THE PARSER
	PUSHJ	P,GETIN		;GET USAGE FORMAT INPUT FILE SPEC
	PUSHJ	P,GETOUT	;GET FACT  FORMAT OUTPUT FILE SPEC (NEW OR OLD)
	PUSHJ	P,GETOPN	;GO OPEN THE FILES
	PUSHJ	P,GETDEF	;GET DEFAULT DATA THAT CAN'T BE PRODUCED WITH USAGE DATA
	PUSHJ	P,CLRTBL	;ZERO THE FACT ENTRY BUILDING TABLE


;HERE TO BEGIN TO READ AN ENTRY

READXX:	PUSHJ	P,USGIN		;SET UP TO READ ANOTHER RECORD
	JUMPF	DONE		;EOF. GO FINISH UP
READX1:	LDB	T1,USGSEQ	;GET SEQUENCE # POINTER
	CAIE	T1,"1"		;IS THIS THE FIRST RECORD OF AN ENTRY?
	JRST	READXX		;NO, READ UNTIL WE FIND ONE
	MOVE	T1,USGTYP	;GET POINTER TO ENTRY TYPE
	MOVEI	T2,LENTYP	;GET THE LENGTH
	PUSHJ	P,NUMDEC	;CONVERT FOR DISPATCH TABLE
	MOVEM	T1,SAVTYP	;SAVE THE ENTRY TYPE
	CAIL	T1,DISLEN	;DO WE KNOW ABOUT THIS ENTRY TYPE?
	JRST	[PUSHJ	P,UNSUPP;NO REPORT IT AND READ NEXT ENTRY
		JRST	READXX]
	PUSHJ	P,@DISPAT(T1)	;GO PROCESS APPROPRIATE ROUTINE
				; THE DISPATCH ROUTINE WILL DO A TRUE RETURN
				; IF NO ERRORS ARE ENCOUNTERED. OTHERWISE,
				; IF A SEQUENCE NUMBER OF 1 IS READ, THE
				; ROUTINE WILL GIVE A FALSE RETURN
	JUMPT	READXX		;GOOD RETURN. START ON NEXT ENTRY
	$WARN	(Incomplete entry ^D/SAVTYP/ found)
	JRST	READX1		;GO HERE IN CASE THE LAST RECORD READ IS THE
				; FIRST RECORD OF THE NEXT ENTRY
	SUBTTL	DISPATCH TABLE TO PROCESS USAGE ENTRIES TO FACT ENTRIES

DISPAT:	UNSUPP			;NO ENTRY NUMBERED '0000'
	RESTAR			;SYSTEM RESTART ENTRY '0001' - MAKES A
				; RESTART FACT ENTRY '371'
	SESSIO			;SESSION ENTRY '0002' - MAKES A LOGIN ENTRY
				; '101' AND A LOGOUT ENTRY '141'
	SESSIO			;INCOMPLETE SESSION ENTRY '0003' -
				; MAKES A LOGIN ENTRY '101' AND A CHKPNT
				; ENTRY '201'
	HEADER			;UNDEFINED ENTRY '0004' BUT PROVIDES APR SERIAL
				; NUMBER AND DEFAULT STATION NUMBER
	UNSUPP			;'0005' ENTRY NOT SUPPORTED IN FACT FILE
	UNSUPP			;'0006' ENTRY NOT SUPPORTED IN FACT FILE
	INPSPL			;INPUT SPOOLER ENTRY '0007' ENTRY - MAKES A SPRINT
				; ENTRY '231'
	OUTSPL			;OUTPUT SPOOLER ENTRY '0008' ENTRY - MAKES A
				; SPOOL ENTRY '251'
	DISKUS			;DISK USAGE DIRECTORY AND ACCOUNT STRING
				; ENTRY '0009' - MAKES SPACE ENTRY '161'
	UNSUPP			;'0010' entry not supported in FACT file
	MNTSTR			;User file structure mount entry '0011' - 
				; makes two mount entries '271'
	MNTMAG			;User magtape mount entry '0012' - makes
				; two mount entries '271'
	MNTDEC			;User DECtape mount entry '0013' - makes
				; two mount entries '271'
	FILCMD			;User DECtape file command entry '0014' -
				; makes one mount entry '271'


DISLEN=.-DISPAT			;LENGTH OF DISPATCH TABLE
	SUBTTL	INPUT/OUTPUT ROUTINES

;GETIN - ROUTINE TO GET THE INPUT FILE SPEC FOR THE FILE THAT HAS THE USAGE
;	FORMAT.  THIS FILE'S DATA WILL BE CONVERTED TO FACT FILE FORMAT
;CALL:	PUSHJ	P,GETIN

GETIN:	MOVEI	S1,COM.SZ-1	; Set reserved space
	HRLM	S1,CBL		;  for bookkeeping in data block
	MOVEI	S1,4		; Time to call the parser
	MOVEI	S2,PARINP	;  with appropriate arguments
	$CALL	PARSER##	; "Come in, Tokyo"
	JUMPF	NOPE		; Process any indigestible input
	HRRZ	S1,1(S2)	; Address of returned data block
	HRRZM	S1,PARINP+PAR.CM; Save for later
	MOVEI	S1,COM.SZ+CBL	; Point to parsed stuff
	$CALL	P$SETU##	; Tell GALAXY where it is
	$CALL	P$IFIL##
	JUMPF	DONT		; ???
	HRL	T1,S1		;ADDRESS OF FD
	HRRI	T1,USGFD	;USAGE FILE FD FOR USGFOB
	BLT	T1,USGFD-1(S2)	;BLT THE LENGTH OF THE FD RETURNED BY P$IFIL
	POPJ	P,

NOPE:	MOVE	S1,PRT.EM(S2)	; Point to ASCIZ error message
	MOVE	T1,PRT.FL(S2)	; Get flags
	TLZE	T1,(P.ENDT)	; End of take file?
	POPJ	P,
	OUTSTR	[ASCIZ /? /]	; No, call it an error
	OUTSTR	(S1)		; Output it
	POPJ	P,

DONT:	OUTSTR	[ASCIZ /? Unknown command
/]
	JRST	GETIN		; Do it right this time


;GETOUT - ROUTINE TO THE THE OUTPUT FILE SPEC FOR THE FILE THAT WILL
;	HAVE THE FACT FILE FORMAT.
;CALL:	PUSHJ	P,GETOUT

GETOUT:	MOVEI	S1,COM.SZ-1	; Set reserved space
	HRLM	S1,CBL		;  for bookkeeping in data block
	MOVEI	S1,4		; Time to call the parser
	MOVEI	S2,PAROUT	;  with appropriate arguments
	$CALL	PARSER##	; "Come in, Tokyo"
	JUMPF	NOPE		; Process any indigestible input
	HRRZ	S1,1(S2)	; Address of returned data block
	HRRZM	S1,PAROUT+PAR.CM; Save for later
	MOVEI	S1,COM.SZ+CBL	; Point to parsed stuff
	$CALL	P$SETU##	; Tell GALAXY where it is
	$CALL	P$OFIL##		;GET OUTPUT FILE SPEC
	JUMPF	DONT1		; ???
	HRL	T1,S1		;ADDRESS OF FD
	HRRI	T1,FCTFD	;ADDRESS WHERE TO PUT NEW FD
	BLT	T1,FCTFD-1(S2)	;COPY IT ALL
	$RETT

DONT1:	OUTSTR	[ASCIZ /? Unknown command
/]
	JRST	GETOUT		; Do it right this time


;GETOPN - ROUTINE TO OPEN INPUT AND OUTPUT FILES
;CALL:	PUSHJ	P,GETOPN

GETOPN:	MOVEI	S1,FOB.SZ	;LENGTH OF FOB
	MOVEI	S2,USGFOB	;ADDRESS OF INPUT FOB
	$CALL	F%IOPN		;OPEN THE USAGE FILE
	SKIPT
	$FATAL	(Error (^E/S1/) opening USAGE file ^F/USGFD/)
	MOVEM	S1,USGIFN	;SAVE THE INTERNAL FILE NUMBER (IFN)
	MOVEI	S1,FOB.SZ	;LENGTH OF FOB
	MOVEI	S2,FCTFOB	;ADDRESS OF OUTPUT FOB
	$CALL	F%OOPN		;OPEN THE FACT FILE
	SKIPT
	$FATAL	(Error (^E/S1/) opening FACT file ^F/FCTFD/)
	MOVEM	S1,FCTIFN	;SAVE THE INTERNAL FILE NUMBER (IFN)
	$RETT			;NOW GO PROCESS
;USGIN - ROUTINE TO READ A USAGE RECORD OF AN ENTRY INTO USEBLK
;CALL:	PUSHJ	P,USGIN


USGIN:	$CALL	.SAVE1		;SAVE P1
	MOVE	P1,[POINT 7,USEBLK]	;MAKE A BYTE POINTER TO STORE THE RECORD
	MOVE	S1,USGIFN	;GET THE USAGE INTERNAL FILE NUMBER
USGIN1:	$CALL	F%IBYT		;READ A CHARACTER
	JUMPF	USGIN2
	CAIN	S2,.CHLFD	;IS THIS THE END OF THE RECORD (LINE-FEED)?
	$RETT			;YES. RETURN TO THE CALLER
	SKIPN	S2		;IS THE CHARACTER A NULL?
	JRST	USGIN1		;YES. NOT INTERESTED IN NULLS
	IDPB	S2,P1		;NO. PUT CHARACTER IN USEBLK
	JRST	USGIN1		;AND READ ANOTHER CHARACTER

USGIN2:	CAIN	S1,EREOF$	;IS IT AN END-OF-FILE ERROR?
	$RETF			;YES. LET CALLER DECIDE WHAT TO DO
	$FATAL	(Error (^E/S1/) reading USAGE file ^F/USGFD/)



;FCTOUT - ROUTINE TO OUTPUT FACT FILE ENTRIES. THE ENTRY IS FOUND IN FACTBL:.
;	THE BYTE COUNT (36-BIT BYTES) IS FOUND BY REFERENCING HDRCNT
;CALL:	PUSHJ	P,FCTOUT

FCTOUT:	LOAD	S2,,HDRCNT	;GET THE WORD COUNT OF ENTRY
	HRLZS	S2		;PUT NUMBER OF BYTES IN LH
	HRRI	S2,FACTBL	;ADDRESS WHERE FACT ENTRY IS FOUND
	MOVE	S1,FCTIFN	;GET FACT FILE IFN
	$CALL	F%OBUF		;OUTPUT THE ENTRY
	SKIPT
	$FATAL	(Error writing FACT entry whose first word is ^O/FACTBL/)
	PUSHJ	P,CLRTBL	;YES. ZERO FACT FILE ENTRY BUILDING TABLE
	$RETT			;AND RETURN



;DONE - ROUTINE TO FINISH UP
;CALL:	JRST	DONE

DONE:	PUSHJ	P,EOFENT	;MAKE AN END-OF-FILE FACT ENTRY
	MOVE	S1,USGIFN	;USAGE INTERNAL FILE NUMBER
	$CALL	F%REL		;CLOSE AND RELEASE THE FILE
	SKIPT
	$WARN	(Error (^E/S1/) trying to close USAGE file ^F/USGFD/)
	MOVE	S1,FCTIFN	;FACT INTERNAL FILE NUMBER
	$CALL	F%REL		;CLOSE AND RELEASE THE FILE
	SKIPT
	$WARN	(Error (^E/S1/) trying to close FACT file ^F/FCTFD/)
	OUTSTR	[ASCIZ /
[USAGE to FACT conversion completed]/]	;YES. REPORT CONVERSION COMPLETE
	EXIT
	SUBTTL	GENERAL ROUTINES

;GETDEF - ROUTINE TO GET DEFAULT DATA WHEN FACT FILE DATA FOR PARTICULAR
;	ENTRIES IS NOT PROVIDED IN THE USAGE ENTRY.  NOTE THAT IF USAGE
;	FILES ARE PROCESSED ON A SYSTEM DIFFERENT FROM WHERE THE USAGE
;	FILE WAS CREATED, THEN THESE DEFAULTS WILL REFLECT THE SYSTEM THAT
;	THE FACT FILES WERE CREATED ON.

GETDEF:	MOVX	T1,%LDFFA	;ASSUME THIS WAS DAEMON'S PPN.  USED IN
	GETTAB	T1,		; RESTART ENTRY
	  MOVE	T1,[1,,2]	;ERROR. DEFAULT TO [1,2]
	MOVEM	T1,FFAPPN	;SAVE IT
	$RETT


;CHKLIN - ROUTINE TO FIGURE OUT AND STORE WHAT GOES IN THE TTY LINE NUMBER
;	SLOT OF THE FACT FILE FOR ANY ENTRY.  IF DETACHED, A 7776 IS PUT IN;
;	IF A CTY, A 7777 IS PUT IN.  OTHERWISE, THE LINE NUMBER IN THE USAGE
;	ENTRY IS PUT IN THE FACT ENTRY.
;CALL:	PUSHJ	P,CHKLIN
;	RETURNS APPROPRIATE CONVERTED LINE NUMBER IN T1

CHKLIN:	LDB	T1,USGDES	;GET TERMINAL DESIGNATOR
	CAIN	T1,"C"		;IS THE LINE NUMBER THE CTY?
	JRST	[MOVEI	T1,7777	;YES.
		STORE T1,,HDRLIN
		$RETT]
	CAIN	T1,"D"		;NO. IS THE LINE DETACHED?
	JRST	[MOVEI	T1,7776	;YES.
		STORE	T1,,HDRLIN
		$RETT]
	MOVE	T1,USGLIN	;NO. GET THE BYTE POINTER TO THE LINE NUMBER
	MOVEI	T2,LENLIN	; AND ITS LENGTH
	PJRST	NUMOCT		;CONVERT IT

;CLRTBL - ROUTINE TO ZERO FACT FILE ENTRY BUILDING TABLE, FACTBL.

CLRTBL:	SETZM	FACTBL
	MOVE	T1,[FACTBL,,FACTBL+1]
	BLT	T1,FACEND
	$RETT


;FNDNOD - Routine to find a node number based on the node name found in
;	record #1 of any USAGE entry.  Returns true with node number in
;	T1.  Returns false if node doesn't currently exist in the network.

FNDNOD:	MOVE	T1,USGNOD	;POINTER TO NODE NAME
	MOVEI	T2,LENNOD	;AND ITS LENGTH
	PUSHJ	P,ASCSIX	;CONVERT IT TO SIXBIT
	MOVEI	T3,2		;NODE ARGUMENT BLOCK IS 2 WORDS LONG
	MOVE	T1,[.NDRNN,,T3]	;GET THE NODE NUMBER
	NODE.	T1,
	$RETF			;ERROR. NODE NOT IN CURRENT NETWORK
	$RETT			;NODE NUMBER IN T1
	SUBTTL	USAGE DATA TO FACT DATA CONVERSION ROUTINES

;UNSUPP - ROUTINE TO USE IF A USAGE FILE ENTRY HAS NOT BEEN SUPPORTED
;	IN THE FACT FILES PRODUCED BY TOPS10 AND APPROPRIATE CUSPS

UNSUPP:	$WARN	(Entry type ^D/SAVTYP/ is not supported in FACT file format)
	$RETT


;RESTAR - ROUTINE TO PROCESS SYSTEM RESTART RECORD
;	ALWAYS DOES A TRUE RETURN SINCE ONLY ONE USAGE RECORD HAS TO BE
;	READ TO MAKE A FACT FILE ENTRY.  THUS A TRUE RETURN WILL FORCE READXX
;	TO READ THE REST OF THE ENTRY WITH NO ERROR REPORTING.

RESTAR:	ZERO	,HDRCNT		;ZERO WORD COUNT OF ENTRY
	MOVEI	T1,371		;GET FACT ENTRY TYPE
	STORE	T1,,HDRTYP
	MOVE	T1,USGJOB	;GET POINTER TO JOB NUMBER
	MOVEI	T2,LENJOB	; AND ITS LENGTH
	PUSHJ	P,NUMDEC	;CONVERT TO BINARY
	STORE 	T1,,HDRJOB	;STORE IT
	PUSHJ	P,CHKLIN	;DETERMINE THE LINE NUMBER
	STORE	T1,,HDRLIN	; AND STORE IT
	INCR	,HDRCNT		;DONE WITH THE FIRST WORD
	MOVE	T1,FFAPPN	;GET THE PPN WE ASSUME DAEMON RUNS UNDER
	STORE	T1,,HDRPPN	; AND STORE IT
	INCR	,HDRCNT		;DONE WITH THE SECOND WORD
	MOVE	T1,USGLDT	;GET THE POINTER TO THE DATE/TIME ENTRY WAS MADE
	$CALL	DATTIM		;CONVERT IT TO UNIVERSAL DATE/TIME
	SKIPF			;ERROR. LEAVE IT AS ZERO
	STORE	S2,,HDRDTM	;STORE IT
	INCR	,HDRCNT		;DONE WITH THIRD AND LAST WORD OF RESTART ENTRY
	PUSHJ	P,FCTOUT	;OUTPUT THE FACT ENTRY
;	PUSHJ	P,HEADER	;FIND THE NODE # AND APR SERIAL # FOR LATER
				; SPOOLER ENTRIES.  FIRST RECORD HAS ALREADY
				; BEEN READ; HEADER ROUTINE WILL READ THE SECOND.
;	$RETT


;Fall into HEADER routine.
;HEADER - Routine to store default APR serial number and station number
;	for later spooler entries.  This routine is also called by RESTART
;	in case a partial USAGE file is being processed.

HEADER:	PUSHJ	P,FNDNOD	;FIND THE NODE NUMBER
	JUMPT	HEADE1		;DID THE NODE. UUO FAIL?
	MOVX	T1,.GTLOC	;YES. GET CURRENT CENTRAL SITE # AS A DEFAULT
	GETTAB	T1,
	  MOVEI	T1,0		;ERROR.  JUST SETTLE FOR 0 CENTRAL SITE
HEADE1:	MOVEM	T1,SAVNOD	;SAVE THE NODE NUMBER
	PUSHJ	P,USGIN		;READ THE NEXT RECORD
	JUMPF	DONE		;EOF. FINISH UP
	LDB	T1,USGSEQ	;GET THE SEQUENCE NUMBER
	CAIE	T1,"2"		;IS IT THE SECOND RECORD?
	JRST	[$WARN	(Incomplete entry ^D/SAVTYP/)
		JRST	HEADE3]	;FIND THE SYSTEM DEFAULT
	$CALL	.SAVE1
	MOVE	P1,[-6,,0]	;MAXIMUM # OF CPU'S IN A SYSTEM
HEADE2:	HRRZ	T1,P1
	MOVE	T1,USGCPN(T1)	;GET POINTER TO CPU SERIAL NUMBER
	MOVEI	T2,LENCPU	;AND ITS LENGTH
	PUSHJ	P,NUMDEC	;CONVERT IT
	JUMPN	T1,HEADE4	;DID WE FIND ONE?
	AOBJN	P1,HEADE2	;NO. LOOK FOR ANOTHER
HEADE3:	MOVX	T1,%CNSER	;HERE IF NO SERIAL NUMBER CAN BE FOUND
	GETTAB	T1,		;SO GET THIS SYSTEM'S BOOT CPU SERIAL #
	  MOVEI	T1,0		;ERROR. HAVE TO DEFAULT TO ZERO
HEADE4:	MOVEM	T1,SAVAPR	;SAVE FOR LATER SPOOLER ENTRIES
	$RETT



;EOFENT - Routine to make and end-of-file FACT entry.  Called by a routine
;	called "DONE".

EOFENT:	ZERO	,HDRCNT		;INITIALIZE ENTRY COUNT
	MOVEI	T1,777		;ENTRY TYPE
	STORE	T1,,HDRTYP	;STORE IT
	INCR	,HDRCNT		;DONE WITH ENTRY
	PUSHJ	P,FCTOUT	;WRITE IT
	POPJ	P,
;SESSIO - ROUTINE TO CONVERT A SESSION ENTRY OF A USAGE FILE TO A LOGIN AND A
;	LOGOUT ENTRY IN FACT FILE FORMAT.  IF THE USAGE ENTRY IS AN INCOMPLETE
;	SESSION ENTRY A LOGIN AND CHECKPOINT ENTRY IS OUTPUT.  A SESSION ENTRY
;	CONSISTS OF FOUR RECORD.  IF ANY INFORMATION IS MISSING, THE ROUTINE
;	WILL DO A FALSE RETURN.  OTHERWISE, IT WILL DO A FALSE RETURN.
;	IN THE CASE OF A CHECKPOINT ENTRY, THE SIXBIT PROGRAM NAME WILL BE ZERO.

SESSIO:	ZERO	,HDRCNT		;INITIALIZE THE WORD COUNT OF LOGIN ENTRY
	PUSHJ	P,LGIWD1	;WORK ON FIRST WORD OF LOGIN ENTRY (TYPE,JOB,LINE,COUNT)
	PUSHJ	P,LGOWD3	;LOGOUT DATE/TIME IS IN THIS RECORD.
				; SO CONVERT IT NOW AND SAVE FOR LATER

;NOW ALL DATA HAS BEEN OBTAINED FROM THE FIRST USAGE RECORD.  GO READ ANOTHER ONE.

	PUSHJ	P,USGIN		;SET UP TO READ ANOTHER RECORD
	JUMPF	[$WARN	(Incomplete SESSION entry -- record 2 is missing)
		JRST	DONE]
	LDB	T1,USGSEQ	;GET THE RECORD SEQUENCE #
	CAIE	T1,"2"		;IS THIS THE SECOND RECORD?
	$RETF			;NO. GIVE A FALSE RETURN TO INDICATE ERROR
	PUSHJ	P,LGIWD3	;WORK ON WORD THREE OF THE LOGIN ENTRY (DATE/TIME)
	PUSHJ	P,LGOWD4	;RUNTIME IS IN THIS RECORD. SO GET IT AND
				; SAVE IT FOR LATER (WORD 4, LOGOUT/CHKPNT)

;NOW ALL DATA HAS BEEN OBTAINED FROM THE SECOND USAGE RECORD.  GO READ THE THIRD
;ONE TO GET MORE DATA.

	PUSHJ	P,USGIN		;GO READ ANOTHER RECORD
	LDB	T1,USGSEQ	;GET THE RECORD SEQUENCE NUMBER
	CAIE	T1,"3"		;IS THIS THE THIRD RECORD?
	$RETF			;NO. GIVE A FALSE RETURN
	PUSHJ	P,LGOWD5	;GET THE CORE-TIME INTEGRAL AND SAVE IT FOR
				; LATER (WORD 5, LOGOUT/CHKPNT)
	PUSHJ	P,LGOWD6	;GET DISK READS AND SAVE IT FOR LATER (WORD 6,
				; LOGOUT/CHKPNT)
	PUSHJ	P,LGOWD7	;GET DISK WRITES AND SAVE IT FOR LATER (WORD 7,
				; LOGOUT/CHKPNT)

;NOW ALL DATA HAS BEEN OBTAINED FROM THE THIRD USAGE RECORD.
;GO READ THE FOURTH TO GET THE PROJECT-PROGRAMMER NUMBER

	PUSHJ	P,USGIN		;GO READ ANOTHER RECORD
	LDB	T1,USGSEQ	;GET THE RECORD SEQUENCE #
	CAIE	T1,"4"		;IS THIS THE FOURTH RECORD?
	$RETF			;NO, GIVE A FALSE RETURN
	PUSHJ	P,LGIWD2	;WORK ON WORD 2 OF THE LOGIN ENTRY (PPN)
	PUSHJ	P,FCTOUT	;NOW OUTPUT THE LOGIN ENTRY

;NOW MAKE A LOGOUT OR CHECKPOINT ENTRY. THE THREE DIFFERENCES OF THESE
;	ENTRIES ARE: 1)ENTRY TYPE, 2) CHECKPOINT ENTRY HAS 0 FOR
;	THE SIXBIT NAME OF PROGRAM, AND 3) CHECKPOINT ENTRY IS ONE WORD LONGER

	PUSHJ	P,LGOWD1	;WORK ON WORD 1 OF THE LOGOUT/CHECKPOINT ENTRY
	MOVE	T1,SAVPPN	;WORK ON WORD 2 OF THE LOGOUT/CHKPNT ENTRY
	STORE	T1,,HDRPPN	;PPN HAS ALREADY BEEN FOUND
	INCR	,HDRCNT		;DONE WITH WORD 2
	MOVE	T1,SAVLDT	;WORK ON WORD 3
	STORE	T1,,HDRDTM	;DATE/TIME HAS ALREADY BEEN FOUND
	INCR	,HDRCNT		;DONE WITH WORD 3
	MOVE	T1,SAVRUN	;WORK ON WORD 4
	STORE	T1,,LGORUN	;RUNTIME HAS ALREADY BEEN FOUND
	INCR	,HDRCNT		;DONE WITH WORD 4
	MOVE	T1,SAVCTI	;WORK ON WORD 5
	STORE	T1,,LGOCTI	;CORE-TIME INTEGRAL HAS ALREADY BEEN FOUND
	INCR	,HDRCNT		;DONE WITH WORD 5
	MOVE	T1,SAVDRD	;WORK ON WORD 6
	STORE	T1,,LGODRD	;DISK READS HAVE ALREADY BEEN FOUND
	INCR	,HDRCNT		;DONE WITH WORD 6
	MOVE	T1,SAVDWR	;WORK ON WORD 7
	STORE	T1,,LGODWR	;DISK WRITES HAVE ALREADY BEEN FOUND
	INCR	,HDRCNT		;DONE WITH WORD 7
	MOVE	T1,SAVTYP	;GET THE ENTRY TYPE
	CAIE	T1,3		;IS AN INCOMPLETE SESSION ENTRY?
	JRST	SESSI1		;NO. OUTPUT THE LOGOUT ENTRY
	MOVEI	T1,0		;YES. FAKE A CHECKPOINT ENTRY.  WORK ON WORD 8
	STORE	T1,,CHKPGM	;PUT IN ZERO WORD FOR SIXBIT PROGRAM NAME
	INCR	,HDRCNT		;CHKPNT ENTRY IS ONE WORD LONGER.  DONE WITH WORD 8
SESSI1:	PUSHJ	P,FCTOUT	;OUTPUT THE ENTRY
	$RETT			;DONE WITH THIS SESSION ENTRY
;LGIWD1 - ROUTINE TO MAKE THE FIRST WORD OF A LOGIN ENTRY
;	THE ENTRY HEADER RECORD MUST BE IN USGBLK

LGIWD1:	MOVEI	T1,101		;LOGIN TYPE CODE
	STORE	T1,,HDRTYP	;STORE IT
	MOVE	T1,USGJOB	;GET POINTER TO JOB #
	MOVEI	T2,LENJOB	; AND ITS LENGTH
	PUSHJ	P,NUMDEC	;CONVERT
	STORE	T1,,HDRJOB	;STORE IT
	MOVEM	T1,SAVJOB	;ALSO SAVE IT FOR THE LOGOUT/CHKPNT ENTRY
	PUSHJ	P,CHKLIN	;DETERMINE THE LINE NUMBER
	STORE	T1,,HDRLIN	;STORE IT
	MOVEM	T1,SAVLIN	;ALSO SAVE IT FOR THE LOGOUT/CHKPNT ENTRY
	INCR	,HDRCNT		;DONE WITH FIRST WORD
	$RETT


;LGIWD2 - ROUTINE TO MAKE WORD 2 OF A LOGIN ENTRY, A PROJECT-PROGRAMMER NUMBER

LGIWD2:	MOVE	T1,USGPRJ	;GET THE PROJECT NUMBER
	MOVEI	T2,LENPRJ	; AND ITS LENGTH
	PUSHJ	P,NUMOCT	;CONVERT IT
	STORE	T1,,HDRPRJ	;STORE IT
	MOVE	T1,USGPRG	;GET POINTER TO PROGRAMMER NUMBER
	MOVEI	T2,LENPRG	; AND ITS LENGTH
	PUSHJ	P,NUMOCT	;CONVERT IT
	STORE	T1,,HDRPOG	;STORE IT
	LOAD	T1,,HDRPPN	;GET THE WHOLE PPN
	MOVEM	T1,SAVPPN	;SAVE FOR LOGOUT/CHKPNT ENTRY
	INCR	,HDRCNT		;DONE WITH ANOTHER WORD
	$RETT			;DONE WITH ANOTHER WORD


;LGIWD3 - ROUTINE TO MAKE WORD 3 OF THE LOGIN ENTRY.  THE DATE/TIME IS
;	FOUND IN THE SECOND USAGE RECORD OF A SESSION ENTRY.

LGIWD3:	MOVE	T1,USGBDT	;GET POINTER OF LOGIN DATE/TIME
	$CALL	DATTIM		;CONVERT
	SKIPF			;ERROR. LEAVE DATE/TIME AS ZERO
	STORE	S2,,HDRDTM	;STORE IT IN FACT FILE BLOCK
	INCR	,HDRCNT		;DONE WITH WORD 3
	$RETT


;LGOWD1 - ROUTINE TO MAKE WORD 1 OF A LOGOUT/CHECKPOINT ENTRY. IT
;	CONTAINS THE ENTRY TYPE, JOB #, LINE #, AND WORD COUNT

LGOWD1:	MOVE	T1,SAVTYP	;GET THE ENTRY TYPE
	CAIE	T1,2		;IS THIS A COMPLETE SESSION?
	SKIPA	T1,[201]	;NO. HAVE TO MAKE A CHECKPOINT ENTRY
	MOVEI	T1,141		;YES. HAVE TO MAKE A LOGOUT ENTRY
	STORE	T1,,HDRTYP	;STORE IT
	MOVE	T1,SAVJOB	;GET THE JOB #
	STORE	T1,,HDRJOB	;STORE IT
	MOVE	T1,SAVLIN	;GET THE LINE #
	STORE	T1,,HDRLIN	;STORE IT
	INCR	,HDRCNT		;DONE WITH FIRST WORD
	$RETT


;LGOWD3 - ROUTINE TO MAKE LOGOUT/CHKPNT WORD 3. THE LOGOUT DATE/TIME IS IN RECORD 1
;	OF THE USAGE FILE. HENCE IT WILL BE CONVERTED HERE BUT SAVED
;	IN SAVLDT UNTIL THE LOGOUT OR CHECKPOINT ENTRY IS MADE.

LGOWD3:	MOVE	T1,USGLDT	;GET LOGOUT DATE/TIME POINTER
	$CALL	DATTIM		;CONVERT
	SKIPT
	MOVEI	S2,0		;ERROR. MAKE IT ZERO
	MOVEM	S2,SAVLDT	;SAVE IT FOR LATER
	$RETT


;LGOWD4 - ROUTINE TO MAKE WORD 4 OF LOGOUT/CHKPNT ENTRY, THE RUNTIME.

LGOWD4:	MOVE	T1,USGRUN	;GET POINTER TO RUNTIME
	MOVEI	T2,LENRUN	;AND ITS LENGTH
	PUSHJ	P,NUMDEC	;CONVERT IT
	MOVEM	T1,SAVRUN	;SAVE IT FOR NOW
	$RETT			;AND RETURN



;LGOWD5 - ROUTINE TO MAKE WORD 5 OF A LOGOUT/CHKPNT ENTRY, THE CORE-TIME
;	INTEGRAL IN 100 * KILO-CORE-SECONDS

LGOWD5:	MOVE	T1,USGCTI	;GET POINTER TO CORE-TIME INTEGRAL
	MOVEI	T2,LENCTI	;AND ITS LENGTH
	PUSHJ	P,NUMDEC	;CONVERT IT
	MOVEM	T1,SAVCTI	;SAVE IT FOR LATER
	$RETT


;LGOWD6 - ROUTINE TO MAKE WORD 6 OF A LOGOUT/CHKPNT ENTRY, DISK READS IN BLOCKS

LGOWD6:	MOVE	T1,USGDRD	;GET POINTER TO DISK READS
	MOVEI	T2,LENDRD	;AND ITS LENGTH
	PUSHJ	P,NUMDEC	;CONVERT IT
	MOVEM	T1,SAVDRD	;SAVE IT FOR LATER
	$RETT


;LGOWD7 - ROUTINE TO MAKE WORD 7 OF A LOGOUT/CHKPNT ENTRY, DISK WRITES IN BLOCKS

LGOWD7:	MOVE	T1,USGDWR	;GET POINTER TO DISK WRITES
	MOVEI	T2,LENDWR	;AND ITS LENGTH
	PUSHJ	P,NUMDEC	;CONVERT IT
	MOVEM	T1,SAVDWR	;SAVE IT FOR LATER
	$RETT
;INPSPL - Routine to convert a USAGE input spooler entry to a SPRINT FACT
;	file entry as defined in SPRINT.MAC.
;
;	1.  The station number is the node number of the node name in record
;	    #1.  If the node doesn't  exist at the time this program is being g
;	    run, the node number of the central site (found by routines RESTAR
;	    or HEADER) is put in the FACT entry.
;	2.  The bit that flags whether the batch input request was created or r
;	    not, will always be on...implying that the request was created.
;	3.  The field image of SPRINT (both MPB and GALAXY) outputs centiseconds
;	    as runtime in the FACT file.  This is not according to the FACT file
;	    specification.  If you have changed your SPRINT to output milliseconds,
;	    then patch this routine as follows:
;
;		at INPSP1
;		change the PUSHJ P,INPWD5
;			to a PUSHJ OUTWD5


INPSPL:	ZERO	,HDRCNT		;INITIALIZE WORD COUNT OF FACT ENTRY
	PUSHJ	P,INPWD1	;WORK ON FIRST WORD (TYPE, JOB, LINE, COUNT)
	PUSHJ	P,IOPWD3	;WORK ON THIRD WORD - DATE AND TIME
	PUSHJ	P,IOWD4A	;FOURTH WORD - NODE NAME (STATION NO.)

;Now all data has been obtained from the first USAGE record.  Go read another.

	PUSHJ	P,USGIN
	JUMPF	[$WARN	(Incomplete input spooler entry -- record 2 is missing)
		JRST 	DONE]	;EOF IN USAGE FILE ENCOUNTERED
	LDB	T1,USGSEQ	;GET THE RECORD SEQUENCE #
	CAIE	T1,"2"		;IS IT THE SECOND RECORD?
	$RETF			;NO.
	PUSHJ	P,IOWD4B	;FINISH WORD 4 FROM RECORD 2
	PUSHJ	P,INPWD5	;FIFTH WORD - RUNTIME IN CENTISECONDS
	PUSHJ	P,IOPWD6	;SIXTH WORD - CORE-TIME INTEGRAL
	PUSHJ	P,IOPWD7	;SEVENTH WORD -DISK READS
	PUSHJ	P,IOPWD8	;EIGHTH WORD - DISK WRITES
	PUSHJ	P,IOPWD9	;NINTH WORD - INPUT DEVICE
	PUSHJ	P,IOPW10	;TENTH WORD - SEQUENCE NUMBER
	PUSHJ	P,INPW11	;ELEVENTH WORD - CARDS READ AND REQUEST CREATED

;Now all data has been obtained from the second USAGE record.  Read another one.

	PUSHJ	P,USGIN
	JUMPF	[$WARN	(Incomplete input spooler entry -- record 3 is missing)
		JRST	DONE]	;EOF FOUND
	LDB	T1,USGSEQ	;GET THE RECORD SEQUENCE NUMBER
	CAIE	T1,"3"		;IS IT THE THIRD RECORD?
	$RETF			;NO.
	PUSHJ	P,IOPWD2	;SECOND WORD - PPN OF USER
	PUSHJ	P,FCTOUT	;OUTPUT THE FACT FILE ENTRY
	$RETT			;DONE WITH THIS ENTRY
;OUTSPL - Routine to convert a USAGE output spooler entry to a SPOOL FACT
;	file entry as defined in the FACT file specification.
;
;	1.  The station number is the node number of the node name in record
;	    #1.  If the node doesn't  exist at the time this program is being g
;	    run, the node number of the central site (found by routines RESTAR
;	    or HEADER) is put in the FACT entry.


OUTSPL:	ZERO	,HDRCNT		;INITIALIZE WORD COUNT OF FACT ENTRY
	PUSHJ	P,OUTWD1	;WORK ON FIRST WORD (TYPE, JOB, LINE, COUNT)
	PUSHJ	P,IOPWD3	;WORK ON THIRD WORD - DATE AND TIME
	PUSHJ	P,IOWD4A	;FOURTH WORD - NODE NAME (STATION NO.)

;Now all data has been obtained from the first USAGE record.  Go read another.

	PUSHJ	P,USGIN
	JUMPF	[$WARN	(Incomplete output spooler entry -- record 2 is missing)
		JRST 	DONE]	;EOF IN USAGE FILE ENCOUNTERED
	LDB	T1,USGSEQ	;GET THE RECORD SEQUENCE #
	CAIE	T1,"2"		;IS IT THE SECOND RECORD?
	$RETF			;NO.
	PUSHJ	P,IOWD4B	;FINISH WORD 4 FROM RECORD 2
	PUSHJ	P,OUTWD5	;FIFTH WORD - RUNTIME IN MILLISECONDS
	PUSHJ	P,IOPWD6	;SIXTH WORD - CORE-TIME INTEGRAL
	PUSHJ	P,IOPWD7	;SEVENTH WORD -DISK READS
	PUSHJ	P,IOPWD8	;EIGHTH WORD - DISK WRITES
	PUSHJ	P,IOPWD9	;NINTH WORD - INPUT DEVICE
	PUSHJ	P,IOPW10	;TENTH WORD - SEQUENCE NUMBER
	PUSHJ	P,OUTW11	;ELEVENTH WORD - OUTPUT UNITS GENERATED

;Now all data has been obtained from the second USAGE record.  Read another one.

	PUSHJ	P,USGIN
	JUMPF	[$WARN	(Incomplete output spooler entry -- record 3 is missing)
		JRST	DONE]	;EOF FOUND
	LDB	T1,USGSEQ	;GET THE RECORD SEQUENCE NUMBER
	CAIE	T1,"3"		;IS IT THE THIRD RECORD?
	$RETF			;NO.
	PUSHJ	P,IOPWD2	;SECOND WORD - PPN OF USER
	PUSHJ	P,FCTOUT	;OUTPUT THE FACT FILE ENTRY
	$RETT			;DONE WITH THIS ENTRY
;Routines specific to a particular spooler entry.  All common routines follow.

;INPWD1 - Routine to make word 1 of SPRINT entry.  It contains entry type 231,
;	job number of SPRINT, line number of SPRINT job, and entry word count.

INPWD1:	MOVEI	T1,231		;ENTRY TYPE
	STORE	T1,,HDRTYP	;STORE IT
	MOVE	T1,USGJOB	;GET POINTER TO JOB NUMBER
	MOVEI	T2,LENJOB	;AND ITS LENGTH
	PUSHJ	P,NUMDEC	;CONVERT IT
	STORE 	T1,,HDRJOB	;STORE IT
	PUSHJ	P,CHKLIN	;DETERMINE THE LINE NUMBER
	STORE 	T1,,HDRLIN	;AND STORE IT
	INCR	,HDRCNT		;DONE WITH FIRST WORD
	POPJ	P,



;INPWD5 - Routine to make word 5 of SPRINT spooler entries -- the runtime.  In
;	field image software, SPRINT outputs centiseconds rather than standard
;	milliseconds.

INPWD5:	MOVE	T1,USGIRU	;POINTER TO RUNTIME
	MOVEI	T2,LENRUN	;AND ITS LENGTH
	PUSHJ	P,NUMDEC	;CONVERT IT
	IDIVI	T1,^D10		;CONVERT TO CENTISECONDS
	STORE	T1,,IOSRUN	;STORE IT
	INCR	,HDRCNT		;DONE WITH FIFTH WORD
	POPJ	P,


;INPW11 - Routine to make word 11 of SPRINT entry -- cards read and batch request
;	completed.  The batch request completed flag will always be on.

INPW11:	MOVE	T1,USGICD	;POINTER TO CARDS READ
	MOVEI	T2,LENUNT	;AND ITS LENGTH
	PUSHJ	P,NUMDEC	;CONVERT
	STORE	T1,,IOSUNT	;STORE IT
	MOVEI	T1,-1		;SET THE BIT
	STORE	T1,,INPCOM	;STORE IT
	INCR	,HDRCNT		;DONE WITH LAST WORD
	POPJ	P,



;OUTWD1 - Routine to make word 1 of SPOOL entry.  It contains entry type 251,
;	job number of the output spooler, line number of the output spooler
;	job, and entry word count.

OUTWD1:	MOVEI	T1,251		;ENTRY TYPE
	STORE	T1,,HDRTYP	;STORE IT
	MOVE	T1,USGJOB	;GET POINTER TO JOB NUMBER
	MOVEI	T2,LENJOB	;AND ITS LENGTH
	PUSHJ	P,NUMDEC	;CONVERT IT
	STORE 	T1,,HDRJOB	;STORE IT
	PUSHJ	P,CHKLIN	;DETERMINE THE LINE NUMBER
	STORE 	T1,,HDRLIN	;AND STORE IT
	INCR	,HDRCNT		;DONE WITH FIRST WORD
	POPJ	P,



;OUTWD5 - Routine to make word 5 of output spooler entries -- the runtime.
;	This is according to spec; the units are milliseconds.

OUTWD5:	MOVE	T1,USGIRU	;POINTER TO RUNTIME
	MOVEI	T2,LENRUN	;AND ITS LENGTH
	PUSHJ	P,NUMDEC	;CONVERT IT
	STORE	T1,,IOSRUN	;STORE IT
	INCR	,HDRCNT		;DONE WITH FIFTH WORD
	POPJ	P,



;OUTW11 - Routine to make word 11 of SPOOL entry -- output units generated.

OUTW11:	MOVE	T1,USGICD	;POINTER TO UNITS OUTPUT
	MOVEI	T2,LENUNT	;AND ITS LENGTH
	PUSHJ	P,NUMDEC	;CONVERT
	STORE	T1,,IOSUNT	;STORE IT
	INCR	,HDRCNT		;DONE WITH LAST WORD
	POPJ	P,
;Common routines that output data for input and output spooler entries.



;IOPWD2 - Routine to make word 2 of both spoolers' entries -- the user's PPN.

IOPWD2:	MOVE	T1,USGPRJ	;POINTER TO PROJECT PROGRAMMER NUMBER
	MOVEI	T2,LENPPN	;AND ITS LENGTH
	PUSHJ	P,NUMOCT	;CONVERT IT
	STORE 	T1,,HDRPPN	;STORE IT
	INCR	,HDRCNT		;DONE WITH WORD 2
	POPJ	P,


;IOPWD3 - Routine to make word 3 of both spoolers' entries -- the date and time.

IOPWD3:	MOVE	T1,USGLDT	;POINTER TO DATE/TIME
	$CALL	DATTIM		;CONVERT IT
	SKIPF			;ERROR. LEAVE DATE/TIME AS ZERO
	STORE	S2,,HDRDTM	;STORE IT
	INCR	,HDRCNT		;DONE WITH THIRD WORD
	POPJ	P,


;IOPWD4 - Routine to make word 4 of both spoolers - the queue name, the
;	station number and the APR serial number.  The queue name is the
;	first two characters of the queue name found in the USAGE file.  The
;	station number is found using the node name in the USAGE record #1.
;	If the node doesn't exist, the central site is used as a default; this
;	default is found and saved by the routines HEADER or RESTAR.  These
;	same routines also save the APR serial number.  This serial number is
;	usually CPU0; but, on an SMP system, the serial number is the first
;	non-zero serial number beginning with CPU0.

IOWD4A:	$CALL	FNDNOD		;GET THE STATION NUMBER
	SKIPT
	MOVE	T1,SAVNOD	;ERROR. USE THE DEFAULT
	STORE	T1,,IOSSTA	;STORE IT
	MOVE	T1,SAVAPR	;APR SERIAL NUMBER
	STORE 	T1,,IOSAPR	;STORE IT
	POPJ	P,		;RETURN AFTER SOME OF WORD 4

IOWD4B:	MOVE	T1,USGIQN	;BYTE POINTER TO QUEUE NAME
	MOVEI	T2,LENQNM	;AND ITS LENGTH
	PUSHJ	P,ASCSIX	;CONVERT TO SIXBIT
	STORE 	T4,,IOSQUE	;STORE IT
	INCR	,HDRCNT		;DONE WITH FOURTH WORD
	POPJ	P,



;IOPWD6 - Routine to make word 6 of both spoolers -- the core-time integral
;	in kilocore-seconds*100.

IOPWD6:	MOVE	T1,USGICT	;POINTER TO CORE-TIME INTEGRAL
	MOVEI	T2,LENCTI	;AND ITS LENGTH
	PUSHJ	P,NUMDEC	;CONVERT
	STORE	T1,,IOSCTI	;STORE IT
	INCR	,HDRCNT		;DONE WITH SIXTH WORD
	POPJ	P,



;IOPWD7 - Routine to make word 7 of both spoolers -- disk reads.

IOPWD7:	MOVE	T1,USGIDR	;POINTER TO DISK READS
	MOVEI	T2,LENDRD	;AND ITS LENGTH
	PUSHJ	P,NUMDEC	;CONVERT
	STORE	T1,,IOSDRD	;STORE IT
	INCR	,HDRCNT		;DONE WITH SEVENTH WORD
	POPJ	P,



;IOPWD8	- Routine to make word 8 of both spoolers -- disk writes.

IOPWD8:	MOVE	T1,USGIDW	;POINTER TO DISK WRITES
	MOVEI	T2,LENDWR	;AND ITS LENGTH
	PUSHJ	P,NUMDEC	;CONVERT
	STORE	T1,,IOSDWR	;STORE IT
	INCR	,HDRCNT		;DONE WITH EIGHTH
	POPJ	P,



;IOPWD9 - Routine to make word 9 of both spoolers -- physical device name in
;	SIXBIT.

IOPWD9:	MOVE	T1,USGIDV	;POINTER TO DEVICE NAME
	MOVEI	T2,LENDEV	;AND ITS LENGTH
	PUSHJ	P,ASCSIX	;CONVERT TO SIXBIT
	STORE	T4,,IOSDEV	;STORE IT
	INCR	,HDRCNT		;DONE WITH NINTH WORD
	POPJ	P,


;IOPW10 - Routine to make word 10 of both spoolers -- sequence number.

IOPW10:	MOVE	T1,USGISN	;POINTER TO SEQUENCE NUMBER
	MOVEI	T2,LENSSQ	;AND ITS LENGTH
	PUSHJ	P,NUMDEC	;CONVERT
	STORE	T1,,IOSSEQ	;STORE IT
	INCR	,HDRCNT		;DONE WITH TENTH WORD
	POPJ	P,
;DISKUS - Routine to convert a USAGE disk storage entry to a SPACE FACT
;	file entry.  Differences are as follows:
;
;	1.  The UFD status word is always zero.
;	2.  The reserved quota is always zero.
;	3.  The last word is always 'OUT' in SIXBIT.

DISKUS:	ZERO	,HDRCNT		;INITIALIZE WORD COUNT
	PUSHJ	P,DSKWD1	;WORK ON FIRST WORD (TYPE, JOB, LINE, COUNT)
	PUSHJ	P,DSKWD3	;WORD ON THIRD WORD - DATE AND TIME

;All data has been obtained from the first record.  Read another one.

	PUSHJ	P,USGIN
	JUMPF	[$WARN	(Incomplete disk storage entry -- record 2 is missing)
		JRST	DONE]	;END OF FILE WAS SEEN. GO FINISH UP
	LDB	T1,USGSEQ	;GET THE SEQUENCE #
	CAIE	T1,"2"		;IS IT THE SECOND RECORD?
	$RETF			;NO.
	PUSHJ	P,DSKWD2	;SECOND WORD - DIRECTORY PPN
	PUSHJ	P,DSKWD4	;FOURTH WORD - FILE STRUCTURE NAME IN SIXBIT
	PUSHJ	P,DSKWD5	;FIFTH WORD - UFD STATUS WORD
	PUSHJ	P,DSKWD6	;SIXTH WORD - FCFS QUOTA
	PUSHJ	P,DSKWD7	;SEVENTH WORD - LOGGED OUT QUOTA
	PUSHJ	P,DSKWD8	;EIGHTH WORD - RESERVED QUOTA
	PUSHJ	P,DSKWD9	;NINTH WORD - BLOCKS ALLOCATED
	PUSHJ	P,DSKW10	;TENTH WORD - BLOCKS REMAINING FOR USER'S FCFS
	PUSHJ	P,DSKW11	;ELEVENTH WORD - 'OUT' IN SIXBIT
	PUSHJ	P,FCTOUT	;OUTPUT THE FACT ENTRY
	$RETT			;DONE WITH THIS ENTRY



;DSKWD1 - Routine to make word 1 of a SPACE entry -- entry type which is 161,
;	job number of BACKUP program which made the USAGE entry, its line
;	number and the word count.

DSKWD1:	MOVEI	T1,161		;ENTRY TYPE
	STORE	T1,,HDRTYP	;STORE IT
	MOVE	T1,USGJOB	;POINTER TO JOB NUMBER
	MOVEI	T2,LENJOB	;AND ITS LENGTH
	PUSHJ	P,NUMDEC	;CONVERT IT
	STORE	T1,,HDRJOB	;STORE IT
	PUSHJ	P,CHKLIN	;DETERMINE THE LINE NUMBER
	STORE	T1,,HDRLIN	;AND STORE IT
	INCR	,HDRCNT		;DONE WITH FIRST WORD
	POPJ	P,


;DSKWD2 - Routine to make word 2 of a SPACE FACT file entry -- directory ppn.

DSKWD2:	MOVE	T1,USGDIR	;POINTER TO PPN
	MOVEI	T2,LENPPN	;AND ITS LENGTH
	PUSHJ	P,NUMOCT	;CONVERT IT
	STORE	T1,,HDRPPN	;STORE IT
	INCR	,HDRCNT		;DONE WITH SECOND WORD
	POPJ	P,


;DSKWD3 - Routine to make word 3 of a SPACE FACT file entry -- date and time.

DSKWD3:	MOVE	T1,USGLDT	;POINTER TO DATE/TIME
	$CALL	DATTIM		;CONVERT IT
	SKIPF			;ERROR. LEAVE DATE/TIME AS ZERO
	STORE	S2,,HDRDTM	;STORE IT
	INCR	,HDRCNT		;DONE WITH THIRD WORD
	POPJ	P,


;DSKWD4 - Routine to make word 4 of a SPACE FACT file entry -- the file structure
;	name in SIXBIT.

DSKWD4:	MOVE	T1,USGFSN	;POINTER TO THE FILE STRUCTURE NAME
	MOVEI	T2,LENDEV	;AND ITS LENGTH
	PUSHJ	P,ASCSIX	;CONVERT IT
	STORE	T4,,DSKSTR	;STORE IT
	INCR	,HDRCNT		;DONE WITH FOURTH WORD
	POPJ	P,



;DSKWD5 - Routine to make word 5 of a SPACE FACT file entry -- the UFD
;	status word.  This word is always zero since this information
;	is not found in the USAGE entry.

DSKWD5:	ZERO	,DSKUFD		;ZERO THE WORD
	INCR	,HDRCNT		;DONE WITH FIFTH WORD
	POPJ	P,



;DSKWD6 - Routine to make word 6 of a SPACE FACT file entry -- the FCFS
;	(first come first served) quota.

DSKWD6:	MOVE	T1,USGQTF	;POINTER TO FCFS QUOTA
	MOVEI	T2,LENQTF	;AND ITS LENGTH
	PUSHJ	P,NUMDEC	;CONVERT IT
	STORE	T1,,DSKFCS	;STORE IT
	INCR	,HDRCNT		;DONE WITH SIXTH WORD
	POPJ	P,



;DSKWD7 - Routine to make word 7 of a SPACE FACT file entry -- the logged-out
;	quota.

DSKWD7:	MOVE	T1,USGQTO	;POINTER TO THE LOGGED-OUT QUOTA
	MOVEI	T2,LENQTO	;AND ITS LENGTH
	PUSHJ	P,NUMDEC	;CONVERT IT
	STORE	T1,,DSKLGO	;STORE IT
	INCR	,HDRCNT		;DONE WITH THE SEVENTH WORD
	POPJ	P,


;DSKWD8 - Routine to make word 8 of a SPACE FACT file entry -- the reserved 
;	quota.  This will always be zero since it isn't recorded in the USAGE
;	entry.

DSKWD8:	ZERO	,DSKRSV		;ZERO THE WORD
	INCR	,HDRCNT		;DONE WITH THE EIGHTH WORD
	POPJ	P,


;DSKWD9 - Routine to make word 9 of a SPACE FACT file entry -- blocks allocated.

DSKWD9:	MOVE	T1,USGALL	;POINTER TO BLOCKS ALLOCATED
	MOVEI	T2,LENALC	;AND ITS LENGTH
	PUSHJ	P,NUMDEC	;CONVERT IT
	STORE	T1,,DSKALC	;STORE IT
	INCR	,HDRCNT		;DONE WITH WORD 9
	POPJ	P,


;DSKW10 - Routine to make word 10 of a SPACE FACT file entry -- blocks remaining
;	for the user's FCFS.

DSKW10:	MOVE	T1,USGADU	;POINTER TO BLOCKS ACTUALLY USED
	MOVEI	T2,LENADU	;AND ITS LENGTH
	PUSHJ	P,NUMDEC	;CONVERT IT
	LOAD	T2,,DSKFCS	;GET FCFS QUOTA
	SUB	T2,T1		;BLOCKS REMAINING FOR USER'S FCFS
	STORE	T2,,DSKREM	;STORE IT
	INCR	,HDRCNT		;DONE WITH TENTH WORD
	POPJ	P,


;DSKW11 - Routine to make word 11 of a SPACE FACT file entry -- always the
;	SIXBIT word 'OUT'.

DSKW11:	MOVSI	T1,'OUT'	;SIXBIT OUT LEFT-JUSTIFIED
	STORE	T1,,DSKOUT	;STORE IT
	INCR	,HDRCNT		;DONE WITH WORD 11
	POPJ	P,
MOUNT:
;MNTSTR, MNTMAG, and MNTDEC - Routines to make mount and dismount FACT file
;	entries for file structures, magtapes, and DECtapes.  The routines
;	called MNTWD? are commonly used for all three USAGE entries to make
;	mount FACT file entries.  DSMWD? are commonly used to make dismount
;	FACT entries.  STRWD? routines are used for file structures, MTAWD?
;	routine are used for magtapes, and DTAWD? routines are used for
;	DECtape dependent information.  Since these FACT entries were
;	designed to look like spooler FACT entries, the DEFSTR's defined
;	for spooler and SPRINT FACT file entries will be used to make
;	mount and dismount FACT file entries.  Known differences common to
;	all device FACT entries follows.  If a difference specific to the
;	device exists, it will be documented at the entry point (MNTSTR,
;	MNTMAG, or MNTDEC).
;
;	1.  All FACT file entries will appear to have been made by UMOUNT program
;	    since runtime, core-time integral and disk reads/writes used by the
;	    MOUNT program are not recorded in the corresponding USAGE entry.
;	    Therefore, the fourth word of the entry will have SIXBIT 'UM' for
;	    mounts and SIXBIT 'UD' for dismounts.
;	2.  Because of difference #1, the runtime, core-time integral, disk
;	    reads, and disk writes (words #5, 6, 7, and 8) will always be zero.
;	3.  For each USAGE entry read (entry types "0011" thru "0013"), two
;	    FACT entries will be written--one with 'UM' in the fourth word
;	    and the other with 'UD' in the fourth word.  In the 'UM' FACT
;	    file entry the date and time will be the serviced date and time
;	    of the request found in the second record of the USAGE entry.  In
;	    the 'UD' FACT file entry the date and time will be the date and
;	    time found in record #1 of the USAGE  entry.
;	4.  In the eleventh word (flags,,clock), as in FACT entries made by
;	    UMOUNT, the LH will always contain 1 and the RH will always be
;	    zero.
;MNTSTR - Routine to make two entries whenever a user file structure USAGE
;	entry is found.  The two entries will simulate a mount and a dismount
;	entry.  For differences see comments at label MOUNT:.

MNTSTR:	ZERO	,HDRCNT		;INITIALIZE THE WORD COUNT FOR MOUNT ENTRY
	PUSHJ	P,MNTWD1	;WORK ON FIRST WORD (TYPE, JOB #, LINE, COUNT)
	PUSHJ	P,DSMWD3	;DISMOUNT DATE/TIME IS IN THIS RECORD SO
				; CONVERT IT NOW AND SAVE FOR LATER
	PUSHJ	P,MNTWD4	;FOURTH WORD - SERIAL #,'UM',,STATION #

;NOW ALL DATA HAS BEEN OBTAINED FROM THE FIRST RECORD.  READ THE SECOND.

	$CALL	USGIN
	JUMPF	[$WARN	(Incomplete file struture USAGE entry -- record 2 is missing)
		JRST	DONE]	;EOF FOUND.  GO FINISH UP.
	LDB	T1,USGSEQ	;GET THE RECORD SEQUENCE #
	CAIE	T1,"2"		;IS IT THE SECOND RECORD?
	$RETF			;NO.
	PUSHJ	P,STRWD3	;THIRD WORD - DATE/TIME
	PUSHJ	P,MNTWD5	;FIFTH WORD - RUNTIME
	PUSHJ	P,MNTWD6	;SIXTH WORD - CORE-TIME INTEGRAL
	PUSHJ	P,MNTWD7	;SEVENTH WORD - DISK READS
	PUSHJ	P,MNTWD8	;EIGHTH WORD - DISK WRITES
	PUSHJ	P,STRWD9	;NINTH WORD - FILE STRUCTURE NAME
	PUSHJ	P,MNTW10	;TENTH WORD - DEFINED AS ZERO
	PUSHJ	P,MNTW11	;ELEVENTH WORD - FLAGS,,CLOCK -- DEFINED AS 1,,0

;All information has been taken form the second record.  Read the third to get
;	the project-programmer number.

	$CALL	USGIN
	JUMPF	[$WARN	(Incomplete file structure entry -- record 3 is missing)
		JRST	DONE]	;EOF READ.  GO FINISH UP.
	LDB	T1,USGSEQ	;GET THE RECORD SEQUENCE #
	CAIE	T1,"3"		;IS IT THE THIRD RECORD?
	$RETF			;NO.
	PUSHJ	P,MNTWD2	;SECOND WORD - PROJECT-PROGRAMMER NUMBER
	PUSHJ	P,FCTOUT	;WRITE THE MOUNT FACT ENTRY
MNTST1:	ZERO	,HDRCNT		;INITIALIZE WORD COUNT FOR DISMOUNT ENTRY
	PUSHJ	P,DSMWD1	;NOW MAKE THE DISMOUNT FACT ENTRY -- WORD 1
	MOVE	T1,SAVPPN	;WORD 2 - PROJECT-PROGRAMMER NUMBER
	STORE	T1,,HDRPPN	;ALREADY FOUND WITH MNTWD2 ROUTINE
	INCR	,HDRCNT		;DONE WITH WORD 2
	MOVE	T1,SAVLDT	;WORD 3 - DATE/TIME
	STORE	T1,,HDRDTM	;HAD ALREADY BEEN FOUND
	INCR	,HDRCNT		;DONE WITH WORD 3
	PUSHJ	P,DSMWD4	;FOURTH WORD -- SERIAL #, 'UD',,STATION #
	PUSHJ	P,MNTWD5	;FIFTH WORD -- RUNTIME
	PUSHJ	P,MNTWD6	;SIXTH WORD -- CORE-TIME INTEGRAL
	PUSHJ	P,MNTWD7	;SEVENTH WORD -- DISK READS
	PUSHJ	P,MNTWD8	;EIGHTH WORD -- DISK WRITES
	MOVE	T1,SAVDEV	;NINTH WORD -- DEVICE NAME
	STORE	T1,,IOSDEV	;ALREADY FOUND WITH STRWD9 ROUTINE
	INCR	,HDRCNT		;DONE WITH WORD 9
	PUSHJ	P,MNTW10	;TENTH WORD - DEFINED AS ZERO
	PUSHJ	P,MNTW11	;ELEVENTH WORD - DEFINED AS 1,,0
	PUSHJ	P,FCTOUT	;WRITE THE DISMOUNT ENTRY
	$RETT
;MNTMAG - Routine to make two entries whenever a user magtape mount USAGE
;	entry is found.  The two entries will simulate a mount and a dismount
;	entry.  For differences see comments at label MOUNT:.
;
;	1.  An additional difference is that the device is not included in
;	    this entry.

MNTMAG:	ZERO	,HDRCNT		;INITIALIZE THE WORD COUNT FOR THE MOUNT ENTRY
	PUSHJ	P,MNTWD1	;WORK ON FIRST WORD (TYPE, JOB #, LINE, COUNT)
	PUSHJ	P,DSMWD3	;DISMOUNT DATE/TIME IS IN THIS RECORD SO CONVERT
				; IT NOW AND SAVE FOR LATER
	PUSHJ	P,MNTWD4	;FOURTH WORD - SERIAL #,'UM',,STATION #

;NOW ALL DATA HAS BEEN OBTAINED FROM THE FIRST RECORD.  READ ANOTHER.

	$CALL	USGIN
	JUMPF	[$WARN	(Incomplete magtape mount USAGE entry -- record 2 is missing)
		JRST	DONE]	;EOF FOUND.  GO FINISH UP.
	LDB	T1,USGSEQ	;GET THE RECORD SEQUENCE #
	CAIE	T1,"2"		;IS IT THE SECOND RECORD?
	$RETF			;NO.
	PUSHJ	P,MTAWD3	;THIRD WORD - DATE/TIME
	PUSHJ	P,MNTWD5	;FIFTH WORD - RUNTIME
	PUSHJ	P,MNTWD6	;SIXTH WORD - CORE-TIME INTEGRAL
	PUSHJ	P,MNTWD7	;SEVENTH WORD - DISK READS
	PUSHJ	P,MNTWD8	;EIGHTH WORD - DISK WRITES
	PUSHJ	P,MTAWD9	;NINTH WORD - FILE STRUCTURE NAME
	PUSHJ	P,MNTW10	;TENTH WORD - DEFINED AS ZERO
	PUSHJ	P,MNTW11	;ELEVENTH WORD - FLAGS,,CLOCK -- DEFINED AS 1,,0

;All information has been taken form the second record.  Read the third to get
;	the project-programmer number.

	$CALL	USGIN
	JUMPF	[$WARN	(Incomplete magtape mount entry -- record 3 is missing)
		JRST	DONE]	;EOF READ.  GO FINISH UP.
	LDB	T1,USGSEQ	;GET THE RECORD SEQUENCE #
	CAIE	T1,"3"		;IS IT THE THIRD RECORD?
	$RETF			;NO.
	PUSHJ	P,MNTWD2	;SECOND WORD - PROJECT-PROGRAMMER NUMBER
	PUSHJ	P,FCTOUT	;WRITE THE MOUNT FACT ENTRY
MNTMA1:	ZERO	,HDRCNT		;INITIALIZE WORD COUNT OF DISMOUNT ENTRY
	PUSHJ	P,DSMWD1	;NOW MAKE THE DISMOUNT FACT ENTRY -- WORD 1
	MOVE	T1,SAVPPN	;WORD 2 - PROJECT-PROGRAMMER NUMBER
	STORE	T1,,HDRPPN	;ALREADY FOUND WITH MNTWD2 ROUTINE
	INCR	,HDRCNT		;DONE WITH WORD 2
	MOVE	T1,SAVLDT	;WORD 3 - DATE/TIME
	STORE	T1,,HDRDTM	;HAD ALREADY BEEN FOUND
	INCR	,HDRCNT		;DONE WITH WORD 3
	PUSHJ	P,DSMWD4	;FOURTH WORD -- SERIAL #, 'UD',,STATION #
	PUSHJ	P,MNTWD5	;FIFTH WORD -- RUNTIME
	PUSHJ	P,MNTWD6	;SIXTH WORD -- CORE-TIME INTEGRAL
	PUSHJ	P,MNTWD7	;SEVENTH WORD -- DISK READS
	PUSHJ	P,MNTWD8	;EIGHTH WORD -- DISK WRITES
	MOVE	T1,SAVDEV	;NINTH WORD -- DEVICE NAME
	STORE	T1,,IOSDEV	;ALREADY FOUND WITH MTAWD9 ROUTINE
	INCR	,HDRCNT		;DONE WITH WORD 9
	PUSHJ	P,MNTW10	;TENTH WORD - DEFINED AS ZERO
	PUSHJ	P,MNTW11	;ELEVENTH WORD - DEFINED AS 1,,0
	PUSHJ	P,FCTOUT	;WRITE THE DISMOUNT ENTRY
	$RETT
;MNTDEC - Routine to make two entries whenever a user DECtape mount USAGE
;	entry is found.  The two entries will simulate a mount and a dismount
;	entry.  For differences see comments at label MOUNT:.
;
;	1.  An additional difference is that the device is not included in
;	    this entry.

MNTDEC:	ZERO	,HDRCNT		;INITIALIZE THE WORD COUNT FOR THE MOUNT ENTRY
	PUSHJ	P,MNTWD1	;WORK ON FIRST WORD (TYPE, JOB #, LINE, COUNT)
	PUSHJ	P,DSMWD3	;DISMOUNT DATE/TIME IS IN THIS RECORD SO CONVERT
				; IT NOW AND SAVE FOR LATER
	PUSHJ	P,MNTWD4	;FOURTH WORD - SERIAL #,'UM',,STATION #

;NOW ALL DATA HAS BEEN OBTAINED FROM THE FIRST RECORD.  READ ANOTHER.

	$CALL	USGIN
	JUMPF	[$WARN	(Incomplete DECtape mount USAGE entry -- record 2 is missing)
		JRST	DONE]	;EOF FOUND.  GO FINISH UP.
	LDB	T1,USGSEQ	;GET THE RECORD SEQUENCE #
	CAIE	T1,"2"		;IS IT THE SECOND RECORD?
	$RETF			;NO.
	PUSHJ	P,DTAWD3	;THIRD WORD - DATE/TIME
	PUSHJ	P,MNTWD5	;FIFTH WORD - RUNTIME
	PUSHJ	P,MNTWD6	;SIXTH WORD - CORE-TIME INTEGRAL
	PUSHJ	P,MNTWD7	;SEVENTH WORD - DISK READS
	PUSHJ	P,MNTWD8	;EIGHTH WORD - DISK WRITES
	PUSHJ	P,DTAWD9	;NINTH WORD - FILE STRUCTURE NAME
	PUSHJ	P,MNTW10	;TENTH WORD - DEFINED AS ZERO
	PUSHJ	P,MNTW11	;ELEVENTH WORD - FLAGS,,CLOCK -- DEFINED AS 1,,0

;All information has been taken form the second record.  Read the third to get
;	the project-programmer number.

	$CALL	USGIN
	JUMPF	[$WARN	(Incomplete DECtape mount entry -- record 3 is missing)
		JRST	DONE]	;EOF READ.  GO FINISH UP.
	LDB	T1,USGSEQ	;GET THE RECORD SEQUENCE #
	CAIE	T1,"3"		;IS IT THE THIRD RECORD?
	$RETF			;NO.
	PUSHJ	P,MNTWD2	;SECOND WORD - PROJECT-PROGRAMMER NUMBER
	PUSHJ	P,FCTOUT	;WRITE THE MOUNT FACT ENTRY
MNTDE1:	ZERO	,HDRCNT		;INITIALIZE WORD COUNT OF DISMOUNT ENTRY
	PUSHJ	P,DSMWD1	;NOW MAKE THE DISMOUNT FACT ENTRY -- WORD 1
	MOVE	T1,SAVPPN	;WORD 2 - PROJECT-PROGRAMMER NUMBER
	STORE	T1,,HDRPPN	;ALREADY FOUND WITH MNTWD2 ROUTINE
	INCR	,HDRCNT		;DONE WITH WORD 2
	MOVE	T1,SAVLDT	;WORD 3 - DATE/TIME
	STORE	T1,,HDRDTM	;HAD ALREADY BEEN FOUND
	INCR	,HDRCNT		;DONE WITH WORD 3
	PUSHJ	P,DSMWD4	;FOURTH WORD -- SERIAL #, 'UD',,STATION #
	PUSHJ	P,MNTWD5	;FIFTH WORD -- RUNTIME
	PUSHJ	P,MNTWD6	;SIXTH WORD -- CORE-TIME INTEGRAL
	PUSHJ	P,MNTWD7	;SEVENTH WORD -- DISK READS
	PUSHJ	P,MNTWD8	;EIGHTH WORD -- DISK WRITES
	MOVE	T1,SAVDEV	;NINTH WORD -- DEVICE NAME
	STORE	T1,,IOSDEV	;ALREADY FOUND WITH DTAWD9 ROUTINE
	INCR	,HDRCNT		;DONE WITH WORD 9
	PUSHJ	P,MNTW10	;TENTH WORD - DEFINED AS ZERO
	PUSHJ	P,MNTW11	;ELEVENTH WORD - DEFINED AS 1,,0
	PUSHJ	P,FCTOUT	;WRITE THE DISMOUNT ENTRY
	$RETT
;MNTWD1 - Routine to make first word of any mount FACT entry - entry type, job
;	number, line number and word count.  The first three items will be saved
;	for the corresponding dismount FACT entry (see DSMWD1).

MNTWD1:	MOVEI	T1,271		;ENTRY TYPE
	STORE	T1,,HDRTYP	;STORE IT
	MOVE	T1,USGJOB	;POINTER TO JOB NUMBER
	MOVEI	T2,LENJOB	;AND ITS LENGTH
	PUSHJ	P,NUMDEC	;CONVERT IT
	STORE	T1,,HDRJOB	;STORE IT
	MOVEM	T1,SAVJOB	;SAVE FOR THE DISMOUNT ENTRY
	PUSHJ	P,CHKLIN	;DETERMINE THE LINE NUMBER
	STORE	T1,,HDRLIN	;STORE IT
	MOVEM	T1,SAVLIN	;SAVE FOR THE DISMOUNT ENTRY
	INCR	,HDRCNT		;DONE WITH WORD 1
	POPJ	P,


;DSMWD1 - Routine to make word 1 of a dismount FACT entry - entry type, job
;	number, line number and word count.  The job number and line number
;	have been saved by the MNTWD1 routine.

DSMWD1:	MOVEI	T1,271		;ENTRY TYPE
	STORE	T1,,HDRTYP	;STORE IT
	MOVE	T1,SAVJOB	;GET THE JOB NUMBER
	STORE 	T1,,HDRJOB	;STORE IT
	MOVE	T1,SAVLIN	;GET THE LINE NUMBER
	STORE	T1,,HDRLIN	;STORE IT
	INCR	,HDRCNT		;DONE WITH WORD 1
	POPJ	P,

;MNTWD2 - Routine to make word 2 of any mount FACT entry - the user's project
;	programmer number.

MNTWD2:	MOVE	T1,USGPRJ	;POINTER TO PROJECT PROGRAMMER NUMBER
	MOVEI	T2,LENPPN	;AND ITS LENGTH
	PUSHJ	P,NUMOCT	;CONVERT IT
	STORE	T1,,HDRPPN	;STORE IT
	MOVEM	T1,SAVPPN	;SAVE IN CASE OF A DISMOUNT ENTRY
	INCR	,HDRCNT		;DONE WITH WORD 2
	POPJ	P,


;STRWD3 - Routine to make word 3 of a file structure mount FACT entry - the
;	date/time.  This datum is the serviced date/time found in the USAGE
;	entry.

STRWD3:	MOVE	T1,USGFDT	;POINTER TO SERVICED DATE/TIME
	$CALL	DATTIM		;CONVERT IT
	SKIPF			;ERROR. LEAVE THE WORD 0
	STORE	S2,,HDRDTM	;STORE IT
	INCR	,HDRCNT		;DONE WITH THE THIRD WORD
	POPJ	P,


;MTAWD3 and DTAWD3 - Routine to make word 3 of magtape and DECtape mount entries
;	the date/time.  This item (serviced date/time) just happens to be in
;	 the same character position of both USAGE entries.

MTAWD3:
DTAWD3:	MOVE	T1,USGMDT	;POINTER TO THE MOUNT DATE/TIME
	$CALL	DATTIM		;CONVERT IT
	SKIPF			;ERROR. LEAVE IT AS ZERO
	STORE	S2,,HDRDTM	;STORE IT
	INCR	,HDRCNT		;DONE WITH THE THIRD WORD
	POPJ	P,


;DSMWD3 - Routine to make word 3 of a dismount FACT entry - the date/time.
;	 This item is found in the first record of the USAGE entry.  Since
;	the dismount entry if made after the mount entry, the date/time needs
;	to be stored.

DSMWD3:	MOVE	T1,USGLDT	;POINTER TO DATE/TIME
	$CALL	DATTIM		;CONVERT IT
	SKIPT
	MOVEI	S2,0		;ERROR. JUST STORE A ZERO
	MOVEM	S2,SAVLDT	;SAVE IT FOR LATER
	POPJ	P,


;MNTWD4 - Routine to make word 4 of a mount FACT entry - the APR serial
;	number, SIXBIT 'UM', and the station number.  The serial number and
;	station number is found with the same method as with spooler FACT
;	entries.  These two items are also stored away for the dismount entry.

MNTWD4:	MOVEI	T1,'UM'		;INDICATE A UMOUNT MOUNT
	STORE	T1,,IOSQUE	;STORE IT
	$CALL	FNDNOD		;GET THE STATION NUMBER
	SKIPT
	MOVE	T1,SAVNOD	;ERROR. USE THE DEFAULT
	STORE	T1,,IOSSTA	;STORE IT FOR MOUNT ENTRY
	MOVEM	T1,DSMNOD	;SAVE IT FOR THE DISMOUNT ENTRY
	MOVE	T1,SAVAPR	;GET THE CPU SERIAL NUMBER
	STORE	T1,,IOSAPR	;STORE IT
	INCR	,HDRCNT		;DONE WITH FOURTH WORD
	POPJ	P,


;DSMWD4 - Routine to make word 4 of a dismount FACT entry - the APR serial
;	number, SIXBIT 'UD', and the station number.  The serial number and
;	station number is found with the same method as with spooler FACT
;	entries.  These two items were stored away by the routine MNTWD4.

DSMWD4:	MOVEI	T1,'UD'		;INDICATE A UMOUNT DISMOUNT
	STORE	T1,,IOSQUE	;STORE IT
	MOVE	T1,DSMNOD	;NODE USED IN THE CORRESPONDING MOUNT ENTRY
	STORE	T1,,IOSSTA	;STORE IT
	MOVE	T1,SAVAPR	;GET THE CPU SERIAL NUMBER
	STORE	T1,,IOSAPR	;STORE IT
	INCR	,HDRCNT		;DONE WITH FOURTH WORD
	POPJ	P,


;MNTWD5 - Routine to make word 5 of a mount and dismount entry - runtime.
;	This is zero because the runtime of the program doing mounts/dismounts
;	is not included in the USAGE entry.

MNTWD5:	ZERO	,IOSRUN		;ZERO WORD 5
	INCR	,HDRCNT		;DONE WITH FIFTH WORD
	POPJ	P,


;MNTWD6 - Routine to make word 6 of a mount and dismount entry - core-time integral.
;	This is zero because the CTI of the program doing mounts/dismounts
;	is not included in the USAGE entry.

MNTWD6:	ZERO	,IOSCTI		;ZERO WORD 6
	INCR	,HDRCNT		;DONE WITH SIXTH WORD
	POPJ	P,


;MNTWD7 - Routine to make word 7 of a mount and dismount entry - disk reads.
;	This is zero because the disk reads of the program doing mounts/dismounts
;	is not included in the USAGE entry.

MNTWD7:	ZERO	,IOSDRD		;ZERO WORD 7
	INCR	,HDRCNT		;DONE WITH SEVENTH WORD
	POPJ	P,


;MNTWD8 - Routine to make word 8 of a mount and dismount entry - disk writes.
;	This is zero because the disk writes of the program doing mounts/dismounts
;	is not included in the USAGE entry.

MNTWD8:	ZERO	,IOSDWR		;ZERO WORD 8
	INCR	,HDRCNT		;DONE WITH EIGHTTH WORD
	POPJ	P,


;STRWD9 - Routine to make word 9 of a file structure mount FACT entry - the
;	file structure name.

STRWD9:	MOVE	T1,USGSTR	;POINTER TO THE DEVICE NAME
	MOVEI	T2,LENSTR	;AND ITS LENGTH
	PUSHJ	P,ASCSIX	;CONVERT IT
	STORE	T4,,IOSDEV	;STORE IT
	MOVEM	T4,SAVDEV	;SAVE IT FOR THE DISMOUNT ENTRY
	INCR	,HDRCNT		;DONE WITH NINTH WORD
	POPJ	P,


;MNTWD9 - Routine to make word 9 of magtape and DECtape mount FACT entries -
;	the device name.

DTAWD9:	SKIPA	T1,USGDDV	;HERE FOR DECTAPE RECORD
MTAWD9:	MOVE	T1,USGMDV	;AND HERE FOR MAGTAPE
	MOVEI	T2,LENDEV	;LENGTH OF THE FIELD
	PUSHJ	P,ASCSIX	;CONVERT TO SIXBIT
	STORE	T4,,IOSDEV	;STORE IN RECORD
	MOVEM	T4,SAVDEV	;AND SAVE FOR DISMOUNT FACT ENTRY
	INCR	,HDRCNT		;DONE WITH NINTH WORD
	POPJ	P,
	


;MNTW10 - Routine to make word 10 of mount and dismount FACT entries which
;	is defined to always be zero.

MNTW10:	ZERO	,IOSSEQ		;ZERO THE WORD
	INCR	,HDRCNT		;DONE WITH WORD 10
	POPJ	P,


;MNTW11 - Routine to make word 11 of a mount and a dismount FACT entry which
;	is always defined to be 1 in the left half and zero in the right half.

MNTW11:	ZERO	,IOSUNT		;DEFINED TO BE ZERO
	MOVEI	T1,1		;FLAG THE BIT
	STORE	T1,,MNTCOM	;MOUNTS IN USAGE ENTRY ARE ALWAYS COMPLETED
	INCR	,HDRCNT		;DONE WITH ELEVENTH WORD
	POPJ	P,
;FILCMD - Routine to make an OMOUNT file command FACT entry.  Since this entry
;	was designed to look like spooler and SPRINT FACT entries (as with
;	the other mount entries--see comments at MOUNT:), the DEFSTR's
;	defined for spooler and SPRINT FACT entries will be used to make
;	the DECtape file command FACT entries.  The differences are:
;
;	1.  The device name in the tenth word will be zero (spaces in SIXBIT).
;	2.  In the eleventh word (request successful), the left half will
;	    always be 1.  The right half (time used by request in seconds) is
;	    calculated by adding the difference of the scheduled date/time
;	    of request and the serviced date/time of request to the connect
;	    time.

FILCMD:	ZERO	,HDRCNT		;INITIALIZE THE WORD COUNT
	PUSHJ	P,FILWD1	;WORK ON FIRST WORD (TYPE, JOB #, LINE, COUNT)
	PUSHJ	P,FILWD3	;THIRD WORD - DATE/TIME OF ENTRY
	PUSHJ	P,FILWD4	;FOURTH WORD - 'OF',SATION #,,SERIAL NUMBER

;NOW ALL DATA HAS BEEN OBTAINED FROM THE FIRST RECORD.  READ ANOTHER.

	$CALL	USGIN
	JUMPF	[$WARN	(Incomplete DECtape file command entry -- record 2 is missing)
		JRST	DONE]	;EOF SEEN.  GO FINISH UP
	LDB	T1,USGSEQ	;GET THE RECORD SEQUENCE #
	CAIE	T1,"2"		;IS IT THE SECOND RECORD?
	$RETF			;NO.
	PUSHJ	P,FILWD5	;FIFTH WORD - RUNTIME USED BY OMOUNT
	PUSHJ	P,FILWD6	;SIXTH WORD - CORE-TIME INTEGRAL USED BY OMOUNT
	PUSHJ	P,FILWD7	;SEVENTH WORD - DISK READS DONE BY OMOUNT
	PUSHJ	P,FILWD8	;EIGHTH WORD - DISK WRITES DONE BY OMOUNT
	PUSHJ	P,FILWD9	;NINTH WORD - DEVICE NAME (ALWAYS ZERO)
	PUSHJ	P,FILW10	;TENTH WORD - DEFINED TO BE ZERO
	PUSHJ	P,FILW11	;ELEVENTH WORD - 1,,TIME USED BY REQUEST

;NOW ALL DATA HAS BEEN OBTAINED FROM THE SECOND RECORD.  READ THE THIRD FOR
;	THE PROJECT PROGRAMMER NUMBER.

	$CALL	USGIN
	JUMPF	[$WARN	(Incomplete DECtape file command USAGE entry -- record 3 is missing)
		JRST	DONE]	;EOF READ. GO FINISH UP
	LDB	T1,USGSEQ	;GET THE RECORD SEQUENCE #
	CAIE	T1,"3"		;IS IT THE THIRD RECORD?
	$RETF
	PUSHJ	P,FILWD2	;SECOND WORD - PROJECT PROGRAMMER NUMBER
	PUSHJ	P,FCTOUT	;OUTPUT THE FACT ENTRY
	$RETT
;FILWD1 - Routine to make word 1 of a DECtape file command FACT entry -
;	entry type, job number, line number and word count.

FILWD1:	MOVEI	T1,271		;ENTRY TYPE
	STORE	T1,,HDRTYP	;STORE IT
	MOVE	T1,USGJOB	;POINTER TO JOB NUMBER
	MOVEI	T2,LENJOB	;AND ITS LENGTH
	PUSHJ	P,NUMDEC	;CONVERT IT
	STORE	T1,,HDRJOB	;STORE IT
	PUSHJ	P,CHKLIN	;DETERMINE THE LINE NUMBER
	STORE	T1,HDRLIN	;STORE IT
	INCR	,HDRCNT		;DONE WITH WORD 1
	POPJ	P,



;FILWD2 - Routine to make word 2 of a DECtape file command FACT entry - the
;	project programmer number.

FILWD2:	MOVE	T1,USGPRJ	;POINTER TO PROJECT PROGRAMMER NUMBER
	MOVEI	T2,LENPPN	;AND ITS LENGTH
	PUSHJ	P,NUMOCT	;CONVERT IT
	STORE	T1,,HDRPPN	;STORE IT
	INCR	,HDRCNT		;DONE WITH WORD 2
	POPJ	P,


;FILWD3 - Routine to make word 3 of a DECtape file command FACT entry - the
;	date/time.

FILWD3:	MOVE	T1,USGLDT	;POINTER TO THE DATE/TIME
	$CALL	DATTIM		;CONVERT IT
	SKIPF			;ERROR. LEAVE IT AS ZERO
	STORE	S2,,HDRDTM	;STORE IT
	INCR	,HDRCNT		;DONE WITH WORD 3
	POPJ	P,


;FILWD4 - Routine to make word 4 of a DECtape file command FACT entry - the
;	APR serial number, 'OF', and the station number.  The serial number
;	and station number is found with the same method as with spooler FACT
;	entries.

FILWD4:	MOVEI	T1,'OF'		;INDICATE A FILE COMMAND MOUNT 
	STORE	T1,,IOSQUE	;STORE IT
	$CALL	FNDNOD		;GET THE STATION NUMBER
	SKIPT
	MOVE	T1,SAVNOD	;ERROR. USE THE DEFAULT
	STORE	T1,,IOSSTA	;STORE IT
	MOVE	T1,SAVAPR	;GET THE CPU SERIAL NUMBER
	STORE	T1,,IOSAPR	;STORE IT
	INCR	,HDRCNT		;DONE WITH FOURTH WORD
	POPJ	P,



;FILWD5 - Routine to make word 5 of a DECtape file command FACT entry - the
;	runtime used by OMOUNT to service the file command.

FILWD5:	MOVE	T1,USGDRT	;POINTER TO THE RUNTIME
	MOVEI	T2,LENRUN	;AND ITS LENGTH
	PUSHJ	P,NUMDEC	;CONVERT IT
	STORE	T1,,IOSRUN	;STORE IT
	INCR	,HDRCNT		;DONE WITH FIFTH WORD
	POPJ	P,


;FILWD6 - Routine to make word 6 of a DECtape file command FACT entry - the
;	core-time integral used by OMOUNT to service the file command.

FILWD6:	MOVE	T1,USGDCT	;POINTER TO THE CORE-TIME INTEGRAL
	MOVEI	T2,LENCTI	;AND ITS LENGTH
	PUSHJ	P,NUMDEC	;CONVERT IT
	STORE	T1,,IOSCTI	;STORE IT
	INCR	,HDRCNT		;DONE WITH SIXTH WORD
	POPJ	P,


;FILWD7 - Routine to make word 7 of the DECtape file command FACT entry - disk
;	reads done by OMOUNT to service the request.

FILWD7:	MOVE	T1,USGDDR	;POINTER TO DISK READS
	MOVEI	T2,LENDRD	;AND ITS LENGTH
	PUSHJ	P,NUMDEC	;CONVERT IT
	STORE	T1,,IOSDRD	;STORE IT
	INCR	,HDRCNT		;DONE WITH SEVENTH WORD
	POPJ	P,


;FILWD8 - Routine to make word 8 of the DECtape file command FACT entry - disk
;	writes done by OMOUNT to service the request.

FILWD8:	MOVE	T1,USGDDW	;POINTER TO DISK WRITES
	MOVEI	T2,LENDWR	;AND ITS LENGTH
	PUSHJ	P,NUMDEC	;CONVERT IT
	STORE	T1,,IOSDWR	;STORE IT
	INCR	,HDRCNT		;DONE WITH EIGHTH WORD
	POPJ	P,


;FILWD9 - Routine to make word 9 of the DECtape file command FACT entry - the
;	device name.  Since the device used is not available in the USAGE entry
;	the word will be zero (spaces in SIXBIT).

FILWD9:	ZERO	,IOSDEV		;PUT SPACES IN FOR DEVICE
	INCR	,HDRCNT		;DONE WITH NINTH WORD
	POPJ	P,


;FILW10 - Routine to make word 10 of the DECtape file command FACT entry.
;	This word has been defined to be zero.

FILW10:	ZERO	,IOSSEQ		;ZERO THE WORD
	INCR	,HDRCNT		;DONE WITH TENTH WORD
	POPJ	P,


;FILW11 - Routine to make word 11 of the DECtape file command FACT entry - 
;	the right half contains a 1 to signify a successful request and the
;	right half contains the time used by the request in seconds.  This
;	clock time is calculated by the following:
;
;	(connect time) + (serviced date/time - scheduled date/time)

FILW11:	MOVE	T1,USGDSC	;POINTER TO THE SCHEDULED DATE/TIME
	$CALL	DATTIM		;CONVERT IT
	SKIPT
	MOVEI	S2,0		;ERROR. ASSUME ZERO
	MOVEM	S2,SAVSDT	;SAVE THE DATE/TIME
	MOVE	T1,USGDSE	;POINTER TO THE SERVICED DATE/TIME
	$CALL	DATTIM		;CONVERT IT
	SKIPT
	MOVEI	S2,0		;ERROR. ASSUME ZERO
	SUB	S2,SAVSDT	;TIME DIFFERENCE BETWEEN THE TWO
	MOVE	T1,S2
	MUL	T1,[^D24*^D60*^D60]
	DIV	T1,[1,,0]
	TRNE	T2,1B18		;SHOULD THE NUMBER BE ROUNDED?
	AOS	T1		;YES.
	MOVEM	T1,SAVSDT	;SAVE SECONDS
	MOVE	T1,USGDCO	;POINTER TO THE CONNECT TIME
	MOVEI	T2,LENCON	;AND ITS LENGTH
	PUSHJ	P,NUMDEC	;CONVERT IT
	ADD	T1,SAVSDT	;GET TOTAL NUMBER OF SECONDS
	STORE	T1,,IOSUNT	;STORE IT
	MOVEI	T1,1		;SET THE SUCCESS BIT TO 1
	STORE	T1,,MNTCOM	;STORE IT
	INCR	,HDRCNT		;DONE WITH ELEVENTH WORD
	POPJ	P,
	SUBTTL	DATA CONVERSION SUBROUTINES


;NUMDEC - ROUTINE TO CONVERT AN ASCII NUMBER TO BINARY (RADIX 10)
;NUMOCT - ROUTINE TO CONVERT AN ASCII NUMBER TO BINARY (RADIX 8)
;CALL:	MOVE	T1,POINTER TO FIRST CHARACTER OF NUMBER IN USEBLK
;	MOVE	T2,LENGTH OF FIELD WHICH CONTAINS NUMBER
;	PUSHJ	P,NUMDEC/NUMOCT
;RETURNS NUMBER IN T1

NUMDEC:	SKIPA	T4,[^D10]	;HERE IF THE BASE IS 10
NUMOCT:	MOVEI	T4,^D8		;HERE IF THE BASE IS 8
	STKVAR	<PTR>
	MOVEM	T1,PTR		;SAVE POINTER
	MOVEI	T1,0		;START WITH ZERO
NUMOC1:	ILDB	T3,PTR		;GET NEXT CHARACTER
	IMUL	T1,T4		;ADJUST PLACE HOLDER
	ADDI	T1,-"0"(T3)	;CONVERT DIGIT
	SOJG	T2,NUMOC1	;ADJUST CHARACTER COUNT
	$RETT			;CONVERTED NUMBER IS IN T1



;ASCSIX - ROUTINE TO CONVERT AN ASCII STRING TO SIXBIT.
;
;CALL:	MOVE	T1,POINTER TO FIRST ASCII CHARACTER IN USEBLK
;	MOVE	T2,LENGTH OF FIELD THAT CONTAINS THE CHARACTERS TO BE
;		   CONVERTED.  IF THE LENGTH IS GREATER THAN SIX, ONLY THE
;		   FIRST SIX CHARACTERS WILL BE CONVERTED.
;RETURNS SIXBIT CHARACTERS RIGHT-JUSTIFIED IN T4

ASCSIX:	CAILE	T2,6		;CAN ONLY FIT SIX CHARACTERS IN A WORD
	MOVEI	T2,6		; SO JUST RETURN THE FIRST SIX
	SETZ	T4,		;CLEAR RETURNED VALUE
ASCSI1:	ILDB	T3,T1		;GET AN ASCII CHARACTER
	SUBI	T3,40		;CONVERT TO SIXBIT
	LSH	T4,6		;MAKE ROOM FOR THE CHARACTER
	DPB	T3,[POINT 6,T4,35] ;INSERT THE CHARACTER
	SOJG	T2,ASCSI1	;CONVERT ALL OF THEM
	POPJ	P,		;AND RETURN
;DATTIM - ROUTINE TO CONVERT YYYYMMDDHHMMSS FORMAT DATE/TIME TO UNIVERSAL
;	DATE/TIME WORD
;CALL:	MOVE	T1,POINTER TO DATE/TIME IN USAGE RECORD
;RETURNS DATE/TIME IN S2
;	T2 IS USED AS THE BYTE POINTER TO THE S%DATI ARGUMENT BLOCK
;	T4 IS USED FOR THE DATA LOAD/DEPOSIT BYTE TRANSFER
;	THE ARGUMENT STRING FOR THE S%DATI CALL WILL HAVE THE FORMAT OF
;	MM/DD/YY HHMM:SS<NULL>

DATTIM:	MOVE	T2,[POINT 7,TEMP+1,6]	;BYTE PTR INTO ARGUMENT BLOCK FOR YEAR
	ILDB	T4,T1		;"1"
	CAIN	T4,"0"		;IS THIS A ZERO DATE/TIME?
	JRST	[MOVEI	S2,0	;YES, IF NO DATE/TIME, PUT ZEROES IN
		JRST	.RETT]	;AND RETURN TRUE
	IDPB	T4,T2
	ILDB	T4,T1		;"9"
	IDPB	T4,T2
	ILDB	T4,T1		;"8"
	IDPB	T4,T2
	ILDB	T4,T1		;"0"
	IDPB	T4,T2
	MOVEI	T4,":"		;COLON SEPARATOR
	IDPB	T4,T2
DATTI1:	MOVE	T2,[POINT 7,TEMP]	;BYTE POINTER TO MONTH IN ARGUMENT BLOCK
	ILDB	T4,T1		;"M"
	IDPB	T4,T2
	ILDB	T4,T1		;"M"
	IDPB	T4,T2
	MOVEI	T4,"-"		;DASH SEPARATOR
	IDPB	T4,T2
;BYTE POINTER TO DAY IN ARGUMENT BLOCK IS ALREADY SET UP
DATTI2:	ILDB	T4,T1		;"D"
	IDPB	T4,T2
	ILDB	T4,T1		;"D"
	IDPB	T4,T2
	MOVEI	T4,"-"		;DASH SEPARATOR
	IDPB	T4,T2
DATTI3:	MOVE	T2,[POINT 7,TEMP+2,6]	;BYTE POINTER TO HOURS IN ARGUMENT BLOCK
	ILDB	T4,T1		;"H"
	IDPB	T4,T2
	ILDB	T4,T1		;"H"
	IDPB	T4,T2
	MOVEI	T4,":"		;COLON SEPARATOR
	IDPB	T4,T2
;BYTE POINTER TO MINUTES IN ARGUMENT BLOCK IS ALREADY SET UP
DATTI4:	ILDB	T4,T1		;"M"
	IDPB	T4,T2
	ILDB	T4,T1		;"M"
	IDPB	T4,T2
	MOVEI	T4,":"		;COLON SEPARATOR
	IDPB	T4,T2
;BYTE POINTER TO SECONDS IN ARGUMENT BLOCK IS ALREADY SET UP
DATTI5:	ILDB	T4,T1		;"S"
	IDPB	T4,T2
	ILDB	T4,T1		;"S"
	IDPB	T4,T2
	MOVEI	T4,0		;FINISH UP THE ASCIZ STRING WITH A NULL
	IDPB	T4,T2

;ASCIZ STRING IS ALL SET UP IN TEMP.  NOW CALL S%DATI TO CONVERT IT

DATTI6:	MOVE	S1,[POINT 7,TEMP]	;POINT TO DATE/TIME ASCIZ STRING
	TXO	S2,CM%IDA!CM%ITM	;RETURN DATE AND TIME
	$CALL	S%DATI
	SKIPF
	$RETT			;NO ERRORS
	$WARN	(Error (^E/S1/) converting date/time string "^T/TEMP/")
	$RETF
	SUBTTL	Command parser interface




CBL:	BLOCK	PBSIZ		;COMMAND BLOCK FOR TOKENS

PARINP:	EXP	COMINP,PSTINP,CBL,0	;PARSER INITIALIZATION FOR INPUT FILE

COMINP:	$INIT	(.PROGI)
PSTINP:	ASCIZ	/Please enter USAGE file to be read: /



PAROUT:	EXP	COMOUT,PSTOUT,CBL,0	;PAERSER INITIALIZATION FOR OUTPUT FILE
COMOUT:	$INIT	(.PROGO)
PSTOUT:	ASCIZ	/Please enter file to be written: /

.PROGI:	$NOISE	(.PROG1,Please enter USAGE file to be read:)
.PROG1:	$IFILE	(CONFRM,,$DEFAULT (<ALL:USAGE.OUT>))

.PROGO:	$NOISE	(.PROG2,Please enter file to be written:)
.PROG2:	$OFILE	(CONFRM,,$DEFAULT (<DSK:FACT.SYS>))


CONFRM:	$CRLF
	SUBTTL	ERROR SUBROUTINES
	SUBTTL	MISCELLANEOUS STORAGE


USGIFN:	0			;USAGE FILE INTERNAL FILE NUMBER (IFN)
FCTIFN:	0			;FACT FILE INTERNAL FILE NUMBER (IFN)
USEBLK:	BLOCK	^D128		;STORAGE FOR A USAGE FILE RECORD
FACTBL:	BLOCK	40		;STORAGE FOR FACT FILE ENTRY
FACEND:	0			;SIGNIFIES END OF FACT ENTRY BLOCK (USED FOR BLT'S)

SAVTYP:	0			;USAGE ENTRY TYPE
SAVJOB:	0			;JOB NUMBER
SAVLIN:	0			;LINE NUMBER
SAVBDT:	0			;LOGIN DATE/TIME FOR SESSION ENTRY
SAVLDT:	0			;LOGOUT/CHKPNT DATE/TIME FOR SESSION ENTRY
SAVDAT:	0			;DATE/TIME SAVED FOR DISK UTILIZATION ENTRIES
SAVRUN:	0			;LOGOUT/CHKPNT RUN TIME
SAVCTI:	0			;CORE-TIME INTEGRAL FOR SESSION ENTRY
SAVDRD:	0			;DISK READS FOR SESSION ENTRY
SAVDWR:	0			;DISK WRITES FOR SESSION ENTRY
SAVPPN:	0			;PROJECT-PROGRAMMER NUMBER
SAVNOD:	0			;DEFAULT STATION NUMBER FOR SPOOL/MOUNT ENTRIES
SAVAPR:	0			;APR SERIAL NUMBER FOR SPOOL/MOUNT ENTRIES
DSMNOD:	0			;NODE NUMBER SAVED FOR DISMOUNT ENTRY
SAVDEV:	0			;FILE STRUCTURE NAME SAVED FOR DISMOUNT ENTRY
SAVSDT:	0			;USED TO CALCULATE FILE COMMAND CLOCK TIME


FFAPPN:	0			;DEFAULT PPN OF DAEMON


USAGE:	BLOCK	6		;LOOKUP BLOCK FOR USAGE FILE

FACT:	BLOCK	6		;ENTER BLOCK FOR USAGE FILE
USEFIL:	[ASCIZ /USAGE/]		;DEFAULT INPUT FILE NAME
USEEXT:	[ASCIZ /OUT/]		;DEFAULT INPUT EXTENSION

FCTFIL:	[ASCIZ /FACT/]		;DEFAULT OUTPUT FILE NAME
FCTEXT:	[ASCIZ /BIN/]		;DEFAULT OUTPUT EXTENSION

TEMP:	BLOCK 21		;TEMPORARY STORAGE


	.TEXT	"/SEGMENT:LOW OPRPAR.REL"


	END	CONV10