Checksums

= Checksum algorithms =

ck_std : "std"
Two u32 locations in the rom, "sumt" and "xort", are used to save this checksum. sumt = simpl u32 sum of all u32 values of the ROM, excluding the sumt and xort locations. i.e.

for (i=0; i< romsize; i+=4) { if ((i == sumt_location) || (i == xort_location)) continue; sumt += rom[i]; xort ^= rom[i]; }

This checksum is constantly calculated and verified during runtime.

ck_alt : "secondary" / "alt"
Some ROMs have both the std checksum and this one (?). It is also calc'd + verified continuously.

It is the same "std" algo as described above, but applied to a region of the ROM described in the RAMF struct. On the ROMs I've seen, the u32 "alt_sumt" and "alt_xort" values are stored after the secondary IVT (&IVT2 + 0x400). The region seems to always start after the alt_* values (&IVT2 + 0x408; RAMF.altcks_start). It ends @ ( *RAMF.altcks_start + 1) : either &struct FID, or some random shit (i.e. Juke) if the FID struct is before IVT2. The calc loop 2 locations (the cks_alt1 vals) => this seems to be unnecessary since they are stored outside the cks_alt1 area.