1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - GX - demos - UnitTours/2D_CharBg_6
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 apply mosaic effect on BG #0:
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/screen data same as 2D_CharBG_1.
27 // 2. Enable mosaic on BGs by G2_BGxMosaic(TRUE);
28 // 3. Specify the size of mosaics by G2_SetBGMosaicSize().
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 u16 sScrnBuf[SCREEN_SIZE]; // Buffer for screen data (BG #0)
40
41 #ifdef SDK_TWL
TwlMain(void)42 void TwlMain(void)
43 #else
44 void NitroMain(void)
45 #endif
46 {
47 int mosaic_H = 0, mosaic_V = 0;
48
49 //---------------------------------------------------------------------------
50 // Initialize:
51 // Enables IRQ interrupts, initializes VRAM, and sets BG #0 for text mode.
52 //---------------------------------------------------------------------------
53 DEMOInitCommon();
54 DEMOInitVRAM();
55 DEMOInitDisplayBG0Only();
56
57 //---------------------------------------------------------------------------
58 // Transmitting the character data and the palette data
59 //---------------------------------------------------------------------------
60 GX_LoadBG0Char(d_64_256_bg_schDT, 0, sizeof(d_64_256_bg_schDT));
61 GX_LoadBGPltt(d_64_256_bg_sclDT, 0, sizeof(d_64_256_bg_sclDT));
62
63 G2_BG0Mosaic(TRUE); // enables mosaic on BG #0
64
65 {
66 int i, j;
67 for (i = 0; i < 8; i++)
68 {
69 for (j = 0; j < 8; j++)
70 {
71 sScrnBuf[(i * 32) + j] = (u16)((i * 0x10) + j);
72 }
73 }
74 }
75 // Store the data in the main memory, and invalidate the cache.
76 DC_FlushRange(sScrnBuf, sizeof(sScrnBuf));
77 /* I/O register is accessed using DMA operation, so cache wait is not needed */
78 // DC_WaitWriteBufferEmpty();
79
80 // DMA Transfer to BG0 screen
81 GX_LoadBG0Scr(sScrnBuf, 0, sizeof(sScrnBuf));
82
83 DEMOStartDisplay();
84 //---------------------------------------------------------------------------
85 // Main Loop
86 //---------------------------------------------------------------------------
87 while (1)
88 {
89 DEMOReadKey();
90
91 if (DEMO_IS_PRESS(PAD_KEY_DOWN))
92 mosaic_V++;
93 if (DEMO_IS_PRESS(PAD_KEY_UP))
94 mosaic_V--;
95 if (DEMO_IS_PRESS(PAD_KEY_RIGHT))
96 mosaic_H++;
97 if (DEMO_IS_PRESS(PAD_KEY_LEFT))
98 mosaic_H--;
99 if (mosaic_H > 15)
100 mosaic_H = 15;
101 if (mosaic_H < 0)
102 mosaic_H = 0;
103 if (mosaic_V > 15)
104 mosaic_V = 15;
105 if (mosaic_V < 0)
106 mosaic_V = 0;
107 if (DEMO_IS_TRIG(PAD_BUTTON_SELECT))
108 {
109 mosaic_H = 0;
110 mosaic_V = 0;
111 }
112
113 #ifdef SDK_AUTOTEST
114 mosaic_H = 7;
115 mosaic_V = 8; // default params for testing.
116 GX_SetBankForLCDC(GX_VRAM_LCDC_C);
117 EXT_TestSetVRAMForScreenShot(GX_VRAM_LCDC_C);
118 EXT_TestScreenShot(100, 0xDEC8A11C);
119 EXT_TestTickCounter();
120 #endif //SDK_AUTOTEST
121
122 OS_WaitVBlankIntr(); // Waiting for the end of the VBlank interrupt
123
124 //---------------------------------------------------------------------------
125 // Specify the horizontal/vertical size of mosaics on BGs
126 //---------------------------------------------------------------------------
127 G2_SetBGMosaicSize(mosaic_H, mosaic_V);
128 }
129 }
130
131 //---------------------------------------------------------------------------
132 // VBlank interrupt function:
133 //
134 // Interrupt handlers are registered on the interrupt table by OS_SetIRQFunction.
135 // OS_EnableIrqMask selects IRQ interrupts to enable, and
136 // OS_EnableIrq enables IRQ interrupts.
137 // Notice that you have to call 'OS_SetIrqCheckFlag' to check a VBlank interrupt.
138 //---------------------------------------------------------------------------
VBlankIntr(void)139 void VBlankIntr(void)
140 {
141 OS_SetIrqCheckFlag(OS_IE_V_BLANK); // Checking VBlank interrupt
142 }
143