From 9bdff9e1dc0510c470635080ff2e90953289cf83 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 12 Oct 2019 17:21:08 +1000 Subject: [PATCH] GTE: Fix NCDT --- src/core/gte.cpp | 22 ++++++++++------------ src/core/gte.h | 3 +-- src/core/gte.inl | 6 +++--- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/core/gte.cpp b/src/core/gte.cpp index abb8d6157..c79d472da 100644 --- a/src/core/gte.cpp +++ b/src/core/gte.cpp @@ -309,7 +309,7 @@ void Core::ExecuteInstruction(Instruction inst) break; case 0x16: - Execute_NCCT(inst); + Execute_NCDT(inst); break; case 0x1B: @@ -435,19 +435,17 @@ void Core::PushSZ(s32 value) m_regs.dr32[19] = static_cast(value); // SZ3 <- value } -void Core::PushRGB(u8 r, u8 g, u8 b, u8 c) -{ - m_regs.dr32[20] = m_regs.dr32[21]; // RGB0 <- RGB1 - m_regs.dr32[21] = m_regs.dr32[22]; // RGB1 <- RGB2 - m_regs.dr32[22] = - ZeroExtend32(r) | (ZeroExtend32(g) << 8) | (ZeroExtend32(b) << 16) | (ZeroExtend32(c) << 24); // RGB2 <- Value -} - void Core::PushRGBFromMAC() { // Note: SHR 4 used instead of /16 as the results are different. - PushRGB(TruncateRGB<0>(m_regs.MAC1 >> 4), TruncateRGB<1>(m_regs.MAC2 >> 4), TruncateRGB<2>(m_regs.MAC3 >> 4), - m_regs.RGBC[3]); + const u32 r = TruncateRGB<0>(static_cast(m_regs.MAC1 >> 4)); + const u32 g = TruncateRGB<1>(static_cast(m_regs.MAC2 >> 4)); + const u32 b = TruncateRGB<2>(static_cast(m_regs.MAC3 >> 4)); + const u32 c = ZeroExtend32(m_regs.RGBC[3]); + + m_regs.dr32[20] = m_regs.dr32[21]; // RGB0 <- RGB1 + m_regs.dr32[21] = m_regs.dr32[22]; // RGB1 <- RGB2 + m_regs.dr32[22] = r | (g << 8) | (b << 16) | (c << 24); // RGB2 <- Value } u32 Core::UNRDivide(u32 lhs, u32 rhs) @@ -662,7 +660,7 @@ void Core::RTPS(const s16 V[3], u8 shift, bool lm, bool last) // The command does saturate IR1,IR2,IR3 to -8000h..+7FFFh (regardless of lm bit). When using RTP with sf=0, then the // IR3 saturation flag (FLAG.22) gets set if "MAC3 SAR 12" exceeds -8000h..+7FFFh (although IR3 is saturated // when "MAC3" exceeds -8000h..+7FFFh). - TruncateAndSetIR<3>(z >> 12, false); + TruncateAndSetIR<3>(s32(z >> 12), false); m_regs.dr32[11] = std::clamp(m_regs.MAC3, lm ? 0 : IR123_MIN_VALUE, IR123_MAX_VALUE); #undef dot3 diff --git a/src/core/gte.h b/src/core/gte.h index e99f8d8a2..b6d3d9165 100644 --- a/src/core/gte.h +++ b/src/core/gte.h @@ -53,12 +53,11 @@ private: void TruncateAndSetIR(s32 value, bool lm); template - u8 TruncateRGB(s32 value); + u32 TruncateRGB(s32 value); void SetOTZ(s32 value); void PushSXY(s32 x, s32 y); void PushSZ(s32 value); - void PushRGB(u8 r, u8 g, u8 b, u8 c); void PushRGBFromMAC(); // Divide using Unsigned Newton-Raphson algorithm. diff --git a/src/core/gte.inl b/src/core/gte.inl index adfa8f55b..733558a2f 100644 --- a/src/core/gte.inl +++ b/src/core/gte.inl @@ -99,7 +99,7 @@ void GTE::Core::TruncateAndSetMACAndIR(s64 value, u8 shift, bool lm) } template -u8 GTE::Core::TruncateRGB(s32 value) +u32 GTE::Core::TruncateRGB(s32 value) { if (value < 0 || value > 0xFF) { @@ -110,8 +110,8 @@ u8 GTE::Core::TruncateRGB(s32 value) else m_regs.FLAG.color_b_saturated = true; - value = (value < 0) ? 0 : 0xFF; + return (value < 0) ? 0 : 0xFF; } - return static_cast(value); + return static_cast(value); }