1 #include <math.h>
2 #include "Common.h"
3 #include "gles2N64.h"
4 #include "Debug.h"
5 #include "RSP.h"
6 #include "RDP.h"
7 #include "N64.h"
8 #include "F3D.h"
9 #include "3DMath.h"
10 #include "VI.h"
11 #include "ShaderCombiner.h"
12 #include "FrameBuffer.h"
13 #include "DepthBuffer.h"
14 #include "GBI.h"
15 #include "gSP.h"
16 #include "Turbo3D.h"
17 #include "Textures.h"
18 #include "Config.h"
19
RSP_LoadMatrix(float mtx[4][4],uint32_t address)20 void RSP_LoadMatrix( float mtx[4][4], uint32_t address )
21 {
22 int i, j;
23 float recip = 1.5258789e-05f;
24
25 struct _N64Matrix
26 {
27 int16_t integer[4][4];
28 uint16_t fraction[4][4];
29 } *n64Mat = (struct _N64Matrix *)&gfx_info.RDRAM[address];
30
31 for (i = 0; i < 4; i++)
32 for (j = 0; j < 4; j++)
33 mtx[i][j] = (float)(n64Mat->integer[i][j^1]) + (float)(n64Mat->fraction[i][j^1]) * recip;
34 }
35
36
RSP_ProcessDList(void)37 void RSP_ProcessDList(void)
38 {
39 int i, j;
40 uint32_t uc_start, uc_dstart, uc_dsize;
41
42 VI_UpdateSize();
43
44 __RSP.PC[0] = *(uint32_t*)&gfx_info.DMEM[0x0FF0];
45 __RSP.PCi = 0;
46 __RSP.count = -1;
47
48 __RSP.halt = false;
49 __RSP.busy = true;
50
51 gSP.matrix.stackSize = MIN( 32, *(uint32_t*)&gfx_info.DMEM[0x0FE4] >> 6 );
52 gSP.matrix.modelViewi = 0;
53 gSP.changed &= ~CHANGED_CPU_FB_WRITE;
54 gSP.changed |= CHANGED_MATRIX;
55 gln64gDPSetTexturePersp(G_TP_PERSP);
56
57 for (i = 0; i < 4; i++)
58 for (j = 0; j < 4; j++)
59 gSP.matrix.modelView[0][i][j] = 0.0f;
60
61 gSP.matrix.modelView[0][0][0] = 1.0f;
62 gSP.matrix.modelView[0][1][1] = 1.0f;
63 gSP.matrix.modelView[0][2][2] = 1.0f;
64 gSP.matrix.modelView[0][3][3] = 1.0f;
65
66 uc_start = *(uint32_t*)&gfx_info.DMEM[0x0FD0];
67 uc_dstart = *(uint32_t*)&gfx_info.DMEM[0x0FD8];
68 uc_dsize = *(uint32_t*)&gfx_info.DMEM[0x0FDC];
69
70 if ((uc_start != __RSP.uc_start) || (uc_dstart != __RSP.uc_dstart))
71 gln64gSPLoadUcodeEx( uc_start, uc_dstart, uc_dsize );
72
73 gln64gDPSetAlphaCompare(G_AC_NONE);
74 gln64gDPSetDepthSource(G_ZS_PIXEL);
75 gln64gDPSetRenderMode(0, 0);
76 gln64gDPSetAlphaDither(G_AD_DISABLE);
77 gln64gDPSetCombineKey(G_CK_NONE);
78 gln64gDPSetTextureFilter(G_TF_POINT);
79 gln64gDPSetTextureLUT(G_TT_NONE);
80 gln64gDPSetTextureLOD(G_TL_TILE);
81 gln64gDPSetTexturePersp(G_TP_PERSP);
82 gln64gDPSetCycleType(G_CYC_1CYCLE);
83 gln64gDPPipelineMode(G_PM_NPRIMITIVE);
84
85 #ifdef NEW
86 depthBufferList().setNotCleared();
87 #endif
88
89 if (GBI_GetCurrentMicrocodeType() == Turbo3D)
90 RunTurbo3D();
91 else
92 while (!__RSP.halt)
93 {
94 uint32_t pc = __RSP.PC[__RSP.PCi];
95
96 if ((pc + 8) > RDRAMSize)
97 break;
98
99
100 __RSP.w0 = *(uint32_t*)&gfx_info.RDRAM[pc];
101 __RSP.w1 = *(uint32_t*)&gfx_info.RDRAM[pc+4];
102 __RSP.cmd = _SHIFTR( __RSP.w0, 24, 8 );
103
104 __RSP.PC[__RSP.PCi] += 8;
105 __RSP.nextCmd = _SHIFTR( *(uint32_t*)&gfx_info.RDRAM[pc+8], 24, 8 );
106
107 GBI.cmd[__RSP.cmd]( __RSP.w0, __RSP.w1 );
108 RSP_CheckDLCounter();
109 }
110
111 if (config.frameBufferEmulation.copyToRDRAM)
112 FrameBuffer_CopyToRDRAM( gDP.colorImage.address );
113 if (config.frameBufferEmulation.copyDepthToRDRAM)
114 FrameBuffer_CopyDepthBuffer( gDP.colorImage.address );
115
116 __RSP.busy = false;
117 __RSP.DList++;
118 gSP.changed |= CHANGED_COLORBUFFER;
119 }
120
121 static
RSP_SetDefaultState(void)122 void RSP_SetDefaultState(void)
123 {
124 unsigned i, j;
125
126 gln64gSPTexture(1.0f, 1.0f, 0, 0, true);
127 gDP.loadTile = &gDP.tiles[7];
128 gSP.textureTile[0] = &gDP.tiles[0];
129 gSP.textureTile[1] = &gDP.tiles[1];
130 gSP.lookat[0].x = gSP.lookat[1].x = 1.0f;
131 gSP.lookatEnable = false;
132
133 gSP.objMatrix.A = 1.0f;
134 gSP.objMatrix.B = 0.0f;
135 gSP.objMatrix.C = 0.0f;
136 gSP.objMatrix.D = 1.0f;
137 gSP.objMatrix.X = 0.0f;
138 gSP.objMatrix.Y = 0.0f;
139 gSP.objMatrix.baseScaleX = 1.0f;
140 gSP.objMatrix.baseScaleY = 1.0f;
141 gSP.objRendermode = 0;
142
143 for (i = 0; i < 4; i++)
144 for (j = 0; j < 4; j++)
145 gSP.matrix.modelView[0][i][j] = 0.0f;
146
147 gSP.matrix.modelView[0][0][0] = 1.0f;
148 gSP.matrix.modelView[0][1][1] = 1.0f;
149 gSP.matrix.modelView[0][2][2] = 1.0f;
150 gSP.matrix.modelView[0][3][3] = 1.0f;
151
152 gDP.otherMode._u64 = 0U;
153 }
154
155 uint32_t DepthClearColor = 0xfffcfffc;
156
setDepthClearColor(void)157 static void setDepthClearColor(void)
158 {
159 if (strstr(__RSP.romname, (const char *)"Elmo's") != NULL)
160 DepthClearColor = 0xFFFFFFFF;
161 else if (strstr(__RSP.romname, (const char *)"Taz Express") != NULL)
162 DepthClearColor = 0xFFBCFFBC;
163 else if (strstr(__RSP.romname, (const char *)"NFL QBC 2000") != NULL || strstr(__RSP.romname, (const char *)"NFL Quarterback Club") != NULL || strstr(__RSP.romname, (const char *)"Jeremy McGrath Super") != NULL)
164 DepthClearColor = 0xFFFDFFFC;
165 else
166 DepthClearColor = 0xFFFCFFFC;
167 }
168
RSP_Init(void)169 void RSP_Init(void)
170 {
171 unsigned i;
172 char romname[21];
173
174 RDRAMSize = 1024 * 1024 * 8;
175 __RSP.DList = 0;
176 __RSP.uc_start = __RSP.uc_dstart = 0;
177
178 __RSP.bLLE = false;
179
180 for (i = 0; i < 20; ++i)
181 romname[i] = gfx_info.HEADER[(32 + i) ^ 3];
182 romname[20] = 0;
183
184 // remove all trailing spaces
185 while (romname[strlen(romname) - 1] == ' ')
186 romname[strlen(romname) - 1] = 0;
187
188 strncpy(__RSP.romname, romname, 21);
189 setDepthClearColor();
190 config.generalEmulation.hacks = 0;
191 if (strstr(__RSP.romname, (const char *)"OgreBattle64") != NULL)
192 config.generalEmulation.hacks |= hack_Ogre64;
193 else if (strstr(__RSP.romname, (const char *)"MarioGolf64") != NULL ||
194 strstr(__RSP.romname, (const char *)"F1 POLE POSITION 64") != NULL
195 )
196 config.generalEmulation.hacks |= hack_noDepthFrameBuffers;
197 else if (strstr(__RSP.romname, (const char *)"CONKER BFD") != NULL ||
198 strstr(__RSP.romname, (const char *)"MICKEY USA") != NULL
199 )
200 config.generalEmulation.hacks |= hack_blurPauseScreen;
201 else if (strstr(__RSP.romname, (const char *)"MarioTennis") != NULL)
202 config.generalEmulation.hacks |= hack_scoreboard;
203 else if (strstr(__RSP.romname, (const char *)"Pilot Wings64") != NULL)
204 config.generalEmulation.hacks |= hack_pilotWings;
205 else if (strstr(__RSP.romname, (const char *)"THE LEGEND OF ZELDA") != NULL ||
206 strstr(__RSP.romname, (const char *)"ZELDA MASTER QUEST") != NULL
207 )
208 config.generalEmulation.hacks |= hack_subscreen;
209 else if (strstr(__RSP.romname, (const char *)"LEGORacers") != NULL)
210 config.generalEmulation.hacks |= hack_legoRacers;
211 else if (strstr(__RSP.romname, (const char *)"Blast") != NULL)
212 config.generalEmulation.hacks |= hack_blastCorps;
213
214 RSP_SetDefaultState();
215
216 DepthBuffer_Init();
217 GBI_Init();
218
219 }
220