internal static bool goodchecksum(IList <byte> romdata, RomMapMode mode, int size) { int snestopc(int snesAddress) => RomUtil.ConvertSnesToPc(snesAddress, mode, size); var checksum = (int)getchecksum(romdata); return(((romdata[snestopc(0x00FFDE)] ^ romdata[snestopc(0x00FFDC)]) == 0xFF) && ((romdata[snestopc(0x00FFDF)] ^ romdata[snestopc(0x00FFDD)]) == 0xFF) && ((romdata[snestopc(0x00FFDE)] & 0xFF) == (checksum & 0xFF)) && ((romdata[snestopc(0x00FFDF)] & 0xFF) == ((checksum >> 8) & 0xFF))); }
internal static void fixchecksum(IList <byte> romdata, RomMapMode mode, int size) { int snestopc(int snesAddress) => RomUtil.ConvertSnesToPc(snesAddress, mode, size); // randomdude999: clear out checksum bytes before recalculating checksum, this should make it correct on roms that don't have a checksum yet romdata.writeromdata(snestopc(0x00FFDC), 0xFFFF0000); var checksum = getchecksum(romdata); romdata.writeromdata_byte(snestopc(0x00FFDE), (byte)(checksum & 255)); romdata.writeromdata_byte(snestopc(0x00FFDF), (byte)((checksum >> 8) & 255)); romdata.writeromdata_byte(snestopc(0x00FFDC), (byte)((checksum & 255) ^ 255)); romdata.writeromdata_byte(snestopc(0x00FFDD), (byte)(((checksum >> 8) & 255) ^ 255)); }