diff --git a/Source/Project64-rsp-core/cpu/RSPInterpreterOps.cpp b/Source/Project64-rsp-core/cpu/RSPInterpreterOps.cpp index ac47edcda..cf9e8b1b2 100644 --- a/Source/Project64-rsp-core/cpu/RSPInterpreterOps.cpp +++ b/Source/Project64-rsp-core/cpu/RSPInterpreterOps.cpp @@ -1515,87 +1515,38 @@ void RSP_Vector_VGE(void) void RSP_Vector_VCL(void) { - uint8_t el, del; RSPVector Result; - - for (el = 0; el < 8; el++) + for (uint8_t el = 0; el < 8; el++) { - del = EleSpec[RSPOpC.e].B[el]; - - if ((RSP_Flags[0].UW & (1 << (7 - el))) != 0) + if (VCOL.Get(el)) { - if ((RSP_Flags[0].UW & (1 << (15 - el))) != 0) + if (VCOH.Get(el)) { - if ((RSP_Flags[1].UW & (1 << (7 - el))) != 0) - { - RSP_ACCUM[el].HW[1] = -RSP_Vect[RSPOpC.vt].u16(del); - } - else - { - RSP_ACCUM[el].HW[1] = RSP_Vect[RSPOpC.vs].s16(el); - } + RSP_ACCUM[el].HW[1] = VCCL.Get(el) ? -RSP_Vect[RSPOpC.vt].ue(el, RSPOpC.e) : RSP_Vect[RSPOpC.vs].s16(el); } else { - if ((RSP_Flags[2].UW & (1 << (7 - el)))) - { - if (RSP_Vect[RSPOpC.vs].u16(el) + RSP_Vect[RSPOpC.vt].u16(del) > 0x10000) - { - RSP_ACCUM[el].HW[1] = RSP_Vect[RSPOpC.vs].s16(el); - RSP_Flags[1].UW &= ~(1 << (7 - el)); - } - else - { - RSP_ACCUM[el].HW[1] = -RSP_Vect[RSPOpC.vt].u16(del); - RSP_Flags[1].UW |= (1 << (7 - el)); - } - } - else - { - if (RSP_Vect[RSPOpC.vt].u16(del) + RSP_Vect[RSPOpC.vs].u16(el) != 0) - { - RSP_ACCUM[el].HW[1] = RSP_Vect[RSPOpC.vs].s16(el); - RSP_Flags[1].UW &= ~(1 << (7 - el)); - } - else - { - RSP_ACCUM[el].HW[1] = -RSP_Vect[RSPOpC.vt].u16(del); - RSP_Flags[1].UW |= (1 << (7 - el)); - } - } + bool Set = VCE.Get(el) ? (RSP_Vect[RSPOpC.vs].u16(el) + RSP_Vect[RSPOpC.vt].ue(el, RSPOpC.e) <= 0x10000) : (RSP_Vect[RSPOpC.vt].ue(el, RSPOpC.e) + RSP_Vect[RSPOpC.vs].u16(el) == 0); + RSP_ACCUM[el].HW[1] = Set ? -RSP_Vect[RSPOpC.vt].ue(el, RSPOpC.e) : RSP_Vect[RSPOpC.vs].s16(el); + VCCL.Set(el, Set); } } else { - if ((RSP_Flags[0].UW & (1 << (15 - el))) != 0) + if (VCOH.Get(el)) { - if ((RSP_Flags[1].UW & (1 << (15 - el))) != 0) - { - RSP_ACCUM[el].HW[1] = RSP_Vect[RSPOpC.vt].s16(del); - } - else - { - RSP_ACCUM[el].HW[1] = RSP_Vect[RSPOpC.vs].s16(el); - } + RSP_ACCUM[el].UHW[1] = VCCH.Get(el) ? RSP_Vect[RSPOpC.vt].ue(el, RSPOpC.e) : RSP_Vect[RSPOpC.vs].s16(el); } else { - if (RSP_Vect[RSPOpC.vs].u16(el) - RSP_Vect[RSPOpC.vt].u16(del) >= 0) - { - RSP_ACCUM[el].HW[1] = RSP_Vect[RSPOpC.vt].u16(del); - RSP_Flags[1].UW |= (1 << (15 - el)); - } - else - { - RSP_ACCUM[el].HW[1] = RSP_Vect[RSPOpC.vs].s16(el); - RSP_Flags[1].UW &= ~(1 << (15 - el)); - } + RSP_ACCUM[el].HW[1] = VCCH.Set(el, RSP_Vect[RSPOpC.vs].u16(el) - RSP_Vect[RSPOpC.vt].ue(el, RSPOpC.e) >= 0) ? RSP_Vect[RSPOpC.vt].ue(el, RSPOpC.e) : RSP_Vect[RSPOpC.vs].s16(el); } } Result.s16(el) = RSP_ACCUM[el].HW[1]; } - RSP_Flags[0].UW = 0; - RSP_Flags[2].UW = 0; + VCOL.Clear(); + VCOH.Clear(); + VCE.Clear(); RSP_Vect[RSPOpC.vd] = Result; } diff --git a/Source/Project64-rsp-core/cpu/RSPRegister.cpp b/Source/Project64-rsp-core/cpu/RSPRegister.cpp index f6d1065dc..dc3484a23 100644 --- a/Source/Project64-rsp-core/cpu/RSPRegister.cpp +++ b/Source/Project64-rsp-core/cpu/RSPRegister.cpp @@ -5,7 +5,9 @@ UWORD32 RSP_GPR[32], RSP_Flags[4]; UDWORD RSP_ACCUM[8]; RSPVector RSP_Vect[32]; -RSPFlag VCOL(RSP_Flags[0].UHW[0]), VCOH(RSP_Flags[0].UHW[1]); +RSPFlag VCOL(RSP_Flags[0].UB[0]), VCOH(RSP_Flags[0].UB[1]); +RSPFlag VCCL(RSP_Flags[1].UB[0]), VCCH(RSP_Flags[1].UB[1]); +RSPFlag VCE(RSP_Flags[2].UB[0]); char * GPR_Strings[32] = { "R0", diff --git a/Source/Project64-rsp-core/cpu/RSPRegisters.h b/Source/Project64-rsp-core/cpu/RSPRegisters.h index ae7bee5d0..e8423b364 100644 --- a/Source/Project64-rsp-core/cpu/RSPRegisters.h +++ b/Source/Project64-rsp-core/cpu/RSPRegisters.h @@ -104,4 +104,6 @@ extern UWORD32 RSP_GPR[32], RSP_Flags[4]; extern UDWORD RSP_ACCUM[8]; extern RSPVector RSP_Vect[32]; -extern RSPFlag VCOL, VCOH; \ No newline at end of file +extern RSPFlag VCOL, VCOH; +extern RSPFlag VCCL, VCCH; +extern RSPFlag VCE; \ No newline at end of file diff --git a/Source/Project64-rsp-core/cpu/RspTypes.cpp b/Source/Project64-rsp-core/cpu/RspTypes.cpp index 8e7f90e45..e8cf324a8 100644 --- a/Source/Project64-rsp-core/cpu/RspTypes.cpp +++ b/Source/Project64-rsp-core/cpu/RspTypes.cpp @@ -51,7 +51,7 @@ uint64_t & RSPVector::u64(uint8_t Index) return m_Reg[Index]; } -RSPFlag::RSPFlag(uint16_t & Flag) : +RSPFlag::RSPFlag(uint8_t & Flag) : m_Flag(Flag) { } @@ -61,7 +61,7 @@ void RSPFlag::Clear(void) m_Flag = 0; } -void RSPFlag::Set(uint8_t Index, bool Value) +bool RSPFlag::Set(uint8_t Index, bool Value) { if (Value) { @@ -71,10 +71,10 @@ void RSPFlag::Set(uint8_t Index, bool Value) { m_Flag &= ~(1 << (7 - Index)); } + return Value; } bool RSPFlag::Get(uint8_t Index) const { return (m_Flag & (1 << (7 - Index))) != 0; } - diff --git a/Source/Project64-rsp-core/cpu/RspTypes.h b/Source/Project64-rsp-core/cpu/RspTypes.h index 44f8a2571..36fb1e516 100644 --- a/Source/Project64-rsp-core/cpu/RspTypes.h +++ b/Source/Project64-rsp-core/cpu/RspTypes.h @@ -39,17 +39,17 @@ public: int32_t & s32(uint8_t Index); uint64_t & u64(uint8_t Index); -private: +private: uint64_t m_Reg[2] alignas(16); }; class RSPFlag { public: - RSPFlag(uint16_t & Flag); + RSPFlag(uint8_t & Flag); void Clear(void); - void Set(uint8_t Index, bool Value); + bool Set(uint8_t Index, bool Value); bool Get(uint8_t Index) const; private: @@ -57,5 +57,5 @@ private: RSPFlag(const RSPFlag &); RSPFlag & operator=(const RSPFlag &); - uint16_t & m_Flag; + uint8_t & m_Flag; }; \ No newline at end of file