Skip to content

How does this emulator handle overflow? #27

@ghost

Description

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions