Arachnoid GLESv1.1 plugin. Compile and run (a bit glitchy and no frameskip) on the...
[mupen64plus-pandora.git] / source / mupen64plus-video-arachnoid / src / ucodes / UCode2.cpp
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 "UCode2.h"
23 #include "UCode0.h"
24 #include "GBI.h"
25 #include "RSP.h"
26 #include "RDP.h"
27 #include "UCodeDefs.h"
28 #include "GBIDefs.h"
29 #include "Logger.h"
30 #include "Memory.h"
31 #include "DisplayListParser.h"
32
33 //-----------------------------------------------------------------------------
34 // Static Variables
35 //-----------------------------------------------------------------------------
36 GBI*               UCode2::m_gbi = 0;   //!< Pointer to Graphics Binary Interface
37 RSP*               UCode2::m_rsp = 0;   //!< Pointer to Reality Signal Processor 
38 RDP*               UCode2::m_rdp = 0;   //!< Pointer to Reality Drawing Processor 
39 Memory*            UCode2::m_memory            = 0;
40 DisplayListParser* UCode2::m_displayListParser = 0;
41
42 //-----------------------------------------------------------------------------
43 //! Constructor
44 //-----------------------------------------------------------------------------
45 UCode2::UCode2()
46 {
47 }
48
49 //-----------------------------------------------------------------------------
50 //! Destructor
51 //-----------------------------------------------------------------------------
52 UCode2::~UCode2()
53 {
54 }
55
56 //-----------------------------------------------------------------------------
57 // Initialize 
58 //-----------------------------------------------------------------------------
59 void UCode2::initialize(GBI* gbi, RSP* rsp, RDP* rdp, Memory* mem, DisplayListParser* dlp)
60 {
61     m_rsp = rsp;
62     m_rdp = rdp;
63     m_gbi = gbi;
64     m_memory = mem;
65     m_displayListParser = dlp;
66 }
67
68 //-----------------------------------------------------------------------------
69 //* Initialize GBI
70 //! Assigns functions to the GBI
71 //-----------------------------------------------------------------------------
72 void UCode2::initializeGBI()
73 {
74     UCode0::initializeGBI(m_gbi);
75     GBI_SetGBI(GBI::G_RDPHALF_1, F3D_RDPHALF_1, m_gbi->m_cmds, renderSky);
76 }
77
78 //-----------------------------------------------------------------------------
79 //* RDP Half 1 With Sky Rendering
80 //! Render Sky
81 //! @todo Set Half 1 also?
82 //! @todo Use extracted color
83 //! @todo set x0 and x1
84 //-----------------------------------------------------------------------------
85 void UCode2::renderSky(MicrocodeArgument* ucode)
86 {    
87     //Check for error
88     if ( (ucode->w1)>>24 != 0xCE )
89     {
90         return;
91     }
92
93     unsigned int w2  = m_displayListParser->getNextWord();
94     m_displayListParser->getNextWord();
95     m_displayListParser->getNextWord();
96     m_displayListParser->getNextWord();
97     m_displayListParser->getNextWord();
98     m_displayListParser->getNextWord();
99     m_displayListParser->getNextWord();
100     m_displayListParser->getNextWord();
101     m_displayListParser->getNextWord();
102     
103     //Extract Vertex Coordinats
104     unsigned int x0 = 0;     //TODO Use VI pos or Viewport pos or Scissor pos ?
105     unsigned int y0 = (unsigned int)int(w2&0xFFFF)/4;
106     unsigned int x1 = 320;   //TODO Use VI Height or Viewport Height or Scissor Height ?
107     unsigned int y1 = (unsigned int)int(w2>>16)/4;
108
109     m_rdp->RDP_TexRect(x0, y0, x1, y1, 0, 0, 0, 1024, 1024);  
110 }