home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol158 / crck.a86 < prev    next >
Encoding:
Text File  |  1984-04-29  |  2.0 KB  |  80 lines

  1. ;>>:yam8.csm 7-31-82
  2. ; converted to a86 for use with CI C86, 10-15-83, pjh
  3. ;
  4. ;CRCK is a program to read any CP/M file and print
  5. ;a CYCLIC-REDUNDANCY-CHECK number based on the
  6. ;CCITT standard polynominal:
  7. ;   X^16 + X^15 + X^13 + X^7 + X^4 + X^2 + X + 1
  8. ;
  9. ;Useful for checking accuracy of file transfers.
  10. ;More accurate than a simple checksum.
  11. ;
  12. ;**************************************************
  13. ;
  14. ;    unsigned crck(buffer, bufsize, oldcrc)
  15. ;
  16. ;    At start of packet, oldcrc is set to 0
  17. ;
  18. ;    crc is accumulated by:
  19. ;        oldcrc=crck(buffer, bufsize, oldcrc);
  20. ;
  21. ;    crck for file is final value of oldcrc
  22. ;
  23. ;    A Short Hostory of this function and crckfile() in yam7.c"
  24. ;
  25. ;    1.  First version used getc and called crck once per char.
  26. ;    this took 39.2 seconds to crck all the yam C files (12357)
  27. ;
  28. ;    2.  Then crckfile was recoded to use read() instead of getc.
  29. ;    Time: 19.1 seconds
  30. ;
  31. ;    3.  Several small changes in crckfile were unsuccessful in
  32. ;    reducing this time.
  33. ;
  34. ;    4.  crck and crckfile recoded to call crck once per sector.
  35. ;    This reduced time to 11.7 seconds, same as crck itself.
  36. ;    That is the current version.  Note that the CRC polynomial used
  37. ;    here is somewhat unusual; the only thing I know sure is that
  38. ;    the answers agree with those given by the CRCK program -hence the
  39. ;    function name.
  40. ;
  41.  
  42. DEFCGBL    equ    0c1h
  43. DEFDGBL    equ    0c2h
  44. RELCGBL    equ    0c3h
  45. ABSCGBL    equ    0c4h
  46.  
  47.     cseg
  48.  
  49. crck:    push    bp
  50.     mov    bp,sp
  51.     mov    bx,4[bp]    ; get buffer pointer
  52.     mov    cx,6[bp]    ; get buffer size
  53.     mov    dx,8[bp]    ; get oldcrc
  54. ;
  55. ;---------------------------------------------
  56. ;Bsed on an 8080 routine for generating a
  57. ;CYCLIC-REDUNDANCY-CHECK by Fred Gutman.
  58. ;From 'EDN' magazine, June 5, 1979 issue, page 84.
  59. ;
  60. bytlop:    test    dh,128        ; Q-bit mask
  61.     pushf            ; save status
  62.     add    dx,dx        ; 2 x r(x)
  63.     add    dl,[bx]        ; add byte from buffer
  64.     inc    bx        ; increment pointer to next byte
  65.     popf            ; retreive Q-bit status
  66.     jz    qb2        ; if Q-bit is zero
  67.     xor    dx,0a097h    ; gen. poly
  68. qb2:    loop    bytlop        ; do till buffer m-t
  69.     mov    ax,dx        ; answer in accumulator for return
  70.     pop    bp
  71.     ret
  72.  
  73.     eseg
  74.  
  75.     dw    crck
  76.     db    DEFCGBL,'crck',0
  77.     dw    0,0
  78.  
  79.     end
  80.