From ea6af0e98b4a51188704789744b18607650f0714 Mon Sep 17 00:00:00 2001 From: booto Date: Fri, 18 Sep 2015 02:55:09 +0800 Subject: [PATCH] VI: Fix vert beam position inaccuracy --- Source/Core/Core/HW/VideoInterface.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Source/Core/Core/HW/VideoInterface.cpp b/Source/Core/Core/HW/VideoInterface.cpp index 9149348891..50817ab803 100644 --- a/Source/Core/Core/HW/VideoInterface.cpp +++ b/Source/Core/Core/HW/VideoInterface.cpp @@ -4,6 +4,7 @@ #include "Common/ChunkFile.h" #include "Common/CommonTypes.h" +#include "Common/MathUtil.h" #include "Common/StringUtil.h" #include "Core/ConfigManager.h" @@ -286,7 +287,7 @@ void RegisterMMIO(MMIO::Mapping* mmio, u32 base) // MMIOs with unimplemented writes that trigger warnings. mmio->Register(base | VI_VERTICAL_BEAM_POSITION, MMIO::ComplexRead([](u32) { - return (s_half_line_count + 1) / 2; + return 1 + (s_half_line_count-1) / 2; }), MMIO::ComplexWrite([](u32, u16 val) { WARN_LOG(VIDEOINTERFACE, "Changing vertical beam position to 0x%04x - not documented or implemented yet", val); @@ -294,7 +295,8 @@ void RegisterMMIO(MMIO::Mapping* mmio, u32 base) ); mmio->Register(base | VI_HORIZONTAL_BEAM_POSITION, MMIO::ComplexRead([](u32) { - return static_cast(m_HTiming0.HLW * (CoreTiming::GetTicks() - s_ticks_last_line_start) / GetTicksPerHalfLine()); + u16 value = static_cast(1 + m_HTiming0.HLW * (CoreTiming::GetTicks() - s_ticks_last_line_start) / (GetTicksPerHalfLine())); + return MathUtil::Clamp(value, static_cast(1), static_cast(m_HTiming0.HLW * 2)); }), MMIO::ComplexWrite([](u32, u16 val) { WARN_LOG(VIDEOINTERFACE, "Changing horizontal beam position to 0x%04x - not documented or implemented yet", val); @@ -624,7 +626,7 @@ void Update() for (UVIInterruptRegister& reg : m_InterruptRegister) { - if (s_half_line_count == 2 * reg.VCT) + if (s_half_line_count + 1 == 2 * reg.VCT) { reg.IR_INT = 1; }