Mercurial > hg > index.fcgi > lj > lj046
view src/dssleep.c @ 0:c84446dfb3f5
initial add
author | paulo@localhost |
---|---|
date | Fri, 13 Mar 2009 00:39:12 -0700 |
parents | |
children |
line source
1 #include <nds.h>
3 /*
4 by Mighty Max and melw,
5 after http://forum.gbadev.org/viewtopic.php?t=12011
6 */
8 int needLidSleep(void) {
9 // when reading keys
10 if (IPC->buttons & 0x0080) {
11 /* hinge is closed */
13 /* Step 1: Turn off all interrupts but vblank for waking up */
14 unsigned long oldIE = REG_IE;
15 REG_IE = IRQ_VBLANK;
17 /* Step 2: Power off most of the system */
18 powerOFF(POWER_LCD);
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 }
26 /* Step 4: Wait a bit more (necessary?) */
27 swiWaitForVBlank();
29 /* Step 5: Restore old machine state */
30 powerON(POWER_LCD);
31 REG_IE = oldIE;
32 return 1;
33 }
34 return 0;
35 }