Arachnoid GLESv1.1 plugin. Compile and run (a bit glitchy and no frameskip) on the...
[mupen64plus-pandora.git] / source / mupen64plus-video-arachnoid / src / ucodes / UCode10.cpp
CommitLineData
22726e4d 1/******************************************************************************
2 * Arachnoid Graphics Plugin for Mupen64Plus
3 * http://bitbucket.org/wahrhaft/mupen64plus-video-arachnoid/
4 *
5 * Copyright (C) 2007 Kristofer Karlsson, Rickard Niklasson
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *****************************************************************************/
21
22#include "UCode10.h"
23#include "UCode5.h"
24
25//Forward declaration
26#include "GBI.h"
27#include "RSP.h"
28#include "RDP.h"
29#include "Memory.h"
30#include "DisplayListParser.h"
31#include "UCodeDefs.h"
32#include "GBIDefs.h"
33#include "Logger.h"
34
35
36#define CONKER_BFD_ADD_VERTICES 1 /*F3DEX2_VTX ?*/
37
38#define RSP_MOVE_WORD_MATRIX 0x00 // NOTE: also used by movemem
39#define RSP_MOVE_WORD_NUMLIGHT 0x02
40#define RSP_MOVE_WORD_CLIP 0x04
41#define RSP_MOVE_WORD_SEGMENT 0x06
42#define RSP_MOVE_WORD_FOG 0x08
43#define RSP_MOVE_WORD_LIGHTCOL 0x0a
44#define RSP_MOVE_WORD_POINTS 0x0c
45#define RSP_MOVE_WORD_PERSPNORM 0x0e
46
47#define RSP_GBI2_MV_MEM__VIEWPORT 8
48#define RSP_GBI2_MV_MEM__LIGHT 10
49#define RSP_GBI2_MV_MEM__POINT 12
50#define RSP_GBI2_MV_MEM__MATRIX 14 /* NOTE: this is in moveword table */
51
52//-----------------------------------------------------------------------------
53// Static Variables
54//-----------------------------------------------------------------------------
55RSP* UCode10::m_rsp = 0; //!< Pointer to Reality Signal Processor
56RDP* UCode10::m_rdp = 0; //!< Pointer to Reality Drawing Processor
57Memory* UCode10::m_memory = 0;
58GBI* UCode10::m_gbi = 0;
59DisplayListParser* UCode10::m_displayListParser = 0;
60
61//-----------------------------------------------------------------------------
62//! Constructor
63//-----------------------------------------------------------------------------
64UCode10::UCode10()
65{
66}
67
68//-----------------------------------------------------------------------------
69//! Destructor
70//-----------------------------------------------------------------------------
71UCode10::~UCode10()
72{
73}
74
75//-----------------------------------------------------------------------------
76//! Initialize
77//-----------------------------------------------------------------------------
78void UCode10::initialize(GBI* gbi, RSP* rsp, RDP* rdp, Memory* mem, DisplayListParser* dlp)
79{
80 m_gbi = gbi;
81 m_rsp = rsp;
82 m_rdp = rdp;
83 m_memory = mem;
84 m_displayListParser = dlp;
85}
86
87//-----------------------------------------------------------------------------
88//! Initialize GBI
89//-----------------------------------------------------------------------------
90void UCode10::initializeGBI()
91{
92 //Load F3DEX
93 UCode5::initializeGBI();
94
95 GBI_SetGBI( GBI::G_VTX, CONKER_BFD_ADD_VERTICES, m_gbi->m_cmds, ConkerBFD_Vertex );
96 GBI_SetGBI( GBI::G_TRI4, 0x10, m_gbi->m_cmds, ConkerBFD_Vertex );
97 GBI_SetGBI( GBI::G_TRI4, 0x11, m_gbi->m_cmds, ConkerBFD_Add4Triangles );
98 GBI_SetGBI( GBI::G_TRI4, 0x12, m_gbi->m_cmds, ConkerBFD_Add4Triangles );
99 GBI_SetGBI( GBI::G_TRI4, 0x13, m_gbi->m_cmds, ConkerBFD_Add4Triangles );
100 GBI_SetGBI( GBI::G_TRI4, 0x14, m_gbi->m_cmds, ConkerBFD_Add4Triangles );
101 GBI_SetGBI( GBI::G_TRI4, 0x15, m_gbi->m_cmds, ConkerBFD_Add4Triangles );
102 GBI_SetGBI( GBI::G_TRI4, 0x16, m_gbi->m_cmds, ConkerBFD_Add4Triangles );
103 GBI_SetGBI( GBI::G_TRI4, 0x17, m_gbi->m_cmds, ConkerBFD_Add4Triangles );
104 GBI_SetGBI( GBI::G_TRI4, 0x18, m_gbi->m_cmds, ConkerBFD_Add4Triangles );
105 GBI_SetGBI( GBI::G_TRI4, 0x19, m_gbi->m_cmds, ConkerBFD_Add4Triangles );
106 GBI_SetGBI( GBI::G_TRI4, 0x1a, m_gbi->m_cmds, ConkerBFD_Add4Triangles );
107 GBI_SetGBI( GBI::G_TRI4, 0x1b, m_gbi->m_cmds, ConkerBFD_Add4Triangles );
108 GBI_SetGBI( GBI::G_TRI4, 0x1c, m_gbi->m_cmds, ConkerBFD_Add4Triangles );
109 GBI_SetGBI( GBI::G_TRI4, 0x1d, m_gbi->m_cmds, ConkerBFD_Add4Triangles );
110 GBI_SetGBI( GBI::G_TRI4, 0x1e, m_gbi->m_cmds, ConkerBFD_Add4Triangles );
111 GBI_SetGBI( GBI::G_TRI4, 0x1f, m_gbi->m_cmds, ConkerBFD_Add4Triangles );
112 GBI_SetGBI( GBI::G_MOVEWORD, F3DEX2_MOVEWORD, m_gbi->m_cmds, ConkerBFD_MoveWord );
113 GBI_SetGBI( GBI::G_MOVEMEM, F3DEX2_MOVEMEM, m_gbi->m_cmds, ConkerBFD_MoveMem );
114}
115
116//-----------------------------------------------------------------------------
117//! Conker Bad Fur Day Vertex
118//-----------------------------------------------------------------------------
119void UCode10::ConkerBFD_Vertex(MicrocodeArgument* ucode)
120{
121 unsigned int vertexEnd = (((ucode->w0) )&0xFFF)/2;
122 unsigned int numVertices = (((ucode->w0)>>12)&0xFFF);
123
124 //Add Vertices
125 m_rsp->getVertexMgr()->addConkerVertices( ucode->w1, numVertices, vertexEnd - numVertices );
126 // m_rsp->RSP_Vertex( ucode->w1, numVertices, vertexEnd - numVertices);
127}
128
129//-----------------------------------------------------------------------------
130//! Conker Bad Fur Day Add Four Triangles
131//-----------------------------------------------------------------------------
132void UCode10::ConkerBFD_Add4Triangles(MicrocodeArgument* ucode)
133{
134 unsigned int w0 = ucode->w0;
135 unsigned int w1 = ucode->w1;
136
137 unsigned int idx[12];
138 idx[0] = (w1 )&0x1F; //Tri1
139 idx[1] = (w1>> 5)&0x1F;
140 idx[2] = (w1>>10)&0x1F;
141 idx[3] = (w1>>15)&0x1F; //Tri2
142 idx[4] = (w1>>20)&0x1F;
143 idx[5] = (w1>>25)&0x1F;
144 idx[6] = (w0 )&0x1F; //Tri3
145 idx[7] = (w0>> 5)&0x1F;
146 idx[8] = (w0>>10)&0x1F;
147 idx[9] = (((w0>>15)&0x7)<<2)|(w1>>30); //Tri4
148 idx[10] = (w0>>18)&0x1F;
149 idx[11] = (w0>>23)&0x1F;
150
151 //Add Triagles
152 m_rsp->RSP_1Triangle(idx[0], idx[1], idx[2]);
153 m_rsp->RSP_1Triangle(idx[3], idx[4], idx[5]);
154 m_rsp->RSP_1Triangle(idx[6], idx[7], idx[8]);
155 m_rsp->RSP_1Triangle(idx[9], idx[10], idx[11]);
156
157 unsigned int* RDRAMu32 = m_memory->getRDRAMint32();
158
159 //Get next command
160 MicrocodeArgument* ucodeNext = (MicrocodeArgument*)&RDRAMu32[(m_displayListParser->getPC()>>2)];
161
162 //Conker Bad Fur Day Render Fix (because conker has multiple Tri4)
163 ucode->cmd = GBI::G_TRI4;
164 if ( ucodeNext->cmd >= 0x10 && ucodeNext->cmd <= 0x1f )
165 {
166 ucodeNext->cmd = GBI::G_TRI4;
167 }
168}
169
170//-----------------------------------------------------------------------------
171//! Conker Bad Fur Day Move Word
172//-----------------------------------------------------------------------------
173void UCode10::ConkerBFD_MoveWord(MicrocodeArgument* ucode)
174{
175 unsigned int dwType = ((ucode->w0) >> 16) & 0xFF;
176
177 if( dwType == RSP_MOVE_WORD_NUMLIGHT )
178 {
179 m_rsp->RSP_NumLights( ((ucode->w1)/48) );
180 }
181 else
182 {
183 UCode5::F3DEX2_MoveWord(ucode);
184 }
185}
186
187//-----------------------------------------------------------------------------
188//! Conker Bad Fur Day Move Memory
189//-----------------------------------------------------------------------------
190void UCode10::ConkerBFD_MoveMem(MicrocodeArgument* ucode)
191{
192 unsigned int dwType = ((ucode->w0) ) & 0xFE;
193 unsigned int dwAddr = ucode->w1; //RSPSegmentAddr((gfx->words.w1));
194
195 switch ( dwType )
196 {
197 case RSP_GBI2_MV_MEM__MATRIX:
198 m_rsp->getVertexMgr()->setConkerAddress(dwAddr);
199 break;
200
201 case RSP_GBI2_MV_MEM__LIGHT:
202 {
203 unsigned int dwOffset2 = ((ucode->w0) >> 5) & 0x3FFF;
204 if( dwOffset2 >= 0x30 )
205 {
206 m_rsp->RSP_Light(((dwOffset2 - 0x30)/0x30), dwAddr);
207 }
208 else
209 {
210 //FIX ME
211 }
212 }
213 break;
214
215 default:
216 UCode5::F3DEX2_MoveMem(ucode);
217 break;
218 }
219}