1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - MB - demos - multiboot-PowerSave
3   File:     menu.c
4 
5   Copyright 2006-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 #ifdef SDK_TWL
20 #include	<twl.h>
21 #else
22 #include	<nitro.h>
23 #endif
24 
25 
26 #include "common.h"
27 #include "dispfunc.h"
28 
29 
30 /*****************************************************************************/
31 /* Declaration */
32 
33 static void MenuInit(void);
34 static void MenuUpdate(void);
35 static void MenuDraw(void);
36 
37 
38 /*****************************************************************************/
39 /* Constants */
40 
41 enum
42 {
43     MENU_POWERSAVE,
44     MENU_NUM
45 };
46 
47 
48 /*****************************************************************************/
49 /* Variables */
50 
51 static struct
52 {
53     int     cursor;
54     BOOL    loop;
55 }
56 menu_context;
57 
58 
59 /*****************************************************************************/
60 /* Functions */
61 
62 /*---------------------------------------------------------------------------*
63   Name:         MenuInit
64 
65   Description:  Initializes the state of the DS Single-Card Play initial settings menu.
66 
67   Arguments:    None.
68 
69   Returns:      None.
70  *---------------------------------------------------------------------------*/
MenuInit(void)71 static void MenuInit(void)
72 {
73     menu_context.cursor = 0;
74     menu_context.loop = TRUE;
75 
76     /* Initializes display settings */
77     GX_DispOn();
78     GXS_DispOn();
79     G2_SetBG0Offset(0, 0);
80     G2S_SetBG0Offset(0, 0);
81 }
82 
83 /*---------------------------------------------------------------------------*
84   Name:         MenuUpdate
85 
86   Description:  Updates the state of the DS Single-Card Play initial settings menu.
87 
88   Arguments:    None.
89 
90   Returns:      None.
91  *---------------------------------------------------------------------------*/
MenuUpdate(void)92 static void MenuUpdate(void)
93 {
94     const u16 keyData = ReadKeySetTrigger();
95 
96     /* Change cursor number */
97     if ((keyData & PAD_KEY_DOWN) != 0)
98     {
99         if (++menu_context.cursor >= MENU_NUM)
100             menu_context.cursor -= MENU_NUM;
101     }
102     else if ((keyData & PAD_KEY_UP) != 0)
103     {
104         if (--menu_context.cursor < 0)
105             menu_context.cursor += MENU_NUM;
106     }
107     else if ((keyData & (PAD_BUTTON_A | PAD_BUTTON_START)) != 0)
108     {
109         menu_context.loop = FALSE;
110     }
111 
112     switch (menu_context.cursor)
113     {
114     case MENU_POWERSAVE:
115         /* Configure power-save mode */
116         if ((keyData & (PAD_KEY_RIGHT | PAD_KEY_LEFT)) != 0)
117         {
118             g_power_save_mode = !g_power_save_mode;
119         }
120         break;
121     }
122 }
123 
124 /*---------------------------------------------------------------------------*
125   Name:         MenuDraw
126 
127   Description:  Draws the state of the DS Single-Card Play initial settings menu.
128 
129   Arguments:    None.
130 
131   Returns:      None.
132  *---------------------------------------------------------------------------*/
MenuDraw(void)133 static void MenuDraw(void)
134 {
135     enum
136     { DISP_OX = 5, DISP_OY = 5 };
137     BgClear();
138     BgPutString(DISP_OX + 3, DISP_OY - 3, WHITE, "Multiboot Sample", 32);
139     BgPrintf(DISP_OX + 0, DISP_OY + 0, WHITE,
140              "Power Save       %s", g_power_save_mode ? "[TRUE]" : "[FALSE]");
141     BgPutChar(DISP_OX - 2, DISP_OY + menu_context.cursor, RED, '*');
142     BgPutString(DISP_OX, DISP_OY + 14, WHITE, " Press A or START Button", 32);
143 }
144 
145 /*---------------------------------------------------------------------------*
146   Name:         MenuMode
147 
148   Description:  Initial settings menu for the DS Single-Card parent device.
149 
150   Arguments:    None.
151 
152   Returns:      None.
153  *---------------------------------------------------------------------------*/
MenuMode(void)154 void MenuMode(void)
155 {
156     MenuInit();
157     while (menu_context.loop)
158     {
159         MenuUpdate();
160         MenuDraw();
161         OS_WaitVBlankIntr();
162     }
163 }
164