Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How does this emulator handle overflow? #27

Open
ghost opened this issue Sep 2, 2018 · 0 comments
Open

How does this emulator handle overflow? #27

ghost opened this issue Sep 2, 2018 · 0 comments

Comments

@ghost
Copy link

ghost commented Sep 2, 2018

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants