; int sprintf(char *dest, char *format, ...)
;
; Entry:	AX	format string (DS:AX)
;		DX:BX	string buffer
; Uses:		AX
; Return:	Number of bytes output

include	clib.inc
include	stdio.inc

	public	@vsbufin
	public	@sprintf

_TEXT	SEGMENT

@vsbufin PROC
	xor	dx,dx
@vsbufin ENDP

@sprintf02:
	push	bp
	sub	sp,18
	mov	bp,sp
	push	es
	push	cx
	push	bx
	test	dx,dx
	jnz	@F
	mov	dx,ds
	mov	bx,offset _bufin
    @@:
	push	dx
	push	ss	; FILE
	push	bp
	push	ds	; format string in AX
	push	ax
	mov	word ptr [bp.iob_bp],bx
	mov	word ptr [bp.iob_bp+2],dx
	mov	word ptr [bp.iob_base],bx
	mov	word ptr [bp.iob_base+2],dx
	mov	[bp.iob_cnt],7FFFh
	mov	[bp.iob_flag],0042h
	add	bp,20+ARG1
	push	ss
	push	bp
	call	_output
	les	bx,[bp-20-ARG1]
	mov	byte ptr es:[bx],0
	pop	dx
	pop	bx
	pop	cx
	pop	es
	add	sp,18
	pop	bp
	ret

@sprintf PROC DIST
	call	@sprintf02
	ret
@sprintf ENDP

_TEXT	ENDS

	END
