home *** CD-ROM | disk | FTP | other *** search
/ PC World 2000 August / PCWorld_2000-08_cd.bin / Software / TemaCD / xbasic / xbpro.exe / xb / acrc32.x < prev    next >
Text File  |  1999-12-20  |  1KB  |  68 lines

  1. '
  2. ' ####################
  3. ' #####  PROLOG  #####
  4. ' ####################
  5. '
  6. PROGRAM    "crc32"
  7. VERSION    "0.0002"
  8. '
  9. IMPORT    "xst"
  10. '
  11. DECLARE FUNCTION  Entry ()
  12. '
  13. '
  14. ' ######################
  15. ' #####  Entry ()  #####
  16. ' ######################
  17. '
  18. FUNCTION  Entry ()
  19.     ULONG table[]
  20.     ULONG sum, filenum, n, a, b, magic
  21.     UBYTE i, j, c
  22. '
  23.     DIM table[255]
  24.     magic = 0xEDB88320
  25. '
  26. ' NOTE: Before XBasic v5.0021 the line with "XOR 0xEDB88320"
  27. ' did not work properly because spasm generated the wrong
  28. ' binary machine instruction for XOR with immediate value.
  29. ' A new version of "spasm" is included with v5.0021 XBasic.
  30. '
  31.     FOR j = 0 TO 255
  32.         sum = j
  33.         FOR i = 0 TO 7
  34.             IF (sum AND 1) THEN
  35.                 rum = sum
  36.                 sum = (sum >> 1) XOR magic
  37.                 bum = (rum >> 1) XOR 0xEDB88320
  38.                 IF (sum != bum) THEN PRINT "sum : bum = "; HEX$(sum,8); " : "; HEX$(bum,8)
  39.             ELSE
  40.                 sum = (sum >> 1)
  41.             END IF
  42.         NEXT i
  43.         table[j] = sum
  44.         PRINT "table[" j "]=" HEXX$(sum)
  45.     NEXT j
  46. '
  47.     filename$ = INLINE$("Enter file name ==>> ")
  48.     filenum = OPEN( filename$ , $$RD)
  49.     crc32 = 0xFFFFFFFF
  50.     n = 0
  51. '
  52.     XstGetSystemTime(@a)
  53. '
  54.     DO
  55.         READ [filenum], c
  56.         INC n
  57.         crc32 = table[(crc32 XOR c) AND 0xFF] XOR (crc32>>8)
  58.     LOOP UNTIL EOF(filenum)
  59. '
  60.     crc32 = crc32 XOR 0xFFFFFFFF
  61.     XstGetSystemTime(@b)
  62. '
  63.     PRINT
  64.     PRINT "CRC32 = " HEX$(crc32) " : file size= " n " bytes : time ="; (b-a); " msecs"
  65.   filename$ = INLINE$("\n press enter to terminate")
  66. END FUNCTION
  67. END PROGRAM
  68.