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

@vsbufin PROC
	xor	dx,dx
@vsbufin ENDP

@sprintf02 PROC
	push	bp
	sub	sp,18
	mov	bp,sp
	push	es
	push	cx
	push	bx
	or	dx,dx
	jnz	@sprintf02_00
	mov	dx,ss
	mov	bx,DZ_bufin
    @sprintf02_00:
	push	dx
	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
	mov	cx,bp	; FILE
	push	cs	; format string in CS:AX
	pop	es
	mov	bx,ax	; SS:CX, ES:BX, SS:DX
	mov	dx,sp
	add	dx,32
	mov	ah,_DZ_OUTPUT
	int	DZ
	les	bx,[bp]
	mov	byte ptr es:[bx],0
	pop	dx
	pop	bx
	pop	cx
	pop	es
	add	sp,18
	pop	bp
	ret
@sprintf02 ENDP

csprintf proc fastcall, buffer:word, format:word
	push	cs
	jmp	xprintf
csprintf endp

ssprintf proc fastcall, buffer:word, format:word
	push	ss
ssprintf endp

xprintf proc fastcall, buffer:word, format:word
	push	format
	mov	bx,buffer
	pop	ax
	pop	dx
xprintf endp

_sprintf PROC
	call	@sprintf02
	ret
_sprintf ENDP
