1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - GX - demos - UnitTours/2D_Oam_2
3 File: main.c
4
5 Copyright 2003-2009 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:: 2009-06-04#$
14 $Rev: 10698 $
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 same as 2D_Oam_1
27 // 2. Set up a matrix with G2_SetOBJAffine
28 //---------------------------------------------------------------------------
29
30 #ifdef SDK_TWL
31 #include <twl.h>
32 #else
33 #include <nitro.h>
34 #endif
35 #include "DEMO.h"
36 #include "data.h"
37
38 static GXOamAttr sOamBak[128]; // Buffer for OAM
39
40 #ifdef SDK_TWL
TwlMain(void)41 void TwlMain(void)
42 #else
43 void NitroMain(void)
44 #endif
45 {
46 u16 rotate = 0;
47
48 //---------------------------------------------------------------------------
49 // Initialize:
50 // They enable IRQ interrupts, initialize VRAM, and make the OBJ visible
51 //---------------------------------------------------------------------------
52 DEMOInitCommon();
53 DEMOInitVRAM();
54 DEMOInitDisplayOBJOnly();
55
56 //---------------------------------------------------------------------------
57 // Transmitting the character data and the palette data
58 //---------------------------------------------------------------------------
59 GX_LoadOBJ(d_64_256_obj_schDT, 0, sizeof(d_64_256_obj_schDT));
60 GX_LoadOBJPltt(d_64_256_obj_sclDT, 0, sizeof(d_64_256_obj_sclDT));
61
62 MI_DmaFill32(3, sOamBak, 192, sizeof(sOamBak)); // Clear OAM buffer
63
64 DEMOStartDisplay();
65 //---------------------------------------------------------------------------
66 // Main Loop
67 //---------------------------------------------------------------------------
68 while (1)
69 {
70 DEMOReadKey();
71
72 if (DEMO_IS_PRESS(PAD_KEY_RIGHT))
73 rotate += 256;
74 if (DEMO_IS_PRESS(PAD_KEY_LEFT))
75 rotate -= 256;
76 if (DEMO_IS_PRESS(PAD_BUTTON_R))
77 rotate += 256;
78 if (DEMO_IS_PRESS(PAD_BUTTON_L))
79 rotate -= 256;
80 if (DEMO_IS_TRIG(PAD_BUTTON_SELECT))
81 rotate = 0;
82
83 G2_SetOBJAttr(&sOamBak[0], // Pointer to the attributes
84 60, // X
85 35, // Y
86 0, // Priority
87 GX_OAM_MODE_NORMAL, // OBJ mode
88 FALSE, // Mosaic
89 GX_OAM_EFFECT_AFFINE, // Flip/affine/no display/affine(double)
90 GX_OAM_SHAPE_64x64, // Size and shape
91 GX_OAM_COLORMODE_256, // OBJ character data are in 256-color format
92 0, // Character name
93 0, // Color param
94 0 // Affine param
95 );
96
97 {
98 fx16 sinVal, cosVal;
99 MtxFx22 mtx;
100 GXOamAffine *tmp = (GXOamAffine *)(&sOamBak[0]);
101
102 sinVal = FX_SinIdx(rotate);
103 cosVal = FX_CosIdx(rotate);
104 mtx._00 = cosVal;
105 mtx._01 = sinVal;
106 mtx._10 = -sinVal;
107 mtx._11 = cosVal;
108 G2_SetOBJAffine(tmp, &mtx);
109 }
110
111 // Store the data in main memory and invalidate the cache
112 DC_FlushRange(sOamBak, sizeof(sOamBak));
113 /* I/O register is accessed using DMA operation, so cache wait is not needed */
114 // DC_WaitWriteBufferEmpty();
115
116 #ifdef SDK_AUTOTEST
117 rotate = 4098; // Default params for testing
118 GX_SetBankForLCDC(GX_VRAM_LCDC_C);
119 EXT_TestSetVRAMForScreenShot(GX_VRAM_LCDC_C);
120 EXT_TestScreenShot(100, 0x2F6D8647);
121 EXT_TestTickCounter();
122 #endif //SDK_AUTOTEST
123
124 OS_WaitVBlankIntr(); // Waiting for the end of the V-Blank interrupt
125
126 GX_LoadOAM(sOamBak, 0, sizeof(sOamBak));
127 }
128 }
129
130 //---------------------------------------------------------------------------
131 // V-Blank interrupt function:
132 //
133 // Interrupt handlers are registered on the interrupt table by OS_SetIRQFunction.
134 // OS_EnableIrqMask selects IRQ interrupts to enable, and
135 // OS_EnableIrq enables IRQ interrupts.
136 // Notice that you have to call OS_SetIrqCheckFlag to check a V-Blank interrupt.
137 //---------------------------------------------------------------------------
VBlankIntr(void)138 void VBlankIntr(void)
139 {
140 OS_SetIrqCheckFlag(OS_IE_V_BLANK); // Checking V-Blank interrupt
141 }
142