Use a precomputed CRC table for xmodem
[uccvend-snackrom.git] / ROM2 / xmodem.c
index 7615d9b..3aa776a 100644 (file)
@@ -21,6 +21,7 @@
 #include "chime.h"
 #include "sci.h"
 #include "xmodem.h"
+#include "crctab.h"
 
 /* These definitions are for xmodem protocol. */
 
@@ -51,28 +52,6 @@ readchar (int timeout)
   return 0;
 }
 
-#define CRC16 0x1021           /* Generator polynomial (X^16 + X^12 + X^5 + 1) */
-
-
-/* Call this to init the fast CRC-16 calculation table.  */
-
-static short crctab(u8 val) {
-      int i;
-      unsigned int crc;
-
-      crc = val << 8;
-
-      for (i = 0; i < 8; ++i)
-       {
-         crc <<= 1;
-
-         if (crc & 0x10000)
-           crc ^= CRC16;
-       }
-
-         return crc;
-}
-
 /* Calculate a CRC-16 for the LEN byte message pointed at by P.  */
 /* Pads with ^Z if necessary */
 
@@ -83,11 +62,11 @@ docrc (unsigned char *p, int len)
   unsigned short crc = 0;
 
   while (len-- > 0)
-    crc = (crc << 8) ^ crctab((crc >> 8) ^ *p++);
+    crc = (crc << 8) ^ crctab[(crc >> 8) ^ *p++];
   if (len2 < 128) {
     len = 128-len;
     while (len-- > 0)
-      crc = (crc << 8) ^ crctab((crc >> 8) ^ 0x1a);
+      crc = (crc << 8) ^ crctab[(crc >> 8) ^ 0x1a];
   }
 
   return crc;

UCC git Repository :: git.ucc.asn.au