Add HuC6280 timing hooks - #138
Open
mre wants to merge 1 commit into
Open
Conversation
| /// Most memory implementations can ignore this. Systems with devices on the | ||
| /// CPU bus can override it to keep timers, video chips, or DMA engines in | ||
| /// sync with instruction execution. | ||
| fn tick(&mut self, _cycles: u64) {} |
Collaborator
There was a problem hiding this comment.
Why do we need this? On the 6502, all cycles either read or write to memory, so by my intuition, get_byte and others will be called accordingly. (Does this assumption hold true on the HuC6280 as well?)
omarandlorraine
approved these changes
Jun 29, 2026
omarandlorraine
left a comment
Collaborator
There was a problem hiding this comment.
Most of this makes sense to me. My only doubt is I'm not sure I understand the motive for adding the ticks method to the Memory trait.
| /// Extra cycles charged after a relative branch is taken. | ||
| #[must_use] | ||
| fn branch_taken_extra_cycles(from: u16, to: u16) -> u64 { | ||
| 1 + u64::from((from ^ to) & 0xFF00 != 0) |
| } | ||
|
|
||
| fn interrupt_dispatch_cycles() -> u64 { | ||
| 8 |
Collaborator
There was a problem hiding this comment.
What does this mean? Does the 6280 really wait so long before starting an interrupt?
| } | ||
| } | ||
|
|
||
| fn add_cycles(&mut self, cycles: u64) { |
Collaborator
There was a problem hiding this comment.
I like that this has been extracted to its own method.
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.
So I'm not 100% certain that this is the right move, but I decided to put this PR up for discussions.
Basically, what I noticed is that my TurboGrafx emulator behaved weirdly: there were some sprite/background glitches I couldn't explain. At least in part, this is due to cycle timing issues in the 6502 emulator.
This PR is an attempt to account for those issues. Namely, extra cycles for branching and interrupts are accounted for now and I've simplified the cycle arithmetic to clean up the code a bit.