;///////////////////////////////////////////////////////////////////////////////
;/// @file strlen.asm
;///
;/// @brief Destiny3D Memory Manager strlen 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_strlen proc
	;Paramaters, char *Str1

	push ebx
	mov ebx, esp

	mov eax, [ebx + 08h]	;Str1
	mov edx, eax

	test eax, 3
	jz Find0

	and edx, 2
	cmp edx, 2
	je Align2
	jg Align3

	Align1:
		mov edx, eax
		add eax, 3
		mov ebx, [eax]
		jmp	short Find0_3

	Align2:
		mov edx, eax
		add eax, 2
		mov ebx, [eax]
		jmp short Find0_2

	Align3:
		mov edx, eax
		inc eax
		mov ebx, [eax]
		jmp short Find0_1

	;our processing loop
	Find0:
		;grab 4 bytes
		mov ebx, [eax]

		;test every byte from right to left
		and bl, 0FFh
		jz short Found0_1

	Find0_1:
		and bh, 0FFh
		jz short Found0_2

	Find0_2:
		test ebx, 000FF0000h
		jz short Found0_3

	Find0_3:
		test ebx, 0FF000000h
		jz short Found0_4

		;goto the next 4 bytes
		add eax, 4

		jmp short Find0

	Found0_1:
		sub eax, edx
		pop ebx
		ret

	Found0_2:
		inc eax
		sub eax, edx
		pop ebx
		ret

	Found0_3:
		add eax, 2
		sub eax, edx
		pop ebx
		ret

	Found0_4:
		add eax, 3
		sub eax, edx
		pop ebx
		ret

Internal_ASM_strlen endp

END