1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - GX - demos - UnitTours/Sub_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 the same as for Sub_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 DEMOInitDisplaySubOBJOnly();
53
54 //---------------------------------------------------------------------------
55 // Transmitting the character data and the palette data
56 //---------------------------------------------------------------------------
57 GXS_LoadOBJ(d_64_256_obj_schDT, 0, sizeof(d_64_256_obj_schDT));
58 GXS_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 //---------------------------------------------------------------------------
103 // G2_SetOBJEffect
104 // Produces effects such as flip, scale, and rotate
105 //---------------------------------------------------------------------------
106 G2_SetOBJEffect(&sOamBak[0], effect, 0 // Select affine params if GX_OAM_EFFECT_AFFINE or GX_OAM_EFFECT_AFFINE_DOUBLE selected
107 );
108 }
109
110 // Store the data in main memory and invalidate the cache
111 DC_FlushRange(sOamBak, sizeof(sOamBak));
112 /* I/O register is accessed using DMA operation, so cache wait is not needed */
113 // DC_WaitWriteBufferEmpty();
114
115 OS_WaitVBlankIntr(); // Waiting for the end of the V-Blank interrupt
116
117 GXS_LoadOAM(sOamBak, 0, sizeof(sOamBak));
118 }
119 }
120
121 //---------------------------------------------------------------------------
122 // V-Blank interrupt function:
123 //
124 // Interrupt handlers are registered on the interrupt table by OS_SetIRQFunction.
125 // OS_EnableIrqMask selects IRQ interrupts to enable, and
126 // OS_EnableIrq enables IRQ interrupts.
127 // Notice that you have to call OS_SetIrqCheckFlag to check a V-Blank interrupt.
128 //---------------------------------------------------------------------------
VBlankIntr(void)129 void VBlankIntr(void)
130 {
131 OS_SetIrqCheckFlag(OS_IE_V_BLANK); // Checking V-Blank interrupt
132 }
133