1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - GX - demos - UnitTours/2D_BmpBg_MainRam
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 the image on the main memory by main memory display mode:
20 //
21 // If display mode is main memory display mode, a bitmap image on
22 // the main memory is displayed through the specialized FIFO.
23 // This sample loads different four images to the main memory,
24 // and displays them by turns.
25 //
26 // HOWTO:
27 // 1. Switch to main memory display mode by GX_SetGraphicsMode(GX_DISPMODE_MMEM, ...).
28 // 2. Transfer images on the main memory by MI_DispMemDmaCopy() every V-Blank.
29 //---------------------------------------------------------------------------
30
31 #ifdef SDK_TWL
32 #include <twl.h>
33 #else
34 #include <nitro.h>
35 #endif
36 #include "DEMO.h"
37 #include "image.h"
38
39 #ifdef SDK_TWL
TwlMain(void)40 void TwlMain(void)
41 #else
42 void NitroMain(void)
43 #endif
44 {
45 int count = 0;
46 int slot = 0;
47
48 //---------------------------------------------------------------------------
49 // Initialize:
50 // They enable IRQ interrupts, and initialize VRAM.
51 //---------------------------------------------------------------------------
52 DEMOInitCommon();
53 DEMOInitVRAM();
54
55 GX_SetGraphicsMode(GX_DISPMODE_MMEM, // display main memory
56 (GXBGMode)0, // dummy
57 (GXBG0As)0); // dummy
58
59 DEMOStartDisplay();
60
61 #ifdef SDK_AUTOTEST
62 GX_SetBankForLCDC(GX_VRAM_LCDC_C);
63 EXT_TestSetVRAMForScreenShot(GX_VRAM_LCDC_C);
64 #endif // SDK_AUTOTEST
65
66 //-------------------------------------------------------------------------
67 // Give the main memory access priority to ARM9.
68 // In MI_DispMemDmaCopy, ARM9 should send a lot of pixel to VRAM via DMA
69 // at highest priority (higher than ARM7 sound DMA).
70 // This may be a risk that sound noise occurs.
71 //---------------------------------------------------------------------------
72 MI_SetMainMemoryPriority(MI_PROCESSOR_ARM9);
73
74 while (1)
75 {
76 if (count++ > 90)
77 {
78 slot++;
79 slot &= 0x03;
80 count = 0;
81 }
82
83 #ifdef SDK_AUTOTEST
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 // Transfer images from main memory to VRAM through the specialized FIFO by DMA.
92 // It must be completed within a period of V-Blank.
93 //---------------------------------------------------------------------------
94 MI_DispMemDmaCopy(3, IMAGE_MRAM256x192[slot]);
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