checksum

This forum contains all information about TDBAccess library for NHL 2004 roster access and general NHL coding questions.

Moderator: Owen

Post Reply
guest

checksum

Post by guest » Mon Nov 10, 2003 9:20 am

HI !

How did you calculate the checksum (crc) of a tdb file?

Thanx!

vincent_filion@yahoo.com

Artem
Site Admin
Posts: 1166
Joined: Thu Oct 23, 2003 5:30 pm

Post by Artem » Mon Nov 10, 2003 11:13 am

What do you mean? How I got "the formula" or you want "the formula" itself?

guest

checksum

Post by guest » Mon Nov 10, 2003 12:10 pm

HI !

I know theres a checksum for each table in the tdb file but how did you calcul it..

Yes I want the formula.. please :)

Vince.

vincent_filion@yahoo.com

Artem
Site Admin
Posts: 1166
Joined: Thu Oct 23, 2003 5:30 pm

Post by Artem » Tue Nov 11, 2003 4:13 pm

Here is Pascal version. I just directly converted it from assembler so there is probably a way to make it more compact, I didn't bother.

Code: Select all

var HashTable: array[0..255] of LongWord;

function HashBuffer(Buffer: PChar; BufSize: LongWord; InitHash: LongWord): LongWord;

	procedure CreateHashTable;
	var
		ax, si, cx: Longword;
		i: byte;
	begin
		cx := 0;
		for i := Low(HashTable) to High(HashTable) do
		begin
			ax := cx;
			ax := ax shl $18;
			for si := 0 to 7 do
			begin
				if (integer(ax) >= 0) then
				begin
					ax := ax shl 1;
				end
				else
				begin
					ax := ax + ax;
					ax := ax xor $4C11DB7;
				end;
			end;
			HashTable[i] := ax;
			Inc(cx);
		end;
	end;

var
	ax, si: LongWord;
	di: byte;
	i: LongWord;
begin
	if (integer(HashTable[1]) >= 0) then
	begin
		CreateHashTable;
		ax := InitHash;
	end
	else
		ax := InitHash;
	for i := 0 to BufSize - 1 do
	begin
		di := Byte(Buffer[i]);
		si := ax;
		si := si shr $18;
		si := si xor di;
		si := HashTable[si];
		ax := ax shl 8;
		ax := ax xor si;
	end;
	Result := ax;
end;
When calling HashBuffer, Buffer is pointer to the section of TDB file you want to hash and InitHash is $FFFFFFFF.

blinky
Posts: 190
Joined: Fri Oct 24, 2003 12:29 am
Contact:

Post by blinky » Tue Nov 11, 2003 7:19 pm

:shock:

"Mrs Hoover, I swallowed my crayon again. I don't feel so good"...
"I think I bent my wookie".

Post Reply