home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / BEEHIVE / COMMS / YAM.ARC / YAM89.CSM < prev    next >
Text File  |  1990-09-20  |  5KB  |  165 lines

  1. ;YAM89.CSM (YAM8 & YAM9 combined for BDSC v1.46)
  2. ;
  3. ;>>:yam8.asm 9-30-81
  4. ;
  5. ;CRCK is a program to read any CP/M file and print
  6. ;a CYCLIC-REDUNDANCY-CHECK number based on the
  7. ;CCITT standard polynominal:
  8. ;   X^16 + X^15 + X^13 + X^7 + X^4 + X^2 + X + 1
  9. ;
  10. ;Useful for checking accuracy of file transfers.
  11. ;More accurate than a simple checksum.
  12. ;
  13. ;**************************************************
  14. ;
  15. ;    unsigned crck(buffer, bufsize, oldcrc)
  16. ;
  17. ;    At start of packet, oldcrc is set to 0
  18. ;
  19. ;    crc is accumulated by:
  20. ;        oldcrc=crck(buffer, bufsize, oldcrc);
  21. ;
  22. ;    crck for file is final value of oldcrc
  23. ;
  24. ;    A Short History of this function and crckfile() in yam7.c"
  25. ;
  26. ;    1.  First version used getc and called crck once per char.
  27. ;    this took 39.2 seconds to crck all the yam C files (12357)
  28. ;
  29. ;    2.  Then crckfile was recoded to use read() instead of getc.
  30. ;    Time: 19.1 seconds
  31. ;
  32. ;    3.  Several small changes in crckfile were unsuccessful in
  33. ;    reducing this time.
  34. ;
  35. ;    4.  crck and crckfile recoded to call crck once per sector.
  36. ;    This reduced time to 11.7 seconds, same as crck itself.
  37. ;    That is the current version.  Note that the CRC polynomial used
  38. ;    here is somewhat unusual; the only thing I know sure is that
  39. ;    the answers agree with those given by the CRCK program -hence the
  40. ;    function name.
  41. ;
  42.     maclib bds
  43.  
  44.     function crck
  45.  
  46.     call    arghak
  47.     push    b
  48. bytlop:    lhld    arg1
  49.     mov    c,m
  50.     inx    h        ;fetch (next) byte from buffer
  51.     shld    arg1
  52.     lhld    arg3        ; get accumulated checksum
  53. ;
  54. ;---------------------------------------------
  55. ;An 8080 routine for generating a CYCLIC-
  56. ;REDUNDANCY-CHECK.  Character leaves that
  57. ;character in location REM.  By Fred Gutman.
  58. ;From 'EDN' magazine, June 5, 1979 issue, page 84.
  59. ;
  60. DIVP:
  61.     MOV    A,H
  62.     ANI    128    ;Q-BIT MASK
  63.     PUSH    PSW    ;SAVE STATUS
  64.     DAD    H    ;2 X R(X)
  65.     mov    a,c
  66.     ADD    L
  67.     MOV    L,A
  68.     POP    PSW
  69.     JZ    QB2    ;IF Q-BIT IS ZERO
  70.     MOV    A,H
  71.     XRI    0A0H    ;MS HALF OF GEN. POLY
  72.     MOV    H,A
  73.     MOV    A,L
  74.     XRI    97H    ;LS HALF OF GEN. POLY
  75.     MOV    L,A
  76. QB2:
  77.     shld    arg3    ;store in accumulator
  78.     lhld    arg2
  79.     dcx    h
  80.     shld    arg2    ;count number of bytes in buffer
  81.     mov    a,h
  82.     ora    l
  83.     jnz    bytlop
  84.     lhld    arg3    ;return with accumulated crck in HL
  85.     pop    b    ;pull up ur shorts
  86.     RET
  87.  
  88.     endfunction
  89. ;>>:yam9.asm 9-30-81
  90. ;************************************************************************
  91. ;* CRCSUBS (Cyclic Redundancy Code Subroutines) version 1.20        *
  92. ;* 8080 Mnemonics                            *
  93. ;*                                    *
  94. ;*         This subroutine will compute and check a true 16-bit        *
  95. ;*    Cyclic Redundancy Code for a message of arbitrary length.    *
  96. ;*                                    *
  97. ;*    The  use  of this scheme will guarantee detection of all    *
  98. ;*    single and double bit errors, all  errors  with  an  odd    *
  99. ;*    number  of  error bits, all burst errors of length 16 or    *
  100. ;*    less, 99.9969% of all 17-bit error bursts, and  99.9984%    *
  101. ;*    of  all  possible  longer  error bursts.  (Ref: Computer    *
  102. ;*    Networks, Andrew S.  Tanenbaum, Prentiss-Hall, 1981)        *
  103. ;*                                    *
  104. ;*                                    *
  105. ;************************************************************************
  106. ;*                                    *
  107. ;*    From: CRCSUB12.ASM                        *
  108. ;*    Designed & coded by Paul Hansknecht, June 13, 1981        *
  109. ;*                                    *
  110. ;*                                    *
  111. ;*    Copyright (c) 1981, Carpenter Associates            *
  112. ;*                Box 451                    *
  113. ;*                Bloomfield Hills, MI 48013            *
  114. ;*                313/855-3074                *
  115. ;*                                    *
  116. ;*    This program may be freely reproduced for non-profit use.    *
  117. ;*                                    *
  118. ;************************************************************************
  119. ;
  120. ;    unsigned updcrc(char, oldcrc)
  121. ;
  122. ;    At start of packet, oldcrc is set to initial value
  123. ;        oldcrc=0;
  124. ;
  125. ;    crc is accumulated by:
  126. ;        oldcrc=updcrc(char, oldcrc);
  127. ;
  128. ;    at end of packet,
  129. ;        oldcrc=updcrc(0,updcrc(0,oldcrc));
  130. ;        send(oldcrc>>8); send(oldcrc);
  131. ;
  132. ;    on receive, the return value of updcrc is checked after the
  133. ;    last call (with the second CRC byte); 0 indicates no error detected
  134. ;
  135.  
  136.     function updcrc
  137.  
  138.     push    b        ;save stack frame
  139.     call    ma2toh        ;get char
  140.     mov    c,a
  141.     call    ma3toh        ;and olde crc value
  142.     MVI    B,8
  143. UPDLOOP:MOV    A,C
  144.     RLC
  145.     MOV    C,A
  146.     MOV    A,L
  147.     RAL
  148.     MOV    L,A
  149.     MOV    A,H
  150.     RAL
  151.     MOV    H,A
  152.     JNC    SKIPIT
  153.     MOV    A,H        ; The generator is X^16 + X^12 + X^5 + 1
  154.     XRI    10H        ; as recommended by CCITT.
  155.     MOV    H,A        ; An alternate generator which is often
  156.     MOV    A,L        ; used in synchronous transmission protocols
  157.     XRI    21H        ; is X^16 + X^15 + X^2 + 1. This may be
  158.     MOV    L,A        ; used by substituting XOR 80H for XOR 10H
  159. SKIPIT:    DCR    B        ; and XOR 05H for XOR 21H in the adjacent code.
  160.     JNZ    UPDLOOP
  161.     POP    B
  162.     RET            ; return with latest crc in hl
  163.  
  164.     endfunction
  165.