include	clib.inc
include	malloc.inc
include	conio.inc

	assume	bx:ptr S_DOBJ

PPROC	dlclose, dobj:dword
	push ax		; AX on init returned in DX
	invoke dlhide, dobj
	push ax		; if visible returned in CX
	invoke rcclose, es:[bx].dl_rect, es:[bx].dl_flag, es:[bx].dl_wp
	push ax		; if open returned in AX
	les bx,dobj
	mov ax,es:[bx]
	and ax,_D_MYBUF or _D_RCNEW
	.if ZERO?
	    mov word ptr es:[bx].dl_wp,ax
	    mov word ptr es:[bx].dl_wp+2,ax
	.endif
    	.if ax & _D_RCNEW
	    invoke free, es::bx
	.else
    	    and es:[bx].dl_flag,not _D_DOPEN
	.endif
	pop ax
	pop cx
	pop dx
	ret
PEND	dlclose

	END
