
;===============
;
; CHECK_CALC
;
;   Routine to compute a running check byte value from a string
;   of data. This computes the check value from the string
;   addressed at the R0 memory pointer for the count of bytes
;   specified in the entry R1 register. The resulting check 
;   byte value is returned in the A register. This simple
;   check routine XOR's the new byte with the running value
;   and then rotates the result left by one bit and then adds
;   one with the rotated carry ignoring the resulting carry.
;
;   Entry:
;     R0 = Pointer to memory data to compute 
;     R1 = Count of bytes to compute.
;   Exit:
;     A = Computed CHECK value.
;     R0 & R1 are modified
;   Uses:
;     B  But value is saved
;
CHECK_CALC:
    PUSH    B        ;save this becasue we use it
    MOV     B, #0    ;init the check value
CHECK_LP:
    MOV     A, @R0   ;fetch a byte
    XRL     A, B     ;XOR the values
    CLR     C        ;make sure carry is clear
    RLC     A        ;rotate left
    ADDC    A, #1    ;add 1 plus carry back in
    MOV     B, A     ;update running value
    INC     R0       ;bump buffer pointer
    DJNZ    R1, CHECK_LP   ;loop till all bytes complete
    MOV     A, B     ;align return value
    POP     B        ;restore reg we used
    RET
