;///////////////////////////////////////////////////////////////////////////////
;/// @file memcmp.asm
;///
;/// @brief Destiny3D Memory Manager memcmp replacement
;///
;/// @author Lightning
;///
;/// This file is the intellectual property of Novus Delta, LLC.. Usage of the
;/// contents of this file is subject to the Destiny3D Member License which
;/// can be found at http://www.destiny3d.com.  Any other usage is prohibited.
;///
;/// This file is distributed "AS IS" without warranty of any kind.  Novus
;/// Delta, LLC. does not guarantee the fitness of the contents of this file
;/// for any particular purpose.
;///
;/// Copyright (C) 2001-2003 Novus Delta, LLC. All Rights Reserved.
;///
;/// <hr>
;///                                 Change History
;/// <hr>
;///
;/// @date May 2001
;/// @author Lightning
;/// @remarks Creation
;///
;///////////////////////////////////////////////////////////////////////////////


.586p					;pentium commands allowed
.mmx					;MMX allowed
.k3d					;3DNow allowed
.model flat, C

.CODE

;i take care of pushing and popping edi, esi, ebp, and ebx if I need to use them
;as it makes it easier to cut down on the code that the function goes thru

Internal_ASM_memcmp proc
	;the Paramaters are void *Ptr1, void *Ptr2, long Len

	push ebx
	mov ebx, esp
	align 4

	;divide by 16, edx = remainder
	mov eax, [ebx + 10h]	;Len
	mov edx, [ebx + 08h]	;Ptr1
	mov ebx, [ebx + 0Ch]	;Ptr2

	push eax

	and eax, 0FFFFFFFCh
	jz Do3Bytes

	MemchrLoop:
		mov ecx, [edx]
		xor ecx, [ebx]
		jnz short NoMatch

		add edx, 4
		add ebx, 4
		sub eax, 4
		jnz short MemchrLoop


	Do3Bytes:
		pop eax
		push eax
		and eax, 3
		jmp dword ptr CheckArray[eax * 4]

	CheckArray dd CheckDone, Check1, Check2, Check3

	Check1:
		mov cl, [edx]
		mov ch, [ebx]
		cmp cl, ch
		jb Ptr1Smaller
		jg Ptr2Smaller

		pop ecx
		pop ebx
		xor eax, eax
		ret

	Check2:
		mov cx, [edx]
		mov dx, [ebx]
		xchg cl, ch
		xchg dl, dh
		cmp cx, dx
		jb Ptr1Smaller
		jg Ptr2Smaller

		pop ecx
		pop ebx
		xor eax, eax
		ret

	Check3:
		mov ecx, [edx]
		mov edx, [ebx]
		and ecx, 000FFFFFFh
		and edx, 000FFFFFFh
		bswap ecx
		bswap edx
		cmp ecx, edx
		jb Ptr1Smaller
		jg Ptr2Smaller

		pop ecx
		pop ebx
		xor eax, eax
		ret

	CheckDone:
		pop ecx
		pop ebx
		xor eax, eax
		ret

	NoMatch:
		mov ebx, [ebx]
		xor ecx, ebx
		bswap ecx
		bswap ebx
		cmp ecx, ebx
		jg Ptr2Smaller

	Ptr1Smaller:
		pop ecx
		pop ebx
		xor eax, eax
		dec eax
		ret

	Ptr2Smaller:
		pop ecx
		pop ebx
		xor eax, eax
		inc al
		ret

Internal_ASM_memcmp endp

END