From 8a8ce8d41c487b000dce3923405b2b4cf6fea0fc Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Thu, 2 Jul 2020 02:51:22 +1000 Subject: [PATCH] NamcoGunCon: Use correct GPU clock as reference --- src/core/gpu.cpp | 5 +++++ src/core/gpu.h | 3 +++ src/core/namco_guncon.cpp | 3 ++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/core/gpu.cpp b/src/core/gpu.cpp index 6382a9478..3d879fb8e 100644 --- a/src/core/gpu.cpp +++ b/src/core/gpu.cpp @@ -393,6 +393,11 @@ void GPU::DMAWrite(const u32* words, u32 word_count) * PAL - sysclk * 709379 / 451584 */ +TickCount GPU::GetCRTCFrequency() const +{ + return m_console_is_pal ? 53203425 : 53693175; +} + TickCount GPU::CRTCTicksToSystemTicks(TickCount gpu_ticks, TickCount fractional_ticks) const { // convert to master clock, rounding up as we want to overshoot not undershoot diff --git a/src/core/gpu.h b/src/core/gpu.h index 065e76ac7..7758ce605 100644 --- a/src/core/gpu.h +++ b/src/core/gpu.h @@ -173,6 +173,9 @@ public: // Converts window coordinates into horizontal ticks and scanlines. Returns false if out of range. Used for lightguns. bool ConvertScreenCoordinatesToBeamTicksAndLines(s32 window_x, s32 window_y, u32* out_tick, u32* out_line) const; + // Returns the video clock frequency. + TickCount GetCRTCFrequency() const; + protected: TickCount CRTCTicksToSystemTicks(TickCount crtc_ticks, TickCount fractional_ticks) const; TickCount SystemTicksToCRTCTicks(TickCount sysclk_ticks, TickCount* fractional_ticks) const; diff --git a/src/core/namco_guncon.cpp b/src/core/namco_guncon.cpp index 965b4a9ea..e98268caa 100644 --- a/src/core/namco_guncon.cpp +++ b/src/core/namco_guncon.cpp @@ -169,7 +169,8 @@ void NamcoGunCon::UpdatePosition() } // 8MHz units for X = 44100*768*11/7 = 53222400 / 8000000 = 6.6528 - m_position_x = static_cast(static_cast(tick) * (1.0f / 6.6528f)); + const double divider = static_cast(m_system->GetGPU()->GetCRTCFrequency()) / 8000000.0; + m_position_x = static_cast(static_cast(tick) / static_cast(divider)); m_position_y = static_cast(line); Log_DebugPrintf("Lightgun window coordinates %d,%d -> tick %u line %u 8mhz ticks %u", mouse_x, mouse_y, tick, line, m_position_x);