From chekmate@athena.mit.edu Tue Aug 7 14:08:01 1990 From: chekmate@athena.mit.edu (Adam Kao) Newsgroups: comp.sys.handhelds Subject: Re: usrlib format Date: 5 Aug 90 17:59:57 GMT Organization: Massachusetts Institute of Technology NOTE1: I am posting this from a friend's account - please respond to the address below, and not anything from the headers. NOTE2: This is the first time I've posted something myself. Please forgive my impending ineptness. Alonso Gariepy writes: >Since Kermit also needs a CRC, my guess was that they may be using the Kermit >CRC throughout. Here is a fragment of C code that calculates the type-3 >Kermit checksum. It is based on the CRC-CCITT polynomial x^16+x^12+x^5+1. > >crc() >{ /* Compute a nibble-oriented type-3 Kermit block check. */ > /* This algorithm was invented by Andy Lowry of Columbia University */ > unsigned n, crc; > > crc = 0; > while (getnibble(&n)) > crc = (crc >> 4) ^ (((n ^ crc) & 0x0f) * 0x1081); > > return (crc); >} > >Alas, this doesn't seem to correspond to the HP 48 hardware CRC. > Ah, but I think that it actually does. A while back, I set out to determine the HP48's CRC algorithm. I wrote a machine language routine to run the CRC portion of the BYTES command on an arbitrary address and length of nibbles. Then, by examining various nibble patterns and their CRCs, I came up with the following algorithm: unsigned int crc(long addr, int len) { unsigned int crc = 0; unsigned int new_nib; while (len--) { new_nib = (crc ^ nib(addr++)) & 0xf; crc = crc >> 4; crc ^= (new_nib | (new_nib << 7) | (new_nib << 12)); } return crc; } If you squint carefully, I think they turn out to be equivalent - I just coded bit-shifts instead of a multiplication. There is one important thing to note, however, which may explain why Alonso didn't think this was the correct CRC algorithm. The CRC that is stored with a library object does not include the five prolog nibbles 04B20. It starts with the library length field, just after the prolog. Dave Kaffine For now, try email at dkaffine@east.sun.com