;
 ; --------------------------------------------------------------
 ;
 ; Function TextComp(sThis As String, _
 ;                   sThat As String) As Long
 ;
 ; Returns Lesser (-1), Equal (0) or Greater (1)
 ;
 ; --------------------------------------------------------------
 ;
 ; This procedure requires a module level integer array to be
 ; initialized by calling the UnsBuildTextCompTable sub-routine.
 ;
 ; Private lpTxtCmp As Long
 ; lpTxtCmp = UnsBuildTextCompTable ' Class Init before patch
 ;
 ; --------------------------------------------------------------
;

; nasm -f bin TextComp.asm -o TextComp.bin

 [bits 32]   ; start of code

   push esi
   push edi      ; preserve pointer registers
   push ebx

   mov esi,[esp+20]    ; copy this str descriptor
   mov edi,[esp+24]    ; copy that str descriptor
   mov esi,[esi]       ; get this string pointer
   mov edi,[edi]       ; get that string pointer
   xor eax, eax        ; zero eax default return

   test esi, esi       ; validate string pointer
   jz _this            ; invalid pointer, resolve
   test edi, edi       ; validate string pointer
   jz _that            ; invalid pointer, resolve

   mov ebx,2876543h    ; txtcmp SA patched on init
   mov ecx, -1         ; start pos zero offset - 1
   test ebx, ebx       ; validate txtcmp header
   jz _exitp           ; exit if null SA pointer

   mov edx,[ebx+16]    ; get cnt of lookup elements
   mov ebx,[ebx+12]    ; get first lookup address
   cmp edx, 10000h     ; check if count is valid
   jne _exitp          ; exit if not correctly init
   dec edx             ; prep chr holder/lookup idx

  _txtcomp:            ; perform text compare
   inc ecx             ; increment chr pos offset
   test dx, dx         ; test for null terminator
   jz _exitp           ; strings are equal
   mov dx,[esi+ecx*2]  ; get next this wchar
   mov dx,[ebx+edx*2]  ; assign lookup wchar
   mov ax,[edi+ecx*2]  ; get next that wchar
   cmp dx,[ebx+eax*2]  ; compare lookup chrs
   je _txtcomp

   sbb eax, eax
   js _exitp
   inc eax
   jmp _exitp

  _that:
   cmp eax,[esi-4]  ; compare str byte length
   rcl eax, 1
   jmp _exitp

  _this:
   test edi, edi    ; validate string pointer
   jz _exitp
   cmp eax,[edi-4]  ; compare str byte length
   sbb eax, eax

  _exitp:
   mov edx,[esp+28] ; copy return descriptor
   mov [edx], eax   ; assign function result

   pop ebx
   pop edi      ; restore registers
   pop esi

   xor eax, eax ; clear eax tell VB all okay
   ret 16       ; cleanup (lpObj, p1, p2, rc)

;
 ;Function TextComp(sThis As String, sThat As String) As Long
 ;   Dim iChrPos = 0&  ' Returns Lesser (-1), Equal (0) or Greater (1)
 ;   Select Case True
 ;     Case StrPtr(sThis) = 0&
 ;       If StrPtr(sThat) = 0& Then Else TextComp = -1&
 ;     Case StrPtr(sThat) = 0&
 ;       TextComp = 1&
 ;     Case Else
 ;       ThisStr.pvData = StrPtr(sThis)
 ;       ThatStr.pvData = StrPtr(sThat)
 ;       Do While ThisChrs(iChrPos) And (iaLCase(ThisChrs(iChrPos)) = iaLCase(ThatChrs(iChrPos)))
 ;          iChrPos = iChrPos + 1&
 ;       Loop
 ;       TextComp = Sgn(iaLCase(ThisChrs(iChrPos)) - iaLCase(ThatChrs(iChrPos)))
 ;   End Select
 ;End Function
;
