From cabcd2cc95b6236b2dc23265ca7707fe07130236 Mon Sep 17 00:00:00 2001 From: zilmar Date: Mon, 14 Nov 2022 11:19:02 +1030 Subject: [PATCH] Core: Handle masking of random in CSystemTimer::UpdateTimers --- .../N64System/Mips/SystemTiming.cpp | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Source/Project64-core/N64System/Mips/SystemTiming.cpp b/Source/Project64-core/N64System/Mips/SystemTiming.cpp index 5165ac18b..dc9daf265 100644 --- a/Source/Project64-core/N64System/Mips/SystemTiming.cpp +++ b/Source/Project64-core/N64System/Mips/SystemTiming.cpp @@ -165,19 +165,24 @@ void CSystemTimer::UpdateTimers() m_Reg.COUNT_REGISTER += TimeTaken; random = (uint32_t)m_Reg.RANDOM_REGISTER - ((TimeTaken * CGameSettings::OverClockModifier()) / m_System.CountPerOp()); wired = (uint32_t)m_Reg.WIRED_REGISTER; - if (random < wired) + if (wired > 31) { - if (wired == 0) + if (random <= wired) { - random &= 31; - } - else - { - uint32_t increment = 32 - wired; + uint32_t increment = 64; random += ((wired - random + increment - 1) / increment) * increment; } + m_Reg.RANDOM_REGISTER = random & 0x3F; + } + else + { + if (random <= wired) + { + uint32_t increment = wired != 32 ? (32 - wired) : 1; + random += ((wired - random + increment - 1) / increment) * increment; + } + m_Reg.RANDOM_REGISTER = random & 0x1F; } - m_Reg.RANDOM_REGISTER = random; } }