1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - GX - demos - UnitTours/2D_Oam_Translucent
3   File:     main.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-10-30#$
14   $Rev: 9157 $
15   $Author: okubata_ryoma $
16  *---------------------------------------------------------------------------*/
17 
18 //---------------------------------------------------------------------------
19 // A sample that uses OBJ with alpha blending effect
20 //
21 // This sample displays two spheres
22 // One of the spheres is transparent
23 //
24 // USAGE:
25 //   UP, DOWN   : Change level of transparency
26 //
27 // HOWTO:
28 // 1. Set GX_OAM_MODE_XLU to OAM attribute to use transparent OBJ
29 // 2. Set transparent object with G2_SetBlendAlpha
30 //---------------------------------------------------------------------------
31 
32 #ifdef SDK_TWL
33 #include <twl.h>
34 #else
35 #include <nitro.h>
36 #endif
37 #include "DEMO.h"
38 #include "data.h"
39 //---------------------------------------------------------------------------
40 //  Summary:
41 //        OAM buffer region
42 //---------------------------------------------------------------------------
43 static GXOamAttr s_OAMBuffer[128];
44 
45 //---------------------------------------------------------------------------
46 //  Summary:
47 //        VBlank interrupt process
48 //  Description:
49 //        Enables a flag that confirms that a V-Blank interrupt has been performed
50 //
51 //        The following steps will be performed during common initialization (DEMOInitCommon), causing this function to be called during V-Blanks
52 //        * Select IRQ interrupt (OS_SetIrqMask)
53 //        * Register this function, which performs IRQ interrupts (OS_SetIRQFunction)
54 //        * Enable IRQ interrupts (OS_EnableIrq)
55 //
56 //---------------------------------------------------------------------------
VBlankIntr(void)57 void VBlankIntr(void)
58 {
59     OS_SetIrqCheckFlag(OS_IE_V_BLANK); // Sets a V-Blank interrupt confirmation flag
60 }
61 
62 //---------------------------------------------------------------------------
63 //  Summary:
64 //        Display translucent OBJs
65 //  Description:
66 //        Displays translucent OBJ characters
67 //        OBJs displayed on the left are displayed normally. OBJs displayed on the right are translucent.
68 //      OBJ
69 //  Controls:
70 //        UP, DOWN: Blending factor of the translucent OBJ can be changed
71 //---------------------------------------------------------------------------
72 #ifdef SDK_TWL
TwlMain(void)73 void TwlMain(void)
74 #else
75 void NitroMain(void)
76 #endif
77 {
78     int     eva = 12;
79 
80     //---------------------
81     // Initialization
82     //---------------------
83     DEMOInitCommon();
84     DEMOInitVRAM();
85     DEMOInitDisplayOBJOnly();
86 
87     /* Load character data and palette data */
88     GX_LoadOBJ(d_64_256_obj_schDT, 0, sizeof(d_64_256_obj_schDT));
89     GX_LoadOBJPltt(d_64_256_obj_sclDT, 0, sizeof(d_64_256_obj_sclDT));
90 
91     DEMOStartDisplay();
92 
93     //---------------------
94     //  Main loop
95     //---------------------
96     while (1)
97     {
98         /* Load pad information */
99         DEMOReadKey();
100 #ifdef SDK_AUTOTEST                    // Code for auto-test
101         {
102             const EXTKeys keys[8] = { {PAD_KEY_DOWN, 5}, {0, 0} };
103             EXT_AutoKeys(keys, &gKeyWork.press, &gKeyWork.trigger);
104         }
105 #endif
106 
107         if (DEMO_IS_PRESS(PAD_KEY_UP))
108         {
109             if (++eva > 0x10)
110             {
111                 eva = 0x10;
112             }
113             OS_Printf("eva=%d\n", eva);
114         }
115         else if (DEMO_IS_PRESS(PAD_KEY_DOWN))
116         {
117             if (--eva < 0x00)
118             {
119                 eva = 0x00;
120             }
121             OS_Printf("eva=%d\n", eva);
122         }
123 
124         /* Configure the normal OAM attributes of the OBJ */
125         G2_SetOBJAttr(&s_OAMBuffer[0], // Use the first OAM
126                       0,               // x position
127                       0,               // y position
128                       0,               // Priority order
129                       GX_OAM_MODE_NORMAL,       // Normal OBJ
130                       FALSE,           // Disable mosaic
131                       GX_OAM_EFFECT_NONE,       // No special effects
132                       GX_OAM_SHAPE_64x64,       // OBJ size
133                       GX_OAM_COLOR_256, // 256 colors
134                       0,               // Character name
135                       0, 0);
136 
137         /* Configure the OAM attributes of the translucent OBJ */
138         G2_SetOBJAttr(&s_OAMBuffer[1], // Use 2nd OAM
139                       64,              // x position
140                       0,               // y position
141                       0,               // Priority order
142                       GX_OAM_MODE_XLU, // Translucent OBJ
143                       FALSE,           // Disable mosaic
144                       GX_OAM_EFFECT_NONE,       // No special effects
145                       GX_OAM_SHAPE_64x64,       // OBJ size
146                       GX_OAM_COLOR_256, // 256 colors
147                       0,               // Character name
148                       0, 0);
149         /* Alpha blending settings */
150         G2_SetBlendAlpha(GX_BLEND_PLANEMASK_NONE,       // First target plane not specified
151                          GX_BLEND_PLANEMASK_BD, // Second target plane uses backdrop
152                          eva,          // Set blending factor for first plane
153                          0);           //
154 
155 #ifdef SDK_AUTOTEST
156         GX_SetBankForLCDC(GX_VRAM_LCDC_C);
157         EXT_TestSetVRAMForScreenShot(GX_VRAM_LCDC_C);
158         EXT_TestScreenShot(100, 0x80C7021F);
159         EXT_TestTickCounter();
160 #endif //SDK_AUTOTEST
161 
162         /* Flush the cache to main memory */
163         DC_FlushRange(s_OAMBuffer, sizeof(s_OAMBuffer));
164         /* I/O register is accessed using DMA operation, so cache wait is not needed */
165         // DC_WaitWriteBufferEmpty();
166 
167         /* V-Blank wait */
168         OS_WaitVBlankIntr();
169 
170         /* Transfer to OAM */
171         GX_LoadOAM(s_OAMBuffer,        // Transfer OAM buffer to OAM
172                    0, sizeof(s_OAMBuffer));
173         MI_DmaFill32(3,                // Clear OAM buffer
174                      s_OAMBuffer, 192, sizeof(s_OAMBuffer));
175     }
176 }
177