click below to safely check yuor pokemons.
use std::ops::RangeInclusive;
pub fn calc_checksum(slice: &[u8]) -> u8 {
slice.iter()
.fold(0xFF, |sum, x| sum.wrapping_sub(*x))
}
fn uninitialized_region(slice: &[u8]) -> bool {
slice.iter().all(|x| *x == 0xFF)
}
pub const CHECKSUM_REGIONS: [(RangeInclusive<usize>, usize); 15] = [
(0x2598..=0x3522, 0x3523), // main data (incl. "active" box)
(0x4000..=0x5A4B, 0x5A4C), // boxes 1-6
(0x4000..=0x4461, 0x5A4D), // box 1
(0x4462..=0x48C3, 0x5A4E), // box 2
(0x48C4..=0x4D25, 0x5A4F), // box 3
(0x4D26..=0x5187, 0x5A50), // box 4
(0x5188..=0x55E9, 0x5A51), // box 5
(0x55EA..=0x5A4B, 0x5A52), // box 6
(0x6000..=0x7A4B, 0x7A4C), // boxes 7-12
(0x6000..=0x6461, 0x7A4D), // box 7
(0x6462..=0x68C3, 0x7A4E), // box 8
(0x68C4..=0x6D25, 0x7A4F), // box 9
(0x6D26..=0x7187, 0x7A50), // box 10
(0x7188..=0x75E9, 0x7A51), // box 11
(0x75EA..=0x7A4B, 0x7A52), // box 12
];
pub fn validate_checksums(sram: &[u8]) -> bool {
CHECKSUM_REGIONS.into_iter()
.filter(|(range, _)| !uninitialized_region(&sram[range.clone()]))
.all(|(range, offset)| calc_checksum(&sram[range]) == sram[offset])
}

