Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/src/core/cpu_pgxp.h
7400 views
1
// SPDX-FileCopyrightText: 2016 iCatButler, 2019-2024 Connor McLaughlin <[email protected]>
2
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
3
4
#pragma once
5
#include "cpu_core.h"
6
7
namespace CPU::PGXP {
8
9
/// State management.
10
void Initialize();
11
void Reset();
12
void Shutdown();
13
14
/// Returns true if PGXP state should be saved to memory save states.
15
bool ShouldSavePGXPState();
16
17
/// Returns memory usage to serialize additional PGXP state.
18
size_t GetStateSize();
19
20
/// Save/load additional PGXP state.
21
void DoState(StateWrapper& sw);
22
23
/// Vertex lookup from GPU side.
24
bool GetPreciseVertex(u32 addr, u32 value, int x, int y, int xOffs, int yOffs, float* out_x, float* out_y,
25
float* out_w);
26
27
// GTE instruction hooks.
28
29
void GTE_RTPS(float x, float y, float z, u32 value);
30
bool GTE_HasPreciseVertices(u32 sxy0, u32 sxy1, u32 sxy2);
31
float GTE_NCLIP();
32
33
// CPU instruction implementations.
34
35
void CPU_MFC2(Instruction instr, u32 rdVal);
36
void CPU_MTC2(Instruction instr, u32 rtVal);
37
void CPU_LWC2(Instruction instr, u32 addr, u32 rtVal);
38
void CPU_SWC2(Instruction instr, u32 addr, u32 rtVal);
39
void CPU_LW(Instruction instr, u32 addr, u32 rtVal);
40
void CPU_LH(Instruction instr, u32 addr, u32 rtVal);
41
void CPU_LHU(Instruction instr, u32 addr, u32 rtVal);
42
void CPU_LBx(Instruction instr, u32 addr, u32 rtVal);
43
void CPU_LWx(Instruction instr, u32 addr, u32 rtVal);
44
void CPU_SB(Instruction instr, u32 addr, u32 rtVal);
45
void CPU_SH(Instruction instr, u32 addr, u32 rtVal);
46
void CPU_SW(Instruction instr, u32 addr, u32 rtVal);
47
void CPU_SWx(Instruction instr, u32 addr, u32 rtVal);
48
void CPU_MOVE(u32 Rd, u32 Rs, u32 rsVal);
49
void CPU_MOVE_Packed(u32 rd_and_rs, u32 rsVal);
50
void CPU_ADDI(Instruction instr, u32 rsVal);
51
void CPU_ANDI(Instruction instr, u32 rsVal);
52
void CPU_ORI(Instruction instr, u32 rsVal);
53
void CPU_XORI(Instruction instr, u32 rsVal);
54
void CPU_SLTI(Instruction instr, u32 rsVal);
55
void CPU_SLTIU(Instruction instr, u32 rsVal);
56
void CPU_LUI(Instruction instr);
57
void CPU_ADD(Instruction instr, u32 rsVal, u32 rtVal);
58
void CPU_SUB(Instruction instr, u32 rsVal, u32 rtVal);
59
void CPU_AND_(Instruction instr, u32 rsVal, u32 rtVal);
60
void CPU_OR_(Instruction instr, u32 rsVal, u32 rtVal);
61
void CPU_XOR_(Instruction instr, u32 rsVal, u32 rtVal);
62
void CPU_NOR(Instruction instr, u32 rsVal, u32 rtVal);
63
void CPU_SLT(Instruction instr, u32 rsVal, u32 rtVal);
64
void CPU_SLTU(Instruction instr, u32 rsVal, u32 rtVal);
65
void CPU_MULT(Instruction instr, u32 rsVal, u32 rtVal);
66
void CPU_MULTU(Instruction instr, u32 rsVal, u32 rtVal);
67
void CPU_DIV(Instruction instr, u32 rsVal, u32 rtVal);
68
void CPU_DIVU(Instruction instr, u32 rsVal, u32 rtVal);
69
void CPU_SLL(Instruction instr, u32 rtVal);
70
void CPU_SRL(Instruction instr, u32 rtVal);
71
void CPU_SRA(Instruction instr, u32 rtVal);
72
void CPU_SLLV(Instruction instr, u32 rtVal, u32 rsVal);
73
void CPU_SRLV(Instruction instr, u32 rtVal, u32 rsVal);
74
void CPU_SRAV(Instruction instr, u32 rtVal, u32 rsVal);
75
void CPU_MFC0(Instruction instr, u32 rdVal);
76
void CPU_MTC0(Instruction instr, u32 rdVal, u32 rtVal);
77
78
// Utility functions.
79
80
ALWAYS_INLINE u32 PackMoveArgs(Reg rd, Reg rs)
81
{
82
return (static_cast<u32>(rd) << 8) | static_cast<u32>(rs);
83
}
84
85
ALWAYS_INLINE void TryMove(Reg rd, Reg rs, Reg rt)
86
{
87
u32 src;
88
if (rs == Reg::zero)
89
src = static_cast<u32>(rt);
90
else if (rt == Reg::zero)
91
src = static_cast<u32>(rs);
92
else
93
return;
94
95
CPU_MOVE(static_cast<u32>(rd), src, g_state.regs.r[src]);
96
}
97
98
ALWAYS_INLINE void TryMoveImm(Reg rd, Reg rs, u32 imm)
99
{
100
if (imm == 0)
101
{
102
const u32 src = static_cast<u32>(rs);
103
CPU_MOVE(static_cast<u32>(rd), src, g_state.regs.r[src]);
104
}
105
}
106
107
} // namespace CPU::PGXP
108