1 REM Ins{nd av: Kristoffer Eriksson <5357>    1988-07-25 01.15.11 (WRITE)
; Fil: KERMCSUM.ASM
; Av:  Kristoffer Eriksson, "SKE" <5357>, 1987.
;
;-Ver--/-Datum----/-Sign-/-Kommentar----------------------------------
; 1.00 / 87-08-15 / SKE  / KERMCSUM
;
; Kontrollsummarutin till Bo Kullmars Kermit-program K.


;*  Summera str{ng f|r Kermit-kontrollsumma.
;*  In: DE = VAROOT(Str{ng$)
;*  Ut:  L = Summa, bittar 5-0,
;*       H = Summa, bittar 13-6.

Csum:       ex     de,hl
            inc    hl
            inc    hl
            ld     e,(hl)             ; DE <- Str{ngens adress.
            inc    hl
            ld     d,(hl)
            inc    hl
            ld     c,(hl)             ; BC <- Str{ngens l{ngd.
            inc    hl
            ld     b,(hl)
            ld     hl,0               ; HL <- Startsumma = 0.
Loop:       ld     a,c                ; Slut?
            or     b
            jr z   CEnd
            ld     a,(de)             ; Summera.
            add    l
            ld     l,a
            ld     a,0
            adc    h
            ld     h,a
            dec    bc
            inc    de
            jr     Loop

CEnd:       ld     a,l
            rlc    a
            rl     h
            rlc    a
            rl     h                  ; H <- bit 13-6.
            ld     a,l
            and    63
            ld     l,a                ; L <- bit 5-0.
            ret
