Mercurial > hg > index.fcgi > lj > lj046-2players
diff src/dssleep.c @ 0:c84446dfb3f5
initial add
author | paulo@localhost |
---|---|
date | Fri, 13 Mar 2009 00:39:12 -0700 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/dssleep.c Fri Mar 13 00:39:12 2009 -0700 1.3 @@ -0,0 +1,35 @@ 1.4 +#include <nds.h> 1.5 + 1.6 +/* 1.7 +by Mighty Max and melw, 1.8 +after http://forum.gbadev.org/viewtopic.php?t=12011 1.9 +*/ 1.10 + 1.11 +int needLidSleep(void) { 1.12 + // when reading keys 1.13 + if (IPC->buttons & 0x0080) { 1.14 + /* hinge is closed */ 1.15 + 1.16 + /* Step 1: Turn off all interrupts but vblank for waking up */ 1.17 + unsigned long oldIE = REG_IE; 1.18 + REG_IE = IRQ_VBLANK; 1.19 + 1.20 + /* Step 2: Power off most of the system */ 1.21 + powerOFF(POWER_LCD); 1.22 + 1.23 + /* Step 3: Wait one vblank at a time until the ARM7 tells us 1.24 + that the lid is no longer closed */ 1.25 + while (IPC->buttons & 0x0080) { 1.26 + swiWaitForVBlank(); 1.27 + } 1.28 + 1.29 + /* Step 4: Wait a bit more (necessary?) */ 1.30 + swiWaitForVBlank(); 1.31 + 1.32 + /* Step 5: Restore old machine state */ 1.33 + powerON(POWER_LCD); 1.34 + REG_IE = oldIE; 1.35 + return 1; 1.36 + } 1.37 + return 0; 1.38 +}