X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=ROM2%2Fxmodem.c;h=d0e09dd0a04bc57a235f4d0ee89b884167ecee8f;hb=2e98bf59fc918f4e3d0dcfda51b381c8ef853746;hp=7615d9bff363c51e10592ca62f9124804286563c;hpb=db71d9706715bf39fa5c5696108019bacd8181fa;p=uccvend-snackrom.git diff --git a/ROM2/xmodem.c b/ROM2/xmodem.c index 7615d9b..d0e09dd 100644 --- a/ROM2/xmodem.c +++ b/ROM2/xmodem.c @@ -21,6 +21,7 @@ #include "chime.h" #include "sci.h" #include "xmodem.h" +#include "crctab.h" /* These definitions are for xmodem protocol. */ @@ -51,43 +52,22 @@ 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 */ +/* Pads with ^Z up to 128 bytes if told to */ -static unsigned short -docrc (unsigned char *p, int len) +unsigned short +docrc (unsigned char *p, short len, bool pad, unsigned short crc) { - int len2 = len; - unsigned short crc = 0; + short len2 = len; - while (len-- > 0) - crc = (crc << 8) ^ crctab((crc >> 8) ^ *p++); - if (len2 < 128) { + while (len-- > 0) { + crc = (crc << 8) ^ (crctab[(crc >> 8) ^ *p]); + p++; + } + if (pad && len2 < 128) { len = 128-len; while (len-- > 0) - crc = (crc << 8) ^ crctab((crc >> 8) ^ 0x1a); + crc = (crc << 8) ^ crctab[(crc >> 8) ^ 0x1a]; } return crc; @@ -183,7 +163,7 @@ xmodem_send_packet (const unsigned char *packet, int len) if (crcflag) { u16 crc; - crc = docrc ((unsigned char*)packet, len); + crc = docrc ((unsigned char*)packet, len, 1, 0); s[0] = crc >> 8; s[1] = crc & 0xff;