;							>>B/S<<
; ADVANCED DIRECTORY FUNCTIONS
;
; 02.14 krs 07/??/80
; 02.20 krs 07/??/80
; 02.35 dew 10/??/81
; 02.37 krs 02/??/82 subdirs
; 02.40 sbw 08/05/82 Miscellaneous
; 02.42 sbw 12/16/82 Archive flag
;
	icl	pdef		;02.39
	icl	df		;02.39
	df.dos			;02.39
	df.cpu			;02.39
	df.sys			;02.39
;
	NAM	DR2242
;
	ENT	GETCLS,GDIRST
	ENT	DIRCLS,DIRSIZ
	ENT	RDLABL		; (21) READ LABEL
	ent	getatb,getath,getdre,xgetat,getatx	;02.15
	ent	cks00					;02.20
;
	EXT	CSDTE,GTSDT,DIV16
	EXT	FCBDK,ASDTE,MOVE
	EXT	URREG					;02.14
	ext	savaf					;02.20
	EXT	SDT					;02.37
;
;
;	GET CLUSTER NUBER
;ENTER: A = RECORD NUMBER
;RETURNS: A = CLUSTER NUMBER
;
GETCLS:	PUSH	H
	PUSH	D
	MVI	L,SDTCSZ
	CALL	GTSDT	; @HL=SDT.CLUSTER
	MVI	D,0				;02.37
SUBM0:	SUB	M				;02.37
	JM	GOTIT6				;02.37
	INR	D				;02.37
	BR	SUBM0				;02.37
GOTIT6:	MOV	A,D	; CLUSTER NUMBER	 02.37
	POP	D
	POP	H
	RET
;
; GET START OF MASTER DIRECTORY
; EXIT: HL:=START BLOCK
;
GDIRST:	MVI	L,SDTMDR
	CALL	GTSDT
	PUSH	PSW
	MOV	A,M
	INX	H
	MOV	H,M
	MOV	L,A	; HL:=BLOCK
	POP	PSW
	RET
;
;  GET DIRECTORY TYPE IN (A)
; NUMBER OF ENTRIES IN DIR (A)
;
DIRSIZ:	PUSH	H
	MVI	L,SDTMLN
	BR	DIRCL1					;02.35
;
; NUMBER OF CLUSTERS IN DIRECTORY (A)
;
DIRCLS:	PUSH	H
	MVI	L,SDTMCL
DIRCL1:	CALL	GTSDT
	MOV	A,M
	POP	H
	RET
;
; READ DISK LABEL FROM SDT (21)
;
RDLABL:	CALL	FCBDK	; GET ACTUAL DISK NUM
	CALL	ASDTE	; PT AT CSDT
	LXI	B,sdtdty				;02.20
	LHLD	CSDTE
	DAD	B	; @HL=LABEL
	mov	a,m	;get dir type flags		 02.20
	SAFUCB						;02.35
	inx	h	;now sdtnam			 02.20
	INX	D	; @DE=FCB.NAME
	XCHG
	LXI	B,8
	JMP	MOVE	; FCB.NAME:=LABEL
;
; GET ATTRIBUTES					;02.14
;
GETATH:	PUSH	D					;02.15
	INX	D					;02.15
	INX	D					;02.15
	INX	D					;02.15
	LDAX	D	;GET BYTE WITH BIG BIT		;02.15
	ANI	80H	;CLEAR GARBAGE			;02.15
	RLC		; -------H			 02.15
GETAT1:	RLC		; ------HB			 02.15
	RLC		; -----HB-			 02.15
	POP	D					;02.15
	RET						;02.15
;
GETATB: PUSH	D					;02.15
	INX	D					;02.15
	INX	D					;02.15
	LDAX	D	;GET BYTE WITH BIG BIT		 02.15
	ANI	80H	; CLEAR GARBAGE			 02.15
	BR	GETAT1	;MERGE LOGIC			;02.15	;02.35
;
GETDRE:	PUSH	H					;02.14
	LXI	H,FCBDE					;02.15
	DAD	D	; ADDRESS THE BYTE		 02.15
	MOV	A,M	; GET IT			 02.15
	POP	H					;02.15
	RET						;02.15
;
;	===== XGETAT COPIED FROM MULTIOS AT 02.37 ======
;
;	H = Attribute byte					;02.40
;	C = Dir entry #						;02.40
;								;02.40
;	Saves BC						;02.40
;
; Table relates atribute byte to order of atributes in FCB:
;
;		P W R U S  A  B  F'
XACTRL:	DB	6,9,8,7,10,11,2,0
;
; Permanent, Write protect, Read protect, User, System, Archive,
;				Big, Not a file.
;
XGETAT:	PUSH	B
	PUSH	H
	LXI	H,FCBDE
	DAD	D	;ADDRESS DIR ENMT
	POP	B	;GET B=ATT,C=ENT #
	MOV	M,C	;STORE DIR ENT #
;
	MVI	C,8		; 8 BITS IN BYTE
	LXI	H,XACTRL-1	; DISPLACEMENT IN FCB
;
	MOV	A,B		; ORIGINAL PWRUS-B-
XATLUP:	PUSH	B		; SAVE COUNT AND ATTRIB
	INX	H		; ADDRESS NEXT TABLE ENTRY
	ANI	80H		; TEST RELEVANT BIT
	BRZ	NOTON		; BYPASS IF NOT ON
	PUSH	H		; SAVE ADDRESS
	MOV	L,M		; DISPLACEMENT FOR ADDITION
	MVI	H,0		; HIGH BYTE 0
	DAD	D		; HL -> DESIRED SPOT
	MOV	A,M
	ORI	80H		; TURN ON HIGH BIT
	MOV	M,A		; AND PUT BACK
	POP	H		; 0 DISP ENTRIES WILL BE CLEANED UP
NOTON:	POP	B		; AFTER FALLING OUT OF LOOP
	MOV	A,B
	RLC			; ROTATE TO NEXT BIT
	MOV	B,A
	DCR	C
	JNZ	XATLUP
;
	LDAX	D		; CLEAR ALL BUT DISK
	ANI	3FH		; IN BYTE 0
	STAX	D
	POP	B
	RET	
;
GETATX: PUSH	D		;SAVE FCB
	XCHG		;FCB TO H
	INX	H
	INX	H	; NOW AT BIG BYTE
	POP	D
	RET	
;
; BLDATR added 02.42
;
; Input:	DE = Address of user's FCB
;
; Gather the attribute bits from the high bits of the FCB into an
; attribute byte of the form used in the directory entry.
;
; Output:	A = Attribute byte reflected in FCB.
;		BC, DE, HL preserved.
;
	ent	bldatr
bldatr:
	push	h
	push	b
;
	lxi	h,xactrl
	lxi	b,(8<<8)!0	; Bit count and initial attribute byte
  .do
	mov	a,m		; Get offset to FCB byte
	ora	a		;	containing next attribute
	brz	..1		; Jump with CY clear if zero offset
	push	h
	mov	l,a		; Else offset into FCB
	mvi	h,0
	dad	d
	mov	a,m
	pop	h
	ral			; Roll attribute into CY
..1:
	mov	a,c
	ral			; Roll attribute into attribute byte
	mov	c,a
	inx	h		; Point to next offset
	dbrnz	.do		; Loop until all bits
  .until
	pop	b
	pop	h
	ani	^BIGFIL		; Never return big flag
	ret
;
	EJECT
CKS00:	PUSH	H		;SAVE BUFFER ADDRESS
	push	b						;02.20
	MVI	C,128
	XRA	A
CKS01:	XRA	M		;PROCESS NEXT BYTE
	INX	H
	DCR	C
	BRNZ	CKS01						;02.35
	pop	b						;02.20
	POP	H		;CKSUM IN A
	RET
;
;
	END
