1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - GX - demos - UnitTours/Sub_CharBg_1
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 use BG #0 as text mode
19 //
20 // This sample simply displays a sphere on the display
21 //
22 // HOWTO:
23 // 1. Transfer the character data with GXS_LoadBGxChar
24 // 2. Transfer the palette data with GXS_LoadBGPltt
25 // 3. Transfer the screen data with GXS_LoadBGxScr
26 //
27 // Do not forget to flush the corresponding cache if you modified the data
28 // before transfer
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 //---------------------------------------------------------------------------
48 // Initialize:
49 // Enables IRQ interrupts, initializes VRAM, and sets BG #0 for text mode
50 //---------------------------------------------------------------------------
51 DEMOInitCommon();
52 DEMOInitVRAM();
53 DEMOInitDisplaySubBG0Only();
54
55 //---------------------------------------------------------------------------
56 // Transmitting the character data and the palette data
57 //---------------------------------------------------------------------------
58 GXS_LoadBG0Char(d_64_256_bg_schDT, 0, sizeof(d_64_256_bg_schDT));
59 GXS_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 // Store the data in the main memory, and invalidate the cache
72 DC_FlushRange(sScrnBuf, sizeof(sScrnBuf));
73 /* I/O register is accessed using DMA operation, so cache wait is not needed */
74 // DC_WaitWriteBufferEmpty();
75
76 // DMA transfer to BG #0 screen
77 GXS_LoadBG0Scr(sScrnBuf, 0, sizeof(sScrnBuf));
78
79 DEMOStartDisplay();
80
81 //---------------------------------------------------------------------------
82 // Main Loop
83 //---------------------------------------------------------------------------
84 while (1)
85 {
86 OS_WaitVBlankIntr(); // Waiting for the end of the VBlank interrupt
87 GXS_LoadBG0Scr(sScrnBuf, 0, sizeof(sScrnBuf));
88 }
89 }
90
91 //---------------------------------------------------------------------------
92 // V-Blank interrupt function:
93 //
94 // Interrupt handlers are registered on the interrupt table by OS_SetIRQFunction.
95 // OS_EnableIrqMask selects IRQ interrupts to enable, and
96 // OS_EnableIrq enables IRQ interrupts.
97 // Notice that you have to call OS_SetIrqCheckFlag to check a V-Blank interrupt.
98 //---------------------------------------------------------------------------
VBlankIntr(void)99 void VBlankIntr(void)
100 {
101 OS_SetIrqCheckFlag(OS_IE_V_BLANK); // Checking V-Blank interrupt
102 }
103