;Copyright 2000 - Mark McDonald All rights reserved
; DECLARE: FUNCTION getchksum(BYVAL string) AS INTEGER
; GETCHKSUM(STRING)
;     Returns an integer checksum of STRING.
;     EXAMPLE:  T = GETCHKSUM("HELLO WORLD")    796

Extrn   Get$Loc: Far
Extrn   Rls$Alloc: Far

MCODE Segment Byte
        Assume  CS: MCODE

        Public  getchksum

getchksum Proc Far

ARG     StrHandle: WORD = Retbytes

        push    BP                      ;
        mov     BP,SP                   ;
        push    DS                      ;

        mov     AX, StrHandle           ; put string handle in AX
        push    AX                      ; push it on the on stack
        call    Get$Loc                 ; get location of string
        mov     DS,DX                   ; put segment in DS
        mov     SI,AX                   ; put offset in SI
        xor     AX,AX                   ; clear AX
        jcxz    Exit                    ; is string null?
        xor     BX,BX                   ; clear BX
ReadChar:
        lodsb                           ; load a character
        add     BX,AX                   ; add char val to the total
        loop    ReadChar                ; do it CX times
        mov     AX,BX                   ; put checksum in AX
Exit:
        push    AX                      ; save return val
        push    Word Ptr StrHandle      ; push string handle
        call    Rls$Alloc               ; release string
        pop     AX                      ; restore return val
        pop     DS                      ;
        pop     BP                      ;
        retf    Retbytes                ;
getchksum EndP
MCODE EndS
        End