; CRC32
;
; Program for Proteus
;
; (C) 1998-2004 Simone Zanella Productions
;
; This program calculate 32 bit Ansi X3.66 CRC on the first file specified;
; CRC is also calculated by padding file to multiple of 128 and 1024 bytes
; with character ASCII 26.
; Implicit parameters: input and output are NULL.
;!proteus -z
IF ISEMPTY(ARGV(5))
CONSOLELN "Syntax: " ARGV(1) " " ARGV(2) " filename"
CONSOLELN ""
CONSOLELN "Purpose: compute 32 bit Ansi X3.66 CRC (with and without padding)."
ABORT 0
FI
H = FOPEN(ARGV(5), 1)
Crc32 = 0xFFFFFFFF
WHILE NOT(FEOF(H))
Crc32(FREAD(H, 2048), @Crc32)
LOOP
CONSOLELN "File: " ARGV(5)
CONSOLELN "32 bit CRC Ansi X3.66 : " \
PADL(PFORMAT("lX", NNOT(Crc32)), 8, "0")
N = FSIZE(H)
FCLOSE(H)
R1 = MOD(N, 128)
IF R1
R1 = SUB(128, R1)
B = REPLICATE(CHR(26), R1)
Crc32(B, @Crc32)
FI
CONSOLELN "Pad to multiple of 128 bytes : " \
PADL(PFORMAT("lX", NNOT(Crc32)), 8, "0")
R2 = MOD(N, 1024)
IF R2
R2 = SUB(SUB(1024, R2), R1)
B = REPLICATE(CHR(26), R2)
Crc32(B, @Crc32)
FI
CONSOLELN "Pad to multiple of 1024 bytes : " \
PADL(PFORMAT("lX", NNOT(Crc32)), 8, "0")
ABORT 0