; TITLE "SCRC - Syslib 4.0" NAME ('CRC') ;================================================================= ; The Libraries, Version 4, (C) 1989 by Alpha Systems Corp. ;----------------------------------------------------------------- ; Author : Harold F. Bower ; Derived from SCRC.Z80 Ver 1.1 by Richard Conn ; Date : 17 Sep 89 ; Version : 1.2 ; Module : SCRC ; Abstract: This module contains the routines CRCCLR, CRCDONE ; and CRCUPD which implement the X^16 + X^12 + X^5 + 1 ; Cyclic Redundancy Code polynomial as recommended by CCITT. ; The use of this error detection scheme will guarantee ; detection of all single and double bit errors, all errors ; with an odd number of error bits, all burst errors of ; length 16 or less, 99.9969% of all 17-bit error bursts, ; and 99.9984% of all possible longer error bursts. (Ref: ; Computer Networks, Andrew S. Tanenbaum, Prentiss-Hall, 1981) ; This routine is typically used as follows: ; CRC$MAKE: ; ROUTINE TO ESTABLISH CRC VALUE ; CALL CRCCLR ; CLEAR CRC ; ; ACQUIRE VALUES ; CALL CRCDONE ; GET VALUE ; LD (CRCVAL),HL ; SAVE VALUE ; CRC$CHECK: ; ROUTINE TO CHECK CRC VALUE ; CALL CRCCLR ; CLEAR CRC ; ; ACQUIRE VALUES ; CALL CRCDONE ; DONE ; EX DE,HL ; VALUE IN DE ; LD HL,(CRCVAL) ; FROM BEFORE ; CALL COMPHD ; COMPARE HL TO DE (SYSLIB ROUTINE) ; JP NZ,ERROR ; ERROR IF NOT SAME ; Revision: ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ; Module Entry Points PUBLIC CRCCLR, CRCDONE, CRCUPD .Z80 CSEG ;=============================================================== ; NAME - CRCCLR ; Entry: - None ; Exit : - None ; Uses : - None ; Special Requirements: None ;=============================================================== CRCCLR: PUSH HL LD HL,0 ; Set CRC to zero LD (CRCVAL),HL POP HL RET ;=============================================================== ; NAME - CRCUPD ; Entry: A - Contains byte to be included in CRC calculation ; Exit : - None ; Uses : - None ; Special Requirements: None ;=============================================================== CRCUPD: PUSH AF ; Save all Regs PUSH BC PUSH HL LD B,8 ; Rotate 8 Bits LD C,A ; Byte in C LD HL,(CRCVAL) ; HL = Old CRC value UPDLOOP: RL C ; Rotate HLC as a 24-BIT Acc Left 1 Bit ADC HL,HL JR NC,SKIPIT LD A,H ; The generator is X^16 + X^12 + X^5 + 1 XOR 10H ; as recommended by CCITT. LD H,A ; An alternate generator which is often LD A,L ; used in synch transmission protocols XOR 21H ; is X^16 + X^15 + X^2 + 1. This may be LD L,A ; used by subbing XOR 80H for XOR 10H ; and XOR 05H for XOR 21H in this code. SKIPIT: DJNZ UPDLOOP ; Count down 8 bits LD (CRCVAL),HL ; Save new CRC value POP HL ; Restore all POP BC POP AF RET ;=============================================================== ; NAME - CRCDONE - Contains final 2 bytes. Send H then L. ; Entry: - None ; Exit : HL - Contains the calculated 16-bit CRC value ; Uses : HL ; Special Requirements: None ;=============================================================== CRCDONE: PUSH AF ; Save A XOR A ; Send out 2 Zeroes CALL CRCUPD CALL CRCUPD LD HL,(CRCVAL) ; Return CRC value in HL POP AF RET ; Buffer for CRC value DSEG ; Put in Data Segment CRCVAL: DEFS 2 END