comparison src/dssleep.c @ 0:c84446dfb3f5

initial add
author paulo@localhost
date Fri, 13 Mar 2009 00:39:12 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:2428a840cff0
1 #include <nds.h>
2
3 /*
4 by Mighty Max and melw,
5 after http://forum.gbadev.org/viewtopic.php?t=12011
6 */
7
8 int needLidSleep(void) {
9 // when reading keys
10 if (IPC->buttons & 0x0080) {
11 /* hinge is closed */
12
13 /* Step 1: Turn off all interrupts but vblank for waking up */
14 unsigned long oldIE = REG_IE;
15 REG_IE = IRQ_VBLANK;
16
17 /* Step 2: Power off most of the system */
18 powerOFF(POWER_LCD);
19
20 /* Step 3: Wait one vblank at a time until the ARM7 tells us
21 that the lid is no longer closed */
22 while (IPC->buttons & 0x0080) {
23 swiWaitForVBlank();
24 }
25
26 /* Step 4: Wait a bit more (necessary?) */
27 swiWaitForVBlank();
28
29 /* Step 5: Restore old machine state */
30 powerON(POWER_LCD);
31 REG_IE = oldIE;
32 return 1;
33 }
34 return 0;
35 }