home *** CD-ROM | disk | FTP | other *** search
- ;----------------------------------------------------------------
- ; This is a module in the ASMLIB library
- ;
- ; This module uses the character issued to it in register a and
- ; uses the following polynomial to generate a 16 bit cyclic-
- ; redundancy checksum. The checksum is able to distinguish between
- ; two very similar text items since any differences in text quickly
- ; show up in the checksum. This is useful for data integrity checking
- ; in disk files or over modem lines etc.
- ;
- ; This module has 3 entry points which
- ;
- ; 1) Clear any accumulated crc.
- ; 2) Add a character to the current crc.
- ; 3) Return the current crc value.
- ;
- ; A cyclic-redundancy-check number is generated by the ccitt
- ; standard polynominal:
- ; x^16 + x^15 + x^13 + x^7 + x^4 + x^2 + x + 1
- ;
- ; The routine for doing this is in 8080 and comes from the
- ; 'EDN' magazine June 5 1979 issue Page 84. Written By Fred Gutman.
- ;
- ; Written R.C.H. 22/9/83
- ; Last Update R.C.H. 24/11/83
- ;----------------------------------------------------------------
- ;
- name 'CRC'
- public clrcrc,addcrc,getcrc
- ;
- ; This entry point clears the current CRC
- ;
- clrcrc:
- push h
- lxi h,0 ; do a clear
- shld rem
- pop h
- ret
- ;
- ; Return the accumulated CRC in the HL register
- ;
- getcrc:
- lhld rem
- ret
- ;
- ; Add the character in A to the current running CRC.
- ;
- addcrc:
- push h ; Save this from harm
- push psw ; Save the character too
- sta mess ; Save.
- divp:
- lhld rem ; get remainder
- mov a,h
- ani 128 ; q-bit mask
- push psw ; save status
- dad h ; 2 x r(x)
- lda mess ; message bit in lsb
- add l
- mov l,a
- pop psw
- jz qb2 ; if q-bit is zero
- qb: mov a,h
- xri 0a0h ; ms half of gen. poly
- mov h,a
- mov a,l
- xri 97h ; ls half of gen. poly
- mov l,a
- qb2: shld rem
- pop psw
- pop h
- ret
- ;
- ; Data storage
- ;
- dseg
- ;
- mess: db 0 ; char for crc calc
- rem: dw 0 ;crc remainder storage
- ;
- end