Duckstation/src/pse/gte.h

84 lines
2.5 KiB
C
Raw Normal View History

#pragma once
#include "common/state_wrapper.h"
#include "gte_types.h"
namespace GTE {
class Core
{
public:
Core();
~Core();
void Initialize();
void Reset();
bool DoState(StateWrapper& sw);
u32 ReadRegister(u32 index) const { return m_regs.dr32[index]; }
void WriteRegister(u32 index, u32 value) { m_regs.dr32[index] = value; }
u32 ReadDataRegister(u32 index) const;
void WriteDataRegister(u32 index, u32 value);
u32 ReadControlRegister(u32 index) const;
void WriteControlRegister(u32 index, u32 value);
void ExecuteInstruction(Instruction inst);
private:
2019-09-25 15:40:55 +00:00
static constexpr s64 MAC0_MIN_VALUE = -(INT64_C(1) << 31);
static constexpr s64 MAC0_MAX_VALUE = (INT64_C(1) << 31) - 1;
2019-09-25 05:40:08 +00:00
static constexpr s64 MAC123_MIN_VALUE = -(INT64_C(1) << 43);
static constexpr s64 MAC123_MAX_VALUE = (INT64_C(1) << 43) - 1;
static constexpr s32 IR0_MIN_VALUE = 0x0000;
static constexpr s32 IR0_MAX_VALUE = 0x1000;
static constexpr s32 IR123_MIN_VALUE = -(INT64_C(1) << 15);
static constexpr s32 IR123_MAX_VALUE = (INT64_C(1) << 15) - 1;
2019-09-25 15:40:55 +00:00
// Checks for underflow/overflow. Returns the value untouched so it can be threaded through an expression.
2019-09-25 05:40:08 +00:00
template<u32 index>
2019-09-25 15:40:55 +00:00
s64 CheckMACResult(s64 value);
2019-09-25 05:40:08 +00:00
2019-09-22 11:41:11 +00:00
template<u32 index>
2019-09-25 15:40:55 +00:00
s64 TruncateAndSetMAC(s64 value, u8 shift);
2019-09-22 11:41:11 +00:00
template<u32 index>
2019-09-25 15:40:55 +00:00
s16 TruncateAndSetIR(s32 value, bool lm);
2019-09-22 11:41:11 +00:00
template<u32 index>
2019-09-25 15:40:55 +00:00
u8 TruncateRGB(s32 value);
2019-09-22 11:41:11 +00:00
2019-09-22 10:38:11 +00:00
void SetOTZ(s32 value);
void PushSXY(s32 x, s32 y);
void PushSZ(s32 value);
2019-09-22 11:41:11 +00:00
void PushRGB(u8 r, u8 g, u8 b, u8 c);
2019-09-25 05:40:08 +00:00
// 3x3 matrix * 3x1 vector, updates MAC[1-3] and IR[1-3]
2019-09-25 15:07:01 +00:00
void MulMatVec(const s16 M[3][3], const s16 Vx, const s16 Vy, const s16 Vz, u8 shift, bool lm);
2019-09-25 05:40:08 +00:00
// 3x3 matrix * 3x1 vector with translation, updates MAC[1-3] and IR[1-3]
2019-09-25 15:07:01 +00:00
void MulMatVec(const s16 M[3][3], const s32 T[3], const s16 Vx, const s16 Vy, const s16 Vz, u8 shift, bool lm);
2019-09-22 11:41:11 +00:00
2019-09-25 15:07:01 +00:00
void RTPS(const s16 V[3], bool sf, bool lm);
2019-09-25 10:24:50 +00:00
void NCCS(const s16 V[3], bool sf, bool lm);
2019-09-22 11:41:11 +00:00
void NCDS(const s16 V[3], bool sf, bool lm);
void Execute_RTPS(Instruction inst);
void Execute_RTPT(Instruction inst);
void Execute_NCLIP(Instruction inst);
void Execute_SQR(Instruction inst);
2019-09-22 10:38:11 +00:00
void Execute_AVSZ3(Instruction inst);
void Execute_AVSZ4(Instruction inst);
2019-09-25 10:24:50 +00:00
void Execute_NCCS(Instruction inst);
void Execute_NCCT(Instruction inst);
2019-09-22 11:41:11 +00:00
void Execute_NCDS(Instruction inst);
2019-09-25 10:24:50 +00:00
void Execute_NCDT(Instruction inst);
2019-09-25 05:58:33 +00:00
void Execute_MVMVA(Instruction inst);
2019-09-25 10:24:50 +00:00
void Execute_DPCS(Instruction inst);
Regs m_regs = {};
};
2019-09-22 11:41:11 +00:00
#include "gte.inl"
} // namespace GTE