Rice GLES2 (from mupen64plus-ae) plugin. Compile but doesn't works well on the OpenPa...
[mupen64plus-pandora.git] / source / gles2rice / src / RSP_GBI_Sprite2D.h
1 /*
2 Copyright (C) 2002 Rice1964
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
18 */
19
20 // Sprite2D Ucodes
21
22 #include "Render.h"
23
24 Sprite2DInfo g_Sprite2DInfo;
25 uint32 g_SavedUcode=1;
26  
27 void RSP_GBI_Sprite2DBase(Gfx *gfx)
28 {
29     uint32 dwAddr = RSPSegmentAddr((gfx->words.w1));
30     dwAddr &= (g_dwRamSize-1);
31
32     //RSP_RDP_NOIMPL("RDP: Sprite2D (0x%08x 0x%08x)", (gfx->words.w0), (gfx->words.w1));
33
34     g_Sprite2DInfo.spritePtr = (SpriteStruct *)(g_pRDRAMs8+dwAddr);
35
36     DEBUGGER_PAUSE_AND_DUMP_COUNT_N(NEXT_SPRITE_2D, {DebuggerAppendMsg("Pause after Sprite2DBase: Addr=%08X\n", dwAddr);});
37 }
38
39 typedef struct{
40     uint32 SourceImagePointer;
41     uint32 TlutPointer;
42
43     short SubImageWidth;
44     short Stride;
45
46     char  SourceImageBitSize;
47     char  SourceImageType;
48     short SubImageHeight;
49
50     short scaleY;
51     short scaleX;
52
53     short SourceImageOffsetS;
54     char  dummy1[2]; 
55
56     short px;
57     short SourceImageOffsetT;
58
59     char  dummy2[2]; 
60     short py;
61
62 } PuzzleMasterSprite;
63
64 void RSP_GBI_Sprite2D_PuzzleMaster64(Gfx *gfx)
65 {
66     uint32 dwAddr = RSPSegmentAddr((gfx->words.w1));
67     dwAddr &= (g_dwRamSize-1);
68
69     g_Sprite2DInfo.spritePtr = (SpriteStruct *)(g_pRDRAMs8+dwAddr);
70
71     g_Sprite2DInfo.flipX = 0;
72     g_Sprite2DInfo.flipY = 0;
73     g_Sprite2DInfo.px = 0;
74     g_Sprite2DInfo.py = 0;
75
76     SpriteStruct tempInfo;
77     memcpy(&tempInfo, g_Sprite2DInfo.spritePtr, sizeof(SpriteStruct));
78     PuzzleMasterSprite info;
79     memcpy(&info, g_Sprite2DInfo.spritePtr, sizeof(PuzzleMasterSprite));
80
81     g_Sprite2DInfo.px = info.px>>2;
82     g_Sprite2DInfo.py = info.py>>2;
83     g_Sprite2DInfo.scaleX = info.scaleX / 1024.0f;
84     g_Sprite2DInfo.scaleY = info.scaleY / 1024.0f;
85
86     tempInfo.SourceImageOffsetS = info.SourceImageOffsetS;
87     tempInfo.SourceImageOffsetT = info.SourceImageOffsetT;
88     g_Sprite2DInfo.spritePtr = &tempInfo;
89
90     CRender::g_pRender->DrawSprite2D(g_Sprite2DInfo, 1);
91     DEBUGGER_PAUSE_AND_DUMP_COUNT_N(NEXT_SPRITE_2D, {DebuggerAppendMsg("Pause after Sprite2DBase: Addr=%08X\n", dwAddr);});
92 }
93
94
95 void RSP_GBI1_Sprite2DDraw(Gfx *gfx)
96 {
97     // This ucode is shared by PopMtx and gSPSprite2DDraw
98     g_Sprite2DInfo.px = (short)(((gfx->words.w1)>>16)&0xFFFF)/4;
99     g_Sprite2DInfo.py = (short)((gfx->words.w1)&0xFFFF)/4;
100
101     //RSP_RDP_NOIMPL("gSPSprite2DDraw is not implemented", (gfx->words.w0), (gfx->words.w1));
102     CRender::g_pRender->DrawSprite2D(g_Sprite2DInfo, 1);
103     DEBUGGER_PAUSE_AND_DUMP_COUNT_N(NEXT_SPRITE_2D, 
104         {DebuggerAppendMsg("Pause after Sprite2DDraw at (%d, %d)\n", g_Sprite2DInfo.px, g_Sprite2DInfo.py);});
105
106     LoadedUcodeMap[RSP_SPRITE2D_SCALEFLIP] = &RSP_GBI1_CullDL;
107     LoadedUcodeMap[RSP_SPRITE2D_DRAW] = &RSP_GBI1_PopMtx;
108     LoadedUcodeMap[RSP_SPRITE2D_BASE] = &RSP_GBI1_Sprite2DBase;
109
110 }
111
112 void RSP_GBI0_Sprite2DDraw(Gfx *gfx)
113 {
114     // This ucode is shared by PopMtx and gSPSprite2DDraw
115     g_Sprite2DInfo.px = (short)(((gfx->words.w1)>>16)&0xFFFF)/4;
116     g_Sprite2DInfo.py = (short)((gfx->words.w1)&0xFFFF)/4;
117
118     //RSP_RDP_NOIMPL("gSPSprite2DDraw is not implemented", (gfx->words.w0), (gfx->words.w1));
119     CRender::g_pRender->DrawSprite2D(g_Sprite2DInfo, 0);
120     DEBUGGER_PAUSE_AND_DUMP_COUNT_N(NEXT_SPRITE_2D, {TRACE0("Pause after Sprite2DDraw\n");});
121 }
122
123
124 void RSP_GBI1_Sprite2DScaleFlip(Gfx *gfx)
125 {
126     g_Sprite2DInfo.scaleX = (((gfx->words.w1)>>16)&0xFFFF)/1024.0f;
127     g_Sprite2DInfo.scaleY = ((gfx->words.w1)&0xFFFF)/1024.0f;
128
129     if( ((gfx->words.w1)&0xFFFF) < 0x100 )
130     {
131         g_Sprite2DInfo.scaleY = g_Sprite2DInfo.scaleX;
132     }
133
134     g_Sprite2DInfo.flipX = (uint8)(((gfx->words.w0)>>8)&0xFF);
135     g_Sprite2DInfo.flipY = (uint8)((gfx->words.w0)&0xFF);
136     //RSP_RDP_NOIMPL("RSP_SPRITE2D_SCALEFLIP is not implemented", (gfx->words.w0), (gfx->words.w1));
137     DEBUGGER_PAUSE_AND_DUMP_COUNT_N(NEXT_SPRITE_2D, 
138         {DebuggerAppendMsg("Pause after Sprite2DScaleFlip, Flip (%d,%d), Scale (%f, %f)\n", g_Sprite2DInfo.flipX, g_Sprite2DInfo.flipY,
139             g_Sprite2DInfo.scaleX, g_Sprite2DInfo.scaleY);});
140 }
141
142
143 void RSP_GBI1_Sprite2DBase(Gfx *gfx)
144 {
145     if( !status.bUseModifiedUcodeMap )
146     {
147         memcpy( &LoadedUcodeMap, &ucodeMap1, sizeof(UcodeMap));
148         status.bUseModifiedUcodeMap = true;
149     }
150
151     LoadedUcodeMap[RSP_SPRITE2D_BASE] = &RSP_GBI_Sprite2DBase;
152     LoadedUcodeMap[RSP_SPRITE2D_SCALEFLIP] = &RSP_GBI1_Sprite2DScaleFlip;
153     LoadedUcodeMap[RSP_SPRITE2D_DRAW] = &RSP_GBI1_Sprite2DDraw;
154
155     TRACE0("Adding Sprite2D ucodes to ucode 1");
156     RSP_GBI_Sprite2DBase(gfx);
157 }
158
159
160 void RSP_GBI0_Sprite2DBase(Gfx *gfx)
161 {
162     //Weired, this ucode 0 game is using ucode 1, but sprite2D cmd is working differently from
163     //normal ucode1 sprite2D game
164
165     TRACE0("Ucode 0 game is using Sprite2D, and using ucode 1 codes, create a new ucode for me");
166
167     RSP_GBI_Sprite2DBase(gfx);
168 }
169