1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - GX - demos - UnitTours/Window
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:: 2009-02-06#$
14 $Rev: 9986 $
15 $Author: yosizaki $
16 *---------------------------------------------------------------------------*/
17 //---------------------------------------------------------------------------
18 // A sample which transform window in HBlank period.
19 //
20 // Back ground image is displayed only in transformed window.
21 //
22 // HOWTO:
23 // 1. On HBlank interruption, Change window position.
24 //
25 //---------------------------------------------------------------------------
26 #ifdef SDK_TWL
27 #include <twl.h>
28 #else
29 #include <nitro.h>
30 #endif
31 #include "DEMO.h"
32 #include "data.h"
33
34 //---------------------------------------------------------------------------
35 // Array for window position per line
36 //---------------------------------------------------------------------------
37 static u16 s_WindowSizePerLine[192];
38
39 //---------------------------------------------------------------------------
40 // Create window horizontal position table per line
41 //---------------------------------------------------------------------------
CreateWindowStyle(void)42 static void CreateWindowStyle(void)
43 {
44 int i;
45 u16 left_pos;
46 u16 right_pos;
47 int size;
48
49 for (i = 0; i < 96; i++)
50 {
51 size = (256 * i) / 96;
52 left_pos = (u16)(128 - (size / 2));
53 right_pos = (u16)(128 + (size / 2));
54 s_WindowSizePerLine[i] = (u16)((left_pos << 8) | right_pos);
55 }
56 for (i = 96; i < 192; i++)
57 {
58 s_WindowSizePerLine[i] = s_WindowSizePerLine[191 - i];
59 }
60 }
61
62 //---------------------------------------------------------------------------
63 // HBlank interrupt
64 // Set window horizontal position along position table.
65 //---------------------------------------------------------------------------
HBlankIntr(void)66 static void HBlankIntr(void)
67 {
68 const int count = GX_GetVCount();
69
70 // case not VBlank
71 if (count < 192)
72 {
73 //---------------------------------------------------------------------------
74 // Set window horizontal position
75 G2_SetWnd0Position(s_WindowSizePerLine[count] >> 8,
76 0, s_WindowSizePerLine[count] & 0xff, 192);
77 //---------------------------------------------------------------------------
78 }
79 // Set flag which checks HBlank interrupt.
80 OS_SetIrqCheckFlag(OS_IE_H_BLANK);
81 }
82
83 //---------------------------------------------------------------------------
84 // VBlank interrupt function:
85 //
86 // Interrupt handlers are registered on the interrupt table by OS_SetIRQFunction.
87 // OS_EnableIrqMask selects IRQ interrupts to enable, and
88 // OS_EnableIrq enables IRQ interrupts.
89 // Notice that you have to call 'OS_SetIrqCheckFlag' to check a VBlank interrupt.
90 //---------------------------------------------------------------------------
VBlankIntr(void)91 void VBlankIntr(void)
92 {
93 //---------------------------------------------------------------------------
94 // Set Window horizontal position (first line)
95 G2_SetWnd0Position(s_WindowSizePerLine[0] >> 8, 0, s_WindowSizePerLine[0] & 0xff, 192);
96 //---------------------------------------------------------------------------
97
98 // Set flag which checks VBlank interrupt.
99 OS_SetIrqCheckFlag(OS_IE_V_BLANK);
100 }
101
102 //---------------------------------------------------------------------------
103 // main
104 //---------------------------------------------------------------------------
105 #ifdef SDK_TWL
TwlMain(void)106 void TwlMain(void)
107 #else
108 void NitroMain(void)
109 #endif
110 {
111 // Initialize
112 DEMOInitCommon();
113 DEMOInitVRAM();
114 DEMOInitDisplayBG0Only();
115
116 // setting interrupt
117 (void)OS_DisableIrq(); // Disable IRQ interrupt
118 OS_SetIrqFunction(OS_IE_H_BLANK, // Add function on H-Blank interrupt
119 HBlankIntr);
120 (void)OS_EnableIrqMask(OS_IE_V_BLANK // Set interrupt setting flag
121 | OS_IE_H_BLANK);
122 (void)GX_HBlankIntr(TRUE); // Rise a H-Blank interrupt
123 (void)OS_EnableIrq(); // Enabled IRQ interrupt
124
125 // Load 2D graphic data
126 GX_LoadBG0Char(d_natsunoumi_schDT, 0, sizeof(d_natsunoumi_schDT));
127 GX_LoadBGPltt(d_natsunoumi_sclDT, 0, sizeof(d_natsunoumi_sclDT));
128 GX_LoadBG0Scr(d_natsunoumi_sscDT, 0, sizeof(d_natsunoumi_sscDT));
129
130 // Window setting
131 GX_SetVisibleWnd(GX_WNDMASK_W0); // Turn on WINDOW-0
132 // Set inside of window visible BG0
133 G2_SetWnd0InsidePlane(GX_WND_PLANEMASK_BG0, FALSE);
134 // Set outside of window unvisible
135 G2_SetWndOutsidePlane(GX_WND_PLANEMASK_NONE, FALSE);
136
137 // Create window horizontal position table
138 CreateWindowStyle();
139
140 DEMOStartDisplay();
141
142 // main loop
143 while (1)
144 {
145 // Wait VBlank
146 OS_WaitVBlankIntr();
147
148 #ifdef SDK_AUTOTEST // code for auto test
149 GX_SetBankForLCDC(GX_VRAM_LCDC_C);
150 EXT_TestSetVRAMForScreenShot(GX_VRAM_LCDC_C);
151 EXT_TestScreenShot(100, 0x7C44DB20);
152 EXT_TestTickCounter();
153 #endif //SDK_AUTOTEST
154 }
155 }
156