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 //*****************************************************************************
24 // NOTE THAT THIS FILE IS BASED ON MATERIAL FROM glN64.
25 // http://gln64.emulation64.com/
27 //*****************************************************************************
29 #include "CombinerStageCreator.h"
31 //-----------------------------------------------------------------------------
33 //! Function used to set combiner stage, tries to simplify and optimize as
36 //! @param[in] combineCycle Values to be added/subracted/multiplied and interpolated.
37 //! @param[out] stageOut Simplified combine cycle with combiner formula.
38 //-----------------------------------------------------------------------------
39 void setStage(CombineCycle* combineCycle, CombinerStage* stageOut)
41 // Load the first operand
42 stageOut->op[0].op = LOAD;
43 stageOut->op[0].param1 = combineCycle->loadValue;
46 // If we're just subtracting zero, skip it
47 if (combineCycle->subValue != ZERO)
49 if (combineCycle->subValue == stageOut->op[0].param1)
50 stageOut->op[0].param1 = ZERO;
54 stageOut->op[1].op = SUB;
55 stageOut->op[1].param1 = combineCycle->subValue;
61 if ((stageOut->numOps > 1) || (stageOut->op[0].param1 != ZERO))
63 if (combineCycle->multValue == ZERO)
66 stageOut->op[0].op = LOAD;
67 stageOut->op[0].param1 = ZERO;
71 if ( stageOut->numOps == 1 && stageOut->op[0].param1 == ONE )
74 stageOut->op[0].param1 = combineCycle->multValue;
79 stageOut->op[stageOut->numOps].op = MUL;
80 stageOut->op[stageOut->numOps].param1 = combineCycle->multValue;
86 //Don't bother adding zero
87 if (combineCycle->addValue != ZERO)
89 // If all we have so far is zero, then load this instead
90 if ((stageOut->numOps == 1) && (stageOut->op[0].param1 == ZERO))
92 stageOut->op[0].param1 = combineCycle->addValue;
96 stageOut->op[stageOut->numOps].op = ADD;
97 stageOut->op[stageOut->numOps].param1 = combineCycle->addValue;
102 // Handle interpolation
103 if ((stageOut->numOps == 4) && (stageOut->op[1].param1 == stageOut->op[3].param1))
105 stageOut->numOps = 1;
106 stageOut->op[0].op = INTERPOLATE;
107 stageOut->op[0].param2 = stageOut->op[1].param1;
108 stageOut->op[0].param3 = stageOut->op[2].param1;