1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - GX - demos - UnitTours/Sub_Oam_2
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-09-18#$
14   $Rev: 8573 $
15   $Author: okubata_ryoma $
16  *---------------------------------------------------------------------------*/
17 
18 //---------------------------------------------------------------------------
19 // A sample that rotates an OBJ
20 //
21 // USAGE:
22 //   LEFT, L: Turn left
23 //   RIGHT,R: Turn right
24 //
25 // HOWTO:
26 // 1. Set up the character/palette/attribute data the same as for Sub_Oam_1
27 // 2. Set up a matrix with G2S_SetOBJAffine
28 // 3. Transfer the copy of object attribute memory with GXS_LoadOAM
29 //---------------------------------------------------------------------------
30 
31 #ifdef SDK_TWL
32 #include <twl.h>
33 #else
34 #include <nitro.h>
35 #endif
36 #include "DEMO.h"
37 #include "data.h"
38 
39 static GXOamAttr sOamBak[128];         // Buffer for OAM
40 
41 #ifdef SDK_TWL
TwlMain(void)42 void TwlMain(void)
43 #else
44 void NitroMain(void)
45 #endif
46 {
47     u16     rotate = 0;
48 
49     //---------------------------------------------------------------------------
50     // Initialize:
51     // Enable IRQ interrupts, initialize VRAM, and make OBJ visible
52     //---------------------------------------------------------------------------
53     DEMOInitCommon();
54     DEMOInitVRAM();
55     DEMOInitDisplaySubOBJOnly();
56 
57     //---------------------------------------------------------------------------
58     // Transmitting the character data and the palette data
59     //---------------------------------------------------------------------------
60     GXS_LoadOBJ(d_64_256_obj_schDT, 0, sizeof(d_64_256_obj_schDT));
61     GXS_LoadOBJPltt(d_64_256_obj_sclDT, 0, sizeof(d_64_256_obj_sclDT));
62 
63     MI_DmaFill32(3, sOamBak, 192, sizeof(sOamBak));     // Let out of the screen if not display
64 
65     DEMOStartDisplay();
66     //---------------------------------------------------------------------------
67     // Main Loop
68     //---------------------------------------------------------------------------
69     while (1)
70     {
71         DEMOReadKey();
72 
73         if (DEMO_IS_PRESS(PAD_KEY_RIGHT))
74             rotate += 256;
75         if (DEMO_IS_PRESS(PAD_KEY_LEFT))
76             rotate -= 256;
77         if (DEMO_IS_PRESS(PAD_BUTTON_R))
78             rotate += 256;
79         if (DEMO_IS_PRESS(PAD_BUTTON_L))
80             rotate -= 256;
81         if (DEMO_IS_TRIG(PAD_BUTTON_SELECT))
82             rotate = 0;
83 
84         G2_SetOBJAttr(&sOamBak[0],     // A pointer to the attributes
85                       60,              // x
86                       35,              // y
87                       0,               // Priority
88                       GX_OAM_MODE_NORMAL,       // OBJ mode
89                       FALSE,           // Mosaic
90                       GX_OAM_EFFECT_AFFINE,     // Flip/affine/no display/affine(double)
91                       GX_OAM_SHAPE_64x64,       // Size and shape
92                       GX_OAM_COLORMODE_256,     // OBJ character data are in 256-color format
93                       0,               // Character name
94                       0,               // Color param
95                       0                // Affine param
96             );
97 
98         {
99             fx16    sinVal, cosVal;
100             MtxFx22 mtx;
101             GXOamAffine *tmp = (GXOamAffine *)(&sOamBak[0]);
102 
103             sinVal = FX_SinIdx(rotate);
104             cosVal = FX_CosIdx(rotate);
105             mtx._00 = cosVal;
106             mtx._01 = sinVal;
107             mtx._10 = -sinVal;
108             mtx._11 = cosVal;
109             G2_SetOBJAffine(tmp, &mtx);
110         }
111 
112         // Store the data in main memory, and invalidate the cache
113         DC_FlushRange(sOamBak, sizeof(sOamBak));
114         /* I/O register is accessed using DMA operation, so cache wait is not needed */
115         // DC_WaitWriteBufferEmpty();
116 
117         OS_WaitVBlankIntr();           // Waiting for the end of the V-Blank interrupt
118 
119         GXS_LoadOAM(sOamBak, 0, sizeof(sOamBak));
120     }
121 }
122 
123 //---------------------------------------------------------------------------
124 // V-Blank interrupt function:
125 //
126 // Interrupt handlers are registered on the interrupt table by OS_SetIRQFunction.
127 // OS_EnableIrqMask selects IRQ interrupts to enable, and
128 // OS_EnableIrq enables IRQ interrupts.
129 // Notice that you have to call OS_SetIrqCheckFlag to check a V-Blank interrupt.
130 //---------------------------------------------------------------------------
VBlankIntr(void)131 void VBlankIntr(void)
132 {
133     OS_SetIrqCheckFlag(OS_IE_V_BLANK); // Checking V-Blank interrupt
134 }
135