/***************************************************************************\ CRC-16 Calculcations Author : Greg Young, Z-World. These functions compute the 1021-CRC used in many applications (XModem, Opto-22 Networking, Etc.) These perform the same function as getcrc in MATH.LIB, but can work on larger blocks of memory. \***************************************************************************/ unsigned CRCByte ( char cByte ); unsigned CRCBlock ( void *pMem,unsigned wCount ); #asm ; .CRCByte : Shift One Byte into Current CRC-CCITT ; ; INPUT : ; HL = CRC Accumulator ; DE = Pointer to Data ; OUTPUT : ; HL = CRC Accumulator ; DE = DE + 1 .CRCByte:: push bc ; Protect BC ld b,8 ; B = Bit Counter ld a,(de) ; C = Next Data Byte ld c,a inc de ; Bump Input Pointer .CRCB0: ld a,c ; A.7 = Data.7 ^ CRC.15 xor h add hl,hl ; Accumulator <<= 1 jp p,.CRCB1 ; If A.7 Clear, Move to Next Bit ld a,10h ; Accumulator ^= 0x1021 xor h ld h,a ld a,21h xor l ld l,a .CRCB1: rl c ; Ready Next Bit djnz .CRCB0 ; Continue til All Bits Shifted pop bc ; Restore BC ret ; Done ; .CRCBlock : Compute CRC-CCITT for Block ; ; INPUT : ; HL = Accumulator ; DE = Data Input Pointer ; BC = Byte Counter ; OUTPUT : ; HL = Accumulator ; DE = DE + BC .CRCBlock:: call .CRCByte ; Shift in Next Byte dec bc ; Adjust Byte Count ld a,b ; Continue til Zero or c jr nz,.CRCBlock ret ; Done ; CRCByte : C Interface to .CRCByte CRCByte:: ld hl,2 ; DE = &Byte add hl,sp ex de,hl ld hl,0 ; HL = Accumulator jr .CRCByte ; Compute CRC ; CRCBlock : C Interface to .CRCBlock CRCBlock:: call .param2 ; HL = Input Pointer, DE = Byte Count ld b,d ; BC = Byte Count ld c,e ex de,hl ; DE = Input Data Pointer ld hl,0 ; HL = Accumulator jp .CRCBlock ; Compute CRC #endasm