1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - GX - demos - UnitTours/Sub_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 mosaic size in a vertical direction
23 // LEFT, RIGHT: Control the mosaic size in a horizontal direction
24 //
25 // HOWTO:
26 // 1. Set up the character/palette/screen data the same as Sub_CharBg_1
27 // 2. Enable mosaic on BGs with G2S_BGxMosaic(TRUE)
28 // 3. Specify the mosaic size with G2S_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 DEMOInitDisplaySubBG0Only();
56
57 //---------------------------------------------------------------------------
58 // Transmitting the character data and the palette data
59 //---------------------------------------------------------------------------
60 GXS_LoadBG0Char(d_64_256_bg_schDT, 0, sizeof(d_64_256_bg_schDT));
61 GXS_LoadBGPltt(d_64_256_bg_sclDT, 0, sizeof(d_64_256_bg_sclDT));
62
63 G2S_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 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 GXS_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 OS_WaitVBlankIntr(); // Waiting for the end of the V-Blank interrupt
114
115 //---------------------------------------------------------------------------
116 // Specify the horizontal/vertical size of mosaics on BGs
117 //---------------------------------------------------------------------------
118 G2S_SetBGMosaicSize(mosaic_H, mosaic_V);
119 }
120 }
121
122 //---------------------------------------------------------------------------
123 // V-Blank interrupt function:
124 //
125 // Interrupt handlers are registered on the interrupt table by OS_SetIRQFunction.
126 // OS_EnableIrqMask selects IRQ interrupts to enable, and
127 // OS_EnableIrq enables IRQ interrupts.
128 // Notice that you have to call OS_SetIrqCheckFlag to check a V-Blank interrupt.
129 //---------------------------------------------------------------------------
VBlankIntr(void)130 void VBlankIntr(void)
131 {
132 OS_SetIrqCheckFlag(OS_IE_V_BLANK); // Checking V-Blank interrupt
133 }
134