1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - GX - demos - UnitTours/2D_Oam_4
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 // A sample that flips OBJs.
19 //
20 // USAGE:
21 // A: Flips horizontally
22 // B: Flips vertically
23 //
24 // HOWTO:
25 // 1. Set up the character/palette/attribute data same as 2D_Oam_1
26 // 2. Flip horizontally/vertically by setting corresponding fields
27 //---------------------------------------------------------------------------
28 #ifdef SDK_TWL
29 #include <twl.h>
30 #else
31 #include <nitro.h>
32 #endif
33 #include "DEMO.h"
34 #include "data.h"
35
36 static GXOamAttr sOamBak[128]; // Buffer for OAM
37
38 #ifdef SDK_TWL
TwlMain(void)39 void TwlMain(void)
40 #else
41 void NitroMain(void)
42 #endif
43 {
44 int flip_H = 0, flip_V = 0;
45
46 //---------------------------------------------------------------------------
47 // Initialize:
48 // Enable IRQ interrupts, initialize VRAM, and make OBJ visible
49 //---------------------------------------------------------------------------
50 DEMOInitCommon();
51 DEMOInitVRAM();
52 DEMOInitDisplayOBJOnly();
53
54 //---------------------------------------------------------------------------
55 // Transmitting the character data and the palette data
56 //---------------------------------------------------------------------------
57 GX_LoadOBJ(d_64_256_obj_schDT, 0, sizeof(d_64_256_obj_schDT));
58 GX_LoadOBJPltt(d_64_256_obj_sclDT, 0, sizeof(d_64_256_obj_sclDT));
59
60 MI_DmaFill32(3, sOamBak, 192, sizeof(sOamBak)); // Let out of the screen if not display
61
62 G2_SetOBJAttr(&sOamBak[0], // a pointer to the attributes
63 0, // x
64 0, // y
65 0, // priority
66 GX_OAM_MODE_NORMAL, // OBJ mode
67 FALSE, // mosaic
68 GX_OAM_EFFECT_NONE, // flip/affine/no display/affine(double)
69 GX_OAM_SHAPE_64x64, // size and shape
70 GX_OAM_COLORMODE_256, // OBJ character data are in 256-color format
71 0, // character name
72 0, // color param
73 0 // affine param
74 );
75
76 DEMOStartDisplay();
77 //---------------------------------------------------------------------------
78 // Main Loop
79 //---------------------------------------------------------------------------
80 while (1)
81 {
82 DEMOReadKey();
83
84 if (DEMO_IS_TRIG(PAD_BUTTON_A))
85 {
86 ++flip_H;
87 flip_H %= 2;
88 }
89 if (DEMO_IS_TRIG(PAD_BUTTON_B))
90 {
91 ++flip_V;
92 flip_V %= 2;
93 }
94
95 {
96 GXOamEffect effect = (GXOamEffect)0;
97 if (flip_H)
98 effect |= GX_OAM_EFFECT_FLIP_H;
99 if (flip_V)
100 effect |= GX_OAM_EFFECT_FLIP_V;
101
102 #ifdef SDK_AUTOTEST
103 effect = (GXOamEffect)(GX_OAM_EFFECT_FLIP_H | GX_OAM_EFFECT_FLIP_V); // Default params for testing
104 #endif //SDK_AUTOTEST
105
106
107 //---------------------------------------------------------------------------
108 // G2_SetOBJEffect:
109 // Produces effects such as flip/scale and rotation
110 //---------------------------------------------------------------------------
111 G2_SetOBJEffect(&sOamBak[0], effect, 0 // Select affine params if GX_OAM_EFFECT_AFFINE or GX_OAM_EFFECT_AFFINE_DOUBLE selected
112 );
113 }
114
115 // Store the data in the main memory, and invalidate the cache.
116 DC_FlushRange(sOamBak, sizeof(sOamBak));
117 /* I/O register is accessed using DMA operation, so cache wait is not needed */
118 // DC_WaitWriteBufferEmpty();
119
120 #ifdef SDK_AUTOTEST
121 GX_SetBankForLCDC(GX_VRAM_LCDC_C);
122 EXT_TestSetVRAMForScreenShot(GX_VRAM_LCDC_C);
123 EXT_TestScreenShot(100, 0x9975CFB4);
124 EXT_TestTickCounter();
125 #endif //SDK_AUTOTEST
126
127 OS_WaitVBlankIntr(); // Waiting for the end of the V-Blank interrupt
128
129 GX_LoadOAM(sOamBak, 0, sizeof(sOamBak));
130 }
131 }
132
133 //---------------------------------------------------------------------------
134 // V-Blank interrupt function:
135 //
136 // Interrupt handlers are registered on the interrupt table by OS_SetIRQFunction.
137 // OS_EnableIrqMask selects IRQ interrupts to enable, and
138 // OS_EnableIrq enables IRQ interrupts.
139 // Notice that you have to call OS_SetIrqCheckFlag to check a V-Blank interrupt.
140 //---------------------------------------------------------------------------
VBlankIntr(void)141 void VBlankIntr(void)
142 {
143 OS_SetIrqCheckFlag(OS_IE_V_BLANK); // Checking V-Blank interrupt
144 }
145