All pastes #575410 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-06-19 00:42 UTC
rendered paste body
//This part's pretty simple...
info.prgCrc = Crc32::Compute( prg.Mem(), prg.Size() );
info.crc = info.prgCrc;
if (chr.Size())
{
	info.chrCrc = Crc32::Compute( chr.Mem(), chr.Size() );
	info.crc = Crc32::Compute( chr.Mem(), chr.Size(), info.crc );
}


//But this I don't quite get :P (mainly trying to duplicate the same mixed crc output that
//(crc >> 8) ^ lut.data[(crc ^ data) & 0xFF] does without having to do CRC manually like this)
namespace Nes
{
	namespace Core
	{
		namespace Crc32
		{
			dword NST_CALL Compute(dword crc,uint data)
			{
				struct Lut
				{
					dword data[256];

					Lut()
					{
						for (uint i=0; i < 256; ++i)
						{
							dword n = i;

							for (uint j=0; j < 8; ++j)
								n = (n >> 1) ^ (((~n & 1) - 1) & 0xEDB88320);

							data[i] = n;
						}
					}
				};

				static const Lut lut;

				return (crc >> 8) ^ lut.data[(crc ^ data) & 0xFF];
			}

			dword NST_CALL Compute(const void* const mem,const dword length,dword crc)
			{
				crc ^= 0xFFFFFFFF;

				for (const byte *NST_RESTRICT data=static_cast<const byte*>(mem), *const end=data+length; data != end; ++data)
					crc = Compute( crc, *data );

				crc ^= 0xFFFFFFFF;

				return crc;
			}
		}
	}
}