/
RSP.cpp
203 lines (169 loc) · 5.01 KB
/
RSP.cpp
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#ifndef __LINUX__
# include <windows.h>
#else
# include "winlnxdefs.h"
#endif
#include <math.h>
#include "Common.h"
#include "gles2N64.h"
#include "OpenGL.h"
#include "Debug.h"
#include "RSP.h"
#include "RDP.h"
#include "N64.h"
#include "F3D.h"
#include "3DMath.h"
#include "VI.h"
#include "ShaderCombiner.h"
#include "DepthBuffer.h"
#include "GBI.h"
#include "gSP.h"
#include "Textures.h"
//#define PRINT_DISPLAYLIST
//#define PRINT_DISPLAYLIST_NUM 1
RSPInfo RSP;
void RSP_LoadMatrix( f32 mtx[4][4], u32 address )
{
f32 recip = 1.5258789e-05f;
struct _N64Matrix
{
SHORT integer[4][4];
WORD fraction[4][4];
} *n64Mat = (struct _N64Matrix *)&RDRAM[address];
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
mtx[i][j] = (GLfloat)(n64Mat->integer[i][j^1]) + (GLfloat)(n64Mat->fraction[i][j^1]) * recip;
}
#ifdef RSPTHREAD
int RSP_ThreadProc(void *param)
{
RSP_Init();
while(true)
{
int num = 0;
RSP.threadIdle = RSP.threadEvents.empty();
//process all events
while(!RSP.threadEvents.empty())
{
switch (RSP.threadEvents.front())
{
case (RSPMSG_PROCESSDLIST):
RSP_ProcessDList();
break;
case (RSPMSG_UPDATESCREEN):
VI_UpdateScreen();
break;
case (RSPMSG_CLOSE):
OGL_Stop();
return 0;
break;
case (RSPMSG_DESTROYTEXTURES):
Combiner_Destroy();
TextureCache_Destroy();
break;
case (RSPMSG_INITTEXTURES):
TextureCache_Init();
Combiner_Init();
gSP.changed = gDP.changed = 0xFFFFFFFF;
break;
case (RSPMSG_CAPTURESCREEN):
OGL_SaveScreenshot();
break;
}
RSP.threadEvents.pop();
num++;
}
}
return 0;
}
#endif // RSPTHREAD
void RSP_ProcessDList()
{
VI_UpdateSize();
OGL_UpdateScale();
TextureCache_ActivateNoise(2);
RSP.PC[0] = *(u32*)&DMEM[0x0FF0];
RSP.PCi = 0;
RSP.count = 0;
RSP.halt = FALSE;
RSP.busy = TRUE;
#ifdef __TRIBUFFER_OPT
__indexmap_clear();
#endif
gSP.matrix.stackSize = min( 32, *(u32*)&DMEM[0x0FE4] >> 6 );
gSP.matrix.modelViewi = 0;
gSP.changed |= CHANGED_MATRIX;
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
gSP.matrix.modelView[0][i][j] = 0.0f;
gSP.matrix.modelView[0][0][0] = 1.0f;
gSP.matrix.modelView[0][1][1] = 1.0f;
gSP.matrix.modelView[0][2][2] = 1.0f;
gSP.matrix.modelView[0][3][3] = 1.0f;
u32 uc_start = *(u32*)&DMEM[0x0FD0];
u32 uc_dstart = *(u32*)&DMEM[0x0FD8];
u32 uc_dsize = *(u32*)&DMEM[0x0FDC];
if ((uc_start != RSP.uc_start) || (uc_dstart != RSP.uc_dstart))
gSPLoadUcodeEx( uc_start, uc_dstart, uc_dsize );
gDPSetAlphaCompare(G_AC_NONE);
gDPSetDepthSource(G_ZS_PIXEL);
gDPSetRenderMode(0, 0);
gDPSetAlphaDither(G_AD_DISABLE);
gDPSetColorDither(G_CD_DISABLE);
gDPSetCombineKey(G_CK_NONE);
gDPSetTextureConvert(G_TC_FILT);
gDPSetTextureFilter(G_TF_POINT);
gDPSetTextureLUT(G_TT_NONE);
gDPSetTextureLOD(G_TL_TILE);
gDPSetTextureDetail(G_TD_CLAMP);
gDPSetTexturePersp(G_TP_PERSP);
gDPSetCycleType(G_CYC_1CYCLE);
gDPPipelineMode(G_PM_NPRIMITIVE);
#ifdef PRINT_DISPLAYLIST
if ((RSP.DList%PRINT_DISPLAYLIST_NUM) == 0) LOG(LOG_VERBOSE, "BEGIN DISPLAY LIST %i \n", RSP.DList);
#endif
while (!RSP.halt)
{
u32 pc = RSP.PC[RSP.PCi];
if ((pc + 8) > RDRAMSize)
{
#ifdef DEBUG
DebugMsg( DEBUG_LOW | DEBUG_ERROR, "ATTEMPTING TO EXECUTE RSP COMMAND AT INVALID RDRAM LOCATION\n" );
#endif
break;
}
u32 w0 = *(u32*)&RDRAM[pc];
u32 w1 = *(u32*)&RDRAM[pc+4];
RSP.nextCmd = _SHIFTR( *(u32*)&RDRAM[pc+8], 24, 8 );
RSP.cmd = _SHIFTR( w0, 24, 8 );
RSP.PC[RSP.PCi] += 8;
#ifdef PROFILE_GBI
GBI_ProfileBegin(RSP.cmd);
#endif
#ifdef PRINT_DISPLAYLIST
if ((RSP.DList%PRINT_DISPLAYLIST_NUM) == 0) LOG(LOG_VERBOSE, "%s: w0=0x%x w1=0x%x\n", GBI_GetFuncName(GBI.current->type, RSP.cmd), w0, w1);
#endif
GBI.cmd[RSP.cmd]( w0, w1 );
#ifdef PROFILE_GBI
GBI_ProfileEnd(RSP.cmd);
#endif
}
#ifdef PRINT_DISPLAYLIST
if ((RSP.DList%PRINT_DISPLAYLIST_NUM) == 0) LOG(LOG_VERBOSE, "END DISPLAY LIST %i \n", RSP.DList);
#endif
RSP.busy = FALSE;
RSP.DList++;
gSP.changed |= CHANGED_COLORBUFFER;
}
void RSP_Init()
{
RDRAMSize = 1024 * 1024 * 8;
RSP.DList = 0;
RSP.uc_start = RSP.uc_dstart = 0;
gDP.loadTile = &gDP.tiles[7];
gSP.textureTile[0] = &gDP.tiles[0];
gSP.textureTile[1] = &gDP.tiles[1];
DepthBuffer_Init();
GBI_Init();
OGL_Start();
}