home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 340.lha / JModem_v1.0 / docrc.asm next >
Encoding:
Assembly Source File  |  1990-01-23  |  1.5 KB  |  49 lines

  1. ******************************************************************
  2. * Routines used by the JModem.c file. (C) 1989 Kenneth Ã–sterberg *
  3. * Use the Manx assembler to compile this file, and link it with  *
  4. * the object file of the C program.                              *
  5. ******************************************************************
  6.  
  7.         public    _docrc
  8.  
  9. ; This routine calculates the CRC (== checksum) word of a string buffer.
  10. ; To call the function from C:
  11. ; docrc(buffer,size)
  12. ; UBYTE *buffer;
  13. ; UWORD size;
  14. ; The resulting CRC value is placed in the last word of the buffer. If the
  15. ; old value matched the new one, TRUE (nonzero) is returned.
  16.  
  17. _docrc:
  18.         movem.l    d1-d3/a0,-(a7)
  19.         move.l    4*4+4(a7),a0       ; A0 = bufptr
  20.         move.w    4*4+8(a7),d0       ; D0 = size
  21.         subq.w    #2,d0              ; Exclude CRC word in buffer
  22.         clr.l    d1                 ; Holds read byte
  23.         clr.l    d2                 ; D2 = crc
  24. crc0:
  25.         move.b    (a0)+,d1
  26.         add.w    d1,d2
  27.         move.w    d0,d3
  28.         and.w    #7,d3              ; (size and 7)
  29.         rol.w    d3,d2              ; shift left
  30.         subq.w    #1,d0
  31.         bne.s    crc0
  32.  
  33.         moveq    #1,d0              ; assume CRC match
  34.         move.b    1(a0),d1           ; Get high byte of old CRC
  35.         lsl.w    #8,d1
  36.         move.b    (a0),d1            ; Get low byte of old CRC
  37.         cmp.w    d2,d1              ; New & old equal?
  38.         beq.s    crcmatch
  39.  
  40.         clr.l    d0                 ; CRC mismatch
  41.         move.b    d2,(a0)+           ; Store new CRC, low byte
  42.         lsr.w    #8,d2
  43.         move.b    d2,(a0)            ; Store high byte
  44. crcmatch:
  45.         movem.l    (a7)+,d1-d3/a0
  46.         rts
  47.  
  48.         end
  49.