include	clib.inc
include	string.inc

PPROC	wcstrcpy, cp:dword, wc:dword, count:word
	push	ds
	push	si
	push	di
	les	di,cp
	push	es
	push	di
	lds	si,wc
	mov	cx,count
	mov	dx,es
	cld
    wcstrcpy_start:
	test	cx,cx
	jz	wcstrcpy_end
	dec	cx
	lodsw
	cmp	al,' '
	jbe	wcstrcpy_start
	cmp	al,176
	ja	wcstrcpy_start
	sub	si,2
	test	cx,cx
	jz	wcstrcpy_end
    wcstrcpy_loop:
	lodsw
	cmp	al,176
	ja	wcstrcpy_end
	and	ah,0Fh
	cmp	ah,12
	jb	wcstrcpy_cpy
	mov	ah,al
	mov	al,'&'
	stosb
	mov	al,ah
    wcstrcpy_cpy:
	stosb
	dec	cx
	jnz	wcstrcpy_loop
    wcstrcpy_end:
	xor	ax,ax
	stosb
	call	strtrim
	pop	di
	pop	si
	pop	ds
	ret
PEND	wcstrcpy

	END
