1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - GX - demos - UnitTours/2D_BmpBg_Vram
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-17#$
14   $Rev: 8556 $
15   $Author: okubata_ryoma $
16  *---------------------------------------------------------------------------*/
17 
18 //---------------------------------------------------------------------------
19 // A sample that displays VRAM image:
20 //
21 // If display mode is VRAM display mode, a bitmap image on VRAM is displayed.
22 // This sample loads different four images to VRAM A-D, and displays them by turns.
23 //
24 // HOWTO:
25 // 1. Set the target VRAM banks to LCDC mode.
26 // 2. Load images to them (by MI_DmaCopy32()).
27 // 3. Start to display the VRAM image by GX_SetGraphicsMode(GX_DISPMODE_VRAM_A, ...).
28 //---------------------------------------------------------------------------
29 
30 #ifdef SDK_TWL
31 #include <twl.h>
32 #else
33 #include <nitro.h>
34 #endif
35 #include "DEMO.h"
36 #include "image.h"
37 
38 #ifdef SDK_TWL
TwlMain(void)39 void TwlMain(void)
40 #else
41 void NitroMain(void)
42 #endif
43 {
44     int     vram_slot = 0, count = 0;
45 
46     //---------------------------------------------------------------------------
47     // Initialize:
48     // They enable IRQ interrupts, and initialize VRAM.
49     //---------------------------------------------------------------------------
50     DEMOInitCommon();
51     DEMOInitVRAM();
52 
53     //---------------------------------------------------------------------------
54     // Map VRAM bank A-D onto LCDC.
55     //---------------------------------------------------------------------------
56     GX_SetBankForLCDC(GX_VRAM_LCDC_A | GX_VRAM_LCDC_B | GX_VRAM_LCDC_C | GX_VRAM_LCDC_D);
57 
58     //---------------------------------------------------------------------------
59     // Download images
60     //---------------------------------------------------------------------------
61     MI_DmaCopy32(3, IMAGE_VRAM256x192[0], (void *)HW_LCDC_VRAM_A,
62                  256 * 192 * sizeof(unsigned short));
63     MI_DmaCopy32(3, IMAGE_VRAM256x192[1], (void *)HW_LCDC_VRAM_B,
64                  256 * 192 * sizeof(unsigned short));
65     MI_DmaCopy32(3, IMAGE_VRAM256x192[2], (void *)HW_LCDC_VRAM_C,
66                  256 * 192 * sizeof(unsigned short));
67     MI_DmaCopy32(3, IMAGE_VRAM256x192[3], (void *)HW_LCDC_VRAM_D,
68                  256 * 192 * sizeof(unsigned short));
69 
70     //---------------------------------------------------------------------------
71     // Set graphics mode VRAM display mode
72     //---------------------------------------------------------------------------
73     GX_SetGraphicsMode(GX_DISPMODE_VRAM_A,      // display VRAM-A
74                        (GXBGMode)0,    // dummy
75                        (GXBG0As)0);    // dummy
76 
77     DEMOStartDisplay();
78     while (1)
79     {
80 
81 #ifdef SDK_AUTOTEST
82         GX_SetBankForLCDC(GX_VRAM_LCDC_C);
83         EXT_TestSetVRAMForScreenShot(GX_VRAM_LCDC_C);
84         EXT_TestScreenShot(100, 0x05230657);
85         EXT_TestTickCounter();
86 #endif //SDK_AUTOTEST
87 
88         OS_WaitVBlankIntr();           // Waiting the end of VBlank interrupt
89 
90         //---------------------------------------------------------------------------
91         // Change the VRAM slot displayed every 90 frames
92         //---------------------------------------------------------------------------
93         if (count++ > 90)
94         {
95             vram_slot++;
96             vram_slot &= 0x03;
97             switch (vram_slot)
98             {
99             case 0:
100                 GX_SetGraphicsMode(GX_DISPMODE_VRAM_A,  // display VRAM-A
101                                    (GXBGMode)0, // dummy
102                                    (GXBG0As)0); // dummy
103                 break;
104             case 1:
105                 GX_SetGraphicsMode(GX_DISPMODE_VRAM_B,  // display VRAM-B
106                                    (GXBGMode)0, // dummy
107                                    (GXBG0As)0); // dummy
108                 break;
109             case 2:
110                 GX_SetGraphicsMode(GX_DISPMODE_VRAM_C,  // display VRAM-C
111                                    (GXBGMode)0, // dummy
112                                    (GXBG0As)0); // dummy
113                 break;
114             case 3:
115                 GX_SetGraphicsMode(GX_DISPMODE_VRAM_D,  // display VRAM-D
116                                    (GXBGMode)0, // dummy
117                                    (GXBG0As)0); // dummy
118                 break;
119             }
120             // reset a counter
121             count = 0;
122         }
123     }
124 }
125 
126 //---------------------------------------------------------------------------
127 // VBlank interrupt function:
128 //
129 // Interrupt handlers are registered on the interrupt table by OS_SetIRQFunction.
130 // OS_EnableIrqMask selects IRQ interrupts to enable, and
131 // OS_EnableIrq enables IRQ interrupts.
132 // Notice that you have to call 'OS_SetIrqCheckFlag' to check a VBlank interrupt.
133 //---------------------------------------------------------------------------
VBlankIntr(void)134 void VBlankIntr(void)
135 {
136     OS_SetIrqCheckFlag(OS_IE_V_BLANK); // checking VBlank interrupt
137 }
138