"SfR Fresh" - the SfR Freeware/Shareware Archive

Member "usr/xb-6.2.3/demo/acrc32.x" of archive xbasic-6.2.3-linux-i386.tar.gz:


As a special service "SfR Fresh" has tried to format the requested source page into HTML format using source code syntax highlighting with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
    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