Fixed CRC. Passes!

This commit is contained in:
brandman211 2012-07-17 04:16:11 +00:00
parent bbf5be7d74
commit cd5458a5e4
1 changed files with 51 additions and 51 deletions

View File

@ -50,13 +50,6 @@ namespace BizHawk.Emulation.Consoles.Intellivision
return (ushort)((crc << 8) ^ CRC16_table[(crc >> 8) ^ data]); return (ushort)((crc << 8) ^ CRC16_table[(crc >> 8) ^ data]);
} }
private ushort UpdateCRC16_Block(ushort crc, byte[] data, int start, int length)
{
for (int item = 0; item < length; item++)
crc = UpdateCRC16(crc, data[start + item]);
return crc;
}
public void Parse() public void Parse()
{ {
// Check to see if the header is valid. // Check to see if the header is valid.
@ -65,22 +58,29 @@ namespace BizHawk.Emulation.Consoles.Intellivision
int offset = 3; int offset = 3;
for (int segment = 0; segment < Rom[1]; segment++) for (int segment = 0; segment < Rom[1]; segment++)
{ {
int start = offset; ushort crc = 0xFFFF;
int low = Rom[offset++] << 8; byte upper_start = Rom[offset++];
int high = (Rom[offset++] << 8) + 0xFF; byte upper_end = Rom[offset++];
// This range is invalid if it starts at an higher range than it ends. crc = UpdateCRC16(crc, upper_start);
if (high < low) crc = UpdateCRC16(crc, upper_end);
int start = upper_start << 8;
int end = (upper_end << 8) | 0xFF;
// This range is invalid if it starts at a higher range than it ends.
if (end < start)
throw new ArgumentException(); throw new ArgumentException();
for (int addr = low; addr <= high; addr++) for (int addr = start; addr <= end; addr++)
{ {
int data; int data;
data = (Rom[offset++] << 8) | (Rom[offset++] & 0xFF); byte high = Rom[offset++];
byte low = Rom[offset++];
crc = UpdateCRC16(crc, high);
crc = UpdateCRC16(crc, low);
data = (high << 8) | low;
WriteCart((ushort)addr, (ushort)data); WriteCart((ushort)addr, (ushort)data);
} }
int expected = (Rom[offset++] << 8) | (Rom[offset++] & 0xFF); int expected = (Rom[offset++] << 8) | Rom[offset++];
int actual = UpdateCRC16_Block(0xFFFF, Rom, start, 2 * (high - low) + 2);
// Check if there is an invalid CRC. // Check if there is an invalid CRC.
if (expected != actual) if (expected != crc)
throw new ArgumentException(); throw new ArgumentException();
} }
} }