Skip to content

Commit

Permalink
RSP: Add class to wrap around RSP flag
Browse files Browse the repository at this point in the history
  • Loading branch information
project64 committed Aug 23, 2023
1 parent 0cb43e0 commit 9dab348
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 15 deletions.
20 changes: 6 additions & 14 deletions Source/Project64-rsp-core/cpu/RSPInterpreterOps.cpp
Expand Up @@ -1304,22 +1304,14 @@ void RSP_Vector_VABS(void)

void RSP_Vector_VADDC(void)
{
uint8_t el, del;
UWORD32 temp;
RSPVector Result;

RSP_Flags[0].UW = 0;
for (el = 0; el < 8; el++)
VCOH.Clear();
for (uint8_t el = 0; el < 8; el++)
{
del = EleSpec[RSPOpC.e].B[el];

temp.UW = (int)RSP_Vect[RSPOpC.vs].u16(el) + (int)RSP_Vect[RSPOpC.vt].u16(del);
RSP_ACCUM[el].HW[1] = temp.HW[0];
Result.u16(el) = temp.UHW[0];
if (temp.UW & 0xffff0000)
{
RSP_Flags[0].UW |= (1 << (7 - el));
}
int32_t Temp = (int32_t)RSP_Vect[RSPOpC.vs].u16(el) + (int32_t)RSP_Vect[RSPOpC.vt].ue(el, RSPOpC.e);
RSP_ACCUM[el].HW[1] = (int16_t)Temp;
Result.u16(el) = RSP_ACCUM[el].HW[1];
VCOL.Set(el, (Temp >> 16) != 0);
}
RSP_Vect[RSPOpC.vd] = Result;
}
Expand Down
2 changes: 2 additions & 0 deletions Source/Project64-rsp-core/cpu/RSPRegister.cpp
Expand Up @@ -5,6 +5,8 @@ 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]);

char * GPR_Strings[32] = {
"R0",
"AT",
Expand Down
2 changes: 2 additions & 0 deletions Source/Project64-rsp-core/cpu/RSPRegisters.h
Expand Up @@ -103,3 +103,5 @@ void UpdateRSPRegistersScreen(void);
extern UWORD32 RSP_GPR[32], RSP_Flags[4];
extern UDWORD RSP_ACCUM[8];
extern RSPVector RSP_Vect[32];

extern RSPFlag VCOL, VCOH;
28 changes: 28 additions & 0 deletions Source/Project64-rsp-core/cpu/RspTypes.cpp
Expand Up @@ -50,3 +50,31 @@ uint64_t & RSPVector::u64(uint8_t Index)
{
return m_Reg[Index];
}

RSPFlag::RSPFlag(uint16_t & Flag) :
m_Flag(Flag)
{
}

void RSPFlag::Clear(void)
{
m_Flag = 0;
}

void RSPFlag::Set(uint8_t Index, bool Value)
{
if (Value)
{
m_Flag |= (1 << (7 - Index));
}
else
{
m_Flag &= ~(1 << (7 - Index));
}
}

bool RSPFlag::Get(uint8_t Index) const
{
return (m_Flag & (1 << (7 - Index))) != 0;
}

19 changes: 18 additions & 1 deletion Source/Project64-rsp-core/cpu/RspTypes.h
Expand Up @@ -39,6 +39,23 @@ class RSPVector
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);

void Clear(void);
void Set(uint8_t Index, bool Value);
bool Get(uint8_t Index) const;

private:
RSPFlag();
RSPFlag(const RSPFlag &);
RSPFlag & operator=(const RSPFlag &);

uint16_t & m_Flag;
};

0 comments on commit 9dab348

Please sign in to comment.