Arachnoid GLESv1.1 plugin. Compile and run (a bit glitchy and no frameskip) on the...
[mupen64plus-pandora.git] / source / mupen64plus-video-arachnoid / src / ucodes / UCode6.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 "UCode6.h"
23#include "UCode0.h"
24#include "GBI.h"
25#include "RSP.h"
26#include "RDP.h"
27#include "Memory.h"
28#include "UCodeDefs.h"
29#include "GBIDefs.h"
30#include "Logger.h"
31#include "DisplayListParser.h"
32#include "RSPMatrixManager.h"
33
34//-----------------------------------------------------------------------------
35// Static Variables
36//-----------------------------------------------------------------------------
37GBI* UCode6::m_gbi = 0; // Pointer to Graphics Binary Interface
38RSP* UCode6::m_rsp = 0; // Pointer to Reality Signal Processor
39RDP* UCode6::m_rdp = 0; // Pointer to Reality Drawing Processor
40DisplayListParser* UCode6::m_displayListParser = 0;
41Memory* UCode6::m_memory = 0;
42unsigned int UCode6::m_vertexIndex = 0;
43
44//-----------------------------------------------------------------------------
45//! Constructor
46//-----------------------------------------------------------------------------
47UCode6::UCode6()
48{
49}
50
51//-----------------------------------------------------------------------------
52//! Destructor
53//-----------------------------------------------------------------------------
54UCode6::~UCode6()
55{
56}
57
58//-----------------------------------------------------------------------------
59// Initialize
60//-----------------------------------------------------------------------------
61void UCode6::initialize(GBI* gbi, RSP* rsp, RDP* rdp, Memory* memory, DisplayListParser* dlp)
62{
63 m_gbi = gbi;
64 m_rsp = rsp;
65 m_rdp = rdp;
66 m_memory = memory;
67 m_displayListParser = dlp;
68}
69
70//-----------------------------------------------------------------------------
71//* Initialize GBI
72//! Assigns functions to the GBI
73//-----------------------------------------------------------------------------
74void UCode6::initializeGBI()
75{
76 GBI_InitFlags( F3D );
77
78 // GBI Command Command Value Command Function
79 GBI_SetGBI( GBI::G_SPNOOP, F3D_SPNOOP, m_gbi->m_cmds, UCode0::F3D_SPNoOp );
80 GBI_SetGBI( GBI::G_DMA_MTX, F3DDKR_DMA_MTX, m_gbi->m_cmds, F3DDKR_DMA_Mtx );
81 GBI_SetGBI( GBI::G_MOVEMEM, F3D_MOVEMEM, m_gbi->m_cmds, UCode0::F3D_MoveMem );
82 GBI_SetGBI( GBI::G_DMA_VTX, F3DDKR_DMA_VTX, m_gbi->m_cmds, F3DDKR_DMA_Vtx );
83 GBI_SetGBI( GBI::G_DL, F3D_DL, m_gbi->m_cmds, UCode0::F3D_DList );
84 GBI_SetGBI( GBI::G_DMA_DL, F3DDKR_DMA_DL, m_gbi->m_cmds, F3DDKR_DMA_DList );
85 GBI_SetGBI( GBI::G_DMA_TRI, F3DDKR_DMA_TRI, m_gbi->m_cmds, F3DDKR_DMA_Tri );
86 GBI_SetGBI( GBI::G_DMA_OFFSETS, F3DDKR_DMA_OFFSETS, m_gbi->m_cmds, F3DDKR_DMA_Offsets );
87 GBI_SetGBI( GBI::G_CULLDL, F3D_CULLDL, m_gbi->m_cmds, UCode0::F3D_CullDL );
88 GBI_SetGBI( GBI::G_MOVEWORD, F3D_MOVEWORD, m_gbi->m_cmds, F3DDKR_MoveWord );
89 GBI_SetGBI( GBI::G_TEXTURE, F3D_TEXTURE, m_gbi->m_cmds, UCode0::F3D_Texture );
90 GBI_SetGBI( GBI::G_SETOTHERMODE_H, F3D_SETOTHERMODE_H, m_gbi->m_cmds, UCode0::F3D_SetOtherMode_H );
91 GBI_SetGBI( GBI::G_SETOTHERMODE_L, F3D_SETOTHERMODE_L, m_gbi->m_cmds, UCode0::F3D_SetOtherMode_L );
92 GBI_SetGBI( GBI::G_ENDDL, F3D_ENDDL, m_gbi->m_cmds, UCode0::F3D_EndDL );
93 GBI_SetGBI( GBI::G_SETGEOMETRYMODE, F3D_SETGEOMETRYMODE, m_gbi->m_cmds, UCode0::F3D_SetGeometryMode );
94 GBI_SetGBI( GBI::G_CLEARGEOMETRYMODE,F3D_CLEARGEOMETRYMODE, m_gbi->m_cmds, UCode0::F3D_ClearGeometryMode );
95 GBI_SetGBI( GBI::G_QUAD, F3D_QUAD, m_gbi->m_cmds, UCode0::F3D_Quad );
96 GBI_SetGBI( GBI::G_RDPHALF_1, F3D_RDPHALF_1, m_gbi->m_cmds, UCode0::F3D_RDPHalf_1 );
97 GBI_SetGBI( GBI::G_RDPHALF_2, F3D_RDPHALF_2, m_gbi->m_cmds, UCode0::F3D_RDPHalf_2 );
98 GBI_SetGBI( GBI::G_RDPHALF_CONT, F3D_RDPHALF_CONT, m_gbi->m_cmds, UCode0::F3D_RDPHalf_Cont );
99 GBI_SetGBI( GBI::G_TRI4, F3D_TRI4, m_gbi->m_cmds, UCode0::F3D_Tri4 );
100}
101
102//-----------------------------------------------------------------------------
103// DMA Matrix
104//-----------------------------------------------------------------------------
105void UCode6::F3DDKR_DMA_Mtx(MicrocodeArgument* ucode)
106{
107 if (_SHIFTR( ucode->w0, 0, 16 ) != 64)
108 {
109 //GBI_DetectUCode(); // Something's wrong
110 return;
111 }
112
113 unsigned int index = _SHIFTR( ucode->w0, 16, 4 );
114 unsigned int multiply;
115
116 if (index == 0) // DKR
117 {
118 index = _SHIFTR( ucode->w0, 22, 2 );
119 multiply = 0;
120 }
121 else // Gemini
122 {
123 multiply = _SHIFTR( ucode->w0, 23, 1 );
124 }
125
126 m_rsp->RSP_DMAMatrix( ucode->w1, index, multiply );
127}
128
129//-----------------------------------------------------------------------------
130// DMA Vertex
131//-----------------------------------------------------------------------------
132void UCode6::F3DDKR_DMA_Vtx(MicrocodeArgument* ucode)
133{
134 if ((ucode->w0 & F3DDKR_VTX_APPEND))
135 {
136 if ( m_rsp->getVertexMgr()->getBillboard() ) {
137 m_vertexIndex = 1;
138 }
139 }
140 else {
141 m_vertexIndex = 0;
142 }
143
144 unsigned int n = _SHIFTR( ucode->w0, 19, 5 ) + 1;
145
146 m_rsp->RSP_DMAVertex( ucode->w1, n, m_vertexIndex + _SHIFTR( ucode->w0, 9, 5 ) );
147
148 m_vertexIndex += n;
149}
150
151//-----------------------------------------------------------------------------
152// DMA Triangle
153//-----------------------------------------------------------------------------
154void UCode6::F3DDKR_DMA_Tri(MicrocodeArgument* ucode)
155{
156 m_rsp->RSP_DMATriangles( ucode->w1, _SHIFTR( ucode->w0, 4, 12 ) );
157 m_vertexIndex = 0;
158}
159
160//-----------------------------------------------------------------------------
161// DMA Display List
162//-----------------------------------------------------------------------------
163void UCode6::F3DDKR_DMA_DList(MicrocodeArgument* ucode)
164{
165 m_rsp->RSP_DMADisplayList( ucode->w0, ucode->w1 /*_SHIFTR( ucode->w0, 16, 8 )*/ );
166}
167
168//-----------------------------------------------------------------------------
169// DMA Offsets
170//-----------------------------------------------------------------------------
171void UCode6::F3DDKR_DMA_Offsets(MicrocodeArgument* ucode)
172{
173 Logger::getSingleton().printMsg("PerfectDark_Vertex", M64MSG_VERBOSE);
174 RSPUCodeSetDMAOffsets* temp = (RSPUCodeSetDMAOffsets*)ucode;
175
176 //Set DMA Offsets
177 m_rsp->RSP_SetDMAOffsets(temp->addressOffsetMatrix, temp->addressOffsetVertex);
178}
179
180//-----------------------------------------------------------------------------
181// MoveWord
182//-----------------------------------------------------------------------------
183void UCode6::F3DDKR_MoveWord(MicrocodeArgument* ucode)
184{
185 switch (_SHIFTR( ucode->w0, 0, 8 ))
186 {
187 case 0x02:
188 m_rsp->getVertexMgr()->setBillboard( ucode->w1 & 1 );
189 break;
190 case 0x0A:
191 m_rsp->getMatrixMgr()->selectViewMatrix(_SHIFTR( ucode->w1, 6, 2 ));
192 break;
193 default:
194 UCode0::F3D_MoveWord( ucode );
195 break;
196 }
197}