1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - GX - demos - UnitTours/2D_CharBg_BankEx
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 uses separated BG-VRAM with GX_SetBankForBGEx:
19 //
20 // HOWTO:
21 // 1. Set VRAM Bank for BG with GX_SetBankForBGEx
22 // 2. Set BG Screen offset with GX_SetBGScrOffset to 0x00000
23 // 3. Set Char offset with GX_SetBGCharOffset to 0x20000
24 //
25 //---------------------------------------------------------------------------
26
27 #ifdef SDK_TWL
28 #include <twl.h>
29 #else
30 #include <nitro.h>
31 #endif
32 #include "DEMO.h"
33 #include "data.h"
34
35 static u16 sScrnBuf[SCREEN_SIZE]; // Buffer for screen data (BG #0)
36
37 #ifdef SDK_TWL
TwlMain(void)38 void TwlMain(void)
39 #else
40 void NitroMain(void)
41 #endif
42 {
43 //---------------------------------------------------------------------------
44 // Initialize:
45 // Enables IRQ interrupts, initializes VRAM, and sets BG #0 for text mode
46 //---------------------------------------------------------------------------
47 DEMOInitCommon();
48 DEMOInitVRAM();
49
50 GX_SetBankForBGEx(GX_VRAM_BG_64_E, GX_VRAM_BG_128_A); // VRAM-E, VRAM-A for BGs
51
52 GX_SetGraphicsMode(GX_DISPMODE_GRAPHICS, // Graphics mode
53 GX_BGMODE_0, // BGMODE is 0
54 GX_BG0_AS_2D); // BG #0 is for 2D
55
56 GX_SetVisiblePlane(GX_PLANEMASK_BG0); // Display only BG #0
57
58 GX_SetBGScrOffset(GX_BGSCROFFSET_0x00000);
59 GX_SetBGCharOffset(GX_BGCHAROFFSET_0x20000);
60
61 G2_SetBG0Control(GX_BG_SCRSIZE_TEXT_256x256, // 256pix x 256pix text
62 GX_BG_COLORMODE_256, // use 256 color mode
63 GX_BG_SCRBASE_0x0000, // screen base offset + 0x0000 is the address for BG #0 screen
64 GX_BG_CHARBASE_0x00000, // character base offset + 0x04000 is the address for BG #0 characters
65 GX_BG_EXTPLTT_01 // use BGExtPltt slot #0 if BGExtPltt is enabled
66 );
67
68 G2_SetBG0Priority(0);
69
70 G2_BG0Mosaic(FALSE);
71
72 //---------------------------------------------------------------------------
73 // Transmitting the character data and the palette data
74 //---------------------------------------------------------------------------
75 GX_LoadBG0Char(d_64_256_bg_schDT, 0, sizeof(d_64_256_bg_schDT));
76 GX_LoadBGPltt(d_64_256_bg_sclDT, 0, sizeof(d_64_256_bg_sclDT));
77
78 {
79 int i, j;
80 for (i = 0; i < 8; i++)
81 {
82 for (j = 0; j < 8; j++)
83 {
84 sScrnBuf[(i * 32) + j] = (u16)((i * 0x10) + j);
85 }
86 }
87 }
88 // Store the data in the main memory, and invalidate the cache
89 DC_FlushRange(sScrnBuf, sizeof(sScrnBuf));
90 /* I/O register is accessed using DMA operation, so cache wait is not needed */
91 // DC_WaitWriteBufferEmpty();
92
93 // DMA transfer to BG #0 screen
94 GX_LoadBG0Scr(sScrnBuf, 0, sizeof(sScrnBuf));
95
96 DEMOStartDisplay();
97
98 //---------------------------------------------------------------------------
99 // Main Loop
100 //---------------------------------------------------------------------------
101 while (1)
102 {
103 #ifdef SDK_AUTOTEST
104 GX_SetBankForLCDC(GX_VRAM_LCDC_C);
105 EXT_TestSetVRAMForScreenShot(GX_VRAM_LCDC_C);
106 EXT_TestScreenShot(100, 0xC7953680);
107 EXT_TestTickCounter();
108 #endif //SDK_AUTOTEST
109
110 OS_WaitVBlankIntr(); // Waiting for the end of the V-Blank interrupt
111 GX_LoadBG0Scr(sScrnBuf, 0, sizeof(sScrnBuf));
112 }
113 }
114
115 //---------------------------------------------------------------------------
116 // V-Blank interrupt function:
117 //
118 // Interrupt handlers are registered on the interrupt table by OS_SetIRQFunction.
119 // OS_EnableIrqMask selects IRQ interrupts to enable, and
120 // OS_EnableIrq enables IRQ interrupts.
121 // Notice that you have to call OS_SetIrqCheckFlag to check a V-Blank interrupt.
122 //---------------------------------------------------------------------------
VBlankIntr(void)123 void VBlankIntr(void)
124 {
125 OS_SetIrqCheckFlag(OS_IE_V_BLANK); // Checking V-Blank interrupt
126 }
127