1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - GX - demos - UnitTours/2D_CharBg_4
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 // A sample that scrolls BG #0 (text mode):
19 //
20 // USAGE:
21 // UP, DOWN, LEFT, RIGHT : Scrolls a sphere
22 // SELECT : Move sphere to the initial position
23 //
24 // HOWTO:
25 // 1. Set up the character/palette/screen data same as 2D_CharBG_1.
26 // 2. Specify an offset with G2_SetBGxOffset().
27 //---------------------------------------------------------------------------
28
29 #ifdef SDK_TWL
30 #include <twl.h>
31 #else
32 #include <nitro.h>
33 #endif
34 #include "DEMO.h"
35 #include "data.h"
36
37 static u16 sScrnBuf[SCREEN_SIZE]; // Buffer for screen data (BG #0)
38
39 #ifdef SDK_TWL
TwlMain(void)40 void TwlMain(void)
41 #else
42 void NitroMain(void)
43 #endif
44 {
45 int offset_H = 0, offset_V = 0;
46
47 //---------------------------------------------------------------------------
48 // Initialize:
49 // Enables IRQ interrupts, initializes VRAM, and sets BG #0 for text mode.
50 //---------------------------------------------------------------------------
51 DEMOInitCommon();
52 DEMOInitVRAM();
53 DEMOInitDisplayBG0Only();
54
55 //---------------------------------------------------------------------------
56 // Transmitting the character data and the palette data
57 //---------------------------------------------------------------------------
58 GX_LoadBG0Char(d_64_256_bg_schDT, 0, sizeof(d_64_256_bg_schDT));
59 GX_LoadBGPltt(d_64_256_bg_sclDT, 0, sizeof(d_64_256_bg_sclDT));
60
61 {
62 int i, j;
63 for (i = 0; i < 8; i++)
64 {
65 for (j = 0; j < 8; j++)
66 {
67 sScrnBuf[(i * 32) + j] = (u16)((i * 0x10) + j);
68 }
69 }
70 }
71
72 // Store the data in the main memory, and invalidate the cache.
73 DC_FlushRange(sScrnBuf, sizeof(sScrnBuf));
74 /* I/O register is accessed using DMA operation, so cache wait is not needed */
75 // DC_WaitWriteBufferEmpty();
76
77 // DMA Transfer to BG #0 screen
78 GX_LoadBG0Scr(sScrnBuf, 0, sizeof(sScrnBuf));
79
80 DEMOStartDisplay();
81 //---------------------------------------------------------------------------
82 // Main Loop
83 //---------------------------------------------------------------------------
84 while (1)
85 {
86 DEMOReadKey();
87
88 if (DEMO_IS_PRESS(PAD_KEY_UP))
89 offset_V += 2;
90 if (DEMO_IS_PRESS(PAD_KEY_DOWN))
91 offset_V -= 2;
92 if (DEMO_IS_PRESS(PAD_KEY_RIGHT))
93 offset_H -= 2;
94 if (DEMO_IS_PRESS(PAD_KEY_LEFT))
95 offset_H += 2;
96 if (DEMO_IS_TRIG(PAD_BUTTON_SELECT))
97 {
98 offset_H = 0;
99 offset_V = 0;
100 }
101
102 #ifdef SDK_AUTOTEST
103 offset_H = 10;
104 offset_V = 15; // default params for testing.
105 GX_SetBankForLCDC(GX_VRAM_LCDC_C);
106 EXT_TestSetVRAMForScreenShot(GX_VRAM_LCDC_C);
107 EXT_TestScreenShot(100, 0xAF23A638);
108 EXT_TestTickCounter();
109 #endif //SDK_AUTOTEST
110
111 OS_WaitVBlankIntr(); // Waiting for the end of the VBlank interrupt
112
113 // Setting the offset for BG #0 plane
114 G2_SetBG0Offset(offset_H, offset_V);
115 }
116 }
117
118 //---------------------------------------------------------------------------
119 // VBlank interrupt function:
120 //
121 // Interrupt handlers are registered on the interrupt table by OS_SetIRQFunction.
122 // OS_EnableIrqMask selects IRQ interrupts to enable, and
123 // OS_EnableIrq enables IRQ interrupts.
124 // Notice that you have to call 'OS_SetIrqCheckFlag' to check a VBlank interrupt.
125 //---------------------------------------------------------------------------
VBlankIntr(void)126 void VBlankIntr(void)
127 {
128 OS_SetIrqCheckFlag(OS_IE_V_BLANK); // Checking VBlank interrupt
129 }
130