home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sys / cbm / 3617 < prev    next >
Encoding:
Text File  |  1992-09-09  |  2.0 KB  |  76 lines

  1. Newsgroups: comp.sys.cbm
  2. Path: sparky!uunet!elroy.jpl.nasa.gov!usc!sol.ctr.columbia.edu!destroyer!ubc-cs!unixg.ubc.ca!kakwa.ucs.ualberta.ca!access.usask.ca!ccu.umanitoba.ca!shad04
  3. From: shad04@ccu.umanitoba.ca (Dan Fandrich)
  4. Subject: Re: 16 bit CRC source?
  5. Message-ID: <1992Sep9.094328.16978@ccu.umanitoba.ca>
  6. Summary: Actual code!
  7. Organization: University of Manitoba, Winnipeg, Manitoba, Canada
  8. References: <ioVNqB1w164w@jwt.UUCP>
  9. Date: Wed, 9 Sep 1992 09:43:28 GMT
  10. Lines: 64
  11.  
  12. In article <ioVNqB1w164w@jwt.UUCP> bbs-artmoore@jwt.UUCP writes:
  13. >Am looking for either 16-bit CRC source code (64/128) or the 
  14. >equation/tables.
  15.  
  16. Here's a 6502 code fragment to calculate a 16-bit CRC from my nearly finished
  17. C64 ZMODEM implementation (which has fallen by the wayside -- anyone 
  18. interested in finishing it?).
  19.  
  20. -------- cut here
  21. ;
  22. ;Calculate 16-bit CRC on a data block
  23. ;by Daniel Fandrich <shad04@ccu.umanitoba.ca>
  24. ;
  25. ;This algorithm is the same as used in ZMODEM's CRC-16 fallback mode.
  26. ;
  27. ;To use: 
  28. ;  1) store 0 in crc and crc+1
  29. ;  2) call updcrc once for each byte in the data block
  30. ;  3) call updcrc twice with the block's two CRC-16 bytes
  31. ;  4) if the result in crc and crc+1 are both 0, the data block is correct
  32. ;
  33. crc      = $fb
  34. temp     = $fd
  35.  
  36. updcrc   sta    temp
  37.          pha
  38.          txa
  39.          pha
  40.          ldx    #$07
  41. crc1     bit    crc+1
  42.          bpl    crc2
  43.          jsr    crccal
  44.          lda    crc+1
  45.          eor    #$10
  46.          sta    crc+1
  47.          lda    crc
  48.          eor    #$21
  49.          sta    crc
  50.          clc
  51.          bcc    crc3
  52. crc2     jsr    crccal
  53. crc3     dex
  54.          bpl    crc1
  55.          pla
  56.          tax
  57.          pla
  58.          rts                    ;exit routine
  59. ;
  60. crccal   asl    crc
  61.          rol    crc+1
  62.          asl    temp
  63.          lda    crc
  64.          adc    #0
  65.          sta    crc
  66.          lda    crc+1
  67.          adc    #0
  68.          sta    crc+1
  69.          rts
  70. ;end of source fragment
  71. -------- cut here
  72.  
  73. >>> Dan
  74. -- 
  75. Internet: shad04@ccu.umanitoba.ca               Compu$erve: 72365,306
  76.