1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - GX - demos - UnitTours/2D_CharBg_5
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 //---------------------------------------------------------------------------
19 // A sample that flips all characters on the screen horizontally/vertically:
20 //
21 // USAGE:
22 // A: Flips horizontally
23 // B: Flips vertically
24 //
25 // HOWTO:
26 // 1. Set up the character/palette/screen data same as 2D_CharBG_1.
27 // 2. Set up horizontal/vertical flip bits of the screen data.
28 //---------------------------------------------------------------------------
29
30 #ifdef SDK_TWL
31 #include <twl.h>
32 #else
33 #include <nitro.h>
34 #endif
35 #include "DEMO.h"
36 #include "data.h"
37
38 static u16 sScrnBuf[SCREEN_SIZE]; // Buffer for screen data (BG #0)
39
40 #ifdef SDK_TWL
TwlMain(void)41 void TwlMain(void)
42 #else
43 void NitroMain(void)
44 #endif
45 {
46 //---------------------------------------------------------------------------
47 // Initialize:
48 // Enables IRQ interrupts, initializes VRAM, and sets BG #0 for text mode.
49 //---------------------------------------------------------------------------
50 DEMOInitCommon();
51 DEMOInitVRAM();
52 DEMOInitDisplayBG0Only();
53
54 //---------------------------------------------------------------------------
55 // Transmitting the character data and the palette data
56 //---------------------------------------------------------------------------
57 GX_LoadBG0Char(d_64_256_bg_schDT, 0, sizeof(d_64_256_bg_schDT));
58 GX_LoadBGPltt(d_64_256_bg_sclDT, 0, sizeof(d_64_256_bg_sclDT));
59
60 DEMOStartDisplay();
61 //---------------------------------------------------------------------------
62 // Main Loop
63 //---------------------------------------------------------------------------
64 while (1)
65 {
66 int flip_H = 0, flip_V = 0;
67 int i, j;
68
69 DEMOReadKey();
70
71 if (DEMO_IS_PRESS(PAD_BUTTON_A))
72 flip_H = 1;
73 if (DEMO_IS_PRESS(PAD_BUTTON_B))
74 flip_V = 1;
75
76 #ifdef SDK_AUTOTEST
77 flip_H = 1;
78 flip_V = 1; // default params for testing.
79 GX_SetBankForLCDC(GX_VRAM_LCDC_C);
80 EXT_TestSetVRAMForScreenShot(GX_VRAM_LCDC_C);
81 EXT_TestScreenShot(100, 0xC776DFB4);
82 EXT_TestTickCounter();
83 #endif //SDK_AUTOTEST
84
85 for (i = 0; i < 8; i++)
86 {
87 for (j = 0; j < 8; j++)
88 {
89 sScrnBuf[(i * 32) + j] = (u16)(flip_V << 11 | flip_H << 10 | ((i * 0x10) + j));
90 }
91 }
92 // Store the data in the main memory, and invalidate the cache.
93 DC_FlushRange(sScrnBuf, sizeof(sScrnBuf));
94 /* I/O register is accessed using DMA operation, so cache wait is not needed */
95 // DC_WaitWriteBufferEmpty();
96
97 OS_WaitVBlankIntr(); // Waiting for the end of the VBlank interrupt
98
99 GX_LoadBG0Scr(sScrnBuf, 0, sizeof(sScrnBuf));
100 }
101 }
102
103 //---------------------------------------------------------------------------
104 // VBlank interrupt function:
105 //
106 // Interrupt handlers are registered on the interrupt table by OS_SetIRQFunction.
107 // OS_EnableIrqMask selects IRQ interrupts to enable, and
108 // OS_EnableIrq enables IRQ interrupts.
109 // Notice that you have to call 'OS_SetIrqCheckFlag' to check a VBlank interrupt.
110 //---------------------------------------------------------------------------
VBlankIntr(void)111 void VBlankIntr(void)
112 {
113 OS_SetIrqCheckFlag(OS_IE_V_BLANK); // Checking VBlank interrupt
114 }
115