2023-11-09 01:23:06 +00:00
|
|
|
#include "RspTypes.h"
|
2024-08-07 21:56:15 +00:00
|
|
|
#include <Project64-rsp-core/cpu/RSPRegisters.h>
|
2023-09-21 05:46:26 +00:00
|
|
|
#include <string.h>
|
2023-08-10 00:57:11 +00:00
|
|
|
|
2023-11-09 01:23:06 +00:00
|
|
|
const char * GPR_Strings[32] = {
|
2023-08-10 00:57:11 +00:00
|
|
|
"R0",
|
|
|
|
"AT",
|
|
|
|
"V0",
|
|
|
|
"V1",
|
|
|
|
"A0",
|
|
|
|
"A1",
|
|
|
|
"A2",
|
|
|
|
"A3",
|
|
|
|
"T0",
|
|
|
|
"T1",
|
|
|
|
"T2",
|
|
|
|
"T3",
|
|
|
|
"T4",
|
|
|
|
"T5",
|
|
|
|
"T6",
|
|
|
|
"T7",
|
|
|
|
"S0",
|
|
|
|
"S1",
|
|
|
|
"S2",
|
|
|
|
"S3",
|
|
|
|
"S4",
|
|
|
|
"S5",
|
|
|
|
"S6",
|
|
|
|
"S7",
|
|
|
|
"T8",
|
|
|
|
"T9",
|
|
|
|
"K0",
|
|
|
|
"K1",
|
|
|
|
"GP",
|
|
|
|
"SP",
|
|
|
|
"S8",
|
|
|
|
"RA",
|
2023-09-07 02:11:17 +00:00
|
|
|
};
|
|
|
|
|
2024-08-07 21:56:15 +00:00
|
|
|
CRSPRegisters::CRSPRegisters() :
|
|
|
|
VCOL(m_Flags[0].UB[0]),
|
|
|
|
VCOH(m_Flags[0].UB[1]),
|
|
|
|
VCCL(m_Flags[1].UB[0]),
|
|
|
|
VCCH(m_Flags[1].UB[1]),
|
|
|
|
VCE(m_Flags[2].UB[0])
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CRSPRegisters::Reset(void)
|
2023-09-21 05:46:26 +00:00
|
|
|
{
|
2024-08-07 21:56:15 +00:00
|
|
|
memset(m_GPR, 0, sizeof(m_GPR));
|
|
|
|
for (size_t i = 0, n = sizeof(m_Vect) / sizeof(m_Vect[0]); i < n; i++)
|
2023-09-21 05:46:26 +00:00
|
|
|
{
|
2024-08-07 21:56:15 +00:00
|
|
|
m_Vect[i] = RSPVector();
|
2023-09-21 05:46:26 +00:00
|
|
|
}
|
2024-08-07 21:56:15 +00:00
|
|
|
m_Reciprocals[0] = 0xFFFF;
|
2023-09-28 04:09:23 +00:00
|
|
|
for (uint16_t i = 1; i < 512; i++)
|
|
|
|
{
|
2024-08-07 21:56:15 +00:00
|
|
|
m_Reciprocals[i] = uint16_t((((1ull << 34) / (uint64_t)(i + 512)) + 1) >> 8);
|
2023-09-28 04:09:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (uint16_t i = 0; i < 512; i++)
|
|
|
|
{
|
2023-09-28 06:23:46 +00:00
|
|
|
uint64_t a = (i + 512) >> ((i % 2 == 1) ? 1 : 0);
|
2023-09-28 04:09:23 +00:00
|
|
|
uint64_t b = 1 << 17;
|
|
|
|
while (a * (b + 1) * (b + 1) < (uint64_t(1) << 44))
|
|
|
|
{
|
|
|
|
b++;
|
|
|
|
}
|
2024-08-07 21:56:15 +00:00
|
|
|
m_InverseSquareRoots[i] = uint16_t(b >> 1);
|
2023-09-28 04:09:23 +00:00
|
|
|
}
|
2024-08-07 21:56:15 +00:00
|
|
|
m_Result = 0;
|
|
|
|
m_In = 0;
|
|
|
|
m_High = false;
|
2023-09-21 05:46:26 +00:00
|
|
|
}
|
|
|
|
|
2024-08-07 21:56:15 +00:00
|
|
|
int64_t CRSPRegisters::AccumulatorGet(uint8_t el)
|
2023-09-07 02:11:17 +00:00
|
|
|
{
|
2024-08-07 21:56:15 +00:00
|
|
|
return (((int64_t)m_ACCUM[el].HW[3]) << 32) | (((int64_t)m_ACCUM[el].UHW[2]) << 16) | m_ACCUM[el].UHW[1];
|
2023-09-07 02:11:17 +00:00
|
|
|
}
|
|
|
|
|
2024-08-07 21:56:15 +00:00
|
|
|
void CRSPRegisters::AccumulatorSet(uint8_t el, int64_t Accumulator)
|
2023-09-07 02:11:17 +00:00
|
|
|
{
|
2024-08-07 21:56:15 +00:00
|
|
|
m_ACCUM[el].HW[3] = (int16_t)(Accumulator >> 32);
|
|
|
|
m_ACCUM[el].HW[2] = (int16_t)(Accumulator >> 16);
|
|
|
|
m_ACCUM[el].HW[1] = (int16_t)(Accumulator);
|
2023-09-07 02:11:17 +00:00
|
|
|
}
|
2023-09-07 02:24:36 +00:00
|
|
|
|
2024-08-07 21:56:15 +00:00
|
|
|
uint16_t CRSPRegisters::AccumulatorSaturate(uint8_t el, bool High)
|
2023-09-07 02:24:36 +00:00
|
|
|
{
|
2024-08-07 21:56:15 +00:00
|
|
|
if (m_ACCUM[el].HW[3] < 0)
|
2023-09-07 02:24:36 +00:00
|
|
|
{
|
2024-08-07 21:56:15 +00:00
|
|
|
if (m_ACCUM[el].UHW[3] != 0xFFFF || m_ACCUM[el].HW[2] >= 0)
|
2023-09-07 02:24:36 +00:00
|
|
|
{
|
|
|
|
return High ? 0x8000 : 0x0000;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-08-07 21:56:15 +00:00
|
|
|
return m_ACCUM[el].UHW[High ? 2 : 1];
|
2023-09-07 02:24:36 +00:00
|
|
|
}
|
|
|
|
}
|
2024-08-07 21:56:15 +00:00
|
|
|
if (m_ACCUM[el].UHW[3] != 0 || m_ACCUM[el].HW[2] < 0)
|
2023-09-07 02:24:36 +00:00
|
|
|
{
|
|
|
|
return High ? 0x7fff : 0xffff;
|
|
|
|
}
|
2024-08-07 21:56:15 +00:00
|
|
|
return m_ACCUM[el].UHW[High ? 2 : 1];
|
2023-09-07 02:24:36 +00:00
|
|
|
}
|