include	clib.inc
include	disk.inc
include	conio.inc

_DATA	SEGMENT
PButton	db '&A',0
_DATA	ENDS

_TEXT	SEGMENT

_disk_select proc DIST pascal public uses si di msg:dword
local disk:word
local dobj:S_DOBJ
local tobj[MAXDRIVES]:S_TOBJ
	sub ax,ax
	mov disk,ax
	mov ax,sys_ercode
	or al,sys_erflag
	or al,sys_erdrive
	.if !ax
	    call getdrv
	    mov disk,ax
	.endif
	xor ax,ax
	mov si,ax
	mov dobj.dl_index,al
	mov dobj.dl_count,al
	lea di,tobj
	mov word ptr dobj.dl_object,di
	mov word ptr dobj.dl_object+2,ss
	.repeat
	    .if func(_disk_type, si)
		mov al,dobj.dl_count
		inc dobj.dl_count
		mov [di.to_flag],_O_PBKEY
		cbw
		mov bx,ax
		.if si == disk
		    mov al,dobj.dl_count
		    dec al
		    mov dobj.dl_index,al
		.endif
		mov ax,si
		add al,'A'
		mov [di+3],al
		mov word ptr [di+8],offset PButton
		mov [di+10],ds
		mov byte ptr [di+6],5
		mov byte ptr [di+7],1
		mov ax,bx
		and ax,7
		mov dl,al
		shl al,3
		sub al,dl
		add al,4
		mov [di+4],al
		mov ax,bx
		shr ax,3
		shl ax,1
		add ax,2
		mov [di+5],al
		add di,16
	    .endif
	    inc si
	.until si == MAXDRIVES
	mov dobj.dl_flag,_D_STDDLG
	mov dobj.dl_rect.rc_x,8
	mov dobj.dl_rect.rc_y,9
	mov dobj.dl_rect.rc_col,63
	mov al,dobj.dl_count
	mov ah,0
	dec ax
	mov bx,ax
	shr ax,3
	shl ax,1
	add al,5
	mov dobj.dl_rect.rc_row,al
	mov ax,bx
	.if ax <= 7
	    shl ax,3
	    sub ax,bx
	    add ax,14
	    mov dobj.dl_rect.rc_col,al
	    mov cl,80
	    sub cl,al
	    shr cl,1
	    mov dobj.dl_rect.rc_x,cl
	.endif
	xor di,di
	mov bl,at_foreground[F_Dialog]
	or bl,at_background[B_Dialog]
	invoke dlopen, addr dobj, bx, msg
	.if ax
	    lea si,tobj
	    .repeat
		xor ax,ax
		mov al,dobj.dl_count
		.break .if di >= ax
		mov al,[si+3]
		mov PButton+1,al
		pushm dobj.dl_wp
		pushm [si.to_rect]
		mov al,dobj.dl_rect.rc_col
		push ax
		call rcbprc
		push dx
		push ax
		mov al,dobj.dl_rect.rc_col
		mov ah,0
		push ax
		mov al,[si.to_rect.rc_col]
		push ax
		push ds
		push offset PButton
		call wcpbutt
		inc di
		add si,16
	    .until 0
	    invoke dlmodal, addr dobj
	    mov di,ax
	.endif
	.if di
	    mov al,dobj.dl_index
	    mov ah,0
	    shl ax,4
	    lea bx,tobj
	    add bx,ax
	    xor ax,ax
	    mov al,[bx+3]
	    sub al,'@'
	.else
	    xor ax,ax
    	.endif
	ret
_disk_select endp

_TEXT	ENDS

	END
