1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - GX -
3   File:     gx_load3d.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 #include <nitro/gx/gx_load.h>
18 #include <nitro/gx/gx_vramcnt.h>
19 #ifdef SDK_NITRO
20 #include <nitro/hw/ARM9/mmap_global.h>
21 #include <nitro/hw/ARM9/mmap_vram.h>
22 #else
23 #include <twl/hw/ARM9/mmap_global.h>
24 #include <twl/hw/ARM9/mmap_vram.h>
25 #endif
26 #include <nitro/mi/dma.h>
27 #include "../include/gxstate.h"
28 #include "../include/gxdma.h"
29 
30 
31 //----------------------------------------------------------------------------
32 // Internal states for GX_BeginLoadTex, GX_LoadTex, and GX_EndLoadTex
33 //----------------------------------------------------------------------------
34 static u32 sTexLCDCBlk1 = 0;
35 static u32 sSzTexBlk1 = 0;
36 static u32 sTexLCDCBlk2 = 0;
37 static GXVRamTex sTex = (GXVRamTex)(0);
38 
39 
40 //----------------------------------------------------------------------------
41 // A table of start addresses in LCDC space.
42 // Used by GX_BeginLoadTex and GX_LoadTexEx.
43 //----------------------------------------------------------------------------
44 static const struct
45 {
46     u16     blk1;                      // 12 bit shift
47     u16     blk2;                      // 12 bit shift
48     u16     szBlk1;                    // 12 bit shift
49 }
50 sTexStartAddrTable[16] =
51 {
52     {
53     0, 0, 0}
54     ,                                  // GX_VRAM_TEX_NONE
55     {
56     (u16)(HW_LCDC_VRAM_A >> 12), 0, 0}
57     ,                                  // GX_VRAM_TEX_0_A
58     {
59     (u16)(HW_LCDC_VRAM_B >> 12), 0, 0}
60     ,                                  // GX_VRAM_TEX_0_B
61     {
62     (u16)(HW_LCDC_VRAM_A >> 12), 0, 0}
63     ,                                  // GX_VRAM_TEX_01_AB
64     {
65     (u16)(HW_LCDC_VRAM_C >> 12), 0, 0}
66     ,                                  // GX_VRAM_TEX_0_C
67     {
68     (u16)(HW_LCDC_VRAM_A >> 12), (u16)(HW_LCDC_VRAM_C >> 12), (u16)(HW_VRAM_A_SIZE >> 12)}
69     ,                                  // GX_VRAM_TEX_01_AC
70     {
71     (u16)(HW_LCDC_VRAM_B >> 12), 0, 0}
72     ,                                  // GX_VRAM_TEX_01_BC
73     {
74     (u16)(HW_LCDC_VRAM_A >> 12), 0, 0}
75     ,                                  // GX_VRAM_TEX_012_ABC
76     {
77     (u16)(HW_LCDC_VRAM_D >> 12), 0, 0}
78     ,                                  // GX_VRAM_TEX_0_D
79     {
80     (u16)(HW_LCDC_VRAM_A >> 12), (u16)(HW_LCDC_VRAM_D >> 12), (u16)(HW_VRAM_A_SIZE >> 12)}
81     ,                                  // GX_VRAM_TEX_01_AD
82     {
83     (u16)(HW_LCDC_VRAM_B >> 12), (u16)(HW_LCDC_VRAM_D >> 12), (u16)(HW_VRAM_B_SIZE >> 12)}
84     ,                                  // GX_VRAM_TEX_01_BD
85     {
86     (u16)(HW_LCDC_VRAM_A >> 12),
87             (u16)(HW_LCDC_VRAM_D >> 12), (u16)((HW_VRAM_A_SIZE + HW_VRAM_B_SIZE) >> 12)}
88     ,                                  // GX_VRAM_TEX_012_ABD
89     {
90     (u16)(HW_LCDC_VRAM_C >> 12), 0, 0}
91     ,                                  // GX_VRAM_TEX_01_CD
92     {
93     (u16)(HW_LCDC_VRAM_A >> 12), (u16)(HW_LCDC_VRAM_C >> 12), (u16)(HW_VRAM_A_SIZE >> 12)}
94     ,                                  // GX_VRAM_TEX_012_ACD
95     {
96     (u16)(HW_LCDC_VRAM_B >> 12), 0, 0}
97     ,                                  // GX_VRAM_TEX_012_BCD
98     {
99     (u16)(HW_LCDC_VRAM_A >> 12), 0, 0}
100     ,                                  // GX_VRAM_TEX_0123_ABCD
101 };
102 
103 
104 /*---------------------------------------------------------------------------*
105   Name:         GX_LoadTexEx
106 
107   Description:  Transfers texture images to the LCDC space which are to be
108                 mapped to texture image slots. Note that banks specified
109                 by 'tex' must be mapped to LCDC.
110                 pSrc, destSlotAddr, and szByte must be 4-bytes aligned.
111                 Also, notice that DMA transfer is asynchronous.
112 
113   Arguments:    tex              a set of VRAM banks to be mapped to texture
114                 pSrc             a pointer to the source of texture images
115                 destSlotAddr     a destination address on the slots
116                 szByte           the size of the source
117 
118   Returns:      none
119  *---------------------------------------------------------------------------*/
GX_LoadTexEx(GXVRamTex tex,const void * pSrc,u32 destSlotAddr,u32 szByte)120 void GX_LoadTexEx(GXVRamTex tex, const void *pSrc, u32 destSlotAddr, u32 szByte)
121 {
122     u32     base1, base2, szBlk1;
123     void   *pLCDC;
124 
125     SDK_ALIGN4_ASSERT(szByte);
126     SDK_ALIGN4_ASSERT(destSlotAddr);
127     SDK_ALIGN4_ASSERT(pSrc);
128     SDK_ASSERTMSG((GX_GetBankForLCDC() & tex) == tex,
129                   "Banks specified by tex must be on LCDC space.");
130     GX_VRAM_TEX_ASSERT(tex);
131 
132     base1 = (u32)(sTexStartAddrTable[tex].blk1 << 12);
133     base2 = (u32)(sTexStartAddrTable[tex].blk2 << 12);
134     szBlk1 = (u32)(sTexStartAddrTable[tex].szBlk1 << 12);
135 
136     SDK_ASSERT(0 != base1);
137 
138     // This works only if NITRO_DEBUG is true.
139     // It is declared in gxstate.h
140     GX_RegionCheck_Tex(tex, destSlotAddr, destSlotAddr + szByte);
141 
142     if (0 == base2)
143     {
144         // continuous on LCDC address space
145         pLCDC = (void *)(base1 + destSlotAddr);
146     }
147     else
148     {
149         // two discontinuous blocks on LCDC address space
150         if (destSlotAddr + szByte < szBlk1)
151         {
152             pLCDC = (void *)(base1 + destSlotAddr);
153         }
154         else if (destSlotAddr >= szBlk1)
155         {
156             pLCDC = (void *)(base2 + destSlotAddr - szBlk1);
157         }
158         else
159         {
160             // cross the boundary
161             void   *pLCDC2 = (void *)base2;
162             u32     sz = szBlk1 - destSlotAddr;
163             pLCDC = (void *)(base1 + destSlotAddr);
164 
165             GXi_DmaCopy32(GXi_DmaId, pSrc, pLCDC, sz);
166             GXi_DmaCopy32Async(GXi_DmaId,
167                                (void *)((u8 *)pSrc + sz), pLCDC2, szByte - sz, NULL, NULL);
168             return;
169         }
170     }
171     // DMA Transfer
172     GXi_DmaCopy32Async(GXi_DmaId, pSrc, pLCDC, szByte, NULL, NULL);
173 }
174 
175 
176 /*---------------------------------------------------------------------------*
177   Name:         GX_BeginLoadTex
178 
179   Description:  Remaps the banks for texture image slots onto LCDC space,
180                 and prepares for texture image transfer by GX_LoadTex.
181 
182   Arguments:    none
183 
184   Returns:      none
185  *---------------------------------------------------------------------------*/
GX_BeginLoadTex()186 void GX_BeginLoadTex()
187 {
188 #if 1
189     SDK_ASSERT(0 == sTex && 0 == sTexLCDCBlk1 && 0 == sSzTexBlk1 && 0 == sTexLCDCBlk2);
190 
191     // Texture slots to LCDC
192     sTex = GX_ResetBankForTex();
193     // check
194     GX_VRAM_TEX_ASSERT(sTex);
195 
196     sTexLCDCBlk1 = (u32)(sTexStartAddrTable[sTex].blk1 << 12);
197     sTexLCDCBlk2 = (u32)(sTexStartAddrTable[sTex].blk2 << 12);
198     sSzTexBlk1 = (u32)(sTexStartAddrTable[sTex].szBlk1 << 12);
199 
200 #else
201     SDK_ASSERT(sTex == 0 && sTexLCDCBlk1 == 0 && sSzTexBlk1 == 0 && sTexLCDCBlk2 == 0);
202 
203     // Texture slots to LCDC
204     sTex = GX_ResetBankForTex();
205 
206     switch (sTex)
207     {
208     case GX_VRAM_TEX_01_AC:
209     case GX_VRAM_TEX_012_ACD:
210         sTexLCDCBlk2 = HW_LCDC_VRAM_C;
211         sSzTexBlk1 = HW_VRAM_A_SIZE;
212         // do not break
213     case GX_VRAM_TEX_0_A:
214     case GX_VRAM_TEX_01_AB:
215     case GX_VRAM_TEX_012_ABC:
216     case GX_VRAM_TEX_0123_ABCD:
217         sTexLCDCBlk1 = HW_LCDC_VRAM_A;
218         break;
219 
220     case GX_VRAM_TEX_01_BD:
221         sTexLCDCBlk2 = HW_LCDC_VRAM_D;
222         sSzTexBlk1 = HW_VRAM_B_SIZE;
223         // do not break
224     case GX_VRAM_TEX_0_B:
225     case GX_VRAM_TEX_01_BC:
226     case GX_VRAM_TEX_012_BCD:
227         sTexLCDCBlk1 = HW_LCDC_VRAM_B;
228         break;
229 
230     case GX_VRAM_TEX_0_C:
231     case GX_VRAM_TEX_01_CD:
232         sTexLCDCBlk1 = HW_LCDC_VRAM_C;
233         break;
234 
235     case GX_VRAM_TEX_0_D:
236         sTexLCDCBlk1 = HW_LCDC_VRAM_D;
237         break;
238 
239     case GX_VRAM_TEX_01_AD:
240         sTexLCDCBlk1 = HW_LCDC_VRAM_A;
241         sTexLCDCBlk2 = HW_LCDC_VRAM_D;
242         sSzTexBlk1 = HW_VRAM_A_SIZE;
243         break;
244 
245     case GX_VRAM_TEX_012_ABD:
246         sTexLCDCBlk1 = HW_LCDC_VRAM_A;
247         sTexLCDCBlk2 = HW_LCDC_VRAM_D;
248         sSzTexBlk1 = HW_VRAM_A_SIZE + HW_VRAM_B_SIZE;
249         break;
250 
251     case GX_VRAM_TEX_NONE:
252         break;
253 
254     default:
255         SDK_INTERNAL_ERROR("unknown case 0x%x", sTex);
256         break;
257     };
258 #endif
259 }
260 
261 
262 /*---------------------------------------------------------------------------*
263   Name:         GX_LoadTex
264 
265   Description:  Transfers texture images to the LCDC space which is remapped
266                 from texture image slots. Two DMA transfers may be issued
267                 if there are discontinuous banks on LCDC space. This function
268                 must be called between GX_BeginLoadTex and GX_EndLoadTex.
269                 pSrc, destSlotAddr, and szByte must be 4-bytes aligned.
270 
271   Arguments:    pSrc             a pointer to the source of texture images
272                 destSlotAddr     a destination address on the slots
273                 szByte           the size of the source
274 
275   Returns:      none
276  *---------------------------------------------------------------------------*/
GX_LoadTex(const void * pSrc,u32 destSlotAddr,u32 szByte)277 void GX_LoadTex(const void *pSrc, u32 destSlotAddr, u32 szByte)
278 {
279     void   *pLCDC;
280     SDK_NULL_ASSERT(pSrc);
281 
282     SDK_ASSERT(GX_VRAM_TEX_NONE != sTex);
283     SDK_ASSERT(0 != sTexLCDCBlk1);
284     SDK_ALIGN4_ASSERT(szByte);
285     SDK_ALIGN4_ASSERT(destSlotAddr);
286     SDK_ALIGN4_ASSERT(pSrc);
287 
288     // This works only if NITRO_DEBUG is true.
289     // It is declared in gxstate.h
290     GX_RegionCheck_Tex(sTex, destSlotAddr, destSlotAddr + szByte);
291 
292     if (0 == sTexLCDCBlk2)
293     {
294         // continuous on LCDC address space
295         pLCDC = (void *)(sTexLCDCBlk1 + destSlotAddr);
296     }
297     else
298     {
299         // two discontinuous blocks on LCDC address space
300         if (destSlotAddr + szByte < sSzTexBlk1)
301         {
302             pLCDC = (void *)(sTexLCDCBlk1 + destSlotAddr);
303         }
304         else if (destSlotAddr >= sSzTexBlk1)
305         {
306             pLCDC = (void *)(sTexLCDCBlk2 + destSlotAddr - sSzTexBlk1);
307         }
308         else
309         {
310             // cross the boundary
311             void   *pLCDC2 = (void *)sTexLCDCBlk2;
312             u32     sz = sSzTexBlk1 - destSlotAddr;
313             pLCDC = (void *)(sTexLCDCBlk1 + destSlotAddr);
314 
315             GXi_DmaCopy32(GXi_DmaId, pSrc, pLCDC, sz);
316             GXi_DmaCopy32Async(GXi_DmaId,
317                                (void *)((u8 *)pSrc + sz), pLCDC2, szByte - sz, NULL, NULL);
318             return;
319         }
320     }
321     // DMA Transfer
322     GXi_DmaCopy32Async(GXi_DmaId, pSrc, pLCDC, szByte, NULL, NULL);
323 }
324 
325 
326 /*---------------------------------------------------------------------------*
327   Name:         GX_EndLoadTex
328 
329   Description:  Restores the banks remapped by GX_BeginLoadTex.
330                 This function is called after all the texture transfer is done.
331 
332   Arguments:    none
333 
334   Returns:      none
335  *---------------------------------------------------------------------------*/
GX_EndLoadTex()336 void GX_EndLoadTex()
337 {
338     GXi_WaitDma(GXi_DmaId);
339 
340     // Restore banks for textures
341     GX_SetBankForTex(sTex);
342 
343     sTexLCDCBlk1 = sTexLCDCBlk2 = sSzTexBlk1 = 0;
344     sTex = (GXVRamTex)0;
345 }
346 
347 
348 //----------------------------------------------------------------------------
349 // Internal states for GX_BeginLoadTexPltt, GX_LoadTexPltt,
350 // and GX_EndLoadTexPltt
351 //----------------------------------------------------------------------------
352 static GXVRamTexPltt sTexPltt = (GXVRamTexPltt)(0);
353 static u32 sTexPlttLCDCBlk = 0;
354 
355 
356 //----------------------------------------------------------------------------
357 // A table of start addresses in LCDC space.
358 // Used by GX_BeginLoadTexPltt and GX_LoadTexPlttEx.
359 //----------------------------------------------------------------------------
360 static const u16 sTexPlttStartAddrTable[8] = {
361     0,                                 // GX_VRAM_TEXPLTT_NONE
362     (u16)(HW_LCDC_VRAM_E >> 12),       // GX_VRAM_TEXPLTT_0123_E
363     (u16)(HW_LCDC_VRAM_F >> 12),       // GX_VRAM_TEXPLTT_0_F
364     (u16)(HW_LCDC_VRAM_E >> 12),       // GX_VRAM_TEXPLTT_01234_EF
365     (u16)(HW_LCDC_VRAM_G >> 12),       // GX_VRAM_TEXPLTT_0_G
366     0,                                 // forbidden(GX_VRAM_TEXPLTT_0_EG)
367     (u16)(HW_LCDC_VRAM_F >> 12),       // GX_VRAM_TEXPLTT_01_FG
368     (u16)(HW_LCDC_VRAM_E >> 12)        // GX_VRAM_TEXPLTT_012345_EFG
369 };
370 
371 
372 /*---------------------------------------------------------------------------*
373   Name:         GX_LoadTexPlttEx
374 
375   Description:  Transfers texture palettes to the LCDC space which are to be
376                 mapped to texture palette slots. Note that banks specified
377                 by 'texPltt' must be mapped to LCDC.
378                 pSrc, destSlotAddr, and szByte must be 4-bytes aligned.
379                 Also, notice that DMA transfer is asynchronous.
380 
381   Arguments:    texPltt          a set of VRAM banks to be mapped to texture
382                                  palette slots
383                 pSrc             a pointer to the source of texture palettes
384                 destSlotAddr     a destination address on the slots
385                 szByte           the size of the source
386 
387   Returns:      none
388  *---------------------------------------------------------------------------*/
GX_LoadTexPlttEx(GXVRamTexPltt texPltt,const void * pSrc,u32 destSlotAddr,u32 szByte)389 void GX_LoadTexPlttEx(GXVRamTexPltt texPltt, const void *pSrc, u32 destSlotAddr, u32 szByte)
390 {
391     u32     base;
392     SDK_ASSERTMSG((GX_GetBankForLCDC() & texPltt) == texPltt,
393                   "Banks specified by texPltt must be on LCDC space.");
394 
395     GX_VRAM_TEXPLTT_ASSERT(texPltt);
396     base = (u32)(sTexPlttStartAddrTable[texPltt >> 4] << 12);
397 
398     SDK_NULL_ASSERT(pSrc);
399     SDK_ASSERT(0 != base);
400     SDK_ALIGN4_ASSERT(destSlotAddr);
401     SDK_ALIGN4_ASSERT(szByte);
402     SDK_ALIGN4_ASSERT(pSrc);
403 
404     // This works only if NITRO_DEBUG is true.
405     // It is declared in gxstate.h
406     GX_RegionCheck_TexPltt(texPltt, destSlotAddr, destSlotAddr + szByte);
407 
408     // DMA Transfer
409     GXi_DmaCopy32Async(GXi_DmaId, pSrc, (void *)(base + destSlotAddr), szByte, NULL, NULL);
410 }
411 
412 
413 /*---------------------------------------------------------------------------*
414   Name:         GX_BeginLoadTexPltt
415 
416   Description:  Remaps the banks for texture palette slots onto LCDC space,
417                 and prepares for texture palettes transfer by GX_LoadTexPltt.
418 
419   Arguments:    none
420 
421   Returns:      none
422  *---------------------------------------------------------------------------*/
GX_BeginLoadTexPltt()423 void GX_BeginLoadTexPltt()
424 {
425 #if 1
426     SDK_ASSERT(0 == sTexPltt && 0 == sTexPlttLCDCBlk);
427 
428     // Texture pallet slot to LCDC
429     sTexPltt = GX_ResetBankForTexPltt();
430 
431     GX_VRAM_TEXPLTT_ASSERT(sTexPltt);
432     sTexPlttLCDCBlk = (u32)(sTexPlttStartAddrTable[sTexPltt >> 4] << 12);
433 #else
434     SDK_ASSERT(sTexPltt == 0 && sTexPlttLCDCBlk == 0);
435 
436     // Texture pallet slot to LCDC
437     sTexPltt = GX_ResetBankForTexPltt();
438 
439     switch (sTexPltt)
440     {
441     case GX_VRAM_TEXPLTT_0_F:
442     case GX_VRAM_TEXPLTT_01_FG:
443         sTexPlttLCDCBlk = HW_LCDC_VRAM_F;
444         break;
445     case GX_VRAM_TEXPLTT_0_G:
446         sTexPlttLCDCBlk = HW_LCDC_VRAM_G;
447         break;
448     case GX_VRAM_TEXPLTT_0123_E:
449     case GX_VRAM_TEXPLTT_01234_EF:
450     case GX_VRAM_TEXPLTT_012345_EFG:
451         sTexPlttLCDCBlk = HW_LCDC_VRAM_E;
452         break;
453     case GX_VRAM_TEXPLTT_NONE:
454         break;
455     default:
456         SDK_INTERNAL_ERROR("unknown case 0x%x", sTexPltt);
457         break;
458     }
459 #endif
460 }
461 
462 
463 /*---------------------------------------------------------------------------*
464   Name:         GX_LoadTexPltt
465 
466   Description:  Transfers texture palettes to the LCDC space which is remapped
467                 from texture palette slots. This function must be called
468                 between GX_BeginLoadTexPltt and GX_EndLoadTexPltt.
469                 pSrc, destSlotAddr, and szByte must be 4-bytes aligned.
470 
471   Arguments:    pSrc             a pointer to the source of texture palettes
472                 destSlotAddr     a destination address on the slots
473                 szByte           the size of the source
474 
475   Returns:      none
476  *---------------------------------------------------------------------------*/
GX_LoadTexPltt(const void * pSrc,u32 destSlotAddr,u32 szByte)477 void GX_LoadTexPltt(const void *pSrc, u32 destSlotAddr, u32 szByte)
478 {
479     SDK_NULL_ASSERT(pSrc);
480     SDK_ASSERT(GX_VRAM_TEXPLTT_NONE != sTexPltt);
481     SDK_ASSERT(0 != sTexPlttLCDCBlk);
482     SDK_ALIGN4_ASSERT(destSlotAddr);
483     SDK_ALIGN4_ASSERT(szByte);
484     SDK_ALIGN4_ASSERT(pSrc);
485 
486     // This works only if NITRO_DEBUG is true.
487     // It is declared in gxstate.h
488     GX_RegionCheck_TexPltt(sTexPltt, destSlotAddr, destSlotAddr + szByte);
489 
490     // DMA Transfer
491     GXi_DmaCopy32Async(GXi_DmaId,
492                        pSrc, (void *)(sTexPlttLCDCBlk + destSlotAddr), szByte, NULL, NULL);
493 }
494 
495 
496 /*---------------------------------------------------------------------------*
497   Name:         GX_EndLoadTexPltt
498 
499   Description:  Restores the banks remapped by GX_BeginLoadTexPltt.
500                 This function is called after all the texture palette
501                 transfer is done.
502 
503   Arguments:    none
504 
505   Returns:      none
506  *---------------------------------------------------------------------------*/
GX_EndLoadTexPltt()507 void GX_EndLoadTexPltt()
508 {
509     GXi_WaitDma(GXi_DmaId);
510 
511     // Restore banks for texture pallets
512     GX_SetBankForTexPltt(sTexPltt);
513 
514     sTexPltt = (GXVRamTexPltt)0;
515     sTexPlttLCDCBlk = 0;
516 }
517 
518 
519 //----------------------------------------------------------------------------
520 // Internal states for GX_BeginLoadClearImage, GX_LoadClearImageColor,
521 // GX_LoadClearImageDepth, and GX_EndLoadClearImage.
522 //----------------------------------------------------------------------------
523 static GXVRamClearImage sClrImg = (GXVRamClearImage)(0);
524 static u32 sClrImgLCDCBlk = 0;
525 
526 
527 /*---------------------------------------------------------------------------*
528   Name:         GX_BeginLoadClearImage
529 
530   Description:  Remaps the banks for a clear image onto LCDC space,
531                 and prepares for clear image transfer
532                 by GX_LoadClearImageColor and GX_LoadCleraImageDepth.
533 
534   Arguments:    none
535 
536   Returns:      none
537  *---------------------------------------------------------------------------*/
GX_BeginLoadClearImage()538 void GX_BeginLoadClearImage()
539 {
540     SDK_ASSERT(0 == sClrImg && 0 == sClrImgLCDCBlk);
541 
542     // Texture slot 2&3(Clear Image slots) to LCDC
543     sClrImg = GX_ResetBankForClearImage();
544 
545     switch (sClrImg)
546     {
547     case GX_VRAM_CLEARIMAGE_256_AB:
548     case GX_VRAM_CLEARDEPTH_128_B:
549         sClrImgLCDCBlk = HW_LCDC_VRAM_A;
550         break;
551 
552     case GX_VRAM_CLEARIMAGE_256_CD:
553     case GX_VRAM_CLEARDEPTH_128_D:
554         sClrImgLCDCBlk = HW_LCDC_VRAM_C;
555         break;
556 
557     case GX_VRAM_CLEARDEPTH_128_A:
558         sClrImgLCDCBlk = HW_LCDC_VRAM_A - 0x20000;
559         break;
560 
561     case GX_VRAM_CLEARDEPTH_128_C:
562         sClrImgLCDCBlk = HW_LCDC_VRAM_C - 0x20000;
563         break;
564 
565     case GX_VRAM_CLEARIMAGE_NONE:
566         break;
567 
568     default:
569         SDK_INTERNAL_ERROR("unknown case 0x%x", sClrImg);
570         break;
571     }
572 }
573 
574 
575 /*---------------------------------------------------------------------------*
576   Name:         GX_LoadClearImageColor
577 
578   Description:  Transfers a clear image to the LCDC space which is remapped
579                 from clear image slots. This function must be called
580                 between GX_BeginLoadClearImage and GX_EndLoadClearImage.
581                 pSrc and szByte must be 4-bytes aligned.
582 
583   Arguments:    pSrc             a pointer to the source of a clear color image
584                 szByte           the size of the source
585 
586   Returns:      none
587  *---------------------------------------------------------------------------*/
GX_LoadClearImageColor(const void * pSrc,u32 szByte)588 void GX_LoadClearImageColor(const void *pSrc, u32 szByte)
589 {
590     SDK_NULL_ASSERT(pSrc);
591     SDK_ASSERT(GX_VRAM_CLEARIMAGE_256_AB == sClrImg || GX_VRAM_CLEARIMAGE_256_CD == sClrImg);
592     SDK_ASSERT(0 != sClrImgLCDCBlk);
593     SDK_ALIGN4_ASSERT(szByte);
594     SDK_ALIGN4_ASSERT(pSrc);
595     SDK_ASSERT(szByte <= 0x20000 /* HW_VRAM_A_SIZE or HW_VRAM_C_SIZE */ );
596 
597     GXi_DmaCopy32Async(GXi_DmaId, pSrc, (void *)(sClrImgLCDCBlk), szByte, NULL, NULL);
598 }
599 
600 
601 /*---------------------------------------------------------------------------*
602   Name:         GX_LoadClearImageDepth
603 
604   Description:  Transfers a clear depth to the LCDC space which is remapped
605                 from clear image slots. This function must be called
606                 between GX_BeginLoadClearImage and GX_EndLoadClearImage.
607                 pSrc and szByte must be 4-bytes aligned.
608 
609   Arguments:    pSrc             a pointer to the source of a clear depth image
610                 szByte           the size of the source
611 
612   Returns:      none
613  *---------------------------------------------------------------------------*/
GX_LoadClearImageDepth(const void * pSrc,u32 szByte)614 void GX_LoadClearImageDepth(const void *pSrc, u32 szByte)
615 {
616     SDK_NULL_ASSERT(pSrc);
617     SDK_ASSERT(GX_VRAM_CLEARIMAGE_NONE != sClrImg);
618     SDK_ASSERT(0 != sClrImgLCDCBlk);
619     SDK_ALIGN4_ASSERT(szByte);
620     SDK_ALIGN4_ASSERT(pSrc);
621     SDK_ASSERT(szByte <= 0x20000 /* HW_VRAM_A_SIZE or HW_VRAM_C_SIZE */ );
622 
623     GXi_DmaCopy32Async(GXi_DmaId,
624                        pSrc,
625                        (void *)(sClrImgLCDCBlk + 0x20000 /* HW_VRAM_A_SIZE or HW_VRAM_C_SIZE */ ),
626                        szByte, NULL, NULL);
627 }
628 
629 
630 /*---------------------------------------------------------------------------*
631   Name:         GX_EndLoadClearImage
632 
633   Description:  Restores the banks remapped by GX_BeginLoadTexPltt.
634                 This function is called after all the clear image transfer
635                 is done.
636 
637   Arguments:    none
638 
639   Returns:      none
640  *---------------------------------------------------------------------------*/
GX_EndLoadClearImage()641 void GX_EndLoadClearImage()
642 {
643     GXi_WaitDma(GXi_DmaId);
644 
645     // Restore banks for texture pallets
646     GX_SetBankForClearImage(sClrImg);
647 
648     sClrImg = (GXVRamClearImage)0;
649     sClrImgLCDCBlk = 0;
650 }
651