home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
simtel
/
sigm
/
vols000
/
vol089
/
scrc1.mac
< prev
next >
Wrap
Text File
|
1984-04-29
|
4KB
|
143 lines
;
; SYSLIB Module Name: SCRC1
; Author: Richard Conn
; SYSLIB Version Number: 2.0
; Module Version Number: 1.0
; Module Entry Points:
; CRC1CLR CRC1DONE CRC1K CRC1UPD
; Module External References:
; None
;
;
; These subroutines will compute and check a true 16-bit
; Cyclic Redundancy Code for a message of arbitrary length.
;
; The use of this 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)
;
; These routines are typically used as follows:
; CRC1$MAKE: ; ROUTINE TO ESTABLISH CRC VALUE
; CALL CRC1CLR ; CLEAR CRC
; <loop CALLing CRC1UPD> ; ACQUIRE VALUES
; CALL CRC1DONE ; GET VALUE
; SHLD CRC1VAL ; SAVE VALUE
; CRC1$CHECK: ; ROUTINE TO CHECK CRC VALUE
; CALL CRC1CLR ; CLEAR CRC1
; <loop CALLing CRC1UPD> ; ACQUIRE VALUES
; LHLD CRC1VAL ; FROM BEFORE
; MOV A,H ; SEND HIGH TO UPDATE
; CALL CRC1UPD
; MOV A,L ; SEND LOW TO UPDATE
; CALL CRC1UPD
; CALL CRC1DONE ; NOW DONE
; CALL CRC1K ; RETURN Z IF OK, NZ IF NOT
;
;
; CRC1CLR - Clear the CRC accumulator
; This routine must be called at the start of each byte stream.
;
; Input Parameters: None
;
; Output Parameters: None
;
CRC1CLR::
PUSH H
LXI H,0 ;SET CRC TO ZERO
SHLD CRCVAL
POP H
RET
;
; BUFFER FOR CRC VALUE
;
CRCVAL: DS 2
;
; CRC1UPD - Update the CRC accumulator
; This routine must be called once for each byte in the
; byte stream for which the CRC is being calculated.
;
; Input Parameters: A = byte to be included in CRC
;
; Output Parameters: None
;
CRC1UPD::
PUSH PSW ;SAVE ALL REGS
PUSH B
PUSH H
MVI B,8 ;ROTATE 8 BITS
MOV C,A ;BYTE IN C
LHLD CRCVAL ;HL=OLD CRC VALUE
UPDLOOP:
MOV A,C ;ROTATE HLC AS A 24-BIT ACC LEFT 1 BIT
RLC
MOV C,A
MOV A,L
RAL
MOV L,A
MOV A,H
RAL
MOV H,A
JNC SKIPIT
MOV A,H ; The generator is X^16 + X^15 + X^2 + 1
XRI 80H ; as recommended by CCITT.
MOV H,A ; An alternate generator which is often
MOV A,L ; used in synchronous transmission protocols
XRI 05H ; is X^16 + X^12 + X^5 + 1. This may be
MOV L,A ; used by substituting XOR 10H for XOR 80H
SKIPIT: ; and XOR 21H for XOR 05H in the adjacent code.
DCR B ;COUNT DOWN 8 BITS
JNZ UPDLOOP
SHLD CRCVAL ;SAVE NEW CRC VALUE
POP H ;RESTORE ALL
POP B
POP PSW
RET
;
; CRC1DONE - Complete the CRC calculation
; This routine is called after the last byte of the byte stream
; has passed thru CRC1UPD, and it returns the calculated
; CRC bytes, which must be transmitted as the final
; two bytes of the message (first H, then L).
;
; Input Parameters: None
;
; Output Parameters: HL = calculated CRC bytes
;
CRC1DONE::
PUSH PSW ;SAVE A
XRA A ;SEND OUT 2 ZEROES
CALL CRC1UPD
CALL CRC1UPD
LHLD CRCVAL ;RETURN CRC VALUE IN HL
POP PSW
RET
;
; CRC1K - Check the CRC bytes of the RECEIVED byte stream and return an error
; code to indicate whether the stream was received correctly. It must
; be called after the stream and the two CRC bytes
; have been received and passed thru CRC1UPD.
;
; Input Parameters: None
;
; Output Parameters: A = 0 if message ok (Z)
; A = 0FFH if message garbled (NZ)
;
CRC1K::
PUSH H ;SAVE HL
LHLD CRCVAL ;GET CRC VALUE
MOV A,H ;CHECK FOR ZERO
ORA L
POP H
RZ
MVI A,0FFH ;ERROR CODE
RET
END