by cornutt » Wed May 07, 2003 9:23 pm
Here's my code for computing the Roland checksums. I figured I'd post it here in case anyone else is interested. I've been told that this code works for everything Roland has ever made that requires a checksum (which is pretty much everything they've ever made with MIDI, except for the Juno-106 and the Jupiter retrofit kits). I can testify that this code works with my JD800 and S-750.
Apologies for the funny indenting; the tabs didn't paste properly into the form, and it seems to throw away leading spaces.
-------
unsigned compute_checksum(unsigned char buffer[],
long xstart,
long xend)
{
long first, last; /* start and end of data to be summed */
unsigned sum = 0;
unsigned checksum;
long i;
/*
* Figure out where the data to be summed starts and ends.
* This includes the JD800 address and all of the data except
* the checksum byte itself, but not the EOX, or the
* manufacturer ID, or the first three Roland-specific
* bytes (the unit #, model ID, and command code).
*/
first = xstart+4; /* skip four header bytes */
last = xend-2; /* exclude EOX and the checksum byte */
/* The checksum formula is 128 - (sum of bytes, mod 128). */
for (i = first; i <= last; i++)
sum += buffer[i];
sum &= 0x7f; /* makes it mod 128 */
checksum = 0x80 - sum; /* checksum should be >= 0 && < 0x80 */
/* fix incorrect value of 0x80 if necessary */
if (checksum == 0x80)
checksum = 0;
/* All done */
return(checksum);
}