	.TITLE *** TDV FUNCTION "NEW DIRECTORY" FOR DECTAPE
/ 
/ 
/                   FIRST PRINTING, FEBRUARY 1974
/ 
/ THE INFORMATION IN THIS DOCUMENT IS SUBJECT TO 
/ CHANGE WITHOUT NOTICE AND SHOULD NOT BE CONSTRUED
/ AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION.
/ DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPON-
/ SIBILITY FOR ANY ERRORS THAT MAY APPEAR IN THIS
/ DOCUMENT.
/ 
/ THE SOFTWARE DESCRIBED IN THIS DOCUMENT IS FUR-
/ NISHED TO THE PURCHASER UNDER A LICENSE FOR USE ON
/ A SINGLE COMPUTER SYSTEM AND CAN BE COPIED (WITH
/ INCLUSION OF DIGITAL'S COPYRIGHT NOTICE) ONLY FOR 
/ USE IN SUCH SYSTEM, EXCEPT AS MAY OTHERWISE BE PRO-
/ VIDED IN WRITING BY DIGITAL.
/ 
/ DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPONSIBILITY
/ FOR THE USE OR RELIABILITY OF ITS SOFTWARE ON EQUIP-
/ MENT THAT IS NOT SUPPLIED BY DIGITAL.
/ 
/ COPYRIGHT (C) 1974, BY DIGITAL EQUIPMENT CORPORATION
/ 
/ 
        .EJECT
/
/      EDIT #3        2 JAN 72         C. PROTEAU
/
/ COPYRIGHT 1972, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.
/
/ TDV (TASK DEVELOPMENT) FUNCTION, CALLED "NEW...", USED TO CREATE A NEW
/ FILE DIRECTORY ON DECTAPE.
/
/////////////////////////////////////////////////
/						/
/ CALL:	TDV>NEW					/
/						/
/ SAMPLE PRINTOUT:				/
/						/
/	NEW DIRECTORY ON DECTAPE UNIT 4		/
/						/
/////////////////////////////////////////////////
/
/ THERE ARE 1100 OCTAL BLOCKS ON A DECTAPE, AT LEAST 8 OF WHICH ARE
/ SYSTEM BLOCKS (BLOCKS 71 THRU 100 OCTAL, USED FOR FILE DIRECTORY
/ INFORMATION).
/
/ THERE ARE 2 TYPES OF DIRECTORY FORMAT. THE NORMAL FORMAT FOR BLOCK
/ 100 IS THAT THE FIRST 40 OCTAL WORDS IS THE MASTER BIT MAP FOR THE
/ TAPE FOLLOWED BY 340 OCTAL WORDS OF FILE ENTRIES. EACH FILE ENTRY
/ CONSISTS OF 4 WORDS, SO ON A NORMAL TAPE ONE CAN HAVE UP TO 70
/ OCTAL (56 DECIMAL) FILES. EACH FILE HAS A FILE BIT MAP OF 40 OCTAL
/ WORDS LOCATED IN A CORRESPONDING POSITION IN BLOCKS 71 THRU 77.
/ BLOCK 71 CONTAINS THE FIRST 8 FILE BIT MAPS, AND SO ON. A 1-BIT IN
/ THE BIT MAP INDICATES AN OCCUPIED BLOCK.
/
/ EACH FILE ENTRY OF 4 WORDS IS FORMATTED AS FOLLOWS:
/
/	WORD 0 -- .SIXBT "FIL"
/	WORD 1 -- .SIXBT "NAM"
/	WORD 2 -- .SIXBT "EXT"
/	WORD 3 -- STARTING BLOCK NUMBER IN BITS 8-17
/		  (BIT 0=1 FOR SYSTEM FILE ENTRIES (SEE BELOW))
/
/
/ THE SECOND FORMAT IS FOR A SYSTEM TAPE, ONE USED IN PDP-9/15 SYSTEMS
/ IN WHICH THE OPERATING SYSTEM PROGRAMS RESIDE ON THE DECTAPE IN CORE
/ IMAGE FORM. ON SUCH A TAPE, THE MASTER BIT MAP STILL OCCUPIES THE FIRST
/ 40 OCTAL WORDS OF BLOCK 100. THE NUMBER OF USER FILE ENTRIES IS CUT
/ DOWN TO 30 OCTAL (24 DECIMAL). THE SECOND HALF OF BLOCK 100 STARTS
/ WITH A 40 OCTAL WORD SYSTEM BIT MAP, CORRESPONDING TO THE BLOCKS
/ OCCUPIED BY ALL THE SYSTEM PROGRAMS.
/
/ THERE MAY BE UP TO 30 OCTAL SYSTEM FILE ENTRIES, EACH 4 WORDS LONG.
/ THERE IS NO CORRESPONDING FILE BIT MAP IN BLOCKS 71 THRU 77 FOR
/ SYSTEM FILE ENTRIES.
/
/ ******************** MASTER DIRECTORY BLOCK 100 **********************
/
/	NORMAL TAPE				SYSTEM TAPE
/	-----------				-----------
/
/	*****************			*****************
/	*		*			*		*
/	* 40 OCTAL WORD *			* 40 OCTAL WORD *
/	* MASTER BITMAP *			* MASTER BITMAP *
/	*		*			*		*
/	*****************			*****************
/	*		*			*		*
/	* 70 OCTAL	*			* 30 OCTAL	*
/	* 4-WORD USER	*			* 4-WORD USER	*
/	* FILE ENTRIES	*			* FILE ENTRIES	*
/	*		*			*		*
/	*		*			*****************
/	*		*			*		*
/	*		*			* 40 OCTAL WORD *
/	*		*			* SYSTEM BITMAP *
/	*		*			*		*
/	*		*			*****************
/	*		*			*		*
/	*		*			* 30 OCTAL	*
/	*		*			* 4-WORD SYSTEM *
/	*		*			* FILE ENTRIES	*
/	*		*			*		*
/	*****************			*****************
/
/	WORD 203 OCTAL CORRESPONDS		WORD 203 OCTAL IS PART OF
/	TO THE LAST WORD IN THE			THE SYSTEM BIT MAP. BIT 3
/	31ST FILE ENTRY. BIT 3 MUST		IN THE WORD CORRESPONDS
/	BE 0.					TO BLOCK 71, WHICH IS AL-
/						WAYS OCCUPIED. BIT 3 MUST
/						BE 1.
/
/ THIS TASK ONLY CREATES A NEW DIRECTORY FOR A "NORMAL" TAPE. THE OTHER
/ FORM IS DEPICTED HERE SIMPLY FOR REFERENCE.
/
	.EJECT
/ AT COMPLETION OF THE FUNCTION, THE TERMINATING CHARACTER OF THE
/ COMMAND LINE IS EXAMINED. IF IT IS A CARRIAGE RETURN, THE RESIDENT TDV
/ TASK IS 'REQUESTED' AND THIS TASK EXITS. IF THE LINE IS TERMINATED BY AN
/ ALTMODE, THIS TASK EXITS WITHOUT 'REQUESTING' 'TDV...'. A CTRL T TYPEIN
/ IS THEN NECESSARY TO RE-ESTABLISH TDV DIALOGUE.
/
IDX=ISZ				/USED WHEN THE SKIP IS NOT INTENDED.
X10=10				/AUTOINCREMENT REGISTER 10.
	.DEC
DTPLUN=19			/DECTAPE OUTPUT LUN.
TDVTTY=13			/TDV TTY ERROR & PRINTOUT LUN.
	.OCT
/
	.EJECT
NEW	CAL	XFER		/TRANSFER THE COMMAND LINE READ BY 'TDV...'.
	CAL	WAITFR
	LAC	EV		/SAVE THE EVENT VARIABLE FOR REFERENCE AT
	DAC	XFEREV		/EXIT TIME.
/
/ ATTACH THE DECTAPE.
/
	CAL	ATCHDT
	CAL	WAITFR
	LAC	EV
	SPA
	JMP	ERR1		/"ATTACH" ERROR -- PERHAPS THIS ISN'T A DECTAPE.
/
/ MAKE SURE THAT THE OUTPUT DEVICE IS INDEED DECTAPE.
/
	CAL	HINFDT
	CAL	WAITFR
	LAC	EV
	AND	(77)		/CHECK THE DEVICE CODE.
	SAD	(4)
	SKP
	JMP	ERR2		/NOT DECTAPE.
	LAC	EV
	LRS	6
	AND	(7)
	DAC	UNIT		/SAVE THE DECTAPE UNIT #.
/
/ WRITE OUT DECTAPE BLOCKS 71-100. THE ORDER AND DIRECTION IN WHICH
/ BLOCKS ARE WRITTEN IS CHOSEN TO MINIMIZE TAPE MOTION.
/
	LAC	(400075)	/WRITE OUT FILE BIT MAP BLOCKS, SOME IN THE
	JMS	WRITE		/REVERSE DIRECTION (+400000) AND SOME
	LAC	(400071)	/FORWARD. THOSE WRITTEN IN REVERSE WILL
	JMS	WRITE		/FIRST BE TURNED INTO THEIR COMPLEMENT
	LAC	(+72)		/OBVERSE PATTERN.
	JMS	WRITE
	LAC	(+76)
	JMS	WRITE
	LAC	(400077)
	JMS	WRITE
	LAC	(400073)
	JMS	WRITE
	LAC	(+74)
	JMS	WRITE
	LAC	(+100)
	JMS	WRITE
/
/ PRINT THE "DONE" MESSAGE.
/
	LAC	UNIT		/CONVERT THE UNIT # TO ASCII.
	AAC	+60
	ALS	13		/MOVE IT INTO IOPS ASCII POSITION 1.
	AND	(774000)
	DAC	UNIT
	LAC	MES0+16		/INSERT UNIT # IN MESSAGE.
	AND	(003777)
	TAD	UNIT
	DAC	MES0+16
	LAC	(MES0)
	DAC	TYPE+4
	CAL	TYPE
	CAL	WAITFR
/
/ DETACH THE DECTAPE.
/
	CAL	DTCHDT
	CAL	WAITFR
	LAC	EV
	SPA
	JMP	ERR4		/"DETACH" ERROR.
/
/ FUNCTION COMPLETED. EXAMINE THE EVENT VARIABLE VALUE RETURNED
/ BY THE TRANSFER-COMMAND-LINE DIRECTIVE TO SEE IF THE LINE WAS TERMINATED
/ BY CARRIAGE RETURN (+2), ALTMODE (+1), OR IF THE LINE BUFFER IS TOO
/ SMALL (-16). REQUEST 'TDV...' UNLESS THE TERMINATOR WAS ALTMODE.
/
	LAC	XFEREV
	SAD	(1)
	SKP
EXIT	CAL	REQTDV		/REQUEST 'TDV...'.
	CAL	(10)		/EXIT.
/
	.EJECT
/ ERROR EXIT.
/
ERR2	LAC	(MES2)		/NOT DECTAPE.
	SKP
ERR3	LAC	(MES3)		/DECTAPE ERROR.
	DAC	TYPE+4
	LAC	EV
	DAC	ERRCOD
	CAL	DTCHDT		/DETACH THE DECTAPE.
	CAL	WAITFR
	JMP	TYPEIT
ERR1	LAC	(MES1)		/"ATTACH" ERROR.
	SKP
ERR4	LAC	(MES4)		/"DETACH" ERROR.
	DAC	TYPE+4
	LAC	EV		/SAVE EV VALUE SO THAT SOMEONE MAY EXAMINE
	DAC	ERRCOD		/IT USING THE "OPEN" MCR FUNCTION.
TYPEIT	CAL	TYPE
	CAL	WAITFR
	JMP	EXIT
/
	.EJECT
/ NOTE -- UNIT # IN MES0 IS MODIFIED AT RUN TIME.
/
MES0	010002; 0; .ASCII "NEW DIRECTORY ON DECTAPE UNIT 0"<15>
MES1	004002; 0; .ASCII "NEW-ATTACH ERR"<15>
MES2	005002; 0; .ASCII "NEW-NOT DECTAPE"<15>
MES3	005002; 0; .ASCII "NEW-DECTAPE ERR"<15>
MES4	004002; 0; .ASCII "NEW-DETACH ERR"<15>
/
	.EJECT
/ SUBROUTINE WRITE -- WRITE OUT THE INDICATED DECTAPE BLOCK IN THE INDICATED
/ DIRECTION. COMPLEMENT OBVERSE THE DATA IF THE BLOCK IS TO BE WRITTEN
/ IN THE REVERSE DIRECTION. FOR BLOCK 100, INITIALIZE THE MASTER BITMAP.
/
/ CALLING SEQUENCE:
/
/	+ OR - BLOCK # IN THE AC (+ = FORWARD; - = REVERSE)
/	JMS	WRITE
/	(RETURN IF NO WRITE ERROR OCCURRED)
/
/ ALTERED REGISTERS:
/
/	EFFECTIVELY ALL (DUE TO THE CAL)
/
WRITE	0
	DAC	DTPUT+3		/STORE THE BLOCK NUMBER AND DIRECTION
				/INDICATOR IN THE "PUT" CPB.
/
/ IF THE TAPE IS TO BE WRITTEN IN THE REVERSE DIRECTION, PERFORM THE
/ COMPLEMENT OBVERSE ON THE DATA (SET THE BUFFER TO -1'S).
/
	LAW	-400		/NUMBER OF WORDS PER BLOCK.
	DAC	COUNT
	LAC	(BUF-1)
	DAC*	(X10)
	LAC	DTPUT+3
	SPA!CLA			/FORWARD -- SET BUFFER TO 0'S.
	CLC			/REVERSE -- SET BUFFER TO -1'S.
	DAC*	X10
	ISZ	COUNT
	JMP	.-2
/
/ IF ABOUT TO WRITE BLOCK 100, CHANGE WORD 3 TO INDICATE THAT BLOCKS
/ 71 THRU 100 ARE OCCUPIED.
/
        LAC     DTPUT+3
        SAD     (100
        SKP
        JMP     .+3
	LAC	(077600)
	DAC	BUF+3
/
/ WRITE OUT THE BLOCK.
/
	CAL	DTPUT
	CAL	WAITFR
	LAC	EV
	SPA
	JMP	ERR3		/DECTAPE ERROR.
	JMP*	WRITE
/
	.EJECT
WAITFR	20			/"WAITFOR" CPB.
	EV
/
HINFDT	3600			/"HINF" CPB.
	EV
	DTPLUN			/DECTAPE OUTPUT LUN.
/
ATCHDT	2400			/"ATTACH" CPB.
	EV
	DTPLUN			/DECTAPE OUTPUT LUN.
/
DTCHDT	2500			/"DETACH" CPB.
	EV
	DTPLUN			/DECTAPE OUTPUT LUN.
/
DTPUT	3100			/"PUT DECTAPE BLOCK" CPB.
	EV
	DTPLUN			/DECTAPE OUTPUT LUN.
	XX			/+ OR - (FORWARD OR REVERSE) BLOCK NUMBER.
	BUF			/CORE ADDRESS.
	400			/WORD COUNT.
/
TYPE	2700			/"WRITE" CPB.
	EV
	TDVTTY			/TDV TTY MESSAGE LUN.
	2			/IOPS ASCII DATA MODE.
	XX			/MESSAGE ADDRESS.
/
REQTDV	1			/"REQUEST" CPB.
	0
	.SIXBT	"TDV"
	.SIXBT	"..."
	0			/USE THE DEFAULT PRIORITY.
/
XFER	37			/"TRANSFER TDV COMMAND LINE" CPB.
	EV
	BUF			/BUFFER ADDRESS.
	401			/BUFFER SIZE.
/
/ VARIABLES.
/
XFEREV	0			/EVENT VARIABLE VALUE RETURNED BY THE
				/"XFER" DIRECTIVE.
EV	0			/EVENT VARIABLE.
ERRCOD	0			/EV VALUE SAVED BEFORE ERROR PRINTOUT IN
				/CASE SOMEONE WANTS TO EXAMINE IT USING
				/THE "OPEN" MCR FUNCTION.
UNIT	0			/DECTAPE UNIT #.
COUNT	0			/COUNTER.
/
BUF	.BLOCK	401		/EXTRA WORD IS TO GUARD AGAINST POSSIBLE
				/HARDWARE TIMING ERROR WHEREIN DECTAPE
				/TRANSFERS AN EXTRA WORD.
/
	.END	NEW
