Fix: Correct cycle counts for branch taken and branch page crossing#130
Open
schmelze wants to merge 2 commits intomre:masterfrom
Open
Fix: Correct cycle counts for branch taken and branch page crossing#130schmelze wants to merge 2 commits intomre:masterfrom
schmelze wants to merge 2 commits intomre:masterfrom
Conversation
mre
approved these changes
Feb 8, 2026
Owner
mre
left a comment
There was a problem hiding this comment.
Thanks for the fix. This all sounds reasonable to me. @omarandlorraine, any thoughts before merging?
Owner
|
Oh, and can you run |
Collaborator
Don't think so; it's definitely a positive change and feels DRYer than what we had as well |
Author
|
Ran fmt and updated PR |
Owner
|
Thanks. Can you fix the lint error as well? You can test locally with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes an issue where CPU cycles were not being incremented correctly during conditional branch instructions. According to the MOS 6502 specification:
This patch refactors all of the branch_if_* functions to call a new branch() function. This function centralizes the check to calculate page crossings and adjust cycle count as needed. This does remove the const qualifier on all branch functions, as they now mutate the cycle count.
A new test has been added to check this count: test_branch_cycle_timing()