|
|
1.1 ! root 1: /* ! 2: ** Packet check bytes calculation ! 3: */ ! 4: ! 5: #ifdef vax ! 6: /* ! 7: ** Vax "crc" instruction look-up table for polynomial = 0120001 ! 8: */ ! 9: ! 10: unsigned long crc16t[] = ! 11: { ! 12: 0, 0146001, 0154001, 012000, 0170001, 036000, 024000, 0162001 ! 13: , 0120001, 066000, 074000, 0132001, 050000, 0116001, 0104001, 042000 ! 14: }; ! 15: ! 16: ! 17: /*ARGSUSED*/ ! 18: int ! 19: crc(s, n) ! 20: unsigned char *s; ! 21: int n; ! 22: { ! 23: asm(" crc _crc16t,$0,8(ap),*4(ap) "); ! 24: asm(" cmpw r0,(r3) "); ! 25: asm(" beqlu OK "); ! 26: asm(" movw r0,(r3) "); ! 27: asm(" movl $1,r0 "); ! 28: asm(" ret "); ! 29: asm("OK:movw r0,(r3) "); ! 30: return (0); ! 31: } ! 32: ! 33: ! 34: #else vax ! 35: ! 36: ! 37: /* ! 38: ** crc-16: x**16 + x**15 + x**2 + 1 ! 39: */ ! 40: ! 41: typedef unsigned char uchar; ! 42: typedef unsigned short ushort; ! 43: ! 44: #define lobyte(X) (X&0xff) ! 45: #define hibyte(X) ((X>>8)&0xff) ! 46: ! 47: #ifdef ROMCRC ! 48: extern ushort crc16t_32[2] [16]; ! 49: #else ! 50: ushort crc16t_32[2][16] = ! 51: { ! 52: 0, 0140301, 0140601, 0500, 0141401, 01700, 01200, 0141101, ! 53: 0143001, 03300, 003600, 0143501, 02400, 0142701, 0142201, 02100, ! 54: 0, 0146001, 0154001, 012000, 0170001, 036000, 024000, 0162001, ! 55: 0120001, 066000, 074000, 0132001, 050000, 0116001, 0104001, 042000 ! 56: }; ! 57: #endif ! 58: ! 59: int ! 60: crc(buffer, nbytes) ! 61: register uchar *buffer; ! 62: int nbytes; ! 63: { ! 64: register ushort tcrc = 0; ! 65: register int temp; ! 66: register int i; ! 67: ! 68: if ( (i = nbytes) > 0 ) ! 69: do { ! 70: temp = tcrc ^ *buffer++; ! 71: tcrc = crc16t_32[0][temp & 017] ! 72: ^ crc16t_32[1][(temp>>4) & 017] ! 73: ^ (tcrc >> 8); ! 74: } while ( --i > 0 ); ! 75: ! 76: if ( lobyte(tcrc) != *buffer ) ! 77: i++; ! 78: *buffer++ = lobyte(tcrc); ! 79: ! 80: if ( hibyte(tcrc) != *buffer ) ! 81: i++; ! 82: *buffer++ = hibyte(tcrc); ! 83: ! 84: return(i); ! 85: } ! 86: ! 87: ! 88: #endif vax
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.