;; that is up to 32 characters in length. This version builds the table in
;; such a way that text searches will be independent of case.
;;
;; Call with: DS:SI -> Pattern
;;            ES:DI -> Characteristic vector table
;;               CX  = Pattern length
;;
;; Note: The characteristic vector table should contain 256 double words.

BuildCVTableIC  proc    near
                push    cx                      ;Save CX
                push    di                      ;Save DI
                cld                             ;Clear direction flag
                mov     cx,512                  ;Initialize counter
                xor     ax,ax                   ;Initialize the CVT so
                rep     stosw                   ;it contains all zeroes
                pop     di                      ;Restore DI
                pop     cx                      ;Restore CX

                mov     dx,8000h                ;Set DX:AX to 80000000h
                xor     ax,ax

BCVTIC1:        xor     bh,bh                   ;Initialize BH to 0
                mov     bl,[si]                 ;Get the next character
                inc     si                      ;Increment pointer
                shl     bx,1                    ;Multiply BX by 4 to compute
                shl     bx,1                    ;an index into the CVT
                or      es:[di+bx],ax           ;Set the bit that corresponds
                or      es:[di+bx+2],dx         ;to this position in the CVT

                cmp     bx,104h                 ;Branch if less than "A"
                jb      BCVTIC3
                cmp     bx,1E8h                 ;Branch if greater than "z"
                ja      BCVTIC3

                cmp     bx,168h                 ;Branch if greater than "Z"
                ja      BCVTIC2
                add     bx,80h                  ;Compute index for lowercase
                or      es:[di+bx],ax           ;Set the bit that corresponds
                or      es:[di+bx+2],dx         ;to this position in the CVT
                jmp     short BCVTIC3           ;Branch and continue looping

BCVTIC2:        cmp     bx,184h                 ;Branch if less than "a"
                jb      BCVTIC3
                sub     bx,80h                  ;Compute index for uppercase
                or      es:[di+bx],ax           ;Set the bit that corresponds
                or      es:[di+bx+2],dx         ;to this position in the CVT

BCVTIC3:        shr     dx,1                    ;Shift DX:AX right one bit
                rcr     ax,1
                loop    BCVTIC1                 ;Loop until done
                ret                             ;Return to caller
BuildCVTableIC  endp

