include	clib.inc
include	wsub.inc
include	malloc.inc

PPROC wsfree, wsub:dword
	push	si
	push	di
	les	bx,wsub
	xor	ax,ax
	cmp	word ptr es:[bx.ws_fcb],ax
	mov	es:[bx.ws_count],ax
	jz	wsfree_end
	mov	di,ax
	mov	si,ax
	jmp	wsfree_init
    wsfree_loop:
	les	bx,wsub
	les	bx,es:[bx.ws_fcb]
	mov	ax,si
	shl	ax,2
	add	bx,ax
	xor	ax,ax
	cmp	ax,es:[bx]
	jz	wsfree_next
	pushm	es:[bx]
	mov	es:[bx],ax
	call	free
	inc	di
    wsfree_next:
	inc	si
    wsfree_init:
	les	bx,wsub
	cmp	es:[bx+2],si
	jg	wsfree_loop
	mov	ax,di
    wsfree_end:
	pop	di
	pop	si
	ret
PEND	wsfree

	END
