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 "CombinerStructs.h"
31 //-----------------------------------------------------------------------------
33 //! Try two merge to stages into one
35 //-----------------------------------------------------------------------------
36 void mergeStages(Combiner* c)
39 // If all we have is a load in the first stage we can just replace
40 // each occurance of COMBINED in the second stage with it
41 if ((c->stage[0].numOps == 1) && (c->stage[0].op[0].op == LOAD))
43 int combined = c->stage[0].op[0].param1;
45 for (int i = 0; i < c->stage[1].numOps; i++)
47 c->stage[0].op[i].op = c->stage[1].op[i].op;
48 c->stage[0].op[i].param1 = (c->stage[1].op[i].param1 == COMBINED) ? combined : c->stage[1].op[i].param1;
49 c->stage[0].op[i].param2 = (c->stage[1].op[i].param2 == COMBINED) ? combined : c->stage[1].op[i].param2;
50 c->stage[0].op[i].param3 = (c->stage[1].op[i].param3 == COMBINED) ? combined : c->stage[1].op[i].param3;
53 c->stage[0].numOps = c->stage[1].numOps;
56 // We can't do any merging on an interpolation
57 else if (c->stage[1].op[0].op != INTERPOLATE)
61 // See how many times the first stage is used in the second one
62 for (int i = 0; i < c->stage[1].numOps; i++)
63 if (c->stage[1].op[i].param1 == COMBINED)
66 // If it's not used, just replace the first stage with the second
69 for (int i = 0; i < c->stage[1].numOps; i++)
71 c->stage[0].op[i].op = c->stage[1].op[i].op;
72 c->stage[0].op[i].param1 = c->stage[1].op[i].param1;
73 c->stage[0].op[i].param2 = c->stage[1].op[i].param2;
74 c->stage[0].op[i].param3 = c->stage[1].op[i].param3;
76 c->stage[0].numOps = c->stage[1].numOps;
80 // If it's only used once
81 else if (numCombined == 1)
83 // It's only used in the load, so stack on the ops from stage 2 on stage 1
84 if (c->stage[1].op[0].param1 == COMBINED)
86 for (int i = 1; i < c->stage[1].numOps; i++)
88 c->stage[0].op[c->stage[0].numOps].op = c->stage[1].op[i].op;
89 c->stage[0].op[c->stage[0].numOps].param1 = c->stage[1].op[i].param1;
95 // Otherwise, if it's used in the second op, and that op isn't SUB
96 // we can switch the parameters so it works out to tack the ops onto stage 1
97 else if ((c->stage[1].op[1].param1 == COMBINED) && (c->stage[1].op[1].op != SUB))
99 c->stage[0].op[c->stage[0].numOps].op = c->stage[1].op[1].op;
100 c->stage[0].op[c->stage[0].numOps].param1 = c->stage[1].op[0].param1;
101 c->stage[0].numOps++;
103 // If there's another op, tack it onto stage 1 too
104 if (c->stage[1].numOps > 2)
106 c->stage[0].op[c->stage[0].numOps].op = c->stage[1].op[2].op;
107 c->stage[0].op[c->stage[0].numOps].param1 = c->stage[1].op[2].param1;
108 c->stage[0].numOps++;