1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - GX - demos - UnitTours/2D_Oam_5
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-17#$
14 $Rev: 8556 $
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 same as 2D_Oam_1
27 // 2. Specify the size of mosaic with G2_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 // Enable IRQ interrupts, initialize VRAM, and make 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)); // Let out of the screen if not display
63
64 G2_SetOBJAttr(&sOamBak[0], // a 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 are 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 #ifdef SDK_AUTOTEST
109 mosaic_V = 8;
110 mosaic_H = 9; // Default params for testing
111 GX_SetBankForLCDC(GX_VRAM_LCDC_C);
112 EXT_TestSetVRAMForScreenShot(GX_VRAM_LCDC_C);
113 EXT_TestScreenShot(100, 0xAE992802);
114 EXT_TestTickCounter();
115 #endif //SDK_AUTOTEST
116
117 OS_WaitVBlankIntr(); // Waiting for the end of the V-Blank interrupt
118
119 //---------------------------------------------------------------------------
120 // Specify the horizontal/vertical size of mosaic on OBJs
121 //---------------------------------------------------------------------------
122 G2_SetOBJMosaicSize(mosaic_H, mosaic_V);
123
124 // Store the data in the main memory, and invalidate the cache.
125 DC_FlushRange(sOamBak, sizeof(sOamBak));
126 /* I/O register is accessed using DMA operation, so cache wait is not needed */
127 // DC_WaitWriteBufferEmpty();
128 GX_LoadOAM(sOamBak, 0, sizeof(sOamBak));
129 }
130 }
131
132 //---------------------------------------------------------------------------
133 // V-Blank interrupt function:
134 //
135 // Interrupt handlers are registered on the interrupt table by OS_SetIRQFunction.
136 // OS_EnableIrqMask selects IRQ interrupts to enable, and
137 // OS_EnableIrq enables IRQ interrupts.
138 // Notice that you have to call OS_SetIrqCheckFlag to check a V-Blank interrupt.
139 //---------------------------------------------------------------------------
VBlankIntr(void)140 void VBlankIntr(void)
141 {
142 OS_SetIrqCheckFlag(OS_IE_V_BLANK); // Checking V-Blank interrupt
143 }
144