summaryrefslogtreecommitdiff
path: root/libpcsxcore/psxinterpreter_pgxp.h
blob: a61e8ed352812e113ec1cc95959f59cd24c9dd97 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#ifndef _PSX_INTERPRETER_PGXP_H_
#define _PSX_INTERPRETER_PGXP_H_


/////////////////////////////////////////////
// PGXP wrapper functions
/////////////////////////////////////////////

pgxpPsxNULL() {}

#define psxMTC2 gteMTC2
#define psxCTC2 gteCTC2
#define psxLWC2 gteLWC2
#define psxSWC2 gteSWC2

// Choose between debug and direct function
#ifdef PGXP_CPU_DEBUG
#define PGXP_PSX_FUNC_OP(pu, op, nReg) PGXP_psxTraceOp##nReg
#else
#define PGXP_PSX_FUNC_OP(pu, op, nReg) PGXP_##pu##_##op
#endif

#define PGXP_INT_FUNC(pu, op) \
static void pgxpPsx##op() { \
	PGXP_PSX_FUNC_OP(pu, op, )(psxRegs.code); \
}

#define PGXP_INT_FUNC_0_1(pu, op, test, nReg, reg1) \
static void pgxpPsx##op()	\
{ \
	if (test) return; \
		psx##op(); \
	PGXP_PSX_FUNC_OP(pu, op, nReg)(psxRegs.code, reg1); \
}

#define PGXP_INT_FUNC_1_0(pu, op, test, nReg, reg1)\
static void pgxpPsx##op()	\
{ \
	if (test) return; \
	PGXP_PSX_FUNC_OP(pu, op, nReg)(psxRegs.code, reg1); \
	psx##op(); \
}

#define PGXP_INT_FUNC_1_1(pu, op, test, nReg, reg1, reg2)\
static void pgxpPsx##op()	\
{ \
	if (test) return; \
	u32 temp2 = reg2; \
	psx##op(); \
	PGXP_PSX_FUNC_OP(pu, op, nReg)(psxRegs.code, reg1, temp2); \
}

#define PGXP_INT_FUNC_0_2(pu, op, test, nReg, reg1, reg2) \
static void pgxpPsx##op()	\
{ \
	if (test) return; \
		psx##op(); \
	PGXP_PSX_FUNC_OP(pu, op, nReg)(psxRegs.code, reg1, reg2); \
}

#define PGXP_INT_FUNC_2_1(pu, op, test, nReg, reg1, reg2, reg3) \
static void pgxpPsx##op()	\
{ \
	if (test) return; \
	u32 temp2 = reg2; \
	u32 temp3 = reg3; \
	psx##op(); \
	PGXP_PSX_FUNC_OP(pu, op, nReg)(psxRegs.code, reg1, temp2, temp3); \
}

#define PGXP_INT_FUNC_2_2(pu, op, test, nReg, reg1, reg2, reg3, reg4) \
static void pgxpPsx##op()	\
{ \
	if (test) return; \
	u32 temp3 = reg3; \
	u32 temp4 = reg4; \
	psx##op(); \
	PGXP_PSX_FUNC_OP(pu, op, nReg)(psxRegs.code, reg1, reg2, temp3, temp4); \
}

// Rt = Rs op imm 
PGXP_INT_FUNC_1_1(CPU, ADDI,	!_Rt_, 2, psxRegs.GPR.r[_Rt_], psxRegs.GPR.r[_Rs_])
PGXP_INT_FUNC_1_1(CPU, ADDIU,	!_Rt_, 2, psxRegs.GPR.r[_Rt_], psxRegs.GPR.r[_Rs_])
PGXP_INT_FUNC_1_1(CPU, ANDI,	!_Rt_, 2, psxRegs.GPR.r[_Rt_], psxRegs.GPR.r[_Rs_])
PGXP_INT_FUNC_1_1(CPU, ORI,		!_Rt_, 2, psxRegs.GPR.r[_Rt_], psxRegs.GPR.r[_Rs_])
PGXP_INT_FUNC_1_1(CPU, XORI,	!_Rt_, 2, psxRegs.GPR.r[_Rt_], psxRegs.GPR.r[_Rs_])
PGXP_INT_FUNC_1_1(CPU, SLTI,	!_Rt_, 2, psxRegs.GPR.r[_Rt_], psxRegs.GPR.r[_Rs_])
PGXP_INT_FUNC_1_1(CPU, SLTIU,	!_Rt_, 2, psxRegs.GPR.r[_Rt_], psxRegs.GPR.r[_Rs_])

// Rt = imm
PGXP_INT_FUNC_0_1(CPU, LUI, !_Rt_, 1, psxRegs.GPR.r[_Rt_])

// Rd = Rs op Rt 
PGXP_INT_FUNC_2_1(CPU, ADD,		!_Rd_, 3, psxRegs.GPR.r[_Rd_], psxRegs.GPR.r[_Rs_], psxRegs.GPR.r[_Rt_])
PGXP_INT_FUNC_2_1(CPU, ADDU,	!_Rd_, 3, psxRegs.GPR.r[_Rd_], psxRegs.GPR.r[_Rs_], psxRegs.GPR.r[_Rt_])
PGXP_INT_FUNC_2_1(CPU, SUB,		!_Rd_, 3, psxRegs.GPR.r[_Rd_], psxRegs.GPR.r[_Rs_], psxRegs.GPR.r[_Rt_])
PGXP_INT_FUNC_2_1(CPU, SUBU,	!_Rd_, 3, psxRegs.GPR.r[_Rd_], psxRegs.GPR.r[_Rs_], psxRegs.GPR.r[_Rt_])
PGXP_INT_FUNC_2_1(CPU, AND,		!_Rd_, 3, psxRegs.GPR.r[_Rd_], psxRegs.GPR.r[_Rs_], psxRegs.GPR.r[_Rt_])
PGXP_INT_FUNC_2_1(CPU, OR,		!_Rd_, 3, psxRegs.GPR.r[_Rd_], psxRegs.GPR.r[_Rs_], psxRegs.GPR.r[_Rt_])
PGXP_INT_FUNC_2_1(CPU, XOR,		!_Rd_, 3, psxRegs.GPR.r[_Rd_], psxRegs.GPR.r[_Rs_], psxRegs.GPR.r[_Rt_])
PGXP_INT_FUNC_2_1(CPU, NOR,		!_Rd_, 3, psxRegs.GPR.r[_Rd_], psxRegs.GPR.r[_Rs_], psxRegs.GPR.r[_Rt_])
PGXP_INT_FUNC_2_1(CPU, SLT,		!_Rd_, 3, psxRegs.GPR.r[_Rd_], psxRegs.GPR.r[_Rs_], psxRegs.GPR.r[_Rt_])
PGXP_INT_FUNC_2_1(CPU, SLTU,	!_Rd_, 3, psxRegs.GPR.r[_Rd_], psxRegs.GPR.r[_Rs_], psxRegs.GPR.r[_Rt_])

// Hi/Lo = Rs op Rt
PGXP_INT_FUNC_2_2(CPU, MULT,	0, 4, psxRegs.GPR.n.hi, psxRegs.GPR.n.lo, psxRegs.GPR.r[_Rs_], psxRegs.GPR.r[_Rt_])
PGXP_INT_FUNC_2_2(CPU, MULTU,	0, 4, psxRegs.GPR.n.hi, psxRegs.GPR.n.lo, psxRegs.GPR.r[_Rs_], psxRegs.GPR.r[_Rt_])
PGXP_INT_FUNC_2_2(CPU, DIV,		0, 4, psxRegs.GPR.n.hi, psxRegs.GPR.n.lo, psxRegs.GPR.r[_Rs_], psxRegs.GPR.r[_Rt_])
PGXP_INT_FUNC_2_2(CPU, DIVU,	0, 4, psxRegs.GPR.n.hi, psxRegs.GPR.n.lo, psxRegs.GPR.r[_Rs_], psxRegs.GPR.r[_Rt_])

// Mem[addr] = Rt
PGXP_INT_FUNC_0_2(CPU, SB,	0, 2, psxRegs.GPR.r[_Rt_],  _oB_)
PGXP_INT_FUNC_0_2(CPU, SH,	0, 2, psxRegs.GPR.r[_Rt_],  _oB_)
PGXP_INT_FUNC_0_2(CPU, SW,	0, 2, psxRegs.GPR.r[_Rt_],  _oB_)
PGXP_INT_FUNC_0_2(CPU, SWL, 0, 2, psxRegs.GPR.r[_Rt_],  _oB_)
PGXP_INT_FUNC_0_2(CPU, SWR, 0, 2, psxRegs.GPR.r[_Rt_],  _oB_)

// Rt = Mem[addr]
PGXP_INT_FUNC_0_2(CPU, LWL, 0, 2, psxRegs.GPR.r[_Rt_],  _oB_)
PGXP_INT_FUNC_0_2(CPU, LW,	0, 2, psxRegs.GPR.r[_Rt_],  _oB_)
PGXP_INT_FUNC_0_2(CPU, LWR, 0, 2, psxRegs.GPR.r[_Rt_],  _oB_)
PGXP_INT_FUNC_0_2(CPU, LH,	0, 2, psxRegs.GPR.r[_Rt_],  _oB_)
PGXP_INT_FUNC_0_2(CPU, LHU, 0, 2, psxRegs.GPR.r[_Rt_],  _oB_)
PGXP_INT_FUNC_0_2(CPU, LB,	0, 2, psxRegs.GPR.r[_Rt_],  _oB_)
PGXP_INT_FUNC_0_2(CPU, LBU, 0, 2, psxRegs.GPR.r[_Rt_],  _oB_)

//Rd = Rt op Sa
PGXP_INT_FUNC_1_1(CPU, SLL, !_Rd_, 2, psxRegs.GPR.r[_Rd_], psxRegs.GPR.r[_Rt_])
PGXP_INT_FUNC_1_1(CPU, SRL, !_Rd_, 2, psxRegs.GPR.r[_Rd_], psxRegs.GPR.r[_Rt_])
PGXP_INT_FUNC_1_1(CPU, SRA, !_Rd_, 2, psxRegs.GPR.r[_Rd_], psxRegs.GPR.r[_Rt_])

// Rd = Rt op Rs
PGXP_INT_FUNC_2_1(CPU, SLLV, !_Rd_, 3, psxRegs.GPR.r[_Rd_], psxRegs.GPR.r[_Rt_], psxRegs.GPR.r[_Rs_])
PGXP_INT_FUNC_2_1(CPU, SRLV, !_Rd_, 3, psxRegs.GPR.r[_Rd_], psxRegs.GPR.r[_Rt_], psxRegs.GPR.r[_Rs_])
PGXP_INT_FUNC_2_1(CPU, SRAV, !_Rd_, 3, psxRegs.GPR.r[_Rd_], psxRegs.GPR.r[_Rt_], psxRegs.GPR.r[_Rs_])

PGXP_INT_FUNC_1_1(CPU, MFHI, !_Rd_	, 2, psxRegs.GPR.r[_Rd_], psxRegs.GPR.n.hi)
PGXP_INT_FUNC_1_1(CPU, MTHI, 0		, 2, psxRegs.GPR.n.hi, psxRegs.GPR.r[_Rd_])
PGXP_INT_FUNC_1_1(CPU, MFLO, !_Rd_	, 2, psxRegs.GPR.r[_Rd_], psxRegs.GPR.n.lo)
PGXP_INT_FUNC_1_1(CPU, MTLO, 0		, 2, psxRegs.GPR.n.lo, psxRegs.GPR.r[_Rd_])


// COP2 (GTE)
PGXP_INT_FUNC_0_1(GTE, MFC2, !_Rt_, 1, psxRegs.CP2D.r[_Rd_])
PGXP_INT_FUNC_0_1(GTE, CFC2, !_Rt_, 1, psxRegs.CP2C.r[_Rd_])
PGXP_INT_FUNC_1_0(GTE, MTC2, 0, 1, psxRegs.GPR.r[_Rt_])
PGXP_INT_FUNC_1_0(GTE, CTC2, 0, 1, psxRegs.GPR.r[_Rt_])

PGXP_INT_FUNC_0_2(GTE, LWC2, 0, 2, psxRegs.CP2D.r[_Rt_], _oB_)
PGXP_INT_FUNC_0_2(GTE, SWC2, 0, 2, psxRegs.CP2D.r[_Rt_], _oB_)

// COP0
PGXP_INT_FUNC_0_1(CP0, MFC0, !_Rd_, 1, psxRegs.CP0.r[_Rd_])
PGXP_INT_FUNC_0_1(CP0, CFC0, !_Rd_, 1, psxRegs.CP0.r[_Rd_])
PGXP_INT_FUNC_1_0(CP0, MTC0, !_Rt_, 1, psxRegs.CP2D.r[_Rt_])
PGXP_INT_FUNC_1_0(CP0, CTC0, !_Rt_, 1, psxRegs.CP2D.r[_Rt_])
PGXP_INT_FUNC(CP0, RFE)

#endif//_PSX_INTERPRETER_PGXP_H_