| 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 | #ifndef REALITY_SIGNAL_PROCESSOR_H_ |
| 23 | #define REALITY_SIGNAL_PROCESSOR_H_ |
| 24 | |
| 25 | #define M64P_PLUGIN_PROTOTYPES 1 |
| 26 | #include "m64p_plugin.h" |
| 27 | #include "UCodeDefs.h" |
| 28 | #include "RSPMatrixManager.h" |
| 29 | #include "RSPVertexManager.h" |
| 30 | #include "Matrix4.h" |
| 31 | |
| 32 | //Forward declarations |
| 33 | class VI; |
| 34 | struct RDPTile; |
| 35 | class RDP; |
| 36 | class Memory; |
| 37 | class DisplayListParser; |
| 38 | class RSPLightManager; |
| 39 | class FogManager; |
| 40 | |
| 41 | //----------------------------------------------------------------------------- |
| 42 | // Defines |
| 43 | //----------------------------------------------------------------------------- |
| 44 | |
| 45 | #define RSP_1ST 0xBF |
| 46 | #define RSP_TRI1 (RSP_1ST-0) |
| 47 | #define RSP_CULLDL (RSP_1ST-1) |
| 48 | #define RSP_POPMTX (RSP_1ST-2) |
| 49 | #define RSP_MOVEWORD (RSP_1ST-3) |
| 50 | #define RSP_TEXTURE (RSP_1ST-4) |
| 51 | #define RSP_SETOTHERMODE_H (RSP_1ST-5) |
| 52 | #define RSP_SETOTHERMODE_L (RSP_1ST-6) |
| 53 | #define RSP_ENDDL (RSP_1ST-7) |
| 54 | #define RSP_SETGEOMETRYMODE (RSP_1ST-8) |
| 55 | #define RSP_CLEARGEOMETRYMODE (RSP_1ST-9) |
| 56 | #define RSP_LINE3D (RSP_1ST-10) |
| 57 | #define RSP_RDPHALF_1 (RSP_1ST-11) |
| 58 | #define RSP_RDPHALF_2 (RSP_1ST-12) |
| 59 | #define RSP_RDPHALF_CONT (RSP_1ST-13) |
| 60 | |
| 61 | #define RSP_MODIFYVTX (RSP_1ST-13) |
| 62 | #define RSP_TRI2 (RSP_1ST-14) |
| 63 | #define RSP_BRANCH_Z (RSP_1ST-15) |
| 64 | #define RSP_LOAD_UCODE (RSP_1ST-16) |
| 65 | |
| 66 | #define RSP_SPRITE2D_SCALEFLIP (RSP_1ST-1) |
| 67 | #define RSP_SPRITE2D_DRAW (RSP_1ST-2) |
| 68 | |
| 69 | // flags to inhibit pushing of the display list (on branch) |
| 70 | #define RSP_DLIST_PUSH 0x00 |
| 71 | #define RSP_DLIST_NOPUSH 0x01 |
| 72 | |
| 73 | //----------------------------------------------------------------------------- |
| 74 | //! Viewport |
| 75 | //----------------------------------------------------------------------------- |
| 76 | struct Viewport |
| 77 | { |
| 78 | float vscale[4]; |
| 79 | float vtrans[4]; |
| 80 | float x, y, width, height; |
| 81 | float nearz, farz; |
| 82 | }; |
| 83 | |
| 84 | |
| 85 | //----------------------------------------------------------------------------- |
| 86 | //! Struct used to store Information about Background Image |
| 87 | //----------------------------------------------------------------------------- |
| 88 | struct BGImageInfo |
| 89 | { |
| 90 | unsigned int address; //!< Where texture is stored (in RDRAM) |
| 91 | unsigned int width; //!< Width of texture |
| 92 | unsigned int height; //!< Height of texture |
| 93 | unsigned int format; //!< Format of texture |
| 94 | unsigned int size; //!< Size of texture |
| 95 | unsigned int palette; //!< What Texture Lookup Table to use |
| 96 | }; |
| 97 | |
| 98 | //----------------------------------------------------------------------------- |
| 99 | //* RSPTexture |
| 100 | //! Struct used to store information about current texture on rsp |
| 101 | //----------------------------------------------------------------------------- |
| 102 | struct RSPTexture |
| 103 | { |
| 104 | float scaleS, scaleT; |
| 105 | int level, on, tile; |
| 106 | }; |
| 107 | |
| 108 | //----------------------------------------------------------------------------- |
| 109 | //! Singnal Processor Triangle |
| 110 | //----------------------------------------------------------------------------- |
| 111 | typedef SPVertex SPTriangle[3]; |
| 112 | |
| 113 | //***************************************************************************** |
| 114 | //* RSP |
| 115 | //! Class for emulating the Reality Signal Processor |
| 116 | //***************************************************************************** |
| 117 | class RSP |
| 118 | { |
| 119 | public: |
| 120 | //Constructor |
| 121 | RSP(); |
| 122 | //Destructor |
| 123 | ~RSP(); |
| 124 | |
| 125 | //Initialize |
| 126 | bool initialize(GFX_INFO* graphicsInfo, RDP* rdp, Memory* memory, VI* vi, DisplayListParser* displayListParser, FogManager* fogMgr); |
| 127 | void dispose(); |
| 128 | void reset(); |
| 129 | |
| 130 | void updateGeometryStates(); |
| 131 | |
| 132 | //Trigger Interrupt |
| 133 | void triggerInterrupt(); |
| 134 | |
| 135 | void moveSegment(int segmentID, int value); |
| 136 | |
| 137 | void moveMemViewport(unsigned int segmentAddress); |
| 138 | |
| 139 | RDPTile* getTile(int tile) { return m_textureTiles[tile]; } |
| 140 | void setTile(RDPTile* tile, int index) { m_textureTiles[index] = tile; } |
| 141 | RSPTexture& getTexture() { return m_texture; } |
| 142 | bool getTexturesChanged() { return m_texturesChanged; } |
| 143 | void setTexturesChanged(bool changed) { m_texturesChanged = changed; } |
| 144 | |
| 145 | RSPMatrixManager* getMatrixMgr() { return m_matrixMgr; } |
| 146 | RSPVertexManager* getVertexMgr() { return m_vertexMgr; } |
| 147 | |
| 148 | public: |
| 149 | |
| 150 | //Matrix |
| 151 | void RSP_Matrix( unsigned int segmentAddress, bool projectionMatrix, bool push, bool replace ); |
| 152 | void RSP_PopMatrix(); |
| 153 | void RSP_PopMatrixN(unsigned int num); |
| 154 | void RSP_InsertMatrix(unsigned int where, unsigned int num); |
| 155 | void RSP_DMAMatrix( unsigned int matrix, unsigned char index, unsigned char multiply ); |
| 156 | void RSP_ForceMatrix( unsigned int segmentAddress ); |
| 157 | void RSP_LookAt( unsigned int l ); |
| 158 | void RSP_PerspNormalize( unsigned short scale ); |
| 159 | |
| 160 | //Display List |
| 161 | void RSP_DisplayList(unsigned int segmentAddress); |
| 162 | void RSP_DMADisplayList( unsigned int w0, unsigned int w1 ); |
| 163 | void RSP_CullDisplayList( unsigned int v0, unsigned int vn ); |
| 164 | void RSP_BranchList( unsigned int dl ); |
| 165 | void RSP_BranchLessZ( unsigned int branchdl, unsigned int vtx, float zval ); |
| 166 | void RSP_EndDisplayList(); |
| 167 | |
| 168 | //Light |
| 169 | void RSP_Light( unsigned int lightIndex, unsigned int segmentAddress ); |
| 170 | void RSP_NumLights( int n ); |
| 171 | void RSP_LightColor( unsigned int lightIndex, unsigned int packedColor ); |
| 172 | |
| 173 | //Vertices |
| 174 | void RSP_Vertex(unsigned int segmentAddress, unsigned int numVertices, unsigned int firstVertexIndex); |
| 175 | void RSP_CIVertex(unsigned int segmentAddress, unsigned int numVertices, unsigned int firstVertexIndex); |
| 176 | void RSP_ModifyVertex( unsigned int vtx, unsigned int where, unsigned int val ); |
| 177 | void RSP_SetVertexColor( unsigned int vtx, float r, float g, float b, float a); |
| 178 | void RSP_SetVertexTexCoord( unsigned int vtx, float s, float t); |
| 179 | |
| 180 | void RSP_DMAVertex( unsigned int v, unsigned int n, unsigned int v0 ); |
| 181 | void RSP_SetDMAOffsets( unsigned int mtxoffset, unsigned int vtxoffset ); |
| 182 | void RSP_SetVertexColorBase(unsigned int segmentAddress); |
| 183 | |
| 184 | //Indices |
| 185 | void RSP_1Triangle( int v00, int v01, int v02 ); |
| 186 | void RSP_2Triangles( int v00, int v01, int v02, int flag0, |
| 187 | int v10, int v11, int v12, int flag1 ); |
| 188 | void RSP_4Triangles( int v00, int v01, int v02, |
| 189 | int v10, int v11, int v12, |
| 190 | int v20, int v21, int v22, |
| 191 | int v30, int v31, int v32 ); |
| 192 | void RSP_DMATriangles( unsigned int tris, unsigned int n ); |
| 193 | void RSP_1Quadrangle( int v0, int v1, int v2, int v4 ); |
| 194 | |
| 195 | //Object |
| 196 | void RSP_ObjRectangle( unsigned int sp ); |
| 197 | void RSP_ObjSprite( unsigned int sp ); |
| 198 | void RSP_ObjLoadTxtr( unsigned int tx ); |
| 199 | void RSP_ObjLoadTxSprite( unsigned int txsp ); |
| 200 | void RSP_ObjLoadTxRectR( unsigned int txsp ); |
| 201 | void RSP_ObjMatrix( unsigned int mtx ); |
| 202 | void RSP_ObjSubMatrix( unsigned int mtx ); |
| 203 | |
| 204 | //Rendering |
| 205 | void RSP_Line3D( int v0, int v1, int flag ); |
| 206 | void RSP_LineW3D( int v0, int v1, int wd, int flag ); |
| 207 | void RSP_BgRect1Cyc( unsigned int bg ); |
| 208 | void RSP_BgRectCopy( unsigned int bg ); |
| 209 | void RSP_Sprite2DBase( unsigned int base ); |
| 210 | |
| 211 | //States |
| 212 | void RSP_GeometryMode( unsigned int clear, unsigned int set ); |
| 213 | void RSP_SetGeometryMode( unsigned int mode ); |
| 214 | void RSP_ClearGeometryMode( unsigned int mode ); |
| 215 | |
| 216 | //Clipping |
| 217 | void RSP_ClipRatio( unsigned int r ); |
| 218 | |
| 219 | //Texturing |
| 220 | void RSP_Texture( float sc, float tc, int level, int tile, int on ); |
| 221 | |
| 222 | //Fog |
| 223 | void RSP_FogFactor( short fm, short fo ); |
| 224 | |
| 225 | //UCode |
| 226 | void RSP_LoadUcodeEx( unsigned int uc_start, unsigned int uc_dstart, unsigned short uc_dsize ); |
| 227 | |
| 228 | private: |
| 229 | |
| 230 | //Pointers to big objects and managers |
| 231 | GFX_INFO* m_graphicsInfo; //!< Access to emulator data (like RDRAM ...) |
| 232 | VI* m_vi; //!< Videointerface |
| 233 | Memory* m_memory; //!< Memory managers (handles RDRAM, Texture Memory...) |
| 234 | DisplayListParser* m_displayListParser; //!< Display list parser |
| 235 | FogManager* m_fogMgr; //!< Manager that handles fog |
| 236 | RDP* m_rdp; //!< Pointer to Reality Drawing Processor |
| 237 | |
| 238 | //Helper managers |
| 239 | RSPMatrixManager* m_matrixMgr; //!< Handles matrix stack |
| 240 | RSPVertexManager* m_vertexMgr; //!< Vertex Manager, processes and modifies vertices |
| 241 | RSPLightManager* m_lightMgr; //!< Light Manager, handles lights |
| 242 | |
| 243 | //Geometry Mode |
| 244 | unsigned int m_geometryMode; //!< Contains states (lighting, shading, culling...) |
| 245 | |
| 246 | //Textures |
| 247 | RSPTexture m_texture; |
| 248 | RDPTile* m_textureTiles[2]; |
| 249 | bool m_texturesChanged; |
| 250 | |
| 251 | //Viewport |
| 252 | Viewport m_viewport; |
| 253 | |
| 254 | }; |
| 255 | |
| 256 | #endif |