1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - GX - demos - UnitTours/2D_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-10-20#$
14   $Rev: 9005 $
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 GX_LoadBGxChar().
24 // 2. Transfer the palette data by GX_LoadBGPltt().
25 // 3. Transfer the screen data by GX_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     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     // 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     GX_LoadBG0Scr(sScrnBuf, 0, sizeof(sScrnBuf));
78 
79     DEMOStartDisplay();
80 
81     //---------------------------------------------------------------------------
82     // Main Loop
83     //---------------------------------------------------------------------------
84     while (1)
85     {
86 #ifdef SDK_AUTOTEST
87         GX_SetBankForLCDC(GX_VRAM_LCDC_C);
88         EXT_TestSetVRAMForScreenShot(GX_VRAM_LCDC_C);
89         EXT_TestScreenShot(100, 0xC7953680);
90         EXT_TestTickCounter();
91 #endif //SDK_AUTOTEST
92 
93         OS_WaitVBlankIntr();           // Waiting for the end of the VBlank interrupt
94         GX_LoadBG0Scr(sScrnBuf, 0, sizeof(sScrnBuf));
95     }
96 }
97 
98 //---------------------------------------------------------------------------
99 // VBlank interrupt function:
100 //
101 // Interrupt handlers are registered on the interrupt table by OS_SetIRQFunction.
102 // OS_EnableIrqMask selects IRQ interrupts to enable, and
103 // OS_EnableIrq enables IRQ interrupts.
104 // Notice that you have to call 'OS_SetIrqCheckFlag' to check a VBlank interrupt.
105 //---------------------------------------------------------------------------
VBlankIntr(void)106 void VBlankIntr(void)
107 {
108     OS_SetIrqCheckFlag(OS_IE_V_BLANK); // Checking VBlank interrupt
109 }
110