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 *****************************************************************************/
31 #include "UCodeDefs.h"
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
38 RSP* UCode1::m_rsp = 0; //!< Pointer to Reality Signal Processor
39 RDP* UCode1::m_rdp = 0; //!< Pointer to Reality Drawing Processor
40 Memory* UCode1::m_memory = 0;
41 GBI* UCode1::m_gbi = 0;
43 //-----------------------------------------------------------------------------
45 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
57 //-----------------------------------------------------------------------------
59 //-----------------------------------------------------------------------------
60 void UCode1::initialize(GBI* gbi, RSP* rsp, RDP* rdp, Memory* memory)
68 //-----------------------------------------------------------------------------
70 //-----------------------------------------------------------------------------
71 void UCode1::initializeGBI()
73 // Set GeometryMode flags
74 GBI_InitFlags( F3DEX );
76 // GBI Command Command Value //Target Command Function
77 GBI_SetGBI( GBI::G_SPNOOP, F3D_SPNOOP, m_gbi->m_cmds, UCode0::F3D_SPNoOp );
78 GBI_SetGBI( GBI::G_MTX, F3D_MTX, m_gbi->m_cmds, UCode0::F3D_Mtx );
79 GBI_SetGBI( GBI::G_RESERVED0, F3D_RESERVED0, m_gbi->m_cmds, UCode0::F3D_Reserved0 );
80 GBI_SetGBI( GBI::G_MOVEMEM, F3D_MOVEMEM, m_gbi->m_cmds, UCode0::F3D_MoveMem );
81 GBI_SetGBI( GBI::G_VTX, F3D_VTX, m_gbi->m_cmds, F3DEX_Vtx );
82 GBI_SetGBI( GBI::G_RESERVED1, F3D_RESERVED1, m_gbi->m_cmds, UCode0::F3D_Reserved1 );
83 GBI_SetGBI( GBI::G_DL, F3D_DL, m_gbi->m_cmds, UCode0::F3D_DList );
84 GBI_SetGBI( GBI::G_RESERVED2, F3D_RESERVED2, m_gbi->m_cmds, UCode0::F3D_Reserved2 );
85 GBI_SetGBI( GBI::G_RESERVED3, F3D_RESERVED3, m_gbi->m_cmds, UCode0::F3D_Reserved3 );
86 GBI_SetGBI( GBI::G_SPRITE2D_BASE, F3D_SPRITE2D_BASE, m_gbi->m_cmds, UCode0::F3D_Sprite2D_Base );
87 GBI_SetGBI( GBI::G_TRI1, F3D_TRI1, m_gbi->m_cmds, F3DEX_Tri1 );
88 GBI_SetGBI( GBI::G_CULLDL, F3D_CULLDL, m_gbi->m_cmds, F3DEX_CullDL );
89 GBI_SetGBI( GBI::G_POPMTX, F3D_POPMTX, m_gbi->m_cmds, UCode0::F3D_PopMtx );
90 GBI_SetGBI( GBI::G_MOVEWORD, F3D_MOVEWORD, m_gbi->m_cmds, UCode0::F3D_MoveWord );
91 GBI_SetGBI( GBI::G_TEXTURE, F3D_TEXTURE, m_gbi->m_cmds, UCode0::F3D_Texture );
92 GBI_SetGBI( GBI::G_SETOTHERMODE_H, F3D_SETOTHERMODE_H, m_gbi->m_cmds, UCode0::F3D_SetOtherMode_H );
93 GBI_SetGBI( GBI::G_SETOTHERMODE_L, F3D_SETOTHERMODE_L, m_gbi->m_cmds, UCode0::F3D_SetOtherMode_L );
94 GBI_SetGBI( GBI::G_ENDDL, F3D_ENDDL, m_gbi->m_cmds, UCode0::F3D_EndDL );
95 GBI_SetGBI( GBI::G_SETGEOMETRYMODE, F3D_SETGEOMETRYMODE, m_gbi->m_cmds, UCode0::F3D_SetGeometryMode );
96 GBI_SetGBI( GBI::G_CLEARGEOMETRYMODE,F3D_CLEARGEOMETRYMODE, m_gbi->m_cmds, UCode0::F3D_ClearGeometryMode );
97 GBI_SetGBI( GBI::G_QUAD, F3D_QUAD, m_gbi->m_cmds, F3DEX_Quad );
98 GBI_SetGBI( GBI::G_RDPHALF_1, F3D_RDPHALF_1, m_gbi->m_cmds, UCode0::F3D_RDPHalf_1 );
99 GBI_SetGBI( GBI::G_RDPHALF_2, F3D_RDPHALF_2, m_gbi->m_cmds, UCode0::F3D_RDPHalf_2 );
100 GBI_SetGBI( GBI::G_MODIFYVTX, F3DEX_MODIFYVTX, m_gbi->m_cmds, F3DEX_ModifyVtx );
101 GBI_SetGBI( GBI::G_TRI2, F3DEX_TRI2, m_gbi->m_cmds, F3DEX_Tri2 );
102 GBI_SetGBI( GBI::G_BRANCH_Z, F3DEX_BRANCH_Z, m_gbi->m_cmds, F3DEX_Branch_Z );
103 GBI_SetGBI( GBI::G_LOAD_UCODE, F3DEX_LOAD_UCODE, m_gbi->m_cmds, F3DEX_Load_uCode );
106 //-----------------------------------------------------------------------------
108 //-----------------------------------------------------------------------------
109 void UCode1::F3DEX_Load_uCode(MicrocodeArgument* ucode)
111 Logger::getSingleton().printMsg("F3DEX_Load_uCode - experimental", M64MSG_WARNING);
112 RSPUCodeLoadUCode* temp = (RSPUCodeLoadUCode*)ucode;
114 //unsigned int ucodeDataStart1 = m_memory->getRDRAMAddress( (*(unsigned int*)( m_memory->getRDRAM(pc-12)) );
115 unsigned int ucodeDataStart2 = m_rdp->getHalf1();
117 //if ( ucodeDataStart1 != ucodeDataStart2 )
119 // Logger::getSingleton().printMsg("Warning - UCode Data Start differs", M64MSG_INFO);
123 m_gbi->selectUCode( temp->ucodeStart, //UCodeStart
124 ucodeDataStart2, //UCodeDataStart
125 temp->ucodeSize+1, //UCodeSize
126 8); //UCodeDataSize //Always 8 ???
129 //-----------------------------------------------------------------------------
131 //! @param ucode instruction from displaylist with input data
132 //-----------------------------------------------------------------------------
133 void UCode1::F3DEX_Vtx(MicrocodeArgument* ucode)
135 Logger::getSingleton().printMsg("F3DEX_Vtx", M64MSG_VERBOSE);
136 RSPUCodeAddVertices1* temp = (RSPUCodeAddVertices1*)ucode;
139 m_rsp->RSP_Vertex(temp->segmentAddress, temp->numVertices, temp->firstVertex);
142 //-----------------------------------------------------------------------------
144 //-----------------------------------------------------------------------------
145 void UCode1::F3DEX_ModifyVtx(MicrocodeArgument* ucode)
147 Logger::getSingleton().printMsg("F3DEX_ModifyVtx", M64MSG_VERBOSE);
148 RSPUCodeModifyVertex* temp = (RSPUCodeModifyVertex*)ucode;
150 switch ( temp->modifyType )
152 case G_MWO_POINT_RGBA:
153 m_rsp->RSP_SetVertexColor( temp->vertexIndex,
160 m_rsp->RSP_SetVertexTexCoord(temp->vertexIndex,
164 case G_MWO_POINT_XYSCREEN:
166 case G_MWO_POINT_ZSCREEN:
171 //-----------------------------------------------------------------------------
173 //! @param ucode instruction from displaylist with input data
174 //-----------------------------------------------------------------------------
175 void UCode1::F3DEX_Tri1(MicrocodeArgument* ucode)
177 Logger::getSingleton().printMsg("F3DEX_Tri1", M64MSG_VERBOSE);
178 RSPUCodeAddOneTriangleF3DEX* temp = (RSPUCodeAddOneTriangleF3DEX*)ucode;
181 m_rsp->RSP_1Triangle(temp->index0, temp->index1, temp->index2);
184 //-----------------------------------------------------------------------------
186 //! @param ucode instruction from displaylist with input data
187 //-----------------------------------------------------------------------------
188 void UCode1::F3DEX_Tri2(MicrocodeArgument* ucode)
190 Logger::getSingleton().printMsg("F3DEX_Tri2", M64MSG_VERBOSE);
191 RSPUCodeAddTwoTrianglesF3DEX* temp = (RSPUCodeAddTwoTrianglesF3DEX*)ucode;
194 m_rsp->RSP_2Triangles( temp->v0, temp->v1, temp->v2, 0,
195 temp->v3, temp->v4, temp->v5, 0);
198 //-----------------------------------------------------------------------------
200 //! @param ucode instruction from displaylist with input data
201 //-----------------------------------------------------------------------------
202 void UCode1::F3DEX_Quad( MicrocodeArgument* ucode )
204 Logger::getSingleton().printMsg("F3DEX_Quad", M64MSG_VERBOSE);
205 RSPUCodeAddOneQuadF3DEX* temp = (RSPUCodeAddOneQuadF3DEX*)ucode;
208 m_rsp->RSP_1Quadrangle(temp->index0, temp->index1, temp->index2, temp->index3);
211 //-----------------------------------------------------------------------------
212 //! Cull Display List
213 //-----------------------------------------------------------------------------
214 void UCode1::F3DEX_CullDL(MicrocodeArgument* ucode)
216 static bool warned = false;
219 Logger::getSingleton().printMsg("F3DEX_CullDL - Unimplemented", M64MSG_WARNING);
222 RSPUCodeCullDisplayList* temp = (RSPUCodeCullDisplayList*)ucode;
225 m_rsp->RSP_CullDisplayList( temp->vertexIndex, temp->numVerticies );
228 //-----------------------------------------------------------------------------
230 //-----------------------------------------------------------------------------
231 void UCode1::F3DEX_Branch_Z(MicrocodeArgument* ucode)
233 Logger::getSingleton().printMsg("F3DEX_Branch_Z", M64MSG_VERBOSE);
234 RSPUCodeBranchZF3DEX* temp = (RSPUCodeBranchZF3DEX*)ucode;
236 //Branch Display List?
237 m_rsp->RSP_BranchLessZ(m_rdp->getHalf1(), temp->vertex, (float)(int)temp->zvalue );