1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - GX - demos - UnitTours/Sub_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 or vertically
20 //
21 // USAGE:
22 // A: Flips horizontally
23 // B: Flips vertically
24 //
25 // HOWTO:
26 // 1. Set up the character/palette/screen data the same as Sub_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 DEMOInitDisplaySubBG0Only();
53
54 //---------------------------------------------------------------------------
55 // Transmitting the character data and the palette data
56 //---------------------------------------------------------------------------
57 GXS_LoadBG0Char(d_64_256_bg_schDT, 0, sizeof(d_64_256_bg_schDT));
58 GXS_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 for (i = 0; i < 8; i++)
77 {
78 for (j = 0; j < 8; j++)
79 {
80 sScrnBuf[(i * 32) + j] = (u16)(flip_V << 11 | flip_H << 10 | ((i * 0x10) + j));
81 }
82 }
83 // Store the data in the main memory, and invalidate the cache
84 DC_FlushRange(sScrnBuf, sizeof(sScrnBuf));
85 /* I/O register is accessed using DMA operation, so cache wait is not needed */
86 // DC_WaitWriteBufferEmpty();
87
88 OS_WaitVBlankIntr(); // Waiting for the end of the V-Blank interrupt
89
90 GXS_LoadBG0Scr(sScrnBuf, 0, sizeof(sScrnBuf));
91 }
92 }
93
94 //---------------------------------------------------------------------------
95 // V-Blank interrupt function:
96 //
97 // Interrupt handlers are registered on the interrupt table by OS_SetIRQFunction.
98 // OS_EnableIrqMask selects IRQ interrupts to enable, and
99 // OS_EnableIrq enables IRQ interrupts.
100 // Notice that you have to call OS_SetIrqCheckFlag to check a V-Blank interrupt.
101 //---------------------------------------------------------------------------
VBlankIntr(void)102 void VBlankIntr(void)
103 {
104 OS_SetIrqCheckFlag(OS_IE_V_BLANK); // Checking V-Blank interrupt
105 }
106