Skip to content

Commit

Permalink
Merge pull request #1734 from mina-skunk/main
Browse files Browse the repository at this point in the history
Update gte-registers.hh
  • Loading branch information
nicolasnoble authored Sep 16, 2024
2 parents 9d4db2e + b9fbb30 commit 333249e
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion src/mips/psyqo/gte-registers.hh
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,9 @@ enum class PseudoRegister {
V1, /* pseudo register for full Vector 1, mapped to registers VXY1 and VZ1 */
V2, /* pseudo register for full Vector 2, mapped to registers VXY2 and VZ2 */
SV, /* pseudo register for full 16bit Accumulator Vector, mapped to registers IR1-IR3 */
LV /* pseudo register for full 32bit Maths Accumulator Vector, mapped to registers MAC1-MAC3 */
LV, /* pseudo register for full 32bit Maths Accumulator Vector, mapped to registers MAC1-MAC3 */
Translation, /* pseudo register for full Translation vector, mapped to registers TRX-TRZ */
ScreenOffset, /* pseudo register for full Screen offset, mapped to registers OFX and OFY */
};

/**
Expand Down Expand Up @@ -291,6 +293,18 @@ static inline void writeSafe(const Vec3& in) {
static_assert(valid, "Unable to write vector to pseudo register");
}

/**
* @brief Write a 2D vector to a GTE pseudo register, adding nops after the
* operation.
*
* @tparam reg The pseudo register to write to.
* @param in The vector to write.
*/
template <PseudoRegister reg, bool valid = false>
static inline void writeSafe(const Vec2& in) {
static_assert(valid, "Unable to write vector to pseudo register");
}

/**
* @brief Write a 3D vector to a GTE pseudo register, without adding nops after
* the operation.
Expand All @@ -303,6 +317,18 @@ static inline void writeUnsafe(const Vec3& in) {
static_assert(valid, "Unable to write vector to pseudo register");
}

/**
* @brief Write a 2D vector to a GTE pseudo register, without adding nops after
* the operation.
*
* @tparam reg The pseudo register to write to.
* @param in The vector to write.
*/
template <PseudoRegister reg, bool valid = false>
static inline void writeUnsafe(const Vec2& in) {
static_assert(valid, "Unable to write vector to pseudo register");
}

/**
* @brief Writes a 32-bits value to a GTE register from memory.
*
Expand Down Expand Up @@ -806,6 +832,19 @@ inline void writeSafe<PseudoRegister::V2>(const Vec3& in) {
writeSafe<Register::VZ2>(Short(in.z));
}

template <>
inline void writeSafe<PseudoRegister::Translation>(const Vec3& in) {
write<Register::TRX, Unsafe>(in.x.raw());
write<Register::TRX, Unsafe>(in.y.raw());
write<Register::TRZ, Safe>(in.z.raw());
}

template <>
inline void writeSafe<PseudoRegister::ScreenOffset>(const Vec2& in) {
write<Register::OFX, Unsafe>(in.x.raw());
write<Register::OFY, Safe>(in.y.raw());
}

template <>
inline void writeUnsafe<PseudoRegister::Rotation>(const Matrix33& in) {
writeUnsafe<Register::R11R12>(Short(in.vs[0].x), Short(in.vs[0].y));
Expand Down Expand Up @@ -851,6 +890,19 @@ inline void writeUnsafe<PseudoRegister::V2>(const Vec3& in) {
writeUnsafe<Register::VZ2>(Short(in.z));
}

template <>
inline void writeUnsafe<PseudoRegister::Translation>(const Vec3& in) {
write<Register::TRX, Unsafe>(in.x.raw());
write<Register::TRY, Unsafe>(in.y.raw());
write<Register::TRZ, Unsafe>(in.z.raw());
}

template <>
inline void writeUnsafe<PseudoRegister::ScreenOffset>(const Vec2& in) {
write<Register::OFX, Unsafe>(in.x.raw());
write<Register::OFY, Unsafe>(in.y.raw());
}

template <>
inline PackedVec3 readSafe<PseudoRegister::SV>() {
return PackedVec3(Short(readRaw<Register::IR1, Safe>(), Short::RAW),
Expand Down

0 comments on commit 333249e

Please sign in to comment.