$(SIZE) $@
clean:
- rm -f *.o *.elf *.s19 *.b *.a rom.tar.bz2 romsrc.c
+ rm -f *.o *.elf *.s19 *.b *.a rom.tar.bz2 romsrc.c crctab.h
#
# Some useful rules
$(SIZE) $<
rom.tar.bz2:
- rm -f romsrc.c
+ rm -f romsrc.c crctab.h
tar cjf rom.tar.bz2 README Makefile *.c *.h *.s *.x
romsrc.c: rom.tar.bz2
perl -w src2c.pl < $< > $@
+xmodem.c: crctab.h
+
+gencrctab: gencrctab.c
+ gcc -o $@ $<
+
+crctab.h: gencrctab
+ ./gencrctab > $@
+
#
# Implicit rules
#
--- /dev/null
+#include <stdio.h>
+#define CRC16 0x1021 /* Generator polynomial (X^16 + X^12 + X^5 + 1) */
+int main() {
+ int val;
+ printf("const u16 crctab[] = {\n\t");
+ for (val = 0; val <= 255; val++) {
+ int i;
+ unsigned int crc;
+ crc = val << 8;
+ for (i = 0; i < 8; i++) {
+ crc <<= 1;
+ if (crc & 0x10000)
+ crc ^= CRC16;
+ }
+ printf("0x%04x,", crc&0xffff);
+ if ((val+1)%8 == 0) printf("\n\t");
+ }
+ printf("};\n");
+ return 0;
+}
#include "chime.h"
#include "sci.h"
#include "xmodem.h"
+#include "crctab.h"
/* These definitions are for xmodem protocol. */
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 */
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;