Problems with Checksums

I use the Checksum functions a lot, and to be honest the docs are somewhat lacking. I have never got chaining of Checksums to work for example, but here is a different issue. I am using the iNES plugin from the template library, the first function does not work, yet the array method does. Anyone any ideas? The Rom size is correct.

local uint rom_size;
rom_size=header.prgSize * 16 * 1024+header.chrSize * 8 * 1024;
Printf(“Total SIze of Program and Character ROM is %X”,rom_size);
full_crc=Checksum(CHECKSUM_CRC32,prg[0],((header.prgSize * 16 * 1024)+(header.chrSize * 8 * 1024)));
// Calculate using Array
local ubyte full_crc_array [header.prgSize * 16 * 1024+header.chrSize * 8 * 1024];
local uchar full_array_result[4];
for (i=0;i<(header.prgSize * 16 * 1024);i++)
{
full_crc_array[i]=prg[i];
}
for (i=0;i<(header.chrSize * 8 * 1024); i++)
{
full_crc_array[i+(header.prgSize * 16 * 1024)]=chr[i];
}

ChecksumAlgArrayBytes(CHECKSUM_CRC32,full_array_result,full_crc_array,(header.prgSize * 16 * 1024)+(header.chrSize * 8 * 1024));

Printf("\nFull CRC32 using array method");
for (i=0;i<4;i++)
{
   Printf("%X",full_array_result[i]);
}

When calling the ‘Checksum’ function, the second argument should be the starting byte address of the data where you want to calculate the checksum. You are passing ‘prg[0]’ which is the value of the first byte, but you should be passing ‘startof(prg)’ instead as this gives the address of the prg array. Let us know if this doesn’t work for you.

Graeme
SweetScape Software

1 Like

I was not aware of startof(), I think I tried &prg[0] but of course it failed. Thanks