1 /******************************************************************************
2 * Arachnoid Graphics Plugin for Mupen64Plus
3 * http://bitbucket.org/wahrhaft/mupen64plus-video-arachnoid/
5 * Copyright (C) 2007 Kristofer Karlsson, Rickard Niklasson
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.
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.
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 *****************************************************************************/
28 #include "UCodeDefs.h"
31 #include "DisplayListParser.h"
32 #include "RSPMatrixManager.h"
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
37 GBI* UCode6::m_gbi = 0; // Pointer to Graphics Binary Interface
38 RSP* UCode6::m_rsp = 0; // Pointer to Reality Signal Processor
39 RDP* UCode6::m_rdp = 0; // Pointer to Reality Drawing Processor
40 DisplayListParser* UCode6::m_displayListParser = 0;
41 Memory* UCode6::m_memory = 0;
42 unsigned int UCode6::m_vertexIndex = 0;
44 //-----------------------------------------------------------------------------
46 //-----------------------------------------------------------------------------
51 //-----------------------------------------------------------------------------
53 //-----------------------------------------------------------------------------
58 //-----------------------------------------------------------------------------
60 //-----------------------------------------------------------------------------
61 void UCode6::initialize(GBI* gbi, RSP* rsp, RDP* rdp, Memory* memory, DisplayListParser* dlp)
67 m_displayListParser = dlp;
70 //-----------------------------------------------------------------------------
72 //! Assigns functions to the GBI
73 //-----------------------------------------------------------------------------
74 void UCode6::initializeGBI()
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 );
102 //-----------------------------------------------------------------------------
104 //-----------------------------------------------------------------------------
105 void UCode6::F3DDKR_DMA_Mtx(MicrocodeArgument* ucode)
107 if (_SHIFTR( ucode->w0, 0, 16 ) != 64)
109 //GBI_DetectUCode(); // Something's wrong
113 unsigned int index = _SHIFTR( ucode->w0, 16, 4 );
114 unsigned int multiply;
116 if (index == 0) // DKR
118 index = _SHIFTR( ucode->w0, 22, 2 );
123 multiply = _SHIFTR( ucode->w0, 23, 1 );
126 m_rsp->RSP_DMAMatrix( ucode->w1, index, multiply );
129 //-----------------------------------------------------------------------------
131 //-----------------------------------------------------------------------------
132 void UCode6::F3DDKR_DMA_Vtx(MicrocodeArgument* ucode)
134 if ((ucode->w0 & F3DDKR_VTX_APPEND))
136 if ( m_rsp->getVertexMgr()->getBillboard() ) {
144 unsigned int n = _SHIFTR( ucode->w0, 19, 5 ) + 1;
146 m_rsp->RSP_DMAVertex( ucode->w1, n, m_vertexIndex + _SHIFTR( ucode->w0, 9, 5 ) );
151 //-----------------------------------------------------------------------------
153 //-----------------------------------------------------------------------------
154 void UCode6::F3DDKR_DMA_Tri(MicrocodeArgument* ucode)
156 m_rsp->RSP_DMATriangles( ucode->w1, _SHIFTR( ucode->w0, 4, 12 ) );
160 //-----------------------------------------------------------------------------
162 //-----------------------------------------------------------------------------
163 void UCode6::F3DDKR_DMA_DList(MicrocodeArgument* ucode)
165 m_rsp->RSP_DMADisplayList( ucode->w0, ucode->w1 /*_SHIFTR( ucode->w0, 16, 8 )*/ );
168 //-----------------------------------------------------------------------------
170 //-----------------------------------------------------------------------------
171 void UCode6::F3DDKR_DMA_Offsets(MicrocodeArgument* ucode)
173 Logger::getSingleton().printMsg("PerfectDark_Vertex", M64MSG_VERBOSE);
174 RSPUCodeSetDMAOffsets* temp = (RSPUCodeSetDMAOffsets*)ucode;
177 m_rsp->RSP_SetDMAOffsets(temp->addressOffsetMatrix, temp->addressOffsetVertex);
180 //-----------------------------------------------------------------------------
182 //-----------------------------------------------------------------------------
183 void UCode6::F3DDKR_MoveWord(MicrocodeArgument* ucode)
185 switch (_SHIFTR( ucode->w0, 0, 8 ))
188 m_rsp->getVertexMgr()->setBillboard( ucode->w1 & 1 );
191 m_rsp->getMatrixMgr()->selectViewMatrix(_SHIFTR( ucode->w1, 6, 2 ));
194 UCode0::F3D_MoveWord( ucode );