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

Chapter 3.4 conversion to i8 for Branch #29

Open
dariandzirko opened this issue Aug 5, 2023 · 1 comment
Open

Chapter 3.4 conversion to i8 for Branch #29

dariandzirko opened this issue Aug 5, 2023 · 1 comment

Comments

@dariandzirko
Copy link

dariandzirko commented Aug 5, 2023

In cpu.rs

fn branch(&mut self, condition: bool) {
        if condition {
            let jump: i8 = self.mem_read(self.program_counter) as i8;
            let jump_addr = self
                .program_counter
                .wrapping_add(1)
                .wrapping_add(jump as u16);

If I change jump to u16 I get an extremely incorrect result immediately resulting in a BRK command run. The negative flag isn't set and it is immediately changed back to u16 later in the wrapping add. Any idea about this? Is there something in the documentation I am missing where this should a signed and then unsigned add?

@FischLu
Copy link

FischLu commented Sep 4, 2023

signed is necessary here, the jump offset can be a negative value, see here
https://wiki.cdot.senecacollege.ca/wiki/6502_Jumps,_Branches,_and_Procedures

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

2 participants