mirror of https://github.com/rusefi/RomRaider.git
sad attempt to complete alt2 checksum
This commit is contained in:
parent
6335c8f351
commit
68f8c51677
|
@ -45,15 +45,43 @@ public final class CalculateALT2 implements Calculator {
|
|||
int sumt = 0;
|
||||
int xort = 0;
|
||||
int dw = 0;
|
||||
for (int i = range.get(START); i < range.get(END); i += 4) {
|
||||
for (int i = range.get(START) + 4; i < range.get(END); i += 4) {
|
||||
if ((i == range.get(SUMLOC))
|
||||
|| (i == range.get(XORLOC)
|
||||
|| (i == range.get(SKIPLOC)))) continue;
|
||||
dw = (int)parseByteValue(binData, Settings.Endian.BIG, i, 4, true);
|
||||
dw = (int)parseByteValue(binData, Settings.Endian.BIG, i, 4, true); //this works, but shouldn't it be unsigned?
|
||||
sumt += dw;
|
||||
xort ^= dw;
|
||||
}
|
||||
results.put(SUMT, sumt);
|
||||
results.put(XORT, xort);
|
||||
//need to save SUMT and XORT before doing 16bit checksums
|
||||
short sumCAL = 0;
|
||||
short sumCODE = 0;
|
||||
short d = 0;
|
||||
for (int i = range.get(START) + 2; i < range.get(SKIPLOC); i += 2) {
|
||||
if (i == range.get(SUMLOC)){
|
||||
dw = results.get(SUMT);
|
||||
sumCAL += (short)((dw >> 16) & 0xffff);
|
||||
sumCAL += (short)(dw & 0xffff);
|
||||
i += 2; //skip over final 2 bytes of SUMT
|
||||
continue;
|
||||
}
|
||||
if (i == range.get(XORLOC)){
|
||||
dw = results.get(XORT);
|
||||
sumCAL += (short)((dw >> 16) & 0xffff);
|
||||
sumCAL += (short)(dw & 0xffff);
|
||||
i += 2; //skip over final 2 bytes of XORT
|
||||
continue;
|
||||
}
|
||||
d = (short)parseByteValue(binData, Settings.Endian.BIG, i, 2, false);
|
||||
sumCAL += d;
|
||||
}
|
||||
for (int i = range.get(SKIPLOC) + 2; i < range.get(END); i += 2) {
|
||||
d = (short)parseByteValue(binData, Settings.Endian.BIG, i, 2, false);
|
||||
sumCODE += d;
|
||||
}
|
||||
results.put(START, (int)sumCAL); //will this work casting as int?
|
||||
results.put(SKIPLOC, (int)sumCODE); //will this work casting as int?
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,8 +19,12 @@
|
|||
|
||||
package com.romraider.maps.checksum;
|
||||
|
||||
import static com.romraider.xml.RomAttributeParser.parseByteValue;
|
||||
import static com.romraider.xml.RomAttributeParser.parseIntegerValue;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.romraider.Settings;
|
||||
import com.romraider.util.HexUtil;
|
||||
|
||||
/**
|
||||
|
@ -29,6 +33,8 @@ import com.romraider.util.HexUtil;
|
|||
*/
|
||||
public final class ChecksumALT2 extends NissanChecksum {
|
||||
protected static final String SKIPLOC = "skiploc";
|
||||
public static final String SUMCAL = "sumcal";
|
||||
public static final String SUMCODE = "sumcode";
|
||||
|
||||
public ChecksumALT2() {
|
||||
calculator = new CalculateALT2();
|
||||
|
@ -42,5 +48,24 @@ public final class ChecksumALT2 extends NissanChecksum {
|
|||
else {
|
||||
range.put(SKIPLOC, 0x20000);
|
||||
}
|
||||
//override start for ALT2
|
||||
range.put(START, 0x8200);
|
||||
}
|
||||
|
||||
// Validate the 16 bit chks as well
|
||||
public boolean validate(byte[] binData) {
|
||||
calculator.calculate(range, binData, results);
|
||||
final boolean valid =
|
||||
(results.get(SUMT) == (int)parseByteValue(binData, Settings.Endian.BIG, range.get(SUMLOC), 4, true)) &&
|
||||
(results.get(XORT) == (int)parseByteValue(binData, Settings.Endian.BIG, range.get(XORLOC), 4, true)) &&
|
||||
(results.get(SUMCAL) == (short)parseByteValue(binData, Settings.Endian.BIG, range.get(START), 2, false)) &&
|
||||
(results.get(SUMCODE) == (short)parseByteValue(binData, Settings.Endian.BIG, range.get(SKIPLOC), 2, false));
|
||||
return valid;
|
||||
}
|
||||
|
||||
public void update(byte[] binData) {
|
||||
super.update(binData);
|
||||
System.arraycopy(parseIntegerValue(results.get(SUMCAL), Settings.Endian.BIG, 2), 0, binData, range.get(START), 2);
|
||||
System.arraycopy(parseIntegerValue(results.get(SUMCODE), Settings.Endian.BIG, 2), 0, binData, range.get(SKIPLOC), 2);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue