pcwalton / sprocketnes

NES emulator written in Rust
MIT License
749 stars 55 forks source link

How does this emulator handle overflow? #27

Open ghost opened 6 years ago

ghost commented 6 years ago

For example, here's how "inc" is implemented:

// Increments and decrements
fn inc<AM:AddressingMode<M>>(&mut self, am: AM) {
    let val = am.load(self);
    let val = self.set_zn(val + 1);
    am.store(self, val)
}

This is "set_zn":

 fn set_zn(&mut self, val: u8) -> u8 {
    self.set_flag(ZERO_FLAG, val == 0);
    self.set_flag(NEGATIVE_FLAG, (val & 0x80) != 0);
    val
}

I can't see how this would handle a increment of value 255 without panicking? Seeing that there's been no commits in 3 years, perhaps Rust handled overflows differently back then? (Just getting started, writing an emulator in Rust to get to know the language)