1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - GX -
3   File:     gx_load2d.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_load.h>
19 #include <nitro/gx/gx_vramcnt.h>
20 #include <nitro/gx/gx_bgcnt.h>
21 #ifdef SDK_NITRO
22 #include <nitro/hw/ARM9/mmap_global.h>
23 #include <nitro/hw/ARM9/mmap_vram.h>
24 #else
25 #include <twl/hw/ARM9/mmap_global.h>
26 #include <twl/hw/ARM9/mmap_vram.h>
27 #endif
28 #include <nitro/mi/dma.h>
29 
30 #include "../include/gxstate.h"
31 #include "../include/gxdma.h"
32 
33 /*---------------------------------------------------------------------------*
34   Name:         GX_LoadBGPltt
35 
36   Description:  Transfers BG palettes to the standard BG palette RAM
37                 for the MAIN 2D engine.
38                 pSrc, offset, and szByte must be 2-bytes aligned.
39 
40   Arguments:    pSrc             a pointer to the source of BG palettes
41                 offset           an offset to HW_BG_PLTT
42                 szByte           the size of the source
43 
44   Returns:      none
45  *---------------------------------------------------------------------------*/
GX_LoadBGPltt(const void * pSrc,u32 offset,u32 szByte)46 void GX_LoadBGPltt(const void *pSrc, u32 offset, u32 szByte)
47 {
48     SDK_NULL_ASSERT(pSrc);
49     SDK_ASSERT(offset + szByte <= HW_BG_PLTT_SIZE);
50     SDK_ALIGN2_ASSERT(offset);
51     SDK_ALIGN2_ASSERT(szByte);
52 
53     GXi_DmaCopy16(GXi_DmaId, pSrc, (void *)(HW_BG_PLTT + offset), szByte);
54 }
55 
56 
57 /*---------------------------------------------------------------------------*
58   Name:         GXS_LoadBGPltt
59 
60   Description:  Transfers BG palettes to the standard BG palette RAM
61                 for the SUB 2D engine.
62                 pSrc, offset, and szByte must be 2-bytes aligned.
63 
64   Arguments:    pSrc             a pointer to the source of BG palettes
65                 offset           an offset to HW_DB_BG_PLTT
66                 szByte           the size of the source
67 
68   Returns:      none
69  *---------------------------------------------------------------------------*/
GXS_LoadBGPltt(const void * pSrc,u32 offset,u32 szByte)70 void GXS_LoadBGPltt(const void *pSrc, u32 offset, u32 szByte)
71 {
72     SDK_NULL_ASSERT(pSrc);
73     SDK_ASSERT(offset + szByte <= HW_DB_BG_PLTT_SIZE);
74     SDK_ALIGN2_ASSERT(offset);
75     SDK_ALIGN2_ASSERT(szByte);
76 
77     GXi_DmaCopy16(GXi_DmaId, pSrc, (void *)(HW_DB_BG_PLTT + offset), szByte);
78 }
79 
80 
81 /*---------------------------------------------------------------------------*
82   Name:         GX_LoadOBJPltt
83 
84   Description:  Transfers OBJ palettes to the standard OBJ palette RAM
85                 for the MAIN 2D engine.
86                 pSrc, offset, and szByte must be 2-bytes aligned.
87 
88   Arguments:    pSrc             a pointer to the source of OBJ palettes
89                 offset           an offset to HW_OBJ_PLTT
90                 szByte           the size of the source
91 
92   Returns:      none
93  *---------------------------------------------------------------------------*/
GX_LoadOBJPltt(const void * pSrc,u32 offset,u32 szByte)94 void GX_LoadOBJPltt(const void *pSrc, u32 offset, u32 szByte)
95 {
96     SDK_NULL_ASSERT(pSrc);
97     SDK_ASSERT(offset + szByte <= HW_OBJ_PLTT_SIZE);
98     SDK_ALIGN2_ASSERT(offset);
99     SDK_ALIGN2_ASSERT(szByte);
100 
101     GXi_DmaCopy16(GXi_DmaId, pSrc, (void *)(HW_OBJ_PLTT + offset), szByte);
102 }
103 
104 
105 /*---------------------------------------------------------------------------*
106   Name:         GXS_LoadOBJPltt
107 
108   Description:  Transfers OBJ palettes to the standard OBJ palette RAM
109                 for the SUB 2D engine.
110                 pSrc, offset, and szByte must be 2-bytes aligned.
111 
112   Arguments:    pSrc             a pointer to the source of OBJ palettes
113                 offset           an offset to HW_DB_OBJ_PLTT
114                 szByte           the size of the source
115 
116   Returns:      none
117  *---------------------------------------------------------------------------*/
GXS_LoadOBJPltt(const void * pSrc,u32 offset,u32 szByte)118 void GXS_LoadOBJPltt(const void *pSrc, u32 offset, u32 szByte)
119 {
120     SDK_NULL_ASSERT(pSrc);
121     SDK_ASSERT(offset + szByte <= HW_DB_OBJ_PLTT_SIZE);
122     SDK_ALIGN2_ASSERT(offset);
123     SDK_ALIGN2_ASSERT(szByte);
124 
125     GXi_DmaCopy16(GXi_DmaId, pSrc, (void *)(HW_DB_OBJ_PLTT + offset), szByte);
126 }
127 
128 
129 /*---------------------------------------------------------------------------*
130   Name:         GX_LoadOAM
131 
132   Description:  Transfers object attributes to OAM for the MAIN 2D engine.
133                 pSrc, offset, and szByte must be 4-bytes aligned.
134 
135   Arguments:    pSrc             a pointer to the source of object attributes
136                 offset           an offset to HW_OAM
137                 szByte           the size of the source
138 
139   Returns:      none
140  *---------------------------------------------------------------------------*/
GX_LoadOAM(const void * pSrc,u32 offset,u32 szByte)141 void GX_LoadOAM(const void *pSrc, u32 offset, u32 szByte)
142 {
143     SDK_NULL_ASSERT(pSrc);
144     SDK_ASSERT(offset + szByte <= HW_OAM_SIZE);
145     SDK_ALIGN4_ASSERT(offset);
146     SDK_ALIGN4_ASSERT(szByte);
147 
148     GXi_DmaCopy32(GXi_DmaId, pSrc, (void *)(HW_OAM + offset), szByte);
149 }
150 
151 
152 /*---------------------------------------------------------------------------*
153   Name:         GXS_LoadOAM
154 
155   Description:  Transfers object attributes to OAM for the SUB 2D engine.
156                 pSrc, offset, and szByte must be 4-bytes aligned.
157 
158   Arguments:    pSrc             a pointer to the source of object attributes
159                 offset           an offset to HW_DB_OAM
160                 szByte           the size of the source
161 
162   Returns:      none
163  *---------------------------------------------------------------------------*/
GXS_LoadOAM(const void * pSrc,u32 offset,u32 szByte)164 void GXS_LoadOAM(const void *pSrc, u32 offset, u32 szByte)
165 {
166     SDK_NULL_ASSERT(pSrc);
167     SDK_ASSERT(offset + szByte <= HW_DB_OAM_SIZE);
168     SDK_ALIGN4_ASSERT(offset);
169     SDK_ALIGN4_ASSERT(szByte);
170 
171     GXi_DmaCopy32(GXi_DmaId, pSrc, (void *)(HW_DB_OAM + offset), szByte);
172 }
173 
174 
175 /*---------------------------------------------------------------------------*
176   Name:         GX_LoadOBJ
177 
178   Description:  Transfers OBJ to OBJ-VRAM for the MAIN 2D engine.
179                 pSrc, offset, and szByte must be 4-bytes aligned.
180 
181   Arguments:    pSrc             a pointer to the source of OBJ data
182                 offset           an offset to HW_OBJ_VRAM
183                 szByte           the size of the source
184 
185   Returns:      none
186  *---------------------------------------------------------------------------*/
GX_LoadOBJ(const void * pSrc,u32 offset,u32 szByte)187 void GX_LoadOBJ(const void *pSrc, u32 offset, u32 szByte)
188 {
189     u32     ptr;
190     SDK_NULL_ASSERT(pSrc);
191     SDK_ALIGN4_ASSERT(offset);
192     SDK_ALIGN4_ASSERT(szByte);
193     ptr = (u32)G2_GetOBJCharPtr();
194 
195     GX_RegionCheck_OBJ(ptr + offset, ptr + offset + szByte);
196 
197     GXi_DmaCopy32(GXi_DmaId, pSrc, (void *)(ptr + offset), szByte);
198 }
199 
200 
201 /*---------------------------------------------------------------------------*
202   Name:         GXS_LoadOBJ
203 
204   Description:  Transfers OBJ to OBJ-VRAM for the SUB 2D engine.
205                 pSrc, offset, and szByte must be 4-bytes aligned.
206 
207   Arguments:    pSrc             a pointer to the source of OBJ palettes
208                 offset           an offset to HW_DB_OBJ_VRAM
209                 szByte           the size of the source
210 
211   Returns:      none
212  *---------------------------------------------------------------------------*/
GXS_LoadOBJ(const void * pSrc,u32 offset,u32 szByte)213 void GXS_LoadOBJ(const void *pSrc, u32 offset, u32 szByte)
214 {
215     u32     ptr;
216     SDK_NULL_ASSERT(pSrc);
217     SDK_ALIGN4_ASSERT(offset);
218     SDK_ALIGN4_ASSERT(szByte);
219 
220     ptr = (u32)G2S_GetOBJCharPtr();
221 
222     GX_RegionCheck_SubOBJ(ptr + offset, ptr + offset + szByte);
223 
224     GXi_DmaCopy32(GXi_DmaId, pSrc, (void *)(ptr + offset), szByte);
225 }
226 
227 
228 /*---------------------------------------------------------------------------*
229   Name:         GX_LoadBG0Scr
230 
231   Description:  Transfers screen data to BG #0 screen area for the MAIN 2D engine.
232                 pSrc, offset, and szByte must be 2-bytes aligned.
233 
234   Arguments:    pSrc             a pointer to the source of the BG screen data
235                 offset           an offset to the start address of BG #0 screen area
236                 szByte           the size of the source
237 
238   Returns:      none
239  *---------------------------------------------------------------------------*/
GX_LoadBG0Scr(const void * pSrc,u32 offset,u32 szByte)240 void GX_LoadBG0Scr(const void *pSrc, u32 offset, u32 szByte)
241 {
242     u32     ptr;
243     SDK_NULL_ASSERT(pSrc);
244     SDK_ALIGN2_ASSERT(offset);
245     SDK_ALIGN2_ASSERT(szByte);
246     ptr = (u32)G2_GetBG0ScrPtr();
247 
248     GX_RegionCheck_BG(ptr + offset, ptr + offset + szByte);
249 
250     GXi_DmaCopy16(GXi_DmaId, pSrc, (void *)(ptr + offset), szByte);
251 }
252 
253 
254 /*---------------------------------------------------------------------------*
255   Name:         GXS_LoadBG0Scr
256 
257   Description:  Transfers screen data to BG #0 screen area for the SUB 2D engine.
258                 pSrc, offset, and szByte must be 2-bytes aligned.
259 
260   Arguments:    pSrc             a pointer to the source of the BG screen data
261                 offset           an offset to the start address of BG #0 screen area
262                 szByte           the size of the source
263 
264   Returns:      none
265  *---------------------------------------------------------------------------*/
GXS_LoadBG0Scr(const void * pSrc,u32 offset,u32 szByte)266 void GXS_LoadBG0Scr(const void *pSrc, u32 offset, u32 szByte)
267 {
268     u32     ptr;
269     SDK_NULL_ASSERT(pSrc);
270     SDK_ALIGN2_ASSERT(offset);
271     SDK_ALIGN2_ASSERT(szByte);
272     ptr = (u32)G2S_GetBG0ScrPtr();
273 
274     GX_RegionCheck_SubBG(ptr + offset, ptr + offset + szByte);
275 
276     GXi_DmaCopy16(GXi_DmaId, pSrc, (void *)(ptr + offset), szByte);
277 }
278 
279 
280 /*---------------------------------------------------------------------------*
281   Name:         GX_LoadBG1Scr
282 
283   Description:  Transfers screen data to BG #1 screen area for the MAIN 2D engine.
284                 pSrc, offset, and szByte must be 2-bytes aligned.
285 
286   Arguments:    pSrc             a pointer to the source of the BG screen data
287                 offset           an offset to the start address of BG #1 screen area
288                 szByte           the size of the source
289 
290   Returns:      none
291  *---------------------------------------------------------------------------*/
GX_LoadBG1Scr(const void * pSrc,u32 offset,u32 szByte)292 void GX_LoadBG1Scr(const void *pSrc, u32 offset, u32 szByte)
293 {
294     u32     ptr;
295     SDK_NULL_ASSERT(pSrc);
296     SDK_ALIGN2_ASSERT(offset);
297     SDK_ALIGN2_ASSERT(szByte);
298 
299     ptr = (u32)G2_GetBG1ScrPtr();
300 
301     GX_RegionCheck_BG(ptr + offset, ptr + offset + szByte);
302 
303     GXi_DmaCopy16(GXi_DmaId, pSrc, (void *)(ptr + offset), szByte);
304 }
305 
306 
307 /*---------------------------------------------------------------------------*
308   Name:         GXS_LoadBG1Scr
309 
310   Description:  Transfers screen data to BG #1 screen area for the SUB 2D engine.
311                 pSrc, offset, and szByte must be 2-bytes aligned.
312 
313   Arguments:    pSrc             a pointer to the source of the BG screen data
314                 offset           an offset to the start address of BG #1 screen area
315                 szByte           the size of the source
316 
317   Returns:      none
318  *---------------------------------------------------------------------------*/
GXS_LoadBG1Scr(const void * pSrc,u32 offset,u32 szByte)319 void GXS_LoadBG1Scr(const void *pSrc, u32 offset, u32 szByte)
320 {
321     u32     ptr;
322     SDK_NULL_ASSERT(pSrc);
323     SDK_ALIGN2_ASSERT(offset);
324     SDK_ALIGN2_ASSERT(szByte);
325 
326     ptr = (u32)G2S_GetBG1ScrPtr();
327 
328     GX_RegionCheck_SubBG(ptr + offset, ptr + offset + szByte);
329 
330     GXi_DmaCopy16(GXi_DmaId, pSrc, (void *)(ptr + offset), szByte);
331 }
332 
333 
334 /*---------------------------------------------------------------------------*
335   Name:         GX_LoadBG2Scr
336 
337   Description:  Transfers screen data to BG #2 screen area for the MAIN 2D engine.
338                 pSrc, offset, and szByte must be 2-bytes aligned.
339 
340   Arguments:    pSrc             a pointer to the source of the BG screen data
341                 offset           an offset to the start address of BG #2 screen area
342                 szByte           the size of the source
343 
344   Returns:      none
345  *---------------------------------------------------------------------------*/
GX_LoadBG2Scr(const void * pSrc,u32 offset,u32 szByte)346 void GX_LoadBG2Scr(const void *pSrc, u32 offset, u32 szByte)
347 {
348     u32     ptr;
349     SDK_NULL_ASSERT(pSrc);
350     SDK_ALIGN2_ASSERT(offset);
351     SDK_ALIGN2_ASSERT(szByte);
352     ptr = (u32)G2_GetBG2ScrPtr();
353 
354     GX_RegionCheck_BG(ptr + offset, ptr + offset + szByte);
355 
356     GXi_DmaCopy16(GXi_DmaId, pSrc, (void *)(ptr + offset), szByte);
357 }
358 
359 
360 /*---------------------------------------------------------------------------*
361   Name:         GXS_LoadBG2Scr
362 
363   Description:  Transfers screen data to BG #2 screen area for the SUB 2D engine.
364                 pSrc, offset, and szByte must be 2-bytes aligned.
365 
366   Arguments:    pSrc             a pointer to the source of the BG screen data
367                 offset           an offset to the start address of BG #2 screen area
368                 szByte           the size of the source
369 
370   Returns:      none
371  *---------------------------------------------------------------------------*/
GXS_LoadBG2Scr(const void * pSrc,u32 offset,u32 szByte)372 void GXS_LoadBG2Scr(const void *pSrc, u32 offset, u32 szByte)
373 {
374     u32     ptr;
375     SDK_NULL_ASSERT(pSrc);
376     SDK_ALIGN2_ASSERT(offset);
377     SDK_ALIGN2_ASSERT(szByte);
378 
379     ptr = (u32)G2S_GetBG2ScrPtr();
380 
381     GX_RegionCheck_SubBG(ptr + offset, ptr + offset + szByte);
382 
383     GXi_DmaCopy16(GXi_DmaId, pSrc, (void *)(ptr + offset), szByte);
384 }
385 
386 
387 /*---------------------------------------------------------------------------*
388   Name:         GX_LoadBG3Scr
389 
390   Description:  Transfers screen data to BG #3 screen area for the MAIN 2D engine.
391                 pSrc, offset, and szByte must be 2-bytes aligned.
392 
393   Arguments:    pSrc             a pointer to the source of the BG screen data
394                 offset           an offset to the start address of BG #3 screen area
395                 szByte           the size of the source
396 
397   Returns:      none
398  *---------------------------------------------------------------------------*/
GX_LoadBG3Scr(const void * pSrc,u32 offset,u32 szByte)399 void GX_LoadBG3Scr(const void *pSrc, u32 offset, u32 szByte)
400 {
401     u32     ptr;
402     SDK_NULL_ASSERT(pSrc);
403     SDK_ALIGN2_ASSERT(offset);
404     SDK_ALIGN2_ASSERT(szByte);
405 
406     ptr = (u32)G2_GetBG3ScrPtr();
407 
408     GX_RegionCheck_BG(ptr + offset, ptr + offset + szByte);
409 
410     GXi_DmaCopy16(GXi_DmaId, pSrc, (void *)(ptr + offset), szByte);
411 }
412 
413 
414 /*---------------------------------------------------------------------------*
415   Name:         GXS_LoadBG3Scr
416 
417   Description:  Transfers screen data to BG #3 screen area for the SUB 2D engine.
418                 pSrc, offset, and szByte must be 2-bytes aligned.
419 
420   Arguments:    pSrc             a pointer to the source of the BG screen data
421                 offset           an offset to the start address of BG #3 screen area
422                 szByte           the size of the source
423 
424   Returns:      none
425  *---------------------------------------------------------------------------*/
GXS_LoadBG3Scr(const void * pSrc,u32 offset,u32 szByte)426 void GXS_LoadBG3Scr(const void *pSrc, u32 offset, u32 szByte)
427 {
428     u32     ptr;
429     SDK_NULL_ASSERT(pSrc);
430     SDK_ALIGN2_ASSERT(offset);
431     SDK_ALIGN2_ASSERT(szByte);
432 
433     ptr = (u32)G2S_GetBG3ScrPtr();
434 
435     GX_RegionCheck_SubBG(ptr + offset, ptr + offset + szByte);
436 
437     GXi_DmaCopy16(GXi_DmaId, pSrc, (void *)(ptr + offset), szByte);
438 }
439 
440 
441 /*---------------------------------------------------------------------------*
442   Name:         GX_LoadBG0Char
443 
444   Description:  Transfers character data to BG #0 character area for the MAIN
445                 2D engine. pSrc, offset, and szByte must be 4-bytes aligned.
446 
447   Arguments:    pSrc             a pointer to the source of the BG character data
448                 offset           an offset to the start address of BG #0 character area
449                 szByte           the size of the source
450 
451   Returns:      none
452  *---------------------------------------------------------------------------*/
GX_LoadBG0Char(const void * pSrc,u32 offset,u32 szByte)453 void GX_LoadBG0Char(const void *pSrc, u32 offset, u32 szByte)
454 {
455     u32     ptr;
456     SDK_NULL_ASSERT(pSrc);
457     SDK_ALIGN4_ASSERT(offset);
458     SDK_ALIGN4_ASSERT(szByte);
459 
460     ptr = (u32)G2_GetBG0CharPtr();
461 
462     GX_RegionCheck_BG(ptr + offset, ptr + offset + szByte);
463 
464     GXi_DmaCopy32(GXi_DmaId, pSrc, (void *)(ptr + offset), szByte);
465 }
466 
467 
468 /*---------------------------------------------------------------------------*
469   Name:         GXS_LoadBG0Char
470 
471   Description:  Transfers character data to BG #0 character area for the SUB
472                 2D engine. pSrc, offset, and szByte must be 4-bytes aligned.
473 
474   Arguments:    pSrc             a pointer to the source of the BG character data
475                 offset           an offset to the start address of BG #0 character area
476                 szByte           the size of the source
477 
478   Returns:      none
479  *---------------------------------------------------------------------------*/
GXS_LoadBG0Char(const void * pSrc,u32 offset,u32 szByte)480 void GXS_LoadBG0Char(const void *pSrc, u32 offset, u32 szByte)
481 {
482     u32     ptr;
483     SDK_NULL_ASSERT(pSrc);
484     SDK_ALIGN4_ASSERT(offset);
485     SDK_ALIGN4_ASSERT(szByte);
486 
487     ptr = (u32)G2S_GetBG0CharPtr();
488 
489     GX_RegionCheck_SubBG(ptr + offset, ptr + offset + szByte);
490 
491     GXi_DmaCopy32(GXi_DmaId, pSrc, (void *)(ptr + offset), szByte);
492 }
493 
494 
495 /*---------------------------------------------------------------------------*
496   Name:         GX_LoadBG1Char
497 
498   Description:  Transfers character data to BG #1 character area for the MAIN
499                 2D engine. pSrc, offset, and szByte must be 4-bytes aligned.
500 
501   Arguments:    pSrc             a pointer to the source of the BG character data
502                 offset           an offset to the start address of BG #1 character area
503                 szByte           the size of the source
504 
505   Returns:      none
506  *---------------------------------------------------------------------------*/
GX_LoadBG1Char(const void * pSrc,u32 offset,u32 szByte)507 void GX_LoadBG1Char(const void *pSrc, u32 offset, u32 szByte)
508 {
509     u32     ptr;
510     SDK_NULL_ASSERT(pSrc);
511     SDK_ALIGN4_ASSERT(offset);
512     SDK_ALIGN4_ASSERT(szByte);
513 
514     ptr = (u32)G2_GetBG1CharPtr();
515 
516     GX_RegionCheck_BG(ptr + offset, ptr + offset + szByte);
517 
518     GXi_DmaCopy32(GXi_DmaId, pSrc, (void *)(ptr + offset), szByte);
519 }
520 
521 
522 /*---------------------------------------------------------------------------*
523   Name:         GXS_LoadBG1Char
524 
525   Description:  Transfers character data to BG #1 character area for the SUB
526                 2D engine. pSrc, offset, and szByte must be 4-bytes aligned.
527 
528   Arguments:    pSrc             a pointer to the source of the BG character data
529                 offset           an offset to the start address of BG #1 character area
530                 szByte           the size of the source
531 
532   Returns:      none
533  *---------------------------------------------------------------------------*/
GXS_LoadBG1Char(const void * pSrc,u32 offset,u32 szByte)534 void GXS_LoadBG1Char(const void *pSrc, u32 offset, u32 szByte)
535 {
536     u32     ptr;
537     SDK_NULL_ASSERT(pSrc);
538     SDK_ALIGN4_ASSERT(offset);
539     SDK_ALIGN4_ASSERT(szByte);
540 
541     ptr = (u32)G2S_GetBG1CharPtr();
542 
543     GX_RegionCheck_SubBG(ptr + offset, ptr + offset + szByte);
544 
545     GXi_DmaCopy32(GXi_DmaId, pSrc, (void *)(ptr + offset), szByte);
546 }
547 
548 
549 /*---------------------------------------------------------------------------*
550   Name:         GX_LoadBG2Char
551 
552   Description:  Transfers character data to BG #2 character area for the MAIN
553                 2D engine. pSrc, offset, and szByte must be 4-bytes aligned.
554 
555   Arguments:    pSrc             a pointer to the source of the BG character data
556                 offset           an offset to the start address of BG #2 character area
557                 szByte           the size of the source
558 
559   Returns:      none
560  *---------------------------------------------------------------------------*/
GX_LoadBG2Char(const void * pSrc,u32 offset,u32 szByte)561 void GX_LoadBG2Char(const void *pSrc, u32 offset, u32 szByte)
562 {
563     u32     ptr;
564     SDK_NULL_ASSERT(pSrc);
565     SDK_ALIGN4_ASSERT(offset);
566     SDK_ALIGN4_ASSERT(szByte);
567 
568     ptr = (u32)G2_GetBG2CharPtr();
569 
570     GX_RegionCheck_BG(ptr + offset, ptr + offset + szByte);
571 
572     GXi_DmaCopy32(GXi_DmaId, pSrc, (void *)(ptr + offset), szByte);
573 }
574 
575 
576 /*---------------------------------------------------------------------------*
577   Name:         GXS_LoadBG2Char
578 
579   Description:  Transfers character data to BG #2 character area for the SUB
580                 2D engine. pSrc, offset, and szByte must be 4-bytes aligned.
581 
582   Arguments:    pSrc             a pointer to the source of the BG character data
583                 offset           an offset to the start address of BG #2 character area
584                 szByte           the size of the source
585 
586   Returns:      none
587  *---------------------------------------------------------------------------*/
GXS_LoadBG2Char(const void * pSrc,u32 offset,u32 szByte)588 void GXS_LoadBG2Char(const void *pSrc, u32 offset, u32 szByte)
589 {
590     u32     ptr;
591     SDK_NULL_ASSERT(pSrc);
592     SDK_ALIGN4_ASSERT(offset);
593     SDK_ALIGN4_ASSERT(szByte);
594 
595     ptr = (u32)G2S_GetBG2CharPtr();
596 
597     GX_RegionCheck_SubBG(ptr + offset, ptr + offset + szByte);
598 
599     GXi_DmaCopy32(GXi_DmaId, pSrc, (void *)(ptr + offset), szByte);
600 }
601 
602 
603 /*---------------------------------------------------------------------------*
604   Name:         GX_LoadBG3Char
605 
606   Description:  Transfers character data to BG #3 character area for the MAIN
607                 2D engine. pSrc, offset, and szByte must be 4-bytes aligned.
608 
609   Arguments:    pSrc             a pointer to the source of the BG character data
610                 offset           an offset to the start address of BG #3 character area
611                 szByte           the size of the source
612 
613   Returns:      none
614  *---------------------------------------------------------------------------*/
GX_LoadBG3Char(const void * pSrc,u32 offset,u32 szByte)615 void GX_LoadBG3Char(const void *pSrc, u32 offset, u32 szByte)
616 {
617     u32     ptr;
618     SDK_NULL_ASSERT(pSrc);
619     SDK_ALIGN4_ASSERT(offset);
620     SDK_ALIGN4_ASSERT(szByte);
621 
622     ptr = (u32)G2_GetBG3CharPtr();
623 
624     GX_RegionCheck_BG(ptr + offset, ptr + offset + szByte);
625 
626     GXi_DmaCopy32(GXi_DmaId, pSrc, (void *)(ptr + offset), szByte);
627 }
628 
629 
630 /*---------------------------------------------------------------------------*
631   Name:         GXS_LoadBG3Char
632 
633   Description:  Transfers character data to BG #3 character area for the SUB
634                 2D engine. pSrc, offset, and szByte must be 4-bytes aligned.
635 
636   Arguments:    pSrc             a pointer to the source of the BG character data
637                 offset           an offset to the start address of BG #3 character area
638                 szByte           the size of the source
639 
640   Returns:      none
641  *---------------------------------------------------------------------------*/
GXS_LoadBG3Char(const void * pSrc,u32 offset,u32 szByte)642 void GXS_LoadBG3Char(const void *pSrc, u32 offset, u32 szByte)
643 {
644     u32     ptr;
645     SDK_NULL_ASSERT(pSrc);
646     SDK_ALIGN4_ASSERT(offset);
647     SDK_ALIGN4_ASSERT(szByte);
648 
649     ptr = (u32)G2S_GetBG3CharPtr();
650 
651     GX_RegionCheck_SubBG(ptr + offset, ptr + offset + szByte);
652 
653     GXi_DmaCopy32(GXi_DmaId, pSrc, (void *)(ptr + offset), szByte);
654 }
655 
656 
657 //----------------------------------------------------------------------------
658 // Internal states for GX_BeginLoadBGExtPltt, GX_LoadBGExtPltt,
659 // and GX_EndLoadBGExtPltt
660 //----------------------------------------------------------------------------
661 static GXVRamBGExtPltt sBGExtPltt = (GXVRamBGExtPltt)(0);
662 static u32 sBGExtPlttLCDCBlk = 0;
663 static u32 sBGExtPlttLCDCOffset = 0;
664 
665 
666 /*---------------------------------------------------------------------------*
667   Name:         GX_BeginLoadBGExtPltt
668 
669   Description:  Remaps the banks for MAIN 2D engine's BG extended palettes
670                 onto LCDC space, and prepares for palettes transfer
671                 by GX_LoadBGExtPltt.
672 
673   Arguments:    none
674 
675   Returns:      none
676  *---------------------------------------------------------------------------*/
GX_BeginLoadBGExtPltt()677 void GX_BeginLoadBGExtPltt()
678 {
679     SDK_ASSERT(0 == sBGExtPltt && 0 == sBGExtPlttLCDCBlk && 0 == sBGExtPlttLCDCOffset);
680 
681     // BGExtPltt slots to LCDC
682     sBGExtPltt = GX_ResetBankForBGExtPltt();
683 
684     switch (sBGExtPltt)
685     {
686     case GX_VRAM_BGEXTPLTT_0123_E:
687         sBGExtPlttLCDCBlk = HW_LCDC_VRAM_E;
688         sBGExtPlttLCDCOffset = 0;
689         break;
690 
691     case GX_VRAM_BGEXTPLTT_23_G:
692         sBGExtPlttLCDCBlk = HW_LCDC_VRAM_G;
693         sBGExtPlttLCDCOffset = 0x4000;
694         break;
695 
696     case GX_VRAM_BGEXTPLTT_0123_FG:
697     case GX_VRAM_BGEXTPLTT_01_F:
698         sBGExtPlttLCDCBlk = HW_LCDC_VRAM_F;
699         sBGExtPlttLCDCOffset = 0;
700         break;
701 
702     case GX_VRAM_BGEXTPLTT_NONE:
703         break;
704 
705     default:
706         SDK_INTERNAL_ERROR("unknown case 0x%x", sBGExtPltt);
707         break;
708     }
709 }
710 
711 
712 /*---------------------------------------------------------------------------*
713   Name:         GX_LoadBGExtPltt
714 
715   Description:  Transfers BG extended palettes to the LCDC space which is
716                 remapped from BG extended palette slots. This function must be
717                 called between GX_BeginLoadBGExtPltt and GX_EndLoadBGExtPltt.
718                 pSrc, destSlotAddr, and szByte must be 4-bytes aligned.
719 
720   Arguments:    pSrc             a pointer to the source of BG extended palettes
721                 destSlotAddr     a destination address on the slots
722                 szByte           the size of the source
723 
724   Returns:      none
725  *---------------------------------------------------------------------------*/
GX_LoadBGExtPltt(const void * pSrc,u32 destSlotAddr,u32 szByte)726 void GX_LoadBGExtPltt(const void *pSrc, u32 destSlotAddr, u32 szByte)
727 {
728     SDK_NULL_ASSERT(pSrc);
729     SDK_ASSERT(sBGExtPltt != GX_VRAM_BGEXTPLTT_NONE);
730     SDK_ASSERT(sBGExtPlttLCDCBlk != 0);
731     SDK_ALIGN4_ASSERT(szByte);
732     SDK_ALIGN4_ASSERT(destSlotAddr);
733     SDK_ALIGN4_ASSERT(pSrc);
734 
735 #ifdef SDK_DEBUG
736     switch (sBGExtPltt)
737     {
738     case GX_VRAM_BGEXTPLTT_0123_E:
739     case GX_VRAM_BGEXTPLTT_0123_FG:
740         SDK_ASSERTMSG(destSlotAddr + szByte <= 0x8000,
741                       "Illegal address/size specified(0x%5x->0x%5x)",
742                       destSlotAddr, destSlotAddr + szByte);
743         break;
744 
745     case GX_VRAM_BGEXTPLTT_23_G:
746         SDK_ASSERTMSG(destSlotAddr + szByte <= 0x8000,
747                       "Illegal address/size specified(0x%5x->0x%5x)",
748                       destSlotAddr, destSlotAddr + szByte);
749         SDK_ASSERTMSG(destSlotAddr >= 0x4000,
750                       "BGExtPltt 0x0000 - 0x4000 not available(0x%5x->0x%5x)",
751                       destSlotAddr, destSlotAddr + szByte);
752         break;
753 
754     case GX_VRAM_BGEXTPLTT_01_F:
755         SDK_ASSERTMSG(destSlotAddr + szByte <= 0x4000,
756                       "BGExtPltt 0x4000 - 0x8000 not available(0x%5x->0x%5x)",
757                       destSlotAddr, destSlotAddr + szByte);
758         break;
759 
760     default:
761         SDK_INTERNAL_ERROR("unknown case 0x%x", sBGExtPltt);
762         break;
763     }
764 #endif
765     GXi_DmaCopy32Async(GXi_DmaId,
766                        pSrc,
767                        (void *)(sBGExtPlttLCDCBlk + destSlotAddr - sBGExtPlttLCDCOffset),
768                        szByte, NULL, NULL);
769 }
770 
771 
772 /*---------------------------------------------------------------------------*
773   Name:         GX_EndLoadBGExtPltt
774 
775   Description:  Restores the banks remapped by GX_BeginLoadBGExtPltt.
776                 This function is called after all the transfer is done.
777 
778   Arguments:    none
779 
780   Returns:      none
781  *---------------------------------------------------------------------------*/
GX_EndLoadBGExtPltt()782 void GX_EndLoadBGExtPltt()
783 {
784     GXi_WaitDma(GXi_DmaId);
785 
786     // Restore banks for BGExtPltt
787     GX_SetBankForBGExtPltt(sBGExtPltt);
788 
789     sBGExtPltt = (GXVRamBGExtPltt)0;
790     sBGExtPlttLCDCBlk = 0;
791     sBGExtPlttLCDCOffset = 0;
792 }
793 
794 
795 //----------------------------------------------------------------------------
796 // Internal states for GX_BeginLoadOBJExtPltt, GX_LoadOBJExtPltt,
797 // and GX_EndLoadOBJExtPltt
798 //----------------------------------------------------------------------------
799 static GXVRamOBJExtPltt sOBJExtPltt = (GXVRamOBJExtPltt)(0);
800 static u32 sOBJExtPlttLCDCBlk = 0;
801 
802 
803 /*---------------------------------------------------------------------------*
804   Name:         GX_BeginLoadOBJExtPltt
805 
806   Description:  Remaps the banks for MAIN 2D engine's OBJ extended palettes
807                 onto LCDC space, and prepares for palettes transfer
808                 by GX_LoadOBJExtPltt.
809 
810   Arguments:    none
811 
812   Returns:      none
813  *---------------------------------------------------------------------------*/
GX_BeginLoadOBJExtPltt()814 void GX_BeginLoadOBJExtPltt()
815 {
816     SDK_ASSERT(0 == sOBJExtPltt && 0 == sOBJExtPlttLCDCBlk);
817 
818     // OBJExtPltt slot to LCDC
819     sOBJExtPltt = GX_ResetBankForOBJExtPltt();
820 
821     switch (sOBJExtPltt)
822     {
823     case GX_VRAM_OBJEXTPLTT_0_F:
824         sOBJExtPlttLCDCBlk = HW_LCDC_VRAM_F;
825         break;
826 
827     case GX_VRAM_OBJEXTPLTT_0_G:
828         sOBJExtPlttLCDCBlk = HW_LCDC_VRAM_G;
829         break;
830 
831     case GX_VRAM_OBJEXTPLTT_NONE:
832         break;
833 
834     default:
835         SDK_INTERNAL_ERROR("unknown case 0x%x", sOBJExtPltt);
836         break;
837     };
838 }
839 
840 
841 /*---------------------------------------------------------------------------*
842   Name:         GX_LoadOBJExtPltt
843 
844   Description:  Transfers OBJ extended palettes to the LCDC space which is
845                 remapped from OBJ extended palette slots. This function must be
846                 called between GX_BeginLoadOBJExtPltt and GX_EndLoadOBJExtPltt.
847                 pSrc, destSlotAddr, and szByte must be 4-bytes aligned.
848 
849   Arguments:    pSrc             a pointer to the source of OBJ extended palettes
850                 destSlotAddr     a destination address on the slots
851                 szByte           the size of the source
852 
853   Returns:      none
854  *---------------------------------------------------------------------------*/
GX_LoadOBJExtPltt(const void * pSrc,u32 destSlotAddr,u32 szByte)855 void GX_LoadOBJExtPltt(const void *pSrc, u32 destSlotAddr, u32 szByte)
856 {
857     SDK_NULL_ASSERT(pSrc);
858     SDK_ASSERT(GX_VRAM_OBJEXTPLTT_NONE != sOBJExtPltt);
859     SDK_ASSERT(0 != sOBJExtPlttLCDCBlk);
860     SDK_ALIGN4_ASSERT(szByte);
861     SDK_ALIGN4_ASSERT(pSrc);
862     SDK_ALIGN4_ASSERT(destSlotAddr);
863     SDK_ASSERT(destSlotAddr + szByte <= 0x2000);        // size of OBJExtPltt slot 0
864 
865     GXi_DmaCopy32Async(GXi_DmaId,
866                        pSrc, (void *)(sOBJExtPlttLCDCBlk + destSlotAddr), szByte, NULL, NULL);
867 }
868 
869 
870 /*---------------------------------------------------------------------------*
871   Name:         GX_EndLoadOBJExtPltt
872 
873   Description:  Restores the banks remapped by GX_BeginLoadOBJExtPltt.
874                 This function is called after all the transfer is done.
875 
876   Arguments:    none
877 
878   Returns:      none
879  *---------------------------------------------------------------------------*/
GX_EndLoadOBJExtPltt()880 void GX_EndLoadOBJExtPltt()
881 {
882     GXi_WaitDma(GXi_DmaId);
883 
884     // Restore banks for OBJExtPltt
885     GX_SetBankForOBJExtPltt(sOBJExtPltt);
886 
887     sOBJExtPltt = (GXVRamOBJExtPltt)0;
888     sOBJExtPlttLCDCBlk = 0;
889 }
890 
891 
892 //----------------------------------------------------------------------------
893 // Internal states for GXS_BeginLoadBGExtPltt, GXS_LoadBGExtPltt,
894 // and GXS_EndLoadBGExtPltt
895 //----------------------------------------------------------------------------
896 static GXVRamSubBGExtPltt sSubBGExtPltt = (GXVRamSubBGExtPltt)(0);
897 
898 
899 /*---------------------------------------------------------------------------*
900   Name:         GXS_BeginLoadBGExtPltt
901 
902   Description:  Remaps the banks for SUB 2D engine's BG extended palettes
903                 onto LCDC space, and prepares for palettes transfer
904                 by GXS_LoadBGExtPltt.
905 
906   Arguments:    none
907 
908   Returns:      none
909  *---------------------------------------------------------------------------*/
GXS_BeginLoadBGExtPltt()910 void GXS_BeginLoadBGExtPltt()
911 {
912     SDK_ASSERT(0 == sSubBGExtPltt);
913 
914     // BGExtPltt slot to LCDC
915     sSubBGExtPltt = GX_ResetBankForSubBGExtPltt();
916 
917     SDK_ASSERTMSG(GX_VRAM_SUB_BGEXTPLTT_0123_H == sSubBGExtPltt, "Sub BGExtPltt not allocated");
918 }
919 
920 
921 /*---------------------------------------------------------------------------*
922   Name:         GXS_LoadBGExtPltt
923 
924   Description:  Transfers BG extended palettes to the LCDC space which is
925                 remapped from BG extended palette slots. This function must be
926                 called between GXS_BeginLoadBGExtPltt and GXS_EndLoadBGExtPltt.
927                 pSrc, destSlotAddr, and szByte must be 4-bytes aligned.
928 
929   Arguments:    pSrc             a pointer to the source of BG extended palettes
930                 destSlotAddr     a destination address on the slots
931                 szByte           the size of the source
932 
933   Returns:      none
934  *---------------------------------------------------------------------------*/
GXS_LoadBGExtPltt(const void * pSrc,u32 destSlotAddr,u32 szByte)935 void GXS_LoadBGExtPltt(const void *pSrc, u32 destSlotAddr, u32 szByte)
936 {
937     SDK_NULL_ASSERT(pSrc);
938     SDK_ASSERT(GX_VRAM_SUB_BGEXTPLTT_0123_H == sSubBGExtPltt);
939     SDK_ALIGN4_ASSERT(pSrc);
940     SDK_ALIGN4_ASSERT(destSlotAddr);
941     SDK_ALIGN4_ASSERT(szByte);
942 
943     SDK_ASSERTMSG(destSlotAddr + szByte <= 0x8000,
944                   "Illegal address/size specified(0x%5x->0x%5x)",
945                   destSlotAddr, destSlotAddr + szByte);
946 
947     GXi_DmaCopy32Async(GXi_DmaId,
948                        pSrc, (void *)(HW_LCDC_VRAM_H + destSlotAddr), szByte, NULL, NULL);
949 }
950 
951 
952 /*---------------------------------------------------------------------------*
953   Name:         GXS_EndLoadBGExtPltt
954 
955   Description:  Restores the banks remapped by GXS_BeginLoadBGExtPltt.
956                 This function is called after all the transfer is done.
957 
958   Arguments:    none
959 
960   Returns:      none
961  *---------------------------------------------------------------------------*/
GXS_EndLoadBGExtPltt()962 void GXS_EndLoadBGExtPltt()
963 {
964     GXi_WaitDma(GXi_DmaId);
965 
966     // Restore banks for SubBGExtPltt
967     GX_SetBankForSubBGExtPltt(sSubBGExtPltt);
968 
969     sSubBGExtPltt = (GXVRamSubBGExtPltt)0;
970 }
971 
972 
973 //----------------------------------------------------------------------------
974 // Internal states for GXS_BeginLoadOBJExtPltt, GXS_LoadOBJExtPltt,
975 // and GXS_EndLoadOBJExtPltt
976 //----------------------------------------------------------------------------
977 static GXVRamSubOBJExtPltt sSubOBJExtPltt = (GXVRamSubOBJExtPltt)(0);
978 
979 
980 /*---------------------------------------------------------------------------*
981   Name:         GXS_BeginLoadOBJExtPltt
982 
983   Description:  Remaps the banks for SUB 2D engine's OBJ extended palettes
984                 onto LCDC space, and prepares for palettes transfer
985                 by GXS_LoadOBJExtPltt.
986 
987   Arguments:    none
988 
989   Returns:      none
990  *---------------------------------------------------------------------------*/
GXS_BeginLoadOBJExtPltt()991 void GXS_BeginLoadOBJExtPltt()
992 {
993     SDK_ASSERT(0 == sSubOBJExtPltt);
994 
995     // BGExtPltt slot to LCDC
996     sSubOBJExtPltt = GX_ResetBankForSubOBJExtPltt();
997 
998     SDK_ASSERTMSG(GX_VRAM_SUB_OBJEXTPLTT_0_I == sSubOBJExtPltt, "Sub OBJExtPltt not allocated");
999 }
1000 
1001 
1002 /*---------------------------------------------------------------------------*
1003   Name:         GXS_LoadOBJExtPltt
1004 
1005   Description:  Transfers OBJ extended palettes to the LCDC space which is
1006                 remapped from OBJ extended palette slots. This function must be
1007                 called between GXS_BeginLoadOBJExtPltt and GXS_EndLoadOBJExtPltt.
1008                 pSrc, destSlotAddr, and szByte must be 4-bytes aligned.
1009 
1010   Arguments:    pSrc             a pointer to the source of OBJ extended palettes
1011                 destSlotAddr     a destination address on the slots
1012                 szByte           the size of the source
1013 
1014   Returns:      none
1015  *---------------------------------------------------------------------------*/
GXS_LoadOBJExtPltt(const void * pSrc,u32 destSlotAddr,u32 szByte)1016 void GXS_LoadOBJExtPltt(const void *pSrc, u32 destSlotAddr, u32 szByte)
1017 {
1018     SDK_NULL_ASSERT(pSrc);
1019     SDK_ASSERT(GX_VRAM_SUB_OBJEXTPLTT_0_I == sSubOBJExtPltt);
1020     SDK_ALIGN4_ASSERT(pSrc);
1021     SDK_ALIGN4_ASSERT(destSlotAddr);
1022     SDK_ALIGN4_ASSERT(szByte);
1023 
1024     SDK_ASSERTMSG(destSlotAddr + szByte <= 0x2000,
1025                   "Illegal address/size specified(0x%5x->0x%5x)",
1026                   destSlotAddr, destSlotAddr + szByte);
1027 
1028     GXi_DmaCopy32Async(GXi_DmaId,
1029                        pSrc, (void *)(HW_LCDC_VRAM_I + destSlotAddr), szByte, NULL, NULL);
1030 }
1031 
1032 
1033 /*---------------------------------------------------------------------------*
1034   Name:         GXS_EndLoadOBJExtPltt
1035 
1036   Description:  Restores the banks remapped by GXS_BeginLoadOBJExtPltt.
1037                 This function is called after all the transfer is done.
1038 
1039   Arguments:    none
1040 
1041   Returns:      none
1042  *---------------------------------------------------------------------------*/
GXS_EndLoadOBJExtPltt()1043 void GXS_EndLoadOBJExtPltt()
1044 {
1045     GXi_WaitDma(GXi_DmaId);
1046 
1047     // Restore banks for OBJExtPltt
1048     GX_SetBankForSubOBJExtPltt(sSubOBJExtPltt);
1049 
1050     sSubOBJExtPltt = (GXVRamSubOBJExtPltt)0;
1051 }
1052