diff --git a/src/genie.rs b/src/genie.rs index 77f5bb6bcd230738503e7edf24795a38a3a82e87..8a1fe39a42bd11b94bdf2591881a6808c294d97f 100644 --- a/src/genie.rs +++ b/src/genie.rs @@ -66,13 +66,21 @@ impl Default for GameGenie { #[derive(Clone)] pub struct GameGenieCode { - pub code: String, - pub addr: u16, - pub new_data: u8, - pub old_data: u8, + code: String, + addr: u16, + new_data: u8, + old_data: u8, } impl GameGenieCode { + pub fn is_valid(&self, value: u8) -> bool { + self.old_data == value + } + + pub fn new_data(&self) -> u8 { + self.new_data + } + pub fn short_description(&self) -> String { self.code.to_string() } diff --git a/src/rom.rs b/src/rom.rs index 1444c5e7f9abca45542f256da053aebad1159e9c..350003a978f75878e046cefd5fcf5f7e53f3f9d7 100644 --- a/src/rom.rs +++ b/src/rom.rs @@ -818,9 +818,9 @@ pub static GAME_GENIE: Mbc = Mbc { // one that is expected by the Game Genie code, if that's the case // applies the patch, otherwise returns the original strategy is // going to be used - if genie_code.old_data == (rom.mbc.read_rom)(rom, addr) { + if genie_code.is_valid((rom.mbc.read_rom)(rom, addr)) { debugln!("Applying Game Genie code: {}", game_genie_code); - return genie_code.new_data; + return genie_code.new_data(); } } (rom.mbc.read_rom)(rom, addr)