Add checksumming

git-svn-id: https://profuse.googlecode.com/svn/trunk@48 aa027e90-d47c-11dd-86d7-074df07e0730
This commit is contained in:
ksherlock 2009-09-03 03:52:46 +00:00
parent 2458262bac
commit bfe481b412
2 changed files with 24 additions and 0 deletions

View File

@ -11,6 +11,29 @@
#include <string.h>
uint32_t DiskCopy42::CheckSum(uint8_t *buffer, unsigned length)
{
uint32_t checksum = 0;
if (length & 0x01) return -1;
/*
* checksum starts at 0
* foreach big-endian 16-bit word w:
* checksum += w
* checksum = checksum rotate right 1 (bit 0 --> bit 31)
*/
for(unsigned i = 0; i < length; i += 2)
{
checksum += (buffer[i] << 8);
checksum += buffer[i + 1];
checksum = (checksum >> 1) | (checksum << 31);
//if (checksum & 0x01) checksum = (checksum >> 1) | 0x80000000;
//else checksum >>= 1;
}
return checksum;
}
bool DiskCopy42::Load(const uint8_t *buffer)
{

View File

@ -15,6 +15,7 @@
struct DiskCopy42
{
bool Load(const uint8_t *buffer);
static uint32_t CheckSum(uint8_t *buffer, unsigned length);
char disk_name[64];
uint32_t data_size;