comparison src/dssleep.c @ 2:80a2761bd3a4

change DS keys (add alt. rotate)
author paulo@localhost
date Mon, 23 Mar 2009 01:19: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 }