1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - GX - demos - UnitTours/Sub_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: Scale down
23 // B: Scale up
24 //
25 // HOWTO:
26 // 1. Set up the character/palette/attribute data the same as for Sub_Oam_1
27 // 2. Set up a matrix with G2_SetOBJAffine
28 // 3. Transfer the copy of object attribute memory with GXS_LoadOAM
29 //---------------------------------------------------------------------------
30
31 #ifdef SDK_TWL
32 #include <twl.h>
33 #else
34 #include <nitro.h>
35 #endif
36 #include "DEMO.h"
37 #include "data.h"
38
39 static GXOamAttr sOamBak[128]; // Buffer for OAM
40
41 #ifdef SDK_TWL
TwlMain(void)42 void TwlMain(void)
43 #else
44 void NitroMain(void)
45 #endif
46 {
47 fx32 revScale = FX32_ONE;
48
49 //---------------------------------------------------------------------------
50 // Initialize:
51 // Enable IRQ interrupts, initialize VRAM, and make OBJ visible
52 //---------------------------------------------------------------------------
53 DEMOInitCommon();
54 DEMOInitVRAM();
55 DEMOInitDisplaySubOBJOnly();
56
57 //---------------------------------------------------------------------------
58 // Transmitting the character data and the palette data
59 //---------------------------------------------------------------------------
60 GXS_LoadOBJ(d_64_256_obj_schDT, 0, sizeof(d_64_256_obj_schDT));
61 GXS_LoadOBJPltt(d_64_256_obj_sclDT, 0, sizeof(d_64_256_obj_sclDT));
62
63 MI_DmaFill32(3, sOamBak, 192, sizeof(sOamBak)); // Let out of the screen if not display
64
65 DEMOStartDisplay();
66 //---------------------------------------------------------------------------
67 // Main Loop
68 //---------------------------------------------------------------------------
69 while (1)
70 {
71 MtxFx22 mtx;
72
73 DEMOReadKey();
74
75 if (DEMO_IS_PRESS(PAD_BUTTON_A)) // Scale down
76 revScale += 1 << 7;
77 if (DEMO_IS_PRESS(PAD_BUTTON_B)) // Scale up
78 revScale -= 1 << 7;
79 if (DEMO_IS_TRIG(PAD_BUTTON_SELECT))
80 revScale = FX32_ONE;
81 if (revScale < 1)
82 revScale = 1;
83
84 G2_SetOBJAttr(&sOamBak[0], // A pointer to the attributes
85 0, // x
86 0, // y
87 0, // Priority
88 GX_OAM_MODE_NORMAL, // OBJ mode
89 FALSE, // Mosaic
90 GX_OAM_EFFECT_AFFINE_DOUBLE, // Flip/affine/no display/affine(double)
91 GX_OAM_SHAPE_64x64, // Size and shape
92 GX_OAM_COLORMODE_256, // OBJ character data are in 256-color format
93 0, // Character name
94 0, // Color param
95 0 // Affine param
96 );
97
98 mtx._00 = revScale;
99 mtx._01 = 0;
100 mtx._10 = 0;
101 mtx._11 = revScale;
102
103 G2_SetOBJAffine((GXOamAffine *)&sOamBak[0], &mtx);
104
105 // Store the data in main memory, and invalidate the cache
106 DC_FlushRange(sOamBak, sizeof(sOamBak));
107 /* I/O register is accessed using DMA operation, so cache wait is not needed */
108 // DC_WaitWriteBufferEmpty();
109
110 OS_WaitVBlankIntr(); // Waiting for the end of V-Blank interrupt
111
112 GXS_LoadOAM(sOamBak, 0, sizeof(sOamBak));
113 }
114 }
115
116 //---------------------------------------------------------------------------
117 // V-Blank interrupt function:
118 //
119 // Interrupt handlers are registered on the interrupt table by OS_SetIRQFunction.
120 // OS_EnableIrqMask selects IRQ interrupts to enable, and
121 // OS_EnableIrq enables IRQ interrupts.
122 // Notice that you have to call OS_SetIrqCheckFlag to check a V-Blank interrupt.
123 //---------------------------------------------------------------------------
VBlankIntr(void)124 void VBlankIntr(void)
125 {
126 OS_SetIrqCheckFlag(OS_IE_V_BLANK); // Checking V-Blank interrupt
127 }
128