1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - GX - demos - UnitTours/Sub_Oam_5
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 mosaics an OBJ.
20 //
21 // USAGE:
22 // UP, DOWN: Control the size of mosaic in vertical direction
23 // LEFT, RIGHT: Control the size of mosaic in horizontal direction
24 //
25 // HOWTO:
26 // 1. Set up the character/palette/attribute data the same as for Sub_Oam_1
27 // 2. Specify the size of mosaic with G2S_SetOBJMosaicSize
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 int mosaic_H = 0, mosaic_V = 0;
47
48 //---------------------------------------------------------------------------
49 // Initialize:
50 // They enable IRQ interrupts, initialize VRAM, and make the OBJ visible.
51 //---------------------------------------------------------------------------
52 DEMOInitCommon();
53 DEMOInitVRAM();
54 DEMOInitDisplaySubOBJOnly();
55
56 //---------------------------------------------------------------------------
57 // Transmitting the character data and the palette data
58 //---------------------------------------------------------------------------
59 GXS_LoadOBJ(d_64_256_obj_schDT, 0, sizeof(d_64_256_obj_schDT));
60 GXS_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 G2_SetOBJAttr(&sOamBak[0], // Pointer to the attributes
65 0, // X
66 0, // Y
67 0, // Priority
68 GX_OAM_MODE_NORMAL, // OBJ mode
69 TRUE, // Mosaic
70 GX_OAM_EFFECT_NONE, // Flip/affine/no display/affine(double)
71 GX_OAM_SHAPE_64x64, // Size and shape
72 GX_OAM_COLORMODE_256, // OBJ character data is in 256-color format
73 0, // Character name
74 0, // Color param
75 0 // Affine param
76 );
77
78 DEMOStartDisplay();
79 //---------------------------------------------------------------------------
80 // Main Loop
81 //---------------------------------------------------------------------------
82 while (1)
83 {
84 DEMOReadKey();
85
86 if (DEMO_IS_PRESS(PAD_KEY_DOWN))
87 mosaic_V++;
88 if (DEMO_IS_PRESS(PAD_KEY_UP))
89 mosaic_V--;
90 if (DEMO_IS_PRESS(PAD_KEY_RIGHT))
91 mosaic_H++;
92 if (DEMO_IS_PRESS(PAD_KEY_LEFT))
93 mosaic_H--;
94 if (mosaic_H > 15)
95 mosaic_H = 15;
96 if (mosaic_H < 0)
97 mosaic_H = 0;
98 if (mosaic_V > 15)
99 mosaic_V = 15;
100 if (mosaic_V < 0)
101 mosaic_V = 0;
102 if (DEMO_IS_TRIG(PAD_BUTTON_SELECT))
103 {
104 mosaic_H = 0;
105 mosaic_V = 0;
106 }
107
108 OS_WaitVBlankIntr(); // Waiting for the end of the V-Blank interrupt
109
110 //---------------------------------------------------------------------------
111 // Specify the horizontal/vertical size of mosaic on the OBJs
112 //---------------------------------------------------------------------------
113 G2S_SetOBJMosaicSize(mosaic_H, mosaic_V);
114
115 // Store the data in 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 GXS_LoadOAM(sOamBak, 0, sizeof(sOamBak));
121 }
122 }
123
124 //---------------------------------------------------------------------------
125 // V-Blank interrupt function:
126 //
127 // Interrupt handlers are registered on the interrupt table by OS_SetIRQFunction.
128 // OS_EnableIrqMask selects IRQ interrupts to enable, and
129 // OS_EnableIrq enables IRQ interrupts.
130 // Notice that you have to call OS_SetIrqCheckFlag to check a V-Blank interrupt.
131 //---------------------------------------------------------------------------
VBlankIntr(void)132 void VBlankIntr(void)
133 {
134 OS_SetIrqCheckFlag(OS_IE_V_BLANK); // Checking V-Blank interrupt
135 }
136