/* Teamsound data CRC algorithm 0.1 by Luigi Auriemma e-mail: aluigi@autistici.org web: aluigi.org This simple algorithm calculates the 16 bit checksum stored at the end (the last 4 bytes) of each data block of the program Teamsound (http://www.teamsound.com). To use it: crc = teamsound_cksum(data_block, data_block_size); */ unsigned short teamsound_cksum(unsigned char *data, int fullsize) { int cksum = 0; unsigned short *ptr; if(fullsize <= 4) return(0x0000); ptr = (unsigned short *)data; fullsize = (fullsize - 4) >> 1; while(fullsize--) { cksum += *ptr; // add dx, ax if(cksum > 0xffff) cksum++; // adc dx, 00 cksum &= 0xffff; // I don't know other methods ptr++; // to do "adc" in C } cksum = (cksum >> 8) | (cksum << 8); return(cksum); }