;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;	DRAWSUP.ASM
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
?STD = 1				;Use standard (stdcall) calling convention.
?WIN = 0				;No Windows prolog/epilog needed
?386Regs = 1

.xlist
include cmacro32.inc
include caviarhw.inc
.list
.386
.model flat


;__________________________________________________________________________
;
;	========        3 2 - B I T   S E G M E N T        ========
;__________________________________________________________________________
SEGNAME32	equ	ASM_TEXT32
createSeg %SEGNAME32, CodeSeg32, dword, public, CODE

sBegin CodeSeg32

;----------------------------------------------------------------------
;  Copy a yuv422 buffer into a YUY2 DCI surface
;
cProc cpYCHtoYUY2 <NEAR,STD,PUBLIC> <EBX,ESI,EDI>
	ParmD	lpYCH
	ParmD	lpYUY2
	ParmD	dwWidth
	ParmD	dwHeight
	ParmD	lNextLine

cBegin
	mov	esi,lpYCH		; esi = source
	mov	edi,lpYUY2		; edi = destination
	mov	eax,dwHeight		; Line count
	mov	ebx,dwWidth		; Width in bytes
	shl	ebx,1			; /
	mov	edx,lNextLine		; Offset to next line from end of current line
	sub	edx,ebx			; /
	shr	ebx,2			; Width in dwords

@@:	mov	ecx,ebx			; Dword count
   rep	movsd	[edi],[esi]		; Move a line
	add	edi,edx			; To next line
	dec	eax			; Done?
	jnz	@B			; No
cEnd


;----------------------------------------------------------------------
;  Copy a yuv422 buffer into a YUY2 DCI surface and eliminate the chroma
;
cProc cpYCHtoYUY2grey <NEAR,STD,PUBLIC>, <EBX,ESI,EDI>
	ParmD	lpYCH
	ParmD	lpYUY2
	ParmD	dwWidth
	ParmD	dwHeight
	ParmD	lNextLine

cBegin
	mov	esi,lpYCH		; esi = source
	mov	edi,lpYUY2		; edi = destination
	mov	eax,dwHeight		; Line count
	mov	ebx,dwWidth		; Width in bytes
	shl	ebx,1			; /
	mov	edx,lNextLine		; Offset to next line from end of current line
	sub	edx,ebx			; /
	shr	ebx,2			; Width in duals
	mov	ecx,ebx			; Dual count
	push	ebp			; Use EBP for line counter
	mov	ebp,eax			; /

	align	4
@@:	mov	eax,[esi]		; V:Y:U:Y
	add	esi,4			; Next input dual
	and	eax,00FF00FFh		; Chromas to 0
	or	eax,80008000h		; Chromas to 80h
	mov	[edi],eax		; Output grey dual
	add	edi,4			; Next output dual
	dec	ecx			; Dual count
	jnz	@B			; Loop
	add	edi,edx			; To next line
	mov	ecx,ebx			; Dual count
	dec	ebp			; Done?
	jnz	@B			; No

	pop	ebp			; Restore EBP
cEnd


sEnd

end
