	.title	getdir
;+
;	subroutine getdir(key, type, buf)
;-
;
;	local data
;
	.psect	$r.rwd,con,rw,rel,lcl,d
paramb:
	.byte	3,0
p1:	.word	0
p2:	.word	unit
p3:	.word	device
unit:	.word	0
device:	.blkb	6
	.psect	$r.rod,con,ro,rel,lcl,d
devptr:	.word	st0,st0,st1,st1,st1,st0,st0,st0,st0
uicptr:	.word	bin,usr,tmp,lpr,msg,man,src,inc,lib
ndirs=<.-uicptr>/2		; number of valid keys
	.if ndf	IAS
st0:	.asciz	"ST0"
st1:	.asciz	"ST1"
	.iff		; IAS
st0:	.asciz	"LB0"
st1:	.asciz	"LB0"
	.endc		; IAS
bin:	.asciz	"105,1"
usr:	.asciz	"105,2"
tmp:	.asciz	"105,3"
lpr:	.asciz	"105,4"
msg:	.asciz	"105,5"
man:	.asciz	"105,6"
src:	.asciz	"105,7"
inc:	.asciz	"105,10"
lib:	.asciz	"105,11"
	.even
;
;
ap=%5
key=2
type=4
buf=6
	.psect	$r.roi,con,ro,rel,lcl,i
	.enabl	lsb
getdir::
	mov	buf(ap),r0		; destination address
	mov	@key(ap),r3		; get value of key
	ble	100$			; if key <= 0, invalid
	cmp	r3,#ndirs			; too large?
	bgt	100$			; YES
	dec	r3			; key - 1
	clc				;
	rol	r3			; 2 * (key - 1)
	mov	devptr(r3),r1		; address of device and unit
	mov	r1,p1			; place in parameter block
	movb	2(r1),r2		; generate unit number
	sub	#'0,r2			; ...
	mov	r2,unit			; place in parameter block
	mov	ap,-(sp)		; save arg pointer
	mov	#paramb,ap		; new parameter block
	call	trndev			; translate device
	mov	(sp)+,ap		; restore arg pointer
	mov	#device,r1		; address of buffer
	bis	#<40+<40*256.>>,(r1)	; make lower case
	cmp	@type(ap),#path		; desire pathname format?
	bne	10$			; NO
	movb	#'/,(r0)+		; initial slash
	call	copy			; copy device name
	tstb	-(r0)			; back up over colon
	movb	#'/,(r0)+		; dividing slash
	mov	uicptr(r3),r1		; address of uic string
	call	copy			; copy uic string
	movb	#'/,(r0)+		; trailing slash
	br	100$			; finish up
10$:
	call	copy			; copy device name
	movb	#'[,(r0)+		; ...
	mov	uicptr(r3),r1		; address of uic string
	call	copy			; copy uic string
	movb	#'],(r0)+		; trailing ']'
100$:
	clrb	(r0)			; terminate with EOS
	return
;
;
;	copy subroutine
;
;
copy:
	movb	(r1)+,(r0)+		; copy character
	bne	copy			; if not 0, go again
	tstb	-(r0)			; point at EOS
	return
	.end
