34cf4058 |
1 | #include <math.h> |
2 | #include "Common.h" |
3 | #include "gles2N64.h" |
4 | #include "OpenGL.h" |
5 | #include "Debug.h" |
6 | #include "RSP.h" |
7 | #include "RDP.h" |
8 | #include "N64.h" |
9 | #include "F3D.h" |
10 | #include "3DMath.h" |
11 | #include "VI.h" |
12 | #include "ShaderCombiner.h" |
13 | #include "DepthBuffer.h" |
14 | #include "GBI.h" |
15 | #include "gSP.h" |
16 | #include "Textures.h" |
17 | |
18 | //#define PRINT_DISPLAYLIST |
19 | //#define PRINT_DISPLAYLIST_NUM 1 |
20 | |
21 | RSPInfo RSP; |
22 | |
23 | void RSP_LoadMatrix( f32 mtx[4][4], u32 address ) |
24 | { |
25 | |
26 | f32 recip = 1.5258789e-05f; |
27 | |
28 | struct _N64Matrix |
29 | { |
30 | s16 integer[4][4]; |
31 | u16 fraction[4][4]; |
32 | } *n64Mat = (struct _N64Matrix *)&RDRAM[address]; |
33 | |
34 | for (int i = 0; i < 4; i++) |
35 | for (int j = 0; j < 4; j++) |
36 | mtx[i][j] = (GLfloat)(n64Mat->integer[i][j^1]) + (GLfloat)(n64Mat->fraction[i][j^1]) * recip; |
37 | } |
38 | |
39 | void RSP_ProcessDList() |
40 | { |
41 | VI_UpdateSize(); |
42 | OGL_UpdateScale(); |
43 | TextureCache_ActivateNoise(2); |
44 | |
45 | RSP.PC[0] = *(u32*)&DMEM[0x0FF0]; |
46 | RSP.PCi = 0; |
47 | RSP.count = 0; |
48 | |
49 | RSP.halt = FALSE; |
50 | RSP.busy = TRUE; |
51 | |
52 | #ifdef __TRIBUFFER_OPT |
53 | __indexmap_clear(); |
54 | #endif |
55 | |
56 | gSP.matrix.stackSize = min( 32, *(u32*)&DMEM[0x0FE4] >> 6 ); |
57 | gSP.matrix.modelViewi = 0; |
58 | gSP.changed |= CHANGED_MATRIX; |
59 | |
60 | for (int i = 0; i < 4; i++) |
61 | for (int j = 0; j < 4; j++) |
62 | gSP.matrix.modelView[0][i][j] = 0.0f; |
63 | |
64 | gSP.matrix.modelView[0][0][0] = 1.0f; |
65 | gSP.matrix.modelView[0][1][1] = 1.0f; |
66 | gSP.matrix.modelView[0][2][2] = 1.0f; |
67 | gSP.matrix.modelView[0][3][3] = 1.0f; |
68 | |
69 | u32 uc_start = *(u32*)&DMEM[0x0FD0]; |
70 | u32 uc_dstart = *(u32*)&DMEM[0x0FD8]; |
71 | u32 uc_dsize = *(u32*)&DMEM[0x0FDC]; |
72 | |
73 | if ((uc_start != RSP.uc_start) || (uc_dstart != RSP.uc_dstart)) |
74 | gSPLoadUcodeEx( uc_start, uc_dstart, uc_dsize ); |
75 | |
76 | gDPSetAlphaCompare(G_AC_NONE); |
77 | gDPSetDepthSource(G_ZS_PIXEL); |
78 | gDPSetRenderMode(0, 0); |
79 | gDPSetAlphaDither(G_AD_DISABLE); |
80 | gDPSetColorDither(G_CD_DISABLE); |
81 | gDPSetCombineKey(G_CK_NONE); |
82 | gDPSetTextureConvert(G_TC_FILT); |
83 | gDPSetTextureFilter(G_TF_POINT); |
84 | gDPSetTextureLUT(G_TT_NONE); |
85 | gDPSetTextureLOD(G_TL_TILE); |
86 | gDPSetTextureDetail(G_TD_CLAMP); |
87 | gDPSetTexturePersp(G_TP_PERSP); |
88 | gDPSetCycleType(G_CYC_1CYCLE); |
89 | gDPPipelineMode(G_PM_NPRIMITIVE); |
90 | |
91 | #ifdef PRINT_DISPLAYLIST |
92 | if ((RSP.DList%PRINT_DISPLAYLIST_NUM) == 0) LOG(LOG_VERBOSE, "BEGIN DISPLAY LIST %i \n", RSP.DList); |
93 | #endif |
94 | |
95 | while (!RSP.halt) |
96 | { |
97 | u32 pc = RSP.PC[RSP.PCi]; |
98 | |
99 | if ((pc + 8) > RDRAMSize) |
100 | { |
101 | #ifdef DEBUG |
102 | DebugMsg( DEBUG_LOW | DEBUG_ERROR, "ATTEMPTING TO EXECUTE RSP COMMAND AT INVALID RDRAM LOCATION\n" ); |
103 | #endif |
104 | break; |
105 | } |
106 | |
107 | |
108 | u32 w0 = *(u32*)&RDRAM[pc]; |
109 | u32 w1 = *(u32*)&RDRAM[pc+4]; |
110 | RSP.nextCmd = _SHIFTR( *(u32*)&RDRAM[pc+8], 24, 8 ); |
111 | RSP.cmd = _SHIFTR( w0, 24, 8 ); |
112 | RSP.PC[RSP.PCi] += 8; |
113 | |
114 | #ifdef PROFILE_GBI |
115 | GBI_ProfileBegin(RSP.cmd); |
116 | #endif |
117 | |
118 | #ifdef PRINT_DISPLAYLIST |
119 | 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); |
120 | #endif |
121 | |
122 | GBI.cmd[RSP.cmd]( w0, w1 ); |
123 | |
124 | #ifdef PROFILE_GBI |
125 | GBI_ProfileEnd(RSP.cmd); |
126 | #endif |
127 | } |
128 | |
129 | #ifdef PRINT_DISPLAYLIST |
130 | if ((RSP.DList%PRINT_DISPLAYLIST_NUM) == 0) LOG(LOG_VERBOSE, "END DISPLAY LIST %i \n", RSP.DList); |
131 | #endif |
132 | |
133 | RSP.busy = FALSE; |
134 | RSP.DList++; |
135 | gSP.changed |= CHANGED_COLORBUFFER; |
136 | } |
137 | |
138 | void RSP_Init() |
139 | { |
140 | RDRAMSize = 1024 * 1024 * 8; |
141 | RSP.DList = 0; |
142 | RSP.uc_start = RSP.uc_dstart = 0; |
143 | gDP.loadTile = &gDP.tiles[7]; |
144 | gSP.textureTile[0] = &gDP.tiles[0]; |
145 | gSP.textureTile[1] = &gDP.tiles[1]; |
146 | |
147 | DepthBuffer_Init(); |
148 | GBI_Init(); |
149 | } |
150 | |