
	SECTION .text	

	GLOBAL _simple2x_16
	
	inbuffer     equ 8
	srcPitch     equ 12
	outbuffer    equ 16
	dstPitch     equ 20
	Xres         equ 24
	Yres         equ 28

 
	_simple2x_16:
	
		push ebp
		mov ebp,esp
		push eax
		push esi
		push ebx
		push edi
		push ecx
		
		mov			esi, [ebp+inbuffer]
		mov         eax, [ebp+Xres]
		shr			eax, 2
		mov         [ebp+Xres],eax
		mov			edi, [ebp+outbuffer]
		mov			edx, edi
		add			edx, [ebp+dstPitch]
		mov			ecx, [ebp+Yres]
		;fix tiger heli and others
		mov         ebx,[ebp+srcPitch]
		shl         ebx,1
		mov         eax,[ebp+dstPitch]
		sub         eax,ebx
		add         [ebp+dstPitch],eax

		;align 4
.label0   
		mov			eax, [ebp+Xres]
		;align 4
.label1   
		movq		mm0,[esi]
		movq		mm1, mm0
		punpcklwd   mm0,mm0
		punpckhwd   mm1,mm1
		movq		[edi], mm0
		movq		[edx], mm0
		movq		[edi+8], mm1
		movq		[edx+8], mm1	
		add			esi, 8
		add			edi, 16
		add			edx, 16
		dec			eax
    	jnz			.label1

		add			edi, [ebp+dstPitch]
		add			edx, [ebp+dstPitch] 

		dec			ecx 
		jnz			.label0

		;emms 
		
		pop ecx
		pop edi
		pop ebx
		pop esi
		pop eax 
		pop ebp
		ret