nv2a: Ptimer fixes

Ported from https://github.com/xqemu/xqemu/pull/113 by dracc https://github.com/dracc

A few GPU timing related fixes
NV2A crystal frequency is currently set to debug unit speed of 13.5MHz.
Later retail xboxes had a 16.67MHz crystal according to @JayFoxRox's research(?).
Also, current ptimer clock value calculation is flipped around and on top of that always overflows.

With these fixes, running get_timers.py against xqemu reports values close to what real hardware gives.

Proposed changes
Set NV2A_CRYSTAL_FREQ to retail speed
Fix ptimer_get_clock() behaviour
This commit is contained in:
patrickvl 2018-09-12 16:38:53 +02:00
parent 63f9128ae4
commit 7b4dc90b73
2 changed files with 8 additions and 4 deletions

View File

@ -41,15 +41,19 @@
#include "CxbxCommon.h"
#define NANOSECONDS_PER_SECOND 1000000000
/* PTIMER - time measurement and time-based alarms */
static uint64_t ptimer_get_clock(NV2AState * d)
{
// Get time in nanoseconds
uint64_t time = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
return Muldiv64(time,
uint32_t(d->pramdac.core_clock_freq * d->ptimer.numerator),
CLOCKS_PER_SEC * d->ptimer.denominator);
return Muldiv64(Muldiv64(time,
d->pramdac.core_clock_freq,
NANOSECONDS_PER_SECOND), // Was CLOCKS_PER_SEC
d->ptimer.denominator,
d->ptimer.numerator);
}
DEVICE_READ32(PTIMER)

View File

@ -1753,7 +1753,7 @@
#define NV2A_VERTEX_ATTR_RESERVED2 14
#define NV2A_VERTEX_ATTR_RESERVED3 15
#define NV2A_CRYSTAL_FREQ 13500000
#define NV2A_CRYSTAL_FREQ 16666666 // Was 13500000
#define NV2A_NUM_CHANNELS 32
#define NV2A_NUM_SUBCHANNELS 8