1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - GX - demos - UnitTours/2D_Oam_3
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 //---------------------------------------------------------------------------
19 // A sample that scales an OBJ:
20 //
21 // USAGE:
22 // A: scaling down
23 // B: scaling up
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 fx32 revScale = FX32_ONE;
47
48 //---------------------------------------------------------------------------
49 // Initialize:
50 // They 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 DEMOStartDisplay();
65 //---------------------------------------------------------------------------
66 // Main Loop
67 //---------------------------------------------------------------------------
68 while (1)
69 {
70 MtxFx22 mtx;
71
72 DEMOReadKey();
73
74 if (DEMO_IS_PRESS(PAD_BUTTON_A)) // scaling down
75 revScale += 1 << 7;
76 if (DEMO_IS_PRESS(PAD_BUTTON_B)) // scaling up
77 revScale -= 1 << 7;
78 if (DEMO_IS_TRIG(PAD_BUTTON_SELECT))
79 revScale = FX32_ONE;
80 if (revScale < 1)
81 revScale = 1;
82
83 G2_SetOBJAttr(&sOamBak[0], // a pointer to the attributes
84 0, // x
85 0, // y
86 0, // priority
87 GX_OAM_MODE_NORMAL, // OBJ mode
88 FALSE, // mosaic
89 GX_OAM_EFFECT_AFFINE_DOUBLE, // 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 mtx._00 = revScale;
98 mtx._01 = 0;
99 mtx._10 = 0;
100 mtx._11 = revScale;
101
102 G2_SetOBJAffine((GXOamAffine *)&sOamBak[0], &mtx);
103
104 // Store the data in the main memory, and invalidate the cache
105 DC_FlushRange(sOamBak, sizeof(sOamBak));
106 /* I/O register is accessed using DMA operation, so cache wait is not needed */
107 // DC_WaitWriteBufferEmpty();
108
109 #ifdef SDK_AUTOTEST
110 revScale = 2 << 7; // Default params for testing
111 GX_SetBankForLCDC(GX_VRAM_LCDC_C);
112 EXT_TestSetVRAMForScreenShot(GX_VRAM_LCDC_C);
113 EXT_TestScreenShot(100, 0xF42CA600);
114 EXT_TestTickCounter();
115 #endif //SDK_AUTOTEST
116
117 OS_WaitVBlankIntr(); // Waiting for the end of V-Blank interrupt
118
119 GX_LoadOAM(sOamBak, 0, sizeof(sOamBak));
120 }
121 }
122
123 //---------------------------------------------------------------------------
124 // V-Blank interrupt function:
125 //
126 // Interrupt handlers are registered on the interrupt table by OS_SetIRQFunction.
127 // OS_EnableIrqMask selects IRQ interrupts to enable, and
128 // OS_EnableIrq enables IRQ interrupts.
129 // Notice that you have to call 'OS_SetIrqCheckFlag' to check a V-Blank interrupt.
130 //---------------------------------------------------------------------------
VBlankIntr(void)131 void VBlankIntr(void)
132 {
133 OS_SetIrqCheckFlag(OS_IE_V_BLANK); // Checking V-Blank interrupt
134 }
135