diff --git a/src/rom.rs b/src/rom.rs index 99890032648d90be4f031b4a7505016e3a0fb429..98bdcead0437d164d16a797025e7bbfc21b76f9f 100644 --- a/src/rom.rs +++ b/src/rom.rs @@ -864,6 +864,18 @@ impl Cartridge { self.game_shark = None; } + pub fn checksum(&self) -> u8 { + let mut sum: u8 = 0; + for i in 0x0134..=0x014c { + sum = sum.wrapping_sub(self.rom_data[i]).wrapping_sub(1); + } + sum + } + + pub fn valid_checksum(&self) -> bool { + self.rom_data[0x014d] == self.checksum() + } + pub fn description(&self, column_length: usize) -> String { let title_l = format!("{:width$}", "Title", width = column_length); let publisher_l = format!("{:width$}", "Publisher", width = column_length);