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