1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - GX -
3   File:     gx_vramcnt.c
4 
5   Copyright 2003-2008 Nintendo. All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law. They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Date:: 2008-09-17#$
14   $Rev: 8556 $
15   $Author: okubata_ryoma $
16  *---------------------------------------------------------------------------*/
17 
18 #include <nitro/gx/gx_vramcnt.h>
19 #ifdef SDK_NITRO
20 #include <nitro/hw/ARM9/ioreg_G3X.h>
21 #include <nitro/hw/ARM9/ioreg_GX.h>
22 #include <nitro/hw/ARM9/ioreg_GXS.h>
23 #include <nitro/hw/ARM9/mmap_vram.h>
24 #else
25 #include <twl/hw/ARM9/ioreg_G3X.h>
26 #include <twl/hw/ARM9/ioreg_GX.h>
27 #include <twl/hw/ARM9/ioreg_GXS.h>
28 #include <twl/hw/ARM9/mmap_vram.h>
29 #endif
30 #include "gxstate.h"
31 
32 
33 //---------------------------------------------------------------------------
34 // Enum values for VRAMCNT-A (internal use only)
35 //---------------------------------------------------------------------------
36 typedef enum
37 {
38     GX_VRAMCNT_A_DISABLE = 0,
39     GX_VRAMCNT_A_LCDC_0x06800000 =
40         (0 << REG_GX_VRAMCNT_A_MST_SHIFT) | (0 << REG_GX_VRAMCNT_A_OFS_SHIFT) | (1 <<
41                                                                                  REG_GX_VRAMCNT_A_E_SHIFT),
42     GX_VRAMCNT_A_BG_0x06000000 =
43         (1 << REG_GX_VRAMCNT_A_MST_SHIFT) | (0 << REG_GX_VRAMCNT_A_OFS_SHIFT) | (1 <<
44                                                                                  REG_GX_VRAMCNT_A_E_SHIFT),
45     GX_VRAMCNT_A_BG_0x06020000 =
46         (1 << REG_GX_VRAMCNT_A_MST_SHIFT) | (1 << REG_GX_VRAMCNT_A_OFS_SHIFT) | (1 <<
47                                                                                  REG_GX_VRAMCNT_A_E_SHIFT),
48     GX_VRAMCNT_A_BG_0x06040000 =
49         (1 << REG_GX_VRAMCNT_A_MST_SHIFT) | (2 << REG_GX_VRAMCNT_A_OFS_SHIFT) | (1 <<
50                                                                                  REG_GX_VRAMCNT_A_E_SHIFT),
51     GX_VRAMCNT_A_BG_0x06060000 =
52         (1 << REG_GX_VRAMCNT_A_MST_SHIFT) | (3 << REG_GX_VRAMCNT_A_OFS_SHIFT) | (1 <<
53                                                                                  REG_GX_VRAMCNT_A_E_SHIFT),
54     GX_VRAMCNT_A_OBJ_0x06400000 =
55         (2 << REG_GX_VRAMCNT_A_MST_SHIFT) | (0 << REG_GX_VRAMCNT_A_OFS_SHIFT) | (1 <<
56                                                                                  REG_GX_VRAMCNT_A_E_SHIFT),
57     GX_VRAMCNT_A_OBJ_0x06420000 =
58         (2 << REG_GX_VRAMCNT_A_MST_SHIFT) | (1 << REG_GX_VRAMCNT_A_OFS_SHIFT) | (1 <<
59                                                                                  REG_GX_VRAMCNT_A_E_SHIFT),
60     GX_VRAMCNT_A_TEX_0 =
61         (3 << REG_GX_VRAMCNT_A_MST_SHIFT) | (0 << REG_GX_VRAMCNT_A_OFS_SHIFT) | (1 <<
62                                                                                  REG_GX_VRAMCNT_A_E_SHIFT),
63     GX_VRAMCNT_A_TEX_1 =
64         (3 << REG_GX_VRAMCNT_A_MST_SHIFT) | (1 << REG_GX_VRAMCNT_A_OFS_SHIFT) | (1 <<
65                                                                                  REG_GX_VRAMCNT_A_E_SHIFT),
66     GX_VRAMCNT_A_TEX_2 =
67         (3 << REG_GX_VRAMCNT_A_MST_SHIFT) | (2 << REG_GX_VRAMCNT_A_OFS_SHIFT) | (1 <<
68                                                                                  REG_GX_VRAMCNT_A_E_SHIFT),
69     GX_VRAMCNT_A_TEX_3 =
70         (3 << REG_GX_VRAMCNT_A_MST_SHIFT) | (3 << REG_GX_VRAMCNT_A_OFS_SHIFT) | (1 <<
71                                                                                  REG_GX_VRAMCNT_A_E_SHIFT)
72 }
73 GX_VRAMCNT_A;
74 
75 
76 //---------------------------------------------------------------------------
77 // Enum values for VRAMCNT-B (internal use only)
78 //---------------------------------------------------------------------------
79 typedef enum
80 {
81     GX_VRAMCNT_B_DISABLE = 0,
82     GX_VRAMCNT_B_LCDC_0x06820000 =
83         (0 << REG_GX_VRAMCNT_B_MST_SHIFT) | (0 << REG_GX_VRAMCNT_B_OFS_SHIFT) | (1 <<
84                                                                                  REG_GX_VRAMCNT_B_E_SHIFT),
85     GX_VRAMCNT_B_BG_0x06000000 =
86         (1 << REG_GX_VRAMCNT_B_MST_SHIFT) | (0 << REG_GX_VRAMCNT_B_OFS_SHIFT) | (1 <<
87                                                                                  REG_GX_VRAMCNT_B_E_SHIFT),
88     GX_VRAMCNT_B_BG_0x06020000 =
89         (1 << REG_GX_VRAMCNT_B_MST_SHIFT) | (1 << REG_GX_VRAMCNT_B_OFS_SHIFT) | (1 <<
90                                                                                  REG_GX_VRAMCNT_B_E_SHIFT),
91     GX_VRAMCNT_B_BG_0x06040000 =
92         (1 << REG_GX_VRAMCNT_B_MST_SHIFT) | (2 << REG_GX_VRAMCNT_B_OFS_SHIFT) | (1 <<
93                                                                                  REG_GX_VRAMCNT_B_E_SHIFT),
94     GX_VRAMCNT_B_BG_0x06060000 =
95         (1 << REG_GX_VRAMCNT_B_MST_SHIFT) | (3 << REG_GX_VRAMCNT_B_OFS_SHIFT) | (1 <<
96                                                                                  REG_GX_VRAMCNT_B_E_SHIFT),
97     GX_VRAMCNT_B_OBJ_0x06400000 =
98         (2 << REG_GX_VRAMCNT_B_MST_SHIFT) | (0 << REG_GX_VRAMCNT_B_OFS_SHIFT) | (1 <<
99                                                                                  REG_GX_VRAMCNT_B_E_SHIFT),
100     GX_VRAMCNT_B_OBJ_0x06420000 =
101         (2 << REG_GX_VRAMCNT_B_MST_SHIFT) | (1 << REG_GX_VRAMCNT_B_OFS_SHIFT) | (1 <<
102                                                                                  REG_GX_VRAMCNT_B_E_SHIFT),
103     GX_VRAMCNT_B_TEX_0 =
104         (3 << REG_GX_VRAMCNT_B_MST_SHIFT) | (0 << REG_GX_VRAMCNT_B_OFS_SHIFT) | (1 <<
105                                                                                  REG_GX_VRAMCNT_B_E_SHIFT),
106     GX_VRAMCNT_B_TEX_1 =
107         (3 << REG_GX_VRAMCNT_B_MST_SHIFT) | (1 << REG_GX_VRAMCNT_B_OFS_SHIFT) | (1 <<
108                                                                                  REG_GX_VRAMCNT_B_E_SHIFT),
109     GX_VRAMCNT_B_TEX_2 =
110         (3 << REG_GX_VRAMCNT_B_MST_SHIFT) | (2 << REG_GX_VRAMCNT_B_OFS_SHIFT) | (1 <<
111                                                                                  REG_GX_VRAMCNT_B_E_SHIFT),
112     GX_VRAMCNT_B_TEX_3 =
113         (3 << REG_GX_VRAMCNT_B_MST_SHIFT) | (3 << REG_GX_VRAMCNT_B_OFS_SHIFT) | (1 <<
114                                                                                  REG_GX_VRAMCNT_B_E_SHIFT)
115 }
116 GX_VRAMCNT_B;
117 
118 
119 //---------------------------------------------------------------------------
120 // Enum values for VRAMCNT-C (internal use only)
121 //---------------------------------------------------------------------------
122 typedef enum
123 {
124     GX_VRAMCNT_C_DISABLE = 0,
125     GX_VRAMCNT_C_LCDC_0x06840000 =
126         (0 << REG_GX_VRAMCNT_C_MST_SHIFT) | (0 << REG_GX_VRAMCNT_C_OFS_SHIFT) | (1 <<
127                                                                                  REG_GX_VRAMCNT_C_E_SHIFT),
128     GX_VRAMCNT_C_BG_0x06000000 =
129         (1 << REG_GX_VRAMCNT_C_MST_SHIFT) | (0 << REG_GX_VRAMCNT_C_OFS_SHIFT) | (1 <<
130                                                                                  REG_GX_VRAMCNT_C_E_SHIFT),
131     GX_VRAMCNT_C_BG_0x06020000 =
132         (1 << REG_GX_VRAMCNT_C_MST_SHIFT) | (1 << REG_GX_VRAMCNT_C_OFS_SHIFT) | (1 <<
133                                                                                  REG_GX_VRAMCNT_C_E_SHIFT),
134     GX_VRAMCNT_C_BG_0x06040000 =
135         (1 << REG_GX_VRAMCNT_C_MST_SHIFT) | (2 << REG_GX_VRAMCNT_C_OFS_SHIFT) | (1 <<
136                                                                                  REG_GX_VRAMCNT_C_E_SHIFT),
137     GX_VRAMCNT_C_BG_0x06060000 =
138         (1 << REG_GX_VRAMCNT_C_MST_SHIFT) | (3 << REG_GX_VRAMCNT_C_OFS_SHIFT) | (1 <<
139                                                                                  REG_GX_VRAMCNT_C_E_SHIFT),
140     GX_VRAMCNT_C_ARM7_0x06000000 =
141         (2 << REG_GX_VRAMCNT_C_MST_SHIFT) | (0 << REG_GX_VRAMCNT_C_OFS_SHIFT) | (1 <<
142                                                                                  REG_GX_VRAMCNT_C_E_SHIFT),
143     GX_VRAMCNT_C_ARM7_0x06020000 =
144         (2 << REG_GX_VRAMCNT_C_MST_SHIFT) | (1 << REG_GX_VRAMCNT_C_OFS_SHIFT) | (1 <<
145                                                                                  REG_GX_VRAMCNT_C_E_SHIFT),
146     GX_VRAMCNT_C_TEX_0 =
147         (3 << REG_GX_VRAMCNT_C_MST_SHIFT) | (0 << REG_GX_VRAMCNT_C_OFS_SHIFT) | (1 <<
148                                                                                  REG_GX_VRAMCNT_C_E_SHIFT),
149     GX_VRAMCNT_C_TEX_1 =
150         (3 << REG_GX_VRAMCNT_C_MST_SHIFT) | (1 << REG_GX_VRAMCNT_C_OFS_SHIFT) | (1 <<
151                                                                                  REG_GX_VRAMCNT_C_E_SHIFT),
152     GX_VRAMCNT_C_TEX_2 =
153         (3 << REG_GX_VRAMCNT_C_MST_SHIFT) | (2 << REG_GX_VRAMCNT_C_OFS_SHIFT) | (1 <<
154                                                                                  REG_GX_VRAMCNT_C_E_SHIFT),
155     GX_VRAMCNT_C_TEX_3 =
156         (3 << REG_GX_VRAMCNT_C_MST_SHIFT) | (3 << REG_GX_VRAMCNT_C_OFS_SHIFT) | (1 <<
157                                                                                  REG_GX_VRAMCNT_C_E_SHIFT),
158     GX_VRAMCNT_C_SUBBG_0x06200000 =
159         (4 << REG_GX_VRAMCNT_C_MST_SHIFT) | (1 << REG_GX_VRAMCNT_C_E_SHIFT)
160 }
161 GX_VRAMCNT_C;
162 
163 
164 //---------------------------------------------------------------------------
165 // Enum values for VRAMCNT-D (internal use only)
166 //---------------------------------------------------------------------------
167 typedef enum
168 {
169     GX_VRAMCNT_D_DISABLE = 0,
170     GX_VRAMCNT_D_LCDC_0x06860000 =
171         (0 << REG_GX_VRAMCNT_D_MST_SHIFT) | (0 << REG_GX_VRAMCNT_D_OFS_SHIFT) | (1 <<
172                                                                                  REG_GX_VRAMCNT_D_E_SHIFT),
173     GX_VRAMCNT_D_BG_0x06000000 =
174         (1 << REG_GX_VRAMCNT_D_MST_SHIFT) | (0 << REG_GX_VRAMCNT_D_OFS_SHIFT) | (1 <<
175                                                                                  REG_GX_VRAMCNT_D_E_SHIFT),
176     GX_VRAMCNT_D_BG_0x06020000 =
177         (1 << REG_GX_VRAMCNT_D_MST_SHIFT) | (1 << REG_GX_VRAMCNT_D_OFS_SHIFT) | (1 <<
178                                                                                  REG_GX_VRAMCNT_D_E_SHIFT),
179     GX_VRAMCNT_D_BG_0x06040000 =
180         (1 << REG_GX_VRAMCNT_D_MST_SHIFT) | (2 << REG_GX_VRAMCNT_D_OFS_SHIFT) | (1 <<
181                                                                                  REG_GX_VRAMCNT_D_E_SHIFT),
182     GX_VRAMCNT_D_BG_0x06060000 =
183         (1 << REG_GX_VRAMCNT_D_MST_SHIFT) | (3 << REG_GX_VRAMCNT_D_OFS_SHIFT) | (1 <<
184                                                                                  REG_GX_VRAMCNT_D_E_SHIFT),
185     GX_VRAMCNT_D_ARM7_0x06000000 =
186         (2 << REG_GX_VRAMCNT_D_MST_SHIFT) | (0 << REG_GX_VRAMCNT_D_OFS_SHIFT) | (1 <<
187                                                                                  REG_GX_VRAMCNT_D_E_SHIFT),
188     GX_VRAMCNT_D_ARM7_0x06020000 =
189         (2 << REG_GX_VRAMCNT_D_MST_SHIFT) | (1 << REG_GX_VRAMCNT_D_OFS_SHIFT) | (1 <<
190                                                                                  REG_GX_VRAMCNT_D_E_SHIFT),
191     GX_VRAMCNT_D_TEX_0 =
192         (3 << REG_GX_VRAMCNT_D_MST_SHIFT) | (0 << REG_GX_VRAMCNT_D_OFS_SHIFT) | (1 <<
193                                                                                  REG_GX_VRAMCNT_D_E_SHIFT),
194     GX_VRAMCNT_D_TEX_1 =
195         (3 << REG_GX_VRAMCNT_D_MST_SHIFT) | (1 << REG_GX_VRAMCNT_D_OFS_SHIFT) | (1 <<
196                                                                                  REG_GX_VRAMCNT_D_E_SHIFT),
197     GX_VRAMCNT_D_TEX_2 =
198         (3 << REG_GX_VRAMCNT_D_MST_SHIFT) | (2 << REG_GX_VRAMCNT_D_OFS_SHIFT) | (1 <<
199                                                                                  REG_GX_VRAMCNT_D_E_SHIFT),
200     GX_VRAMCNT_D_TEX_3 =
201         (3 << REG_GX_VRAMCNT_D_MST_SHIFT) | (3 << REG_GX_VRAMCNT_D_OFS_SHIFT) | (1 <<
202                                                                                  REG_GX_VRAMCNT_D_E_SHIFT),
203     GX_VRAMCNT_D_SUBOBJ_0x06600000 =
204         (4 << REG_GX_VRAMCNT_D_MST_SHIFT) | (1 << REG_GX_VRAMCNT_D_E_SHIFT)
205 }
206 GX_VRAMCNT_D;
207 
208 
209 //---------------------------------------------------------------------------
210 // Enum values for VRAMCNT-E (internal use only)
211 //---------------------------------------------------------------------------
212 typedef enum
213 {
214     GX_VRAMCNT_E_DISABLE = 0,
215     GX_VRAMCNT_E_LCDC_0x06880000 =
216         (0 << REG_GX_VRAMCNT_E_MST_SHIFT) | (1 << REG_GX_VRAMCNT_E_E_SHIFT),
217     GX_VRAMCNT_E_BG_0x06000000 =
218         (1 << REG_GX_VRAMCNT_E_MST_SHIFT) | (1 << REG_GX_VRAMCNT_E_E_SHIFT),
219     GX_VRAMCNT_E_OBJ_0x06400000 =
220         (2 << REG_GX_VRAMCNT_E_MST_SHIFT) | (1 << REG_GX_VRAMCNT_E_E_SHIFT),
221     GX_VRAMCNT_E_TEXPLTT_0123 = (3 << REG_GX_VRAMCNT_E_MST_SHIFT) | (1 << REG_GX_VRAMCNT_E_E_SHIFT),
222     GX_VRAMCNT_E_BGEXTPLTT_0123 =
223         (4 << REG_GX_VRAMCNT_E_MST_SHIFT) | (1 << REG_GX_VRAMCNT_E_E_SHIFT)
224 }
225 GX_VRAMCNT_E;
226 
227 
228 //---------------------------------------------------------------------------
229 // Enum values for VRAMCNT-F (internal use only)
230 //---------------------------------------------------------------------------
231 typedef enum
232 {
233     GX_VRAMCNT_F_DISABLE = 0,
234     GX_VRAMCNT_F_LCDC_0x06890000 =
235         (0 << REG_GX_VRAMCNT_F_MST_SHIFT) | (0 << REG_GX_VRAMCNT_F_OFS_SHIFT) | (1 <<
236                                                                                  REG_GX_VRAMCNT_F_E_SHIFT),
237     GX_VRAMCNT_F_BG_0x06000000 =
238         (1 << REG_GX_VRAMCNT_F_MST_SHIFT) | (0 << REG_GX_VRAMCNT_F_OFS_SHIFT) | (1 <<
239                                                                                  REG_GX_VRAMCNT_F_E_SHIFT),
240     GX_VRAMCNT_F_BG_0x06004000 =
241         (1 << REG_GX_VRAMCNT_F_MST_SHIFT) | (1 << REG_GX_VRAMCNT_F_OFS_SHIFT) | (1 <<
242                                                                                  REG_GX_VRAMCNT_F_E_SHIFT),
243     GX_VRAMCNT_F_BG_0x06010000 =
244         (1 << REG_GX_VRAMCNT_F_MST_SHIFT) | (2 << REG_GX_VRAMCNT_F_OFS_SHIFT) | (1 <<
245                                                                                  REG_GX_VRAMCNT_F_E_SHIFT),
246     GX_VRAMCNT_F_BG_0x06014000 =
247         (1 << REG_GX_VRAMCNT_F_MST_SHIFT) | (3 << REG_GX_VRAMCNT_F_OFS_SHIFT) | (1 <<
248                                                                                  REG_GX_VRAMCNT_F_E_SHIFT),
249     GX_VRAMCNT_F_OBJ_0x06400000 =
250         (2 << REG_GX_VRAMCNT_F_MST_SHIFT) | (0 << REG_GX_VRAMCNT_F_OFS_SHIFT) | (1 <<
251                                                                                  REG_GX_VRAMCNT_F_E_SHIFT),
252     GX_VRAMCNT_F_OBJ_0x06404000 =
253         (2 << REG_GX_VRAMCNT_F_MST_SHIFT) | (1 << REG_GX_VRAMCNT_F_OFS_SHIFT) | (1 <<
254                                                                                  REG_GX_VRAMCNT_F_E_SHIFT),
255     GX_VRAMCNT_F_OBJ_0x06410000 =
256         (2 << REG_GX_VRAMCNT_F_MST_SHIFT) | (2 << REG_GX_VRAMCNT_F_OFS_SHIFT) | (1 <<
257                                                                                  REG_GX_VRAMCNT_F_E_SHIFT),
258     GX_VRAMCNT_F_OBJ_0x06414000 =
259         (2 << REG_GX_VRAMCNT_F_MST_SHIFT) | (3 << REG_GX_VRAMCNT_F_OFS_SHIFT) | (1 <<
260                                                                                  REG_GX_VRAMCNT_F_E_SHIFT),
261     GX_VRAMCNT_F_TEXPLTT_0 =
262         (3 << REG_GX_VRAMCNT_F_MST_SHIFT) | (0 << REG_GX_VRAMCNT_F_OFS_SHIFT) | (1 <<
263                                                                                  REG_GX_VRAMCNT_F_E_SHIFT),
264     GX_VRAMCNT_F_TEXPLTT_1 =
265         (3 << REG_GX_VRAMCNT_F_MST_SHIFT) | (1 << REG_GX_VRAMCNT_F_OFS_SHIFT) | (1 <<
266                                                                                  REG_GX_VRAMCNT_F_E_SHIFT),
267     GX_VRAMCNT_F_TEXPLTT_4 =
268         (3 << REG_GX_VRAMCNT_F_MST_SHIFT) | (2 << REG_GX_VRAMCNT_F_OFS_SHIFT) | (1 <<
269                                                                                  REG_GX_VRAMCNT_F_E_SHIFT),
270     GX_VRAMCNT_F_TEXPLTT_5 =
271         (3 << REG_GX_VRAMCNT_F_MST_SHIFT) | (3 << REG_GX_VRAMCNT_F_OFS_SHIFT) | (1 <<
272                                                                                  REG_GX_VRAMCNT_F_E_SHIFT),
273     GX_VRAMCNT_F_BGEXTPLTT_01 =
274         (4 << REG_GX_VRAMCNT_F_MST_SHIFT) | (0 << REG_GX_VRAMCNT_F_OFS_SHIFT) | (1 <<
275                                                                                  REG_GX_VRAMCNT_F_E_SHIFT),
276     GX_VRAMCNT_F_BGEXTPLTT_23 =
277         (4 << REG_GX_VRAMCNT_F_MST_SHIFT) | (1 << REG_GX_VRAMCNT_F_OFS_SHIFT) | (1 <<
278                                                                                  REG_GX_VRAMCNT_F_E_SHIFT),
279     GX_VRAMCNT_F_OBJEXTPLTT =
280         (5 << REG_GX_VRAMCNT_F_MST_SHIFT) | (0 << REG_GX_VRAMCNT_F_OFS_SHIFT) | (1 <<
281                                                                                  REG_GX_VRAMCNT_F_E_SHIFT)
282 }
283 GX_VRAMCNT_F;
284 
285 
286 //---------------------------------------------------------------------------
287 // Enum values for VRAMCNT-G (internal use only)
288 //---------------------------------------------------------------------------
289 typedef enum
290 {
291     GX_VRAMCNT_G_DISABLE = 0,
292     GX_VRAMCNT_G_LCDC_0x06894000 =
293         (0 << REG_GX_VRAMCNT_G_MST_SHIFT) | (0 << REG_GX_VRAMCNT_G_OFS_SHIFT) | (1 <<
294                                                                                  REG_GX_VRAMCNT_G_E_SHIFT),
295     GX_VRAMCNT_G_BG_0x06000000 =
296         (1 << REG_GX_VRAMCNT_G_MST_SHIFT) | (0 << REG_GX_VRAMCNT_G_OFS_SHIFT) | (1 <<
297                                                                                  REG_GX_VRAMCNT_G_E_SHIFT),
298     GX_VRAMCNT_G_BG_0x06004000 =
299         (1 << REG_GX_VRAMCNT_G_MST_SHIFT) | (1 << REG_GX_VRAMCNT_G_OFS_SHIFT) | (1 <<
300                                                                                  REG_GX_VRAMCNT_G_E_SHIFT),
301     GX_VRAMCNT_G_BG_0x06010000 =
302         (1 << REG_GX_VRAMCNT_G_MST_SHIFT) | (2 << REG_GX_VRAMCNT_G_OFS_SHIFT) | (1 <<
303                                                                                  REG_GX_VRAMCNT_G_E_SHIFT),
304     GX_VRAMCNT_G_BG_0x06014000 =
305         (1 << REG_GX_VRAMCNT_G_MST_SHIFT) | (3 << REG_GX_VRAMCNT_G_OFS_SHIFT) | (1 <<
306                                                                                  REG_GX_VRAMCNT_G_E_SHIFT),
307     GX_VRAMCNT_G_OBJ_0x06400000 =
308         (2 << REG_GX_VRAMCNT_G_MST_SHIFT) | (0 << REG_GX_VRAMCNT_G_OFS_SHIFT) | (1 <<
309                                                                                  REG_GX_VRAMCNT_G_E_SHIFT),
310     GX_VRAMCNT_G_OBJ_0x06404000 =
311         (2 << REG_GX_VRAMCNT_G_MST_SHIFT) | (1 << REG_GX_VRAMCNT_G_OFS_SHIFT) | (1 <<
312                                                                                  REG_GX_VRAMCNT_G_E_SHIFT),
313     GX_VRAMCNT_G_OBJ_0x06410000 =
314         (2 << REG_GX_VRAMCNT_G_MST_SHIFT) | (2 << REG_GX_VRAMCNT_G_OFS_SHIFT) | (1 <<
315                                                                                  REG_GX_VRAMCNT_G_E_SHIFT),
316     GX_VRAMCNT_G_OBJ_0x06414000 =
317         (2 << REG_GX_VRAMCNT_G_MST_SHIFT) | (3 << REG_GX_VRAMCNT_G_OFS_SHIFT) | (1 <<
318                                                                                  REG_GX_VRAMCNT_G_E_SHIFT),
319     GX_VRAMCNT_G_TEXPLTT_0 =
320         (3 << REG_GX_VRAMCNT_G_MST_SHIFT) | (0 << REG_GX_VRAMCNT_G_OFS_SHIFT) | (1 <<
321                                                                                  REG_GX_VRAMCNT_G_E_SHIFT),
322     GX_VRAMCNT_G_TEXPLTT_1 =
323         (3 << REG_GX_VRAMCNT_G_MST_SHIFT) | (1 << REG_GX_VRAMCNT_G_OFS_SHIFT) | (1 <<
324                                                                                  REG_GX_VRAMCNT_G_E_SHIFT),
325     GX_VRAMCNT_G_TEXPLTT_4 =
326         (3 << REG_GX_VRAMCNT_G_MST_SHIFT) | (2 << REG_GX_VRAMCNT_G_OFS_SHIFT) | (1 <<
327                                                                                  REG_GX_VRAMCNT_G_E_SHIFT),
328     GX_VRAMCNT_G_TEXPLTT_5 =
329         (3 << REG_GX_VRAMCNT_G_MST_SHIFT) | (3 << REG_GX_VRAMCNT_G_OFS_SHIFT) | (1 <<
330                                                                                  REG_GX_VRAMCNT_G_E_SHIFT),
331     GX_VRAMCNT_G_BGEXTPLTT_01 =
332         (4 << REG_GX_VRAMCNT_G_MST_SHIFT) | (0 << REG_GX_VRAMCNT_G_OFS_SHIFT) | (1 <<
333                                                                                  REG_GX_VRAMCNT_G_E_SHIFT),
334     GX_VRAMCNT_G_BGEXTPLTT_23 =
335         (4 << REG_GX_VRAMCNT_G_MST_SHIFT) | (1 << REG_GX_VRAMCNT_G_OFS_SHIFT) | (1 <<
336                                                                                  REG_GX_VRAMCNT_G_E_SHIFT),
337     GX_VRAMCNT_G_OBJEXTPLTT =
338         (5 << REG_GX_VRAMCNT_G_MST_SHIFT) | (0 << REG_GX_VRAMCNT_G_OFS_SHIFT) | (1 <<
339                                                                                  REG_GX_VRAMCNT_G_E_SHIFT)
340 }
341 GX_VRAMCNT_G;
342 
343 
344 //---------------------------------------------------------------------------
345 // Enum values for VRAMCNT-H (internal use only)
346 //---------------------------------------------------------------------------
347 typedef enum
348 {
349     GX_VRAMCNT_H_DISABLE = 0,
350     GX_VRAMCNT_H_LCDC_0x06898000 =
351         (0 << REG_GX_VRAMCNT_H_MST_SHIFT) | (1 << REG_GX_VRAMCNT_H_E_SHIFT),
352     GX_VRAMCNT_H_SUBBG_0x06200000 =
353         (1 << REG_GX_VRAMCNT_H_MST_SHIFT) | (1 << REG_GX_VRAMCNT_H_E_SHIFT),
354     GX_VRAMCNT_H_SUBBGEXTPLTT_0123 =
355         (2 << REG_GX_VRAMCNT_H_MST_SHIFT) | (1 << REG_GX_VRAMCNT_H_E_SHIFT)
356 }
357 GX_VRAMCNT_H;
358 
359 
360 //---------------------------------------------------------------------------
361 // Enum values for VRAMCNT-I (internal use only)
362 //---------------------------------------------------------------------------
363 typedef enum
364 {
365     GX_VRAMCNT_I_DISABLE = 0,
366     GX_VRAMCNT_I_LCDC_0x068A0000 =
367         (0 << REG_GX_VRAMCNT_I_MST_SHIFT) | (1 << REG_GX_VRAMCNT_I_E_SHIFT),
368     GX_VRAMCNT_I_SUBBG_0x06208000 =
369         (1 << REG_GX_VRAMCNT_I_MST_SHIFT) | (1 << REG_GX_VRAMCNT_I_E_SHIFT),
370     GX_VRAMCNT_I_SUBOBJ_0x06600000 =
371         (2 << REG_GX_VRAMCNT_I_MST_SHIFT) | (1 << REG_GX_VRAMCNT_I_E_SHIFT),
372     GX_VRAMCNT_I_SUBOBJEXTPLTT = (3 << REG_GX_VRAMCNT_I_MST_SHIFT) | (1 << REG_GX_VRAMCNT_I_E_SHIFT)
373 }
374 GX_VRAMCNT_I;
375 
376 #ifdef  SDK_CW_WARNOFF_SAFESTRB
377 #include <nitro/code32.h>
378 #endif
379 /*---------------------------------------------------------------------------*
380   Name:         GX_VRAMCNT_SetLCDC_ (internal use only)
381 
382   Description:  Assigns banks onto LCDC.
383                 DO NOT INLINE THIS.
384 
385   Arguments:    lcdc:       Banks assigned to LCDC.
386 
387   Returns:      None.
388  *---------------------------------------------------------------------------*/
GX_VRAMCNT_SetLCDC_(int lcdc)389 static void GX_VRAMCNT_SetLCDC_(int lcdc)
390 {
391     if (lcdc & GX_VRAM_LCDC_A)
392         reg_GX_VRAMCNT_A = (u8)GX_VRAMCNT_A_LCDC_0x06800000;
393     if (lcdc & GX_VRAM_LCDC_B)
394         reg_GX_VRAMCNT_B = (u8)GX_VRAMCNT_B_LCDC_0x06820000;
395     if (lcdc & GX_VRAM_LCDC_C)
396         reg_GX_VRAMCNT_C = (u8)GX_VRAMCNT_C_LCDC_0x06840000;
397     if (lcdc & GX_VRAM_LCDC_D)
398         reg_GX_VRAMCNT_D = (u8)GX_VRAMCNT_D_LCDC_0x06860000;
399     if (lcdc & GX_VRAM_LCDC_E)
400         reg_GX_VRAMCNT_E = (u8)GX_VRAMCNT_E_LCDC_0x06880000;
401     if (lcdc & GX_VRAM_LCDC_F)
402         reg_GX_VRAMCNT_F = (u8)GX_VRAMCNT_F_LCDC_0x06890000;
403     if (lcdc & GX_VRAM_LCDC_G)
404         reg_GX_VRAMCNT_G = (u8)GX_VRAMCNT_G_LCDC_0x06894000;
405     if (lcdc & GX_VRAM_LCDC_H)
406         reg_GX_VRAMCNT_H = (u8)GX_VRAMCNT_H_LCDC_0x06898000;
407     if (lcdc & GX_VRAM_LCDC_I)
408         reg_GX_VRAMCNT_I = (u8)GX_VRAMCNT_I_LCDC_0x068A0000;
409 }
410 
411 /*---------------------------------------------------------------------------*
412   Name:         GX_VRAMCNT_SetBG_ (internal use only)
413 
414   Description:  Assigns banks onto BG.
415                 The banks are mapped consecutively from HW_BG_VRAM(0x06000000).
416                 This is called only by GX_SetBankForBG.
417 
418   Arguments:    bg:         Banks assigned to BG
419 
420   Returns:      None.
421  *---------------------------------------------------------------------------*/
GX_VRAMCNT_SetBG_(GXVRamBG bg)422 static inline void GX_VRAMCNT_SetBG_(GXVRamBG bg)
423 {
424     switch (bg)
425     {
426     case GX_VRAM_BG_128_D:
427         reg_GX_VRAMCNT_D = (u8)GX_VRAMCNT_D_BG_0x06000000;
428         break;
429 
430     case GX_VRAM_BG_256_CD:
431         reg_GX_VRAMCNT_D = (u8)GX_VRAMCNT_D_BG_0x06020000;
432         // don't break
433     case GX_VRAM_BG_128_C:
434         reg_GX_VRAMCNT_C = (u8)GX_VRAMCNT_C_BG_0x06000000;
435         break;
436 
437     case GX_VRAM_BG_384_BCD:
438         reg_GX_VRAMCNT_D = (u8)GX_VRAMCNT_D_BG_0x06040000;
439         // don't break
440     case GX_VRAM_BG_256_BC:
441         reg_GX_VRAMCNT_C = (u8)GX_VRAMCNT_C_BG_0x06020000;
442         // don't break
443     case GX_VRAM_BG_128_B:
444         reg_GX_VRAMCNT_B = (u8)GX_VRAMCNT_B_BG_0x06000000;
445         break;
446 
447     case GX_VRAM_BG_512_ABCD:
448         reg_GX_VRAMCNT_D = (u8)GX_VRAMCNT_D_BG_0x06060000;
449         // don't break
450     case GX_VRAM_BG_384_ABC:
451         reg_GX_VRAMCNT_C = (u8)GX_VRAMCNT_C_BG_0x06040000;
452         // don't break
453     case GX_VRAM_BG_256_AB:
454         reg_GX_VRAMCNT_B = (u8)GX_VRAMCNT_B_BG_0x06020000;
455         // don't break
456     case GX_VRAM_BG_128_A:
457         reg_GX_VRAMCNT_A = (u8)GX_VRAMCNT_A_BG_0x06000000;
458         // don't break
459     case GX_VRAM_BG_NONE:
460         break;
461 
462     case GX_VRAM_BG_384_ABD:
463         reg_GX_VRAMCNT_A = (u8)GX_VRAMCNT_A_BG_0x06000000;
464         reg_GX_VRAMCNT_B = (u8)GX_VRAMCNT_B_BG_0x06020000;
465         reg_GX_VRAMCNT_D = (u8)GX_VRAMCNT_D_BG_0x06040000;
466         break;
467 
468     case GX_VRAM_BG_384_ACD:
469         reg_GX_VRAMCNT_D = (u8)GX_VRAMCNT_D_BG_0x06040000;
470         // don't break
471     case GX_VRAM_BG_256_AC:
472         reg_GX_VRAMCNT_A = (u8)GX_VRAMCNT_A_BG_0x06000000;
473         reg_GX_VRAMCNT_C = (u8)GX_VRAMCNT_C_BG_0x06020000;
474         break;
475 
476     case GX_VRAM_BG_256_AD:
477         reg_GX_VRAMCNT_A = (u8)GX_VRAMCNT_A_BG_0x06000000;
478         reg_GX_VRAMCNT_D = (u8)GX_VRAMCNT_D_BG_0x06020000;
479         break;
480 
481     case GX_VRAM_BG_256_BD:
482         reg_GX_VRAMCNT_B = (u8)GX_VRAMCNT_B_BG_0x06000000;
483         reg_GX_VRAMCNT_D = (u8)GX_VRAMCNT_D_BG_0x06020000;
484         break;
485 
486     case GX_VRAM_BG_96_EFG:
487         reg_GX_VRAMCNT_G = (u8)GX_VRAMCNT_G_BG_0x06014000;
488         // don't break;
489     case GX_VRAM_BG_80_EF:
490         reg_GX_VRAMCNT_F = (u8)GX_VRAMCNT_F_BG_0x06010000;
491         // don't break;
492     case GX_VRAM_BG_64_E:
493         reg_GX_VRAMCNT_E = (u8)GX_VRAMCNT_E_BG_0x06000000;
494         break;
495 
496     case GX_VRAM_BG_80_EG:
497         reg_GX_VRAMCNT_G = (u8)GX_VRAMCNT_G_BG_0x06010000;
498         reg_GX_VRAMCNT_E = (u8)GX_VRAMCNT_E_BG_0x06000000;
499         break;
500 
501     case GX_VRAM_BG_32_FG:
502         reg_GX_VRAMCNT_G = (u8)GX_VRAMCNT_G_BG_0x06004000;
503         // don't break
504     case GX_VRAM_BG_16_F:
505         reg_GX_VRAMCNT_F = (u8)GX_VRAMCNT_F_BG_0x06000000;
506         break;
507 
508     case GX_VRAM_BG_16_G:
509         reg_GX_VRAMCNT_G = (u8)GX_VRAMCNT_G_BG_0x06000000;
510         break;
511 
512     default:
513         SDK_INTERNAL_ERROR("unknown GXVRamBG, 0x%x specified.", bg);
514         break;
515     }
516 }
517 
518 
519 /*---------------------------------------------------------------------------*
520   Name:         GX_VRAMCNT_SetBGEx1_ (internal use only)
521 
522   Description:  Assigns banks onto BG.
523                 The banks are mapped consecutively from HW_BG_VRAM(0x06000000).
524                 This is called only by GX_SetBankForBG.
525 
526   Arguments:    bg:         Banks assigned to BG
527 
528   Returns:      None.
529  *---------------------------------------------------------------------------*/
GX_VRAMCNT_SetBGEx1_(GXVRamBG bg)530 static inline void GX_VRAMCNT_SetBGEx1_(GXVRamBG bg)
531 {
532     switch (bg)
533     {
534     case GX_VRAM_BG_96_EFG:
535         reg_GX_VRAMCNT_G = (u8)GX_VRAMCNT_G_BG_0x06014000;
536         // don't break;
537     case GX_VRAM_BG_80_EF:
538         reg_GX_VRAMCNT_F = (u8)GX_VRAMCNT_F_BG_0x06010000;
539         // don't break;
540     case GX_VRAM_BG_64_E:
541         reg_GX_VRAMCNT_E = (u8)GX_VRAMCNT_E_BG_0x06000000;
542         break;
543 
544     case GX_VRAM_BG_80_EG:
545         reg_GX_VRAMCNT_G = (u8)GX_VRAMCNT_G_BG_0x06010000;
546         reg_GX_VRAMCNT_E = (u8)GX_VRAMCNT_E_BG_0x06000000;
547         break;
548 
549     case GX_VRAM_BG_32_FG:
550         reg_GX_VRAMCNT_G = (u8)GX_VRAMCNT_G_BG_0x06004000;
551         // don't break
552     case GX_VRAM_BG_16_F:
553         reg_GX_VRAMCNT_F = (u8)GX_VRAMCNT_F_BG_0x06000000;
554         break;
555 
556     case GX_VRAM_BG_16_G:
557         reg_GX_VRAMCNT_G = (u8)GX_VRAMCNT_G_BG_0x06000000;
558         break;
559 
560     default:
561         SDK_INTERNAL_ERROR("unknown GXVRamBG, 0x%x specified.", bg);
562         break;
563     }
564 }
565 
566 /*---------------------------------------------------------------------------*
567   Name:         GX_VRAMCNT_SetBGEx2_ (internal use only)
568 
569   Description:  Assigns banks onto BG.
570                 The banks are mapped consecutively from HW_BG_VRAM(0x06000000).
571                 This is called only by GX_SetBankForBG.
572 
573   Arguments:    bg:         Banks assigned to BG
574 
575   Returns:      None.
576  *---------------------------------------------------------------------------*/
GX_VRAMCNT_SetBGEx2_(GXVRamBG bg)577 static inline void GX_VRAMCNT_SetBGEx2_(GXVRamBG bg)
578 {
579     switch (bg)
580     {
581     case GX_VRAM_BG_128_D:
582         reg_GX_VRAMCNT_D = (u8)GX_VRAMCNT_D_BG_0x06020000;
583         break;
584 
585     case GX_VRAM_BG_256_CD:
586         reg_GX_VRAMCNT_D = (u8)GX_VRAMCNT_D_BG_0x06040000;
587         // don't break
588     case GX_VRAM_BG_128_C:
589         reg_GX_VRAMCNT_C = (u8)GX_VRAMCNT_C_BG_0x06020000;
590         break;
591 
592     case GX_VRAM_BG_384_BCD:
593         reg_GX_VRAMCNT_D = (u8)GX_VRAMCNT_D_BG_0x06060000;
594         // don't break
595     case GX_VRAM_BG_256_BC:
596         reg_GX_VRAMCNT_C = (u8)GX_VRAMCNT_C_BG_0x06040000;
597         // don't break
598     case GX_VRAM_BG_128_B:
599         reg_GX_VRAMCNT_B = (u8)GX_VRAMCNT_B_BG_0x06020000;
600         break;
601 
602     case GX_VRAM_BG_384_ABC:
603         reg_GX_VRAMCNT_C = (u8)GX_VRAMCNT_C_BG_0x06060000;
604         // don't break
605     case GX_VRAM_BG_256_AB:
606         reg_GX_VRAMCNT_B = (u8)GX_VRAMCNT_B_BG_0x06040000;
607         // don't break
608     case GX_VRAM_BG_128_A:
609         reg_GX_VRAMCNT_A = (u8)GX_VRAMCNT_A_BG_0x06020000;
610         // don't break
611     case GX_VRAM_BG_NONE:
612         break;
613 
614     case GX_VRAM_BG_384_ABD:
615         reg_GX_VRAMCNT_A = (u8)GX_VRAMCNT_A_BG_0x06020000;
616         reg_GX_VRAMCNT_B = (u8)GX_VRAMCNT_B_BG_0x06040000;
617         reg_GX_VRAMCNT_D = (u8)GX_VRAMCNT_D_BG_0x06060000;
618         break;
619 
620     case GX_VRAM_BG_384_ACD:
621         reg_GX_VRAMCNT_D = (u8)GX_VRAMCNT_D_BG_0x06060000;
622         // don't break
623     case GX_VRAM_BG_256_AC:
624         reg_GX_VRAMCNT_A = (u8)GX_VRAMCNT_A_BG_0x06020000;
625         reg_GX_VRAMCNT_C = (u8)GX_VRAMCNT_C_BG_0x06040000;
626         break;
627 
628     case GX_VRAM_BG_256_AD:
629         reg_GX_VRAMCNT_A = (u8)GX_VRAMCNT_A_BG_0x06020000;
630         reg_GX_VRAMCNT_D = (u8)GX_VRAMCNT_D_BG_0x06040000;
631         break;
632 
633     case GX_VRAM_BG_256_BD:
634         reg_GX_VRAMCNT_B = (u8)GX_VRAMCNT_B_BG_0x06020000;
635         reg_GX_VRAMCNT_D = (u8)GX_VRAMCNT_D_BG_0x06040000;
636         break;
637 
638     default:
639         SDK_INTERNAL_ERROR("unknown GXVRamBG, 0x%x specified.", bg);
640         break;
641     }
642 }
643 
644 
645 /*---------------------------------------------------------------------------*
646   Name:         GX_VRAMCNT_SetOBJ_ (internal use only)
647 
648   Description:  Assigns banks onto OBJ.
649                 The banks are mapped consecutively from HW_OBJ_VRAM(0x06400000).
650                 This is called only by GX_SetBankForOBJ.
651 
652   Arguments:    obj:        Banks assigned to OBJ
653 
654   Returns:      None.
655  *---------------------------------------------------------------------------*/
GX_VRAMCNT_SetOBJ_(GXVRamOBJ obj)656 static inline void GX_VRAMCNT_SetOBJ_(GXVRamOBJ obj)
657 {
658     switch (obj)
659     {
660     case GX_VRAM_OBJ_256_AB:
661         reg_GX_VRAMCNT_B = (u8)GX_VRAMCNT_B_OBJ_0x06420000;
662         // don't break
663     case GX_VRAM_OBJ_128_A:
664         reg_GX_VRAMCNT_A = (u8)GX_VRAMCNT_A_OBJ_0x06400000;
665         // don't break
666     case GX_VRAM_OBJ_NONE:
667         break;
668 
669     case GX_VRAM_OBJ_128_B:
670         reg_GX_VRAMCNT_B = (u8)GX_VRAMCNT_B_OBJ_0x06400000;
671         break;
672 
673     case GX_VRAM_OBJ_96_EFG:
674         reg_GX_VRAMCNT_G = (u8)GX_VRAMCNT_G_OBJ_0x06414000;
675         // don't break
676     case GX_VRAM_OBJ_80_EF:
677         reg_GX_VRAMCNT_F = (u8)GX_VRAMCNT_F_OBJ_0x06410000;
678         // don't break
679     case GX_VRAM_OBJ_64_E:
680         reg_GX_VRAMCNT_E = (u8)GX_VRAMCNT_E_OBJ_0x06400000;
681         break;
682 
683     case GX_VRAM_OBJ_80_EG:
684         reg_GX_VRAMCNT_G = (u8)GX_VRAMCNT_G_OBJ_0x06410000;
685         reg_GX_VRAMCNT_E = (u8)GX_VRAMCNT_E_OBJ_0x06400000;
686         break;
687 
688     case GX_VRAM_OBJ_32_FG:
689         reg_GX_VRAMCNT_G = (u8)GX_VRAMCNT_G_OBJ_0x06404000;
690         // don't break
691     case GX_VRAM_OBJ_16_F:
692         reg_GX_VRAMCNT_F = (u8)GX_VRAMCNT_F_OBJ_0x06400000;
693         break;
694 
695     case GX_VRAM_OBJ_16_G:
696         reg_GX_VRAMCNT_G = (u8)GX_VRAMCNT_G_OBJ_0x06400000;
697         break;
698 
699     default:
700         SDK_INTERNAL_ERROR("unknown GXVRamOBJ, 0x%x specified.", obj);
701         break;
702     }
703 }
704 
705 /*---------------------------------------------------------------------------*
706   Name:         GX_VRAMCNT_SetARM7_ (internal use only)
707 
708   Description:  Assigns banks to ARM7.
709                 The banks are mapped consecutively from ARM7's 0x06000000.
710                 This is called only by GX_SetBankForARM7.
711 
712   Arguments:    arm7:       Banks assigned to ARM7
713 
714   Returns:      None.
715  *---------------------------------------------------------------------------*/
GX_VRAMCNT_SetARM7_(GXVRamARM7 arm7)716 static inline void GX_VRAMCNT_SetARM7_(GXVRamARM7 arm7)
717 {
718     switch (arm7)
719     {
720     case GX_VRAM_ARM7_256_CD:
721         reg_GX_VRAMCNT_D = (u8)GX_VRAMCNT_D_ARM7_0x06020000;
722         reg_GX_VRAMCNT_C = (u8)GX_VRAMCNT_C_ARM7_0x06000000;
723         break;
724     case GX_VRAM_ARM7_128_C:
725         reg_GX_VRAMCNT_C = (u8)GX_VRAMCNT_C_ARM7_0x06000000;
726         break;
727     case GX_VRAM_ARM7_128_D:
728         reg_GX_VRAMCNT_D = (u8)GX_VRAMCNT_D_ARM7_0x06000000;
729         // don't break
730     case GX_VRAM_ARM7_NONE:
731         break;
732 
733     default:
734         SDK_INTERNAL_ERROR("unknown GXVRamARM7, 0x%x specified.", arm7);
735         break;
736     }
737 }
738 
texOn_()739 static inline void texOn_()
740 {
741     reg_G3X_DISP3DCNT = (u16)((reg_G3X_DISP3DCNT &
742                                ~(REG_G3X_DISP3DCNT_RO_MASK | REG_G3X_DISP3DCNT_GO_MASK)) |
743                               REG_G3X_DISP3DCNT_TME_MASK);
744 }
745 
texOff_()746 static inline void texOff_()
747 {
748     reg_G3X_DISP3DCNT &= (u16)~(REG_G3X_DISP3DCNT_TME_MASK |
749                                 REG_G3X_DISP3DCNT_RO_MASK | REG_G3X_DISP3DCNT_GO_MASK);
750 }
751 
752 
753 /*---------------------------------------------------------------------------*
754   Name:         GX_VRAMCNT_SetTEX_ (internal use only)
755 
756   Description:  Assigns banks to texture image slots.
757                 The banks are mapped consecutively from the slot #0.
758                 This is called only by GX_SetBankForTex.
759 
760   Arguments:    tex:       Banks assigned to texture image slots
761 
762   Returns:      None.
763  *---------------------------------------------------------------------------*/
GX_VRAMCNT_SetTEX_(GXVRamTex tex)764 static inline void GX_VRAMCNT_SetTEX_(GXVRamTex tex)
765 {
766     if (tex == GX_VRAM_TEX_NONE)
767     {
768         texOff_();
769         return;
770     }
771     texOn_();
772 
773     switch (tex)
774     {
775     case GX_VRAM_TEX_01_AC:
776         reg_GX_VRAMCNT_A = (u8)GX_VRAMCNT_A_TEX_0;
777         reg_GX_VRAMCNT_C = (u8)GX_VRAMCNT_C_TEX_1;
778         break;
779 
780     case GX_VRAM_TEX_01_AD:
781         reg_GX_VRAMCNT_A = (u8)GX_VRAMCNT_A_TEX_0;
782         reg_GX_VRAMCNT_D = (u8)GX_VRAMCNT_D_TEX_1;
783         break;
784 
785     case GX_VRAM_TEX_01_BD:
786         reg_GX_VRAMCNT_B = (u8)GX_VRAMCNT_B_TEX_0;
787         reg_GX_VRAMCNT_D = (u8)GX_VRAMCNT_D_TEX_1;
788         break;
789 
790     case GX_VRAM_TEX_012_ABD:
791         reg_GX_VRAMCNT_A = (u8)GX_VRAMCNT_A_TEX_0;
792         reg_GX_VRAMCNT_B = (u8)GX_VRAMCNT_B_TEX_1;
793         reg_GX_VRAMCNT_D = (u8)GX_VRAMCNT_D_TEX_2;
794         break;
795 
796     case GX_VRAM_TEX_012_ACD:
797         reg_GX_VRAMCNT_A = (u8)GX_VRAMCNT_A_TEX_0;
798         reg_GX_VRAMCNT_C = (u8)GX_VRAMCNT_C_TEX_1;
799         reg_GX_VRAMCNT_D = (u8)GX_VRAMCNT_D_TEX_2;
800         break;
801 
802     case GX_VRAM_TEX_0_D:
803         reg_GX_VRAMCNT_D = (u8)GX_VRAMCNT_D_TEX_0;
804         break;
805 
806     case GX_VRAM_TEX_01_CD:
807         reg_GX_VRAMCNT_D = (u8)GX_VRAMCNT_D_TEX_1;
808         // don't break
809     case GX_VRAM_TEX_0_C:
810         reg_GX_VRAMCNT_C = (u8)GX_VRAMCNT_C_TEX_0;
811         break;
812 
813     case GX_VRAM_TEX_012_BCD:
814         reg_GX_VRAMCNT_D = (u8)GX_VRAMCNT_D_TEX_2;
815         // don't break
816     case GX_VRAM_TEX_01_BC:
817         reg_GX_VRAMCNT_C = (u8)GX_VRAMCNT_C_TEX_1;
818         // don't break
819     case GX_VRAM_TEX_0_B:
820         reg_GX_VRAMCNT_B = (u8)GX_VRAMCNT_B_TEX_0;
821         break;
822 
823     case GX_VRAM_TEX_0123_ABCD:
824         reg_GX_VRAMCNT_D = (u8)GX_VRAMCNT_D_TEX_3;
825         // don't break;
826     case GX_VRAM_TEX_012_ABC:
827         reg_GX_VRAMCNT_C = (u8)GX_VRAMCNT_C_TEX_2;
828         // don't break;
829     case GX_VRAM_TEX_01_AB:
830         reg_GX_VRAMCNT_B = (u8)GX_VRAMCNT_B_TEX_1;
831         // don't break;
832     case GX_VRAM_TEX_0_A:
833         reg_GX_VRAMCNT_A = (u8)GX_VRAMCNT_A_TEX_0;
834         break;
835     default:
836         SDK_INTERNAL_ERROR("unknown GXVRamTex, 0x%x specified.", tex);
837         break;
838     }
839 }
840 
clearImageOn_()841 static inline void clearImageOn_()
842 {
843     reg_G3X_DISP3DCNT |= REG_G3X_DISP3DCNT_PRI_MASK;
844 }
845 
clearImageOff_()846 static inline void clearImageOff_()
847 {
848     reg_G3X_DISP3DCNT &= ~REG_G3X_DISP3DCNT_PRI_MASK;
849 }
850 
851 
852 /*---------------------------------------------------------------------------*
853   Name:         GX_VRAMCNT_SetCLRIMG_ (internal use only)
854 
855   Description:  Assigns banks onto ClearImage.
856                 The banks are mapped onto the texture
857                 image slot #2, #3(clear image slot).
858                 This is called only by GX_SetBankForClearImage.
859 
860   Arguments:    clrImg:      Banks assigned to CLRIMG
861 
862   Returns:      None.
863  *---------------------------------------------------------------------------*/
GX_VRAMCNT_SetCLRIMG_(GXVRamClearImage clrImg)864 static inline void GX_VRAMCNT_SetCLRIMG_(GXVRamClearImage clrImg)
865 {
866     switch (clrImg)
867     {
868     case GX_VRAM_CLEARIMAGE_256_AB:
869         reg_GX_VRAMCNT_A = (u8)GX_VRAMCNT_A_TEX_2;
870         // don't break
871     case GX_VRAM_CLEARDEPTH_128_B:
872         reg_GX_VRAMCNT_B = (u8)GX_VRAMCNT_B_TEX_3;
873         clearImageOn_();
874         break;
875 
876     case GX_VRAM_CLEARIMAGE_256_CD:
877         reg_GX_VRAMCNT_C = (u8)GX_VRAMCNT_C_TEX_2;
878         // don't break
879     case GX_VRAM_CLEARDEPTH_128_D:
880         reg_GX_VRAMCNT_D = (u8)GX_VRAMCNT_D_TEX_3;
881         clearImageOn_();
882         break;
883 
884     case GX_VRAM_CLEARIMAGE_NONE:
885         clearImageOff_();
886         break;
887 
888     case GX_VRAM_CLEARDEPTH_128_A:
889         reg_GX_VRAMCNT_A = (u8)GX_VRAMCNT_A_TEX_3;
890         clearImageOn_();
891         break;
892 
893     case GX_VRAM_CLEARDEPTH_128_C:
894         reg_GX_VRAMCNT_C = (u8)GX_VRAMCNT_C_TEX_3;
895         clearImageOn_();
896         break;
897 
898     default:
899         SDK_INTERNAL_ERROR("unknown GXVRamClearImage, 0x%x specified.", clrImg);
900         break;
901     }
902 }
903 
904 
905 
906 /*---------------------------------------------------------------------------*
907   Name:         GX_VRAMCNT_SetTEXPLTT_ (internal use only)
908 
909   Description:  Assigns banks to the texture palette slots.
910                 The banks are mapped consecutively from the slot #0.
911                 This is called only by GX_SetBankForTexPltt.
912 
913   Arguments:    texPltt:       Banks assigned to the texture palette slots
914 
915   Returns:      None.
916  *---------------------------------------------------------------------------*/
GX_VRAMCNT_SetTEXPLTT_(GXVRamTexPltt texPltt)917 static inline void GX_VRAMCNT_SetTEXPLTT_(GXVRamTexPltt texPltt)
918 {
919     switch (texPltt)
920     {
921     case GX_VRAM_TEXPLTT_01_FG:
922         reg_GX_VRAMCNT_G = (u8)GX_VRAMCNT_G_TEXPLTT_1;
923         // don't break
924     case GX_VRAM_TEXPLTT_0_F:
925         reg_GX_VRAMCNT_F = (u8)GX_VRAMCNT_F_TEXPLTT_0;
926         break;
927 
928     case GX_VRAM_TEXPLTT_0_G:
929         reg_GX_VRAMCNT_G = (u8)GX_VRAMCNT_G_TEXPLTT_0;
930         break;
931 
932     case GX_VRAM_TEXPLTT_012345_EFG:
933         reg_GX_VRAMCNT_G = (u8)GX_VRAMCNT_G_TEXPLTT_5;
934         // don't break
935     case GX_VRAM_TEXPLTT_01234_EF:
936         reg_GX_VRAMCNT_F = (u8)GX_VRAMCNT_F_TEXPLTT_4;
937         // don't break
938     case GX_VRAM_TEXPLTT_0123_E:
939         reg_GX_VRAMCNT_E = (u8)GX_VRAMCNT_E_TEXPLTT_0123;
940         break;
941 
942     case GX_VRAM_TEXPLTT_NONE:
943         break;
944 
945     default:
946         SDK_INTERNAL_ERROR("unknown GXVRamTexPltt, 0x%x specified.", texPltt);
947         break;
948     }
949 }
950 
bgExtPlttOn_()951 static inline void bgExtPlttOn_()
952 {
953     reg_GX_DISPCNT |= REG_GX_DISPCNT_BG_MASK;
954 }
955 
bgExtPlttOff_()956 static inline void bgExtPlttOff_()
957 {
958     reg_GX_DISPCNT &= ~REG_GX_DISPCNT_BG_MASK;
959 }
960 
961 /*---------------------------------------------------------------------------*
962   Name:         GX_VRAMCNT_SetBGEXTPLTT_ (internal use only)
963 
964   Description:  Assigns banks to BG extended palettes.
965                 The banks are mapped consecutively from the slot #0 or #2.
966                 This is called only by GX_SetBankForBGExtPltt.
967 
968   Arguments:    bgExtPltt:     Banks assigned to the BG extended palettes
969 
970   Returns:      None.
971  *---------------------------------------------------------------------------*/
GX_VRAMCNT_SetBGEXTPLTT_(GXVRamBGExtPltt bgExtPltt)972 static inline void GX_VRAMCNT_SetBGEXTPLTT_(GXVRamBGExtPltt bgExtPltt)
973 {
974     switch (bgExtPltt)
975     {
976     case GX_VRAM_BGEXTPLTT_0123_E:
977         bgExtPlttOn_();
978         reg_GX_VRAMCNT_E = (u8)GX_VRAMCNT_E_BGEXTPLTT_0123;
979         break;
980 
981     case GX_VRAM_BGEXTPLTT_23_G:
982         bgExtPlttOn_();
983         reg_GX_VRAMCNT_G = (u8)GX_VRAMCNT_G_BGEXTPLTT_23;
984         break;
985 
986     case GX_VRAM_BGEXTPLTT_0123_FG:
987         reg_GX_VRAMCNT_G = (u8)GX_VRAMCNT_G_BGEXTPLTT_23;
988         // don't break
989     case GX_VRAM_BGEXTPLTT_01_F:
990         reg_GX_VRAMCNT_F = (u8)GX_VRAMCNT_F_BGEXTPLTT_01;
991         bgExtPlttOn_();
992         break;
993 
994     case GX_VRAM_BGEXTPLTT_NONE:
995         bgExtPlttOff_();
996         break;
997 
998     default:
999         SDK_INTERNAL_ERROR("unknown GXVRamBGExtPltt, 0x%x specified.", bgExtPltt);
1000         break;
1001     }
1002 }
1003 
objExtPlttOn_()1004 static inline void objExtPlttOn_()
1005 {
1006     reg_GX_DISPCNT |= REG_GX_DISPCNT_O_MASK;
1007 }
1008 
objExtPlttOff_()1009 static inline void objExtPlttOff_()
1010 {
1011     reg_GX_DISPCNT &= ~REG_GX_DISPCNT_O_MASK;
1012 }
1013 
1014 
1015 /*---------------------------------------------------------------------------*
1016   Name:         GX_VRAMCNT_SetOBJEXTPLTT_ (internal use only)
1017 
1018   Description:  Assigns a bank to OBJ extended palettes.
1019                 This is called only by GX_SetBankForOBJExtPltt.
1020 
1021   Arguments:    objExtPltt:     Banks assigned to the OBJ extended palettes
1022 
1023   Returns:      None.
1024  *---------------------------------------------------------------------------*/
GX_VRAMCNT_SetOBJEXTPLTT_(GXVRamOBJExtPltt objExtPltt)1025 static inline void GX_VRAMCNT_SetOBJEXTPLTT_(GXVRamOBJExtPltt objExtPltt)
1026 {
1027     switch (objExtPltt)
1028     {
1029     case GX_VRAM_OBJEXTPLTT_0_F:
1030         objExtPlttOn_();
1031         reg_GX_VRAMCNT_F = (u8)GX_VRAMCNT_F_OBJEXTPLTT;
1032         break;
1033 
1034     case GX_VRAM_OBJEXTPLTT_0_G:
1035         objExtPlttOn_();
1036         reg_GX_VRAMCNT_G = (u8)GX_VRAMCNT_G_OBJEXTPLTT;
1037         break;
1038 
1039     case GX_VRAM_OBJEXTPLTT_NONE:
1040         objExtPlttOff_();
1041         break;
1042 
1043     default:
1044         SDK_INTERNAL_ERROR("unknown GXVRamOBJExtPltt, 0x%x specified.", objExtPltt);
1045         break;
1046     }
1047 }
1048 
1049 
1050 /*---------------------------------------------------------------------------*
1051   Name:         GX_VRAMCNT_SetSubBG_ (internal use only)
1052 
1053   Description:  Assigns a bank to sub 2D engine's BG.
1054                 This is called only by GX_SetBankForSubBG.
1055 
1056   Arguments:    bg:     Banks assigned to sub 2D engine's BG
1057 
1058   Returns:      None.
1059  *---------------------------------------------------------------------------*/
GX_VRAMCNT_SetSubBG_(GXVRamSubBG bg)1060 static inline void GX_VRAMCNT_SetSubBG_(GXVRamSubBG bg)
1061 {
1062     switch (bg)
1063     {
1064     case GX_VRAM_SUB_BG_128_C:
1065         reg_GX_VRAMCNT_C = GX_VRAMCNT_C_SUBBG_0x06200000;
1066         break;
1067 
1068     case GX_VRAM_SUB_BG_48_HI:
1069         reg_GX_VRAMCNT_I = GX_VRAMCNT_I_SUBBG_0x06208000;
1070         // don't break
1071     case GX_VRAM_SUB_BG_32_H:
1072         reg_GX_VRAMCNT_H = GX_VRAMCNT_H_SUBBG_0x06200000;
1073         break;
1074 
1075     case GX_VRAM_SUB_BG_NONE:
1076         break;
1077 
1078     default:
1079         SDK_INTERNAL_ERROR("unknown GXVRamSubBG, 0x%x specified.", bg);
1080         break;
1081     }
1082 }
1083 
1084 
1085 /*---------------------------------------------------------------------------*
1086   Name:         GX_VRAMCNT_SetSubOBJ_ (internal use only)
1087 
1088   Description:  Assigns a bank to sub 2D engine's OBJ.
1089                 This is called only by GX_SetBankForSubOBJ.
1090 
1091   Arguments:    obj:     Banks assigned to sub 2D engine's OBJ
1092 
1093   Returns:      None.
1094  *---------------------------------------------------------------------------*/
GX_VRAMCNT_SetSubOBJ_(GXVRamSubOBJ obj)1095 static inline void GX_VRAMCNT_SetSubOBJ_(GXVRamSubOBJ obj)
1096 {
1097     switch (obj)
1098     {
1099     case GX_VRAM_SUB_OBJ_128_D:
1100         reg_GX_VRAMCNT_D = GX_VRAMCNT_D_SUBOBJ_0x06600000;
1101         break;
1102 
1103     case GX_VRAM_SUB_OBJ_16_I:
1104         reg_GX_VRAMCNT_I = GX_VRAMCNT_I_SUBOBJ_0x06600000;
1105         break;
1106 
1107     case GX_VRAM_SUB_OBJ_NONE:
1108         break;
1109 
1110     default:
1111         SDK_INTERNAL_ERROR("unknown GXVRamSubOBJ, 0x%x specified.", obj);
1112         break;
1113     }
1114 }
1115 
subBGExtPlttOn_()1116 static inline void subBGExtPlttOn_()
1117 {
1118     reg_GXS_DB_DISPCNT |= REG_GXS_DB_DISPCNT_BG_MASK;
1119 }
1120 
subBGExtPlttOff_()1121 static inline void subBGExtPlttOff_()
1122 {
1123     reg_GXS_DB_DISPCNT &= ~REG_GXS_DB_DISPCNT_BG_MASK;
1124 }
1125 
1126 
1127 /*---------------------------------------------------------------------------*
1128   Name:         GX_VRAMCNT_SetSubBGExtPltt_ (internal use only)
1129 
1130   Description:  Assigns a bank to sub 2D engine's BGExtPltt.
1131                 This is called only by GX_SetBankForSubBGExtPltt.
1132 
1133   Arguments:    bgExtPltt:     Banks assigned to sub 2D engine's BGExtPltt
1134 
1135   Returns:      None.
1136  *---------------------------------------------------------------------------*/
GX_VRAMCNT_SetSubBGExtPltt_(GXVRamSubBGExtPltt bgExtPltt)1137 static inline void GX_VRAMCNT_SetSubBGExtPltt_(GXVRamSubBGExtPltt bgExtPltt)
1138 {
1139     switch (bgExtPltt)
1140     {
1141     case GX_VRAM_SUB_BGEXTPLTT_0123_H:
1142         subBGExtPlttOn_();
1143         reg_GX_VRAMCNT_H = GX_VRAMCNT_H_SUBBGEXTPLTT_0123;
1144         break;
1145 
1146     case GX_VRAM_SUB_BGEXTPLTT_NONE:
1147         subBGExtPlttOff_();
1148         break;
1149 
1150     default:
1151         SDK_INTERNAL_ERROR("unknown GXVRamSubBGExtPltt, 0x%x specified.", bgExtPltt);
1152         break;
1153     }
1154 }
1155 
subOBJExtPlttOn_()1156 static inline void subOBJExtPlttOn_()
1157 {
1158     reg_GXS_DB_DISPCNT |= REG_GXS_DB_DISPCNT_O_MASK;
1159 }
1160 
subOBJExtPlttOff_()1161 static inline void subOBJExtPlttOff_()
1162 {
1163     reg_GXS_DB_DISPCNT &= ~REG_GXS_DB_DISPCNT_O_MASK;
1164 }
1165 
1166 
1167 /*---------------------------------------------------------------------------*
1168   Name:         GX_VRAMCNT_SetSubOBJExtPltt_ (internal use only)
1169 
1170   Description:  Assigns a bank to sub 2D engine's OBJExtPltt.
1171                 This is called only by GX_SetBankForSubOBJExtPltt.
1172 
1173   Arguments:    objExtPltt:     Banks assigned to sub 2D engine's OBJExtPltt
1174 
1175   Returns:      None.
1176  *---------------------------------------------------------------------------*/
GX_VRAMCNT_SetSubOBJExtPltt_(GXVRamSubOBJExtPltt objExtPltt)1177 static inline void GX_VRAMCNT_SetSubOBJExtPltt_(GXVRamSubOBJExtPltt objExtPltt)
1178 {
1179     switch (objExtPltt)
1180     {
1181     case GX_VRAM_SUB_OBJEXTPLTT_0_I:
1182         subOBJExtPlttOn_();
1183         reg_GX_VRAMCNT_I = GX_VRAMCNT_I_SUBOBJEXTPLTT;
1184         break;
1185 
1186     case GX_VRAM_SUB_OBJEXTPLTT_NONE:
1187         subOBJExtPlttOff_();
1188         break;
1189     }
1190 }
1191 
1192 extern vu16 GXi_VRamLockId;
1193 /*---------------------------------------------------------------------------*
1194   Name:         GxCheckExclusive
1195 
1196   Description:  Sets an exclusive lock on VRAM when banks are swapped.
1197                 If an exclusive lock has already been set by other library, we should wait for it to be released in order to be proper, but instead we panic here.
1198 
1199 
1200   Arguments:    vramMap -   Logical OR of bank IDs for the group of exclusively locked VRAMs.
1201 
1202   Returns:      None.
1203  *---------------------------------------------------------------------------*/
GxCheckExclusive(u16 vramMap)1204 static void GxCheckExclusive(u16 vramMap)
1205 {
1206     if (!OSi_TryLockVram(vramMap, GXi_VRamLockId))
1207     {
1208         OS_Panic("VRAM bank is locked by another library.\n");
1209     }
1210 }
1211 
1212 //----------------------------------------------------------------------------
1213 // GX_SetBankForX:
1214 //
1215 // 1 Error checking of arg.
1216 // 2 Sets the state for LCDC((LCDC | X) & ~arg).
1217 // 3 Sets the state for X(arg).
1218 // 4 Checks conflicts with other regions.
1219 // 5 Write VRAMCNTs for LCDC.
1220 // 6 Write VRAMCNTs for X.
1221 //----------------------------------------------------------------------------
1222 
1223 
1224 /*---------------------------------------------------------------------------*/
GxSetBankForBG(GXVRamBG bg)1225 static inline void GxSetBankForBG(GXVRamBG bg)
1226 {
1227     // Check parameter
1228     GX_VRAM_BG_ASSERT(bg);
1229     // Change BG banks and LCDC ones.
1230     gGXState.vramCnt.lcdc = (u16)(~bg & (gGXState.vramCnt.lcdc | gGXState.vramCnt.bg));
1231     gGXState.vramCnt.bg = bg;
1232     // Check conflicts( DEBUG build ).
1233     GX_StateCheck_VRAMCnt();
1234     // Switch VRAM banks.
1235     GX_VRAMCNT_SetBG_(bg);
1236     GX_VRAMCNT_SetLCDC_(gGXState.vramCnt.lcdc);
1237 }
1238 
1239 /*---------------------------------------------------------------------------*
1240   Name:         GX_SetBankForBG
1241 
1242   Description:  Assigns banks onto BG.
1243                 The specified banks must be disabled or mapped to LCDC.
1244 
1245   Arguments:    bg:         Banks to be assigned to BG
1246 
1247   Returns:      None.
1248  *---------------------------------------------------------------------------*/
GX_SetBankForBG(GXVRamBG bg)1249 void GX_SetBankForBG(GXVRamBG bg)
1250 {
1251 #ifndef SDK_FINALROM
1252     GxCheckExclusive((u16)bg);
1253 #endif
1254     GxSetBankForBG(bg);
1255 }
1256 
1257 /*---------------------------------------------------------------------------*
1258   Name:         GX_TrySetBankForBG
1259 
1260   Description:  Try to assign banks onto BG.
1261                 The specified banks must be disabled or mapped to LCDC.
1262 
1263   Arguments:    bg:         Banks to be assigned to BG
1264 
1265   Returns:      BOOL.       If VRAM banks could not be locked, return FALSE.
1266  *---------------------------------------------------------------------------*/
GX_TrySetBankForBG(GXVRamBG bg)1267 BOOL GX_TrySetBankForBG(GXVRamBG bg)
1268 {
1269     if (!OSi_TryLockVram((u16)bg, GXi_VRamLockId))
1270     {
1271         return FALSE;
1272     }
1273     GxSetBankForBG(bg);
1274     return TRUE;
1275 }
1276 
1277 /*---------------------------------------------------------------------------*/
1278 /*
1279  * Although we want to strive for even small speed increases through inlining, if this function is declared inline the CW compiler will internally make three separate inline functions, which increases the function call overhead even more.
1280  *
1281  *
1282  * For this reason, as of 2005/02/15 this function has been defined as a real function.
1283  */
GxSetBankForBGEx(GXVRamBG bg1,GXVRamBG bg2)1284 static void GxSetBankForBGEx(GXVRamBG bg1, GXVRamBG bg2)
1285 {
1286     // Check parameter validity
1287     GX_VRAM_BG_ASSERT_EX_1(bg1);
1288     GX_VRAM_BG_ASSERT_EX_2(bg2);
1289     // Change BG banks and LCDC ones.
1290     gGXState.vramCnt.lcdc = (u16)(~(bg1 | bg2) & (gGXState.vramCnt.lcdc | gGXState.vramCnt.bg));
1291     gGXState.vramCnt.bg = (u16)(bg1 | bg2);
1292     // Check conflicts( DEBUG build ).
1293     GX_StateCheck_VRAMCnt();
1294     // Switch VRAM banks
1295     GX_VRAMCNT_SetBGEx1_(bg1);
1296     GX_VRAMCNT_SetBGEx2_(bg2);
1297     GX_VRAMCNT_SetLCDC_(gGXState.vramCnt.lcdc);
1298 }
1299 
1300 /*---------------------------------------------------------------------------*
1301   Name:         GX_SetBankForBGEx
1302 
1303   Description:  Assigns banks onto BG.
1304                 The specified banks must be disabled or mapped to LCDC.
1305 
1306   Arguments:    bg1:         Banks to be assigned to BG ( only bank EFG )
1307                 bg2:         Banks to be assigned to BG ( only bank ABCD )
1308 
1309   Returns:      None.
1310  *---------------------------------------------------------------------------*/
GX_SetBankForBGEx(GXVRamBG bg1,GXVRamBG bg2)1311 void GX_SetBankForBGEx(GXVRamBG bg1, GXVRamBG bg2)
1312 {
1313 #ifndef SDK_FINALROM
1314     GxCheckExclusive((u16)(bg1 | bg2));
1315 #endif
1316     GxSetBankForBGEx(bg1, bg2);
1317 }
1318 
1319 /*---------------------------------------------------------------------------*
1320   Name:         GX_TrySetBankForBGEx
1321 
1322   Description:  Try to assign banks onto BG.
1323                 The specified banks must be disabled or mapped to LCDC.
1324 
1325   Arguments:    bg1:         Banks to be assigned to BG ( only bank EFG )
1326                 bg2:         Banks to be assigned to BG ( only bank ABCD )
1327 
1328   Returns:      BOOL.       If VRAM banks could not be locked, return FALSE.
1329  *---------------------------------------------------------------------------*/
GX_TrySetBankForBGEx(GXVRamBG bg1,GXVRamBG bg2)1330 BOOL GX_TrySetBankForBGEx(GXVRamBG bg1, GXVRamBG bg2)
1331 {
1332     if (!OSi_TryLockVram((u16)(bg1 | bg2), GXi_VRamLockId))
1333     {
1334         return FALSE;
1335     }
1336     GxSetBankForBGEx(bg1, bg2);
1337     return TRUE;
1338 }
1339 
1340 /*---------------------------------------------------------------------------*/
GxSetBankForOBJ(GXVRamOBJ obj)1341 static inline void GxSetBankForOBJ(GXVRamOBJ obj)
1342 {
1343     // Check parameter validity
1344     GX_VRAM_OBJ_ASSERT(obj);
1345     // Change BG banks and LCDC ones.
1346     gGXState.vramCnt.lcdc = (u16)(~obj & (gGXState.vramCnt.lcdc | gGXState.vramCnt.obj));
1347     gGXState.vramCnt.obj = obj;
1348     // Check conflicts( DEBUG build ).
1349     GX_StateCheck_VRAMCnt();
1350     // Switch VRAM banks
1351     GX_VRAMCNT_SetOBJ_(obj);
1352     GX_VRAMCNT_SetLCDC_(gGXState.vramCnt.lcdc);
1353 }
1354 
1355 /*---------------------------------------------------------------------------*
1356   Name:         GX_SetBankForOBJ
1357 
1358   Description:  Assigns banks onto OBJ.
1359                 The specified banks must be disabled or mapped to LCDC.
1360 
1361   Arguments:    obj:         Banks to be assigned to OBJ
1362 
1363   Returns:      None.
1364  *---------------------------------------------------------------------------*/
GX_SetBankForOBJ(GXVRamOBJ obj)1365 void GX_SetBankForOBJ(GXVRamOBJ obj)
1366 {
1367 #ifndef SDK_FINALROM
1368     GxCheckExclusive((u16)obj);
1369 #endif
1370     GxSetBankForOBJ(obj);
1371 }
1372 
1373 /*---------------------------------------------------------------------------*
1374   Name:         GX_TrySetBankForOBJ
1375 
1376   Description:  Try to assign banks onto OBJ.
1377                 The specified banks must be disabled or mapped to LCDC.
1378 
1379   Arguments:    obj:         Banks to be assigned to OBJ
1380 
1381   Returns:      BOOL.       If VRAM banks could not be locked, return FALSE.
1382  *---------------------------------------------------------------------------*/
GX_TrySetBankForOBJ(GXVRamOBJ obj)1383 BOOL GX_TrySetBankForOBJ(GXVRamOBJ obj)
1384 {
1385     if (!OSi_TryLockVram((u16)obj, GXi_VRamLockId))
1386     {
1387         return FALSE;
1388     }
1389     GxSetBankForOBJ(obj);
1390     return TRUE;
1391 }
1392 
1393 /*---------------------------------------------------------------------------*/
GxSetBankForBGExtPltt(GXVRamBGExtPltt bgExtPltt)1394 static inline void GxSetBankForBGExtPltt(GXVRamBGExtPltt bgExtPltt)
1395 {
1396     // Check parameter validity
1397     GX_VRAM_BGEXTPLTT_ASSERT(bgExtPltt);
1398     // Change BG banks and LCDC ones.
1399     gGXState.vramCnt.lcdc =
1400         (u16)(~bgExtPltt & (gGXState.vramCnt.lcdc | gGXState.vramCnt.bgExtPltt));
1401     gGXState.vramCnt.bgExtPltt = bgExtPltt;
1402     // Check conflicts( DEBUG build ).
1403     GX_StateCheck_VRAMCnt();
1404     // Switch VRAM banks
1405     GX_VRAMCNT_SetBGEXTPLTT_(bgExtPltt);
1406     GX_VRAMCNT_SetLCDC_(gGXState.vramCnt.lcdc);
1407 }
1408 
1409 /*---------------------------------------------------------------------------*
1410   Name:         GX_SetBankForBGExtPltt
1411 
1412   Description:  Assigns banks onto BGExtPltt.
1413                 The specified banks must be disabled or mapped to LCDC.
1414 
1415   Arguments:    bgExtPltt:         Banks to be assigned to bgExtPltt
1416 
1417   Returns:      None.
1418  *---------------------------------------------------------------------------*/
GX_SetBankForBGExtPltt(GXVRamBGExtPltt bgExtPltt)1419 void GX_SetBankForBGExtPltt(GXVRamBGExtPltt bgExtPltt)
1420 {
1421 #ifndef SDK_FINALROM
1422     GxCheckExclusive((u16)bgExtPltt);
1423 #endif
1424     GxSetBankForBGExtPltt(bgExtPltt);
1425 }
1426 
1427 /*---------------------------------------------------------------------------*
1428   Name:         GX_TrySetBankForBGExtPltt
1429 
1430   Description:  Try to assign banks onto BGExtPltt.
1431                 The specified banks must be disabled or mapped to LCDC.
1432 
1433   Arguments:    bgExtPltt:         Banks to be assigned to bgExtPltt
1434 
1435   Returns:      BOOL.       If VRAM banks could not be locked, return FALSE.
1436  *---------------------------------------------------------------------------*/
GX_TrySetBankForBGExtPltt(GXVRamBGExtPltt bgExtPltt)1437 BOOL GX_TrySetBankForBGExtPltt(GXVRamBGExtPltt bgExtPltt)
1438 {
1439     if (!OSi_TryLockVram((u16)bgExtPltt, GXi_VRamLockId))
1440     {
1441         return FALSE;
1442     }
1443     GxSetBankForBGExtPltt(bgExtPltt);
1444     return TRUE;
1445 }
1446 
1447 /*---------------------------------------------------------------------------*/
GxSetBankForOBJExtPltt(GXVRamOBJExtPltt objExtPltt)1448 static inline void GxSetBankForOBJExtPltt(GXVRamOBJExtPltt objExtPltt)
1449 {
1450     // Check parameter validity
1451     GX_VRAM_OBJEXTPLTT_ASSERT(objExtPltt);
1452     // Change BG banks and LCDC ones.
1453     gGXState.vramCnt.lcdc =
1454         (u16)(~objExtPltt & (gGXState.vramCnt.lcdc | gGXState.vramCnt.objExtPltt));
1455     gGXState.vramCnt.objExtPltt = objExtPltt;
1456     // Check conflicts( DEBUG build ).
1457     GX_StateCheck_VRAMCnt();
1458     // Switch VRAM banks
1459     GX_VRAMCNT_SetOBJEXTPLTT_(objExtPltt);
1460     GX_VRAMCNT_SetLCDC_(gGXState.vramCnt.lcdc);
1461 }
1462 
1463 /*---------------------------------------------------------------------------*
1464   Name:         GX_SetBankForOBJExtPltt
1465 
1466   Description:  Assigns banks onto OBJExtPltt.
1467                 The specified banks must be disabled or mapped to LCDC.
1468 
1469   Arguments:    objExtPltt:         Banks to be assigned to objExtPltt
1470 
1471   Returns:      None.
1472  *---------------------------------------------------------------------------*/
GX_SetBankForOBJExtPltt(GXVRamOBJExtPltt objExtPltt)1473 void GX_SetBankForOBJExtPltt(GXVRamOBJExtPltt objExtPltt)
1474 {
1475 #ifndef SDK_FINALROM
1476     GxCheckExclusive((u16)objExtPltt);
1477 #endif
1478     GxSetBankForOBJExtPltt(objExtPltt);
1479 }
1480 
1481 /*---------------------------------------------------------------------------*
1482   Name:         GX_TrySetBankForOBJExtPltt
1483 
1484   Description:  Try to assign banks onto OBJExtPltt.
1485                 The specified banks must be disabled or mapped to LCDC.
1486 
1487   Arguments:    objExtPltt:         Banks to be assigned to objExtPltt
1488 
1489   Returns:      BOOL.       If VRAM banks could not be locked, return FALSE.
1490  *---------------------------------------------------------------------------*/
GX_TrySetBankForOBJExtPltt(GXVRamOBJExtPltt objExtPltt)1491 BOOL GX_TrySetBankForOBJExtPltt(GXVRamOBJExtPltt objExtPltt)
1492 {
1493     if (!OSi_TryLockVram((u16)objExtPltt, GXi_VRamLockId))
1494     {
1495         return FALSE;
1496     }
1497     GxSetBankForOBJExtPltt(objExtPltt);
1498     return TRUE;
1499 }
1500 
1501 /*---------------------------------------------------------------------------*/
GxSetBankForTex(GXVRamTex tex)1502 static inline void GxSetBankForTex(GXVRamTex tex)
1503 {
1504     // Check parameter validity
1505     GX_VRAM_TEX_ASSERT(tex);
1506     // Change BG banks and LCDC ones.
1507     gGXState.vramCnt.lcdc = (u16)(~tex & (gGXState.vramCnt.lcdc | gGXState.vramCnt.tex));
1508     gGXState.vramCnt.tex = tex;
1509     // Check conflicts( DEBUG build ).
1510     GX_StateCheck_VRAMCnt();
1511     // Switch VRAM banks
1512     GX_VRAMCNT_SetTEX_(tex);
1513     GX_VRAMCNT_SetLCDC_(gGXState.vramCnt.lcdc);
1514 }
1515 
1516 /*---------------------------------------------------------------------------*
1517   Name:         GX_SetBankForTex
1518 
1519   Description:  Assigns banks onto texture image slots.
1520                 The specified banks must be disabled or mapped to LCDC.
1521 
1522   Arguments:    tex:         Banks to be assigned to texture image slots
1523 
1524   Returns:      None.
1525  *---------------------------------------------------------------------------*/
GX_SetBankForTex(GXVRamTex tex)1526 void GX_SetBankForTex(GXVRamTex tex)
1527 {
1528 #ifndef SDK_FINALROM
1529     GxCheckExclusive((u16)tex);
1530 #endif
1531     GxSetBankForTex(tex);
1532 }
1533 
1534 /*---------------------------------------------------------------------------*
1535   Name:         GX_TrySetBankForTex
1536 
1537   Description:  Try to assign banks onto texture image slots.
1538                 The specified banks must be disabled or mapped to LCDC.
1539 
1540   Arguments:    tex:         Banks to be assigned to texture image slots
1541 
1542   Returns:      BOOL.       If VRAM banks could not be locked, return FALSE.
1543  *---------------------------------------------------------------------------*/
GX_TrySetBankForTex(GXVRamTex tex)1544 BOOL GX_TrySetBankForTex(GXVRamTex tex)
1545 {
1546     if (!OSi_TryLockVram((u16)tex, GXi_VRamLockId))
1547     {
1548         return FALSE;
1549     }
1550     GxSetBankForTex(tex);
1551     return TRUE;
1552 }
1553 
1554 /*---------------------------------------------------------------------------*/
GxSetBankForTexPltt(GXVRamTexPltt texPltt)1555 static inline void GxSetBankForTexPltt(GXVRamTexPltt texPltt)
1556 {
1557     // Check parameter validity
1558     GX_VRAM_TEXPLTT_ASSERT(texPltt);
1559     // Change BG banks and LCDC ones.
1560     gGXState.vramCnt.lcdc = (u16)(~texPltt & (gGXState.vramCnt.lcdc | gGXState.vramCnt.texPltt));
1561     gGXState.vramCnt.texPltt = texPltt;
1562     // Check conflicts( DEBUG build ).
1563     GX_StateCheck_VRAMCnt();
1564     // Switch VRAM banks
1565     GX_VRAMCNT_SetTEXPLTT_(texPltt);
1566     GX_VRAMCNT_SetLCDC_(gGXState.vramCnt.lcdc);
1567 }
1568 
1569 /*---------------------------------------------------------------------------*
1570   Name:         GX_SetBankForTexPltt
1571 
1572   Description:  Assigns banks onto texture palette slots.
1573                 The specified banks must be disabled or mapped to LCDC.
1574 
1575   Arguments:    texPltt:     Banks to be assigned to texture palette slots
1576 
1577   Returns:      None.
1578  *---------------------------------------------------------------------------*/
GX_SetBankForTexPltt(GXVRamTexPltt texPltt)1579 void GX_SetBankForTexPltt(GXVRamTexPltt texPltt)
1580 {
1581 #ifndef SDK_FINALROM
1582     GxCheckExclusive((u16)texPltt);
1583 #endif
1584     GxSetBankForTexPltt(texPltt);
1585 }
1586 
1587 /*---------------------------------------------------------------------------*
1588   Name:         GX_TrySetBankForTexPltt
1589 
1590   Description:  Try to assign banks onto texture palette slots.
1591                 The specified banks must be disabled or mapped to LCDC.
1592 
1593   Arguments:    texPltt:     Banks to be assigned to texture palette slots
1594 
1595   Returns:      BOOL.       If VRAM banks could not be locked, return FALSE.
1596  *---------------------------------------------------------------------------*/
GX_TrySetBankForTexPltt(GXVRamTexPltt texPltt)1597 BOOL GX_TrySetBankForTexPltt(GXVRamTexPltt texPltt)
1598 {
1599     if (!OSi_TryLockVram((u16)texPltt, GXi_VRamLockId))
1600     {
1601         return FALSE;
1602     }
1603     GxSetBankForTexPltt(texPltt);
1604     return TRUE;
1605 }
1606 
1607 /*---------------------------------------------------------------------------*/
GxSetBankForClearImage(GXVRamClearImage clrImg)1608 static inline void GxSetBankForClearImage(GXVRamClearImage clrImg)
1609 {
1610     // Check parameter validity
1611     GX_VRAM_CLRIMG_ASSERT(clrImg);
1612     // Change BG banks and LCDC ones.
1613     gGXState.vramCnt.lcdc = (u16)(~clrImg & (gGXState.vramCnt.lcdc | gGXState.vramCnt.clrImg));
1614     gGXState.vramCnt.clrImg = clrImg;
1615     // Check conflicts( DEBUG build ).
1616     GX_StateCheck_VRAMCnt();
1617     // Switch VRAM banks
1618     GX_VRAMCNT_SetCLRIMG_(clrImg);
1619     GX_VRAMCNT_SetLCDC_(gGXState.vramCnt.lcdc);
1620 }
1621 
1622 /*---------------------------------------------------------------------------*
1623   Name:         GX_SetBankForClearImage
1624 
1625   Description:  Assigns banks onto clear image slots(texture image slot #2,#3).
1626                 The specified banks must be disabled or mapped to LCDC.
1627 
1628   Arguments:    clrImg:       Banks to be assigned to clear image slots
1629 
1630   Returns:      None.
1631  *---------------------------------------------------------------------------*/
GX_SetBankForClearImage(GXVRamClearImage clrImg)1632 void GX_SetBankForClearImage(GXVRamClearImage clrImg)
1633 {
1634 #ifndef SDK_FINALROM
1635     GxCheckExclusive((u16)clrImg);
1636 #endif
1637     GxSetBankForClearImage(clrImg);
1638 }
1639 
1640 /*---------------------------------------------------------------------------*
1641   Name:         GX_TrySetBankForClearImage
1642 
1643   Description:  Try to assign banks onto clear image slots(texture image slot #2,#3).
1644                 The specified banks must be disabled or mapped to LCDC.
1645 
1646   Arguments:    clrImg:       Banks to be assigned to clear image slots
1647 
1648   Returns:      BOOL.       If VRAM banks could not be locked, return FALSE.
1649  *---------------------------------------------------------------------------*/
GX_TrySetBankForClearImage(GXVRamClearImage clrImg)1650 BOOL GX_TrySetBankForClearImage(GXVRamClearImage clrImg)
1651 {
1652     if (!OSi_TryLockVram((u16)clrImg, GXi_VRamLockId))
1653     {
1654         return FALSE;
1655     }
1656     GxSetBankForClearImage(clrImg);
1657     return TRUE;
1658 }
1659 
1660 /*---------------------------------------------------------------------------*/
GxSetBankForARM7(GXVRamARM7 arm7)1661 static inline void GxSetBankForARM7(GXVRamARM7 arm7)
1662 {
1663     // Check parameter validity
1664     GX_VRAM_ARM7_ASSERT(arm7);
1665     // Change BG banks and LCDC ones.
1666     gGXState.vramCnt.lcdc = (u16)(~arm7 & (gGXState.vramCnt.lcdc | gGXState.vramCnt.arm7));
1667     gGXState.vramCnt.arm7 = arm7;
1668     // Check conflicts( DEBUG build ).
1669     GX_StateCheck_VRAMCnt();
1670     // Switch VRAM banks
1671     GX_VRAMCNT_SetARM7_(arm7);
1672     GX_VRAMCNT_SetLCDC_(gGXState.vramCnt.lcdc);
1673 }
1674 
1675 /*---------------------------------------------------------------------------*
1676   Name:         GX_SetBankForARM7
1677 
1678   Description:  Assigns banks onto ARM7 memory space.
1679                 The specified banks must be disabled or mapped to LCDC.
1680 
1681   Arguments:    arm7:     Banks to be assigned to ARM7 memory space
1682 
1683   Returns:      None.
1684  *---------------------------------------------------------------------------*/
GX_SetBankForARM7(GXVRamARM7 arm7)1685 void GX_SetBankForARM7(GXVRamARM7 arm7)
1686 {
1687 #ifndef SDK_FINALROM
1688     GxCheckExclusive((u16)arm7);
1689 #endif
1690     GxSetBankForARM7(arm7);
1691 }
1692 
1693 /*---------------------------------------------------------------------------*
1694   Name:         GX_TrySetBankForARM7
1695 
1696   Description:  Try to assign banks onto ARM7 memory space.
1697                 The specified banks must be disabled or mapped to LCDC.
1698 
1699   Arguments:    arm7:     Banks to be assigned to ARM7 memory space
1700 
1701   Returns:      BOOL.       If VRAM banks could not be locked, return FALSE.
1702  *---------------------------------------------------------------------------*/
GX_TrySetBankForARM7(GXVRamARM7 arm7)1703 BOOL GX_TrySetBankForARM7(GXVRamARM7 arm7)
1704 {
1705     if (!OSi_TryLockVram((u16)arm7, GXi_VRamLockId))
1706     {
1707         return FALSE;
1708     }
1709     GxSetBankForARM7(arm7);
1710     return TRUE;
1711 }
1712 
1713 /*---------------------------------------------------------------------------*/
GxSetBankForLCDC(int lcdc)1714 static inline void GxSetBankForLCDC(int lcdc)
1715 {
1716     // Check parameter validity
1717     GX_VRAM_LCDC_ASSERT(lcdc);
1718     // Change BG banks and LCDC ones.
1719     gGXState.vramCnt.lcdc |= lcdc;
1720     // Check conflicts( DEBUG build ).
1721     GX_StateCheck_VRAMCnt();
1722     // Switch VRAM banks
1723     GX_VRAMCNT_SetLCDC_(lcdc);
1724 }
1725 
1726 /*---------------------------------------------------------------------------*
1727   Name:         GX_SetBankForLCDC
1728 
1729   Description:  Assigns banks onto LCDC memory space.
1730                 The specified banks must be disabled or mapped to LCDC.
1731 
1732   Arguments:    lcdc:     Banks to be assigned to LCDC memory space
1733 
1734   Returns:      None.
1735  *---------------------------------------------------------------------------*/
GX_SetBankForLCDC(int lcdc)1736 void GX_SetBankForLCDC(int lcdc)
1737 {
1738 #ifndef SDK_FINALROM
1739     GxCheckExclusive((u16)lcdc);
1740 #endif
1741     GxSetBankForLCDC(lcdc);
1742 }
1743 
1744 /*---------------------------------------------------------------------------*
1745   Name:         GX_TrySetBankForLCDC
1746 
1747   Description:  Try to assign banks onto LCDC memory space.
1748                 The specified banks must be disabled or mapped to LCDC.
1749 
1750   Arguments:    lcdc:     Banks to be assigned to LCDC memory space
1751 
1752   Returns:      BOOL.       If VRAM banks could not be locked, return FALSE.
1753  *---------------------------------------------------------------------------*/
GX_TrySetBankForLCDC(int lcdc)1754 BOOL GX_TrySetBankForLCDC(int lcdc)
1755 {
1756     if (!OSi_TryLockVram((u16)lcdc, GXi_VRamLockId))
1757     {
1758         return FALSE;
1759     }
1760     GxSetBankForLCDC(lcdc);
1761     return TRUE;
1762 }
1763 
1764 /*---------------------------------------------------------------------------*/
GxSetBankForSubBG(GXVRamSubBG sub_bg)1765 static inline void GxSetBankForSubBG(GXVRamSubBG sub_bg)
1766 {
1767     // Check parameter validity
1768     GX_VRAM_SUB_BG_ASSERT(sub_bg);
1769     // Change BG banks and LCDC ones.
1770     gGXState.vramCnt.lcdc = (u16)(~sub_bg & (gGXState.vramCnt.lcdc | gGXState.vramCnt.sub_bg));
1771     gGXState.vramCnt.sub_bg = sub_bg;
1772     // Check conflicts( DEBUG build ).
1773     GX_StateCheck_VRAMCnt();
1774     // Switch VRAM banks
1775     GX_VRAMCNT_SetSubBG_(sub_bg);
1776     GX_VRAMCNT_SetLCDC_(gGXState.vramCnt.lcdc);
1777 }
1778 
1779 /*---------------------------------------------------------------------------*
1780   Name:         GX_SetBankForSubBG
1781 
1782   Description:  Assigns banks onto sub engine's BG.
1783                 The specified banks must be disabled or mapped to LCDC.
1784 
1785   Arguments:    sub_bg:     Banks to be assigned to sub engine's BG
1786 
1787   Returns:      None.
1788  *---------------------------------------------------------------------------*/
GX_SetBankForSubBG(GXVRamSubBG sub_bg)1789 void GX_SetBankForSubBG(GXVRamSubBG sub_bg)
1790 {
1791 #ifndef SDK_FINALROM
1792     GxCheckExclusive((u16)sub_bg);
1793 #endif
1794     GxSetBankForSubBG(sub_bg);
1795 }
1796 
1797 /*---------------------------------------------------------------------------*
1798   Name:         GX_TrySetBankForSubBG
1799 
1800   Description:  Try to assign banks onto sub engine's BG.
1801                 The specified banks must be disabled or mapped to LCDC.
1802 
1803   Arguments:    sub_bg:     Banks to be assigned to sub engine's BG
1804 
1805   Returns:      BOOL.       If VRAM banks could not be locked, return FALSE.
1806  *---------------------------------------------------------------------------*/
GX_TrySetBankForSubBG(GXVRamSubBG sub_bg)1807 BOOL GX_TrySetBankForSubBG(GXVRamSubBG sub_bg)
1808 {
1809     if (!OSi_TryLockVram((u16)sub_bg, GXi_VRamLockId))
1810     {
1811         return FALSE;
1812     }
1813     GxSetBankForSubBG(sub_bg);
1814     return TRUE;
1815 }
1816 
1817 /*---------------------------------------------------------------------------*/
GxSetBankForSubOBJ(GXVRamSubOBJ sub_obj)1818 static inline void GxSetBankForSubOBJ(GXVRamSubOBJ sub_obj)
1819 {
1820     // Check parameter validity
1821     GX_VRAM_SUB_OBJ_ASSERT(sub_obj);
1822     // Change BG banks and LCDC ones.
1823     gGXState.vramCnt.lcdc = (u16)(~sub_obj & (gGXState.vramCnt.lcdc | gGXState.vramCnt.sub_obj));
1824     gGXState.vramCnt.sub_obj = sub_obj;
1825     // Check conflicts( DEBUG build ).
1826     GX_StateCheck_VRAMCnt();
1827     // Switch VRAM banks
1828     GX_VRAMCNT_SetSubOBJ_(sub_obj);
1829     GX_VRAMCNT_SetLCDC_(gGXState.vramCnt.lcdc);
1830 }
1831 
1832 /*---------------------------------------------------------------------------*
1833   Name:         GX_SetBankForSubOBJ
1834 
1835   Description:  Assigns banks onto sub engine's OBJ.
1836                 The specified banks must be disabled or mapped to LCDC.
1837 
1838   Arguments:    sub_obj:     Banks to be assigned to sub engine's OBJ
1839 
1840   Returns:      None.
1841  *---------------------------------------------------------------------------*/
GX_SetBankForSubOBJ(GXVRamSubOBJ sub_obj)1842 void GX_SetBankForSubOBJ(GXVRamSubOBJ sub_obj)
1843 {
1844 #ifndef SDK_FINALROM
1845     GxCheckExclusive((u16)sub_obj);
1846 #endif
1847     GxSetBankForSubOBJ(sub_obj);
1848 }
1849 
1850 /*---------------------------------------------------------------------------*
1851   Name:         GX_TrySetBankForSubOBJ
1852 
1853   Description:  Try to assign banks onto sub engine's OBJ.
1854                 The specified banks must be disabled or mapped to LCDC.
1855 
1856   Arguments:    sub_obj:     Banks to be assigned to sub engine's OBJ
1857 
1858   Returns:      BOOL.       If VRAM banks could not be locked, return FALSE.
1859  *---------------------------------------------------------------------------*/
GX_TrySetBankForSubOBJ(GXVRamSubOBJ sub_obj)1860 BOOL GX_TrySetBankForSubOBJ(GXVRamSubOBJ sub_obj)
1861 {
1862     if (!OSi_TryLockVram((u16)sub_obj, GXi_VRamLockId))
1863     {
1864         return FALSE;
1865     }
1866     GxSetBankForSubOBJ(sub_obj);
1867     return TRUE;
1868 }
1869 
1870 /*---------------------------------------------------------------------------*/
GxSetBankForSubBGExtPltt(GXVRamSubBGExtPltt sub_bgExtPltt)1871 static inline void GxSetBankForSubBGExtPltt(GXVRamSubBGExtPltt sub_bgExtPltt)
1872 {
1873     // Check parameter validity
1874     GX_VRAM_SUB_BGEXTPLTT_ASSERT(sub_bgExtPltt);
1875     // Change BG banks and LCDC ones.
1876     gGXState.vramCnt.lcdc =
1877         (u16)(~sub_bgExtPltt & (gGXState.vramCnt.lcdc | gGXState.vramCnt.sub_bgExtPltt));
1878     gGXState.vramCnt.sub_bgExtPltt = sub_bgExtPltt;
1879     // Check conflicts( DEBUG build ).
1880     GX_StateCheck_VRAMCnt();
1881     // Switch VRAM banks
1882     GX_VRAMCNT_SetSubBGExtPltt_(sub_bgExtPltt);
1883     GX_VRAMCNT_SetLCDC_(gGXState.vramCnt.lcdc);
1884 }
1885 
1886 /*---------------------------------------------------------------------------*
1887   Name:         GX_SetBankForSubBGExtPltt
1888 
1889   Description:  Assigns banks onto sub engine's BGExtPltt.
1890                 The specified banks must be disabled or mapped to LCDC.
1891 
1892   Arguments:    sub_bgExtPltt:     Banks to be assigned to sub engine's BGExtPltt
1893 
1894   Returns:      None.
1895  *---------------------------------------------------------------------------*/
GX_SetBankForSubBGExtPltt(GXVRamSubBGExtPltt sub_bgExtPltt)1896 void GX_SetBankForSubBGExtPltt(GXVRamSubBGExtPltt sub_bgExtPltt)
1897 {
1898 #ifndef SDK_FINALROM
1899     GxCheckExclusive((u16)sub_bgExtPltt);
1900 #endif
1901     GxSetBankForSubBGExtPltt(sub_bgExtPltt);
1902 }
1903 
1904 /*---------------------------------------------------------------------------*
1905   Name:         GX_TrySetBankForSubBGExtPltt
1906 
1907   Description:  Try to assign banks onto sub engine's BGExtPltt.
1908                 The specified banks must be disabled or mapped to LCDC.
1909 
1910   Arguments:    sub_bgExtPltt:     Banks to be assigned to sub engine's BGExtPltt
1911 
1912   Returns:      BOOL.       If VRAM banks could not be locked, return FALSE.
1913  *---------------------------------------------------------------------------*/
GX_TrySetBankForSubBGExtPltt(GXVRamSubBGExtPltt sub_bgExtPltt)1914 BOOL GX_TrySetBankForSubBGExtPltt(GXVRamSubBGExtPltt sub_bgExtPltt)
1915 {
1916     if (!OSi_TryLockVram((u16)sub_bgExtPltt, GXi_VRamLockId))
1917     {
1918         return FALSE;
1919     }
1920     GxSetBankForSubBGExtPltt(sub_bgExtPltt);
1921     return TRUE;
1922 }
1923 
1924 /*---------------------------------------------------------------------------*/
GxSetBankForSubOBJExtPltt(GXVRamSubOBJExtPltt sub_objExtPltt)1925 static inline void GxSetBankForSubOBJExtPltt(GXVRamSubOBJExtPltt sub_objExtPltt)
1926 {
1927     // Check parameter validity
1928     GX_VRAM_SUB_OBJEXTPLTT_ASSERT(sub_objExtPltt);
1929     // Change BG banks and LCDC ones.
1930     gGXState.vramCnt.lcdc =
1931         (u16)(~sub_objExtPltt & (gGXState.vramCnt.lcdc | gGXState.vramCnt.sub_objExtPltt));
1932     gGXState.vramCnt.sub_objExtPltt = sub_objExtPltt;
1933     // Check conflicts( DEBUG build ).
1934     GX_StateCheck_VRAMCnt();
1935     // Switch VRAM banks
1936     GX_VRAMCNT_SetSubOBJExtPltt_(sub_objExtPltt);
1937     GX_VRAMCNT_SetLCDC_(gGXState.vramCnt.lcdc);
1938 }
1939 
1940 /*---------------------------------------------------------------------------*
1941   Name:         GX_SetBankForSubOBJExtPltt
1942 
1943   Description:  Assigns banks onto sub engine's OBJExtPltt.
1944                 The specified banks must be disabled or mapped to LCDC.
1945 
1946   Arguments:    sub_objExtPltt:     Banks to be assigned to sub engine's OBJExtPltt
1947 
1948   Returns:      None.
1949  *---------------------------------------------------------------------------*/
GX_SetBankForSubOBJExtPltt(GXVRamSubOBJExtPltt sub_objExtPltt)1950 void GX_SetBankForSubOBJExtPltt(GXVRamSubOBJExtPltt sub_objExtPltt)
1951 {
1952 #ifndef SDK_FINALROM
1953     GxCheckExclusive((u16)sub_objExtPltt);
1954 #endif
1955     GxSetBankForSubOBJExtPltt(sub_objExtPltt);
1956 }
1957 
1958 /*---------------------------------------------------------------------------*
1959   Name:         GX_TrySetBankForSubOBJExtPltt
1960 
1961   Description:  Try to assign banks onto sub engine's OBJExtPltt.
1962                 The specified banks must be disabled or mapped to LCDC.
1963 
1964   Arguments:    sub_objExtPltt:     Banks to be assigned to sub engine's OBJExtPltt
1965 
1966   Returns:      BOOL.       If VRAM banks could not be locked, return FALSE.
1967  *---------------------------------------------------------------------------*/
GX_TrySetBankForSubOBJExtPltt(GXVRamSubOBJExtPltt sub_objExtPltt)1968 BOOL GX_TrySetBankForSubOBJExtPltt(GXVRamSubOBJExtPltt sub_objExtPltt)
1969 {
1970     if (!OSi_TryLockVram((u16)sub_objExtPltt, GXi_VRamLockId))
1971     {
1972         return FALSE;
1973     }
1974     GxSetBankForSubOBJExtPltt(sub_objExtPltt);
1975     return TRUE;
1976 }
1977 
1978 #ifdef  SDK_CW_WARNOFF_SAFESTRB
1979 #include <nitro/codereset.h>
1980 #endif
1981 
1982 /*---------------------------------------------------------------------------*
1983   Name:         resetBankForX_
1984 
1985   Description:  Assigns the argument banks onto LCDC memory space.
1986 
1987   Arguments:    g3bit:    A pointer to bank information
1988 
1989   Returns:      None.
1990  *---------------------------------------------------------------------------*/
resetBankForX_(u16 * g3bit)1991 static int resetBankForX_(u16 *g3bit)
1992 {
1993     int     rval = *g3bit;
1994     *g3bit = 0;                        // GX_VRAMCNT_xxxxxx_NONE
1995 
1996     // maps to LCDC
1997     gGXState.vramCnt.lcdc |= rval;
1998     GX_VRAMCNT_SetLCDC_(rval);
1999 
2000     return rval;
2001 }
2002 
2003 
2004 /*---------------------------------------------------------------------------*
2005   Name:         GX_ResetBankForBG
2006 
2007   Description:  Switches BG banks onto LCDC memory space.
2008 
2009   Arguments:    None.
2010 
2011   Returns:      The banks that were assigned to BG.
2012  *---------------------------------------------------------------------------*/
GX_ResetBankForBG()2013 GXVRamBG GX_ResetBankForBG()
2014 {
2015 #ifndef SDK_FINALROM
2016     if (!OSi_TryLockVram((u16)gGXState.vramCnt.bg, GXi_VRamLockId))
2017     {
2018         return GX_VRAM_BG_NONE;
2019     }
2020 #endif
2021     return (GXVRamBG)resetBankForX_(&gGXState.vramCnt.bg);
2022 }
2023 
2024 
2025 /*---------------------------------------------------------------------------*
2026   Name:         GX_ResetBankForOBJ
2027 
2028   Description:  Switches OBJ banks onto LCDC memory space.
2029 
2030   Arguments:    None.
2031 
2032   Returns:      The banks that were assigned to OBJ.
2033  *---------------------------------------------------------------------------*/
GX_ResetBankForOBJ()2034 GXVRamOBJ GX_ResetBankForOBJ()
2035 {
2036 #ifndef SDK_FINALROM
2037     if (!OSi_TryLockVram((u16)gGXState.vramCnt.obj, GXi_VRamLockId))
2038     {
2039         return GX_VRAM_OBJ_NONE;
2040     }
2041 #endif
2042     return (GXVRamOBJ)resetBankForX_(&gGXState.vramCnt.obj);
2043 }
2044 
2045 
2046 /*---------------------------------------------------------------------------*
2047   Name:         GX_ResetBankForBGExtPltt
2048 
2049   Description:  Switches BGExtPltt banks onto LCDC memory space.
2050 
2051   Arguments:    None.
2052 
2053   Returns:      The banks that were assigned to BGExtPltt.
2054  *---------------------------------------------------------------------------*/
GX_ResetBankForBGExtPltt()2055 GXVRamBGExtPltt GX_ResetBankForBGExtPltt()
2056 {
2057 #ifndef SDK_FINALROM
2058     if (!OSi_TryLockVram((u16)gGXState.vramCnt.bgExtPltt, GXi_VRamLockId))
2059     {
2060         return GX_VRAM_BGEXTPLTT_NONE;
2061     }
2062 #endif
2063     bgExtPlttOff_();
2064     return (GXVRamBGExtPltt)resetBankForX_(&gGXState.vramCnt.bgExtPltt);
2065 }
2066 
2067 
2068 /*---------------------------------------------------------------------------*
2069   Name:         GX_ResetBankForOBJExtPltt
2070 
2071   Description:  Switches OBJExtPltt banks onto LCDC memory space.
2072 
2073   Arguments:    None.
2074 
2075   Returns:      The banks that were assigned to OBJExtPltt.
2076  *---------------------------------------------------------------------------*/
GX_ResetBankForOBJExtPltt()2077 GXVRamOBJExtPltt GX_ResetBankForOBJExtPltt()
2078 {
2079 #ifndef SDK_FINALROM
2080     if (!OSi_TryLockVram((u16)gGXState.vramCnt.objExtPltt, GXi_VRamLockId))
2081     {
2082         return GX_VRAM_OBJEXTPLTT_NONE;
2083     }
2084 #endif
2085     objExtPlttOff_();
2086     return (GXVRamOBJExtPltt)resetBankForX_(&gGXState.vramCnt.objExtPltt);
2087 }
2088 
2089 
2090 /*---------------------------------------------------------------------------*
2091   Name:         GX_ResetBankForTex
2092 
2093   Description:  Switches TexImage banks onto LCDC memory space.
2094 
2095   Arguments:    None.
2096 
2097   Returns:      The banks that were assigned to TexImage.
2098  *---------------------------------------------------------------------------*/
GX_ResetBankForTex()2099 GXVRamTex GX_ResetBankForTex()
2100 {
2101 #ifndef SDK_FINALROM
2102     if (!OSi_TryLockVram((u16)gGXState.vramCnt.tex, GXi_VRamLockId))
2103     {
2104         return GX_VRAM_TEX_NONE;
2105     }
2106 #endif
2107     return (GXVRamTex)resetBankForX_(&gGXState.vramCnt.tex);
2108 }
2109 
2110 
2111 /*---------------------------------------------------------------------------*
2112   Name:         GX_ResetBankForTexPltt
2113 
2114   Description:  Switches TexPltt banks onto LCDC memory space.
2115 
2116   Arguments:    None.
2117 
2118   Returns:      The banks that were assigned to TexPltt.
2119  *---------------------------------------------------------------------------*/
GX_ResetBankForTexPltt()2120 GXVRamTexPltt GX_ResetBankForTexPltt()
2121 {
2122 #ifndef SDK_FINALROM
2123     if (!OSi_TryLockVram((u16)gGXState.vramCnt.texPltt, GXi_VRamLockId))
2124     {
2125         return GX_VRAM_TEXPLTT_NONE;
2126     }
2127 #endif
2128     return (GXVRamTexPltt)resetBankForX_(&gGXState.vramCnt.texPltt);
2129 }
2130 
2131 
2132 /*---------------------------------------------------------------------------*
2133   Name:         GX_ResetBankForClearImage
2134 
2135   Description:  Switches ClearImage banks onto LCDC memory space.
2136 
2137   Arguments:    None.
2138 
2139   Returns:      The banks that were assigned to ClearImage.
2140  *---------------------------------------------------------------------------*/
GX_ResetBankForClearImage()2141 GXVRamClearImage GX_ResetBankForClearImage()
2142 {
2143 #ifndef SDK_FINALROM
2144     if (!OSi_TryLockVram((u16)gGXState.vramCnt.clrImg, GXi_VRamLockId))
2145     {
2146         return GX_VRAM_CLEARIMAGE_NONE;
2147     }
2148 #endif
2149     return (GXVRamClearImage)resetBankForX_(&gGXState.vramCnt.clrImg);
2150 }
2151 
2152 
2153 /*---------------------------------------------------------------------------*
2154   Name:         GX_ResetBankForARM7
2155 
2156   Description:  Switches ARM7 banks onto LCDC memory space.
2157 
2158   Arguments:    None.
2159 
2160   Returns:      The banks that were assigned to ARM7.
2161  *---------------------------------------------------------------------------*/
GX_ResetBankForARM7()2162 GXVRamARM7 GX_ResetBankForARM7()
2163 {
2164 #ifndef SDK_FINALROM
2165     if (!OSi_TryLockVram((u16)gGXState.vramCnt.arm7, GXi_VRamLockId))
2166     {
2167         return GX_VRAM_ARM7_NONE;
2168     }
2169 #endif
2170     return (GXVRamARM7)resetBankForX_(&gGXState.vramCnt.arm7);
2171 }
2172 
2173 
2174 /*---------------------------------------------------------------------------*
2175   Name:         GX_ResetBankForSubBG
2176 
2177   Description:  Switches sub engine's BG banks onto LCDC memory space.
2178 
2179   Arguments:    None.
2180 
2181   Returns:      The banks that were assigned to sub engine's BG.
2182  *---------------------------------------------------------------------------*/
GX_ResetBankForSubBG()2183 GXVRamSubBG GX_ResetBankForSubBG()
2184 {
2185 #ifndef SDK_FINALROM
2186     if (!OSi_TryLockVram((u16)gGXState.vramCnt.sub_bg, GXi_VRamLockId))
2187     {
2188         return GX_VRAM_SUB_BG_NONE;
2189     }
2190 #endif
2191     return (GXVRamSubBG)resetBankForX_(&gGXState.vramCnt.sub_bg);
2192 }
2193 
2194 
2195 /*---------------------------------------------------------------------------*
2196   Name:         GX_ResetBankForSubOBJ
2197 
2198   Description:  Switches sub engine's OBJ banks onto LCDC memory space.
2199 
2200   Arguments:    None.
2201 
2202   Returns:      The banks that were assigned to sub engine's OBJ.
2203  *---------------------------------------------------------------------------*/
GX_ResetBankForSubOBJ()2204 GXVRamSubOBJ GX_ResetBankForSubOBJ()
2205 {
2206 #ifndef SDK_FINALROM
2207     if (!OSi_TryLockVram((u16)gGXState.vramCnt.sub_obj, GXi_VRamLockId))
2208     {
2209         return GX_VRAM_SUB_OBJ_NONE;
2210     }
2211 #endif
2212     return (GXVRamSubOBJ)resetBankForX_(&gGXState.vramCnt.sub_obj);
2213 }
2214 
2215 
2216 /*---------------------------------------------------------------------------*
2217   Name:         GX_ResetBankForSubBGExtPltt
2218 
2219   Description:  Switches sub engine's BGExtPltt banks onto LCDC memory space.
2220 
2221   Arguments:    None.
2222 
2223   Returns:      The banks that were assigned to sub engine's BGExtPltt.
2224  *---------------------------------------------------------------------------*/
GX_ResetBankForSubBGExtPltt()2225 GXVRamSubBGExtPltt GX_ResetBankForSubBGExtPltt()
2226 {
2227 #ifndef SDK_FINALROM
2228     if (!OSi_TryLockVram((u16)gGXState.vramCnt.sub_bgExtPltt, GXi_VRamLockId))
2229     {
2230         return GX_VRAM_SUB_BGEXTPLTT_NONE;
2231     }
2232 #endif
2233     subBGExtPlttOff_();
2234     return (GXVRamSubBGExtPltt)resetBankForX_(&gGXState.vramCnt.sub_bgExtPltt);
2235 }
2236 
2237 
2238 /*---------------------------------------------------------------------------*
2239   Name:         GX_ResetBankForSubOBJExtPltt
2240 
2241   Description:  Switches sub engine's OBJExtPltt banks onto LCDC memory space.
2242 
2243   Arguments:    None.
2244 
2245   Returns:      The banks that were assigned to sub engine's OBJExtPltt.
2246  *---------------------------------------------------------------------------*/
GX_ResetBankForSubOBJExtPltt()2247 GXVRamSubOBJExtPltt GX_ResetBankForSubOBJExtPltt()
2248 {
2249 #ifndef SDK_FINALROM
2250     if (!OSi_TryLockVram((u16)gGXState.vramCnt.sub_objExtPltt, GXi_VRamLockId))
2251     {
2252         return GX_VRAM_SUB_OBJEXTPLTT_NONE;
2253     }
2254 #endif
2255     subOBJExtPlttOff_();
2256     return (GXVRamSubOBJExtPltt)resetBankForX_(&gGXState.vramCnt.sub_objExtPltt);
2257 }
2258 
2259 
2260 /*---------------------------------------------------------------------------*
2261   Name:         disableBankForX_
2262 
2263   Description:  Disables the argument banks.
2264 
2265   Arguments:    g3bit:    A pointer to bank information
2266 
2267   Returns:      None.
2268  *---------------------------------------------------------------------------*/
2269 #ifdef  SDK_CW_WARNOFF_SAFESTRB
2270 #include <nitro/code32.h>
2271 #endif
disableBankForX_(u16 * g3bit)2272 static int disableBankForX_(u16 *g3bit)
2273 {
2274     int     rval = *g3bit;
2275     *g3bit = 0;                        // GX_VRAMCNT_xxxxxx_NONE
2276 
2277     if (rval & GX_VRAM_LCDC_A)
2278         reg_GX_VRAMCNT_A = 0;
2279     if (rval & GX_VRAM_LCDC_B)
2280         reg_GX_VRAMCNT_B = 0;
2281     if (rval & GX_VRAM_LCDC_C)
2282         reg_GX_VRAMCNT_C = 0;
2283     if (rval & GX_VRAM_LCDC_D)
2284         reg_GX_VRAMCNT_D = 0;
2285     if (rval & GX_VRAM_LCDC_E)
2286         reg_GX_VRAMCNT_E = 0;
2287     if (rval & GX_VRAM_LCDC_F)
2288         reg_GX_VRAMCNT_F = 0;
2289     if (rval & GX_VRAM_LCDC_G)
2290         reg_GX_VRAMCNT_G = 0;
2291     if (rval & GX_VRAM_LCDC_H)
2292         reg_GX_VRAMCNT_H = 0;
2293     if (rval & GX_VRAM_LCDC_I)
2294         reg_GX_VRAMCNT_I = 0;
2295 
2296     OSi_UnlockVram((u16)rval, GXi_VRamLockId);
2297 
2298     return rval;
2299 }
2300 
2301 #ifdef  SDK_CW_WARNOFF_SAFESTRB
2302 #include <nitro/codereset.h>
2303 #endif
2304 
2305 /*---------------------------------------------------------------------------*
2306   Name:         GX_DisableBankForBG
2307 
2308   Description:  Disables the banks assigned to BG.
2309 
2310   Arguments:    None.
2311 
2312   Returns:      The banks that were assigned to BG.
2313  *---------------------------------------------------------------------------*/
GX_DisableBankForBG()2314 GXVRamBG GX_DisableBankForBG()
2315 {
2316 #ifndef SDK_FINALROM
2317     if (!OSi_TryLockVram((u16)gGXState.vramCnt.bg, GXi_VRamLockId))
2318     {
2319         return GX_VRAM_BG_NONE;
2320     }
2321 #endif
2322     return (GXVRamBG)disableBankForX_(&gGXState.vramCnt.bg);
2323 }
2324 
2325 
2326 /*---------------------------------------------------------------------------*
2327   Name:         GX_DisableBankForOBJ
2328 
2329   Description:  Disables the banks assigned to OBJ.
2330 
2331   Arguments:    None.
2332 
2333   Returns:      The banks that were assigned to OBJ.
2334  *---------------------------------------------------------------------------*/
GX_DisableBankForOBJ()2335 GXVRamOBJ GX_DisableBankForOBJ()
2336 {
2337 #ifndef SDK_FINALROM
2338     if (!OSi_TryLockVram((u16)gGXState.vramCnt.obj, GXi_VRamLockId))
2339     {
2340         return GX_VRAM_OBJ_NONE;
2341     }
2342 #endif
2343     return (GXVRamOBJ)disableBankForX_(&gGXState.vramCnt.obj);
2344 }
2345 
2346 
2347 /*---------------------------------------------------------------------------*
2348   Name:         GX_DisableBankForBGExtPltt
2349 
2350   Description:  Disables the banks assigned to BGExtPltt.
2351 
2352   Arguments:    None.
2353 
2354   Returns:      The banks that were assigned to BGExtPltt.
2355  *---------------------------------------------------------------------------*/
GX_DisableBankForBGExtPltt()2356 GXVRamBGExtPltt GX_DisableBankForBGExtPltt()
2357 {
2358 #ifndef SDK_FINALROM
2359     if (!OSi_TryLockVram((u16)gGXState.vramCnt.bgExtPltt, GXi_VRamLockId))
2360     {
2361         return GX_VRAM_BGEXTPLTT_NONE;
2362     }
2363 #endif
2364     bgExtPlttOff_();
2365     return (GXVRamBGExtPltt)disableBankForX_(&gGXState.vramCnt.bgExtPltt);
2366 }
2367 
2368 
2369 /*---------------------------------------------------------------------------*
2370   Name:         GX_DisableBankForOBJExtPltt
2371 
2372   Description:  Disables the banks assigned to OBJExtPltt.
2373 
2374   Arguments:    None.
2375 
2376   Returns:      The banks that were assigned to OBJExtPltt.
2377  *---------------------------------------------------------------------------*/
GX_DisableBankForOBJExtPltt()2378 GXVRamOBJExtPltt GX_DisableBankForOBJExtPltt()
2379 {
2380 #ifndef SDK_FINALROM
2381     if (!OSi_TryLockVram((u16)gGXState.vramCnt.objExtPltt, GXi_VRamLockId))
2382     {
2383         return GX_VRAM_OBJEXTPLTT_NONE;
2384     }
2385 #endif
2386     objExtPlttOff_();
2387     return (GXVRamOBJExtPltt)disableBankForX_(&gGXState.vramCnt.objExtPltt);
2388 }
2389 
2390 
2391 /*---------------------------------------------------------------------------*
2392   Name:         GX_DisableBankForTex
2393 
2394   Description:  Disables the banks assigned to Tex.
2395 
2396   Arguments:    None.
2397 
2398   Returns:      The banks that were assigned to Tex.
2399  *---------------------------------------------------------------------------*/
GX_DisableBankForTex()2400 GXVRamTex GX_DisableBankForTex()
2401 {
2402 #ifndef SDK_FINALROM
2403     if (!OSi_TryLockVram((u16)gGXState.vramCnt.tex, GXi_VRamLockId))
2404     {
2405         return GX_VRAM_TEX_NONE;
2406     }
2407 #endif
2408     return (GXVRamTex)disableBankForX_(&gGXState.vramCnt.tex);
2409 }
2410 
2411 
2412 /*---------------------------------------------------------------------------*
2413   Name:         GX_DisableBankForTexPltt
2414 
2415   Description:  Disables the banks assigned to TexPltt.
2416 
2417   Arguments:    None.
2418 
2419   Returns:      The banks that were assigned to TexPltt.
2420  *---------------------------------------------------------------------------*/
GX_DisableBankForTexPltt()2421 GXVRamTexPltt GX_DisableBankForTexPltt()
2422 {
2423 #ifndef SDK_FINALROM
2424     if (!OSi_TryLockVram((u16)gGXState.vramCnt.texPltt, GXi_VRamLockId))
2425     {
2426         return GX_VRAM_TEXPLTT_NONE;
2427     }
2428 #endif
2429     return (GXVRamTexPltt)disableBankForX_(&gGXState.vramCnt.texPltt);
2430 }
2431 
2432 
2433 /*---------------------------------------------------------------------------*
2434   Name:         GX_DisableBankForClearImage
2435 
2436   Description:  Disables the banks assigned to ClearImage.
2437 
2438   Arguments:    None.
2439 
2440   Returns:      The banks that were assigned to ClearImage.
2441  *---------------------------------------------------------------------------*/
GX_DisableBankForClearImage()2442 GXVRamClearImage GX_DisableBankForClearImage()
2443 {
2444 #ifndef SDK_FINALROM
2445     if (!OSi_TryLockVram((u16)gGXState.vramCnt.clrImg, GXi_VRamLockId))
2446     {
2447         return GX_VRAM_CLEARIMAGE_NONE;
2448     }
2449 #endif
2450     return (GXVRamClearImage)disableBankForX_(&gGXState.vramCnt.clrImg);
2451 }
2452 
2453 
2454 /*---------------------------------------------------------------------------*
2455   Name:         GX_DisableBankForARM7
2456 
2457   Description:  Disables the banks assigned to ARM7.
2458 
2459   Arguments:    None.
2460 
2461   Returns:      The banks that were assigned to ARM7.
2462  *---------------------------------------------------------------------------*/
GX_DisableBankForARM7()2463 GXVRamARM7 GX_DisableBankForARM7()
2464 {
2465 #ifndef SDK_FINALROM
2466     if (!OSi_TryLockVram((u16)gGXState.vramCnt.arm7, GXi_VRamLockId))
2467     {
2468         return GX_VRAM_ARM7_NONE;
2469     }
2470 #endif
2471     return (GXVRamARM7)disableBankForX_(&gGXState.vramCnt.arm7);
2472 }
2473 
2474 
2475 /*---------------------------------------------------------------------------*
2476   Name:         GX_DisableBankForLCDC
2477 
2478   Description:  Disables the banks assigned to LCDC.
2479 
2480   Arguments:    None.
2481 
2482   Returns:      The banks that were assigned to LCDC.
2483  *---------------------------------------------------------------------------*/
GX_DisableBankForLCDC()2484 GXVRamLCDC GX_DisableBankForLCDC()
2485 {
2486 #ifndef SDK_FINALROM
2487     if (!OSi_TryLockVram((u16)gGXState.vramCnt.lcdc, GXi_VRamLockId))
2488     {
2489         return GX_VRAM_LCDC_NONE;
2490     }
2491 #endif
2492     return (GXVRamLCDC)disableBankForX_(&gGXState.vramCnt.lcdc);
2493 }
2494 
2495 
2496 /*---------------------------------------------------------------------------*
2497   Name:         GX_DisableBankForSubBG
2498 
2499   Description:  Disables the banks assigned to sub engine's BG.
2500 
2501   Arguments:    None.
2502 
2503   Returns:      The banks that were assigned to sub engine's BG.
2504  *---------------------------------------------------------------------------*/
GX_DisableBankForSubBG()2505 GXVRamSubBG GX_DisableBankForSubBG()
2506 {
2507 #ifndef SDK_FINALROM
2508     if (!OSi_TryLockVram((u16)gGXState.vramCnt.sub_bg, GXi_VRamLockId))
2509     {
2510         return GX_VRAM_SUB_BG_NONE;
2511     }
2512 #endif
2513     return (GXVRamSubBG)disableBankForX_(&gGXState.vramCnt.sub_bg);
2514 }
2515 
2516 
2517 /*---------------------------------------------------------------------------*
2518   Name:         GX_DisableBankForSubOBJ
2519 
2520   Description:  Disables the banks assigned to sub engine's OBJ.
2521 
2522   Arguments:    None.
2523 
2524   Returns:      The banks that were assigned to sub engine's OBJ.
2525  *---------------------------------------------------------------------------*/
GX_DisableBankForSubOBJ()2526 GXVRamSubOBJ GX_DisableBankForSubOBJ()
2527 {
2528 #ifndef SDK_FINALROM
2529     if (!OSi_TryLockVram((u16)gGXState.vramCnt.sub_obj, GXi_VRamLockId))
2530     {
2531         return GX_VRAM_SUB_OBJ_NONE;
2532     }
2533 #endif
2534     return (GXVRamSubOBJ)disableBankForX_(&gGXState.vramCnt.sub_obj);
2535 }
2536 
2537 
2538 /*---------------------------------------------------------------------------*
2539   Name:         GX_DisableBankForSubBGExtPltt
2540 
2541   Description:  Disables the banks assigned to sub engine's BGExtPltt.
2542 
2543   Arguments:    None.
2544 
2545   Returns:      The banks that were assigned to sub engine's BGExtPltt.
2546  *---------------------------------------------------------------------------*/
GX_DisableBankForSubBGExtPltt()2547 GXVRamSubBGExtPltt GX_DisableBankForSubBGExtPltt()
2548 {
2549 #ifndef SDK_FINALROM
2550     if (!OSi_TryLockVram((u16)gGXState.vramCnt.sub_bgExtPltt, GXi_VRamLockId))
2551     {
2552         return GX_VRAM_SUB_BGEXTPLTT_NONE;
2553     }
2554 #endif
2555     subBGExtPlttOff_();
2556     return (GXVRamSubBGExtPltt)disableBankForX_(&gGXState.vramCnt.sub_bgExtPltt);
2557 }
2558 
2559 
2560 /*---------------------------------------------------------------------------*
2561   Name:         GX_DisableBankForSubOBJExtPltt
2562 
2563   Description:  Disables the banks assigned to sub engine's OBJExtPltt.
2564 
2565   Arguments:    None.
2566 
2567   Returns:      The banks that were assigned to sub engine's OBJExtPltt.
2568  *---------------------------------------------------------------------------*/
GX_DisableBankForSubOBJExtPltt()2569 GXVRamSubOBJExtPltt GX_DisableBankForSubOBJExtPltt()
2570 {
2571 #ifndef SDK_FINALROM
2572     if (!OSi_TryLockVram((u16)gGXState.vramCnt.sub_objExtPltt, GXi_VRamLockId))
2573     {
2574         return GX_VRAM_SUB_OBJEXTPLTT_NONE;
2575     }
2576 #endif
2577     subOBJExtPlttOff_();
2578     return (GXVRamSubOBJExtPltt)disableBankForX_(&gGXState.vramCnt.sub_objExtPltt);
2579 }
2580 
2581 
2582 
2583 
2584 
2585 /*---------------------------------------------------------------------------*
2586   Name:         GX_GetBankForBG
2587 
2588   Description:  Returns the bank assigned to BG.
2589 
2590   Arguments:    None.
2591 
2592   Returns:      The banks that are assigned to BG.
2593  *---------------------------------------------------------------------------*/
GX_GetBankForBG()2594 GXVRamBG GX_GetBankForBG()
2595 {
2596     return (GXVRamBG)gGXState.vramCnt.bg;
2597 }
2598 
2599 
2600 /*---------------------------------------------------------------------------*
2601   Name:         GX_GetBankForOBJ
2602 
2603   Description:  Returns the bank assigned to OBJ.
2604 
2605   Arguments:    None.
2606 
2607   Returns:      The banks that are assigned to OBJ.
2608  *---------------------------------------------------------------------------*/
GX_GetBankForOBJ()2609 GXVRamOBJ GX_GetBankForOBJ()
2610 {
2611     return (GXVRamOBJ)gGXState.vramCnt.obj;
2612 }
2613 
2614 
2615 /*---------------------------------------------------------------------------*
2616   Name:         GX_GetBankForBGExtPltt
2617 
2618   Description:  Returns the bank assigned to BGExtPltt.
2619 
2620   Arguments:    None.
2621 
2622   Returns:      The banks that are assigned to BGExtPltt.
2623  *---------------------------------------------------------------------------*/
GX_GetBankForBGExtPltt()2624 GXVRamBGExtPltt GX_GetBankForBGExtPltt()
2625 {
2626     return (GXVRamBGExtPltt)gGXState.vramCnt.bgExtPltt;
2627 }
2628 
2629 
2630 /*---------------------------------------------------------------------------*
2631   Name:         GX_GetBankForOBJExtPltt
2632 
2633   Description:  Returns the bank assigned to OBJExtPltt.
2634 
2635   Arguments:    None.
2636 
2637   Returns:      The banks that are assigned to OBJExtPltt.
2638  *---------------------------------------------------------------------------*/
GX_GetBankForOBJExtPltt()2639 GXVRamOBJExtPltt GX_GetBankForOBJExtPltt()
2640 {
2641     return (GXVRamOBJExtPltt)gGXState.vramCnt.objExtPltt;
2642 }
2643 
2644 
2645 /*---------------------------------------------------------------------------*
2646   Name:         GX_GetBankForTex
2647 
2648   Description:  Returns the bank assigned to Tex.
2649 
2650   Arguments:    None.
2651 
2652   Returns:      The banks that are assigned to Tex.
2653  *---------------------------------------------------------------------------*/
GX_GetBankForTex()2654 GXVRamTex GX_GetBankForTex()
2655 {
2656     return (GXVRamTex)gGXState.vramCnt.tex;
2657 }
2658 
2659 
2660 /*---------------------------------------------------------------------------*
2661   Name:         GX_GetBankForTexPltt
2662 
2663   Description:  Returns the bank assigned to TexPltt.
2664 
2665   Arguments:    None.
2666 
2667   Returns:      The banks that are assigned to TexPltt.
2668  *---------------------------------------------------------------------------*/
GX_GetBankForTexPltt()2669 GXVRamTexPltt GX_GetBankForTexPltt()
2670 {
2671     return (GXVRamTexPltt)gGXState.vramCnt.texPltt;
2672 }
2673 
2674 
2675 /*---------------------------------------------------------------------------*
2676   Name:         GX_GetBankForClearImage
2677 
2678   Description:  Returns the bank assigned to ClearImage.
2679 
2680   Arguments:    None.
2681 
2682   Returns:      The banks that are assigned to ClearImage.
2683  *---------------------------------------------------------------------------*/
GX_GetBankForClearImage()2684 GXVRamClearImage GX_GetBankForClearImage()
2685 {
2686     return (GXVRamClearImage)gGXState.vramCnt.clrImg;
2687 }
2688 
2689 
2690 /*---------------------------------------------------------------------------*
2691   Name:         GX_GetBankForARM7
2692 
2693   Description:  Returns the bank assigned to ARM7.
2694 
2695   Arguments:    None.
2696 
2697   Returns:      The banks that are assigned to ARM7.
2698  *---------------------------------------------------------------------------*/
GX_GetBankForARM7()2699 GXVRamARM7 GX_GetBankForARM7()
2700 {
2701     return (GXVRamARM7)gGXState.vramCnt.arm7;
2702 }
2703 
2704 
2705 /*---------------------------------------------------------------------------*
2706   Name:         GX_GetBankForLCDC
2707 
2708   Description:  Returns the bank assigned to LCDC.
2709 
2710   Arguments:    None.
2711 
2712   Returns:      The banks that are assigned to LCDC.
2713  *---------------------------------------------------------------------------*/
GX_GetBankForLCDC()2714 GXVRamLCDC GX_GetBankForLCDC()
2715 {
2716     return (GXVRamLCDC)gGXState.vramCnt.lcdc;
2717 }
2718 
2719 
2720 /*---------------------------------------------------------------------------*
2721   Name:         GX_GetBankForSubBG
2722 
2723   Description:  Returns the bank assigned to sub engine's BG.
2724 
2725   Arguments:    None.
2726 
2727   Returns:      The banks that are assigned to sub engine's BG.
2728  *---------------------------------------------------------------------------*/
GX_GetBankForSubBG()2729 GXVRamSubBG GX_GetBankForSubBG()
2730 {
2731     return (GXVRamSubBG)gGXState.vramCnt.sub_bg;
2732 }
2733 
2734 
2735 /*---------------------------------------------------------------------------*
2736   Name:         GX_GetBankForSubOBJ
2737 
2738   Description:  Returns the bank assigned to sub engine's OBJ.
2739 
2740   Arguments:    None.
2741 
2742   Returns:      The banks that are assigned to sub engine's OBJ.
2743  *---------------------------------------------------------------------------*/
GX_GetBankForSubOBJ()2744 GXVRamSubOBJ GX_GetBankForSubOBJ()
2745 {
2746     return (GXVRamSubOBJ)gGXState.vramCnt.sub_obj;
2747 }
2748 
2749 
2750 /*---------------------------------------------------------------------------*
2751   Name:         GX_GetBankForSubBGExtPltt
2752 
2753   Description:  Returns the bank assigned to sub engine's BGExtPltt.
2754 
2755   Arguments:    None.
2756 
2757   Returns:      The banks that are assigned to sub engine's BGExtPltt.
2758  *---------------------------------------------------------------------------*/
GX_GetBankForSubBGExtPltt()2759 GXVRamSubBGExtPltt GX_GetBankForSubBGExtPltt()
2760 {
2761     return (GXVRamSubBGExtPltt)gGXState.vramCnt.sub_bgExtPltt;
2762 }
2763 
2764 
2765 /*---------------------------------------------------------------------------*
2766   Name:         GX_GetBankForSubOBJExtPltt
2767 
2768   Description:  Returns the bank assigned to sub engine's OBJExtPltt.
2769 
2770   Arguments:    None.
2771 
2772   Returns:      The banks that are assigned to sub engine's OBJExtPltt.
2773  *---------------------------------------------------------------------------*/
GX_GetBankForSubOBJExtPltt()2774 GXVRamSubOBJExtPltt GX_GetBankForSubOBJExtPltt()
2775 {
2776     return (GXVRamSubOBJExtPltt)gGXState.vramCnt.sub_objExtPltt;
2777 }
2778 
2779 
2780 /*---------------------------------------------------------------------------*
2781   Name:         GX_GetSizeOfX_ (internal use only)
2782 
2783   Description:  Returns the size of VRAM allocated to BG/OBJ/Tex etc.
2784 
2785   Arguments:    bit:          The value of GXVRamXXXXX
2786 
2787   Returns:      The size of resource in bytes.
2788  *---------------------------------------------------------------------------*/
GX_GetSizeOfX_(u32 bit)2789 static u32 GX_GetSizeOfX_(u32 bit /* gGXState.vramCnt.????? */ )
2790 {
2791     u32     size = 0;
2792     if (bit & GX_VRAM_LCDC_A)
2793         size += HW_VRAM_A_SIZE;
2794     if (bit & GX_VRAM_LCDC_B)
2795         size += HW_VRAM_B_SIZE;
2796     if (bit & GX_VRAM_LCDC_C)
2797         size += HW_VRAM_C_SIZE;
2798     if (bit & GX_VRAM_LCDC_D)
2799         size += HW_VRAM_D_SIZE;
2800     if (bit & GX_VRAM_LCDC_E)
2801         size += HW_VRAM_E_SIZE;
2802     if (bit & GX_VRAM_LCDC_F)
2803         size += HW_VRAM_F_SIZE;
2804     if (bit & GX_VRAM_LCDC_G)
2805         size += HW_VRAM_G_SIZE;
2806     if (bit & GX_VRAM_LCDC_H)
2807         size += HW_VRAM_H_SIZE;
2808     if (bit & GX_VRAM_LCDC_I)
2809         size += HW_VRAM_I_SIZE;
2810     return size;
2811 }
2812 
2813 
2814 /*---------------------------------------------------------------------------*
2815   Name:         GX_GetSizeOfBG
2816 
2817   Description:  Returns the size of the memory allocated to the main engine's
2818                 BG.
2819 
2820   Arguments:    None.
2821 
2822   Returns:      The size of the main engine's BG.
2823  *---------------------------------------------------------------------------*/
GX_GetSizeOfBG(void)2824 u32 GX_GetSizeOfBG(void)
2825 {
2826     return GX_GetSizeOfX_(gGXState.vramCnt.bg);
2827 }
2828 
2829 
2830 /*---------------------------------------------------------------------------*
2831   Name:         GX_GetSizeOfOBJ
2832 
2833   Description:  Returns the size of the memory allocated to the main engine's OBJ.
2834 
2835   Arguments:    None.
2836 
2837   Returns:      The size of the main engine's OBJ.
2838  *---------------------------------------------------------------------------*/
GX_GetSizeOfOBJ(void)2839 u32 GX_GetSizeOfOBJ(void)
2840 {
2841     return GX_GetSizeOfX_(gGXState.vramCnt.obj);
2842 }
2843 
2844 
2845 /*---------------------------------------------------------------------------*
2846   Name:         GX_GetSizeOfBGExtPltt
2847 
2848   Description:  Returns the size of the memory allocated to the main engine's
2849                 BGExtPltt.
2850 
2851   Arguments:    None.
2852 
2853   Returns:      The size of the main engine's BGExtPltt.
2854  *---------------------------------------------------------------------------*/
GX_GetSizeOfBGExtPltt(void)2855 u32 GX_GetSizeOfBGExtPltt(void)
2856 {
2857     return GX_GetSizeOfX_(gGXState.vramCnt.bgExtPltt);
2858 }
2859 
2860 
2861 /*---------------------------------------------------------------------------*
2862   Name:         GX_GetSizeOfOBJExtPltt
2863 
2864   Description:  Returns the size of the memory allocated to the main engine's
2865                 OBJExtPltt.
2866 
2867   Arguments:    None.
2868 
2869   Returns:      The size of the main engine's OBJExtPltt.
2870  *---------------------------------------------------------------------------*/
GX_GetSizeOfOBJExtPltt(void)2871 u32 GX_GetSizeOfOBJExtPltt(void)
2872 {
2873     return GX_GetSizeOfX_(gGXState.vramCnt.objExtPltt);
2874 }
2875 
2876 
2877 /*---------------------------------------------------------------------------*
2878   Name:         GX_GetSizeOfTex
2879 
2880   Description:  Returns the size of the memory allocated to texture image slots.
2881 
2882   Arguments:    None.
2883 
2884   Returns:      The size of the texture image memory.
2885  *---------------------------------------------------------------------------*/
GX_GetSizeOfTex(void)2886 u32 GX_GetSizeOfTex(void)
2887 {
2888     return GX_GetSizeOfX_(gGXState.vramCnt.tex);
2889 }
2890 
2891 
2892 /*---------------------------------------------------------------------------*
2893   Name:         GX_GetSizeOfTexPltt
2894 
2895   Description:  Returns the size of the memory allocated to texture palette
2896                 slots.
2897 
2898   Arguments:    None.
2899 
2900   Returns:      The size of the texture palette memory.
2901  *---------------------------------------------------------------------------*/
GX_GetSizeOfTexPltt(void)2902 u32 GX_GetSizeOfTexPltt(void)
2903 {
2904     return GX_GetSizeOfX_(gGXState.vramCnt.texPltt);
2905 }
2906 
2907 
2908 /*---------------------------------------------------------------------------*
2909   Name:         GX_GetSizeOfClearImage
2910 
2911   Description:  Returns the size of the memory allocated to clear image slots.
2912 
2913   Arguments:    None.
2914 
2915   Returns:      The size of the clear image memory.
2916  *---------------------------------------------------------------------------*/
GX_GetSizeOfClearImage(void)2917 u32 GX_GetSizeOfClearImage(void)
2918 {
2919     return GX_GetSizeOfX_(gGXState.vramCnt.clrImg);
2920 }
2921 
2922 
2923 /*---------------------------------------------------------------------------*
2924   Name:         GX_GetSizeOfSubBG
2925 
2926   Description:  Returns the size of the memory allocated to the sub engine's BG.
2927 
2928   Arguments:    None.
2929 
2930   Returns:      The size of the sub engine's BG.
2931  *---------------------------------------------------------------------------*/
GX_GetSizeOfSubBG(void)2932 u32 GX_GetSizeOfSubBG(void)
2933 {
2934     return GX_GetSizeOfX_(gGXState.vramCnt.sub_bg);
2935 }
2936 
2937 
2938 /*---------------------------------------------------------------------------*
2939   Name:         GX_GetSizeOfSubOBJ
2940 
2941   Description:  Returns the size of the memory allocated to the sub engine's OBJ.
2942 
2943   Arguments:    None.
2944 
2945   Returns:      The size of the sub engine's OBJ.
2946  *---------------------------------------------------------------------------*/
GX_GetSizeOfSubOBJ(void)2947 u32 GX_GetSizeOfSubOBJ(void)
2948 {
2949     return GX_GetSizeOfX_(gGXState.vramCnt.sub_obj);
2950 }
2951 
2952 
2953 /*---------------------------------------------------------------------------*
2954   Name:         GX_GetSizeOfSubBGExtPltt
2955 
2956   Description:  Returns the size of the memory allocated to the sub engine's
2957                 BGExtPltt.
2958 
2959   Arguments:    None.
2960 
2961   Returns:      The size of the sub engine's BGExtPltt.
2962  *---------------------------------------------------------------------------*/
GX_GetSizeOfSubBGExtPltt(void)2963 u32 GX_GetSizeOfSubBGExtPltt(void)
2964 {
2965     return GX_GetSizeOfX_(gGXState.vramCnt.sub_bgExtPltt);
2966 }
2967 
2968 
2969 /*---------------------------------------------------------------------------*
2970   Name:         GX_GetSizeOfSubOBJExtPltt
2971 
2972   Description:  Returns the size of the memory allocated to the sub engine's
2973                 OBJExtPltt.
2974 
2975   Arguments:    None.
2976 
2977   Returns:      The size of the sub engine's OBJExtPltt.
2978  *---------------------------------------------------------------------------*/
GX_GetSizeOfSubOBJExtPltt(void)2979 u32 GX_GetSizeOfSubOBJExtPltt(void)
2980 {
2981     return GX_GetSizeOfX_(gGXState.vramCnt.sub_objExtPltt);
2982 }
2983 
2984 
2985 /*---------------------------------------------------------------------------*
2986   Name:         GX_GetSizeOfARM7
2987 
2988   Description:  Returns the size of VRAM allocated to ARM7 memory space.
2989 
2990   Arguments:    None.
2991 
2992   Returns:      The size of VRAM allocated to ARM7 memory space.
2993  *---------------------------------------------------------------------------*/
GX_GetSizeOfARM7(void)2994 u32 GX_GetSizeOfARM7(void)
2995 {
2996     return GX_GetSizeOfX_(gGXState.vramCnt.arm7);
2997 }
2998