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 *****************************************************************************/
22 #include "RDPInstructions.h"
23 #include "RDPUCodeStructs.h"
25 #include "DisplayListParser.h"
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
32 RDP* RDPInstructions::m_rdp = 0;
33 DisplayListParser* RDPInstructions::m_displayListParser = 0;
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
38 RDPInstructions::RDPInstructions()
42 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
45 RDPInstructions::~RDPInstructions()
49 //-----------------------------------------------------------------------------
51 //-----------------------------------------------------------------------------
52 bool RDPInstructions::initialize(RDP* rdp, DisplayListParser* displayListParser)
55 m_displayListParser = displayListParser;
59 //-----------------------------------------------------------------------------
61 //! @param ucode instruction from displaylist with input data
62 //-----------------------------------------------------------------------------
63 void RDPInstructions::RDP_SetCImg(MicrocodeArgument* ucode)
65 Logger::getSingleton().printMsg("RDP_SetCImg");
66 RDPUCodeSetImage* temp = (RDPUCodeSetImage*)ucode;
69 m_rdp->RDP_SetCImg(temp->format, temp->size, temp->width, temp->segmentAddress);
72 //-----------------------------------------------------------------------------
74 //! @param ucode instruction from displaylist with input data
75 //-----------------------------------------------------------------------------
76 void RDPInstructions::RDP_SetZImg(MicrocodeArgument* ucode)
78 Logger::getSingleton().printMsg("RDP_SetZImg");
79 RDPUCodeSetImage* temp = (RDPUCodeSetImage*)ucode;
82 m_rdp->RDP_SetZImg(temp->format, temp->size, temp->width, temp->segmentAddress);
85 //-----------------------------------------------------------------------------
87 //! @param ucode instruction from displaylist with input data
88 //-----------------------------------------------------------------------------
89 void RDPInstructions::RDP_SetTImg(MicrocodeArgument* ucode)
91 Logger::getSingleton().printMsg("RDP_SetTImg");
92 RDPUCodeSetImage* temp = (RDPUCodeSetImage*)ucode;
95 m_rdp->RDP_SetTImg(temp->format, temp->size, temp->width, temp->segmentAddress);
98 //-----------------------------------------------------------------------------
100 //! @param ucode instruction from displaylist with input data
101 //-----------------------------------------------------------------------------
102 void RDPInstructions::RDP_SetTile(MicrocodeArgument* ucode)
104 Logger::getSingleton().printMsg("RDP_SetTile");
105 RDPUCodeSetTile* temp = (RDPUCodeSetTile*)ucode;
108 m_rdp->RDP_SetTile( temp->format, temp->size, temp->line, temp->tmem, temp->tile,
109 temp->palette, temp->clampS, temp->clampT, temp->mirrorS, temp->mirrorT,
110 temp->maskS, temp->maskT, temp->shiftS, temp->shiftT
114 //-----------------------------------------------------------------------------
116 //! @param ucode instruction from displaylist with input data
117 //-----------------------------------------------------------------------------
118 void RDPInstructions::RDP_LoadTile(MicrocodeArgument* ucode)
120 Logger::getSingleton().printMsg("RDP_LoadTile");
121 RDPUCodeTileSize* temp = (RDPUCodeTileSize*)ucode;
124 m_rdp->RDP_LoadTile(temp->tile, temp->s0, temp->t0, temp->s1, temp->t1);
127 //-----------------------------------------------------------------------------
129 //! @param ucode instruction from displaylist with input data
130 //-----------------------------------------------------------------------------
131 void RDPInstructions::RDP_LoadBlock(MicrocodeArgument* ucode)
133 Logger::getSingleton().printMsg("RDP_LoadBlock");
134 RDPUCodeTileSize* temp = (RDPUCodeTileSize*)ucode;
137 m_rdp->RDP_LoadBlock(temp->tile, temp->s0, temp->t0, temp->s1, temp->t1);
140 //-----------------------------------------------------------------------------
141 //! Sets the size of tile
142 //! @param ucode instruction from displaylist with input data
143 //-----------------------------------------------------------------------------
144 void RDPInstructions::RDP_SetTileSize(MicrocodeArgument* ucode)
146 Logger::getSingleton().printMsg("RDP_SetTileSize");
147 RDPUCodeTileSize* temp = (RDPUCodeTileSize*)ucode;
150 m_rdp->RDP_SetTileSize(temp->tile, temp->s0, temp->t0, temp->s1, temp->t1);
153 //-----------------------------------------------------------------------------
154 //! Set Texture Look Up Table
155 //! @param ucode instruction from displaylist with input data
156 //-----------------------------------------------------------------------------
157 void RDPInstructions::RDP_LoadTLUT(MicrocodeArgument* ucode)
159 Logger::getSingleton().printMsg("RDP_LoadTLUT");
160 RDPUCodeTileSize* temp = (RDPUCodeTileSize*)ucode;
162 //Load Texture Look Up Table
163 m_rdp->RDP_LoadTLUT(temp->tile, temp->s0, temp->t0, temp->s1, temp->t1);
166 //-----------------------------------------------------------------------------
168 //! Renders a rectangle
169 //! @param ucode instruction from displaylist with input data
170 //-----------------------------------------------------------------------------
171 void RDPInstructions::RDP_FillRect(MicrocodeArgument* ucode)
173 Logger::getSingleton().printMsg("RDP_FillRect");
174 RDPUCodeRectangle* temp = (RDPUCodeRectangle*)ucode;
177 m_rdp->RDP_FillRect(temp->x0, temp->y0, temp->x1, temp->y1);
180 //-----------------------------------------------------------------------------
181 //* Texture Rectangle Flipped
182 //! Renders a textured rectangle
183 //! @todo Better extraction of data
184 //! @param ucode instruction from displaylist with input data
185 //-----------------------------------------------------------------------------
186 void RDPInstructions::RDP_TexRectFlip(MicrocodeArgument* ucode)
188 Logger::getSingleton().printMsg("RDP_TexRectFlip");
189 RDPUCodeTextureRectangle* temp = (RDPUCodeTextureRectangle*)ucode;
192 unsigned int w2 = m_displayListParser->getNextWord();
193 unsigned int w3 = m_displayListParser->getNextWord();
196 unsigned int dwS = ( w2>>16)&0xFFFF;
197 unsigned int dwT = ( w2 )&0xFFFF;
198 int nDSDX = (int)(short)(( w3>>16)&0xFFFF);
199 int nDTDY = (int)(short)(( w3 )&0xFFFF);
201 //Render Texture Rectangle Flipped
202 m_rdp->RDP_TexRectFlip(temp->x1 / 4, temp->y1 / 4,
203 temp->x0 / 4, temp->y0 / 4,
209 //-----------------------------------------------------------------------------
211 //! Not this command use 128bits and not 64 bits wich could cause some
212 //! problems with the program counter.
213 //! @todo Better extraction of data
214 //! @param ucode instruction from displaylist with input data
215 //-----------------------------------------------------------------------------
216 void RDPInstructions::RDP_TexRect(MicrocodeArgument* ucode)
218 Logger::getSingleton().printMsg("RDP_TexRect");
219 RDPUCodeTextureRectangle* temp = (RDPUCodeTextureRectangle*)ucode;
221 unsigned int w2 = m_displayListParser->getNextWord();
222 unsigned int w3 = m_displayListParser->getNextWord();
225 unsigned short uS = (unsigned short)( w2>>16)&0xFFFF;
226 unsigned short uT = (unsigned short)( w2 )&0xFFFF;
227 unsigned short uDSDX = (unsigned short)(( w3>>16)&0xFFFF);
228 unsigned short uDTDY = (unsigned short)(( w3 )&0xFFFF);
230 //Render Texture Rectangle
231 m_rdp->RDP_TexRect( temp->x0 / 4, temp->y0 / 4,
232 temp->x1 / 4, temp->y1 / 4,
238 //-----------------------------------------------------------------------------
239 //! Set Enviroment Color
240 //! @param ucode instruction from displaylist with input data
241 //-----------------------------------------------------------------------------
242 void RDPInstructions::RDP_SetEnvColor(MicrocodeArgument* ucode)
244 Logger::getSingleton().printMsg("RDP_SetEnvColor");
245 RDPUCodeSetColor* temp = (RDPUCodeSetColor*)ucode;
247 //Set enviorment color
248 m_rdp->RDP_SetEnvColor(temp->r / 255.0f, temp->g / 255.0f, temp->b / 255.0f, temp->a / 255.0f);
251 //-----------------------------------------------------------------------------
253 //! @param ucode instruction from displaylist with input data
254 //-----------------------------------------------------------------------------
255 void RDPInstructions::RDP_SetBlendColor(MicrocodeArgument* ucode)
257 Logger::getSingleton().printMsg("RDP_SetBlendColor");
258 RDPUCodeSetColor* temp = (RDPUCodeSetColor*)ucode;
261 m_rdp->RDP_SetBlendColor(temp->r / 255.0f, temp->g / 255.0f, temp->b / 255.0f, temp->a / 255.0f);
264 //-----------------------------------------------------------------------------
266 //! @param ucode instruction from displaylist with input data
267 //-----------------------------------------------------------------------------
268 void RDPInstructions::RDP_SetPrimColor(MicrocodeArgument* ucode)
270 Logger::getSingleton().printMsg("RDP_SetPrimColor");
271 RDPUCodeSetColor* temp = (RDPUCodeSetColor*)ucode;
273 //Set primitive color
274 m_rdp->RDP_SetPrimColor( temp->r / 255.0f, //red
275 temp->g / 255.0f, //green
276 temp->b / 255.0f, //blue
277 temp->a / 255.0f, //alpha
278 temp->prim_min_level,
282 //-----------------------------------------------------------------------------
284 //! @param ucode instruction from displaylist with input data
285 //-----------------------------------------------------------------------------
286 void RDPInstructions::RDP_SetFogColor(MicrocodeArgument* ucode)
288 Logger::getSingleton().printMsg("RDPInstructions_SetFogColor");
289 RDPUCodeSetColor* temp = (RDPUCodeSetColor*)ucode;
292 m_rdp->RDP_SetFogColor(temp->r / 255.0f, temp->g / 255.0f, temp->b / 255.0f, temp->a / 255.0f);
295 //-----------------------------------------------------------------------------
297 //! Note: Fill color is stored diffrently from the other types of colors
298 //! @param ucode instruction from displaylist with input data
299 //-----------------------------------------------------------------------------
300 void RDPInstructions::RDP_SetFillColor(MicrocodeArgument* ucode)
302 Logger::getSingleton().printMsg("RDP_SetFillColor");
303 RDPUCodeSetFillColor* temp = (RDPUCodeSetFillColor*)ucode;
305 //Set fill color (Note: alpha is 0.0 or 1.0) FIXME: 32 or 31? 31 seems to work better with Super Mario 64
306 m_rdp->RDP_SetFillColor(temp->r / 31.0f, temp->g / 31.0f, temp->b / 31.0f, (float)temp->a);
309 //-----------------------------------------------------------------------------
311 //! @todo Extract data
312 //! @param ucode instruction from displaylist with input data
313 //-----------------------------------------------------------------------------
314 void RDPInstructions::RDP_SetCombine(MicrocodeArgument* ucode)
316 Logger::getSingleton().printMsg("RDP_SetCombine");
317 m_rdp->RDP_SetCombine(ucode);
320 //-----------------------------------------------------------------------------
322 //! @todo Extract data
323 //! @param ucode instruction from displaylist with input data
324 //-----------------------------------------------------------------------------
325 void RDPInstructions::RDP_SetOtherMode(MicrocodeArgument* ucode)
327 Logger::getSingleton().printMsg("RDP_SetOtherMode");
328 m_rdp->RDP_SetOtherMode(ucode);
331 //-----------------------------------------------------------------------------
333 //! @param ucode instruction from displaylist with input data
334 //-----------------------------------------------------------------------------
335 void RDPInstructions::RDP_SetPrimDepth(MicrocodeArgument* ucode)
337 Logger::getSingleton().printMsg("RDP_SetPrimDepth");
338 RDPUCodeSetPrimDepth* temp = (RDPUCodeSetPrimDepth*)ucode;
341 m_rdp->RDP_SetPrimDepth(temp->z, temp->dz);
344 //-----------------------------------------------------------------------------
346 //! @param ucode instruction from displaylist with input data
347 //-----------------------------------------------------------------------------
348 void RDPInstructions::RDP_SetScissor(MicrocodeArgument* ucode)
350 Logger::getSingleton().printMsg("RDP_SetScissor");
351 RDPUCodeScissor* temp = (RDPUCodeScissor*)ucode;
354 m_rdp->RDP_SetScissor(temp->x0 / 4, temp->y0 / 4, temp->x1 / 4, temp->y1 / 4, temp->mode);
357 //-----------------------------------------------------------------------------
359 //! Function that signals end of a frame.
360 //-----------------------------------------------------------------------------
361 void RDPInstructions::RDP_FullSync(MicrocodeArgument* ucode)
363 Logger::getSingleton().printMsg("RDP_FullSync");
364 m_rdp->RDP_FullSync();
367 //-----------------------------------------------------------------------------
369 //! Ignored (Function that signals synchronize of texture tile change)
370 //-----------------------------------------------------------------------------
371 void RDPInstructions::RDP_TileSync(MicrocodeArgument* ucode)
375 static bool warned = false;
377 Logger::getSingleton().printMsg("RDP_TileSync - Ignored", M64MSG_WARNING);
382 //-----------------------------------------------------------------------------
384 //! Ignored (Function that signals synchronize of RDP attribute change)
385 //-----------------------------------------------------------------------------
386 void RDPInstructions::RDP_PipeSync(MicrocodeArgument* ucode)
390 static bool warned = false;
392 Logger::getSingleton().printMsg("RDP_PipeSync - Ignored", M64MSG_WARNING);
397 //-----------------------------------------------------------------------------
399 //! Ignored (Function that signals synchronize of textureloading Ignored)
400 //-----------------------------------------------------------------------------
401 void RDPInstructions::RDP_LoadSync(MicrocodeArgument* ucode)
405 static bool warned = false;
407 Logger::getSingleton().printMsg("RDP_LoadSync - Ignored", M64MSG_WARNING);
412 //-----------------------------------------------------------------------------
415 //-----------------------------------------------------------------------------
416 void RDPInstructions::RDP_SetConvert(MicrocodeArgument* ucode)
418 static bool warned = false;
420 Logger::getSingleton().printMsg("RDP_SetConvert - Unimplemented", M64MSG_WARNING);
425 //-----------------------------------------------------------------------------
428 //-----------------------------------------------------------------------------
429 void RDPInstructions::RDP_SetKeyR(MicrocodeArgument* ucode)
431 Logger::getSingleton().printMsg("RDP_SetKeyR");
433 static bool warned = false;
435 Logger::getSingleton().printMsg("RDP_SetKeyR - Unimplemented", M64MSG_WARNING);
440 //-----------------------------------------------------------------------------
441 //* Set Key Green Blue
443 //-----------------------------------------------------------------------------
444 void RDPInstructions::RDP_SetKeyGB(MicrocodeArgument* ucode)
446 static bool warned = false;
448 Logger::getSingleton().printMsg("RDP_SetKeyGB - Unimplemented", M64MSG_WARNING);
453 //-----------------------------------------------------------------------------
455 //! This function gets called when the GBI recives an unknown instruction.
456 //-----------------------------------------------------------------------------
457 void RDPInstructions::RDP_Unknown(MicrocodeArgument* ucode)
461 static bool warned = false;
463 Logger::getSingleton().printMsg("RDP_Unknown - Ignored", M64MSG_WARNING);
468 //-----------------------------------------------------------------------------
471 //-----------------------------------------------------------------------------
472 void RDPInstructions::RDP_NoOp(MicrocodeArgument* ucode)
476 static bool warned = false;
478 Logger::getSingleton().printMsg("RDP_NoOp - Ignored", M64MSG_WARNING);