1 /*---------------------------------------------------------------------------*
2 Project: Dimming & Stopping Motor of DVD drive DEMO
3 File: dimming.c
4
5 Copyright (C)2006 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 $Log: dimming.c,v $
14 Revision 1.10 2007/07/17 06:32:28 urata
15 Added VIResetDimmingCount.
16
17 Revision 1.9 2006/11/29 00:00:54 urata
18 Removed VIResetDimmingCount
19
20 Revision 1.8 2006/11/28 06:02:04 urata
21 Added VIResetDimmingCount.
22
23 Revision 1.7 2006/10/26 07:15:36 urata
24 Removed VI[Set/Get]ScreenSaverMode.
25
26 Revision 1.6 2006/10/26 02:06:30 urata
27 Fixed.
28
29 Revision 1.5 2006/10/26 01:57:52 urata
30 Added VI[Set/Get]ScreenSaverMode.
31
32 Revision 1.4 2006/10/26 00:15:26 urata
33 Added WPAD.
34
35 Revision 1.3 2006/10/25 05:48:12 urata
36 Added VISetTimeToDimming and removed VIEnableDimming, WPAD.
37
38 Revision 1.2 2006/09/14 06:10:03 urata
39 Added WPAD.
40
41 Revision 1.1 2006/09/06 14:08:43 urata
42 Initial checkin.
43
44 $NoKeywords: $
45 *---------------------------------------------------------------------------*/
46 #include <stdlib.h>
47 #include <string.h>
48 #include <stddef.h>
49 #include <stdarg.h>
50 #include <stdio.h>
51 #include <ctype.h>
52
53 #include <revolution.h>
54 #include <revolution/wpad.h>
55 #define DEMO_USE_MEMLIB=1 // This turns on the DEMO library's MEM heaps.
56 #include <demo.h>
57
58
59 #define WAIT_TO_ISSUE_VISetTimeToDimming 500 //500 field
60 #define WAIT_TO_ISSUE_VIResetDimmingCount 500 //500 field
61 /*---------------------------------------------------------------------------*
62 * Name : myAlloc()
63 * Description : Callback needed by WPAD to allocate mem from MEM2 heap
64 * Arguments : size of block, in bytes.
65 * Returns : pointer to allocated block.
66 *---------------------------------------------------------------------------*/
myAlloc(u32 size)67 static void *myAlloc(u32 size)
68 {
69 void *ptr;
70
71 ptr = MEMAllocFromAllocator(&DemoAllocator2, size);
72 ASSERTMSG(ptr, "Memory allocation failed\n");
73
74 return(ptr);
75
76 }
77
78 /*---------------------------------------------------------------------------*
79 * Name : myFree()
80 * Description : Callback needed by WPAD to free mem from MEM2 heap
81 * Arguments : None.
82 * Returns : Always 1.
83 *---------------------------------------------------------------------------*/
myFree(void * ptr)84 static u8 myFree(void *ptr)
85 {
86
87 MEMFreeToAllocator(&DemoAllocator2, ptr);
88
89 // we should ensure that memory is free'd properly, but oh well
90 return(1);
91
92 }
93
94
95 /*---------------------------------------------------------------------------*
96 Name: FontInit
97
98 Description:
99
100 Arguments: none
101
102 Returns: none
103 *---------------------------------------------------------------------------*/
FontInit(void)104 static void FontInit( void )
105 {
106 GXColor Blue = {0x0,0x0,0x80,0xff}; //R,G,B,A
107 if (DEMOInitROMFont() == 0)
108 {
109 OSHalt("FONT ERROR\n");
110 // NOT REACHED HERE
111 }
112
113 // Clear EFB
114 GXSetCopyClear(Blue, 0x00ffffff);
115 GXCopyDisp(DEMOGetCurrentBuffer(), GX_TRUE);
116 }
117
118 /*---------------------------------------------------------------------------*
119 Name: main
120
121 Description:
122
123 Arguments: none
124
125 Returns: none
126 *---------------------------------------------------------------------------*/
main(void)127 void main ( void )
128 {
129 GXRenderModeObj *rmp;
130 s32 wait,wait_for_reset;
131 s16 tx,ty,fh;
132 VITimeToDIM old_time;
133 VITimeToDIM new_time;
134 WPADStatus wpad;
135 u16 oldbtn;
136 u32 type;
137 s32 wpad_state;
138
139 DEMOInit(NULL);
140 FontInit();
141 rmp = DEMOGetRenderModeObj();
142
143 // we should clear the WPADStatus block returned by
144 // WPADRead(), because if no channel is connected, nothing
145 // is copied. So we would be staring at garbage data.
146 memset( (void *)(&wpad), 0, sizeof(WPADStatus));
147
148 // - We must now register memory allocation/free functions
149 // for MEM2.
150 // - WPAD requires some memory in MEM2 for data transfers
151 // between the controller and WPAD driver stack.
152 // - Memory allocation only occurs once, at the initialization.
153 // - Memory usage is on the order of 1KB.
154 // - NOTE: We are using the MEM library allocators defined by
155 // the DEMO library.
156 //
157 WPADRegisterAllocator(myAlloc, myFree);
158
159 // Initialize WPAD!
160 WPADInit();
161
162 // The WPAD initialization process is asynchronous.
163 // So we should wait until it's completed.
164 // The WPAD initialization process is asynchronous.
165 // So we should wait until it's completed.
166 do
167 {
168 wpad_state = WPADGetStatus();
169 } while (WPAD_STATE_SETUP != wpad_state);
170
171
172 new_time = VI_DM_DEFAULT;
173 wait = WAIT_TO_ISSUE_VISetTimeToDimming;
174 wait_for_reset = WAIT_TO_ISSUE_VIResetDimmingCount;
175
176 while(1)
177 {
178 tx = 50;
179 ty = 50;
180
181 DEMOBeforeRender();
182
183 fh = 25;
184 DEMOSetROMFontSize(fh, -1);
185 DEMOInitCaption(DM_FT_XLU, (s16)rmp->fbWidth, (s16) rmp->efbHeight);
186 DEMORFPrintf(tx, ty+=fh, 0, "Dimming test");
187
188 fh = 18;
189 DEMOSetROMFontSize(fh, -1);
190 ty+=fh;
191 DEMORFPrintf(tx, ty+=fh, 0, "Count to dimming = %8u",VIGetDimmingCount());
192 DEMORFPrintf(tx, ty+=fh, 0, "Limit time to dimming = %s",old_time == VI_DM_10M ? "10 minutes" :
193 old_time == VI_DM_15M ? "15 minutes" :
194 " 5 minutes");
195 DEMORFPrintf(tx, ty+=fh, 0, "Wait time to issue VISetTimeToDimming = %3d[field]",
196 wait < 0 ? 0 : wait);
197 DEMORFPrintf(tx, ty+=fh, 0, "Wait time to issue VIResetDimmingCount = %3d[field]",
198 wait_for_reset < 0 ? 0 : wait_for_reset);
199
200
201 ty+=fh;
202 ty+=fh;
203 ty+=fh;
204 DEMORFPrintf(tx, ty+=fh, 0, "A button to change the limit time to 5 minutes.");
205 DEMORFPrintf(tx, ty+=fh, 0, "- button to change the limit time to 10 minutes.");
206 DEMORFPrintf(tx, ty+=fh, 0, "+ button to change the limit time to 15 minutes.");
207 DEMORFPrintf(tx, ty+=fh, 0, "B button to set the wait time to issue VISetTimeToDimming.");
208 DEMORFPrintf(tx, ty+=fh, 0, "1 button to issue VIResetDimmingCount after %d field.",WAIT_TO_ISSUE_VIResetDimmingCount);
209 DEMODoneRender();
210
211 // We should probe the channel first
212 // is a controller connected?
213 if(WPAD_ERR_NONE == WPADProbe(WPAD_CHAN0, &type))
214 {
215 // Read data/status from channel 0.
216 WPADRead( WPAD_CHAN0, &wpad );
217 } // if no error...
218
219
220 DEMOPadRead();
221 if (( DEMOPadGetButtonDown(0) & PAD_BUTTON_A ) || ( (wpad.button & WPAD_BUTTON_A) && !oldbtn ))
222 {
223 new_time = VI_DM_DEFAULT;
224 }
225 if (( DEMOPadGetButtonDown(0) & PAD_BUTTON_X ) || ( (wpad.button & WPAD_BUTTON_MINUS) && !oldbtn ))
226 {
227 new_time = VI_DM_10M;
228 }
229 if (( DEMOPadGetButtonDown(0) & PAD_BUTTON_Y ) || ( (wpad.button & WPAD_BUTTON_PLUS) && !oldbtn ))
230 {
231 new_time = VI_DM_15M;
232 }
233 if (( DEMOPadGetButtonDown(0) & PAD_BUTTON_B ) || ( (wpad.button & WPAD_BUTTON_B) && !oldbtn ))
234 {
235 wait = WAIT_TO_ISSUE_VISetTimeToDimming;
236 }
237 if (( DEMOPadGetButtonDown(0) & PAD_TRIGGER_R ) || ( (wpad.button & WPAD_BUTTON_1) && !oldbtn ))
238 {
239 wait_for_reset = WAIT_TO_ISSUE_VIResetDimmingCount;
240 }
241
242 if(--wait < 0)
243 {
244 old_time = VISetTimeToDimming( new_time );
245 // VISetTimeToDimming works here without calling VIFlush.
246 }
247
248 if(wait_for_reset > 0)
249 {
250 wait_for_reset--;
251 if(wait_for_reset == 0)
252 {
253 VIResetDimmingCount();
254 // VIResetDimmingCount works here without calling VIFlush.
255 }
256 }
257 oldbtn = wpad.button;
258 }
259 }
260
261