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.
The first of these two commits changes our implementation of
QueryPerformanceCounter
andQueryPerformanceFrequency
to use the TSC (like later XDKs did) instead of the kernel's less accurate internal counter.The second commit improves compatibility with non-stock Xbox systems by using a constructor to compute the TSC frequency on startup instead of using a hard-coded value.
It uses a lookup-table of known CPU clock multipliers and FSB divider and multiplier values from the northbridge to derive this frequency from the crystal frequency. This is done with 64 bit integer math and fractions of a Hz to not introduce any errors during the calculations.
The only way this could be wrong should be using a non-stock crystal frequency.
Using this code in xemu requires xemu-project/xemu#1551 so any reasonably recent version should do.
The code is almost unchanged from my old branch that wasn't upstreamed yet (https://github.com/thrimbor/nxdk/tree/tsc).
Supersedes #663